2 * Copyright (c) 2017 Intel, Corp. and others. All rights reserved.
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
8 package org.opendaylight.neutron.northbound.api;
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;
30 public final class NeutronTapFlowNorthbound
31 extends AbstractNeutronNorthbound<NeutronTapFlow, NeutronTapFlowRequest, INeutronTapFlowCRUD> {
33 private static final String RESOURCE_NAME = "Tap Flow";
36 protected String getResourceName() {
41 * Returns a list of all Tap Flows.
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(
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,
60 @QueryParam("limit") String limit,
61 @QueryParam("marker") String marker,
62 @QueryParam("page_reverse") String pageReverse) {
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));
81 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronTapFlowRequest(ans)).build();
85 * Creates new Tap Flow.
87 @Path("{tapServiceUUID}/flows")
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) {
96 INeutronTapFlowCRUD tapFlowInterface = getNeutronCRUD();
98 if (input.isSingleton()) {
99 NeutronTapFlow singleton = input.getSingleton();
100 singleton.setTapFlowServiceID(tapServiceUUID);
102 tapFlowInterface.addTapFlow(singleton);
104 throw new BadRequestException("Only Singleton tapFlow creation supported");
107 return Response.status(HttpURLConnection.HTTP_CREATED).entity(input).build();
111 * Returns a specific Tap Flow.
113 @Path("{tapServiceUUID}/flows/{tapFlowUUID}")
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) {
125 INeutronTapFlowCRUD tapFlowInterface = getNeutronCRUD();
126 if (!tapFlowInterface.tapFlowExists(tapServiceUUID, tapFlowUUID)) {
127 throw new ResourceNotFoundException("Specified UUID does not Exist");
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();
135 return Response.status(HttpURLConnection.HTTP_OK)
136 .entity(new NeutronTapFlowRequest(tapFlow)).build();
141 * Updates a Tap Flow.
143 @Path("{tapServiceUUID}/flows/{tapFlowUUID}")
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) {
154 INeutronTapFlowCRUD tapFlowInterface = getNeutronCRUD();
156 if (!tapFlowInterface.tapFlowExists(tapServiceUUID, tapFlowUUID)) {
157 throw new ResourceNotFoundException("Specified UUID does not Exist");
160 NeutronTapFlow singleton = input.getSingleton();
161 singleton.setTapFlowServiceID(tapServiceUUID);
162 tapFlowInterface.updateTapFlow(singleton);
164 return Response.status(HttpURLConnection.HTTP_OK).entity(input).build();
168 * Deletes a Tap Flow.
170 @Path("{tapServiceUUID}/flows/{tapFlowUUID}")
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) {
178 INeutronTapFlowCRUD tapFlowInterface = getNeutronCRUD();
180 if (!tapFlowInterface.tapFlowExists(tapServiceUUID, tapFlowUUID)) {
181 throw new ResourceNotFoundException("Specified UUID does not Exist");
184 tapFlowInterface.deleteTapFlow(tapServiceUUID, tapFlowUUID);
185 return Response.status(HttpURLConnection.HTTP_NO_CONTENT).build();