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
9 package org.opendaylight.neutron.northbound.api;
11 import java.net.HttpURLConnection;
12 import java.util.ArrayList;
13 import java.util.List;
14 import javax.ws.rs.Consumes;
15 import javax.ws.rs.DELETE;
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.MediaType;
24 import javax.ws.rs.core.Response;
25 import org.codehaus.enunciate.jaxrs.ResponseCode;
26 import org.codehaus.enunciate.jaxrs.StatusCodes;
27 import org.opendaylight.neutron.spi.INeutronTapFlowCRUD;
28 import org.opendaylight.neutron.spi.NeutronTapFlow;
31 public final class NeutronTapFlowNorthbound
32 extends AbstractNeutronNorthbound<NeutronTapFlow, NeutronTapFlowRequest, INeutronTapFlowCRUD> {
34 private static final String RESOURCE_NAME = "Tap Flow";
37 protected String getResourceName() {
42 * Returns a list of all Tap Flows.
45 @Produces({ MediaType.APPLICATION_JSON })
46 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
47 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
48 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
49 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
50 public Response listGroups(
52 @QueryParam("fields") List<String> fields,
53 // OpenStack Tap Flow attributes
54 @QueryParam("id") String queryTapFlowUUID,
55 @QueryParam("tenant_id") String queryTapFlowTenantID,
56 @QueryParam("name") String queryTapFlowName,
57 @QueryParam("source_port") String queryTapFlowSourcePort,
58 @QueryParam("tap_service_id") String queryTapServiceID,
59 @QueryParam("direction") String queryTapFlowDirection,
61 @QueryParam("limit") String limit,
62 @QueryParam("marker") String marker,
63 @QueryParam("page_reverse") String pageReverse) {
65 INeutronTapFlowCRUD tapFlowInterface = getNeutronCRUD();
66 List<NeutronTapFlow> ans = new ArrayList<>();
67 for (NeutronTapFlow nsg : tapFlowInterface.getAll()) {
68 if ((queryTapFlowUUID == null || queryTapFlowUUID.equals(nsg.getID()))
69 && (queryTapFlowTenantID == null || queryTapFlowTenantID.equals(nsg.getTenantID()))
70 && (queryTapFlowName == null || queryTapFlowName.equals(nsg.getName()))
71 && (queryTapServiceID == null || queryTapServiceID.equals(nsg.getTapFlowServiceID()))
72 && (queryTapFlowDirection == null || queryTapFlowDirection.equals(nsg.getTapFlowDirection()))
73 && (queryTapFlowSourcePort == null
74 || queryTapFlowSourcePort.equals(nsg.getTapFlowSourcePort()))) {
75 if (fields.size() > 0) {
76 ans.add(nsg.extractFields(fields));
82 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronTapFlowRequest(ans)).build();
86 * Creates new Tap Flow.
88 @Path("{tapServiceUUID}/flows")
90 @Produces({ MediaType.APPLICATION_JSON })
91 @Consumes({ MediaType.APPLICATION_JSON })
92 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
93 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
94 public Response createTapFlow(@PathParam("tapServiceUUID") String tapServiceUUID,
95 final NeutronTapFlowRequest input) {
97 INeutronTapFlowCRUD tapFlowInterface = getNeutronCRUD();
99 if (input.isSingleton()) {
100 NeutronTapFlow singleton = input.getSingleton();
101 singleton.setTapFlowServiceID(tapServiceUUID);
103 tapFlowInterface.addTapFlow(singleton);
105 throw new BadRequestException("Only Singleton tapFlow creation supported");
108 return Response.status(HttpURLConnection.HTTP_CREATED).entity(input).build();
112 * Returns a specific Tap Flow.
114 @Path("{tapServiceUUID}/flows/{tapFlowUUID}")
116 @Produces({ MediaType.APPLICATION_JSON })
117 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
118 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
119 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
120 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
121 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
122 public Response showTapFlow(@PathParam("tapServiceUUID") String tapServiceUUID,
123 @PathParam("tapFlowUUID") String tapFlowUUID,
124 @QueryParam("fields") List<String> fields) {
126 INeutronTapFlowCRUD tapFlowInterface = getNeutronCRUD();
127 if (!tapFlowInterface.tapFlowExists(tapServiceUUID, tapFlowUUID)) {
128 throw new ResourceNotFoundException("Specified UUID does not Exist");
131 NeutronTapFlow tapFlow = tapFlowInterface.getTapFlow(tapServiceUUID, tapFlowUUID);
132 if (fields.size() > 0) {
133 return Response.status(HttpURLConnection.HTTP_OK)
134 .entity(new NeutronTapFlowRequest(tapFlow.extractFields(fields))).build();
136 return Response.status(HttpURLConnection.HTTP_OK)
137 .entity(new NeutronTapFlowRequest(tapFlow)).build();
142 * Updates a Tap Flow.
144 @Path("{tapServiceUUID}/flows/{tapFlowUUID}")
146 @Produces({ MediaType.APPLICATION_JSON })
147 @Consumes({ MediaType.APPLICATION_JSON })
148 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
149 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
150 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
151 public Response updateTapFlow(@PathParam("tapServiceUUID") String tapServiceUUID,
152 @PathParam("tapFlowUUID") String tapFlowUUID,
153 final NeutronTapFlowRequest input) {
155 INeutronTapFlowCRUD tapFlowInterface = getNeutronCRUD();
157 if (!tapFlowInterface.tapFlowExists(tapServiceUUID, tapFlowUUID)) {
158 throw new ResourceNotFoundException("Specified UUID does not Exist");
161 NeutronTapFlow singleton = input.getSingleton();
162 singleton.setTapFlowServiceID(tapServiceUUID);
163 tapFlowInterface.updateTapFlow(singleton);
165 return Response.status(HttpURLConnection.HTTP_OK).entity(input).build();
169 * Deletes a Tap Flow.
171 @Path("{tapServiceUUID}/flows/{tapFlowUUID}")
173 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
174 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
175 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
176 public Response deleteTapFlow(@PathParam("tapServiceUUID") String tapServiceUUID,
177 @PathParam("tapFlowUUID") String tapFlowUUID) {
179 INeutronTapFlowCRUD tapFlowInterface = getNeutronCRUD();
181 if (!tapFlowInterface.tapFlowExists(tapServiceUUID, tapFlowUUID)) {
182 throw new ResourceNotFoundException("Specified UUID does not Exist");
185 tapFlowInterface.deleteTapFlow(tapServiceUUID, tapFlowUUID);
186 return Response.status(HttpURLConnection.HTTP_NO_CONTENT).build();