NEUTRON-208: BGPVPN network and router association
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronBgpvpnsNorthbound.java
index 8c7fd10a3f1e82c0a8d210b55dd6869ec18991f9..42db59a982908f584bbba205212a11103ddd6863 100644 (file)
@@ -5,12 +5,16 @@
  * 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.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;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.DefaultValue;
@@ -25,38 +29,41 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 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.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.<br>
- * This class provides REST APIs for managing neutron Bgpvpns
- *
- * <br>
- * <br>
- * Authentication scheme : <b>HTTP Basic</b><br>
- * Authentication realm : <b>opendaylight</b><br>
- * Transport : <b>HTTP and HTTPS</b><br>
- * <br>
- * HTTPS Authentication is disabled by default. Administrator can enable it in
- * tomcat-server.xml after adding a proper keystore / SSL certificate from a
- * trusted authority.<br>
- * More info :
- * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
- *
+ * Neutron Northbound REST APIs for Bgpvpn.
  */
-
+@Singleton
 @Path("/bgpvpns")
 public final class NeutronBgpvpnsNorthbound
         extends AbstractNeutronNorthbound<NeutronBgpvpn, NeutronBgpvpnRequest, INeutronBgpvpnCRUD> {
 
+    private static final String RESOURCE_NAME = "Bgpvpn";
+
     @Context
     UriInfo uriInfo;
 
-    private static final String RESOURCE_NAME = "Bgpvpn";
+
+    INeutronBgpvpnNetworkAssociationCRUD neutronBgpvpnNetworkAssociation;
+    INeutronBgpvpnRouterAssociationCRUD neutronBgpvpnRouterAssociation;
+
+    @Inject
+    public NeutronBgpvpnsNorthbound(@Reference INeutronBgpvpnCRUD neutronCRUD,
+                                    INeutronBgpvpnNetworkAssociationCRUD neutronBgpvpnNetworkAssociation,
+                                    INeutronBgpvpnRouterAssociationCRUD neutronBgpvpnRouterAssociation) {
+        super(neutronCRUD);
+        this.neutronBgpvpnNetworkAssociation = neutronBgpvpnNetworkAssociation;
+        this.neutronBgpvpnRouterAssociation = neutronBgpvpnRouterAssociation;
+
+    }
 
     @Override
     protected String getResourceName() {
@@ -66,7 +73,6 @@ public final class NeutronBgpvpnsNorthbound
     /**
      * Returns a list of all Bgpvpns.
      */
-
     @GET
     @Produces({ MediaType.APPLICATION_JSON })
     //@TypeHint(OpenStackBgpvpns.class)
@@ -126,7 +132,6 @@ public final class NeutronBgpvpnsNorthbound
     /**
      * Returns a specific Bgpvpn.
      */
-
     @Path("{bgpvpnUUID}")
     @GET
     @Produces({ MediaType.APPLICATION_JSON })
@@ -181,13 +186,29 @@ public final class NeutronBgpvpnsNorthbound
     /**
      * Deletes a Bgpvpn.
      */
-
     @Path("{bgpvpnUUID}")
     @DELETE
     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
             @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);
     }
 }