2 * Copyright (c) 2014, 2015 Red Hat, Inc. and others. All rights reserved.
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
8 package org.opendaylight.neutron.northbound.api;
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.INeutronFirewallPolicyCRUD;
27 import org.opendaylight.neutron.spi.NeutronFirewallPolicy;
30 * Neutron Northbound REST APIs for Firewall Policies.
32 @Path("/fw/firewall_policies")
33 public final class NeutronFirewallPolicyNorthbound extends
34 AbstractNeutronNorthbound<NeutronFirewallPolicy, NeutronFirewallPolicyRequest, INeutronFirewallPolicyCRUD> {
36 private static final String RESOURCE_NAME = "Firewall Policy";
39 protected String getResourceName() {
44 * Returns a list of all Firewall Policies.
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") })
53 public Response listGroups(
55 @QueryParam("fields") List<String> fields,
56 // OpenStack Firewall Policy attributes
57 @QueryParam("id") String queryFirewallPolicyUUID,
58 @QueryParam("tenant_id") String queryFirewallPolicyTenantID,
59 @QueryParam("name") String queryFirewallPolicyName,
60 @QueryParam("shared") Boolean querySecurityPolicyIsShared,
61 @QueryParam("audited") Boolean querySecurityPolicyIsAudited,
63 @QueryParam("limit") String limit,
64 @QueryParam("marker") String marker,
65 @QueryParam("page_reverse") String pageReverse
66 // sorting not supported
68 INeutronFirewallPolicyCRUD firewallPolicyInterface = getNeutronCRUD();
69 List<NeutronFirewallPolicy> ans = new ArrayList<>();
70 for (NeutronFirewallPolicy nsg : firewallPolicyInterface.getAll()) {
71 if ((queryFirewallPolicyUUID == null || queryFirewallPolicyUUID.equals(nsg.getID()))
72 && (queryFirewallPolicyTenantID == null || queryFirewallPolicyTenantID.equals(nsg.getTenantID()))
73 && (queryFirewallPolicyName == null || queryFirewallPolicyName.equals(nsg.getName()))
74 && (querySecurityPolicyIsShared == null
75 || querySecurityPolicyIsShared.equals(nsg.getFirewallPolicyIsShared()))
76 && (querySecurityPolicyIsAudited == null
77 || querySecurityPolicyIsAudited.equals(nsg.getFirewallPolicyIsAudited()))) {
78 if (fields.size() > 0) {
79 ans.add(nsg.extractFields(fields));
85 //TODO: apply pagination to results
86 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronFirewallPolicyRequest(ans)).build();
90 * Returns a specific Firewall Policy.
92 @Path("{firewallPolicyUUID}")
94 @Produces({ MediaType.APPLICATION_JSON })
95 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
96 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
97 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
98 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
99 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
100 public Response showFirewallPolicy(@PathParam("firewallPolicyUUID") String firewallPolicyUUID,
102 @QueryParam("fields") List<String> fields) {
103 return show(firewallPolicyUUID, fields);
107 * Creates new Firewall Policy.
110 @Produces({ MediaType.APPLICATION_JSON })
111 @Consumes({ MediaType.APPLICATION_JSON })
112 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
113 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
114 public Response createFirewallPolicies(final NeutronFirewallPolicyRequest input) {
115 return create(input);
119 * Updates a Firewall Policy.
121 @Path("{firewallPolicyUUID}")
123 @Produces({ MediaType.APPLICATION_JSON })
124 @Consumes({ MediaType.APPLICATION_JSON })
125 //@TypeHint(OpenStackSubnets.class)
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 updateFirewallPolicy(@PathParam("firewallPolicyUUID") String firewallPolicyUUID,
130 final NeutronFirewallPolicyRequest input) {
131 return update(firewallPolicyUUID, input);
135 * Deletes a Firewall Policy.
137 @Path("{firewallPolicyUUID}")
139 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
140 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
141 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
142 public Response deleteFirewallPolicy(@PathParam("firewallPolicyUUID") String firewallPolicyUUID) {
143 return delete(firewallPolicyUUID);