2 * Copyright (c) 2016 Brocade Communications Systems, Inc. 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
8 package org.opendaylight.neutron.northbound.api;
10 import org.codehaus.enunciate.jaxrs.ResponseCode;
11 import org.codehaus.enunciate.jaxrs.StatusCodes;
12 import org.opendaylight.neutron.spi.INeutronSFCPortChainCRUD;
13 import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
14 import org.opendaylight.neutron.spi.NeutronSFCPortChain;
16 import javax.ws.rs.Consumes;
17 import javax.ws.rs.DELETE;
18 import javax.ws.rs.GET;
19 import javax.ws.rs.POST;
20 import javax.ws.rs.PUT;
21 import javax.ws.rs.Path;
22 import javax.ws.rs.PathParam;
23 import javax.ws.rs.Produces;
24 import javax.ws.rs.QueryParam;
25 import javax.ws.rs.core.MediaType;
26 import javax.ws.rs.core.Response;
27 import java.net.HttpURLConnection;
28 import java.util.ArrayList;
29 import java.util.Iterator;
30 import java.util.List;
33 * Neutron Northbound REST APIs for OpenStack SFC Port Chain.<br>
34 * This class provides REST APIs for managing OpenStack SFC Port Chain
38 * Authentication scheme : <b>HTTP Basic</b><br>
39 * Authentication realm : <b>opendaylight</b><br>
40 * Transport : <b>HTTP and HTTPS</b><br>
42 * HTTPS Authentication is disabled by default. Administrator can enable it in
43 * tomcat-server.xml after adding a proper keystore / SSL certificate from a
44 * trusted authority.<br>
46 * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
50 @Path("/sfc/portchains")
51 public class NeutronSFCPortChainsNorthbound
52 extends AbstractNeutronNorthbound<NeutronSFCPortChain,
53 NeutronSFCPortChainRequest, INeutronSFCPortChainCRUD> {
55 private static final String RESOURCE_NAME = "Sfc Port Chain";
58 protected String getResourceName() {
63 protected NeutronSFCPortChain extractFields(NeutronSFCPortChain o, List<String> fields) {
64 return o.extractFields(fields);
68 protected NeutronSFCPortChainRequest newNeutronRequest(NeutronSFCPortChain o) {
69 return new NeutronSFCPortChainRequest(o);
73 protected INeutronSFCPortChainCRUD getNeutronCRUD() {
74 NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronSFCPortChainCRUD(this);
75 if (answer.getSFCPortChainInterface() == null) {
76 throw new ServiceUnavailableException(serviceUnavailable());
78 return answer.getSFCPortChainInterface();
82 * Returns a list of all SFC Port Chains*/
85 @Produces({ MediaType.APPLICATION_JSON })
87 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
88 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
89 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
90 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
91 public Response listSFCPortChains(
93 @QueryParam("fields") List<String> fields,
94 @QueryParam("id") String queryID,
95 @QueryParam("name") String queryName,
96 @QueryParam("tenant_id") String queryTenantID) {
97 INeutronSFCPortChainCRUD sfcPortChainInterface = getNeutronCRUD();
98 List<NeutronSFCPortChain> allSFCPortChain = sfcPortChainInterface.getAll();
99 List<NeutronSFCPortChain> ans = new ArrayList<>();
100 Iterator<NeutronSFCPortChain> i = allSFCPortChain.iterator();
101 while (i.hasNext()) {
102 NeutronSFCPortChain oSFCPC = i.next();
103 if ((queryID == null || queryID.equals(oSFCPC.getID())) &&
104 (queryName == null || queryName.equals(oSFCPC.getName())) &&
105 (queryTenantID == null || queryTenantID.equals(oSFCPC.getTenantID()))) {
106 if (fields.size() > 0) {
107 ans.add(extractFields(oSFCPC,fields));
114 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronSFCPortChainRequest(ans)).build();
119 * Returns a specific SFC Port Chain */
121 @Path("{portChainUUID}")
123 @Produces({ MediaType.APPLICATION_JSON })
125 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
126 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
127 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
128 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
129 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
130 public Response showSFCPortChain(
131 @PathParam("portChainUUID") String sfcPortChainUUID,
133 @QueryParam("fields") List<String> fields) {
134 return show(sfcPortChainUUID, fields);
138 * Creates new SFC Port Chain*/
140 @Produces({ MediaType.APPLICATION_JSON })
141 @Consumes({ MediaType.APPLICATION_JSON })
143 @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
144 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
145 public Response createSFCPortChain(final NeutronSFCPortChainRequest input) {
146 return create(input);
150 protected void updateDelta(String uuid, NeutronSFCPortChain delta, NeutronSFCPortChain original) {
152 * note: what we get appears to not be a delta but
153 * rather an incomplete updated object. So we need to set
154 * the ID to complete the object and then send that down
159 delta.setTenantID(original.getTenantID());
163 * Updates an existing SFC Port Chain */
164 @Path("{portChainUUID}")
166 @Produces({ MediaType.APPLICATION_JSON })
167 @Consumes({ MediaType.APPLICATION_JSON })
169 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
170 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
171 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
172 public Response updateSFCPortChain(
173 @PathParam("portChainUUID") String sfcPortChainUUID, final NeutronSFCPortChainRequest input) {
174 return update(sfcPortChainUUID, input);
178 * Deletes the SFC Port Chain */
179 @Path("{portChainUUID}")
182 @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
183 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
184 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
185 public Response deleteSFCPortChain(
186 @PathParam("portChainUUID") String sfcPortChainUUID) {
187 return delete(sfcPortChainUUID);