remove irrelevant old JavaDoc from a long bygone era in northbound.api
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronTapFlowNorthbound.java
1 /*
2  * Copyright (c) 2017 Intel, Corp. 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.INeutronTapFlowCRUD;
27 import org.opendaylight.neutron.spi.NeutronTapFlow;
28
29 @Path("/tap/flows")
30 public final class NeutronTapFlowNorthbound
31         extends AbstractNeutronNorthbound<NeutronTapFlow, NeutronTapFlowRequest, INeutronTapFlowCRUD> {
32
33     private static final String RESOURCE_NAME = "Tap Flow";
34
35     @Override
36     protected String getResourceName() {
37         return RESOURCE_NAME;
38     }
39
40     /**
41      * Returns a list of all Tap Flows.
42      */
43     @GET
44     @Produces({ MediaType.APPLICATION_JSON })
45     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
46             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
47             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
48             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
49     public Response listGroups(
50             // return fields
51             @QueryParam("fields") List<String> fields,
52             // OpenStack Tap Flow attributes
53             @QueryParam("id") String queryTapFlowUUID,
54             @QueryParam("tenant_id") String queryTapFlowTenantID,
55             @QueryParam("name") String queryTapFlowName,
56             @QueryParam("source_port") String queryTapFlowSourcePort,
57             @QueryParam("tap_service_id") String queryTapServiceID,
58             @QueryParam("direction") String queryTapFlowDirection,
59             // pagination
60             @QueryParam("limit") String limit,
61             @QueryParam("marker") String marker,
62             @QueryParam("page_reverse") String pageReverse) {
63
64         INeutronTapFlowCRUD tapFlowInterface = getNeutronCRUD();
65         List<NeutronTapFlow> ans = new ArrayList<>();
66         for (NeutronTapFlow nsg : tapFlowInterface.getAll()) {
67             if ((queryTapFlowUUID == null || queryTapFlowUUID.equals(nsg.getID()))
68                     && (queryTapFlowTenantID == null || queryTapFlowTenantID.equals(nsg.getTenantID()))
69                     && (queryTapFlowName == null || queryTapFlowName.equals(nsg.getName()))
70                     && (queryTapServiceID == null || queryTapServiceID.equals(nsg.getTapFlowServiceID()))
71                     && (queryTapFlowDirection == null || queryTapFlowDirection.equals(nsg.getTapFlowDirection()))
72                     && (queryTapFlowSourcePort == null
73                         || queryTapFlowSourcePort.equals(nsg.getTapFlowSourcePort()))) {
74                 if (fields.size() > 0) {
75                     ans.add(nsg.extractFields(fields));
76                 } else {
77                     ans.add(nsg);
78                 }
79             }
80         }
81         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronTapFlowRequest(ans)).build();
82     }
83
84     /**
85      * Creates new Tap Flow.
86      */
87     @Path("{tapServiceUUID}/flows")
88     @POST
89     @Produces({ MediaType.APPLICATION_JSON })
90     @Consumes({ MediaType.APPLICATION_JSON })
91     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
92             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
93     public Response createTapFlow(@PathParam("tapServiceUUID") String tapServiceUUID,
94                                   final NeutronTapFlowRequest input) {
95
96         INeutronTapFlowCRUD tapFlowInterface = getNeutronCRUD();
97
98         if (input.isSingleton()) {
99             NeutronTapFlow singleton = input.getSingleton();
100             singleton.setTapFlowServiceID(tapServiceUUID);
101
102             tapFlowInterface.addTapFlow(singleton);
103         } else {
104             throw new BadRequestException("Only Singleton tapFlow creation supported");
105         }
106
107         return Response.status(HttpURLConnection.HTTP_CREATED).entity(input).build();
108     }
109
110     /**
111      * Returns a specific Tap Flow.
112      */
113     @Path("{tapServiceUUID}/flows/{tapFlowUUID}")
114     @GET
115     @Produces({ MediaType.APPLICATION_JSON })
116     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
117             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
118             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
119             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
120             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
121     public Response showTapFlow(@PathParam("tapServiceUUID") String tapServiceUUID,
122                                 @PathParam("tapFlowUUID") String tapFlowUUID,
123                                 @QueryParam("fields") List<String> fields) {
124
125         INeutronTapFlowCRUD tapFlowInterface = getNeutronCRUD();
126         if (!tapFlowInterface.tapFlowExists(tapServiceUUID, tapFlowUUID)) {
127             throw new ResourceNotFoundException("Specified UUID does not Exist");
128         }
129
130         NeutronTapFlow tapFlow = tapFlowInterface.getTapFlow(tapServiceUUID, tapFlowUUID);
131         if (fields.size() > 0) {
132             return Response.status(HttpURLConnection.HTTP_OK)
133                     .entity(new NeutronTapFlowRequest(tapFlow.extractFields(fields))).build();
134         } else {
135             return Response.status(HttpURLConnection.HTTP_OK)
136                     .entity(new NeutronTapFlowRequest(tapFlow)).build();
137         }
138     }
139
140     /**
141      * Updates a Tap Flow.
142      */
143     @Path("{tapServiceUUID}/flows/{tapFlowUUID}")
144     @PUT
145     @Produces({ MediaType.APPLICATION_JSON })
146     @Consumes({ MediaType.APPLICATION_JSON })
147     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
148             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
149             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
150     public Response updateTapFlow(@PathParam("tapServiceUUID") String tapServiceUUID,
151                                   @PathParam("tapFlowUUID") String tapFlowUUID,
152                                   final NeutronTapFlowRequest input) {
153
154         INeutronTapFlowCRUD tapFlowInterface = getNeutronCRUD();
155
156         if (!tapFlowInterface.tapFlowExists(tapServiceUUID, tapFlowUUID)) {
157             throw new ResourceNotFoundException("Specified UUID does not Exist");
158         }
159
160         NeutronTapFlow singleton = input.getSingleton();
161         singleton.setTapFlowServiceID(tapServiceUUID);
162         tapFlowInterface.updateTapFlow(singleton);
163
164         return Response.status(HttpURLConnection.HTTP_OK).entity(input).build();
165     }
166
167     /**
168      * Deletes a Tap Flow.
169      */
170     @Path("{tapServiceUUID}/flows/{tapFlowUUID}")
171     @DELETE
172     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
173             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
174             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
175     public Response deleteTapFlow(@PathParam("tapServiceUUID") String tapServiceUUID,
176                                   @PathParam("tapFlowUUID") String tapFlowUUID) {
177
178         INeutronTapFlowCRUD tapFlowInterface = getNeutronCRUD();
179
180         if (!tapFlowInterface.tapFlowExists(tapServiceUUID, tapFlowUUID)) {
181             throw new ResourceNotFoundException("Specified UUID does not Exist");
182         }
183
184         tapFlowInterface.deleteTapFlow(tapServiceUUID, tapFlowUUID);
185         return Response.status(HttpURLConnection.HTTP_NO_CONTENT).build();
186     }
187 }