remove irrelevant old JavaDoc from a long bygone era in northbound.api
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronSecurityGroupsNorthbound.java
1 /*
2  * Copyright (c) 2014, 2015 Red Hat, 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.INeutronSecurityGroupCRUD;
27 import org.opendaylight.neutron.spi.NeutronSecurityGroup;
28
29 /**
30  * Neutron Northbound REST APIs for Security Group.
31  */
32 @Path("/security-groups")
33 public final class NeutronSecurityGroupsNorthbound extends
34         AbstractNeutronNorthbound<NeutronSecurityGroup, NeutronSecurityGroupRequest, INeutronSecurityGroupCRUD> {
35
36     private static final String RESOURCE_NAME = "Security Group";
37
38     @Override
39     protected String getResourceName() {
40         return RESOURCE_NAME;
41     }
42
43     /**
44      * Returns a list of all Security Groups.
45      */
46     @GET
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 listGroups(
53             // return fields
54             @QueryParam("fields") List<String> fields,
55             // OpenStack security group attributes
56             @QueryParam("id") String querySecurityGroupUUID,
57             @QueryParam("name") String querySecurityGroupName,
58             @QueryParam("tenant_id") String querySecurityTenantID,
59             @QueryParam("limit") String limit,
60             @QueryParam("marker") String marker,
61             @QueryParam("page_reverse") String pageReverse) {
62         INeutronSecurityGroupCRUD securityGroupInterface = getNeutronCRUD();
63         List<NeutronSecurityGroup> allSecurityGroups = securityGroupInterface.getAll();
64         List<NeutronSecurityGroup> ans = new ArrayList<>();
65         for (NeutronSecurityGroup nsg : allSecurityGroups) {
66             if ((querySecurityGroupUUID == null || querySecurityGroupUUID.equals(nsg.getID()))
67                     && (querySecurityGroupName == null || querySecurityGroupName.equals(nsg.getName()))
68                     && (querySecurityTenantID == null || querySecurityTenantID.equals(nsg.getTenantID()))) {
69                 if (fields.size() > 0) {
70                     ans.add(nsg.extractFields(fields));
71                 } else {
72                     ans.add(nsg);
73                 }
74             }
75         }
76         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronSecurityGroupRequest(ans)).build();
77     }
78
79     /**
80      * Returns a specific Security Group.
81      */
82     @Path("{securityGroupUUID}")
83     @GET
84     @Produces({ MediaType.APPLICATION_JSON })
85     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
86             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
87             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
88             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
89             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
90     public Response showSecurityGroup(@PathParam("securityGroupUUID") String securityGroupUUID,
91             // return fields
92             @QueryParam("fields") List<String> fields) {
93         return show(securityGroupUUID, fields);
94     }
95
96     /**
97      * Creates new Security Group.
98      */
99     @POST
100     @Produces({ MediaType.APPLICATION_JSON })
101     @Consumes({ MediaType.APPLICATION_JSON })
102     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
103             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
104     public Response createSecurityGroups(final NeutronSecurityGroupRequest input) {
105         return create(input);
106     }
107
108     /**
109      * Updates a Security Group.
110      */
111     @Path("{securityGroupUUID}")
112     @PUT
113     @Produces({ MediaType.APPLICATION_JSON })
114     @Consumes({ MediaType.APPLICATION_JSON })
115     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
116             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
117             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
118     public Response updateSecurityGroup(@PathParam("securityGroupUUID") String securityGroupUUID,
119             final NeutronSecurityGroupRequest input) {
120         return update(securityGroupUUID, input);
121     }
122
123     /**
124      * Deletes a Security Group.
125      */
126     @Path("{securityGroupUUID}")
127     @DELETE
128     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
129             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
130             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
131     public Response deleteSecurityGroup(@PathParam("securityGroupUUID") String securityGroupUUID) {
132         return delete(securityGroupUUID);
133     }
134 }