blob: 34d5814e2c418d45a7ee872a598567b58a696e8c [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;
24
25import javax.ws.rs.Consumes;
26import javax.ws.rs.POST;
27import javax.ws.rs.Path;
28import javax.ws.rs.Produces;
29import javax.ws.rs.core.MediaType;
30import javax.ws.rs.core.Response;
31import java.io.IOException;
32import java.io.InputStream;
33
34/**
35 * Resource that acts as an ancillary provider for uploading pre-configured
36 * devices, ports and links.
37 */
38@Path("config")
39public class ConfigResource extends BaseResource {
40
41 @POST
42 @Path("topology")
43 @Consumes(MediaType.APPLICATION_JSON)
44 @Produces(MediaType.APPLICATION_JSON)
45 public Response topology(InputStream input) throws IOException {
46 ObjectMapper mapper = new ObjectMapper();
47 JsonNode cfg = mapper.readTree(input);
48 new ConfigProvider(cfg, get(DeviceProviderRegistry.class),
49 get(LinkProviderRegistry.class),
50 get(HostProviderRegistry.class)).parse();
51 return Response.ok(mapper.createObjectNode().toString()).build();
52 }
53
54}