From b42f1fd9a3fd26047ec8751419c55e8212f25504 Mon Sep 17 00:00:00 2001 From: Ryan Moats Date: Thu, 12 Feb 2015 15:40:05 -0600 Subject: [PATCH] Neutron to return ServiceUnavailable if no providers registered opNFV interwork revealed that neutron returns 200 in error cases where no SB providers are registered and if there is an error getting the list of SB providers. Close both of these holes by returning Service Unavailable Status Change-Id: Iefa092a35bdc178f632373eac3b84578028d3768 Signed-off-by: Ryan Moats --- .../northbound/NeutronFirewallNorthbound.java | 64 ++++++--- .../NeutronFirewallPolicyNorthbound.java | 64 ++++++--- .../NeutronFirewallRulesNorthbound.java | 64 ++++++--- .../NeutronFloatingIPsNorthbound.java | 48 ++++--- ...onLoadBalancerHealthMonitorNorthbound.java | 64 ++++++--- ...NeutronLoadBalancerListenerNorthbound.java | 64 ++++++--- .../NeutronLoadBalancerNorthbound.java | 66 +++++++--- ...tronLoadBalancerPoolMembersNorthbound.java | 49 ++++--- .../NeutronLoadBalancerPoolNorthbound.java | 64 ++++++--- .../northbound/NeutronNetworksNorthbound.java | 67 +++++++--- .../northbound/NeutronPortsNorthbound.java | 65 +++++++--- .../northbound/NeutronRoutersNorthbound.java | 121 +++++++++++++----- .../NeutronSecurityGroupsNorthbound.java | 66 +++++++--- .../NeutronSecurityRulesNorthbound.java | 67 +++++++--- .../northbound/NeutronSubnetsNorthbound.java | 64 ++++++--- 15 files changed, 692 insertions(+), 305 deletions(-) diff --git a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronFirewallNorthbound.java b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronFirewallNorthbound.java index 33043d4389..b97a554f60 100644 --- a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronFirewallNorthbound.java +++ b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronFirewallNorthbound.java @@ -187,13 +187,19 @@ public class NeutronFirewallNorthbound { firewallInterface.addNeutronFirewall(singleton); Object[] instances = NeutronUtil.getInstances(INeutronFirewallAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronFirewallAware service = (INeutronFirewallAware) instance; - int status = service.canCreateNeutronFirewall(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronFirewallAware service = (INeutronFirewallAware) instance; + int status = service.canCreateNeutronFirewall(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"); } firewallInterface.addNeutronFirewall(singleton); if (instances != null) { @@ -220,13 +226,19 @@ public class NeutronFirewallNorthbound { throw new BadRequestException("Firewall UUID already exists"); } if (instances != null) { - for (Object instance : instances) { - INeutronFirewallAware service = (INeutronFirewallAware) instance; - int status = service.canCreateNeutronFirewall(test); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronFirewallAware service = (INeutronFirewallAware) instance; + int status = service.canCreateNeutronFirewall(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"); } } @@ -298,13 +310,19 @@ public class NeutronFirewallNorthbound { Object[] instances = NeutronUtil.getInstances(INeutronFirewallAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronFirewallAware service = (INeutronFirewallAware) instance; - int status = service.canUpdateNeutronFirewall(delta, original); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronFirewallAware service = (INeutronFirewallAware) instance; + int status = service.canUpdateNeutronFirewall(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"); } /* @@ -352,13 +370,19 @@ public class NeutronFirewallNorthbound { NeutronFirewall singleton = firewallInterface.getNeutronFirewall(firewallUUID); Object[] instances = NeutronUtil.getInstances(INeutronFirewallAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronFirewallAware service = (INeutronFirewallAware) instance; - int status = service.canDeleteNeutronFirewall(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronFirewallAware service = (INeutronFirewallAware) instance; + int status = service.canDeleteNeutronFirewall(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"); } /* diff --git a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronFirewallPolicyNorthbound.java b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronFirewallPolicyNorthbound.java index 08e563138c..e9b813d731 100644 --- a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronFirewallPolicyNorthbound.java +++ b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronFirewallPolicyNorthbound.java @@ -184,13 +184,19 @@ public class NeutronFirewallPolicyNorthbound { Object[] instances = NeutronUtil.getInstances(INeutronFirewallPolicyAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronFirewallPolicyAware service = (INeutronFirewallPolicyAware) instance; - int status = service.canCreateNeutronFirewallPolicy(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronFirewallPolicyAware service = (INeutronFirewallPolicyAware) instance; + int status = service.canCreateNeutronFirewallPolicy(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"); } firewallPolicyInterface.addNeutronFirewallPolicy(singleton); if (instances != null) { @@ -218,13 +224,19 @@ public class NeutronFirewallPolicyNorthbound { throw new BadRequestException("Firewall Policy UUID already exists"); } if (instances != null) { - for (Object instance : instances) { - INeutronFirewallPolicyAware service = (INeutronFirewallPolicyAware) instance; - int status = service.canCreateNeutronFirewallPolicy(test); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronFirewallPolicyAware service = (INeutronFirewallPolicyAware) instance; + int status = service.canCreateNeutronFirewallPolicy(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"); } } /* @@ -295,13 +307,19 @@ public class NeutronFirewallPolicyNorthbound { Object[] instances = NeutronUtil.getInstances(INeutronFirewallPolicyAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronFirewallPolicyAware service = (INeutronFirewallPolicyAware) instance; - int status = service.canUpdateNeutronFirewallPolicy(delta, original); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronFirewallPolicyAware service = (INeutronFirewallPolicyAware) instance; + int status = service.canUpdateNeutronFirewallPolicy(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"); } /* @@ -349,13 +367,19 @@ public class NeutronFirewallPolicyNorthbound { NeutronFirewallPolicy singleton = firewallPolicyInterface.getNeutronFirewallPolicy(firewallPolicyUUID); Object[] instances = NeutronUtil.getInstances(INeutronFirewallPolicyAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronFirewallPolicyAware service = (INeutronFirewallPolicyAware) instance; - int status = service.canDeleteNeutronFirewallPolicy(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronFirewallPolicyAware service = (INeutronFirewallPolicyAware) instance; + int status = service.canDeleteNeutronFirewallPolicy(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"); } firewallPolicyInterface.removeNeutronFirewallPolicy(firewallPolicyUUID); diff --git a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronFirewallRulesNorthbound.java b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronFirewallRulesNorthbound.java index 5e51711e5b..40b830da55 100644 --- a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronFirewallRulesNorthbound.java +++ b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronFirewallRulesNorthbound.java @@ -220,13 +220,19 @@ public class NeutronFirewallRulesNorthbound { firewallRuleInterface.addNeutronFirewallRule(singleton); Object[] instances = NeutronUtil.getInstances(INeutronFirewallRuleAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronFirewallRuleAware service = (INeutronFirewallRuleAware) instance; - int status = service.canCreateNeutronFirewallRule(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronFirewallRuleAware service = (INeutronFirewallRuleAware) instance; + int status = service.canCreateNeutronFirewallRule(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"); } // add rule to cache singleton.initDefaults(); @@ -256,13 +262,19 @@ public class NeutronFirewallRulesNorthbound { throw new BadRequestException("Firewall Rule UUID already exists"); } if (instances != null) { - for (Object instance : instances) { - INeutronFirewallRuleAware service = (INeutronFirewallRuleAware) instance; - int status = service.canCreateNeutronFirewallRule(test); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronFirewallRuleAware service = (INeutronFirewallRuleAware) instance; + int status = service.canCreateNeutronFirewallRule(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"); } } /* @@ -342,13 +354,19 @@ public class NeutronFirewallRulesNorthbound { Object[] instances = NeutronUtil.getInstances(INeutronFirewallRuleAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronFirewallRuleAware service = (INeutronFirewallRuleAware) instance; - int status = service.canUpdateNeutronFirewallRule(delta, original); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronFirewallRuleAware service = (INeutronFirewallRuleAware) instance; + int status = service.canUpdateNeutronFirewallRule(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"); } /* @@ -399,13 +417,19 @@ public class NeutronFirewallRulesNorthbound { NeutronFirewallRule singleton = firewallRuleInterface.getNeutronFirewallRule(firewallRuleUUID); Object[] instances = NeutronUtil.getInstances(INeutronFirewallRuleAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronFirewallRuleAware service = (INeutronFirewallRuleAware) instance; - int status = service.canDeleteNeutronFirewallRule(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronFirewallRuleAware service = (INeutronFirewallRuleAware) instance; + int status = service.canDeleteNeutronFirewallRule(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"); } /* diff --git a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronFloatingIPsNorthbound.java b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronFloatingIPsNorthbound.java index 812a09a0a6..3e6c2a4feb 100644 --- a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronFloatingIPsNorthbound.java +++ b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronFloatingIPsNorthbound.java @@ -242,12 +242,18 @@ public class NeutronFloatingIPsNorthbound { } Object[] instances = NeutronUtil.getInstances(INeutronFloatingIPAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronFloatingIPAware service = (INeutronFloatingIPAware) instance; - int status = service.canCreateFloatingIP(singleton); - if (status < 200 || status > 299) - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronFloatingIPAware service = (INeutronFloatingIPAware) instance; + int status = service.canCreateFloatingIP(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"); } floatingIPInterface.addFloatingIP(singleton); if (instances != null) { @@ -363,12 +369,18 @@ public class NeutronFloatingIPsNorthbound { NeutronFloatingIP target = floatingIPInterface.getFloatingIP(floatingipUUID); Object[] instances = NeutronUtil.getInstances(INeutronFloatingIPAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronFloatingIPAware service = (INeutronFloatingIPAware) instance; - int status = service.canUpdateFloatingIP(singleton, target); - if (status < 200 || status > 299) - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronFloatingIPAware service = (INeutronFloatingIPAware) instance; + int status = service.canUpdateFloatingIP(singleton, target); + 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"); } floatingIPInterface.updateFloatingIP(floatingipUUID, singleton); target = floatingIPInterface.getFloatingIP(floatingipUUID); @@ -406,12 +418,18 @@ public class NeutronFloatingIPsNorthbound { NeutronFloatingIP singleton = floatingIPInterface.getFloatingIP(floatingipUUID); Object[] instances = NeutronUtil.getInstances(INeutronFloatingIPAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronFloatingIPAware service = (INeutronFloatingIPAware) instance; - int status = service.canDeleteFloatingIP(singleton); - if (status < 200 || status > 299) - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronFloatingIPAware service = (INeutronFloatingIPAware) instance; + int status = service.canDeleteFloatingIP(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"); } floatingIPInterface.removeFloatingIP(floatingipUUID); if (instances != null) { diff --git a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronLoadBalancerHealthMonitorNorthbound.java b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronLoadBalancerHealthMonitorNorthbound.java index 85aba5d690..aa30e948a2 100644 --- a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronLoadBalancerHealthMonitorNorthbound.java +++ b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronLoadBalancerHealthMonitorNorthbound.java @@ -210,13 +210,19 @@ public class NeutronLoadBalancerHealthMonitorNorthbound { Object[] instances = NeutronUtil.getInstances(INeutronLoadBalancerHealthMonitorAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronLoadBalancerHealthMonitorAware service = (INeutronLoadBalancerHealthMonitorAware) instance; - int status = service.canCreateNeutronLoadBalancerHealthMonitor(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronLoadBalancerHealthMonitorAware service = (INeutronLoadBalancerHealthMonitorAware) instance; + int status = service.canCreateNeutronLoadBalancerHealthMonitor(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"); } loadBalancerHealthMonitorInterface.addNeutronLoadBalancerHealthMonitor(singleton); if (instances != null) { @@ -245,13 +251,19 @@ public class NeutronLoadBalancerHealthMonitorNorthbound { throw new BadRequestException("LoadBalancerHealthMonitor UUID already exists"); } if (instances != null) { - for (Object instance : instances) { - INeutronLoadBalancerHealthMonitorAware service = (INeutronLoadBalancerHealthMonitorAware) instance; - int status = service.canCreateNeutronLoadBalancerHealthMonitor(test); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronLoadBalancerHealthMonitorAware service = (INeutronLoadBalancerHealthMonitorAware) instance; + int status = service.canCreateNeutronLoadBalancerHealthMonitor(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"); } } /* @@ -328,13 +340,19 @@ public class NeutronLoadBalancerHealthMonitorNorthbound { Object[] instances = NeutronUtil.getInstances(INeutronLoadBalancerHealthMonitorAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronLoadBalancerHealthMonitorAware service = (INeutronLoadBalancerHealthMonitorAware) instance; - int status = service.canUpdateNeutronLoadBalancerHealthMonitor(delta, original); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronLoadBalancerHealthMonitorAware service = (INeutronLoadBalancerHealthMonitorAware) instance; + int status = service.canUpdateNeutronLoadBalancerHealthMonitor(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"); } /* @@ -386,13 +404,19 @@ public class NeutronLoadBalancerHealthMonitorNorthbound { NeutronLoadBalancerHealthMonitor singleton = loadBalancerHealthMonitorInterface.getNeutronLoadBalancerHealthMonitor(loadBalancerHealthMonitorID); Object[] instances = NeutronUtil.getInstances(INeutronLoadBalancerHealthMonitorAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronLoadBalancerHealthMonitorAware service = (INeutronLoadBalancerHealthMonitorAware) instance; - int status = service.canDeleteNeutronLoadBalancerHealthMonitor(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronLoadBalancerHealthMonitorAware service = (INeutronLoadBalancerHealthMonitorAware) instance; + int status = service.canDeleteNeutronLoadBalancerHealthMonitor(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"); } loadBalancerHealthMonitorInterface.removeNeutronLoadBalancerHealthMonitor(loadBalancerHealthMonitorID); if (instances != null) { diff --git a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronLoadBalancerListenerNorthbound.java b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronLoadBalancerListenerNorthbound.java index 345c7ee0f3..5d877c59f4 100644 --- a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronLoadBalancerListenerNorthbound.java +++ b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronLoadBalancerListenerNorthbound.java @@ -198,13 +198,19 @@ public class NeutronLoadBalancerListenerNorthbound { Object[] instances = NeutronUtil.getInstances(INeutronLoadBalancerListenerAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronLoadBalancerListenerAware service = (INeutronLoadBalancerListenerAware) instance; - int status = service.canCreateNeutronLoadBalancerListener(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronLoadBalancerListenerAware service = (INeutronLoadBalancerListenerAware) instance; + int status = service.canCreateNeutronLoadBalancerListener(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"); } loadBalancerListenerInterface.addNeutronLoadBalancerListener(singleton); if (instances != null) { @@ -232,13 +238,19 @@ public class NeutronLoadBalancerListenerNorthbound { throw new BadRequestException("LoadBalancerListener UUID already exists"); } if (instances != null) { - for (Object instance : instances) { - INeutronLoadBalancerListenerAware service = (INeutronLoadBalancerListenerAware) instance; - int status = service.canCreateNeutronLoadBalancerListener(test); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronLoadBalancerListenerAware service = (INeutronLoadBalancerListenerAware) instance; + int status = service.canCreateNeutronLoadBalancerListener(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"); } } /* @@ -312,13 +324,19 @@ public class NeutronLoadBalancerListenerNorthbound { Object[] instances = NeutronUtil.getInstances(INeutronLoadBalancerListenerAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronLoadBalancerListenerAware service = (INeutronLoadBalancerListenerAware) instance; - int status = service.canUpdateNeutronLoadBalancerListener(delta, original); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronLoadBalancerListenerAware service = (INeutronLoadBalancerListenerAware) instance; + int status = service.canUpdateNeutronLoadBalancerListener(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"); } /* @@ -366,13 +384,19 @@ public class NeutronLoadBalancerListenerNorthbound { NeutronLoadBalancerListener singleton = loadBalancerListenerInterface.getNeutronLoadBalancerListener(loadBalancerListenerID); Object[] instances = NeutronUtil.getInstances(INeutronLoadBalancerListenerAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronLoadBalancerListenerAware service = (INeutronLoadBalancerListenerAware) instance; - int status = service.canDeleteNeutronLoadBalancerListener(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronLoadBalancerListenerAware service = (INeutronLoadBalancerListenerAware) instance; + int status = service.canDeleteNeutronLoadBalancerListener(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"); } loadBalancerListenerInterface.removeNeutronLoadBalancerListener(loadBalancerListenerID); diff --git a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronLoadBalancerNorthbound.java b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronLoadBalancerNorthbound.java index 308041fe59..67557ce41f 100644 --- a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronLoadBalancerNorthbound.java +++ b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronLoadBalancerNorthbound.java @@ -186,14 +186,21 @@ public class NeutronLoadBalancerNorthbound { } Object[] instances = NeutronUtil.getInstances(INeutronLoadBalancerAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronLoadBalancerAware service = (INeutronLoadBalancerAware) instance; - int status = service.canCreateNeutronLoadBalancer(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronLoadBalancerAware service = (INeutronLoadBalancerAware) instance; + int status = service.canCreateNeutronLoadBalancer(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"); } + loadBalancerInterface.addNeutronLoadBalancer(singleton); if (instances != null) { for (Object instance : instances) { @@ -220,13 +227,19 @@ public class NeutronLoadBalancerNorthbound { throw new BadRequestException("Load Balancer Pool UUID already exists"); } if (instances != null) { - for (Object instance : instances) { - INeutronLoadBalancerAware service = (INeutronLoadBalancerAware) instance; - int status = service.canCreateNeutronLoadBalancer(test); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronLoadBalancerAware service = (INeutronLoadBalancerAware) instance; + int status = service.canCreateNeutronLoadBalancer(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"); } } /* @@ -298,13 +311,19 @@ public class NeutronLoadBalancerNorthbound { Object[] instances = NeutronUtil.getInstances(INeutronLoadBalancerAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronLoadBalancerAware service = (INeutronLoadBalancerAware) instance; - int status = service.canUpdateNeutronLoadBalancer(delta, original); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronLoadBalancerAware service = (INeutronLoadBalancerAware) instance; + int status = service.canUpdateNeutronLoadBalancer(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"); } /* @@ -355,15 +374,22 @@ public class NeutronLoadBalancerNorthbound { NeutronLoadBalancer singleton = loadBalancerInterface.getNeutronLoadBalancer(loadBalancerID); Object[] instances = NeutronUtil.getInstances(INeutronLoadBalancerAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronLoadBalancerAware service = (INeutronLoadBalancerAware) instance; - int status = service.canDeleteNeutronLoadBalancer(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronLoadBalancerAware service = (INeutronLoadBalancerAware) instance; + int status = service.canDeleteNeutronLoadBalancer(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"); } + loadBalancerInterface.removeNeutronLoadBalancer(loadBalancerID); if (instances != null) { for (Object instance : instances) { diff --git a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronLoadBalancerPoolMembersNorthbound.java b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronLoadBalancerPoolMembersNorthbound.java index f9540679cd..22d118ae79 100644 --- a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronLoadBalancerPoolMembersNorthbound.java +++ b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronLoadBalancerPoolMembersNorthbound.java @@ -200,14 +200,21 @@ public Response createLoadBalancerPoolMember( Object[] instances = NeutronUtil.getInstances(INeutronLoadBalancerPoolMemberAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronLoadBalancerPoolMemberAware service = (INeutronLoadBalancerPoolMemberAware) instance; - int status = service.canCreateNeutronLoadBalancerPoolMember(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronLoadBalancerPoolMemberAware service = (INeutronLoadBalancerPoolMemberAware) instance; + int status = service.canCreateNeutronLoadBalancerPoolMember(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"); } + if (instances != null) { for (Object instance : instances) { INeutronLoadBalancerPoolMemberAware service = (INeutronLoadBalancerPoolMemberAware) instance; @@ -242,13 +249,19 @@ public Response createLoadBalancerPoolMember( throw new BadRequestException("Load Balancer PoolMember UUID already exists"); } if (instances != null) { - for (Object instance : instances) { - INeutronLoadBalancerPoolMemberAware service = (INeutronLoadBalancerPoolMemberAware) instance; - int status = service.canCreateNeutronLoadBalancerPoolMember(test); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronLoadBalancerPoolMemberAware service = (INeutronLoadBalancerPoolMemberAware) instance; + int status = service.canCreateNeutronLoadBalancerPoolMember(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"); } } /* @@ -334,13 +347,19 @@ public Response deleteLoadBalancerPoolMember( Object[] instances = NeutronUtil.getInstances(INeutronLoadBalancerPoolMemberAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronLoadBalancerPoolMemberAware service = (INeutronLoadBalancerPoolMemberAware) instance; - int status = service.canDeleteNeutronLoadBalancerPoolMember(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronLoadBalancerPoolMemberAware service = (INeutronLoadBalancerPoolMemberAware) instance; + int status = service.canDeleteNeutronLoadBalancerPoolMember(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"); } if (instances != null) { diff --git a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronLoadBalancerPoolNorthbound.java b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronLoadBalancerPoolNorthbound.java index 77bb525c84..ea4e2d1c9a 100644 --- a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronLoadBalancerPoolNorthbound.java +++ b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronLoadBalancerPoolNorthbound.java @@ -198,13 +198,19 @@ public class NeutronLoadBalancerPoolNorthbound { Object[] instances = NeutronUtil.getInstances(INeutronLoadBalancerPoolAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronLoadBalancerPoolAware service = (INeutronLoadBalancerPoolAware) instance; - int status = service.canCreateNeutronLoadBalancerPool(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronLoadBalancerPoolAware service = (INeutronLoadBalancerPoolAware) instance; + int status = service.canCreateNeutronLoadBalancerPool(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"); } loadBalancerPoolInterface.addNeutronLoadBalancerPool(singleton); if (instances != null) { @@ -232,13 +238,19 @@ public class NeutronLoadBalancerPoolNorthbound { throw new BadRequestException("Load Balancer Pool UUID already exists"); } if (instances != null) { - for (Object instance : instances) { - INeutronLoadBalancerPoolAware service = (INeutronLoadBalancerPoolAware) instance; - int status = service.canCreateNeutronLoadBalancerPool(test); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronLoadBalancerPoolAware service = (INeutronLoadBalancerPoolAware) instance; + int status = service.canCreateNeutronLoadBalancerPool(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"); } } /* @@ -311,13 +323,19 @@ public class NeutronLoadBalancerPoolNorthbound { Object[] instances = NeutronUtil.getInstances(INeutronLoadBalancerPoolAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronLoadBalancerPoolAware service = (INeutronLoadBalancerPoolAware) instance; - int status = service.canUpdateNeutronLoadBalancerPool(delta, original); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronLoadBalancerPoolAware service = (INeutronLoadBalancerPoolAware) instance; + int status = service.canUpdateNeutronLoadBalancerPool(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"); } /* @@ -366,13 +384,19 @@ public class NeutronLoadBalancerPoolNorthbound { NeutronLoadBalancerPool singleton = loadBalancerPoolInterface.getNeutronLoadBalancerPool(loadBalancerPoolUUID); Object[] instances = NeutronUtil.getInstances(INeutronLoadBalancerPoolAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronLoadBalancerPoolAware service = (INeutronLoadBalancerPoolAware) instance; - int status = service.canDeleteNeutronLoadBalancerPool(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronLoadBalancerPoolAware service = (INeutronLoadBalancerPoolAware) instance; + int status = service.canDeleteNeutronLoadBalancerPool(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"); } /* diff --git a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronNetworksNorthbound.java b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronNetworksNorthbound.java index 9c99f346e8..3a3c657956 100644 --- a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronNetworksNorthbound.java +++ b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronNetworksNorthbound.java @@ -204,13 +204,19 @@ public class NeutronNetworksNorthbound { Object[] instances = NeutronUtil.getInstances(INeutronNetworkAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronNetworkAware service = (INeutronNetworkAware) instance; - int status = service.canCreateNetwork(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronNetworkAware service = (INeutronNetworkAware) instance; + int status = service.canCreateNetwork(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"); } // add network to cache @@ -242,13 +248,19 @@ public class NeutronNetworksNorthbound { throw new BadRequestException("network UUID already exists"); } if (instances != null) { - for (Object instance: instances) { - INeutronNetworkAware service = (INeutronNetworkAware) instance; - int status = service.canCreateNetwork(test); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance: instances) { + INeutronNetworkAware service = (INeutronNetworkAware) instance; + int status = service.canCreateNetwork(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"); } testMap.put(test.getID(),test); } @@ -312,14 +324,20 @@ public class NeutronNetworksNorthbound { Object[] instances = NeutronUtil.getInstances(INeutronNetworkAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronNetworkAware service = (INeutronNetworkAware) instance; - NeutronNetwork original = networkInterface.getNetwork(netUUID); - int status = service.canUpdateNetwork(delta, original); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronNetworkAware service = (INeutronNetworkAware) instance; + NeutronNetwork original = networkInterface.getNetwork(netUUID); + int status = service.canUpdateNetwork(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"); } // update network object and return the modified object @@ -366,14 +384,21 @@ public class NeutronNetworksNorthbound { NeutronNetwork singleton = networkInterface.getNetwork(netUUID); Object[] instances = NeutronUtil.getInstances(INeutronNetworkAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronNetworkAware service = (INeutronNetworkAware) instance; - int status = service.canDeleteNetwork(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronNetworkAware service = (INeutronNetworkAware) instance; + int status = service.canDeleteNetwork(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"); } + networkInterface.removeNetwork(netUUID); if (instances != null) { for (Object instance : instances) { diff --git a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronPortsNorthbound.java b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronPortsNorthbound.java index 23f4979f23..5ff3de58d6 100644 --- a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronPortsNorthbound.java +++ b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronPortsNorthbound.java @@ -259,16 +259,21 @@ public class NeutronPortsNorthbound { Object[] instances = NeutronUtil.getInstances(INeutronPortAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronPortAware service = (INeutronPortAware) instance; - int status = service.canCreatePort(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronPortAware service = (INeutronPortAware) instance; + int status = service.canCreatePort(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"); } - // add the port to the cache portInterface.addPort(singleton); if (instances != null) { @@ -353,13 +358,19 @@ public class NeutronPortsNorthbound { } } if (instances != null) { - for (Object instance : instances) { - INeutronPortAware service = (INeutronPortAware) instance; - int status = service.canCreatePort(test); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronPortAware service = (INeutronPortAware) instance; + int status = service.canCreatePort(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"); } } @@ -429,13 +440,19 @@ public class NeutronPortsNorthbound { Object[] instances = NeutronUtil.getInstances(INeutronPortAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronPortAware service = (INeutronPortAware) instance; - int status = service.canUpdatePort(singleton, original); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronPortAware service = (INeutronPortAware) instance; + int status = service.canUpdatePort(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"); } // Verify the new fixed ips are valid @@ -511,13 +528,19 @@ public class NeutronPortsNorthbound { NeutronPort singleton = portInterface.getPort(portUUID); Object[] instances = NeutronUtil.getInstances(INeutronPortAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronPortAware service = (INeutronPortAware) instance; - int status = service.canDeletePort(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronPortAware service = (INeutronPortAware) instance; + int status = service.canDeletePort(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"); } portInterface.removePort(portUUID); if (instances != null) { diff --git a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronRoutersNorthbound.java b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronRoutersNorthbound.java index 45e84f4d15..ccf5ddd1a4 100644 --- a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronRoutersNorthbound.java +++ b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronRoutersNorthbound.java @@ -194,12 +194,18 @@ public class NeutronRoutersNorthbound { } 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"); } /* @@ -270,12 +276,18 @@ public class NeutronRoutersNorthbound { 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 @@ -335,12 +347,18 @@ public class NeutronRoutersNorthbound { NeutronRouter singleton = routerInterface.getRouter(routerUUID); 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) { @@ -415,12 +433,18 @@ public class NeutronRoutersNorthbound { throw new ResourceConflictException("Target Port already allocated"); 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 @@ -493,12 +517,18 @@ public class NeutronRoutersNorthbound { 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 @@ -528,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 = NeutronUtil.getInstances(INeutronRouterAware.class, this); for (Object instance : instances) { INeutronRouterAware service = (INeutronRouterAware) instance; service.neutronRouterInterfaceDetached(target, input); @@ -560,19 +604,32 @@ public class NeutronRoutersNorthbound { } if (!subnet.isValidIP(port.getFixedIPs().get(0).getIpAddress())) throw new ResourceConflictException("Target Port IP not in Target Subnet"); - input.setID(target.getID()); - input.setTenantID(target.getTenantID()); Object[] instances = NeutronUtil.getInstances(INeutronRouterAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronRouterAware service = (INeutronRouterAware) instance; - service.canDetachInterface(target, input); + 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()); port.setDeviceID(null); port.setDeviceOwner(null); target.removeInterface(input.getPortUUID()); - for (Object instance : instances) { + if (instances != null) { + for (Object instance : instances) { + INeutronRouterAware service = (INeutronRouterAware) instance; + service.canDetachInterface(target, input); + } + } for (Object instance : instances) { INeutronRouterAware service = (INeutronRouterAware) instance; service.neutronRouterInterfaceDetached(target, input); } diff --git a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronSecurityGroupsNorthbound.java b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronSecurityGroupsNorthbound.java index bce4de7cc2..d9ca6d4512 100644 --- a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronSecurityGroupsNorthbound.java +++ b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronSecurityGroupsNorthbound.java @@ -178,13 +178,19 @@ public class NeutronSecurityGroupsNorthbound { Object[] instances = NeutronUtil.getInstances(INeutronSecurityGroupAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronSecurityGroupAware service = (INeutronSecurityGroupAware) instance; - int status = service.canCreateNeutronSecurityGroup(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronSecurityGroupAware service = (INeutronSecurityGroupAware) instance; + int status = service.canCreateNeutronSecurityGroup(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"); } // Add to Neutron cache securityGroupInterface.addNeutronSecurityGroup(singleton); @@ -209,10 +215,18 @@ public class NeutronSecurityGroupsNorthbound { if (securityGroupInterface.neutronSecurityGroupExists(test.getSecurityGroupUUID())) { throw new BadRequestException("Security Group UUID already is already created"); } - if (instances != null) for (Object instance : instances) { - INeutronSecurityGroupAware service = (INeutronSecurityGroupAware) instance; - int status = service.canCreateNeutronSecurityGroup(test); - if ((status < 200) || (status > 299)) return Response.status(status).build(); + if (instances != null) { + if (instances.length > 0) { + for (Object instance : instances) { + INeutronSecurityGroupAware service = (INeutronSecurityGroupAware) instance; + int status = service.canCreateNeutronSecurityGroup(test); + if ((status < 200) || (status > 299)) return Response.status(status).build(); + } + } else { + throw new BadRequestException("No providers registered. Please try again later"); + } + } else { + throw new ServiceUnavailableException("Couldn't get providers list. Please try again later"); } } @@ -278,13 +292,19 @@ public class NeutronSecurityGroupsNorthbound { Object[] instances = NeutronUtil.getInstances(INeutronSecurityGroupAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronSecurityGroupAware service = (INeutronSecurityGroupAware) instance; - int status = service.canUpdateNeutronSecurityGroup(delta, original); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronSecurityGroupAware service = (INeutronSecurityGroupAware) instance; + int status = service.canUpdateNeutronSecurityGroup(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"); } /* @@ -333,13 +353,19 @@ public class NeutronSecurityGroupsNorthbound { NeutronSecurityGroup singleton = securityGroupInterface.getNeutronSecurityGroup(securityGroupUUID); Object[] instances = NeutronUtil.getInstances(INeutronSecurityGroupAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronSecurityGroupAware service = (INeutronSecurityGroupAware) instance; - int status = service.canDeleteNeutronSecurityGroup(singleton); - if ((status < 200) || (status > 299)) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronSecurityGroupAware service = (INeutronSecurityGroupAware) instance; + int status = service.canDeleteNeutronSecurityGroup(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"); } /* @@ -354,4 +380,4 @@ public class NeutronSecurityGroupsNorthbound { } return Response.status(204).build(); } -} \ No newline at end of file +} diff --git a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronSecurityRulesNorthbound.java b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronSecurityRulesNorthbound.java index 762317aaf8..9ce98e2b4f 100644 --- a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronSecurityRulesNorthbound.java +++ b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronSecurityRulesNorthbound.java @@ -201,13 +201,19 @@ public class NeutronSecurityRulesNorthbound { } Object[] instances = NeutronUtil.getInstances(INeutronSecurityRuleAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronSecurityRuleAware service = (INeutronSecurityRuleAware) instance; - int status = service.canCreateNeutronSecurityRule(singleton); - if ((status < 200) || (status > 299)) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronSecurityRuleAware service = (INeutronSecurityRuleAware) instance; + int status = service.canCreateNeutronSecurityRule(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"); } // add rule to cache @@ -246,13 +252,19 @@ public class NeutronSecurityRulesNorthbound { throw new BadRequestException("Security Rule UUID already exists"); } if (instances != null) { - for (Object instance : instances) { - INeutronSecurityRuleAware service = (INeutronSecurityRuleAware) instance; - int status = service.canCreateNeutronSecurityRule(test); - if ((status < 200) || (status > 299)) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronSecurityRuleAware service = (INeutronSecurityRuleAware) instance; + int status = service.canCreateNeutronSecurityRule(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"); } } @@ -328,13 +340,19 @@ public class NeutronSecurityRulesNorthbound { Object[] instances = NeutronUtil.getInstances(INeutronSecurityRuleAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronSecurityRuleAware service = (INeutronSecurityRuleAware) instance; - int status = service.canUpdateNeutronSecurityRule(delta, original); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronSecurityRuleAware service = (INeutronSecurityRuleAware) instance; + int status = service.canUpdateNeutronSecurityRule(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"); } /* @@ -383,15 +401,22 @@ public class NeutronSecurityRulesNorthbound { NeutronSecurityRule singleton = securityRuleInterface.getNeutronSecurityRule(securityRuleUUID); Object[] instances = NeutronUtil.getInstances(INeutronSecurityRuleAware.class, this); if (instances != null) { - for (Object instance : instances) { - INeutronSecurityRuleAware service = (INeutronSecurityRuleAware) instance; - int status = service.canDeleteNeutronSecurityRule(singleton); - if (status < 200 || status > 299) { - return Response.status(status).build(); + if (instances.length > 0) { + for (Object instance : instances) { + INeutronSecurityRuleAware service = (INeutronSecurityRuleAware) instance; + int status = service.canDeleteNeutronSecurityRule(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"); } + /* * remove it and return 204 status */ @@ -404,4 +429,4 @@ public class NeutronSecurityRulesNorthbound { } return Response.status(204).build(); } -} \ No newline at end of file +} 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 142b09f8e4..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 @@ -219,13 +219,19 @@ public class NeutronSubnetsNorthbound { } 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) { @@ -269,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"); } } @@ -344,13 +356,19 @@ public class NeutronSubnetsNorthbound { 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"); } /* @@ -399,13 +417,19 @@ public class NeutronSubnetsNorthbound { NeutronSubnet singleton = subnetInterface.getSubnet(subnetUUID); 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"); } /* -- 2.36.6