remove irrelevant old JavaDoc from a long bygone era in northbound.api
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronSubnetsNorthbound.java
1 /*
2  * Copyright (c) 2013, 2015 IBM Corporation and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.neutron.northbound.api;
9
10 import java.net.HttpURLConnection;
11 import java.util.ArrayList;
12 import java.util.List;
13 import javax.ws.rs.Consumes;
14 import javax.ws.rs.DELETE;
15 import javax.ws.rs.DefaultValue;
16 import javax.ws.rs.GET;
17 import javax.ws.rs.POST;
18 import javax.ws.rs.PUT;
19 import javax.ws.rs.Path;
20 import javax.ws.rs.PathParam;
21 import javax.ws.rs.Produces;
22 import javax.ws.rs.QueryParam;
23 import javax.ws.rs.core.Context;
24 import javax.ws.rs.core.MediaType;
25 import javax.ws.rs.core.Response;
26 import javax.ws.rs.core.UriInfo;
27 import org.codehaus.enunciate.jaxrs.ResponseCode;
28 import org.codehaus.enunciate.jaxrs.StatusCodes;
29 import org.opendaylight.neutron.spi.INeutronSubnetCRUD;
30 import org.opendaylight.neutron.spi.NeutronSubnet;
31
32 /**
33  * Neutron Northbound REST APIs for Subnets.<br>
34  */
35 @Path("/subnets")
36 public final class NeutronSubnetsNorthbound
37         extends AbstractNeutronNorthbound<NeutronSubnet, NeutronSubnetRequest, INeutronSubnetCRUD> {
38
39     private static final String RESOURCE_NAME = "Subnet";
40
41     @Override
42     protected String getResourceName() {
43         return RESOURCE_NAME;
44     }
45
46     @Context
47     UriInfo uriInfo;
48
49     /**
50      * Returns a list of all Subnets.
51      */
52     @GET
53     @Produces({ MediaType.APPLICATION_JSON })
54     //@TypeHint(OpenStackSubnets.class)
55     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
56             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
57             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
58             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
59     public Response listSubnets(
60             // return fields
61             @QueryParam("fields") List<String> fields,
62             // note: openstack isn't clear about filtering on lists, so we aren't handling them
63             @QueryParam("id") String queryID,
64             @QueryParam("network_id") String queryNetworkID,
65             @QueryParam("name") String queryName,
66             @QueryParam("ip_version") Integer queryIPVersion,
67             @QueryParam("cidr") String queryCIDR,
68             @QueryParam("gateway_ip") String queryGatewayIp,
69             @QueryParam("enable_dhcp") Boolean queryEnableDHCP,
70             @QueryParam("tenant_id") String queryTenantID,
71             @QueryParam("ipv6_address_mode") String queryIpV6AddressMode,
72             @QueryParam("ipv6_ra_mode") String queryIpV6RaMode,
73             // linkTitle
74             @QueryParam("limit") Integer limit,
75             @QueryParam("marker") String marker,
76             @DefaultValue("false") @QueryParam("page_reverse") Boolean pageReverse
77     // sorting not supported
78     ) {
79         INeutronSubnetCRUD subnetInterface = getNeutronCRUD();
80         List<NeutronSubnet> allSubnets = subnetInterface.getAll();
81         List<NeutronSubnet> ans = new ArrayList<>();
82         for (NeutronSubnet subnet : allSubnets) {
83             if ((queryID == null || queryID.equals(subnet.getID()))
84                     && (queryNetworkID == null || queryNetworkID.equals(subnet.getNetworkUUID()))
85                     && (queryName == null || queryName.equals(subnet.getName()))
86                     && (queryIPVersion == null || queryIPVersion.equals(subnet.getIpVersion()))
87                     && (queryCIDR == null || queryCIDR.equals(subnet.getCidr()))
88                     && (queryGatewayIp == null || queryGatewayIp.equals(subnet.getGatewayIp()))
89                     && (queryEnableDHCP == null || queryEnableDHCP.equals(subnet.getEnableDHCP()))
90                     && (queryTenantID == null || queryTenantID.equals(subnet.getTenantID()))
91                     && (queryIpV6AddressMode == null || queryIpV6AddressMode.equals(subnet.getIpV6AddressMode()))
92                     && (queryIpV6RaMode == null || queryIpV6RaMode.equals(subnet.getIpV6RaMode()))) {
93                 if (fields.size() > 0) {
94                     ans.add(subnet.extractFields(fields));
95                 } else {
96                     ans.add(subnet);
97                 }
98             }
99         }
100
101         if (limit != null && ans.size() > 1) {
102             // Return a paginated request
103             NeutronSubnetRequest request = (NeutronSubnetRequest) PaginatedRequestFactory.createRequest(limit, marker,
104                     pageReverse, uriInfo, ans, NeutronSubnet.class);
105             return Response.status(HttpURLConnection.HTTP_OK).entity(request).build();
106         }
107
108         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronSubnetRequest(ans)).build();
109     }
110
111     /**
112      * Returns a specific Subnet.
113      */
114     @Path("{subnetUUID}")
115     @GET
116     @Produces({ MediaType.APPLICATION_JSON })
117     //@TypeHint(OpenStackSubnets.class)
118     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
119             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
120             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
121             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
122             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
123     public Response showSubnet(@PathParam("subnetUUID") String subnetUUID,
124             // return fields
125             @QueryParam("fields") List<String> fields) {
126         return show(subnetUUID, fields);
127     }
128
129     /**
130      * Creates new Subnets.
131      */
132     @POST
133     @Produces({ MediaType.APPLICATION_JSON })
134     @Consumes({ MediaType.APPLICATION_JSON })
135     //@TypeHint(OpenStackSubnets.class)
136     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
137             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
138     public Response createSubnets(final NeutronSubnetRequest input) {
139         return create(input);
140     }
141
142     @Override
143     protected void updateDelta(String uuid, NeutronSubnet delta, NeutronSubnet original) {
144         /*
145          * note: what we get appears to not be a delta, but rather a
146          * complete updated object.  So, that needs to be sent down to
147          * folks to check
148          */
149         delta.setID(uuid);
150         delta.setNetworkUUID(original.getNetworkUUID());
151         delta.setTenantID(original.getTenantID());
152         delta.setIpVersion(original.getIpVersion());
153         delta.setCidr(original.getCidr());
154     }
155
156     /**
157      * Updates a Subnet.
158      */
159     @Path("{subnetUUID}")
160     @PUT
161     @Produces({ MediaType.APPLICATION_JSON })
162     @Consumes({ MediaType.APPLICATION_JSON })
163     //@TypeHint(OpenStackSubnets.class)
164     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
165             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
166             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
167     public Response updateSubnet(@PathParam("subnetUUID") String subnetUUID, final NeutronSubnetRequest input) {
168         return update(subnetUUID, input);
169     }
170
171     /**
172      * Deletes a Subnet.
173      */
174     @Path("{subnetUUID}")
175     @DELETE
176     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
177             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
178             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
179     public Response deleteSubnet(@PathParam("subnetUUID") String subnetUUID) {
180         return delete(subnetUUID);
181     }
182 }