/*
- * Copyright IBM Corporation, 2015. All rights reserved.
+ * Copyright (c) 2015 IBM Corporation and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import java.net.HttpURLConnection;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
-import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
*/
@Path("/vpn/ipsecpolicies")
-public class NeutronVPNIPSECPoliciesNorthbound {
+public class NeutronVPNIPSECPoliciesNorthbound extends AbstractNeutronNorthbound {
- private static final int HTTP_OK_BOTTOM = 200;
- private static final int HTTP_OK_TOP = 299;
- private static final String INTERFACE_NAME = "VPNIPSECPolicy CRUD Interface";
- private static final String UUID_NO_EXIST = "VPNIPSECPolicy 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 static final String RESOURCE_NAME = "VPNIPSECPolicy";
private NeutronVPNIPSECPolicy extractFields(NeutronVPNIPSECPolicy o, List<String> fields) {
return o.extractFields(fields);
}
+ private NeutronCRUDInterfaces getNeutronInterfaces() {
+ NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronVPNIPSECPolicyCRUD(this);
+ if (answer.getVPNIPSECPolicyInterface() == null) {
+ throw new ServiceUnavailableException("NeutronVPNIPSECPolicy CRUD Interface "
+ + RestMessages.SERVICEUNAVAILABLE.toString());
+ }
+ return answer;
+ }
+
@Context
UriInfo uriInfo;
@QueryParam("pfs") String queryPFS
// pagination and sorting are TODO
) {
- INeutronVPNIPSECPolicyCRUD labelInterface = NeutronCRUDInterfaces.getINeutronVPNIPSECPolicyCRUD(this);
- if (labelInterface == null) {
- throw new ServiceUnavailableException("NeutronVPNIPSECPolicy CRUD Interface "
- + RestMessages.SERVICEUNAVAILABLE.toString());
- }
- List<NeutronVPNIPSECPolicy> allNeutronVPNIPSECPolicies = labelInterface.getAllNeutronVPNIPSECPolicies();
+ INeutronVPNIPSECPolicyCRUD policyInterface = getNeutronInterfaces().getVPNIPSECPolicyInterface();
+ List<NeutronVPNIPSECPolicy> allNeutronVPNIPSECPolicies = policyInterface.getAllNeutronVPNIPSECPolicies();
List<NeutronVPNIPSECPolicy> ans = new ArrayList<NeutronVPNIPSECPolicy>();
Iterator<NeutronVPNIPSECPolicy> i = allNeutronVPNIPSECPolicies.iterator();
while (i.hasNext()) {
// return fields
@QueryParam("fields") List<String> fields
) {
- INeutronVPNIPSECPolicyCRUD policyInterface = NeutronCRUDInterfaces.getINeutronVPNIPSECPolicyCRUD(this);
- if (policyInterface == null) {
- throw new ServiceUnavailableException(INTERFACE_NAME
- + RestMessages.SERVICEUNAVAILABLE.toString());
- }
+ INeutronVPNIPSECPolicyCRUD policyInterface = getNeutronInterfaces().getVPNIPSECPolicyInterface();
if (!policyInterface.neutronVPNIPSECPolicyExists(policyUUID)) {
- throw new ResourceNotFoundException(UUID_NO_EXIST);
+ throw new ResourceNotFoundException(uuidNoExist(RESOURCE_NAME));
}
if (fields.size() > 0) {
NeutronVPNIPSECPolicy ans = policyInterface.getNeutronVPNIPSECPolicy(policyUUID);
@TypeHint(NeutronVPNIPSECPolicy.class)
@StatusCodes({
@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_NOT_IMPLEMENTED, condition = "Not Implemented"),
@ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
public Response createVPNIPSECPolicy(final NeutronVPNIPSECPolicyRequest input) {
- INeutronVPNIPSECPolicyCRUD ipsecPolicyInterface = NeutronCRUDInterfaces.getINeutronVPNIPSECPolicyCRUD(this);
- if (ipsecPolicyInterface == null) {
- throw new ServiceUnavailableException(INTERFACE_NAME
- + RestMessages.SERVICEUNAVAILABLE.toString());
- }
+ INeutronVPNIPSECPolicyCRUD ipsecPolicyInterface = getNeutronInterfaces().getVPNIPSECPolicyInterface();
if (input.isSingleton()) {
NeutronVPNIPSECPolicy singleton = input.getSingleton();
- /*
- * verify that the ipsecPolicy doesn't already exist (issue: is deeper inspection necessary?)
- */
- if (ipsecPolicyInterface.neutronVPNIPSECPolicyExists(singleton.getID())) {
- throw new BadRequestException("ipsecPolicy UUID already exists");
- }
Object[] instances = NeutronUtil.getInstances(INeutronVPNIPSECPolicyAware.class, this);
if (instances != null) {
if (instances.length > 0) {
@Consumes({ MediaType.APPLICATION_JSON })
@StatusCodes({
@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_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 updateVPNIPSECPolicy(
@PathParam("policyID") String policyUUID, final NeutronVPNIPSECPolicyRequest input
) {
- INeutronVPNIPSECPolicyCRUD ipsecPolicyInterface = NeutronCRUDInterfaces.getINeutronVPNIPSECPolicyCRUD(this);
- if (ipsecPolicyInterface == null) {
- throw new ServiceUnavailableException(INTERFACE_NAME
- + RestMessages.SERVICEUNAVAILABLE.toString());
- }
+ INeutronVPNIPSECPolicyCRUD ipsecPolicyInterface = getNeutronInterfaces().getVPNIPSECPolicyInterface();
- /*
- * ipsecPolicy has to exist and only a single delta can be supplied
- */
- if (!ipsecPolicyInterface.neutronVPNIPSECPolicyExists(policyUUID)) {
- throw new ResourceNotFoundException(UUID_NO_EXIST);
- }
- if (!input.isSingleton()) {
- throw new BadRequestException("Only single ipsecPolicy deltas supported");
- }
NeutronVPNIPSECPolicy singleton = input.getSingleton();
NeutronVPNIPSECPolicy original = ipsecPolicyInterface.getNeutronVPNIPSECPolicy(policyUUID);
- /*
- * attribute changes blocked by Neutron
- */
- if (singleton.getID() != null || singleton.getTenantID() != null) {
- throw new BadRequestException("Request attribute change not allowed");
- }
-
Object[] instances = NeutronUtil.getInstances(INeutronVPNIPSECPolicyAware.class, this);
if (instances != null) {
if (instances.length > 0) {
@DELETE
@StatusCodes({
@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 deleteVPNIPSECPolicy(
@PathParam("policyID") String policyUUID) {
- INeutronVPNIPSECPolicyCRUD policyInterface = NeutronCRUDInterfaces.getINeutronVPNIPSECPolicyCRUD(this);
- if (policyInterface == null) {
- throw new ServiceUnavailableException(INTERFACE_NAME
- + RestMessages.SERVICEUNAVAILABLE.toString());
- }
+ INeutronVPNIPSECPolicyCRUD policyInterface = getNeutronInterfaces().getVPNIPSECPolicyInterface();
- /*
- * verify that the policy exists and is not in use before removing it
- */
- if (!policyInterface.neutronVPNIPSECPolicyExists(policyUUID)) {
- throw new ResourceNotFoundException(UUID_NO_EXIST);
- }
NeutronVPNIPSECPolicy singleton = policyInterface.getNeutronVPNIPSECPolicy(policyUUID);
Object[] instances = NeutronUtil.getInstances(INeutronVPNIPSECPolicyAware.class, this);
if (instances != null) {