blob: 219abbd6f23148eaaf50014226eca638dbf5b238 [file] [log] [blame]
Thomas Vachuska9252bc32014-10-23 02:33:25 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.onlab.onos.rest;
20
21import com.fasterxml.jackson.databind.JsonNode;
22import com.fasterxml.jackson.databind.ObjectMapper;
23import org.onlab.onos.net.device.DeviceProviderRegistry;
24import org.onlab.onos.net.host.HostProviderRegistry;
25import org.onlab.onos.net.link.LinkProviderRegistry;
26import org.onlab.rest.BaseResource;
27
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
37/**
38 * Resource that acts as an ancillary provider for uploading pre-configured
39 * devices, ports and links.
40 */
41@Path("config")
42public class ConfigResource extends BaseResource {
43
44 @POST
45 @Path("topology")
46 @Consumes(MediaType.APPLICATION_JSON)
47 @Produces(MediaType.APPLICATION_JSON)
48 public Response topology(InputStream input) throws IOException {
49 ObjectMapper mapper = new ObjectMapper();
50 JsonNode cfg = mapper.readTree(input);
51 new ConfigProvider(cfg, get(DeviceProviderRegistry.class),
52 get(LinkProviderRegistry.class),
53 get(HostProviderRegistry.class)).parse();
54 return Response.ok(mapper.createObjectNode().toString()).build();
55 }
56
57}