remove irrelevant old JavaDoc from a long bygone era in northbound.api
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronSecurityRulesNorthbound.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.INeutronSecurityRuleCRUD;
27 import org.opendaylight.neutron.spi.NeutronSecurityRule;
28
29 /**
30  * Neutron Northbound REST APIs for Security Rule.<br>
31  */
32 @Path("/security-group-rules")
33 public final class NeutronSecurityRulesNorthbound
34         extends AbstractNeutronNorthbound<NeutronSecurityRule, NeutronSecurityRuleRequest, INeutronSecurityRuleCRUD> {
35
36     private static final String RESOURCE_NAME = "Security Rule";
37
38     @Override
39     protected String getResourceName() {
40         return RESOURCE_NAME;
41     }
42
43     /**
44      * Returns a list of all Security Rules.
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 listRules(
53             // return fields
54             @QueryParam("fields") List<String> fields,
55             // OpenStack security rule attributes
56             @QueryParam("id") String querySecurityRuleUUID,
57             @QueryParam("direction") String querySecurityRuleDirection,
58             @QueryParam("protocol") String querySecurityRuleProtocol,
59             @QueryParam("port_range_min") Integer querySecurityRulePortMin,
60             @QueryParam("port_range_max") Integer querySecurityRulePortMax,
61             @QueryParam("ethertype") String querySecurityRuleEthertype,
62             @QueryParam("remote_ip_prefix") String querySecurityRuleIpPrefix,
63             @QueryParam("remote_group_id") String querySecurityRemoteGroupID,
64             @QueryParam("security_group_id") String querySecurityRuleGroupID,
65             @QueryParam("tenant_id") String querySecurityRuleTenantID,
66             @QueryParam("limit") String limit,
67             @QueryParam("marker") String marker,
68             @QueryParam("page_reverse") String pageReverse) {
69         INeutronSecurityRuleCRUD securityRuleInterface = getNeutronCRUD();
70         List<NeutronSecurityRule> allSecurityRules = securityRuleInterface.getAll();
71         List<NeutronSecurityRule> ans = new ArrayList<>();
72         for (NeutronSecurityRule nsr : allSecurityRules) {
73             if ((querySecurityRuleUUID == null || querySecurityRuleUUID.equals(nsr.getID()))
74                     && (querySecurityRuleDirection == null
75                             || querySecurityRuleDirection.equals(nsr.getSecurityRuleDirection()))
76                     && (querySecurityRuleProtocol == null
77                             || querySecurityRuleProtocol.equals(nsr.getSecurityRuleProtocol()))
78                     && (querySecurityRulePortMin == null
79                             || querySecurityRulePortMin.equals(nsr.getSecurityRulePortMin()))
80                     && (querySecurityRulePortMax == null
81                             || querySecurityRulePortMax.equals(nsr.getSecurityRulePortMax()))
82                     && (querySecurityRuleEthertype == null
83                             || querySecurityRuleEthertype.equals(nsr.getSecurityRuleEthertype()))
84                     && (querySecurityRuleIpPrefix == null
85                             || querySecurityRuleIpPrefix.equals(nsr.getSecurityRuleRemoteIpPrefix()))
86                     && (querySecurityRuleGroupID == null
87                             || querySecurityRuleGroupID.equals(nsr.getSecurityRuleGroupID()))
88                     && (querySecurityRemoteGroupID == null
89                             || querySecurityRemoteGroupID.equals(nsr.getSecurityRemoteGroupID()))
90                     && (querySecurityRuleTenantID == null || querySecurityRuleTenantID.equals(nsr.getTenantID()))) {
91                 if (fields.size() > 0) {
92                     ans.add(nsr.extractFields(fields));
93                 } else {
94                     ans.add(nsr);
95                 }
96             }
97         }
98         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronSecurityRuleRequest(ans)).build();
99     }
100
101     /**
102      * Returns a specific Security Rule.
103      */
104     @Path("{securityRuleUUID}")
105     @GET
106     @Produces({ MediaType.APPLICATION_JSON })
107     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
108             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
109             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
110             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
111             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
112     public Response showSecurityRule(@PathParam("securityRuleUUID") String securityRuleUUID,
113             // return fields
114             @QueryParam("fields") List<String> fields) {
115         return show(securityRuleUUID, fields);
116     }
117
118     /**
119      * Creates new Security Rule.
120      */
121     @POST
122     @Produces({ MediaType.APPLICATION_JSON })
123     @Consumes({ MediaType.APPLICATION_JSON })
124     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
125             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
126     public Response createSecurityRules(final NeutronSecurityRuleRequest input) {
127         return create(input);
128     }
129
130     /**
131      * Updates a Security Rule.
132      */
133     @Path("{securityRuleUUID}")
134     @PUT
135     @Produces({ MediaType.APPLICATION_JSON })
136     @Consumes({ MediaType.APPLICATION_JSON })
137     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
138             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
139             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
140     public Response updateSecurityRule(@PathParam("securityRuleUUID") String securityRuleUUID,
141             final NeutronSecurityRuleRequest input) {
142         return update(securityRuleUUID, input);
143     }
144
145     /**
146      * Deletes a Security Rule.
147      */
148     @Path("{securityRuleUUID}")
149     @DELETE
150     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
151             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
152             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
153     public Response deleteSecurityRule(@PathParam("securityRuleUUID") String securityRuleUUID) {
154         return delete(securityRuleUUID);
155     }
156 }