blob: 04e7836453a3cae27c3b96b1fd230329fca172c3 [file] [log] [blame]
Thomas Vachuska9252bc32014-10-23 02:33:25 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 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 */
16package org.onlab.onos.rest;
17
18import com.fasterxml.jackson.databind.JsonNode;
19import com.fasterxml.jackson.databind.ObjectMapper;
20import org.onlab.onos.net.device.DeviceProviderRegistry;
21import org.onlab.onos.net.host.HostProviderRegistry;
22import org.onlab.onos.net.link.LinkProviderRegistry;
23import org.onlab.rest.BaseResource;
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080024import org.slf4j.Logger;
25import org.slf4j.LoggerFactory;
Thomas Vachuska9252bc32014-10-23 02:33:25 -070026
27import javax.ws.rs.Consumes;
28import javax.ws.rs.POST;
29import javax.ws.rs.Path;
30import javax.ws.rs.Produces;
31import javax.ws.rs.core.MediaType;
32import javax.ws.rs.core.Response;
33import java.io.IOException;
34import java.io.InputStream;
35
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080036import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
37
Thomas Vachuska9252bc32014-10-23 02:33:25 -070038/**
39 * Resource that acts as an ancillary provider for uploading pre-configured
40 * devices, ports and links.
41 */
42@Path("config")
43public class ConfigResource extends BaseResource {
44
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080045 private static Logger log = LoggerFactory.getLogger(ConfigResource.class);
46
Thomas Vachuska9252bc32014-10-23 02:33:25 -070047 @POST
48 @Path("topology")
49 @Consumes(MediaType.APPLICATION_JSON)
50 @Produces(MediaType.APPLICATION_JSON)
51 public Response topology(InputStream input) throws IOException {
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080052 try {
53 ObjectMapper mapper = new ObjectMapper();
54 JsonNode cfg = mapper.readTree(input);
55 new ConfigProvider(cfg, get(DeviceProviderRegistry.class),
56 get(LinkProviderRegistry.class),
57 get(HostProviderRegistry.class)).parse();
Thomas Vachuska3f06e082014-11-21 11:58:23 -080058 return Response.ok().build();
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080059 } catch (Exception e) {
60 log.error("Unable to parse topology configuration", e);
61 return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()).build();
62 }
Thomas Vachuska9252bc32014-10-23 02:33:25 -070063 }
64
65}