Thomas Vachuska | 9252bc3 | 2014-10-23 02:33:25 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 9252bc3 | 2014-10-23 02:33:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * 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 Vachuska | 9252bc3 | 2014-10-23 02:33:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * 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 Vachuska | 9252bc3 | 2014-10-23 02:33:25 -0700 | [diff] [blame] | 15 | */ |
Jonathan Hart | 9bb32ab | 2015-05-05 18:17:31 -0700 | [diff] [blame] | 16 | package org.onosproject.rest.resources; |
Thomas Vachuska | 9252bc3 | 2014-10-23 02:33:25 -0700 | [diff] [blame] | 17 | |
Ray Milkey | 9b36d81 | 2015-09-09 15:24:54 -0700 | [diff] [blame] | 18 | import java.io.InputStream; |
Thomas Vachuska | 9252bc3 | 2014-10-23 02:33:25 -0700 | [diff] [blame] | 19 | |
| 20 | import javax.ws.rs.Consumes; |
| 21 | import javax.ws.rs.POST; |
| 22 | import javax.ws.rs.Path; |
| 23 | import javax.ws.rs.Produces; |
| 24 | import javax.ws.rs.core.MediaType; |
| 25 | import javax.ws.rs.core.Response; |
Ray Milkey | 9b36d81 | 2015-09-09 15:24:54 -0700 | [diff] [blame] | 26 | |
| 27 | import org.onlab.rest.BaseResource; |
| 28 | import org.onosproject.net.device.DeviceProviderRegistry; |
| 29 | import org.onosproject.net.device.DeviceService; |
| 30 | import org.onosproject.net.host.HostProviderRegistry; |
| 31 | import org.onosproject.net.link.LinkProviderRegistry; |
| 32 | import org.slf4j.Logger; |
| 33 | import org.slf4j.LoggerFactory; |
| 34 | |
| 35 | import com.fasterxml.jackson.databind.JsonNode; |
| 36 | import com.fasterxml.jackson.databind.ObjectMapper; |
Thomas Vachuska | 9252bc3 | 2014-10-23 02:33:25 -0700 | [diff] [blame] | 37 | |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 38 | import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; |
| 39 | |
Thomas Vachuska | 9252bc3 | 2014-10-23 02:33:25 -0700 | [diff] [blame] | 40 | /** |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 41 | * Inject devices, ports, links and end-station hosts. |
Thomas Vachuska | 9252bc3 | 2014-10-23 02:33:25 -0700 | [diff] [blame] | 42 | */ |
| 43 | @Path("config") |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 44 | public class ConfigWebResource extends BaseResource { |
Thomas Vachuska | 9252bc3 | 2014-10-23 02:33:25 -0700 | [diff] [blame] | 45 | |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 46 | private static Logger log = LoggerFactory.getLogger(ConfigWebResource.class); |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 47 | |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 48 | /** |
| 49 | * Upload device, port, link and host data. |
| 50 | * |
| 51 | * @param input JSON blob |
| 52 | * @return 200 OK |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 53 | */ |
Thomas Vachuska | 9252bc3 | 2014-10-23 02:33:25 -0700 | [diff] [blame] | 54 | @POST |
| 55 | @Path("topology") |
| 56 | @Consumes(MediaType.APPLICATION_JSON) |
| 57 | @Produces(MediaType.APPLICATION_JSON) |
Ray Milkey | 9b36d81 | 2015-09-09 15:24:54 -0700 | [diff] [blame] | 58 | public Response topology(InputStream input) { |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 59 | try { |
| 60 | ObjectMapper mapper = new ObjectMapper(); |
| 61 | JsonNode cfg = mapper.readTree(input); |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 62 | new ConfigProvider(cfg, get(DeviceService.class), |
| 63 | get(DeviceProviderRegistry.class), |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 64 | get(LinkProviderRegistry.class), |
| 65 | get(HostProviderRegistry.class)).parse(); |
Thomas Vachuska | 3f06e08 | 2014-11-21 11:58:23 -0800 | [diff] [blame] | 66 | return Response.ok().build(); |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 67 | } 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 Vachuska | 9252bc3 | 2014-10-23 02:33:25 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | } |