ca35c4b260048b8b0829894eaeeb2da5ae63afe9
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronSFCFlowClassifiersNorthbound.java
1 /*
2  * Copyright (c) 2016 Brocade Communications Systems, Inc. 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.INeutronSFCFlowClassifierCRUD;
27 import org.opendaylight.neutron.spi.NeutronSFCFlowClassifier;
28
29 /**
30  * Neutron Northbound REST APIs for OpenStack SFC Flow Classifier.<br>
31  * This class provides REST APIs for managing OpenStack SFC Flow Classifier
32  *
33  * <br>
34  * <br>
35  * Authentication scheme : <b>HTTP Basic</b><br>
36  * Authentication realm : <b>opendaylight</b><br>
37  * Transport : <b>HTTP and HTTPS</b><br>
38  * <br>
39  * HTTPS Authentication is disabled by default. Administrator can enable it in
40  * tomcat-server.xml after adding a proper keystore / SSL certificate from a
41  * trusted authority.<br>
42  * More info :
43  * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
44  *
45  */
46
47 @Path("/sfc/flowclassifiers")
48 public final class NeutronSFCFlowClassifiersNorthbound extends AbstractNeutronNorthbound<NeutronSFCFlowClassifier,
49         NeutronSFCFlowClassifierRequest, INeutronSFCFlowClassifierCRUD> {
50     private static final String RESOURCE_NAME = "Sfc Flow Classifier";
51
52     @Override
53     protected String getResourceName() {
54         return RESOURCE_NAME;
55     }
56
57     /**
58      * Returns a list of all SFC Flow Classifiers.
59      */
60
61     @GET
62     @Produces({ MediaType.APPLICATION_JSON })
63     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
64             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
65             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
66             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
67     public Response listSFCFlowClassifiers(
68             // return fields
69             @QueryParam("fields") List<String> fields,
70             // note: openstack isn't clear about filtering on lists, so we aren't handling them
71             @QueryParam("id") String queryID,
72             @QueryParam("name") String queryName,
73             @QueryParam("ethertype") String queryEthertype,
74             @QueryParam("protocol") String queryProtocol,
75             @QueryParam("source_port_range_min") Integer querySourcePortRangeMin,
76             @QueryParam("source_port_range_max") Integer querySourcePortRangeMax,
77             @QueryParam("tenant_id") String queryTenantID,
78             @QueryParam("destination_port_range_min") Integer queryDestinationPortRangeMin,
79             @QueryParam("destination_port_range_max") Integer queryDestinationPortRangeMax,
80             @QueryParam("source_ip_prefix") String querySourceIpPrefix,
81             @QueryParam("destination_ip_prefix") String queryDestinationIpPrefix,
82             @QueryParam("logical_source_port") String queryLogicalSourcePort,
83             @QueryParam("logical_destination_port") String queryLogicalDestinationPort) {
84         INeutronSFCFlowClassifierCRUD sfcFlowClassifierInterface = getNeutronCRUD();
85         List<NeutronSFCFlowClassifier> allSFCFlowClassifier = sfcFlowClassifierInterface.getAll();
86         List<NeutronSFCFlowClassifier> ans = new ArrayList<>();
87         for (NeutronSFCFlowClassifier classifier : allSFCFlowClassifier) {
88             if ((queryID == null || queryID.equals(classifier.getID()))
89                     && (queryName == null || queryName.equals(classifier.getName()))
90                     && (queryEthertype == null || queryEthertype.equals(classifier.getEthertype()))
91                     && (queryProtocol == null || queryProtocol.equals(classifier.getProtocol()))
92                     && (querySourcePortRangeMin == null
93                         || querySourcePortRangeMin.equals(classifier.getSourcePortRangeMin()))
94                     && (querySourcePortRangeMax == null
95                         || querySourcePortRangeMax.equals(classifier.getSourcePortRangeMax()))
96                     && (queryDestinationPortRangeMin == null
97                             || queryDestinationPortRangeMin.equals(classifier.getDestinationPortRangeMin()))
98                     && (queryDestinationPortRangeMax == null
99                             || queryDestinationPortRangeMax.equals(classifier.getDestinationPortRangeMax()))
100                     && (querySourceIpPrefix == null || querySourceIpPrefix.equals(classifier.getSourceIpPrefix()))
101                     && (queryDestinationIpPrefix == null
102                             || queryDestinationIpPrefix.equals(classifier.getDestinationIpPrefix()))
103                     && (queryLogicalSourcePort == null
104                             || queryLogicalSourcePort.equals(classifier.getLogicalSourcePortUUID()))
105                     && (queryLogicalDestinationPort == null
106                             || queryLogicalDestinationPort.equals(classifier.getLogicalDestinationPortUUID()))
107                     && (queryTenantID == null || queryTenantID.equals(classifier.getTenantID()))) {
108                 if (fields.size() > 0) {
109                     ans.add(classifier.extractFields(fields));
110                 } else {
111                     ans.add(classifier);
112                 }
113             }
114         }
115
116         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronSFCFlowClassifierRequest(ans)).build();
117
118     }
119
120     /**
121      * Returns a specific SFC Flow Classifier.
122      */
123
124     @Path("{flowClassifierUUID}")
125     @GET
126     @Produces({ MediaType.APPLICATION_JSON })
127     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
128             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
129             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
130             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
131             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
132     public Response showSFCFlowClassifier(@PathParam("flowClassifierUUID") String sfcFlowClassifierUUID,
133             // return fields
134             @QueryParam("fields") List<String> fields) {
135         return show(sfcFlowClassifierUUID, fields);
136     }
137
138     /**
139      * Creates new SFC Flow Classifier.
140      */
141     @POST
142     @Produces({ MediaType.APPLICATION_JSON })
143     @Consumes({ MediaType.APPLICATION_JSON })
144     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
145             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
146     public Response createSFCFlowClassifier(final NeutronSFCFlowClassifierRequest input) {
147         return create(input);
148     }
149
150     @Override
151     protected void updateDelta(String uuid, NeutronSFCFlowClassifier delta, NeutronSFCFlowClassifier original) {
152         /*
153          *  note: what we get appears to not be a delta but
154          * rather an incomplete updated object.  So we need to set
155          * the ID to complete the object and then send that down
156          * for folks to check
157          */
158
159         delta.setID(uuid);
160         delta.setTenantID(original.getTenantID());
161     }
162
163     /**
164      * Updates an existing SFC Flow Classifier.
165      */
166     @Path("{flowClassifierUUID}")
167     @PUT
168     @Produces({ MediaType.APPLICATION_JSON })
169     @Consumes({ MediaType.APPLICATION_JSON })
170     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
171             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
172             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
173     public Response updateSFCFlowClassifier(@PathParam("flowClassifierUUID") String sfcFlowClassifierUUID,
174             final NeutronSFCFlowClassifierRequest input) {
175         return update(sfcFlowClassifierUUID, input);
176     }
177
178     /**
179      * Deletes the SFC Flow Classifier.
180      */
181     @Path("{flowClassifierUUID}")
182     @DELETE
183     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
184             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
185             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
186     public Response deleteSFCFlowClassifier(@PathParam("flowClassifierUUID") String sfcFlowClassifierUUID) {
187         return delete(sfcFlowClassifierUUID);
188     }
189 }