[Boron] remove I*Aware interface
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronVPNIPSECPoliciesNorthbound.java
index c37c34d6fd503da89242093d8e579a7e3ace8f60..9510278c9e64a05bcfd44c5fa979415c93250f57 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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,
@@ -31,7 +31,6 @@ import javax.ws.rs.core.UriInfo;
 import org.codehaus.enunciate.jaxrs.ResponseCode;
 import org.codehaus.enunciate.jaxrs.StatusCodes;
 import org.codehaus.enunciate.jaxrs.TypeHint;
-import org.opendaylight.neutron.spi.INeutronVPNIPSECPolicyAware;
 import org.opendaylight.neutron.spi.INeutronVPNIPSECPolicyCRUD;
 import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
 import org.opendaylight.neutron.spi.NeutronVPNIPSECPolicy;
@@ -55,25 +54,33 @@ import org.opendaylight.neutron.spi.NeutronVPNIPSECPolicy;
  */
 
 @Path("/vpn/ipsecpolicies")
-public class NeutronVPNIPSECPoliciesNorthbound {
+public class NeutronVPNIPSECPoliciesNorthbound
+    extends AbstractNeutronNorthbound<NeutronVPNIPSECPolicy, NeutronVPNIPSECPolicyRequest, INeutronVPNIPSECPolicyCRUD> {
 
-    private static final int HTTP_OK_BOTTOM = 200;
-    private static final int HTTP_OK_TOP = 299;
-    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) {
+    @Override
+    protected String getResourceName() {
+        return RESOURCE_NAME;
+    }
+
+    @Override
+    protected NeutronVPNIPSECPolicy extractFields(NeutronVPNIPSECPolicy o, List<String> fields) {
         return o.extractFields(fields);
     }
 
-    private NeutronCRUDInterfaces getNeutronInterfaces() {
+    @Override
+    protected INeutronVPNIPSECPolicyCRUD getNeutronCRUD() {
         NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronVPNIPSECPolicyCRUD(this);
         if (answer.getVPNIPSECPolicyInterface() == null) {
-            throw new ServiceUnavailableException("NeutronVPNIPSECPolicy CRUD Interface "
-                + RestMessages.SERVICEUNAVAILABLE.toString());
+            throw new ServiceUnavailableException(serviceUnavailable());
         }
-        return answer;
+        return answer.getVPNIPSECPolicyInterface();
+    }
+
+    @Override
+    protected NeutronVPNIPSECPolicyRequest newNeutronRequest(NeutronVPNIPSECPolicy o) {
+        return new NeutronVPNIPSECPolicyRequest(o);
     }
 
     @Context
@@ -96,7 +103,6 @@ public class NeutronVPNIPSECPoliciesNorthbound {
             @QueryParam("id") String queryID,
             @QueryParam("tenant_id") String queryTenantID,
             @QueryParam("name") String queryName,
-            @QueryParam("description") String queryDescription,
             @QueryParam("transform_protocol") String queryTransformProtocol,
             @QueryParam("encapsulation_mode") String queryEncapsulationMode,
             @QueryParam("auth_algorithm") String queryAuthAlgorithm,
@@ -104,7 +110,7 @@ public class NeutronVPNIPSECPoliciesNorthbound {
             @QueryParam("pfs") String queryPFS
             // pagination and sorting are TODO
             ) {
-        INeutronVPNIPSECPolicyCRUD policyInterface = getNeutronInterfaces().getVPNIPSECPolicyInterface();
+        INeutronVPNIPSECPolicyCRUD policyInterface = getNeutronCRUD();
         List<NeutronVPNIPSECPolicy> allNeutronVPNIPSECPolicies = policyInterface.getAllNeutronVPNIPSECPolicies();
         List<NeutronVPNIPSECPolicy> ans = new ArrayList<NeutronVPNIPSECPolicy>();
         Iterator<NeutronVPNIPSECPolicy> i = allNeutronVPNIPSECPolicies.iterator();
@@ -112,7 +118,6 @@ public class NeutronVPNIPSECPoliciesNorthbound {
             NeutronVPNIPSECPolicy oSS = i.next();
             if ((queryID == null || queryID.equals(oSS.getID())) &&
                     (queryName == null || queryName.equals(oSS.getName())) &&
-                    (queryDescription == null || queryDescription.equals(oSS.getDescription())) &&
                     (queryAuthAlgorithm == null || queryAuthAlgorithm.equals(oSS.getAuthAlgorithm())) &&
                     (queryEncryptionAlgorithm == null || queryEncryptionAlgorithm.equals(oSS.getEncryptionAlgorithm())) &&
                     (queryPFS == null || queryPFS.equals(oSS.getPerfectForwardSecrecy())) &&
@@ -149,18 +154,7 @@ public class NeutronVPNIPSECPoliciesNorthbound {
             // return fields
             @QueryParam("fields") List<String> fields
             ) {
-        INeutronVPNIPSECPolicyCRUD policyInterface = getNeutronInterfaces().getVPNIPSECPolicyInterface();
-        if (!policyInterface.neutronVPNIPSECPolicyExists(policyUUID)) {
-            throw new ResourceNotFoundException(UUID_NO_EXIST);
-        }
-        if (fields.size() > 0) {
-            NeutronVPNIPSECPolicy ans = policyInterface.getNeutronVPNIPSECPolicy(policyUUID);
-            return Response.status(HttpURLConnection.HTTP_OK).entity(
-                    new NeutronVPNIPSECPolicyRequest(extractFields(ans, fields))).build();
-        } else {
-            return Response.status(HttpURLConnection.HTTP_OK).entity(
-                    new NeutronVPNIPSECPolicyRequest(policyInterface.getNeutronVPNIPSECPolicy(policyUUID))).build();
-        }
+        return show(policyUUID, fields);
     }
 
     /**
@@ -171,50 +165,9 @@ public class NeutronVPNIPSECPoliciesNorthbound {
     @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 = getNeutronInterfaces().getVPNIPSECPolicyInterface();
-        if (input.isSingleton()) {
-            NeutronVPNIPSECPolicy singleton = input.getSingleton();
-
-            Object[] instances = NeutronUtil.getInstances(INeutronVPNIPSECPolicyAware.class, this);
-            if (instances != null) {
-                if (instances.length > 0) {
-                    for (Object instance : instances) {
-                        INeutronVPNIPSECPolicyAware service = (INeutronVPNIPSECPolicyAware) instance;
-                        int status = service.canCreateNeutronVPNIPSECPolicy(singleton);
-                        if (status < HTTP_OK_BOTTOM || status > HTTP_OK_TOP) {
-                            return Response.status(status).build();
-                        }
-                    }
-                } else {
-                    throw new ServiceUnavailableException(NO_PROVIDERS);
-                }
-            } else {
-                throw new ServiceUnavailableException(NO_PROVIDER_LIST);
-            }
-
-            /*
-             * add ipsecPolicy to the cache
-             */
-            ipsecPolicyInterface.addNeutronVPNIPSECPolicy(singleton);
-            if (instances != null) {
-                for (Object instance : instances) {
-                    INeutronVPNIPSECPolicyAware service = (INeutronVPNIPSECPolicyAware) instance;
-                    service.neutronVPNIPSECPolicyCreated(singleton);
-                }
-            }
-        } else {
-
-            /*
-             * only singleton ipsecPolicy creates supported
-             */
-            throw new BadRequestException("Only singleton ipsecPolicy creates supported");
-        }
-        return Response.status(HttpURLConnection.HTTP_CREATED).entity(input).build();
+        return create(input);
     }
 
     /**
@@ -225,48 +178,12 @@ public class NeutronVPNIPSECPoliciesNorthbound {
     @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 = getNeutronInterfaces().getVPNIPSECPolicyInterface();
-
-        NeutronVPNIPSECPolicy singleton = input.getSingleton();
-        NeutronVPNIPSECPolicy original = ipsecPolicyInterface.getNeutronVPNIPSECPolicy(policyUUID);
-
-        Object[] instances = NeutronUtil.getInstances(INeutronVPNIPSECPolicyAware.class, this);
-        if (instances != null) {
-            if (instances.length > 0) {
-                for (Object instance : instances) {
-                    INeutronVPNIPSECPolicyAware service = (INeutronVPNIPSECPolicyAware) instance;
-                    int status = service.canUpdateNeutronVPNIPSECPolicy(singleton, original);
-                    if (status < HTTP_OK_BOTTOM || status > HTTP_OK_TOP) {
-                        return Response.status(status).build();
-                    }
-                }
-            } else {
-                throw new ServiceUnavailableException(NO_PROVIDERS);
-            }
-        } else {
-            throw new ServiceUnavailableException(NO_PROVIDER_LIST);
-        }
-        /*
-         * update the ipsecPolicy entry and return the modified object
-         */
-        ipsecPolicyInterface.updateNeutronVPNIPSECPolicy(policyUUID, singleton);
-        NeutronVPNIPSECPolicy updatedVPNIPSECPolicy = ipsecPolicyInterface.getNeutronVPNIPSECPolicy(policyUUID);
-        if (instances != null) {
-            for (Object instance : instances) {
-                INeutronVPNIPSECPolicyAware service = (INeutronVPNIPSECPolicyAware) instance;
-                service.neutronVPNIPSECPolicyUpdated(updatedVPNIPSECPolicy);
-            }
-        }
-        return Response.status(HttpURLConnection.HTTP_OK).entity(
-                new NeutronVPNIPSECPolicyRequest(ipsecPolicyInterface.getNeutronVPNIPSECPolicy(policyUUID))).build();
+        return update(policyUUID, input);
     }
 
     /**
@@ -276,39 +193,10 @@ public class NeutronVPNIPSECPoliciesNorthbound {
     @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 = getNeutronInterfaces().getVPNIPSECPolicyInterface();
-
-        NeutronVPNIPSECPolicy singleton = policyInterface.getNeutronVPNIPSECPolicy(policyUUID);
-        Object[] instances = NeutronUtil.getInstances(INeutronVPNIPSECPolicyAware.class, this);
-        if (instances != null) {
-            if (instances.length > 0) {
-                for (Object instance : instances) {
-                    INeutronVPNIPSECPolicyAware service = (INeutronVPNIPSECPolicyAware) instance;
-                    int status = service.canDeleteNeutronVPNIPSECPolicy(singleton);
-                    if (status < HTTP_OK_BOTTOM || status > HTTP_OK_TOP) {
-                        return Response.status(status).build();
-                    }
-                }
-            } else {
-                throw new ServiceUnavailableException(NO_PROVIDERS);
-            }
-        } else {
-            throw new ServiceUnavailableException(NO_PROVIDER_LIST);
-        }
-        policyInterface.removeNeutronVPNIPSECPolicy(policyUUID);
-        if (instances != null) {
-            for (Object instance : instances) {
-                INeutronVPNIPSECPolicyAware service = (INeutronVPNIPSECPolicyAware) instance;
-                service.neutronVPNIPSECPolicyDeleted(singleton);
-            }
-        }
-        return Response.status(HttpURLConnection.HTTP_NO_CONTENT).build();
+        return delete(policyUUID);
     }
 }