remove irrelevant old JavaDoc from a long bygone era in northbound.api
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronNetworksNorthbound.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.codehaus.enunciate.jaxrs.TypeHint;
30 import org.opendaylight.neutron.spi.INeutronNetworkCRUD;
31 import org.opendaylight.neutron.spi.NeutronNetwork;
32
33 /**
34  * Neutron Northbound REST APIs for Network.
35  */
36 @Path("/networks")
37 public final class NeutronNetworksNorthbound
38         extends AbstractNeutronNorthbound<NeutronNetwork, NeutronNetworkRequest, INeutronNetworkCRUD> {
39
40     private static final String RESOURCE_NAME = "Network";
41
42     @Context
43     UriInfo uriInfo;
44
45     @Override
46     protected String getResourceName() {
47         return RESOURCE_NAME;
48     }
49
50     /**
51      * Returns a list of all Networks.
52      */
53     @GET
54     @Produces({ MediaType.APPLICATION_JSON })
55     //@TypeHint(OpenStackNetworks.class)
56     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
57             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
58             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
59             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
60     public Response listNetworks(
61             // return fields
62             @QueryParam("fields") List<String> fields,
63             // note: openstack isn't clear about filtering on lists, so we aren't handling them
64             @QueryParam("id") String queryID,
65             @QueryParam("name") String queryName,
66             @QueryParam("admin_state_up") String queryAdminStateUp,
67             @QueryParam("status") String queryStatus,
68             @QueryParam("shared") String queryShared,
69             @QueryParam("tenant_id") String queryTenantID,
70             @QueryParam("router_external") String queryRouterExternal,
71             @QueryParam("provider_network_type") String queryProviderNetworkType,
72             @QueryParam("provider_physical_network") String queryProviderPhysicalNetwork,
73             @QueryParam("provider_segmentation_id") String queryProviderSegmentationID,
74             @QueryParam("qos_policy_id") String queryQosPolicyId,
75             // linkTitle
76             @QueryParam("limit") Integer limit,
77             @QueryParam("marker") String marker,
78             @DefaultValue("false") @QueryParam("page_reverse") Boolean pageReverse
79     // sorting not supported
80     ) {
81         INeutronNetworkCRUD networkInterface = getNeutronCRUD();
82         List<NeutronNetwork> allNetworks = networkInterface.getAll();
83         List<NeutronNetwork> ans = new ArrayList<>();
84         for (NeutronNetwork network : allNetworks) {
85             //match filters: TODO provider extension
86             Boolean adminStateUp = queryAdminStateUp != null ? Boolean.valueOf(queryAdminStateUp) : null;
87             Boolean shared = queryShared != null ? Boolean.valueOf(queryShared) : null;
88             Boolean routerExternal = queryRouterExternal != null ? Boolean.valueOf(queryRouterExternal) : null;
89             if ((queryID == null || queryID.equals(network.getID()))
90                     && (queryName == null || queryName.equals(network.getName()))
91                     && (adminStateUp == null || adminStateUp.booleanValue() == network.isAdminStateUp())
92                     && (queryStatus == null || queryStatus.equals(network.getStatus()))
93                     && (shared == null || shared.booleanValue() == network.isShared())
94                     && (routerExternal == null || routerExternal.booleanValue() == network.isRouterExternal())
95                     && (queryTenantID == null || queryTenantID.equals(network.getTenantID()))
96                     && (queryQosPolicyId == null || queryQosPolicyId.equals(network.getQosPolicyId()))) {
97                 if (fields.size() > 0) {
98                     ans.add(network.extractFields(fields));
99                 } else {
100                     ans.add(network);
101                 }
102             }
103         }
104
105         if (limit != null && ans.size() > 1) {
106             // Return a paginated request
107             NeutronNetworkRequest request = (NeutronNetworkRequest) PaginatedRequestFactory.createRequest(limit, marker,
108                     pageReverse, uriInfo, ans, NeutronNetwork.class);
109             return Response.status(HttpURLConnection.HTTP_OK).entity(request).build();
110         }
111
112         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronNetworkRequest(ans)).build();
113
114     }
115
116     /**
117      * Returns a specific Network.
118      */
119     @Path("{netUUID}")
120     @GET
121     @Produces({ MediaType.APPLICATION_JSON })
122     //@TypeHint(OpenStackNetworks.class)
123     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
124             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
125             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
126             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
127             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
128     public Response showNetwork(@PathParam("netUUID") String netUUID,
129             // return fields
130             @QueryParam("fields") List<String> fields) {
131         return show(netUUID, fields);
132     }
133
134     /**
135      * Creates new Networks.
136      */
137     @POST
138     @Produces({ MediaType.APPLICATION_JSON })
139     @Consumes({ MediaType.APPLICATION_JSON })
140     @TypeHint(NeutronNetwork.class)
141     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
142             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
143     public Response createNetworks(final NeutronNetworkRequest input) {
144         return create(input);
145     }
146
147     @Override
148     protected void updateDelta(String uuid, NeutronNetwork delta, NeutronNetwork original) {
149         /*
150          *  note: what we get appears to not be a delta but
151          * rather an incomplete updated object.  So we need to set
152          * the ID to complete the object and then send that down
153          * for folks to check
154          */
155
156         delta.setID(uuid);
157         delta.setTenantID(original.getTenantID());
158     }
159
160     /**
161      * Updates a Network.
162      */
163     @Path("{netUUID}")
164     @PUT
165     @Produces({ MediaType.APPLICATION_JSON })
166     @Consumes({ MediaType.APPLICATION_JSON })
167     //@TypeHint(OpenStackNetworks.class)
168     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
169             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
170             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
171     public Response updateNetwork(@PathParam("netUUID") String netUUID, final NeutronNetworkRequest input) {
172         return update(netUUID, input);
173     }
174
175     /**
176      * Deletes a Network.
177      */
178     @Path("{netUUID}")
179     @DELETE
180     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
181             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
182             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
183     public Response deleteNetwork(@PathParam("netUUID") String netUUID) {
184         return delete(netUUID);
185     }
186 }