blob: b0db47559d1e0eb9f6727a7767b1c0528eae41bb [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/**
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070040 * Inject devices, ports, links and end-station hosts.
Thomas Vachuska9252bc32014-10-23 02:33:25 -070041 */
42@Path("config")
Thomas Vachuskac40d4632015-04-09 16:55:03 -070043public class ConfigWebResource extends BaseResource {
Thomas Vachuska9252bc32014-10-23 02:33:25 -070044
Thomas Vachuskac40d4632015-04-09 16:55:03 -070045 private static Logger log = LoggerFactory.getLogger(ConfigWebResource.class);
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080046
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070047 /**
48 * Upload device, port, link and host data.
49 *
50 * @param input JSON blob
51 * @return 200 OK
52 * @throws IOException
53 */
Thomas Vachuska9252bc32014-10-23 02:33:25 -070054 @POST
55 @Path("topology")
56 @Consumes(MediaType.APPLICATION_JSON)
57 @Produces(MediaType.APPLICATION_JSON)
58 public Response topology(InputStream input) throws IOException {
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080059 try {
60 ObjectMapper mapper = new ObjectMapper();
61 JsonNode cfg = mapper.readTree(input);
Thomas Vachuskac40d4632015-04-09 16:55:03 -070062 new ConfigProvider(cfg, get(DeviceService.class),
63 get(DeviceProviderRegistry.class),
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080064 get(LinkProviderRegistry.class),
65 get(HostProviderRegistry.class)).parse();
Thomas Vachuska3f06e082014-11-21 11:58:23 -080066 return Response.ok().build();
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080067 } catch (Exception e) {
68 log.error("Unable to parse topology configuration", e);
69 return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()).build();
70 }
Thomas Vachuska9252bc32014-10-23 02:33:25 -070071 }
72
73}