NEUTRON-208: BGPVPN network and router association
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronBgpvpnsNorthbound.java
index 4e04cd9d2d17ec795bd670f0dec6021def822ab5..42db59a982908f584bbba205212a11103ddd6863 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.neutron.northbound.api;
 
+import com.webcohesion.enunciate.metadata.rs.ResponseCode;
+import com.webcohesion.enunciate.metadata.rs.StatusCodes;
+import com.webcohesion.enunciate.metadata.rs.TypeHint;
 import java.net.HttpURLConnection;
 import java.util.ArrayList;
 import java.util.List;
@@ -27,11 +30,13 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 import org.apache.aries.blueprint.annotation.service.Reference;
-import org.codehaus.enunciate.jaxrs.ResponseCode;
-import org.codehaus.enunciate.jaxrs.StatusCodes;
-import org.codehaus.enunciate.jaxrs.TypeHint;
 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);
     }
 }