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.
32 @Path("/sfc/portchains")
33 public final class NeutronSFCPortChainsNorthbound
34 extends AbstractNeutronNorthbound<NeutronSFCPortChain, NeutronSFCPortChainRequest, INeutronSFCPortChainCRUD> {
36 private static final String RESOURCE_NAME = "Sfc Port Chain";
39 protected String getResourceName() {
44 * Returns a list of all SFC Port Chains.
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 listSFCPortChains(
54 @QueryParam("fields") List<String> fields,
55 @QueryParam("id") String queryID,
56 @QueryParam("name") String queryName,
57 @QueryParam("tenant_id") String queryTenantID) {
58 INeutronSFCPortChainCRUD sfcPortChainInterface = getNeutronCRUD();
59 List<NeutronSFCPortChain> allSFCPortChain = sfcPortChainInterface.getAll();
60 List<NeutronSFCPortChain> ans = new ArrayList<>();
61 for (NeutronSFCPortChain sfcPortChain : allSFCPortChain) {
62 if ((queryID == null || queryID.equals(sfcPortChain.getID()))
63 && (queryName == null || queryName.equals(sfcPortChain.getName()))
64 && (queryTenantID == null || queryTenantID.equals(sfcPortChain.getTenantID()))) {
65 if (fields.size() > 0) {
66 ans.add(sfcPortChain.extractFields(fields));
68 ans.add(sfcPortChain);
73 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronSFCPortChainRequest(ans)).build();
78 * Returns a specific SFC Port Chain.
80 @Path("{portChainUUID}")
82 @Produces({ MediaType.APPLICATION_JSON })
83 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
84 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
85 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
86 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
87 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
88 public Response showSFCPortChain(@PathParam("portChainUUID") String sfcPortChainUUID,
90 @QueryParam("fields") List<String> fields) {
91 return show(sfcPortChainUUID, fields);
95 * Creates new SFC Port Chain.
98 @Produces({ MediaType.APPLICATION_JSON })
99 @Consumes({ MediaType.APPLICATION_JSON })
100 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
101 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
102 public Response createSFCPortChain(final NeutronSFCPortChainRequest input) {
103 return create(input);
107 protected void updateDelta(String uuid, NeutronSFCPortChain delta, NeutronSFCPortChain original) {
109 * note: what we get appears to not be a delta but
110 * rather an incomplete updated object. So we need to set
111 * the ID to complete the object and then send that down
115 delta.setTenantID(original.getTenantID());
119 * Updates an existing SFC Port Chain.
121 @Path("{portChainUUID}")
123 @Produces({ MediaType.APPLICATION_JSON })
124 @Consumes({ MediaType.APPLICATION_JSON })
125 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
126 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
127 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
128 public Response updateSFCPortChain(@PathParam("portChainUUID") String sfcPortChainUUID,
129 final NeutronSFCPortChainRequest input) {
130 return update(sfcPortChainUUID, input);
134 * Deletes the SFC Port Chain.
136 @Path("{portChainUUID}")
138 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
139 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
140 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
141 public Response deleteSFCPortChain(@PathParam("portChainUUID") String sfcPortChainUUID) {
142 return delete(sfcPortChainUUID);