Checkstyle formatting issues fix (Northbound API)
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronSFCPortChainsNorthbound.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.Iterator;
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.INeutronSFCPortChainCRUD;
28 import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
29 import org.opendaylight.neutron.spi.NeutronSFCPortChain;
30
31 /**
32  * Neutron Northbound REST APIs for OpenStack SFC Port Chain.<br>
33  * This class provides REST APIs for managing OpenStack SFC Port Chain
34  *
35  * <br>
36  * <br>
37  * Authentication scheme : <b>HTTP Basic</b><br>
38  * Authentication realm : <b>opendaylight</b><br>
39  * Transport : <b>HTTP and HTTPS</b><br>
40  * <br>
41  * HTTPS Authentication is disabled by default. Administrator can enable it in
42  * tomcat-server.xml after adding a proper keystore / SSL certificate from a
43  * trusted authority.<br>
44  * More info :
45  * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
46  *
47  */
48
49 @Path("/sfc/portchains")
50 public class NeutronSFCPortChainsNorthbound
51         extends AbstractNeutronNorthbound<NeutronSFCPortChain, NeutronSFCPortChainRequest, INeutronSFCPortChainCRUD> {
52
53     private static final String RESOURCE_NAME = "Sfc Port Chain";
54
55     @Override
56     protected String getResourceName() {
57         return RESOURCE_NAME;
58     }
59
60     @Override
61     protected NeutronSFCPortChain extractFields(NeutronSFCPortChain o, List<String> fields) {
62         return o.extractFields(fields);
63     }
64
65     @Override
66     protected NeutronSFCPortChainRequest newNeutronRequest(NeutronSFCPortChain o) {
67         return new NeutronSFCPortChainRequest(o);
68     }
69
70     @Override
71     protected INeutronSFCPortChainCRUD getNeutronCRUD() {
72         NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronSFCPortChainCRUD(this);
73         if (answer.getSFCPortChainInterface() == null) {
74             throw new ServiceUnavailableException(serviceUnavailable());
75         }
76         return answer.getSFCPortChainInterface();
77     }
78
79     /**
80      * Returns a list of all SFC Port Chains*/
81
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_IMPLEMENTED, condition = "Not Implemented"),
87             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
88     public Response listSFCPortChains(
89             // return fields
90             @QueryParam("fields") List<String> fields,
91             @QueryParam("id") String queryID,
92             @QueryParam("name") String queryName,
93             @QueryParam("tenant_id") String queryTenantID) {
94         INeutronSFCPortChainCRUD sfcPortChainInterface = getNeutronCRUD();
95         List<NeutronSFCPortChain> allSFCPortChain = sfcPortChainInterface.getAll();
96         List<NeutronSFCPortChain> ans = new ArrayList<>();
97         Iterator<NeutronSFCPortChain> i = allSFCPortChain.iterator();
98         while (i.hasNext()) {
99             NeutronSFCPortChain oSFCPC = i.next();
100             if ((queryID == null || queryID.equals(oSFCPC.getID()))
101                     && (queryName == null || queryName.equals(oSFCPC.getName()))
102                     && (queryTenantID == null || queryTenantID.equals(oSFCPC.getTenantID()))) {
103                 if (fields.size() > 0) {
104                     ans.add(extractFields(oSFCPC, fields));
105                 } else {
106                     ans.add(oSFCPC);
107                 }
108             }
109         }
110
111         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronSFCPortChainRequest(ans)).build();
112
113     }
114
115     /**
116      * Returns a specific SFC Port Chain */
117
118     @Path("{portChainUUID}")
119     @GET
120     @Produces({ MediaType.APPLICATION_JSON })
121     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
122             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
123             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
124             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
125             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
126     public Response showSFCPortChain(@PathParam("portChainUUID") String sfcPortChainUUID,
127             // return fields
128             @QueryParam("fields") List<String> fields) {
129         return show(sfcPortChainUUID, fields);
130     }
131
132     /**
133      * Creates new SFC Port Chain*/
134     @POST
135     @Produces({ MediaType.APPLICATION_JSON })
136     @Consumes({ MediaType.APPLICATION_JSON })
137     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
138             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
139     public Response createSFCPortChain(final NeutronSFCPortChainRequest input) {
140         return create(input);
141     }
142
143     @Override
144     protected void updateDelta(String uuid, NeutronSFCPortChain delta, NeutronSFCPortChain original) {
145         /*
146          *  note: what we get appears to not be a delta but
147          * rather an incomplete updated object.  So we need to set
148          * the ID to complete the object and then send that down
149          * for folks to check
150          */
151
152         delta.setID(uuid);
153         delta.setTenantID(original.getTenantID());
154     }
155
156     /**
157      * Updates an existing SFC Port Chain */
158     @Path("{portChainUUID}")
159     @PUT
160     @Produces({ MediaType.APPLICATION_JSON })
161     @Consumes({ MediaType.APPLICATION_JSON })
162     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
163             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
164             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
165     public Response updateSFCPortChain(@PathParam("portChainUUID") String sfcPortChainUUID,
166             final NeutronSFCPortChainRequest input) {
167         return update(sfcPortChainUUID, input);
168     }
169
170     /**
171      * Deletes the SFC Port Chain */
172     @Path("{portChainUUID}")
173     @DELETE
174     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
175             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
176             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
177     public Response deleteSFCPortChain(@PathParam("portChainUUID") String sfcPortChainUUID) {
178         return delete(sfcPortChainUUID);
179     }
180 }