NEUTRON-208: BGPVPN network and router association
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronBgpvpnsNorthbound.java
index 55e7bc5d394f8902dafc57826e9751f7b907dae5..42db59a982908f584bbba205212a11103ddd6863 100644 (file)
@@ -31,7 +31,12 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 import org.apache.aries.blueprint.annotation.service.Reference;
 import org.opendaylight.neutron.spi.INeutronBgpvpnCRUD;
+import org.opendaylight.neutron.spi.INeutronBgpvpnNetworkAssociationCRUD;
+import org.opendaylight.neutron.spi.INeutronBgpvpnRouterAssociationCRUD;
 import org.opendaylight.neutron.spi.NeutronBgpvpn;
+import org.opendaylight.neutron.spi.NeutronBgpvpnNetworkAssociation;
+import org.opendaylight.neutron.spi.NeutronBgpvpnRouterAssociation;
+
 
 /**
  * Neutron Northbound REST APIs for Bgpvpn.
@@ -46,9 +51,18 @@ public final class NeutronBgpvpnsNorthbound
     @Context
     UriInfo uriInfo;
 
+
+    INeutronBgpvpnNetworkAssociationCRUD neutronBgpvpnNetworkAssociation;
+    INeutronBgpvpnRouterAssociationCRUD neutronBgpvpnRouterAssociation;
+
     @Inject
-    public NeutronBgpvpnsNorthbound(@Reference INeutronBgpvpnCRUD neutronCRUD) {
+    public NeutronBgpvpnsNorthbound(@Reference INeutronBgpvpnCRUD neutronCRUD,
+                                    INeutronBgpvpnNetworkAssociationCRUD neutronBgpvpnNetworkAssociation,
+                                    INeutronBgpvpnRouterAssociationCRUD neutronBgpvpnRouterAssociation) {
         super(neutronCRUD);
+        this.neutronBgpvpnNetworkAssociation = neutronBgpvpnNetworkAssociation;
+        this.neutronBgpvpnRouterAssociation = neutronBgpvpnRouterAssociation;
+
     }
 
     @Override
@@ -178,6 +192,23 @@ public final class NeutronBgpvpnsNorthbound
             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
     public Response deleteBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID) {
+        NeutronBgpvpnNetworkAssociationsNorthbound netAssoNorthBound =
+                new NeutronBgpvpnNetworkAssociationsNorthbound(neutronBgpvpnNetworkAssociation);
+        List<NeutronBgpvpnNetworkAssociation> allBgpvpnNetAssos = neutronBgpvpnNetworkAssociation.getAll();
+        for (NeutronBgpvpnNetworkAssociation bgpvpnNetAsso : allBgpvpnNetAssos) {
+            if (bgpvpnUUID != null && bgpvpnUUID.equals(bgpvpnNetAsso.getBgpvpnId())) {
+                netAssoNorthBound.delete(bgpvpnNetAsso.getID());
+            }
+        }
+
+        NeutronBgpvpnRouterAssociationsNorthbound routeAssoNorthBound =
+                new NeutronBgpvpnRouterAssociationsNorthbound(neutronBgpvpnRouterAssociation);
+        List<NeutronBgpvpnRouterAssociation> allBgpvpnRouteAssos = neutronBgpvpnRouterAssociation.getAll();
+        for (NeutronBgpvpnRouterAssociation bgpvpnRouteAsso : allBgpvpnRouteAssos) {
+            if (bgpvpnUUID != null && bgpvpnUUID.equals(bgpvpnRouteAsso.getBgpvpnId())) {
+                routeAssoNorthBound.delete(bgpvpnRouteAsso.getID());
+            }
+        }
         return delete(bgpvpnUUID);
     }
 }