6d46e78bf6b0641f8c548e953449e246e14d57a0
[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.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.INeutronSFCPortChainCRUD;
27 import org.opendaylight.neutron.spi.NeutronSFCPortChain;
28
29 /**
30  * Neutron Northbound REST APIs for OpenStack SFC Port Chain.<br>
31  * This class provides REST APIs for managing OpenStack SFC Port Chain
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/portchains")
48 public final class NeutronSFCPortChainsNorthbound
49         extends AbstractNeutronNorthbound<NeutronSFCPortChain, NeutronSFCPortChainRequest, INeutronSFCPortChainCRUD> {
50
51     private static final String RESOURCE_NAME = "Sfc Port Chain";
52
53     @Override
54     protected String getResourceName() {
55         return RESOURCE_NAME;
56     }
57
58     /**
59      * Returns a list of all SFC Port Chains.
60      */
61
62     @GET
63     @Produces({ MediaType.APPLICATION_JSON })
64     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
65             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
66             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
67             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
68     public Response listSFCPortChains(
69             // return fields
70             @QueryParam("fields") List<String> fields,
71             @QueryParam("id") String queryID,
72             @QueryParam("name") String queryName,
73             @QueryParam("tenant_id") String queryTenantID) {
74         INeutronSFCPortChainCRUD sfcPortChainInterface = getNeutronCRUD();
75         List<NeutronSFCPortChain> allSFCPortChain = sfcPortChainInterface.getAll();
76         List<NeutronSFCPortChain> ans = new ArrayList<>();
77         for (NeutronSFCPortChain sfcPortChain : allSFCPortChain) {
78             if ((queryID == null || queryID.equals(sfcPortChain.getID()))
79                     && (queryName == null || queryName.equals(sfcPortChain.getName()))
80                     && (queryTenantID == null || queryTenantID.equals(sfcPortChain.getTenantID()))) {
81                 if (fields.size() > 0) {
82                     ans.add(sfcPortChain.extractFields(fields));
83                 } else {
84                     ans.add(sfcPortChain);
85                 }
86             }
87         }
88
89         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronSFCPortChainRequest(ans)).build();
90
91     }
92
93     /**
94      * Returns a specific SFC Port Chain.
95      */
96
97     @Path("{portChainUUID}")
98     @GET
99     @Produces({ MediaType.APPLICATION_JSON })
100     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
101             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
102             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
103             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
104             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
105     public Response showSFCPortChain(@PathParam("portChainUUID") String sfcPortChainUUID,
106             // return fields
107             @QueryParam("fields") List<String> fields) {
108         return show(sfcPortChainUUID, fields);
109     }
110
111     /**
112      * Creates new SFC Port Chain.
113      */
114     @POST
115     @Produces({ MediaType.APPLICATION_JSON })
116     @Consumes({ MediaType.APPLICATION_JSON })
117     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
118             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
119     public Response createSFCPortChain(final NeutronSFCPortChainRequest input) {
120         return create(input);
121     }
122
123     @Override
124     protected void updateDelta(String uuid, NeutronSFCPortChain delta, NeutronSFCPortChain original) {
125         /*
126          *  note: what we get appears to not be a delta but
127          * rather an incomplete updated object.  So we need to set
128          * the ID to complete the object and then send that down
129          * for folks to check
130          */
131
132         delta.setID(uuid);
133         delta.setTenantID(original.getTenantID());
134     }
135
136     /**
137      * Updates an existing SFC Port Chain.
138      */
139     @Path("{portChainUUID}")
140     @PUT
141     @Produces({ MediaType.APPLICATION_JSON })
142     @Consumes({ MediaType.APPLICATION_JSON })
143     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
144             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
145             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
146     public Response updateSFCPortChain(@PathParam("portChainUUID") String sfcPortChainUUID,
147             final NeutronSFCPortChainRequest input) {
148         return update(sfcPortChainUUID, input);
149     }
150
151     /**
152      * Deletes the SFC Port Chain.
153      */
154     @Path("{portChainUUID}")
155     @DELETE
156     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
157             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
158             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
159     public Response deleteSFCPortChain(@PathParam("portChainUUID") String sfcPortChainUUID) {
160         return delete(sfcPortChainUUID);
161     }
162 }