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.INeutronSFCPortPairCRUD;
27 import org.opendaylight.neutron.spi.NeutronSFCPortPair;
30 * Neutron Northbound REST APIs for OpenStack SFC Port Pair.<br>
31 * This class provides REST APIs for managing OpenStack SFC Port Pair
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/portpairs")
48 public final class NeutronSFCPortPairsNorthbound
49 extends AbstractNeutronNorthbound<NeutronSFCPortPair, NeutronSFCPortPairRequest, INeutronSFCPortPairCRUD> {
51 private static final String RESOURCE_NAME = "Sfc Port Pair";
54 protected String getResourceName() {
59 * Returns a list of all SFC Port Pairs.
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 listSFCPortPairs(
70 @QueryParam("fields") List<String> fields,
71 @QueryParam("id") String queryID,
72 @QueryParam("name") String queryName,
73 @QueryParam("tenant_id") String queryTenantID,
74 @QueryParam("ingress") String queryIngressPort,
75 @QueryParam("egress") String queryEgressPort) {
76 INeutronSFCPortPairCRUD sfcPortPairInterface = getNeutronCRUD();
77 List<NeutronSFCPortPair> allSFCPortPair = sfcPortPairInterface.getAll();
78 List<NeutronSFCPortPair> ans = new ArrayList<>();
79 for (NeutronSFCPortPair sfcPortPair : allSFCPortPair) {
80 if ((queryID == null || queryID.equals(sfcPortPair.getID()))
81 && (queryName == null || queryName.equals(sfcPortPair.getName()))
82 && (queryIngressPort == null || queryIngressPort.equals(sfcPortPair.getIngressPortUUID()))
83 && (queryEgressPort == null || queryEgressPort.equals(sfcPortPair.getEgressPortUUID()))
84 && (queryTenantID == null || queryTenantID.equals(sfcPortPair.getTenantID()))) {
85 if (fields.size() > 0) {
86 ans.add(sfcPortPair.extractFields(fields));
93 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronSFCPortPairRequest(ans)).build();
98 * Returns a specific SFC Port Pair.
101 @Path("{portPairUUID}")
103 @Produces({ MediaType.APPLICATION_JSON })
104 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
105 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
106 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
107 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
108 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
109 public Response showSFCPortPair(@PathParam("portPairUUID") String sfcPortPairUUID,
111 @QueryParam("fields") List<String> fields) {
112 return show(sfcPortPairUUID, fields);
116 * Creates new SFC Port Pair.
119 @Produces({ MediaType.APPLICATION_JSON })
120 @Consumes({ MediaType.APPLICATION_JSON })
121 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
122 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
123 public Response createSFCPortPair(final NeutronSFCPortPairRequest input) {
124 return create(input);
128 protected void updateDelta(String uuid, NeutronSFCPortPair delta, NeutronSFCPortPair original) {
130 * note: what we get appears to not be a delta but
131 * rather an incomplete updated object. So we need to set
132 * the ID to complete the object and then send that down
137 delta.setTenantID(original.getTenantID());
141 * Updates an existing SFC Port Pair.
143 @Path("{portPairUUID}")
145 @Produces({ MediaType.APPLICATION_JSON })
146 @Consumes({ MediaType.APPLICATION_JSON })
147 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
148 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
149 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
150 public Response updateSFCPortPair(@PathParam("portPairUUID") String sfcPortPairUUID,
151 final NeutronSFCPortPairRequest input) {
152 return update(sfcPortPairUUID, input);
156 * Deletes the SFC Port Pair.
159 @Path("{portPairUUID}")
161 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
162 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
163 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
164 public Response deleteSFCPortPair(@PathParam("portPairUUID") String sfcPortPairUUID) {
165 return delete(sfcPortPairUUID);