remove irrelevant old JavaDoc from a long bygone era in northbound.api
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronFirewallNorthbound.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.INeutronFirewallCRUD;
27 import org.opendaylight.neutron.spi.NeutronFirewall;
28
29 /**
30  * Neutron Northbound REST APIs for Firewall.
31  */
32 @Path("/fw/firewalls")
33 public final class NeutronFirewallNorthbound
34         extends AbstractNeutronNorthbound<NeutronFirewall, NeutronFirewallRequest, INeutronFirewallCRUD> {
35
36     private static final String RESOURCE_NAME = "Firewall";
37
38     @Override
39     protected String getResourceName() {
40         return RESOURCE_NAME;
41     }
42
43     /**
44      * Returns a list of all Firewalls.
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
53     public Response listGroups(
54             // return fields
55             @QueryParam("fields") List<String> fields,
56             // OpenStack firewall attributes
57             @QueryParam("id") String queryFirewallUUID,
58             @QueryParam("tenant_id") String queryFirewallTenantID,
59             @QueryParam("name") String queryFirewallName,
60             @QueryParam("admin_state_up") Boolean queryFirewallAdminStateIsUp,
61             @QueryParam("shared") Boolean queryFirewallIsShared,
62             @QueryParam("firewall_policy_id") String queryFirewallPolicyID,
63             // pagination
64             @QueryParam("limit") String limit,
65             @QueryParam("marker") String marker,
66             @QueryParam("page_reverse") String pageReverse
67     // sorting not supported
68     ) {
69         INeutronFirewallCRUD firewallInterface = getNeutronCRUD();
70         List<NeutronFirewall> ans = new ArrayList<>();
71         for (NeutronFirewall nsg : firewallInterface.getAll()) {
72             if ((queryFirewallUUID == null || queryFirewallUUID.equals(nsg.getID()))
73                     && (queryFirewallTenantID == null || queryFirewallTenantID.equals(nsg.getTenantID()))
74                     && (queryFirewallName == null || queryFirewallName.equals(nsg.getName()))
75                     && (queryFirewallAdminStateIsUp == null
76                             || queryFirewallAdminStateIsUp.equals(nsg.getFirewallAdminStateIsUp()))
77                     && (queryFirewallIsShared == null || queryFirewallIsShared.equals(nsg.getFirewallIsShared()))
78                     && (queryFirewallPolicyID == null || queryFirewallPolicyID.equals(nsg.getFirewallPolicyID()))) {
79                 if (fields.size() > 0) {
80                     ans.add(nsg.extractFields(fields));
81                 } else {
82                     ans.add(nsg);
83                 }
84             }
85         }
86         //TODO: apply pagination to results
87         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronFirewallRequest(ans)).build();
88     }
89
90     /**
91      * Returns a specific Firewall.
92      */
93     @Path("{firewallUUID}")
94     @GET
95     @Produces({ MediaType.APPLICATION_JSON })
96     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
97             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
98             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
99             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
100             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
101     public Response showFirewall(@PathParam("firewallUUID") String firewallUUID,
102             // return fields
103             @QueryParam("fields") List<String> fields) {
104         return show(firewallUUID, fields);
105     }
106
107     /**
108      * Creates new Firewall.
109      */
110     @POST
111     @Produces({ MediaType.APPLICATION_JSON })
112     @Consumes({ MediaType.APPLICATION_JSON })
113     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
114             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
115     public Response createFirewalls(final NeutronFirewallRequest input) {
116         return create(input);
117     }
118
119     /**
120      * Updates a Firewall.
121      */
122     @Path("{firewallUUID}")
123     @PUT
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 updateFirewall(@PathParam("firewallUUID") String firewallUUID, final NeutronFirewallRequest input) {
130         return update(firewallUUID, input);
131     }
132
133     /**
134      * Deletes a Firewall.
135      */
136     @Path("{firewallUUID}")
137     @DELETE
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 deleteFirewall(@PathParam("firewallUUID") String firewallUUID) {
142         return delete(firewallUUID);
143     }
144 }