Add implementation of NeutronVPNIPSECSiteConnectionsNorthbound 34/18534/4
authorbhavesh.kumar1 <bhavesh.kumar1@tcs.com>
Fri, 17 Apr 2015 11:31:13 +0000 (17:01 +0530)
committerRyan Moats <rmoats@us.ibm.com>
Fri, 17 Apr 2015 13:00:35 +0000 (08:00 -0500)
Change-Id: I6e22e73214d215214003cf1606ab96438acb3a5b
Signed-off-by: bhavesh.kumar1 <bhavesh.kumar1@tcs.com>
neutron-spi/src/main/java/org/opendaylight/neutron/spi/INeutronVPNIPSECSiteConnectionsCRUD.java [new file with mode: 0644]
neutron-spi/src/main/java/org/opendaylight/neutron/spi/NeutronCRUDInterfaces.java
neutron-spi/src/main/java/org/opendaylight/neutron/spi/NeutronVPNIPSECSiteConnection.java
northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/NeutronVPNIPSECSiteConnectionsNorthbound.java
transcriber/src/main/java/org/opendaylight/neutron/transcriber/Activator.java
transcriber/src/main/java/org/opendaylight/neutron/transcriber/NeutronVPNIPSECSiteConnectionsInterface.java [new file with mode: 0644]

diff --git a/neutron-spi/src/main/java/org/opendaylight/neutron/spi/INeutronVPNIPSECSiteConnectionsCRUD.java b/neutron-spi/src/main/java/org/opendaylight/neutron/spi/INeutronVPNIPSECSiteConnectionsCRUD.java
new file mode 100644 (file)
index 0000000..14f8b5b
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Copyright Tata Consultancy Services, 2015.  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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.neutron.spi;
+
+import java.util.List;
+
+public interface INeutronVPNIPSECSiteConnectionsCRUD {
+
+    /**
+     * yes Applications call this interface method to determine if a particular
+     * NeutronVPNIPSECSiteConnection object exists
+     *
+     * @param policyID
+     *            policyID of the NeutronVPNIPSECSiteConnection object
+     * @return boolean
+     */
+
+    public boolean neutronVPNIPSECSiteConnectionsExists(String policyID);
+
+    /**
+     * Applications call this interface method to return if a particular
+     * NeutronVPNIPSECSiteConnection object exists
+     *
+     * @param uuid
+     *            UUID of the NeutronVPNIPSECSiteConnection object
+     * @return {@link org.opendaylight.neutron.neutron.spi.NeutronVPNIPSECSiteConnection}
+     *         NeutronVPNIPSECSiteConnection class
+     */
+
+    public NeutronVPNIPSECSiteConnection getNeutronVPNIPSECSiteConnections(String policyID);
+
+    /**
+     * Applications call this interface method to return all
+     * NeutronVPNIPSECSiteConnection objects
+     *
+     * @return List of NeutronVPNIPSECSiteConnection objects
+     */
+
+    public List<NeutronVPNIPSECSiteConnection> getAllNeutronVPNIPSECSiteConnections();
+
+    /**
+     * Applications call this interface method to add a
+     * NeutronVPNIPSECSiteConnection object to the concurrent map
+     *
+     * @param input
+     *            NeutronVPNIPSECSiteConnection object
+     * @return boolean on whether the object was added or not
+     */
+
+    public boolean addNeutronVPNIPSECSiteConnections(NeutronVPNIPSECSiteConnection input);
+
+    /**
+     * Applications call this interface method to remove a
+     * NeutronVPNIPSECSiteConnection object to the concurrent map
+     *
+     * @param policyID
+     *            identifier for the NeutronVPNIPSECSiteConnection object
+     * @return boolean on whether the object was removed or not
+     */
+
+    public boolean removeNeutronVPNIPSECSiteConnections(String policyID);
+
+    /**
+     * Applications call this interface method to edit a
+     * NeutronVPNIPSECSiteConnection object
+     *
+     * @param policyID
+     *            identifier of the NeutronVPNIPSECSiteConnection object
+     * @param delta
+     *            NeutronVPNIPSECSiteConnection object containing changes to
+     *            apply
+     * @return boolean on whether the object was updated or not
+     */
+
+    public boolean updateNeutronVPNIPSECSiteConnections(String policyID, NeutronVPNIPSECSiteConnection delta);
+
+    /**
+     * Applications call this interface method to see if a connection is in use
+     *
+     * @param policyID
+     *            identifier of the NeutronVPNIPSECSiteConnection object
+     * @return boolean on whether the connection is already is in use or not
+     */
+
+    public boolean neutronVPNIPSECSiteConnectionsInUse(String policyID);
+
+}
index 8c92d6cc8f48c8904a902fafeec55e72467f8069..29e7ac35a018f8c7bfb7662551896956b45077e6 100644 (file)
@@ -113,14 +113,17 @@ public class NeutronCRUDInterfaces {
         return answer;
     }
 
-    public static Object getInstances(Class<?> clazz,Object bundle) {
+    public static INeutronVPNIPSECSiteConnectionsCRUD getINeutronVPNIPSECSiteConnectionsCRUD(Object o) {
+        INeutronVPNIPSECSiteConnectionsCRUD answer = (INeutronVPNIPSECSiteConnectionsCRUD) getInstances(INeutronVPNIPSECSiteConnectionsCRUD.class, o);
+        return answer;
+    }
+
+    public static Object getInstances(Class<?> clazz, Object bundle) {
         try {
-            BundleContext bCtx = FrameworkUtil.getBundle(bundle.getClass())
-                    .getBundleContext();
+            BundleContext bCtx = FrameworkUtil.getBundle(bundle.getClass()).getBundleContext();
 
             ServiceReference<?>[] services = null;
-                services = bCtx.getServiceReferences(clazz.getName(),
-                        null);
+            services = bCtx.getServiceReferences(clazz.getName(), null);
             if (services != null) {
                 return bCtx.getService(services[0]);
             }
index c627ae90e3e03afcf01669862371e2f577bb1046..f549bfb4462ae79684bc3ccb4ed664ac617d99b9 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.neutron.spi;
 
 import java.io.Serializable;
 
+import java.util.Iterator;
 import java.util.List;
 
 import javax.xml.bind.annotation.XmlAccessType;
@@ -224,4 +225,80 @@ public class NeutronVPNIPSECSiteConnection implements Serializable, INeutronObje
         this.deadPeerDetection = deadPeerDetection;
     }
 
+    /**
+     * This method copies selected fields from the object and returns them as a
+     * new object, suitable for marshaling.
+     *
+     * @param fields
+     *            List of attributes to be extracted
+     * @return a NeutronVPNIPSECSiteConnection object with only the selected
+     *         fields populated
+     */
+
+    public NeutronVPNIPSECSiteConnection extractFields(List<String> fields) {
+        NeutronVPNIPSECSiteConnection ans = new NeutronVPNIPSECSiteConnection();
+        Iterator<String> i = fields.iterator();
+        while (i.hasNext()) {
+            String s = i.next();
+            if (s.equals("id")) {
+                ans.setID(this.getID());
+            }
+            if (s.equals("tenant_id")) {
+                ans.setTenantID(this.getTenantID());
+            }
+            if (s.equals("name")) {
+                ans.setName(this.getName());
+            }
+            if (s.equals("description")) {
+                ans.setDescription(this.getDescription());
+            }
+            if (s.equals("peer_address")) {
+                ans.setPeerAddress(this.getPeerAddress());
+            }
+            if (s.equals("peer_id")) {
+                ans.setPeerID(this.getPeerID());
+            }
+            if (s.equals("route_mode")) {
+                ans.setRouteMode(this.getRouteMode());
+            }
+            if (s.equals("mtu")) {
+                ans.setMtu(this.getMtu());
+            }
+            if (s.equals("auth_mode")) {
+                ans.setAuthMode(this.getAuthMode());
+            }
+            if (s.equals("psk")) {
+                ans.setPreSharedKey(this.getPreSharedKey());
+            }
+            if (s.equals("initiator")) {
+                ans.setInitiator(this.getInitiator());
+            }
+            if (s.equals("admin_state_up")) {
+                ans.setAdminStateUp(this.getAdminStateUp());
+            }
+            if (s.equals("status")) {
+                ans.setStatus(this.getStatus());
+            }
+            if (s.equals("ikepolicy_id")) {
+                ans.setIkePolicyID(this.getIkePolicyID());
+            }
+            if (s.equals("ipsecpolicy_id")) {
+                ans.setIpsecPolicyID(this.getIpsecPolicyID());
+            }
+            if (s.equals("vpnservice_id")) {
+                ans.setVpnServiceID(this.getVpnServiceID());
+            }
+        }
+        return ans;
+    }
+
+    @Override
+    public String toString() {
+        return "NeutronVPNIPSECSiteConnection{" + "id='" + id + '\'' + ", tenantID='" + tenantID + '\'' + ", name='"
+                + name + '\'' + ", description=" + description + ", peerAddress=" + peerAddress + ", peerID='" + peerID
+                + '\'' + ", routeMode='" + routeMode + '\'' + ", mtu=" + mtu + ", authMode='" + authMode + '\''
+                + ", preSharedKey='" + preSharedKey + '\'' + ", initiator='" + initiator + '\'' + ", adminStateUp="
+                + adminStateUp + ", status='" + status + '\'' + ", ikePolicyID='" + ikePolicyID + '\''
+                + ", ipsecPolicyID='" + ipsecPolicyID + '\'' + ", vpnServiceID='" + vpnServiceID + '\'' + '}';
+    }
 }
index be2623e13aa5bdb31b03a904ae2665b58f5aa76b..ead03707820a229235f94b41e5a4a0ca6e497e89 100644 (file)
@@ -31,7 +31,10 @@ 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.INeutronVPNIKEPolicyAware;
 import org.opendaylight.neutron.spi.INeutronVPNIPSECSiteConnectionAware;
+import org.opendaylight.neutron.spi.INeutronVPNIPSECSiteConnectionsCRUD;
+import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
 import org.opendaylight.neutron.spi.NeutronVPNIPSECSiteConnection;
 
 /**
@@ -55,72 +58,298 @@ import org.opendaylight.neutron.spi.NeutronVPNIPSECSiteConnection;
 @Path("/vpn/ipsecsiteconnections")
 public class NeutronVPNIPSECSiteConnectionsNorthbound {
 
+    private NeutronVPNIPSECSiteConnection extractFields(NeutronVPNIPSECSiteConnection o, List<String> fields) {
+        return o.extractFields(fields);
+    }
+
     @Context
     UriInfo uriInfo;
 
     /**
-     * Returns a list of all VPN IPSEC SiteConnections */
+     * Returns a list of all VPN IPSEC SiteConnections
+     */
 
     @GET
     @Produces({ MediaType.APPLICATION_JSON })
-    @StatusCodes({
-        @ResponseCode(code = 501, condition = "Not Implemented") })
+    @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") })
     public Response listVPNIPSECSiteConnections(
-            ) {
-        throw new UnimplementedException("Not Implemented");
+            // return fields
+            @QueryParam("fields") List<String> fields,
+            // filter fields
+            @QueryParam("id") String queryID, @QueryParam("tenant_id") String queryTenantID,
+            @QueryParam("name") String queryName, @QueryParam("description") String queryDescription,
+            @QueryParam("peer_address") String queryPeerAddress, @QueryParam("peer_id") String queryPeerID,
+            @QueryParam("route_mode") String queryRouteMode, @QueryParam("mtu") Integer queryMtu,
+            @QueryParam("auth_mode") String queryAuthMode, @QueryParam("psk") String queryPsk,
+            @QueryParam("initiator") String queryInitiator, @QueryParam("admin_state_up") String queryAdminStateUp,
+            @QueryParam("status") String queryStatus, @QueryParam("ikepolicy_id") String queryIkePolicyID,
+            @QueryParam("ipsecpolicy_id") String queryIpSecPolicyID,
+            @QueryParam("vpnservice_id") String queryVpnServiceID
+    // pagination and sorting are TODO
+    ) {
+        INeutronVPNIPSECSiteConnectionsCRUD labelInterface = NeutronCRUDInterfaces
+                .getINeutronVPNIPSECSiteConnectionsCRUD(this);
+        if (labelInterface == null) {
+            throw new ServiceUnavailableException("NeutronVPNIPSECSiteConnections CRUD Interface "
+                    + RestMessages.SERVICEUNAVAILABLE.toString());
+        }
+        List<NeutronVPNIPSECSiteConnection> allNeutronVPNIPSECSiteConnection = labelInterface
+                .getAllNeutronVPNIPSECSiteConnections();
+        List<NeutronVPNIPSECSiteConnection> ans = new ArrayList<NeutronVPNIPSECSiteConnection>();
+        Iterator<NeutronVPNIPSECSiteConnection> i = allNeutronVPNIPSECSiteConnection.iterator();
+        while (i.hasNext()) {
+            NeutronVPNIPSECSiteConnection oSS = i.next();
+            if ((queryID == null || queryID.equals(oSS.getID()))
+                    && (queryTenantID == null || queryTenantID.equals(oSS.getTenantID()))
+                    && (queryName == null || queryName.equals(oSS.getName()))
+                    && (queryDescription == null || queryDescription.equals(oSS.getDescription()))
+                    && (queryPeerAddress == null || queryPeerAddress.equals(oSS.getPeerAddress()))
+                    && (queryPeerID == null || queryPeerID.equals(oSS.getPeerID()))
+                    && (queryRouteMode == null || queryRouteMode.equals(oSS.getRouteMode()))
+                    && (queryMtu == null || queryMtu.equals(oSS.getMtu()))
+                    && (queryAuthMode == null || queryAuthMode.equals(oSS.getAuthMode()))
+                    && (queryPsk == null || queryPsk.equals(oSS.getPreSharedKey()))
+                    && (queryInitiator == null || queryInitiator.equals(oSS.getInitiator()))
+                    && (queryAdminStateUp == null || queryAdminStateUp.equals(oSS.getAdminStateUp()))
+                    && (queryStatus == null || queryStatus.equals(oSS.getStatus()))
+                    && (queryIkePolicyID == null || queryIkePolicyID.equals(oSS.getIkePolicyID()))
+                    && (queryIpSecPolicyID == null || queryIpSecPolicyID.equals(oSS.getIpsecPolicyID()))
+                    && (queryVpnServiceID == null || queryVpnServiceID.equals(oSS.getVpnServiceID())))
+                if (fields.size() > 0)
+                    ans.add(extractFields(oSS, fields));
+                else
+                    ans.add(oSS);
+        }
+
+        // TODO: apply pagination to results
+        return Response.status(200).entity(new NeutronVPNIPSECSiteConnectionRequest(ans)).build();
     }
 
     /**
-     * Returns a specific VPN IPSEC SiteConnection */
+     * Returns a specific VPN IPSEC SiteConnection
+     */
 
     @Path("{connectionID}")
     @GET
     @Produces({ MediaType.APPLICATION_JSON })
-    @StatusCodes({
-        @ResponseCode(code = 501, condition = "Not Implemented") })
-    public Response showVPNIPSECSiteConnection(
-            @PathParam("connectionID") String connectionID,
-            // return fields
-            @QueryParam("fields") List<String> fields
-            ) {
-        throw new UnimplementedException("Not Implemented");
+    @StatusCodes({ @ResponseCode(code = 200, condition = "Operation successful"),
+            @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") })
+    public Response showVPNIPSECSiteConnection(@PathParam("policyID") String policyID,
+    // return fields
+            @QueryParam("fields") List<String> fields) {
+        INeutronVPNIPSECSiteConnectionsCRUD connectionInterface = NeutronCRUDInterfaces
+                .getINeutronVPNIPSECSiteConnectionsCRUD(this);
+        if (connectionInterface == null) {
+            throw new ServiceUnavailableException("NeutronVPNIPSECSiteConnections CRUD Interface "
+                    + RestMessages.SERVICEUNAVAILABLE.toString());
+        }
+        if (!connectionInterface.neutronVPNIPSECSiteConnectionsExists(policyID)) {
+            throw new ResourceNotFoundException("NeutronVPNIPSECSiteConnections ID not found");
+        }
+        if (fields.size() > 0) {
+            NeutronVPNIPSECSiteConnection ans = connectionInterface.getNeutronVPNIPSECSiteConnections(policyID);
+            return Response.status(200).entity(new NeutronVPNIPSECSiteConnectionRequest(extractFields(ans, fields)))
+                    .build();
+        } else {
+            return Response
+                    .status(200)
+                    .entity(new NeutronVPNIPSECSiteConnectionRequest(connectionInterface
+                            .getNeutronVPNIPSECSiteConnections(policyID))).build();
+        }
     }
 
     /**
-     * Creates new VPN IPSEC SiteConnection */
+     * Creates new VPN IPSEC SiteConnection
+     */
     @POST
     @Produces({ MediaType.APPLICATION_JSON })
     @Consumes({ MediaType.APPLICATION_JSON })
     @TypeHint(NeutronVPNIPSECSiteConnection.class)
-    @StatusCodes({
-        @ResponseCode(code = 501, condition = "Not Implemented") })
+    @StatusCodes({ @ResponseCode(code = 201, condition = "Created"),
+            @ResponseCode(code = 400, condition = "Bad Request"),
+            @ResponseCode(code = 401, condition = "Unauthorized"),
+            @ResponseCode(code = 501, condition = "Not Implemented"),
+            @ResponseCode(code = 503, condition = "No providers available") })
     public Response createVPNIPSECSiteConnection(final NeutronVPNIPSECSiteConnectionRequest input) {
-        throw new UnimplementedException("Not Implemented");
+        INeutronVPNIPSECSiteConnectionsCRUD ipsecSiteConnectionsInterface = NeutronCRUDInterfaces
+                .getINeutronVPNIPSECSiteConnectionsCRUD(this);
+        if (ipsecSiteConnectionsInterface == null) {
+            throw new ServiceUnavailableException("VPNIPSECSiteConnections CRUD Interface "
+                    + RestMessages.SERVICEUNAVAILABLE.toString());
+        }
+        if (input.isSingleton()) {
+            NeutronVPNIPSECSiteConnection singleton = input.getSingleton();
+
+            /*
+             * verify that the ipsec site connection doesn't already exist (issue: is deeper
+             * inspection necessary?)
+             */
+            if (ipsecSiteConnectionsInterface.neutronVPNIPSECSiteConnectionsExists(singleton.getID()))
+                throw new BadRequestException("VPNIPSECSiteConnections ID already exists");
+            Object[] instances = NeutronUtil.getInstances(INeutronVPNIPSECSiteConnectionAware.class, this);
+            if (instances != null) {
+                if (instances.length > 0) {
+                    for (Object instance : instances) {
+                        INeutronVPNIPSECSiteConnectionAware service = (INeutronVPNIPSECSiteConnectionAware) instance;
+                        int status = service.canCreateNeutronVPNIPSECSiteConnection(singleton);
+                        if (status < 200 || status > 299)
+                            return Response.status(status).build();
+                    }
+                } else {
+                    throw new ServiceUnavailableException("No providers registered.  Please try again later");
+                }
+            } else {
+                throw new ServiceUnavailableException("Couldn't get providers list.  Please try again later");
+            }
+            /*
+             * add ipsecSiteConnections to the cache
+             */
+            ipsecSiteConnectionsInterface.addNeutronVPNIPSECSiteConnections(singleton);
+            if (instances != null) {
+                for (Object instance : instances) {
+                    INeutronVPNIPSECSiteConnectionAware service = (INeutronVPNIPSECSiteConnectionAware) instance;
+                    service.neutronVPNIPSECSiteConnectionCreated(singleton);
+                }
+            }
+        } else {
+
+            /*
+             * only singleton ipsecSiteConnections creates supported
+             */
+            throw new BadRequestException("Only singleton ipsecSiteConnections creates supported");
+        }
+        return Response.status(201).entity(input).build();
     }
 
     /**
-     * Updates a VPN IPSEC SiteConnection */
+     * Updates a VPN IPSEC SiteConnection
+     */
     @Path("{policyID}")
     @PUT
     @Produces({ MediaType.APPLICATION_JSON })
     @Consumes({ MediaType.APPLICATION_JSON })
-    @StatusCodes({
-        @ResponseCode(code = 501, condition = "Not Implemented") })
-    public Response updateVPNIPSECSiteConnection(
-            @PathParam("policyID") String policyID, final NeutronVPNIPSECSiteConnectionRequest input
-            ) {
-        throw new UnimplementedException("Not Implemented");
+    @StatusCodes({ @ResponseCode(code = 200, condition = "Operation successful"),
+            @ResponseCode(code = 400, condition = "Bad Request"),
+            @ResponseCode(code = 401, condition = "Unauthorized"), @ResponseCode(code = 404, condition = "Not Found"),
+            @ResponseCode(code = 501, condition = "Not Implemented"),
+            @ResponseCode(code = 503, condition = "No providers available") })
+    public Response updateVPNIPSECSiteConnection(@PathParam("policyID") String policyID,
+            final NeutronVPNIPSECSiteConnectionRequest input) {
+        INeutronVPNIPSECSiteConnectionsCRUD ipsecSiteConnectionsInterface = NeutronCRUDInterfaces
+                .getINeutronVPNIPSECSiteConnectionsCRUD(this);
+
+        if (ipsecSiteConnectionsInterface == null) {
+            throw new ServiceUnavailableException("VPNIPSECSiteConnections CRUD Interface "
+                    + RestMessages.SERVICEUNAVAILABLE.toString());
+        }
+
+        /*
+         * ipsecSiteConnection has to exist and only a single delta can be
+         * supplied
+         */
+        if (!ipsecSiteConnectionsInterface.neutronVPNIPSECSiteConnectionsExists(policyID))
+            throw new ResourceNotFoundException("VPNIPSECSiteConnections ID not found");
+        if (!input.isSingleton())
+            throw new BadRequestException("Only singleton deltas supported");
+        NeutronVPNIPSECSiteConnection singleton = input.getSingleton();
+        NeutronVPNIPSECSiteConnection original = ipsecSiteConnectionsInterface
+                .getNeutronVPNIPSECSiteConnections(policyID);
+
+        /*
+         * attribute changes blocked by Neutron
+         */
+        if (singleton.getID() != null || singleton.getTenantID() != null)
+            throw new BadRequestException("Request attribute change not allowed");
+
+        Object[] instances = NeutronUtil.getInstances(INeutronVPNIKEPolicyAware.class, this);
+        if (instances != null) {
+            if (instances.length > 0) {
+                for (Object instance : instances) {
+                    INeutronVPNIPSECSiteConnectionAware service = (INeutronVPNIPSECSiteConnectionAware) instance;
+                    int status = service.canUpdateNeutronVPNIPSECSiteConnection(singleton, original);
+                    if (status < 200 || status > 299)
+                        return Response.status(status).build();
+                }
+            } else {
+                throw new ServiceUnavailableException("No providers registered.  Please try again later");
+            }
+        } else {
+            throw new ServiceUnavailableException("Couldn't get providers list.  Please try again later");
+        }
+        /*
+         * update the ipsecSiteConnections entry and return the modified object
+         */
+        ipsecSiteConnectionsInterface.updateNeutronVPNIPSECSiteConnections(policyID, singleton);
+        NeutronVPNIPSECSiteConnection updatedVPNIKEPolicy = ipsecSiteConnectionsInterface
+                .getNeutronVPNIPSECSiteConnections(policyID);
+        if (instances != null) {
+            for (Object instance : instances) {
+                INeutronVPNIPSECSiteConnectionAware service = (INeutronVPNIPSECSiteConnectionAware) instance;
+                service.neutronVPNIPSECSiteConnectionUpdated(updatedVPNIKEPolicy);
+            }
+        }
+        return Response
+                .status(200)
+                .entity(new NeutronVPNIPSECSiteConnectionRequest(ipsecSiteConnectionsInterface
+                        .getNeutronVPNIPSECSiteConnections(policyID))).build();
     }
 
     /**
-     * Deletes a VPN IPSEC SiteConnection */
+     * Deletes a VPN IPSEC SiteConnection
+     */
 
     @Path("{policyID}")
     @DELETE
-    @StatusCodes({
-        @ResponseCode(code = 501, condition = "Not Implemented") })
-    public Response deleteVPNIPSECSiteConnection(
-            @PathParam("policyID") String policyID) {
-        throw new UnimplementedException("Not Implemented");
+    @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") })
+    public Response deleteVPNIPSECSiteConnection(@PathParam("policyID") String policyID) {
+        INeutronVPNIPSECSiteConnectionsCRUD ipsecSiteConnectionsInterface = NeutronCRUDInterfaces
+                .getINeutronVPNIPSECSiteConnectionsCRUD(this);
+        if (ipsecSiteConnectionsInterface == null) {
+            throw new ServiceUnavailableException("NeutronVPNIPSECSiteConnections CRUD Interface "
+                    + RestMessages.SERVICEUNAVAILABLE.toString());
+        }
+
+        /*
+         * verify that the iSiteConnections exists and is not in use before
+         * removing it
+         */
+        if (!ipsecSiteConnectionsInterface.neutronVPNIPSECSiteConnectionsExists(policyID))
+            throw new ResourceNotFoundException("VPNIPSECSiteConnections ID not found");
+        NeutronVPNIPSECSiteConnection singleton = ipsecSiteConnectionsInterface
+                .getNeutronVPNIPSECSiteConnections(policyID);
+        Object[] instances = NeutronUtil.getInstances(INeutronVPNIPSECSiteConnectionAware.class, this);
+        if (instances != null) {
+            if (instances.length > 0) {
+                for (Object instance : instances) {
+                    INeutronVPNIPSECSiteConnectionAware service = (INeutronVPNIPSECSiteConnectionAware) instance;
+                    int status = service.canDeleteNeutronVPNIPSECSiteConnection(singleton);
+                    if (status < 200 || status > 299)
+                        return Response.status(status).build();
+                }
+            } else {
+                throw new ServiceUnavailableException("No providers registered.  Please try again later");
+            }
+        } else {
+            throw new ServiceUnavailableException("Couldn't get providers list.  Please try again later");
+        }
+        ipsecSiteConnectionsInterface.removeNeutronVPNIPSECSiteConnections(policyID);
+        if (instances != null) {
+            for (Object instance : instances) {
+                INeutronVPNIPSECSiteConnectionAware service = (INeutronVPNIPSECSiteConnectionAware) instance;
+                service.neutronVPNIPSECSiteConnectionDeleted(singleton);
+            }
+        }
+        return Response.status(204).build();
     }
+
 }
index 971b1f89a3199b597368fdb3972e07c79baa7e26..3511949e53e34618422f070babb97338b38a9a84 100644 (file)
@@ -27,6 +27,7 @@ import org.opendaylight.neutron.spi.INeutronSecurityGroupCRUD;
 import org.opendaylight.neutron.spi.INeutronSecurityRuleCRUD;
 import org.opendaylight.neutron.spi.INeutronSubnetCRUD;
 import org.opendaylight.neutron.spi.INeutronVPNServiceCRUD;
+import org.opendaylight.neutron.spi.INeutronVPNIPSECSiteConnectionsCRUD;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
@@ -135,15 +136,19 @@ public class Activator implements BundleActivator {
             registrations.add(neutronVPNServiceInterfaceRegistration);
         }
 
+        NeutronVPNIPSECSiteConnectionsInterface neutronVPNIPSECSiteConnectionsInterface = new NeutronVPNIPSECSiteConnectionsInterface();
+        ServiceRegistration<INeutronVPNIPSECSiteConnectionsCRUD> neutronVPNIPSECSiteConnectionsInterfaceRegistration = context.registerService(INeutronVPNIPSECSiteConnectionsCRUD.class, neutronVPNIPSECSiteConnectionsInterface, null);
+        if (neutronVPNIPSECSiteConnectionsInterfaceRegistration != null) {
+            registrations.add(neutronVPNIPSECSiteConnectionsInterfaceRegistration);
+        }
     }
 
     @Override
     public void stop(BundleContext context) throws Exception {
-       for(ServiceRegistration registration : registrations) {
-           if(registration != null) {
-               registration.unregister();
-           }
-       }
-
+        for (ServiceRegistration registration : registrations) {
+            if (registration != null) {
+                registration.unregister();
+            }
+        }
     }
 }
diff --git a/transcriber/src/main/java/org/opendaylight/neutron/transcriber/NeutronVPNIPSECSiteConnectionsInterface.java b/transcriber/src/main/java/org/opendaylight/neutron/transcriber/NeutronVPNIPSECSiteConnectionsInterface.java
new file mode 100644 (file)
index 0000000..cec9e3c
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * Copyright Tata Consultancy Services, 2015.  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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.neutron.transcriber;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import org.opendaylight.neutron.spi.NeutronVPNIPSECSiteConnection;
+import org.opendaylight.neutron.spi.INeutronVPNIPSECSiteConnectionsCRUD;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NeutronVPNIPSECSiteConnectionsInterface implements INeutronVPNIPSECSiteConnectionsCRUD {
+    private static final Logger logger = LoggerFactory.getLogger(NeutronVPNIKEPolicyInterface.class);
+    private ConcurrentMap<String, NeutronVPNIPSECSiteConnection> neutronVPNIPSECSiteConnectionDB = new ConcurrentHashMap<String, NeutronVPNIPSECSiteConnection>();
+
+    // this method uses reflection to update an object from it's delta.
+
+    private boolean overwrite(Object target, Object delta) {
+        Method[] methods = target.getClass().getMethods();
+
+        for (Method toMethod : methods) {
+            if (toMethod.getDeclaringClass().equals(target.getClass()) && toMethod.getName().startsWith("set")) {
+
+                String toName = toMethod.getName();
+                String fromName = toName.replace("set", "get");
+
+                try {
+                    Method fromMethod = delta.getClass().getMethod(fromName);
+                    Object value = fromMethod.invoke(delta, (Object[]) null);
+                    if (value != null) {
+                        toMethod.invoke(target, value);
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+    // INeutronVPNIPSECSiteConnectionsCRUD methods
+
+    @Override
+    public boolean neutronVPNIPSECSiteConnectionsExists(String policyID) {
+        return neutronVPNIPSECSiteConnectionDB.containsKey(policyID);
+    }
+
+    @Override
+    public NeutronVPNIPSECSiteConnection getNeutronVPNIPSECSiteConnections(String policyID) {
+        if (!neutronVPNIPSECSiteConnectionsExists(policyID)) {
+            return null;
+        }
+        return neutronVPNIPSECSiteConnectionDB.get(policyID);
+    }
+
+    @Override
+    public List<NeutronVPNIPSECSiteConnection> getAllNeutronVPNIPSECSiteConnections() {
+        Set<NeutronVPNIPSECSiteConnection> allNeutronVPNIPSECSiteConnections = new HashSet<NeutronVPNIPSECSiteConnection>();
+        for (Entry<String, NeutronVPNIPSECSiteConnection> entry : neutronVPNIPSECSiteConnectionDB.entrySet()) {
+            NeutronVPNIPSECSiteConnection meteringLabelRule = entry.getValue();
+            allNeutronVPNIPSECSiteConnections.add(meteringLabelRule);
+        }
+        logger.debug("Exiting getAllNeutronVPNIPSECSiteConnections, Found {} OpenStackVPNIPSECSiteConnections", allNeutronVPNIPSECSiteConnections.size());
+        List<NeutronVPNIPSECSiteConnection> ans = new ArrayList<NeutronVPNIPSECSiteConnection>();
+        ans.addAll(allNeutronVPNIPSECSiteConnections);
+        return ans;
+    }
+
+    @Override
+    public boolean addNeutronVPNIPSECSiteConnections(NeutronVPNIPSECSiteConnection input) {
+        if (neutronVPNIPSECSiteConnectionsExists(input.getID())) {
+            return false;
+        }
+        neutronVPNIPSECSiteConnectionDB.putIfAbsent(input.getID(), input);
+        return true;
+    }
+
+    @Override
+    public boolean removeNeutronVPNIPSECSiteConnections(String policyID) {
+        if (!neutronVPNIPSECSiteConnectionsExists(policyID)) {
+            return false;
+        }
+        neutronVPNIPSECSiteConnectionDB.remove(policyID);
+        return true;
+    }
+
+    @Override
+    public boolean updateNeutronVPNIPSECSiteConnections(String policyID, NeutronVPNIPSECSiteConnection delta) {
+        if (!neutronVPNIPSECSiteConnectionsExists(policyID)) {
+            return false;
+        }
+        NeutronVPNIPSECSiteConnection target = neutronVPNIPSECSiteConnectionDB.get(policyID);
+        return overwrite(target, delta);
+    }
+
+    @Override
+    public boolean neutronVPNIPSECSiteConnectionsInUse(String policyID) {
+        if (!neutronVPNIPSECSiteConnectionsExists(policyID)) {
+            return true;
+        }
+        return false;
+    }
+}
\ No newline at end of file