blob: ab64e31edaebe083a3a01a71c624c01822b65c7f [file] [log] [blame]
Thomas Vachuska9252bc32014-10-23 02:33:25 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuska9252bc32014-10-23 02:33:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska9252bc32014-10-23 02:33:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska9252bc32014-10-23 02:33:25 -070015 */
Jonathan Hart9bb32ab2015-05-05 18:17:31 -070016package org.onosproject.rest.resources;
Thomas Vachuska9252bc32014-10-23 02:33:25 -070017
Ray Milkey9b36d812015-09-09 15:24:54 -070018import java.io.InputStream;
Thomas Vachuska9252bc32014-10-23 02:33:25 -070019
20import javax.ws.rs.Consumes;
21import javax.ws.rs.POST;
22import javax.ws.rs.Path;
23import javax.ws.rs.Produces;
24import javax.ws.rs.core.MediaType;
25import javax.ws.rs.core.Response;
Ray Milkey9b36d812015-09-09 15:24:54 -070026
27import org.onlab.rest.BaseResource;
28import org.onosproject.net.device.DeviceProviderRegistry;
29import org.onosproject.net.device.DeviceService;
30import org.onosproject.net.host.HostProviderRegistry;
31import org.onosproject.net.link.LinkProviderRegistry;
32import org.slf4j.Logger;
33import org.slf4j.LoggerFactory;
34
35import com.fasterxml.jackson.databind.JsonNode;
36import com.fasterxml.jackson.databind.ObjectMapper;
Thomas Vachuska9252bc32014-10-23 02:33:25 -070037
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080038import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
39
Thomas Vachuska9252bc32014-10-23 02:33:25 -070040/**
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070041 * Inject devices, ports, links and end-station hosts.
Thomas Vachuska9252bc32014-10-23 02:33:25 -070042 */
43@Path("config")
Thomas Vachuskac40d4632015-04-09 16:55:03 -070044public class ConfigWebResource extends BaseResource {
Thomas Vachuska9252bc32014-10-23 02:33:25 -070045
Thomas Vachuskac40d4632015-04-09 16:55:03 -070046 private static Logger log = LoggerFactory.getLogger(ConfigWebResource.class);
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080047
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070048 /**
49 * Upload device, port, link and host data.
50 *
51 * @param input JSON blob
52 * @return 200 OK
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070053 */
Thomas Vachuska9252bc32014-10-23 02:33:25 -070054 @POST
55 @Path("topology")
56 @Consumes(MediaType.APPLICATION_JSON)
57 @Produces(MediaType.APPLICATION_JSON)
Ray Milkey9b36d812015-09-09 15:24:54 -070058 public Response topology(InputStream input) {
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080059 try {
60 ObjectMapper mapper = new ObjectMapper();
61 JsonNode cfg = mapper.readTree(input);
Thomas Vachuskac40d4632015-04-09 16:55:03 -070062 new ConfigProvider(cfg, get(DeviceService.class),
63 get(DeviceProviderRegistry.class),
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080064 get(LinkProviderRegistry.class),
65 get(HostProviderRegistry.class)).parse();
Thomas Vachuska3f06e082014-11-21 11:58:23 -080066 return Response.ok().build();
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080067 } catch (Exception e) {
68 log.error("Unable to parse topology configuration", e);
69 return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()).build();
70 }
Thomas Vachuska9252bc32014-10-23 02:33:25 -070071 }
72
73}