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 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;
30 * Neutron Northbound REST APIs for OpenStack SFC Port Chain.<br>
31 * This class provides REST APIs for managing OpenStack SFC Port Chain
35 * Authentication scheme : <b>HTTP Basic</b><br>
36 * Authentication realm : <b>opendaylight</b><br>
37 * Transport : <b>HTTP and HTTPS</b><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>
43 * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
47 @Path("/sfc/portchains")
48 public final class NeutronSFCPortChainsNorthbound
49 extends AbstractNeutronNorthbound<NeutronSFCPortChain, NeutronSFCPortChainRequest, INeutronSFCPortChainCRUD> {
51 private static final String RESOURCE_NAME = "Sfc Port Chain";
54 protected String getResourceName() {
59 * Returns a list of all SFC Port Chains*/
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 listSFCPortChains(
69 @QueryParam("fields") List<String> fields,
70 @QueryParam("id") String queryID,
71 @QueryParam("name") String queryName,
72 @QueryParam("tenant_id") String queryTenantID) {
73 INeutronSFCPortChainCRUD sfcPortChainInterface = getNeutronCRUD();
74 List<NeutronSFCPortChain> allSFCPortChain = sfcPortChainInterface.getAll();
75 List<NeutronSFCPortChain> ans = new ArrayList<>();
76 for (NeutronSFCPortChain sfcPortChain : allSFCPortChain) {
77 if ((queryID == null || queryID.equals(sfcPortChain.getID()))
78 && (queryName == null || queryName.equals(sfcPortChain.getName()))
79 && (queryTenantID == null || queryTenantID.equals(sfcPortChain.getTenantID()))) {
80 if (fields.size() > 0) {
81 ans.add(sfcPortChain.extractFields(fields));
83 ans.add(sfcPortChain);
88 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronSFCPortChainRequest(ans)).build();
93 * Returns a specific SFC Port Chain */
95 @Path("{portChainUUID}")
97 @Produces({ MediaType.APPLICATION_JSON })
98 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
99 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
100 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
101 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
102 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
103 public Response showSFCPortChain(@PathParam("portChainUUID") String sfcPortChainUUID,
105 @QueryParam("fields") List<String> fields) {
106 return show(sfcPortChainUUID, fields);
110 * Creates new SFC Port Chain*/
112 @Produces({ MediaType.APPLICATION_JSON })
113 @Consumes({ MediaType.APPLICATION_JSON })
114 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
115 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
116 public Response createSFCPortChain(final NeutronSFCPortChainRequest input) {
117 return create(input);
121 protected void updateDelta(String uuid, NeutronSFCPortChain delta, NeutronSFCPortChain original) {
123 * note: what we get appears to not be a delta but
124 * rather an incomplete updated object. So we need to set
125 * the ID to complete the object and then send that down
130 delta.setTenantID(original.getTenantID());
134 * Updates an existing SFC Port Chain */
135 @Path("{portChainUUID}")
137 @Produces({ MediaType.APPLICATION_JSON })
138 @Consumes({ MediaType.APPLICATION_JSON })
139 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
140 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
141 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
142 public Response updateSFCPortChain(@PathParam("portChainUUID") String sfcPortChainUUID,
143 final NeutronSFCPortChainRequest input) {
144 return update(sfcPortChainUUID, input);
148 * Deletes the SFC Port Chain */
149 @Path("{portChainUUID}")
151 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
152 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
153 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
154 public Response deleteSFCPortChain(@PathParam("portChainUUID") String sfcPortChainUUID) {
155 return delete(sfcPortChainUUID);