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.INeutronFirewallCRUD;
27 import org.opendaylight.neutron.spi.NeutronFirewall;
30 * Neutron Northbound REST APIs for Firewall.
32 @Path("/fw/firewalls")
33 public final class NeutronFirewallNorthbound
34 extends AbstractNeutronNorthbound<NeutronFirewall, NeutronFirewallRequest, INeutronFirewallCRUD> {
36 private static final String RESOURCE_NAME = "Firewall";
39 protected String getResourceName() {
44 * Returns a list of all Firewalls.
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 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,
64 @QueryParam("limit") String limit,
65 @QueryParam("marker") String marker,
66 @QueryParam("page_reverse") String pageReverse
67 // sorting not supported
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));
86 //TODO: apply pagination to results
87 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronFirewallRequest(ans)).build();
91 * Returns a specific Firewall.
93 @Path("{firewallUUID}")
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,
103 @QueryParam("fields") List<String> fields) {
104 return show(firewallUUID, fields);
108 * Creates new Firewall.
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);
120 * Updates a Firewall.
122 @Path("{firewallUUID}")
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);
134 * Deletes a Firewall.
136 @Path("{firewallUUID}")
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);