4b658e051f24f7f4a189934b4c04b2c790301858
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronSFCPortPairGroupsNorthbound.java
1 /*
2  * Copyright (c) 2016 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.neutron.northbound.api;
9
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;
28
29 /**
30  * Neutron Northbound REST APIs for OpenStack SFC Port Pair.<br>
31  * This class provides REST APIs for managing OpenStack SFC Port Pair
32  *
33  * <br>
34  * <br>
35  * Authentication scheme : <b>HTTP Basic</b><br>
36  * Authentication realm : <b>opendaylight</b><br>
37  * Transport : <b>HTTP and HTTPS</b><br>
38  * <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>
42  * More info :
43  * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
44  *
45  */
46
47 @Path("/sfc/portpairgroups")
48 public final class NeutronSFCPortPairGroupsNorthbound extends AbstractNeutronNorthbound<NeutronSFCPortPairGroup,
49         NeutronSFCPortPairGroupRequest, INeutronSFCPortPairGroupCRUD> {
50
51     private static final String RESOURCE_NAME = "Sfc Port Pair Group";
52
53     @Override
54     protected String getResourceName() {
55         return RESOURCE_NAME;
56     }
57
58     /**
59      * Returns a list of all SFC Port Pair Groups.
60      */
61
62     @GET
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 listSFCPortPairGroups(
69             // return fields
70             @QueryParam("fields") List<String> fields,
71             @QueryParam("id") String queryID,
72             @QueryParam("name") String queryName,
73             @QueryParam("tenant_id") String queryTenantID,
74             @QueryParam("port_pairs") List<String> queryPortPairsUUID) {
75         INeutronSFCPortPairGroupCRUD sfcPortPairGroupInterface = getNeutronCRUD();
76         List<NeutronSFCPortPairGroup> allSFCPortPairGroup = sfcPortPairGroupInterface.getAll();
77         List<NeutronSFCPortPairGroup> ans = new ArrayList<>();
78         for (NeutronSFCPortPairGroup sfcPortPairGroup : allSFCPortPairGroup) {
79             if ((queryID == null || queryID.equals(sfcPortPairGroup.getID()))
80                     && (queryName == null || queryName.equals(sfcPortPairGroup.getName()))
81                     && (queryTenantID == null || queryTenantID.equals(sfcPortPairGroup.getTenantID()))) {
82                 if (fields.size() > 0) {
83                     ans.add(sfcPortPairGroup.extractFields(fields));
84                 } else {
85                     ans.add(sfcPortPairGroup);
86                 }
87             }
88         }
89
90         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronSFCPortPairGroupRequest(ans)).build();
91
92     }
93
94     /**
95      * Returns a specific SFC Port Pair Group.
96      */
97
98     @Path("{portPairGroupUUID}")
99     @GET
100     @Produces({ MediaType.APPLICATION_JSON })
101     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
102             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
103             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
104             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
105             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
106     public Response showSFCPortPairGroup(@PathParam("portPairGroupUUID") String sfcPortPairGroupUUID,
107             // return fields
108             @QueryParam("fields") List<String> fields) {
109         return show(sfcPortPairGroupUUID, fields);
110     }
111
112     /**
113      * Creates new SFC Port Pair Group.
114      */
115     @POST
116     @Produces({ MediaType.APPLICATION_JSON })
117     @Consumes({ MediaType.APPLICATION_JSON })
118     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
119             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
120     public Response createSFCPortPairGroup(final NeutronSFCPortPairGroupRequest input) {
121         return create(input);
122     }
123
124     @Override
125     protected void updateDelta(String uuid, NeutronSFCPortPairGroup delta, NeutronSFCPortPairGroup original) {
126         /*
127          *  note: what we get appears to not be a delta but
128          * rather an incomplete updated object.  So we need to set
129          * the ID to complete the object and then send that down
130          * for folks to check
131          */
132
133         delta.setID(uuid);
134         delta.setTenantID(original.getTenantID());
135     }
136
137     /**
138      * Updates an existing SFC Port Pair Group.
139      */
140     @Path("{portPairGroupUUID}")
141     @PUT
142     @Produces({ MediaType.APPLICATION_JSON })
143     @Consumes({ MediaType.APPLICATION_JSON })
144     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
145             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
146             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
147     public Response updateSFCPortPairGroup(@PathParam("portPairGroupUUID") String sfcPortPairGroupUUID,
148             final NeutronSFCPortPairGroupRequest input) {
149         return update(sfcPortPairGroupUUID, input);
150     }
151
152     /**
153      * Deletes the SFC Port Pair Group.
154      */
155
156     @Path("{portPairGroupUUID}")
157     @DELETE
158     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
159             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
160             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
161     public Response deleteSFCPortPairGroup(@PathParam("portPairGroupUUID") String sfcPortPairGroupUUID) {
162         return delete(sfcPortPairGroupUUID);
163     }
164 }