2 * Copyright 2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onosproject.openstackswitching.web;
19 import com.fasterxml.jackson.databind.ObjectMapper;
20 import com.fasterxml.jackson.databind.node.ObjectNode;
21 import org.onosproject.openstackswitching.OpenstackSubnet;
22 import org.onosproject.openstackswitching.OpenstackSwitchingService;
23 import org.onosproject.rest.AbstractWebResource;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 import javax.ws.rs.Consumes;
28 import javax.ws.rs.POST;
29 import javax.ws.rs.Path;
30 import javax.ws.rs.Produces;
31 import javax.ws.rs.core.MediaType;
32 import javax.ws.rs.core.Response;
33 import java.io.InputStream;
36 public class OpenstackSubnetWebResource extends AbstractWebResource {
37 protected static final Logger log = LoggerFactory
38 .getLogger(OpenstackSubnetWebResource.class);
40 private static final OpenstackSubnetCodec SUBNET_CODEC = new OpenstackSubnetCodec();
43 @Consumes(MediaType.APPLICATION_JSON)
44 @Produces(MediaType.APPLICATION_JSON)
45 public Response createSubnet(InputStream input) {
47 ObjectMapper mapper = new ObjectMapper();
48 ObjectNode subnetNode = (ObjectNode) mapper.readTree(input);
50 OpenstackSubnet openstackSubnet = SUBNET_CODEC.decode(subnetNode, this);
52 OpenstackSwitchingService switchingService = get(OpenstackSwitchingService.class);
53 switchingService.createSubnet(openstackSubnet);
54 log.info("REST API subnets is called with {}", subnetNode.toString());
55 return Response.status(Response.Status.OK).build();
56 } catch (Exception e) {
57 log.error("Creates VirtualSubnet failed because of exception {}",
59 return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString())