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