X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetworkconfiguration%2Fneutron%2Fnorthbound%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetworkconfig%2Fneutron%2Fnorthbound%2FNeutronSubnetsNorthbound.java;h=fa66501d0ef02183a2089ca9ddc82274e1552d60;hb=3997099eb61b0f2adc47f7a85952c324e9de223f;hp=8f20269603b1ed1802fc04812974125016c1811b;hpb=42c32160bfd41de57189bb246fec5ffb48ed8e9e;p=controller.git diff --git a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronSubnetsNorthbound.java b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronSubnetsNorthbound.java index 8f20269603..fa66501d0e 100644 --- a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronSubnetsNorthbound.java +++ b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronSubnetsNorthbound.java @@ -36,13 +36,6 @@ import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetAware; import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetCRUD; import org.opendaylight.controller.networkconfig.neutron.NeutronCRUDInterfaces; 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.InternalServerErrorException; -import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException; -import org.opendaylight.controller.sal.utils.ServiceHelper; /** * Neutron Northbound REST APIs for Subnets.
@@ -224,15 +217,21 @@ public class NeutronSubnetsNorthbound { if (singleton.gatewayIP_Pool_overlap()) { throw new ResourceConflictException("IP pool overlaps with gateway"); } - Object[] instances = ServiceHelper.getGlobalInstances(INeutronSubnetAware.class, this, null); + Object[] instances = NeutronUtil.getInstances(INeutronSubnetAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronSubnetAware service = (INeutronSubnetAware) instance; - int status = service.canCreateSubnet(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronSubnetAware service = (INeutronSubnetAware) instance; + int status = service.canCreateSubnet(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"); } subnetInterface.addSubnet(singleton); if (instances != null) { @@ -245,7 +244,7 @@ public class NeutronSubnetsNorthbound { List bulk = input.getBulk(); Iterator i = bulk.iterator(); HashMap testMap = new HashMap(); - Object[] instances = ServiceHelper.getGlobalInstances(INeutronSubnetAware.class, this, null); + Object[] instances = NeutronUtil.getInstances(INeutronSubnetAware.class, this); while (i.hasNext()) { NeutronSubnet test = i.next(); @@ -276,13 +275,19 @@ public class NeutronSubnetsNorthbound { throw new ResourceConflictException("IP pool overlaps with gateway"); } if (instances != null) { - for (Object instance : instances) { - INeutronSubnetAware service = (INeutronSubnetAware) instance; - int status = service.canCreateSubnet(test); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronSubnetAware service = (INeutronSubnetAware) instance; + int status = service.canCreateSubnet(test); + 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"); } } @@ -349,15 +354,21 @@ public class NeutronSubnetsNorthbound { throw new BadRequestException("Attribute edit blocked by Neutron"); } - Object[] instances = ServiceHelper.getGlobalInstances(INeutronSubnetAware.class, this, null); + Object[] instances = NeutronUtil.getInstances(INeutronSubnetAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronSubnetAware service = (INeutronSubnetAware) instance; - int status = service.canUpdateSubnet(delta, original); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronSubnetAware service = (INeutronSubnetAware) instance; + int status = service.canUpdateSubnet(delta, 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"); } /* @@ -404,15 +415,21 @@ public class NeutronSubnetsNorthbound { return Response.status(409).build(); } NeutronSubnet singleton = subnetInterface.getSubnet(subnetUUID); - Object[] instances = ServiceHelper.getGlobalInstances(INeutronSubnetAware.class, this, null); + Object[] instances = NeutronUtil.getInstances(INeutronSubnetAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronSubnetAware service = (INeutronSubnetAware) instance; - int status = service.canDeleteSubnet(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronSubnetAware service = (INeutronSubnetAware) instance; + int status = service.canDeleteSubnet(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"); } /*