blob: 746b76a321e7f52e18b9400ccdaba651cf0e0d7b [file] [log] [blame]
Thomas Vachuska9252bc32014-10-23 02:33:25 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 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
18import com.fasterxml.jackson.databind.JsonNode;
19import com.fasterxml.jackson.databind.ObjectMapper;
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.net.device.DeviceProviderRegistry;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070021import org.onosproject.net.device.DeviceService;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.net.host.HostProviderRegistry;
23import org.onosproject.net.link.LinkProviderRegistry;
Thomas Vachuska9252bc32014-10-23 02:33:25 -070024import org.onlab.rest.BaseResource;
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080025import org.slf4j.Logger;
26import org.slf4j.LoggerFactory;
Thomas Vachuska9252bc32014-10-23 02:33:25 -070027
28import javax.ws.rs.Consumes;
29import javax.ws.rs.POST;
30import javax.ws.rs.Path;
31import javax.ws.rs.Produces;
32import javax.ws.rs.core.MediaType;
33import javax.ws.rs.core.Response;
34import java.io.IOException;
35import java.io.InputStream;
36
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080037import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
38
Thomas Vachuska9252bc32014-10-23 02:33:25 -070039/**
40 * Resource that acts as an ancillary provider for uploading pre-configured
41 * devices, ports and links.
42 */
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 Vachuska9252bc32014-10-23 02:33:25 -070048 @POST
49 @Path("topology")
50 @Consumes(MediaType.APPLICATION_JSON)
51 @Produces(MediaType.APPLICATION_JSON)
52 public Response topology(InputStream input) throws IOException {
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080053 try {
54 ObjectMapper mapper = new ObjectMapper();
55 JsonNode cfg = mapper.readTree(input);
Thomas Vachuskac40d4632015-04-09 16:55:03 -070056 new ConfigProvider(cfg, get(DeviceService.class),
57 get(DeviceProviderRegistry.class),
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080058 get(LinkProviderRegistry.class),
59 get(HostProviderRegistry.class)).parse();
Thomas Vachuska3f06e082014-11-21 11:58:23 -080060 return Response.ok().build();
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080061 } catch (Exception e) {
62 log.error("Unable to parse topology configuration", e);
63 return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()).build();
64 }
Thomas Vachuska9252bc32014-10-23 02:33:25 -070065 }
66
67}