Thomas Vachuska | 9252bc3 | 2014-10-23 02:33:25 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 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 | */ |
| 16 | package org.onlab.onos.rest; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.JsonNode; |
| 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 20 | import org.onlab.onos.net.device.DeviceProviderRegistry; |
| 21 | import org.onlab.onos.net.host.HostProviderRegistry; |
| 22 | import org.onlab.onos.net.link.LinkProviderRegistry; |
| 23 | import org.onlab.rest.BaseResource; |
| 24 | |
| 25 | import javax.ws.rs.Consumes; |
| 26 | import javax.ws.rs.POST; |
| 27 | import javax.ws.rs.Path; |
| 28 | import javax.ws.rs.Produces; |
| 29 | import javax.ws.rs.core.MediaType; |
| 30 | import javax.ws.rs.core.Response; |
| 31 | import java.io.IOException; |
| 32 | import 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") |
| 39 | public 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 | } |