package org.opendaylight.neutron.northbound.api;
+import java.net.HttpURLConnection;
import org.codehaus.enunciate.jaxrs.ResponseCode;
import org.codehaus.enunciate.jaxrs.StatusCodes;
import org.opendaylight.neutron.spi.INeutronFirewallAware;
import org.opendaylight.neutron.spi.INeutronFirewallCRUD;
-import org.opendaylight.neutron.spi.INeutronFirewallRuleCRUD;
import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
import org.opendaylight.neutron.spi.NeutronFirewall;
@Path("/fw/firewalls")
public class NeutronFirewallNorthbound {
+ private static final int HTTP_OK_BOTTOM = 200;
+ private static final int HTTP_OK_TOP = 299;
+ private static final String INTERFACE_NAME = "Firewall CRUD Interface";
+ private static final String UUID_NO_EXIST = "Firewall UUID does not exist.";
+ private static final String NO_PROVIDERS = "No providers registered. Please try again later";
+ private static final String NO_PROVIDER_LIST = "Couldn't get providers list. Please try again later";
+
private NeutronFirewall extractFields(NeutronFirewall o, List<String> fields) {
return o.extractFields(fields);
}
+ private NeutronCRUDInterfaces getNeutronInterfaces() {
+ NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronFirewallCRUD(this);
+ if (answer.getFirewallInterface() == null) {
+ throw new ServiceUnavailableException(INTERFACE_NAME
+ + RestMessages.SERVICEUNAVAILABLE.toString());
+ }
+ return answer;
+ }
+
/**
* Returns a list of all Firewalls */
@GET
@Produces({ MediaType.APPLICATION_JSON })
@StatusCodes({
- @ResponseCode(code = 200, condition = "Operation successful"),
- @ResponseCode(code = 401, condition = "Unauthorized"),
- @ResponseCode(code = 501, condition = "Not Implemented"),
- @ResponseCode(code = 503, condition = "No providers available") })
+ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
+ @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
+ @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
+ @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
public Response listGroups(
// return fields
@QueryParam("page_reverse") String pageReverse
// sorting not supported
) {
- INeutronFirewallCRUD firewallInterface = NeutronCRUDInterfaces.getINeutronFirewallCRUD(this);
- INeutronFirewallRuleCRUD firewallRuleInterface = NeutronCRUDInterfaces.getINeutronFirewallRuleCRUD(this);
-
- if (firewallInterface == null) {
- throw new ServiceUnavailableException("Firewall CRUD Interface "
- + RestMessages.SERVICEUNAVAILABLE.toString());
- }
+ INeutronFirewallCRUD firewallInterface = getNeutronInterfaces().getFirewallInterface();
List<NeutronFirewall> allFirewalls = firewallInterface.getAllNeutronFirewalls();
List<NeutronFirewall> ans = new ArrayList<NeutronFirewall>();
Iterator<NeutronFirewall> i = allFirewalls.iterator();
}
}
//TODO: apply pagination to results
- return Response.status(200).entity(
+ return Response.status(HttpURLConnection.HTTP_OK).entity(
new NeutronFirewallRequest(ans)).build();
}
@GET
@Produces({ MediaType.APPLICATION_JSON })
@StatusCodes({
- @ResponseCode(code = 200, condition = "Operation successful"),
- @ResponseCode(code = 401, condition = "Unauthorized"),
- @ResponseCode(code = 404, condition = "Not Found"),
- @ResponseCode(code = 501, condition = "Not Implemented"),
- @ResponseCode(code = 503, condition = "No providers available") })
+ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
+ @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
+ @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
+ @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
+ @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
public Response showFirewall(@PathParam("firewallUUID") String firewallUUID,
// return fields
@QueryParam("fields") List<String> fields) {
- INeutronFirewallCRUD firewallInterface = NeutronCRUDInterfaces.getINeutronFirewallCRUD(this);
- if (firewallInterface == null) {
- throw new ServiceUnavailableException("Firewall CRUD Interface "
- + RestMessages.SERVICEUNAVAILABLE.toString());
- }
+ INeutronFirewallCRUD firewallInterface = getNeutronInterfaces().getFirewallInterface();
if (!firewallInterface.neutronFirewallExists(firewallUUID)) {
- throw new ResourceNotFoundException("Firewall UUID does not exist.");
+ throw new ResourceNotFoundException(UUID_NO_EXIST);
}
if (fields.size() > 0) {
NeutronFirewall ans = firewallInterface.getNeutronFirewall(firewallUUID);
- return Response.status(200).entity(
+ return Response.status(HttpURLConnection.HTTP_OK).entity(
new NeutronFirewallRequest(extractFields(ans, fields))).build();
} else {
- return Response.status(200).entity(new NeutronFirewallRequest(firewallInterface.getNeutronFirewall(firewallUUID))).build();
+ return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronFirewallRequest(firewallInterface.getNeutronFirewall(firewallUUID))).build();
}
}
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
@StatusCodes({
- @ResponseCode(code = 201, condition = "Created"),
- @ResponseCode(code = 400, condition = "Bad Request"),
- @ResponseCode(code = 401, condition = "Unauthorized"),
- @ResponseCode(code = 403, condition = "Forbidden"),
- @ResponseCode(code = 404, condition = "Not Found"),
- @ResponseCode(code = 409, condition = "Conflict"),
- @ResponseCode(code = 501, condition = "Not Implemented"),
- @ResponseCode(code = 503, condition = "No providers available") })
+ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
+ @ResponseCode(code = HttpURLConnection.HTTP_BAD_REQUEST, condition = "Bad Request"),
+ @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
+ @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
+ @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
+ @ResponseCode(code = HttpURLConnection.HTTP_CONFLICT, condition = "Conflict"),
+ @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
+ @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
public Response createFirewalls(final NeutronFirewallRequest input) {
- INeutronFirewallCRUD firewallInterface = NeutronCRUDInterfaces.getINeutronFirewallCRUD(this);
- if (firewallInterface == null) {
- throw new ServiceUnavailableException("Firewall CRUD Interface "
- + RestMessages.SERVICEUNAVAILABLE.toString());
- }
+ INeutronFirewallCRUD firewallInterface = getNeutronInterfaces().getFirewallInterface();
if (input.isSingleton()) {
NeutronFirewall singleton = input.getSingleton();
for (Object instance : instances) {
INeutronFirewallAware service = (INeutronFirewallAware) instance;
int status = service.canCreateNeutronFirewall(singleton);
- if (status < 200 || status > 299) {
+ if (status < HTTP_OK_BOTTOM || status > HTTP_OK_TOP) {
return Response.status(status).build();
}
}
} else {
- throw new ServiceUnavailableException("No providers registered. Please try again later");
+ throw new ServiceUnavailableException(NO_PROVIDERS);
}
} else {
- throw new ServiceUnavailableException("Couldn't get providers list. Please try again later");
+ throw new ServiceUnavailableException(NO_PROVIDER_LIST);
}
firewallInterface.addNeutronFirewall(singleton);
if (instances != null) {
for (Object instance : instances) {
INeutronFirewallAware service = (INeutronFirewallAware) instance;
int status = service.canCreateNeutronFirewall(test);
- if (status < 200 || status > 299) {
+ if (status < HTTP_OK_BOTTOM || status > HTTP_OK_TOP) {
return Response.status(status).build();
}
}
} else {
- throw new ServiceUnavailableException("No providers registered. Please try again later");
+ throw new ServiceUnavailableException(NO_PROVIDERS);
}
} else {
- throw new ServiceUnavailableException("Couldn't get providers list. Please try again later");
+ throw new ServiceUnavailableException(NO_PROVIDER_LIST);
}
}
}
}
}
- return Response.status(201).entity(input).build();
+ return Response.status(HttpURLConnection.HTTP_CREATED).entity(input).build();
}
/**
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
@StatusCodes({
- @ResponseCode(code = 200, condition = "Operation successful"),
- @ResponseCode(code = 400, condition = "Bad Request"),
- @ResponseCode(code = 401, condition = "Unauthorized"),
- @ResponseCode(code = 403, condition = "Forbidden"),
- @ResponseCode(code = 404, condition = "Not Found"),
- @ResponseCode(code = 501, condition = "Not Implemented"),
- @ResponseCode(code = 503, condition = "No providers available") })
+ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
+ @ResponseCode(code = HttpURLConnection.HTTP_BAD_REQUEST, condition = "Bad Request"),
+ @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
+ @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
+ @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
+ @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
+ @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
public Response updateFirewall(
@PathParam("firewallUUID") String firewallUUID, final NeutronFirewallRequest input) {
- INeutronFirewallCRUD firewallInterface = NeutronCRUDInterfaces.getINeutronFirewallCRUD(this);
- if (firewallInterface == null) {
- throw new ServiceUnavailableException("Firewall CRUD Interface "
- + RestMessages.SERVICEUNAVAILABLE.toString());
- }
+ INeutronFirewallCRUD firewallInterface = getNeutronInterfaces().getFirewallInterface();
/*
* verify the Firewall exists and there is only one delta provided
*/
if (!firewallInterface.neutronFirewallExists(firewallUUID)) {
- throw new ResourceNotFoundException("Firewall UUID does not exist.");
+ throw new ResourceNotFoundException(UUID_NO_EXIST);
}
if (!input.isSingleton()) {
throw new BadRequestException("Only singleton edit supported");
for (Object instance : instances) {
INeutronFirewallAware service = (INeutronFirewallAware) instance;
int status = service.canUpdateNeutronFirewall(delta, original);
- if (status < 200 || status > 299) {
+ if (status < HTTP_OK_BOTTOM || status > HTTP_OK_TOP) {
return Response.status(status).build();
}
}
} else {
- throw new ServiceUnavailableException("No providers registered. Please try again later");
+ throw new ServiceUnavailableException(NO_PROVIDERS);
}
} else {
- throw new ServiceUnavailableException("Couldn't get providers list. Please try again later");
+ throw new ServiceUnavailableException(NO_PROVIDER_LIST);
}
/*
service.neutronFirewallUpdated(updatedFirewall);
}
}
- return Response.status(200).entity(new NeutronFirewallRequest(firewallInterface.getNeutronFirewall(firewallUUID))).build();
+ return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronFirewallRequest(firewallInterface.getNeutronFirewall(firewallUUID))).build();
}
/**
@Path("{firewallUUID}")
@DELETE
@StatusCodes({
- @ResponseCode(code = 204, condition = "No Content"),
- @ResponseCode(code = 401, condition = "Unauthorized"),
- @ResponseCode(code = 404, condition = "Not Found"),
- @ResponseCode(code = 409, condition = "Conflict"),
- @ResponseCode(code = 501, condition = "Not Implemented"),
- @ResponseCode(code = 503, condition = "No providers available") })
+ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
+ @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
+ @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
+ @ResponseCode(code = HttpURLConnection.HTTP_CONFLICT, condition = "Conflict"),
+ @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
+ @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
public Response deleteFirewall(
@PathParam("firewallUUID") String firewallUUID) {
- INeutronFirewallCRUD firewallInterface = NeutronCRUDInterfaces.getINeutronFirewallCRUD(this);
- if (firewallInterface == null) {
- throw new ServiceUnavailableException("Firewall CRUD Interface "
- + RestMessages.SERVICEUNAVAILABLE.toString());
- }
+ INeutronFirewallCRUD firewallInterface = getNeutronInterfaces().getFirewallInterface();
/*
* verify the Firewall exists and it isn't currently in use
*/
if (!firewallInterface.neutronFirewallExists(firewallUUID)) {
- throw new ResourceNotFoundException("Firewall UUID does not exist.");
+ throw new ResourceNotFoundException(UUID_NO_EXIST);
}
if (firewallInterface.neutronFirewallInUse(firewallUUID)) {
- return Response.status(409).build();
+ return Response.status(HttpURLConnection.HTTP_CONFLICT).build();
}
NeutronFirewall singleton = firewallInterface.getNeutronFirewall(firewallUUID);
Object[] instances = NeutronUtil.getInstances(INeutronFirewallAware.class, this);
for (Object instance : instances) {
INeutronFirewallAware service = (INeutronFirewallAware) instance;
int status = service.canDeleteNeutronFirewall(singleton);
- if (status < 200 || status > 299) {
+ if (status < HTTP_OK_BOTTOM || status > HTTP_OK_TOP) {
return Response.status(status).build();
}
}
} else {
- throw new ServiceUnavailableException("No providers registered. Please try again later");
+ throw new ServiceUnavailableException(NO_PROVIDERS);
}
} else {
- throw new ServiceUnavailableException("Couldn't get providers list. Please try again later");
+ throw new ServiceUnavailableException(NO_PROVIDER_LIST);
}
/*
service.neutronFirewallDeleted(singleton);
}
}
- return Response.status(204).build();
+ return Response.status(HttpURLConnection.HTTP_NO_CONTENT).build();
}
}