bgpvpn: simplify bgpvpn related code 33/28233/2
authorIsaku Yamahata <isaku.yamahata@intel.com>
Fri, 9 Oct 2015 20:01:09 +0000 (13:01 -0700)
committerIsaku Yamahata <isaku.yamahata@intel.com>
Fri, 16 Oct 2015 22:04:33 +0000 (15:04 -0700)
This patch simplifies bgpvpn related code.

Change-Id: I36fdb996d4b20dfb1319ec11fe815a882b1bed85
Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
neutron-spi/src/main/java/org/opendaylight/neutron/spi/INeutronBgpvpnCRUD.java
northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/NeutronBgpvpnsNorthbound.java
transcriber/src/main/java/org/opendaylight/neutron/transcriber/NeutronBgpvpnInterface.java

index c5586aeaa8231a7c4e84be274d13ddba80acab97..ae95395bd32273154dc6ecad24e835623a54b64a 100644 (file)
@@ -15,81 +15,7 @@ import java.util.List;
  *
  */
 
-public interface INeutronBgpvpnCRUD extends INeutronCRUD<NeutronBgpvpn>{
-    /**
-     * Applications call this interface method to determine if a particular
-     * Bgpvpn object exists
-     *
-     * @param uuid
-     *            UUID of the Bgpvpn object
-     * @return boolean
-     */
-
-    boolean bgpvpnExists(String uuid);
-
-    /**
-     * Applications call this interface method to return if a particular
-     * Bgpvpn object exists
-     *
-     * @param uuid
-     *            UUID of the Bgpvpn object
-     * @return {@link org.opendaylight.neutron.spi.NeutronBgpvpn}
-     *          OpenStack Bgpvpn class
-     */
-
-    NeutronBgpvpn getBgpvpn(String uuid);
-
-    /**
-     * Applications call this interface method to return all Bgpvpn objects
-     *
-     * @return List of OpenStackBgpvpn objects
-     */
-
-    List<NeutronBgpvpn> getAllBgpvpns();
-
-    /**
-     * Applications call this interface method to add a Bgpvpn object to the
-     * concurrent map
-     *
-     * @param input
-     *            OpenStackBgpvpn object
-     * @return boolean on whether the object was added or not
-     */
-
-    boolean addBgpvpn(NeutronBgpvpn input);
-
-    /**
-     * Applications call this interface method to remove a Bgpvpn object to the
-     * concurrent map
-     *
-     * @param uuid
-     *            identifier for the bgpvpn object
-     * @return boolean on whether the object was removed or not
-     */
-
-    boolean removeBgpvpn(String uuid);
-
-    /**
-     * Applications call this interface method to edit a Bgpvpn object
-     *
-     * @param uuid
-     *            identifier of the bgpvpn object
-     * @param delta
-     *            OpenStackBgpvpn object containing changes to apply
-     * @return boolean on whether the object was updated or not
-     */
-
-    boolean updateBgpvpn(String uuid, NeutronBgpvpn delta);
-
-    /**
-     * Applications call this interface method to determine if a Bgpvpn object
-     * is use
-     *
-     * @param bgpvpnUUID
-     *            identifier of the bgpvpn object
-     *
-     * @return boolean on whether the bgpvpn is in use or not
-     */
-
-    boolean bgpvpnInUse(String bgpvpnUUID);
+public interface INeutronBgpvpnCRUD extends INeutronCRUD<NeutronBgpvpn> {
+    // Nothing Here.
+    // This class is defined to use reflection like INuetornBgpvpnCRUD.class
 }
index 3f9837b9ec39c7265fd2054b17faca76125f1faa..f85c55595fb240b1f5acf92621d5b1b24fc98188 100644 (file)
@@ -115,7 +115,7 @@ public class NeutronBgpvpnsNorthbound
             // sorting not supported
             ) {
         INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
-        List<NeutronBgpvpn> allBgpvpns = bgpvpnInterface.getAllBgpvpns();
+        List<NeutronBgpvpn> allBgpvpns = bgpvpnInterface.getAll();
         List<NeutronBgpvpn> ans = new ArrayList<NeutronBgpvpn>();
         Iterator<NeutronBgpvpn> i = allBgpvpns.iterator();
         while (i.hasNext()) {
@@ -172,18 +172,7 @@ public class NeutronBgpvpnsNorthbound
             // return fields
             @QueryParam("fields") List<String> fields
             ) {
-        INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
-        if (!bgpvpnInterface.bgpvpnExists(bgpvpnUUID)) {
-            throw new ResourceNotFoundException(uuidNoExist());
-        }
-        if (fields.size() > 0) {
-            NeutronBgpvpn ans = bgpvpnInterface.getBgpvpn(bgpvpnUUID);
-            return Response.status(HttpURLConnection.HTTP_OK).entity(
-                    new NeutronBgpvpnRequest(extractFields(ans, fields))).build();
-        } else {
-            return Response.status(HttpURLConnection.HTTP_OK).entity(
-                    new NeutronBgpvpnRequest(bgpvpnInterface.getBgpvpn(bgpvpnUUID))).build();
-        }
+        return show(bgpvpnUUID, fields);
     }
 
     /**
@@ -196,25 +185,20 @@ public class NeutronBgpvpnsNorthbound
         @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
         @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
     public Response createBgpvpns(final NeutronBgpvpnRequest input) {
-        INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
-        if (input.isSingleton()) {
-            NeutronBgpvpn singleton = input.getSingleton();
-
-            // add bgpvpn to MDSAL
-            singleton.initDefaults();
-            bgpvpnInterface.addBgpvpn(singleton);
-        } else {
-            // add items to MDSAL
-            for (NeutronBgpvpn test : input.getBulk()) {
-                test.initDefaults();
-                bgpvpnInterface.addBgpvpn(test);
-            }
-        }
-        return Response.status(HttpURLConnection.HTTP_CREATED).entity(input).build();
+        return create(input);
     }
 
     /**
      * Updates a Bgpvpn */
+    @Override
+    protected void updateDelta(String uuid,
+                               NeutronBgpvpn delta, NeutronBgpvpn original) {
+        //Fill in defaults if they're missing in update
+        delta.initDefaults();
+        delta.setID(uuid);
+        delta.setTenantID(original.getTenantID());
+    }
+
     @Path("{bgpvpnUUID}")
     @PUT
     @Produces({ MediaType.APPLICATION_JSON })
@@ -226,28 +210,7 @@ public class NeutronBgpvpnsNorthbound
     public Response updateBgpvpn(
             @PathParam("bgpvpnUUID") String bgpvpnUUID, final NeutronBgpvpnRequest input
             ) {
-        INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
-
-        NeutronBgpvpn updatedObject = input.getSingleton();
-        NeutronBgpvpn original = bgpvpnInterface.getBgpvpn(bgpvpnUUID);
-
-        /*
-         *  note: what we get appears to not be a delta but
-         * rather an incomplete updated object.  So we need to set
-         * the ID to complete the object and then send that down
-         * for folks to check
-         */
-
-        updatedObject.setID(bgpvpnUUID);
-        updatedObject.setTenantID(original.getTenantID());
-        //Fill in defaults if they're missing in update
-        updatedObject.initDefaults();
-
-        // update bgpvpn object
-        bgpvpnInterface.updateBgpvpn(bgpvpnUUID, updatedObject);
-
-        return Response.status(HttpURLConnection.HTTP_OK).entity(
-                new NeutronBgpvpnRequest(bgpvpnInterface.getBgpvpn(bgpvpnUUID))).build();
+        return update(bgpvpnUUID, input);
     }
 
     /**
@@ -260,11 +223,6 @@ public class NeutronBgpvpnsNorthbound
         @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
     public Response deleteBgpvpn(
             @PathParam("bgpvpnUUID") String bgpvpnUUID) {
-        INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
-
-        if (!bgpvpnInterface.removeBgpvpn(bgpvpnUUID)) {
-            throw new InternalServerErrorException("Could not delete bgpvpn");
-        }
-        return Response.status(HttpURLConnection.HTTP_NO_CONTENT).build();
+        return delete(bgpvpnUUID);
     }
 }
index 1fca51b1e388e0d06c352019335d24dd047dc362..16d1c55c8eeb155d9b66d31b984f6907ebc59686 100644 (file)
@@ -46,53 +46,24 @@ public class NeutronBgpvpnInterface extends AbstractNeutronInterface<Bgpvpn, Bgp
         super(providerContext);
     }
 
-    @Override
-    public boolean bgpvpnExists(String uuid) {
-        return exists(uuid);
-    }
-
-    @Override
-    public NeutronBgpvpn getBgpvpn(String uuid) {
-        return get(uuid);
-    }
-
     @Override
     protected List<Bgpvpn> getDataObjectList(Bgpvpns bgpvpns) {
         return bgpvpns.getBgpvpn();
     }
 
     @Override
-    public List<NeutronBgpvpn> getAllBgpvpns() {
-        return getAll();
-    }
-
-    @Override
-    public boolean addBgpvpn(NeutronBgpvpn input) {
-        return add(input);
-    }
-
-    @Override
-    public boolean removeBgpvpn(String uuid) {
-        return remove(uuid);
-    }
-
-    @Override
-    public boolean updateBgpvpn(String uuid, NeutronBgpvpn delta) {
-        return update(uuid, delta);
+    public boolean inUse(String uuid) {
+        return !exists(uuid);
     }
 
     @Override
-    public boolean bgpvpnInUse(String bgpvpnUUID) {
-        return !exists(bgpvpnUUID);
-    }
-
     protected NeutronBgpvpn fromMd(Bgpvpn bgpvpn) {
         NeutronBgpvpn result = new NeutronBgpvpn();
         result.setAdminStateUp(bgpvpn.isAdminStateUp());
         result.setBgpvpnName(bgpvpn.getName());
         result.setAutoAggregate(bgpvpn.isAutoAggregate());
         result.setStatus(bgpvpn.getStatus());
-        result.setTenantID(bgpvpn.getTenantId().getValue().replace("-", ""));
+        result.setTenantID(bgpvpn.getTenantId());
         result.setID(bgpvpn.getUuid().getValue());
         if(bgpvpn.getVnid() != null) {
             result.setVnid(bgpvpn.getVnid());
@@ -148,6 +119,7 @@ public class NeutronBgpvpnInterface extends AbstractNeutronInterface<Bgpvpn, Bgp
         return result;
     }
 
+    @Override
     protected Bgpvpn toMd(NeutronBgpvpn bgpvpn) {
         BgpvpnBuilder bgpvpnBuilder = new BgpvpnBuilder();
 
@@ -224,6 +196,7 @@ public class NeutronBgpvpnInterface extends AbstractNeutronInterface<Bgpvpn, Bgp
         return bgpvpnBuilder.build();
     }
 
+    @Override
     protected Bgpvpn toMd(String uuid) {
         BgpvpnBuilder bgpvpnBuilder = new BgpvpnBuilder();
         bgpvpnBuilder.setUuid(toUuid(uuid));
@@ -237,6 +210,7 @@ public class NeutronBgpvpnInterface extends AbstractNeutronInterface<Bgpvpn, Bgp
                 .child(Bgpvpn.class, bgpvpn.getKey());
     }
 
+    @Override
     protected InstanceIdentifier<Bgpvpns> createInstanceIdentifier() {
         return InstanceIdentifier.create(Neutron.class)
                 .child(Bgpvpns.class);