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.INeutronTapServiceCRUD;
28 import org.opendaylight.neutron.spi.NeutronTapService;
30 @Path("/tap/services")
31 public final class NeutronTapServiceNorthbound
32 extends AbstractNeutronNorthbound<NeutronTapService, NeutronTapServiceRequest, INeutronTapServiceCRUD> {
34 private static final String RESOURCE_NAME = "Tap Service";
37 protected String getResourceName() {
42 * Returns a list of all Tap Services.
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 Service attributes
54 @QueryParam("id") String queryTapServiceUUID,
55 @QueryParam("tenant_id") String queryTapServiceTenantID,
56 @QueryParam("name") String queryTapServiceName,
57 @QueryParam("port_id") String queryTapServicePortID,
59 @QueryParam("limit") String limit,
60 @QueryParam("marker") String marker,
61 @QueryParam("page_reverse") String pageReverse) {
62 INeutronTapServiceCRUD tapServiceInterface = getNeutronCRUD();
63 List<NeutronTapService> ans = new ArrayList<>();
64 for (NeutronTapService nsg : tapServiceInterface.getAll()) {
65 if ((queryTapServiceUUID == null || queryTapServiceUUID.equals(nsg.getID()))
66 && (queryTapServiceTenantID == null || queryTapServiceTenantID.equals(nsg.getTenantID()))
67 && (queryTapServiceName == null || queryTapServiceName.equals(nsg.getName()))
68 && (queryTapServicePortID == null || queryTapServicePortID.equals(nsg.getTapServicePortID()))) {
69 if (fields.size() > 0) {
70 ans.add(nsg.extractFields(fields));
76 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronTapServiceRequest(ans)).build();
80 * Returns a specific Tap Service.
82 @Path("{tapServiceUUID}")
84 @Produces({ MediaType.APPLICATION_JSON })
85 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
86 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
87 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
88 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
89 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
90 public Response showTapService(@PathParam("tapServiceUUID") String tapServiceUUID,
91 @QueryParam("fields") List<String> fields) {
92 return show(tapServiceUUID, fields);
96 * Creates new Tap Service.
99 @Produces({ MediaType.APPLICATION_JSON })
100 @Consumes({ MediaType.APPLICATION_JSON })
101 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
102 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
103 public Response createTapService(final NeutronTapServiceRequest input) {
104 return create(input);
108 * Updates a Tap Service.
110 @Path("{tapServiceUUID}")
112 @Produces({ MediaType.APPLICATION_JSON })
113 @Consumes({ MediaType.APPLICATION_JSON })
114 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
115 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
116 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
117 public Response updateTapService(@PathParam("tapServiceUUID") String tapServiceUUID,
118 final NeutronTapServiceRequest input) {
119 return update(tapServiceUUID, input);
123 * Deletes a Tap Service.
125 @Path("{tapServiceUUID}")
127 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
128 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
129 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
130 public Response deleteTapService(@PathParam("tapServiceUUID") String tapServiceUUID) {
131 return delete(tapServiceUUID);