remove irrelevant old JavaDoc from a long bygone era in northbound.api
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronTapServiceNorthbound.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.INeutronTapServiceCRUD;
27 import org.opendaylight.neutron.spi.NeutronTapService;
28
29 @Path("/tap/services")
30 public final class NeutronTapServiceNorthbound
31         extends AbstractNeutronNorthbound<NeutronTapService, NeutronTapServiceRequest, INeutronTapServiceCRUD> {
32
33     private static final String RESOURCE_NAME = "Tap Service";
34
35     @Override
36     protected String getResourceName() {
37         return RESOURCE_NAME;
38     }
39
40     /**
41      * Returns a list of all Tap Services.
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 Service attributes
53             @QueryParam("id") String queryTapServiceUUID,
54             @QueryParam("tenant_id") String queryTapServiceTenantID,
55             @QueryParam("name") String queryTapServiceName,
56             @QueryParam("port_id") String queryTapServicePortID,
57             // pagination
58             @QueryParam("limit") String limit,
59             @QueryParam("marker") String marker,
60             @QueryParam("page_reverse") String pageReverse) {
61         INeutronTapServiceCRUD tapServiceInterface = getNeutronCRUD();
62         List<NeutronTapService> ans = new ArrayList<>();
63         for (NeutronTapService nsg : tapServiceInterface.getAll()) {
64             if ((queryTapServiceUUID == null || queryTapServiceUUID.equals(nsg.getID()))
65                     && (queryTapServiceTenantID == null || queryTapServiceTenantID.equals(nsg.getTenantID()))
66                     && (queryTapServiceName == null || queryTapServiceName.equals(nsg.getName()))
67                     && (queryTapServicePortID == null || queryTapServicePortID.equals(nsg.getTapServicePortID()))) {
68                 if (fields.size() > 0) {
69                     ans.add(nsg.extractFields(fields));
70                 } else {
71                     ans.add(nsg);
72                 }
73             }
74         }
75         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronTapServiceRequest(ans)).build();
76     }
77
78     /**
79      * Returns a specific Tap Service.
80      */
81     @Path("{tapServiceUUID}")
82     @GET
83     @Produces({ MediaType.APPLICATION_JSON })
84     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
85             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
86             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
87             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
88             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
89     public Response showTapService(@PathParam("tapServiceUUID") String tapServiceUUID,
90             @QueryParam("fields") List<String> fields) {
91         return show(tapServiceUUID, fields);
92     }
93
94     /**
95      * Creates new Tap Service.
96      */
97     @POST
98     @Produces({ MediaType.APPLICATION_JSON })
99     @Consumes({ MediaType.APPLICATION_JSON })
100     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
101             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
102     public Response createTapService(final NeutronTapServiceRequest input) {
103         return create(input);
104     }
105
106     /**
107      * Updates a Tap Service.
108      */
109     @Path("{tapServiceUUID}")
110     @PUT
111     @Produces({ MediaType.APPLICATION_JSON })
112     @Consumes({ MediaType.APPLICATION_JSON })
113     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
114             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
115             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
116     public Response updateTapService(@PathParam("tapServiceUUID") String tapServiceUUID,
117             final NeutronTapServiceRequest input) {
118         return update(tapServiceUUID, input);
119     }
120
121     /**
122      * Deletes a Tap Service.
123      */
124     @Path("{tapServiceUUID}")
125     @DELETE
126     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
127             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
128             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
129     public Response deleteTapService(@PathParam("tapServiceUUID") String tapServiceUUID) {
130         return delete(tapServiceUUID);
131     }
132 }