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.
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(
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));
84 ans.add(sfcPortChain);
89 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronSFCPortChainRequest(ans)).build();
94 * Returns a specific SFC Port Chain.
97 @Path("{portChainUUID}")
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,
107 @QueryParam("fields") List<String> fields) {
108 return show(sfcPortChainUUID, fields);
112 * Creates new SFC Port Chain.
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);
124 protected void updateDelta(String uuid, NeutronSFCPortChain delta, NeutronSFCPortChain original) {
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
133 delta.setTenantID(original.getTenantID());
137 * Updates an existing SFC Port Chain.
139 @Path("{portChainUUID}")
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);
152 * Deletes the SFC Port Chain.
154 @Path("{portChainUUID}")
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);