[Boron] remove I*Aware interface
[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
9 package org.opendaylight.neutron.northbound.api;
10
11 import java.net.HttpURLConnection;
12
13 import org.codehaus.enunciate.jaxrs.ResponseCode;
14 import org.codehaus.enunciate.jaxrs.StatusCodes;
15 import org.opendaylight.neutron.spi.INeutronFirewallCRUD;
16 import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
17 import org.opendaylight.neutron.spi.NeutronFirewall;
18
19 import javax.ws.rs.Consumes;
20 import javax.ws.rs.DELETE;
21 import javax.ws.rs.GET;
22 import javax.ws.rs.POST;
23 import javax.ws.rs.PUT;
24 import javax.ws.rs.Path;
25 import javax.ws.rs.PathParam;
26 import javax.ws.rs.Produces;
27 import javax.ws.rs.QueryParam;
28 import javax.ws.rs.core.MediaType;
29 import javax.ws.rs.core.Response;
30 import java.util.ArrayList;
31 import java.util.List;
32
33 /**
34  * Neutron Northbound REST APIs for Firewall.<br>
35  * This class provides REST APIs for managing neutron Firewall
36  *
37  * <br>
38  * <br>
39  * Authentication scheme : <b>HTTP Basic</b><br>
40  * Authentication realm : <b>opendaylight</b><br>
41  * Transport : <b>HTTP and HTTPS</b><br>
42  * <br>
43  * HTTPS Authentication is disabled by default. Administrator can enable it in
44  * tomcat-server.xml after adding a proper keystore / SSL certificate from a
45  * trusted authority.<br>
46  * More info :
47  * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
48  *
49  */
50 @Path("/fw/firewalls")
51 public class NeutronFirewallNorthbound
52     extends AbstractNeutronNorthbound<NeutronFirewall, NeutronFirewallRequest, INeutronFirewallCRUD> {
53
54     private static final String RESOURCE_NAME = "Firewall";
55
56     @Override
57     protected String getResourceName() {
58         return RESOURCE_NAME;
59     }
60
61     @Override
62     protected NeutronFirewall extractFields(NeutronFirewall o, List<String> fields) {
63         return o.extractFields(fields);
64     }
65
66     @Override
67     protected NeutronFirewallRequest newNeutronRequest(NeutronFirewall o) {
68         return new NeutronFirewallRequest(o);
69     }
70
71     @Override
72     protected INeutronFirewallCRUD getNeutronCRUD() {
73         NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronFirewallCRUD(this);
74         if (answer.getFirewallInterface() == null) {
75             throw new ServiceUnavailableException(serviceUnavailable());
76         }
77         return answer.getFirewallInterface();
78     }
79
80     /**
81      * Returns a list of all Firewalls */
82     @GET
83     @Produces({ MediaType.APPLICATION_JSON })
84     @StatusCodes({
85             @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
86             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
87             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
88             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
89
90     public Response listGroups(
91             // return fields
92             @QueryParam("fields") List<String> fields,
93             // OpenStack firewall attributes
94             @QueryParam("id") String queryFirewallUUID,
95             @QueryParam("tenant_id") String queryFirewallTenantID,
96             @QueryParam("name") String queryFirewallName,
97             @QueryParam("admin_state_up") Boolean queryFirewallAdminStateIsUp,
98             @QueryParam("shared") Boolean queryFirewallIsShared,
99             @QueryParam("firewall_policy_id") String queryFirewallPolicyID,
100             // pagination
101             @QueryParam("limit") String limit,
102             @QueryParam("marker") String marker,
103             @QueryParam("page_reverse") String pageReverse
104             // sorting not supported
105     ) {
106         INeutronFirewallCRUD firewallInterface = getNeutronCRUD();
107         List<NeutronFirewall> ans = new ArrayList<NeutronFirewall>();
108         for (NeutronFirewall nsg : firewallInterface.getAllNeutronFirewalls()) {
109             if ((queryFirewallUUID == null ||
110                 queryFirewallUUID.equals(nsg.getID())) &&
111                 (queryFirewallTenantID == null ||
112                     queryFirewallTenantID.equals(nsg.getTenantID())) &&
113                 (queryFirewallName == null ||
114                     queryFirewallName.equals(nsg.getFirewallName())) &&
115                 (queryFirewallAdminStateIsUp == null ||
116                     queryFirewallAdminStateIsUp.equals(nsg.getFirewallAdminStateIsUp())) &&
117                 (queryFirewallIsShared == null ||
118                     queryFirewallIsShared.equals(nsg.getFirewallIsShared())) &&
119                 (queryFirewallPolicyID == null ||
120                     queryFirewallPolicyID.equals(nsg.getFirewallPolicyID()))) {
121                 if (fields.size() > 0) {
122                     ans.add(extractFields(nsg,fields));
123                 } else {
124                     ans.add(nsg);
125                 }
126             }
127         }
128         //TODO: apply pagination to results
129         return Response.status(HttpURLConnection.HTTP_OK).entity(
130                 new NeutronFirewallRequest(ans)).build();
131     }
132
133     /**
134      * Returns a specific Firewall */
135
136     @Path("{firewallUUID}")
137     @GET
138     @Produces({ MediaType.APPLICATION_JSON })
139     @StatusCodes({
140             @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
141             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
142             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
143             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
144             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
145     public Response showFirewall(@PathParam("firewallUUID") String firewallUUID,
146                                       // return fields
147                                       @QueryParam("fields") List<String> fields) {
148         return show(firewallUUID, fields);
149     }
150
151     /**
152      * Creates new Firewall */
153
154     @POST
155     @Produces({ MediaType.APPLICATION_JSON })
156     @Consumes({ MediaType.APPLICATION_JSON })
157     @StatusCodes({
158             @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
159             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
160     public Response createFirewalls(final NeutronFirewallRequest input) {
161         return create(input);
162     }
163
164     /**
165      * Updates a Firewall */
166
167     @Path("{firewallUUID}")
168     @PUT
169     @Produces({ MediaType.APPLICATION_JSON })
170     @Consumes({ MediaType.APPLICATION_JSON })
171     @StatusCodes({
172             @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
173             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
174             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
175     public Response updateFirewall(
176             @PathParam("firewallUUID") String firewallUUID, final NeutronFirewallRequest input) {
177         return update(firewallUUID, input);
178     }
179
180     /**
181      * Deletes a Firewall */
182
183     @Path("{firewallUUID}")
184     @DELETE
185     @StatusCodes({
186             @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
187             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
188             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
189     public Response deleteFirewall(
190             @PathParam("firewallUUID") String firewallUUID) {
191         return delete(firewallUUID);
192     }
193 }