northbound: simplify neutron interface loading 43/45543/1
authorIsaku Yamahata <isaku.yamahata@intel.com>
Tue, 13 Sep 2016 15:50:29 +0000 (08:50 -0700)
committerIsaku Yamahata <isaku.yamahata@intel.com>
Tue, 13 Sep 2016 16:32:40 +0000 (09:32 -0700)
Now subnets/ports/routers northbound doesn't need dependent
interface. So getNeutronInterface() can be removed.

Change-Id: I7a78ec35a0b7f2efa79840672e257cc7e5724457
Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/NeutronPortsNorthbound.java
northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/NeutronRoutersNorthbound.java
northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/NeutronSubnetsNorthbound.java

index 3fd71c768f9c617dcda54317e58fa756d6b34b62..96683743978464074fad9898f6724e8bd5f351da 100644 (file)
@@ -29,7 +29,6 @@ import javax.ws.rs.core.UriInfo;
 import org.codehaus.enunciate.jaxrs.ResponseCode;
 import org.codehaus.enunciate.jaxrs.StatusCodes;
 import org.opendaylight.neutron.spi.INeutronPortCRUD;
-import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
 import org.opendaylight.neutron.spi.NeutronPort;
 
 /**
@@ -61,33 +60,6 @@ public final class NeutronPortsNorthbound
         return RESOURCE_NAME;
     }
 
-    private NeutronCRUDInterfaces getNeutronInterfaces(boolean needNetworks, boolean needSubnets) {
-        NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronPortCRUD(this);
-        if (answer.getPortInterface() == null) {
-            throw new ServiceUnavailableException(serviceUnavailable());
-        }
-        if (needNetworks) {
-            answer = answer.fetchINeutronNetworkCRUD(this);
-            if (answer.getNetworkInterface() == null) {
-                throw new ServiceUnavailableException(
-                        "Network CRUD Interface " + RestMessages.SERVICEUNAVAILABLE.toString());
-            }
-        }
-        if (needSubnets) {
-            answer = answer.fetchINeutronSubnetCRUD(this);
-            if (answer.getSubnetInterface() == null) {
-                throw new ServiceUnavailableException(
-                        "Subnet CRUD Interface " + RestMessages.SERVICEUNAVAILABLE.toString());
-            }
-        }
-        return answer;
-    }
-
-    @Override
-    protected INeutronPortCRUD getNeutronCRUD() {
-        return getNeutronInterfaces(false, false).getPortInterface();
-    }
-
     @Context
     UriInfo uriInfo;
 
@@ -122,7 +94,7 @@ public final class NeutronPortsNorthbound
             @DefaultValue("false") @QueryParam("page_reverse") Boolean pageReverse
     // sorting not supported
     ) {
-        INeutronPortCRUD portInterface = getNeutronInterfaces(false, false).getPortInterface();
+        INeutronPortCRUD portInterface = getNeutronCRUD();
         List<NeutronPort> allPorts = portInterface.getAll();
         List<NeutronPort> ans = new ArrayList<>();
         Iterator<NeutronPort> i = allPorts.iterator();
@@ -186,7 +158,6 @@ public final class NeutronPortsNorthbound
     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
     public Response createPorts(final NeutronPortRequest input) {
-        getNeutronInterfaces(true, true); // Ensure that services for networks and subnets are loaded
         return create(input);
     }
 
index 60264b4dedcf0af271640149804810fc2eb19af2..2eee4be8e396cde856a0617bdd02ac4fc5bd6a20 100644 (file)
@@ -26,7 +26,6 @@ import javax.ws.rs.core.Response;
 import org.codehaus.enunciate.jaxrs.ResponseCode;
 import org.codehaus.enunciate.jaxrs.StatusCodes;
 import org.opendaylight.neutron.spi.INeutronRouterCRUD;
-import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
 import org.opendaylight.neutron.spi.NeutronRouter;
 import org.opendaylight.neutron.spi.NeutronRouter_Interface;
 
@@ -60,26 +59,6 @@ public final class NeutronRoutersNorthbound
         return RESOURCE_NAME;
     }
 
-    private NeutronCRUDInterfaces getNeutronInterfaces(boolean flag) {
-        NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronRouterCRUD(this);
-        if (answer.getRouterInterface() == null) {
-            throw new ServiceUnavailableException(serviceUnavailable());
-        }
-        if (flag) {
-            answer = answer.fetchINeutronNetworkCRUD(this);
-            if (answer.getNetworkInterface() == null) {
-                throw new ServiceUnavailableException(
-                        "Network CRUD Interface " + RestMessages.SERVICEUNAVAILABLE.toString());
-            }
-        }
-        return answer;
-    }
-
-    @Override
-    protected INeutronRouterCRUD getNeutronCRUD() {
-        return getNeutronInterfaces(false).getRouterInterface();
-    }
-
     /**
      * Returns a list of all Routers */
 
@@ -106,7 +85,7 @@ public final class NeutronRoutersNorthbound
             @QueryParam("page_reverse") String pageReverse
     // sorting not supported
     ) {
-        INeutronRouterCRUD routerInterface = getNeutronInterfaces(false).getRouterInterface();
+        INeutronRouterCRUD routerInterface = getNeutronCRUD();
         if (routerInterface == null) {
             throw new ServiceUnavailableException(serviceUnavailable());
         }
@@ -162,7 +141,6 @@ public final class NeutronRoutersNorthbound
     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
     public Response createRouters(final NeutronRouterRequest input) {
-        getNeutronInterfaces(true); // ensure that network service is loaded
         return create(input);
     }
 
@@ -184,7 +162,6 @@ public final class NeutronRoutersNorthbound
             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
     public Response updateRouter(@PathParam("routerUUID") String routerUUID, NeutronRouterRequest input) {
-        getNeutronInterfaces(true); // ensure that network service is loaded
         return update(routerUUID, input);
     }
 
index 561c4ca10470c75530b20e82360a7e22e84f1120..4a7d4634f171f2b3c820b277bcc89980162eda10 100644 (file)
@@ -29,7 +29,6 @@ import javax.ws.rs.core.UriInfo;
 import org.codehaus.enunciate.jaxrs.ResponseCode;
 import org.codehaus.enunciate.jaxrs.StatusCodes;
 import org.opendaylight.neutron.spi.INeutronSubnetCRUD;
-import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
 import org.opendaylight.neutron.spi.NeutronSubnet;
 
 /**
@@ -60,26 +59,6 @@ public final class NeutronSubnetsNorthbound
         return RESOURCE_NAME;
     }
 
-    private NeutronCRUDInterfaces getNeutronInterfaces(boolean needNetwork) {
-        NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronSubnetCRUD(this);
-        if (answer.getSubnetInterface() == null) {
-            throw new ServiceUnavailableException(serviceUnavailable());
-        }
-        if (needNetwork) {
-            answer = answer.fetchINeutronNetworkCRUD(this);
-            if (answer.getNetworkInterface() == null) {
-                throw new ServiceUnavailableException(
-                        "Network CRUD Interface " + RestMessages.SERVICEUNAVAILABLE.toString());
-            }
-        }
-        return answer;
-    }
-
-    @Override
-    protected INeutronSubnetCRUD getNeutronCRUD() {
-        return getNeutronInterfaces(false).getSubnetInterface();
-    }
-
     @Context
     UriInfo uriInfo;
 
@@ -112,7 +91,7 @@ public final class NeutronSubnetsNorthbound
             @DefaultValue("false") @QueryParam("page_reverse") Boolean pageReverse
     // sorting not supported
     ) {
-        INeutronSubnetCRUD subnetInterface = getNeutronInterfaces(false).getSubnetInterface();
+        INeutronSubnetCRUD subnetInterface = getNeutronCRUD();
         List<NeutronSubnet> allNetworks = subnetInterface.getAll();
         List<NeutronSubnet> ans = new ArrayList<>();
         Iterator<NeutronSubnet> i = allNetworks.iterator();
@@ -174,7 +153,6 @@ public final class NeutronSubnetsNorthbound
     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
     public Response createSubnets(final NeutronSubnetRequest input) {
-        getNeutronInterfaces(true); // Ensure that network service is loaded
         return create(input);
     }