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.Iterator;
13 import java.util.List;
14 import javax.ws.rs.Consumes;
15 import javax.ws.rs.DELETE;
16 import javax.ws.rs.GET;
17 import javax.ws.rs.POST;
18 import javax.ws.rs.PUT;
19 import javax.ws.rs.Path;
20 import javax.ws.rs.PathParam;
21 import javax.ws.rs.Produces;
22 import javax.ws.rs.QueryParam;
23 import javax.ws.rs.core.MediaType;
24 import javax.ws.rs.core.Response;
25 import org.codehaus.enunciate.jaxrs.ResponseCode;
26 import org.codehaus.enunciate.jaxrs.StatusCodes;
27 import org.opendaylight.neutron.spi.INeutronSFCPortPairGroupCRUD;
28 import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
29 import org.opendaylight.neutron.spi.NeutronSFCPortPairGroup;
32 * Neutron Northbound REST APIs for OpenStack SFC Port Pair.<br>
33 * This class provides REST APIs for managing OpenStack SFC Port Pair
37 * Authentication scheme : <b>HTTP Basic</b><br>
38 * Authentication realm : <b>opendaylight</b><br>
39 * Transport : <b>HTTP and HTTPS</b><br>
41 * HTTPS Authentication is disabled by default. Administrator can enable it in
42 * tomcat-server.xml after adding a proper keystore / SSL certificate from a
43 * trusted authority.<br>
45 * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
49 @Path("/sfc/portpairgroups")
50 public class NeutronSFCPortPairGroupsNorthbound extends AbstractNeutronNorthbound<NeutronSFCPortPairGroup,
51 NeutronSFCPortPairGroupRequest, INeutronSFCPortPairGroupCRUD> {
53 private static final String RESOURCE_NAME = "Sfc Port Pair Group";
56 protected String getResourceName() {
61 protected NeutronSFCPortPairGroup extractFields(NeutronSFCPortPairGroup o, List<String> fields) {
62 return o.extractFields(fields);
66 protected NeutronSFCPortPairGroupRequest newNeutronRequest(NeutronSFCPortPairGroup o) {
67 return new NeutronSFCPortPairGroupRequest(o);
71 protected INeutronSFCPortPairGroupCRUD getNeutronCRUD() {
72 NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronSFCPortPairGroupCRUD(this);
73 if (answer.getSFCPortPairGroupInterface() == null) {
74 throw new ServiceUnavailableException(serviceUnavailable());
76 return answer.getSFCPortPairGroupInterface();
80 * Returns a list of all SFC Port Pair Groups*/
83 @Produces({ MediaType.APPLICATION_JSON })
84 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
85 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
86 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
87 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
88 public Response listSFCPortPairGroups(
90 @QueryParam("fields") List<String> fields,
91 @QueryParam("id") String queryID,
92 @QueryParam("name") String queryName,
93 @QueryParam("tenant_id") String queryTenantID,
94 @QueryParam("port_pairs") List<String> queryPortPairsUUID) {
95 INeutronSFCPortPairGroupCRUD sfcPortPairGroupInterface = getNeutronCRUD();
96 List<NeutronSFCPortPairGroup> allSFCPortPairGroup = sfcPortPairGroupInterface.getAll();
97 List<NeutronSFCPortPairGroup> ans = new ArrayList<>();
98 Iterator<NeutronSFCPortPairGroup> i = allSFCPortPairGroup.iterator();
100 NeutronSFCPortPairGroup oSFCPPG = i.next();
101 if ((queryID == null || queryID.equals(oSFCPPG.getID()))
102 && (queryName == null || queryName.equals(oSFCPPG.getName()))
103 && (queryTenantID == null || queryTenantID.equals(oSFCPPG.getTenantID()))) {
104 if (fields.size() > 0) {
105 ans.add(extractFields(oSFCPPG, fields));
112 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronSFCPortPairGroupRequest(ans)).build();
117 * Returns a specific SFC Port Pair Group*/
119 @Path("{portPairGroupUUID}")
121 @Produces({ MediaType.APPLICATION_JSON })
122 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
123 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
124 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
125 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
126 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
127 public Response showSFCPortPairGroup(@PathParam("portPairGroupUUID") String sfcPortPairGroupUUID,
129 @QueryParam("fields") List<String> fields) {
130 return show(sfcPortPairGroupUUID, fields);
134 * Creates new SFC Port Pair Group*/
136 @Produces({ MediaType.APPLICATION_JSON })
137 @Consumes({ MediaType.APPLICATION_JSON })
138 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
139 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
140 public Response createSFCPortPairGroup(final NeutronSFCPortPairGroupRequest input) {
141 return create(input);
145 protected void updateDelta(String uuid, NeutronSFCPortPairGroup delta, NeutronSFCPortPairGroup original) {
147 * note: what we get appears to not be a delta but
148 * rather an incomplete updated object. So we need to set
149 * the ID to complete the object and then send that down
154 delta.setTenantID(original.getTenantID());
158 * Updates an existing SFC Port Pair Group*/
159 @Path("{portPairGroupUUID}")
161 @Produces({ MediaType.APPLICATION_JSON })
162 @Consumes({ MediaType.APPLICATION_JSON })
163 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
164 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
165 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
166 public Response updateSFCPortPairGroup(@PathParam("portPairGroupUUID") String sfcPortPairGroupUUID,
167 final NeutronSFCPortPairGroupRequest input) {
168 return update(sfcPortPairGroupUUID, input);
172 * Deletes the SFC Port Pair Group*/
174 @Path("{portPairGroupUUID}")
176 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
177 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
178 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
179 public Response deleteSFCPortPairGroup(@PathParam("portPairGroupUUID") String sfcPortPairGroupUUID) {
180 return delete(sfcPortPairGroupUUID);