blob: af1ae9dd012b45c66747ac28ce787431f717772e [file] [log] [blame]
danielbb83ebc2015-10-29 15:13:06 +09001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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
7 *
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.
15 */
16package org.onosproject.openstackswitching.web;
17
18
19import com.fasterxml.jackson.databind.ObjectMapper;
20import com.fasterxml.jackson.databind.node.ObjectNode;
21import org.onosproject.openstackswitching.OpenstackSubnet;
22import org.onosproject.openstackswitching.OpenstackSwitchingService;
23import org.onosproject.rest.AbstractWebResource;
24import org.slf4j.Logger;
25import org.slf4j.LoggerFactory;
26
27import javax.ws.rs.Consumes;
28import javax.ws.rs.POST;
29import javax.ws.rs.Path;
30import javax.ws.rs.Produces;
31import javax.ws.rs.core.MediaType;
32import javax.ws.rs.core.Response;
33import java.io.InputStream;
34
35@Path("subnets")
36public class OpenstackSubnetWebResource extends AbstractWebResource {
37 protected static final Logger log = LoggerFactory
38 .getLogger(OpenstackSubnetWebResource.class);
39
40 private static final OpenstackSubnetCodec SUBNET_CODEC = new OpenstackSubnetCodec();
41
42 @POST
43 @Consumes(MediaType.APPLICATION_JSON)
44 @Produces(MediaType.APPLICATION_JSON)
45 public Response createSubnet(InputStream input) {
46 try {
47 ObjectMapper mapper = new ObjectMapper();
48 ObjectNode subnetNode = (ObjectNode) mapper.readTree(input);
49
50 OpenstackSubnet openstackSubnet = SUBNET_CODEC.decode(subnetNode, this);
51
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 {}",
58 e.toString());
59 return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString())
60 .build();
61 }
62 }
63
64}