Adding implementation for NeutronVPNServicesNorthbound 27/18527/2
authorShreshthaJoshi <shreshtha.joshi@tcs.com>
Fri, 17 Apr 2015 10:37:05 +0000 (16:07 +0530)
committerRyan Moats <rmoats@us.ibm.com>
Fri, 17 Apr 2015 12:49:05 +0000 (07:49 -0500)
Change-Id: Ibb8f4d068e0ad7ae967878340f1ce12fab89643d
Signed-off-by: ShreshthaJoshi <shreshtha.joshi@tcs.com>
neutron-spi/src/main/java/org/opendaylight/neutron/spi/INeutronVPNServiceCRUD.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/NeutronVPNService.java
northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/NeutronVPNServicesNorthbound.java
transcriber/src/main/java/org/opendaylight/neutron/transcriber/Activator.java
transcriber/src/main/java/org/opendaylight/neutron/transcriber/NeutronVPNServiceInterface.java [new file with mode: 0644]

diff --git a/neutron-spi/src/main/java/org/opendaylight/neutron/spi/INeutronVPNServiceCRUD.java b/neutron-spi/src/main/java/org/opendaylight/neutron/spi/INeutronVPNServiceCRUD.java
new file mode 100644 (file)
index 0000000..2d9b011
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * 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;
+
+/**
+ * This interface defines the methods for CRUD of NB VPNService objects
+ *
+ */
+
+public interface INeutronVPNServiceCRUD {
+
+    /**
+     * Applications call this interface method to determine if a particular
+     * VPNService object exists
+     *
+     * @param uuid
+     *            UUID of the VPNService object
+     * @return boolean
+     */
+
+    public boolean neutronVPNServiceExists(String uuid);
+
+    /**
+     * Applications call this interface method to return if a particular
+     * VPNService object exists
+     *
+     * @param uuid
+     *            UUID of the VPNService object
+     * @return {@link org.opendaylight.neutron.neutron.spi.NeutronVPNService.OpenStackVPNService}
+     *         OpenStack VPNService class
+     */
+
+    public NeutronVPNService getVPNService(String uuid);
+
+    /**
+     * Applications call this interface method to return all VPNService objects
+     *
+     * @return a Set of OpenStackVPNService objects
+     */
+
+    public List<NeutronVPNService> getAllVPNService();
+
+    /**
+     * Applications call this interface method to add a VPNService object to the
+     * concurrent map
+     *
+     * @param input
+     *            OpenStackVPNService object
+     * @return boolean on whether the object was added or not
+     */
+
+    public boolean addVPNService(NeutronVPNService input);
+
+    /**
+     * Applications call this interface method to remove a VPNService object to
+     * the concurrent map
+     *
+     * @param uuid
+     *            identifier for the VPNService object
+     * @return boolean on whether the object was removed or not
+     */
+
+    public boolean removeVPNService(String uuid);
+
+    /**
+     * Applications call this interface method to edit a VPNService object
+     *
+     * @param uuid
+     *            identifier of the VPNService object
+     * @param delta
+     *            OpenStackVPNService object containing changes to apply
+     * @return boolean on whether the object was updated or not
+     */
+
+    public boolean updateVPNService(String uuid, NeutronVPNService delta);
+
+    /**
+     * Applications call this interface method to see if a MAC address is in use
+     *
+     * @param uuid
+     *            identifier of the VPNService object
+     * @return boolean on whether the macAddress is already associated with a
+     *         port or not
+     */
+
+    public boolean neutronVPNServiceInUse(String uuid);
+
+}
index a67ea9da024287a88450548ac73c3f8d8bec9d1a..8c92d6cc8f48c8904a902fafeec55e72467f8069 100644 (file)
@@ -108,6 +108,11 @@ public class NeutronCRUDInterfaces {
         return answer;
     }
 
+    public static INeutronVPNServiceCRUD getINeutronVPNServiceCRUD(Object o) {
+        INeutronVPNServiceCRUD answer = (INeutronVPNServiceCRUD) getInstances(INeutronVPNServiceCRUD.class, o);
+        return answer;
+    }
+
     public static Object getInstances(Class<?> clazz,Object bundle) {
         try {
             BundleContext bCtx = FrameworkUtil.getBundle(bundle.getClass())
index 35b711ae80bee149a4a7cae5a0edbfa8fcf52e2c..2da34bd5b15312bc8eaea6d8f10df127050391de 100644 (file)
@@ -9,12 +9,16 @@
 package org.opendaylight.neutron.spi;
 
 import java.io.Serializable;
+import java.util.Iterator;
+import java.util.List;
 
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
+import org.opendaylight.neutron.spi.INeutronObject;
+
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.NONE)
 public class NeutronVPNService implements Serializable, INeutronObject {
@@ -111,4 +115,37 @@ public class NeutronVPNService implements Serializable, INeutronObject {
     public void setDescription(String description) {
         this.description = description;
     }
+
+    public NeutronVPNService extractFields(List<String> fields) {
+        NeutronVPNService ans = new NeutronVPNService();
+        Iterator<String> i = fields.iterator();
+        while (i.hasNext()) {
+            String s = i.next();
+            if (s.equals("id")) {
+                ans.setID(this.getID());
+            }
+            if (s.equals("admin_state_up")) {
+                ans.setAdminStateUp(this.getAdminStateUp());
+            }
+            if (s.equals("description")) {
+                ans.setDescription(this.getDescription());
+            }
+            if (s.equals("name")) {
+                ans.setName(this.getName());
+            }
+            if (s.equals("router_id")) {
+                ans.setRouterUUID(this.getRouterUUID());
+            }
+            if (s.equals("status")) {
+                ans.setStatus(this.getStatus());
+            }
+            if (s.equals("subnet_id")) {
+                ans.setSubnetUUID(this.getSubnetUUID());
+            }
+            if (s.equals("tenant_id")) {
+                ans.setTenantID(this.getTenantID());
+            }
+        }
+        return ans;
+    }
 }
index 9dc67b98bf99ad75ac15748fcf6d9f8ed7a1d058..611db03f2c92d16f38ae3c29a3e8c702d26ded4a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright IBM Corporation, 2013.  All rights reserved.
+ * Copyright IBM Corporation, 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,
@@ -32,6 +32,8 @@ import org.codehaus.enunciate.jaxrs.ResponseCode;
 import org.codehaus.enunciate.jaxrs.StatusCodes;
 import org.codehaus.enunciate.jaxrs.TypeHint;
 import org.opendaylight.neutron.spi.INeutronVPNServiceAware;
+import org.opendaylight.neutron.spi.INeutronVPNServiceCRUD;
+import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
 import org.opendaylight.neutron.spi.NeutronVPNService;
 
 /**
@@ -55,72 +57,323 @@ import org.opendaylight.neutron.spi.NeutronVPNService;
 @Path("/vpn/vpnservices")
 public class NeutronVPNServicesNorthbound {
 
+    private NeutronVPNService extractFields(NeutronVPNService o, List<String> fields) {
+        return o.extractFields(fields);
+    }
+
     @Context
     UriInfo uriInfo;
 
     /**
-     * Returns a list of all VPN Services */
+     * Returns a list of all VPN Services
+     */
 
     @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 listVPNServices(
-            ) {
-        throw new UnimplementedException("Not Implemented");
+            // return fields
+            @QueryParam("fields") List<String> fields,
+            // OpenStack VPNService attributes
+            @QueryParam("id") String queryID, @QueryParam("tenant_id") String queryTenantID,
+            @QueryParam("name") String queryName, @QueryParam("admin_state_up") String queryAdminStateUp,
+            @QueryParam("router_id") String queryRouterID, @QueryParam("status") String queryStatus,
+            @QueryParam("subnet_id") String querySubnetID,
+            // pagination
+            @QueryParam("limit") String limit, @QueryParam("marker") String marker,
+            @QueryParam("page_reverse") String pageReverse
+    // sorting not supported
+    ) {
+        INeutronVPNServiceCRUD VPNServiceInterface = NeutronCRUDInterfaces.getINeutronVPNServiceCRUD(this);
+        if (VPNServiceInterface == null) {
+            throw new ServiceUnavailableException("VPNService CRUD Interface "
+                    + RestMessages.SERVICEUNAVAILABLE.toString());
+        }
+        List<NeutronVPNService> allVPNService = VPNServiceInterface.getAllVPNService();
+        List<NeutronVPNService> ans = new ArrayList<NeutronVPNService>();
+        Iterator<NeutronVPNService> i = allVPNService.iterator();
+        while (i.hasNext()) {
+            NeutronVPNService oSS = i.next();
+            if ((queryID == null || queryID.equals(oSS.getID()))
+                    && (queryName == null || queryName.equals(oSS.getName()))
+                    && (queryAdminStateUp == null || queryAdminStateUp.equals(oSS.getAdminStateUp()))
+                    && (queryStatus == null || queryStatus.equals(oSS.getStatus()))
+                    && (querySubnetID == null || querySubnetID.equals(oSS.getSubnetUUID()))
+                    && (queryRouterID == null || queryRouterID.equals(oSS.getRouterUUID()))
+                    && (queryTenantID == null || queryTenantID.equals(oSS.getTenantID()))) {
+                if (fields.size() > 0)
+                    ans.add(extractFields(oSS, fields));
+                else
+                    ans.add(oSS);
+            }
+        }
+
+        return Response.status(200).entity(new NeutronVPNServiceRequest(ans)).build();
     }
 
     /**
-     * Returns a specific VPN Service */
+     * Returns a specific VPN Service
+     */
 
     @Path("{serviceID}")
     @GET
     @Produces({ MediaType.APPLICATION_JSON })
-    @StatusCodes({
-        @ResponseCode(code = 501, condition = "Not Implemented") })
-    public Response showVPNService(
-            @PathParam("serviceID") String serviceID,
-            // 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 = 404, condition = "Not Found"),
+            @ResponseCode(code = 501, condition = "Not Implemented"),
+            @ResponseCode(code = 503, condition = "No providers available") })
+    public Response showVPNService(@PathParam("serviceID") String serviceID,
+    // return fields
+            @QueryParam("fields") List<String> fields) {
+        INeutronVPNServiceCRUD VPNServiceInterface = NeutronCRUDInterfaces.getINeutronVPNServiceCRUD(this);
+        if (VPNServiceInterface == null) {
+            throw new ServiceUnavailableException("VPNService CRUD Interface "
+                    + RestMessages.SERVICEUNAVAILABLE.toString());
+        }
+        if (!VPNServiceInterface.neutronVPNServiceExists(serviceID)) {
+            throw new ResourceNotFoundException("VPNService UUID does not exist.");
+        }
+        if (fields.size() > 0) {
+            NeutronVPNService ans = VPNServiceInterface.getVPNService(serviceID);
+            return Response.status(200).entity(new NeutronVPNServiceRequest(extractFields(ans, fields))).build();
+        } else {
+            return Response.status(200)
+                    .entity(new NeutronVPNServiceRequest(VPNServiceInterface.getVPNService(serviceID))).build();
+        }
     }
 
     /**
-     * Creates new VPN Service */
+     * Creates new VPN Service
+     */
     @POST
     @Produces({ MediaType.APPLICATION_JSON })
     @Consumes({ MediaType.APPLICATION_JSON })
     @TypeHint(NeutronVPNService.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 = 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") })
     public Response createVPNService(final NeutronVPNServiceRequest input) {
-        throw new UnimplementedException("Not Implemented");
+        INeutronVPNServiceCRUD VPNServiceInterface = NeutronCRUDInterfaces.getINeutronVPNServiceCRUD(this);
+        if (VPNServiceInterface == null) {
+            throw new ServiceUnavailableException("VPNService CRUD Interface "
+                    + RestMessages.SERVICEUNAVAILABLE.toString());
+        }
+        if (input.isSingleton()) {
+            NeutronVPNService singleton = input.getSingleton();
+
+            /*
+             * Verify that the VPNService doesn't already exist.
+             */
+            if (VPNServiceInterface.neutronVPNServiceExists(singleton.getID())) {
+                throw new BadRequestException("VPNService UUID already exists");
+            }
+            Object[] instances = NeutronUtil.getInstances(INeutronVPNServiceAware.class, this);
+            if (instances != null) {
+                if (instances.length > 0) {
+                    for (Object instance : instances) {
+                        INeutronVPNServiceAware service = (INeutronVPNServiceAware) instance;
+                        int status = service.canCreateNeutronVPNService(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");
+            }
+
+            VPNServiceInterface.addVPNService(singleton);
+            if (instances != null) {
+                for (Object instance : instances) {
+                    INeutronVPNServiceAware service = (INeutronVPNServiceAware) instance;
+                    service.neutronVPNServiceCreated(singleton);
+                }
+            }
+        } else {
+            List<NeutronVPNService> bulk = input.getBulk();
+            Iterator<NeutronVPNService> i = bulk.iterator();
+            HashMap<String, NeutronVPNService> testMap = new HashMap<String, NeutronVPNService>();
+            Object[] instances = NeutronUtil.getInstances(INeutronVPNServiceAware.class, this);
+            while (i.hasNext()) {
+                NeutronVPNService test = i.next();
+
+                /*
+                 * Verify that the VPNService doesn't already exist
+                 */
+
+                if (VPNServiceInterface.neutronVPNServiceExists(test.getID())) {
+                    throw new BadRequestException("VPN Service UUID already is already created");
+                }
+                if (testMap.containsKey(test.getID())) {
+                    throw new BadRequestException("VPN Service UUID already exists");
+                }
+                if (instances != null) {
+                    if (instances.length > 0) {
+                        for (Object instance : instances) {
+                            INeutronVPNServiceAware service = (INeutronVPNServiceAware) instance;
+                            int status = service.canCreateNeutronVPNService(test);
+                            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");
+                }
+            }
+            /*
+             * now, each element of the bulk request can be added to the cache
+             */
+            i = bulk.iterator();
+            while (i.hasNext()) {
+                NeutronVPNService test = i.next();
+                VPNServiceInterface.addVPNService(test);
+                if (instances != null) {
+                    for (Object instance : instances) {
+                        INeutronVPNServiceAware service = (INeutronVPNServiceAware) instance;
+                        service.neutronVPNServiceCreated(test);
+                    }
+                }
+            }
+        }
+        return Response.status(201).entity(input).build();
     }
 
     /**
-     * Updates a VPN Service */
+     * Updates a VPN Service
+     */
     @Path("{serviceID}")
     @PUT
     @Produces({ MediaType.APPLICATION_JSON })
     @Consumes({ MediaType.APPLICATION_JSON })
-    @StatusCodes({
-        @ResponseCode(code = 501, condition = "Not Implemented") })
-    public Response updateVPNService(
-            @PathParam("serviceID") String serviceID, final NeutronVPNServiceRequest 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 = 403, condition = "Forbidden"),
+            @ResponseCode(code = 404, condition = "Not Found"),
+            @ResponseCode(code = 501, condition = "Not Implemented"),
+            @ResponseCode(code = 503, condition = "No providers available") })
+    public Response updateVPNService(@PathParam("serviceID") String serviceID, final NeutronVPNServiceRequest input) {
+        INeutronVPNServiceCRUD VPNServiceInterface = NeutronCRUDInterfaces.getINeutronVPNServiceCRUD(this);
+        if (VPNServiceInterface == null) {
+            throw new ServiceUnavailableException("VPNService CRUD Interface "
+                    + RestMessages.SERVICEUNAVAILABLE.toString());
+        }
+
+        /*
+         * verify the VPNService exists and there is only one delta provided
+         */
+        if (!VPNServiceInterface.neutronVPNServiceExists(serviceID)) {
+            throw new ResourceNotFoundException("VPNService UUID does not exist.");
+        }
+        if (!input.isSingleton()) {
+            throw new BadRequestException("Only singleton edit supported");
+        }
+        NeutronVPNService delta = input.getSingleton();
+        NeutronVPNService original = VPNServiceInterface.getVPNService(serviceID);
+
+        /*
+         * updates restricted by Neutron
+         */
+        if (delta.getID() != null || delta.getTenantID() != null || delta.getName() != null
+                || delta.getRouterUUID() != null || delta.getStatus() != null || delta.getAdminStateUp() != null
+                || delta.getSubnetUUID() != null) {
+            throw new BadRequestException("Attribute edit blocked by Neutron");
+        }
+
+        Object[] instances = NeutronUtil.getInstances(INeutronVPNServiceAware.class, this);
+        if (instances != null) {
+            if (instances.length > 0) {
+                for (Object instance : instances) {
+                    INeutronVPNServiceAware service = (INeutronVPNServiceAware) instance;
+                    int status = service.canUpdateNeutronVPNService(delta, 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 object and return it
+         */
+        VPNServiceInterface.updateVPNService(serviceID, delta);
+        NeutronVPNService updatedVPNService = VPNServiceInterface.getVPNService(serviceID);
+        if (instances != null) {
+            for (Object instance : instances) {
+                INeutronVPNServiceAware service = (INeutronVPNServiceAware) instance;
+                service.neutronVPNServiceUpdated(updatedVPNService);
+            }
+        }
+        return Response.status(200).entity(new NeutronVPNServiceRequest(VPNServiceInterface.getVPNService(serviceID)))
+                .build();
     }
 
     /**
-     * Deletes a VPN Service */
+     * Deletes a VPN Service
+     */
 
     @Path("{serviceID}")
     @DELETE
-    @StatusCodes({
-        @ResponseCode(code = 501, condition = "Not Implemented") })
-    public Response deleteVPNService(
-            @PathParam("serviceID") String serviceID) {
-        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 deleteVPNService(@PathParam("serviceID") String serviceID) {
+        INeutronVPNServiceCRUD VPNServiceInterface = NeutronCRUDInterfaces.getINeutronVPNServiceCRUD(this);
+        if (VPNServiceInterface == null) {
+            throw new ServiceUnavailableException("VPNService CRUD Interface "
+                    + RestMessages.SERVICEUNAVAILABLE.toString());
+        }
+
+        /*
+         * verify the VPNService exists and it isn't currently in use
+         */
+        if (!VPNServiceInterface.neutronVPNServiceExists(serviceID)) {
+            throw new ResourceNotFoundException("VPNService UUID does not exist.");
+        }
+        if (VPNServiceInterface.neutronVPNServiceInUse(serviceID)) {
+            return Response.status(409).build();
+        }
+        NeutronVPNService singleton = VPNServiceInterface.getVPNService(serviceID);
+        Object[] instances = NeutronUtil.getInstances(INeutronVPNServiceAware.class, this);
+        if (instances != null) {
+            if (instances.length > 0) {
+                for (Object instance : instances) {
+                    INeutronVPNServiceAware service = (INeutronVPNServiceAware) instance;
+                    int status = service.canDeleteNeutronVPNService(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");
+        }
+
+        VPNServiceInterface.removeVPNService(serviceID);
+        if (instances != null) {
+            for (Object instance : instances) {
+                INeutronVPNServiceAware service = (INeutronVPNServiceAware) instance;
+                service.neutronVPNServiceDeleted(singleton);
+            }
+        }
+        return Response.status(204).build();
     }
 }
index 3e7d540ea8ede59d53edf5e8c84fa6f87704a2ad..971b1f89a3199b597368fdb3972e07c79baa7e26 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright IBM Corporation, 2013.  All rights reserved.
+ * Copyright IBM Corporation and others, 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,
@@ -26,6 +26,7 @@ import org.opendaylight.neutron.spi.INeutronRouterCRUD;
 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.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
@@ -128,6 +129,12 @@ public class Activator implements BundleActivator {
             registrations.add(neutronMeteringLabelInterfaceRegistration);
         }
 
+        NeutronVPNServiceInterface neutronVPNServiceInterface = new NeutronVPNServiceInterface();
+        ServiceRegistration<INeutronVPNServiceCRUD> neutronVPNServiceInterfaceRegistration = context.registerService(INeutronVPNServiceCRUD.class, neutronVPNServiceInterface, null);
+        if(neutronVPNServiceInterfaceRegistration != null) {
+            registrations.add(neutronVPNServiceInterfaceRegistration);
+        }
+
     }
 
     @Override
diff --git a/transcriber/src/main/java/org/opendaylight/neutron/transcriber/NeutronVPNServiceInterface.java b/transcriber/src/main/java/org/opendaylight/neutron/transcriber/NeutronVPNServiceInterface.java
new file mode 100644 (file)
index 0000000..0527788
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * 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.Set;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.opendaylight.neutron.spi.INeutronVPNServiceCRUD;
+import org.opendaylight.neutron.spi.NeutronVPNService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NeutronVPNServiceInterface implements INeutronVPNServiceCRUD {
+    private static final Logger logger = LoggerFactory.getLogger(NeutronVPNServiceInterface.class);
+    private ConcurrentMap<String, NeutronVPNService> VPNServiceDB = new ConcurrentHashMap<String, NeutronVPNService>();
+
+    // 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;
+    }
+
+    @Override
+    public boolean neutronVPNServiceExists(String uuid) {
+        return VPNServiceDB.containsKey(uuid);
+    }
+
+    @Override
+    public NeutronVPNService getVPNService(String uuid) {
+        if (!neutronVPNServiceExists(uuid)) {
+            logger.debug("No VPNService Have Been Defined");
+            return null;
+        }
+        return VPNServiceDB.get(uuid);
+    }
+
+    @Override
+    public List<NeutronVPNService> getAllVPNService() {
+        Set<NeutronVPNService> allVPNService = new HashSet<NeutronVPNService>();
+        for (Entry<String, NeutronVPNService> entry : VPNServiceDB.entrySet()) {
+            NeutronVPNService VPNService = entry.getValue();
+            allVPNService.add(VPNService);
+        }
+        logger.debug("Exiting getVPNService, Found {} OpenStackVPNService", allVPNService.size());
+        List<NeutronVPNService> ans = new ArrayList<NeutronVPNService>();
+        ans.addAll(allVPNService);
+        return ans;
+    }
+
+    @Override
+    public boolean addVPNService(NeutronVPNService input) {
+        if (neutronVPNServiceExists(input.getID())) {
+            return false;
+        }
+        VPNServiceDB.putIfAbsent(input.getID(), input);
+        return true;
+    }
+
+    @Override
+    public boolean removeVPNService(String uuid) {
+        if (!neutronVPNServiceExists(uuid)) {
+            return false;
+        }
+        VPNServiceDB.remove(uuid);
+        return true;
+    }
+
+    @Override
+    public boolean updateVPNService(String uuid, NeutronVPNService delta) {
+        if (!neutronVPNServiceExists(uuid)) {
+            return false;
+        }
+        NeutronVPNService target = VPNServiceDB.get(uuid);
+        return overwrite(target, delta);
+    }
+
+    @Override
+    public boolean neutronVPNServiceInUse(String uuid) {
+        return !neutronVPNServiceExists(uuid);
+    }
+
+}