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.INeutronSFCPortPairGroupCRUD;
27 import org.opendaylight.neutron.spi.NeutronSFCPortPairGroup;
30 * Neutron Northbound REST APIs for OpenStack SFC Port Pair.
32 @Path("/sfc/portpairgroups")
33 public final class NeutronSFCPortPairGroupsNorthbound extends AbstractNeutronNorthbound<NeutronSFCPortPairGroup,
34 NeutronSFCPortPairGroupRequest, INeutronSFCPortPairGroupCRUD> {
36 private static final String RESOURCE_NAME = "Sfc Port Pair Group";
39 protected String getResourceName() {
44 * Returns a list of all SFC Port Pair Groups.
47 @Produces({ MediaType.APPLICATION_JSON })
48 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
49 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
50 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
51 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
52 public Response listSFCPortPairGroups(
54 @QueryParam("fields") List<String> fields,
55 @QueryParam("id") String queryID,
56 @QueryParam("name") String queryName,
57 @QueryParam("tenant_id") String queryTenantID,
58 @QueryParam("port_pairs") List<String> queryPortPairsUUID) {
59 INeutronSFCPortPairGroupCRUD sfcPortPairGroupInterface = getNeutronCRUD();
60 List<NeutronSFCPortPairGroup> allSFCPortPairGroup = sfcPortPairGroupInterface.getAll();
61 List<NeutronSFCPortPairGroup> ans = new ArrayList<>();
62 for (NeutronSFCPortPairGroup sfcPortPairGroup : allSFCPortPairGroup) {
63 if ((queryID == null || queryID.equals(sfcPortPairGroup.getID()))
64 && (queryName == null || queryName.equals(sfcPortPairGroup.getName()))
65 && (queryTenantID == null || queryTenantID.equals(sfcPortPairGroup.getTenantID()))) {
66 if (fields.size() > 0) {
67 ans.add(sfcPortPairGroup.extractFields(fields));
69 ans.add(sfcPortPairGroup);
74 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronSFCPortPairGroupRequest(ans)).build();
79 * Returns a specific SFC Port Pair Group.
81 @Path("{portPairGroupUUID}")
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_FOUND, condition = "Not Found"),
87 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
88 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
89 public Response showSFCPortPairGroup(@PathParam("portPairGroupUUID") String sfcPortPairGroupUUID,
91 @QueryParam("fields") List<String> fields) {
92 return show(sfcPortPairGroupUUID, fields);
96 * Creates new SFC Port Pair Group.
99 @Produces({ MediaType.APPLICATION_JSON })
100 @Consumes({ MediaType.APPLICATION_JSON })
101 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
102 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
103 public Response createSFCPortPairGroup(final NeutronSFCPortPairGroupRequest input) {
104 return create(input);
108 protected void updateDelta(String uuid, NeutronSFCPortPairGroup delta, NeutronSFCPortPairGroup original) {
110 * Note: what we get appears to not be a delta but
111 * rather an incomplete updated object. So we need to set
112 * the ID to complete the object and then send that down
116 delta.setTenantID(original.getTenantID());
120 * Updates an existing SFC Port Pair Group.
122 @Path("{portPairGroupUUID}")
124 @Produces({ MediaType.APPLICATION_JSON })
125 @Consumes({ MediaType.APPLICATION_JSON })
126 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
127 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
128 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
129 public Response updateSFCPortPairGroup(@PathParam("portPairGroupUUID") String sfcPortPairGroupUUID,
130 final NeutronSFCPortPairGroupRequest input) {
131 return update(sfcPortPairGroupUUID, input);
135 * Deletes the SFC Port Pair Group.
137 @Path("{portPairGroupUUID}")
139 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
140 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
141 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
142 public Response deleteSFCPortPairGroup(@PathParam("portPairGroupUUID") String sfcPortPairGroupUUID) {
143 return delete(sfcPortPairGroupUUID);