blob: 0c75c174d42b14ed09a695080ba2f515e855d275 [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
Jian Licc730a62016-05-10 16:36:16 -070018import com.fasterxml.jackson.databind.JsonNode;
19import com.fasterxml.jackson.databind.ObjectMapper;
Ray Milkey9b36d812015-09-09 15:24:54 -070020import org.onlab.rest.BaseResource;
21import org.onosproject.net.device.DeviceProviderRegistry;
22import org.onosproject.net.device.DeviceService;
23import org.onosproject.net.host.HostProviderRegistry;
24import org.onosproject.net.link.LinkProviderRegistry;
25import org.slf4j.Logger;
26import org.slf4j.LoggerFactory;
27
Jian Licc730a62016-05-10 16:36:16 -070028import javax.ws.rs.Consumes;
29import javax.ws.rs.POST;
30import javax.ws.rs.Path;
31import javax.ws.rs.core.MediaType;
32import javax.ws.rs.core.Response;
33import java.io.InputStream;
Thomas Vachuska9252bc32014-10-23 02:33:25 -070034
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080035import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
36
Thomas Vachuska9252bc32014-10-23 02:33:25 -070037/**
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070038 * Inject devices, ports, links and end-station hosts.
Thomas Vachuska9252bc32014-10-23 02:33:25 -070039 */
40@Path("config")
Thomas Vachuskac40d4632015-04-09 16:55:03 -070041public class ConfigWebResource extends BaseResource {
Thomas Vachuska9252bc32014-10-23 02:33:25 -070042
Thomas Vachuskac40d4632015-04-09 16:55:03 -070043 private static Logger log = LoggerFactory.getLogger(ConfigWebResource.class);
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080044
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070045 /**
46 * Upload device, port, link and host data.
47 *
48 * @param input JSON blob
49 * @return 200 OK
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070050 */
Thomas Vachuska9252bc32014-10-23 02:33:25 -070051 @POST
52 @Path("topology")
53 @Consumes(MediaType.APPLICATION_JSON)
Ray Milkey9b36d812015-09-09 15:24:54 -070054 public Response topology(InputStream input) {
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080055 try {
56 ObjectMapper mapper = new ObjectMapper();
57 JsonNode cfg = mapper.readTree(input);
Thomas Vachuskac40d4632015-04-09 16:55:03 -070058 new ConfigProvider(cfg, get(DeviceService.class),
59 get(DeviceProviderRegistry.class),
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080060 get(LinkProviderRegistry.class),
61 get(HostProviderRegistry.class)).parse();
Thomas Vachuska3f06e082014-11-21 11:58:23 -080062 return Response.ok().build();
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080063 } catch (Exception e) {
64 log.error("Unable to parse topology configuration", e);
65 return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()).build();
66 }
Thomas Vachuska9252bc32014-10-23 02:33:25 -070067 }
68
69}