Merge "Startup archetype: remove 'Impl' from config subsystem Module name."
[controller.git] / opendaylight / networkconfiguration / neutron / northbound / src / main / java / org / opendaylight / controller / networkconfig / neutron / northbound / NeutronRoutersNorthbound.java
index 0c02adad8a0d4d4ddf499efca66d39b05aff513c..ccf5ddd1a4e2d8370caa25083081457152f8ddc6 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.controller.networkconfig.neutron.northbound;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
@@ -36,12 +37,6 @@ import org.opendaylight.controller.networkconfig.neutron.NeutronPort;
 import org.opendaylight.controller.networkconfig.neutron.NeutronRouter;
 import org.opendaylight.controller.networkconfig.neutron.NeutronRouter_Interface;
 import org.opendaylight.controller.networkconfig.neutron.NeutronSubnet;
-import org.opendaylight.controller.northbound.commons.RestMessages;
-import org.opendaylight.controller.northbound.commons.exception.BadRequestException;
-import org.opendaylight.controller.northbound.commons.exception.ResourceConflictException;
-import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException;
-import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException;
-import org.opendaylight.controller.sal.utils.ServiceHelper;
 
 
 /**
@@ -197,14 +192,20 @@ public class NeutronRoutersNorthbound {
                 if (!externNetwork.isRouterExternal())
                     throw new BadRequestException("External Network Pointer isn't marked as router:external");
             }
-            Object[] instances = ServiceHelper.getGlobalInstances(INeutronRouterAware.class, this, null);
+            Object[] instances = NeutronUtil.getInstances(INeutronRouterAware.class, this);
             if (instances != null) {
-                for (Object instance : instances) {
-                    INeutronRouterAware service = (INeutronRouterAware) instance;
-                    int status = service.canCreateRouter(singleton);
-                    if (status < 200 || status > 299)
-                        return Response.status(status).build();
+                if (instances.length > 0) {
+                    for (Object instance : instances) {
+                        INeutronRouterAware service = (INeutronRouterAware) instance;
+                        int status = service.canCreateRouter(singleton);
+                        if (status < 200 || status > 299)
+                            return Response.status(status).build();
+                    }
+                } else {
+                    throw new ServiceUnavailableException("No providers registered.  Please try again later");
                 }
+            } else {
+                throw new ServiceUnavailableException("Couldn't get providers list.  Please try again later");
             }
 
             /*
@@ -273,14 +274,20 @@ public class NeutronRoutersNorthbound {
                 singleton.getStatus() != null)
             throw new BadRequestException("Request attribute change not allowed");
 
-        Object[] instances = ServiceHelper.getGlobalInstances(INeutronRouterAware.class, this, null);
+        Object[] instances = NeutronUtil.getInstances(INeutronRouterAware.class, this);
         if (instances != null) {
-            for (Object instance : instances) {
-                INeutronRouterAware service = (INeutronRouterAware) instance;
-                int status = service.canUpdateRouter(singleton, original);
-                if (status < 200 || status > 299)
-                    return Response.status(status).build();
+            if (instances.length > 0) {
+                for (Object instance : instances) {
+                    INeutronRouterAware service = (INeutronRouterAware) instance;
+                    int status = service.canUpdateRouter(singleton, original);
+                    if (status < 200 || status > 299)
+                        return Response.status(status).build();
+                }
+            } else {
+                throw new ServiceUnavailableException("No providers registered.  Please try again later");
             }
+        } else {
+            throw new ServiceUnavailableException("Couldn't get providers list.  Please try again later");
         }
         /*
          * if the external gateway info is being changed, verify that the new network
@@ -338,14 +345,20 @@ public class NeutronRoutersNorthbound {
         if (routerInterface.routerInUse(routerUUID))
             throw new ResourceConflictException("Router UUID in Use");
         NeutronRouter singleton = routerInterface.getRouter(routerUUID);
-        Object[] instances = ServiceHelper.getGlobalInstances(INeutronRouterAware.class, this, null);
+        Object[] instances = NeutronUtil.getInstances(INeutronRouterAware.class, this);
         if (instances != null) {
-            for (Object instance : instances) {
-                INeutronRouterAware service = (INeutronRouterAware) instance;
-                int status = service.canDeleteRouter(singleton);
-                if (status < 200 || status > 299)
-                    return Response.status(status).build();
+            if (instances.length > 0) {
+                for (Object instance : instances) {
+                    INeutronRouterAware service = (INeutronRouterAware) instance;
+                    int status = service.canDeleteRouter(singleton);
+                    if (status < 200 || status > 299)
+                        return Response.status(status).build();
+                }
+            } else {
+                throw new ServiceUnavailableException("No providers registered.  Please try again later");
             }
+        } else {
+            throw new ServiceUnavailableException("Couldn't get providers list.  Please try again later");
         }
         routerInterface.removeRouter(routerUUID);
         if (instances != null) {
@@ -418,14 +431,20 @@ public class NeutronRoutersNorthbound {
         if (targetPort.getDeviceID() != null ||
                 targetPort.getDeviceOwner() != null)
             throw new ResourceConflictException("Target Port already allocated");
-        Object[] instances = ServiceHelper.getGlobalInstances(INeutronRouterAware.class, this, null);
+        Object[] instances = NeutronUtil.getInstances(INeutronRouterAware.class, this);
         if (instances != null) {
-            for (Object instance : instances) {
-                INeutronRouterAware service = (INeutronRouterAware) instance;
-                int status = service.canAttachInterface(target, input);
-                if (status < 200 || status > 299)
-                    return Response.status(status).build();
+            if (instances.length > 0) {
+                for (Object instance : instances) {
+                    INeutronRouterAware service = (INeutronRouterAware) instance;
+                    int status = service.canAttachInterface(target, input);
+                    if (status < 200 || status > 299)
+                        return Response.status(status).build();
+                }
+            } else {
+                throw new ServiceUnavailableException("No providers registered.  Please try again later");
             }
+        } else {
+            throw new ServiceUnavailableException("Couldn't get providers list.  Please try again later");
         }
 
         //mark the port device id and device owner fields
@@ -496,14 +515,20 @@ public class NeutronRoutersNorthbound {
             input.setID(target.getID());
             input.setTenantID(target.getTenantID());
 
-            Object[] instances = ServiceHelper.getGlobalInstances(INeutronRouterAware.class, this, null);
+            Object[] instances = NeutronUtil.getInstances(INeutronRouterAware.class, this);
             if (instances != null) {
-                for (Object instance : instances) {
-                    INeutronRouterAware service = (INeutronRouterAware) instance;
-                    int status = service.canDetachInterface(target, input);
-                    if (status < 200 || status > 299)
-                        return Response.status(status).build();
+                if (instances.length > 0) {
+                    for (Object instance : instances) {
+                        INeutronRouterAware service = (INeutronRouterAware) instance;
+                        int status = service.canDetachInterface(target, input);
+                        if (status < 200 || status > 299)
+                            return Response.status(status).build();
+                    }
+                } else {
+                    throw new ServiceUnavailableException("No providers registered.  Please try again later");
                 }
+            } else {
+                throw new ServiceUnavailableException("Couldn't get providers list.  Please try again later");
             }
 
             // reset the port ownership
@@ -533,11 +558,25 @@ public class NeutronRoutersNorthbound {
             input.setSubnetUUID(targetInterface.getSubnetUUID());
             input.setID(target.getID());
             input.setTenantID(target.getTenantID());
+            Object[] instances = NeutronUtil.getInstances(INeutronRouterAware.class, this);
+            if (instances != null) {
+                if (instances.length > 0) {
+                    for (Object instance : instances) {
+                        INeutronRouterAware service = (INeutronRouterAware) instance;
+                        int status = service.canDetachInterface(target, input);
+                        if (status < 200 || status > 299)
+                            return Response.status(status).build();
+                    }
+                } else {
+                    throw new ServiceUnavailableException("No providers registered.  Please try again later");
+                }
+            } else {
+                throw new ServiceUnavailableException("Couldn't get providers list.  Please try again later");
+            }
             NeutronPort port = portInterface.getPort(input.getPortUUID());
             port.setDeviceID(null);
             port.setDeviceOwner(null);
             target.removeInterface(input.getPortUUID());
-            Object[] instances = ServiceHelper.getGlobalInstances(INeutronRouterAware.class, this, null);
             for (Object instance : instances) {
                 INeutronRouterAware service = (INeutronRouterAware) instance;
                 service.neutronRouterInterfaceDetached(target, input);
@@ -565,19 +604,32 @@ public class NeutronRoutersNorthbound {
             }
             if (!subnet.isValidIP(port.getFixedIPs().get(0).getIpAddress()))
                 throw new ResourceConflictException("Target Port IP not in Target Subnet");
+            Object[] instances = NeutronUtil.getInstances(INeutronRouterAware.class, this);
+            if (instances != null) {
+                if (instances.length > 0) {
+                    for (Object instance : instances) {
+                        INeutronRouterAware service = (INeutronRouterAware) instance;
+                        int status = service.canDetachInterface(target, input);
+                        if (status < 200 || status > 299)
+                            return Response.status(status).build();
+                    }
+                } else {
+                    throw new ServiceUnavailableException("No providers registered.  Please try again later");
+                }
+            } else {
+                throw new ServiceUnavailableException("Couldn't get providers list.  Please try again later");
+            }
             input.setID(target.getID());
             input.setTenantID(target.getTenantID());
-            Object[] instances = ServiceHelper.getGlobalInstances(INeutronRouterAware.class, this, null);
+            port.setDeviceID(null);
+            port.setDeviceOwner(null);
+            target.removeInterface(input.getPortUUID());
             if (instances != null) {
                 for (Object instance : instances) {
                     INeutronRouterAware service = (INeutronRouterAware) instance;
                     service.canDetachInterface(target, input);
                 }
-            }
-            port.setDeviceID(null);
-            port.setDeviceOwner(null);
-            target.removeInterface(input.getPortUUID());
-            for (Object instance : instances) {
+            }            for (Object instance : instances) {
                 INeutronRouterAware service = (INeutronRouterAware) instance;
                 service.neutronRouterInterfaceDetached(target, input);
             }