remove irrelevant old JavaDoc from a long bygone era in northbound.api
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronFloatingIpsNorthbound.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.GET;
16 import javax.ws.rs.POST;
17 import javax.ws.rs.PUT;
18 import javax.ws.rs.Path;
19 import javax.ws.rs.PathParam;
20 import javax.ws.rs.Produces;
21 import javax.ws.rs.QueryParam;
22 import javax.ws.rs.core.MediaType;
23 import javax.ws.rs.core.Response;
24 import org.codehaus.enunciate.jaxrs.ResponseCode;
25 import org.codehaus.enunciate.jaxrs.StatusCodes;
26 import org.opendaylight.neutron.spi.INeutronFloatingIpCRUD;
27 import org.opendaylight.neutron.spi.NeutronFloatingIp;
28
29 /**
30  * Neutron Northbound REST APIs for managing Neutron Floating IPs.
31  */
32 @Path("/floatingips")
33 public final class NeutronFloatingIpsNorthbound
34         extends AbstractNeutronNorthbound<NeutronFloatingIp, NeutronFloatingIpRequest, INeutronFloatingIpCRUD> {
35
36     private static final String RESOURCE_NAME = "Floating IP";
37
38     @Override
39     protected String getResourceName() {
40         return RESOURCE_NAME;
41     }
42
43     /**
44      * Returns a list of all FloatingIps.
45      */
46     @GET
47     @Produces({ MediaType.APPLICATION_JSON })
48     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
49             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
50             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
51             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
52     public Response listFloatingIps(
53             // return fields
54             @QueryParam("fields") List<String> fields,
55             // note: openstack isn't clear about filtering on lists, so we aren't handling them
56             @QueryParam("id") String queryID,
57             @QueryParam("floating_network_id") String queryFloatingNetworkId,
58             @QueryParam("port_id") String queryPortId,
59             @QueryParam("fixed_ip_address") String queryFixedIpAddress,
60             @QueryParam("floating_ip_address") String queryFloatingIpAddress,
61             @QueryParam("tenant_id") String queryTenantID,
62             @QueryParam("router_id") String queryRouterID,
63             @QueryParam("status") String queryStatus,
64             // pagination
65             @QueryParam("limit") String limit,
66             @QueryParam("marker") String marker,
67             @QueryParam("page_reverse") String pageReverse
68     // sorting not supported
69     ) {
70         INeutronFloatingIpCRUD floatingIpInterface = getNeutronCRUD();
71         List<NeutronFloatingIp> allFloatingIps = floatingIpInterface.getAll();
72         List<NeutronFloatingIp> ans = new ArrayList<>();
73         for (NeutronFloatingIp floatingIp : allFloatingIps) {
74             //match filters: TODO provider extension and router extension
75             if ((queryID == null || queryID.equals(floatingIp.getID()))
76                     && (queryFloatingNetworkId == null
77                         || queryFloatingNetworkId.equals(floatingIp.getFloatingNetworkUUID()))
78                     && (queryPortId == null || queryPortId.equals(floatingIp.getPortUUID()))
79                     && (queryFixedIpAddress == null || queryFixedIpAddress.equals(floatingIp.getFixedIpAddress()))
80                     && (queryFloatingIpAddress == null
81                         || queryFloatingIpAddress.equals(floatingIp.getFloatingIpAddress()))
82                     && (queryStatus == null || queryStatus.equals(floatingIp.getStatus()))
83                     && (queryRouterID == null || queryRouterID.equals(floatingIp.getRouterUUID()))
84                     && (queryTenantID == null || queryTenantID.equals(floatingIp.getTenantID()))) {
85                 if (fields.size() > 0) {
86                     ans.add(floatingIp.extractFields(fields));
87                 } else {
88                     ans.add(floatingIp);
89                 }
90             }
91         }
92         //TODO: apply pagination to results
93         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronFloatingIpRequest(ans)).build();
94     }
95
96     /**
97      * Returns a specific FloatingIp.
98      */
99     @Path("{floatingipUUID}")
100     @GET
101     @Produces({ MediaType.APPLICATION_JSON })
102     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
103             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
104             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
105             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
106             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
107     public Response showFloatingIp(@PathParam("floatingipUUID") String floatingipUUID,
108             // return fields
109             @QueryParam("fields") List<String> fields) {
110         return show(floatingipUUID, fields);
111     }
112
113     /**
114      * Creates new FloatingIps.
115      */
116     @POST
117     @Produces({ MediaType.APPLICATION_JSON })
118     @Consumes({ MediaType.APPLICATION_JSON })
119     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
120             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
121     public Response createFloatingIps(final NeutronFloatingIpRequest input) {
122         return create(input);
123     }
124
125     /**
126      * Updates a FloatingIp.
127      */
128     @Path("{floatingipUUID}")
129     @PUT
130     @Produces({ MediaType.APPLICATION_JSON })
131     @Consumes({ MediaType.APPLICATION_JSON })
132     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
133             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
134             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
135     public Response updateFloatingIp(@PathParam("floatingipUUID") String floatingipUUID,
136             NeutronFloatingIpRequest input) {
137         return update(floatingipUUID, input);
138     }
139
140     /**
141      * Deletes a FloatingIp.
142      */
143     @Path("{floatingipUUID}")
144     @DELETE
145     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
146             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
147             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
148     public Response deleteFloatingIp(@PathParam("floatingipUUID") String floatingipUUID) {
149         return delete(floatingipUUID);
150     }
151 }