X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetworkconfiguration%2Fneutron%2Fnorthbound%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetworkconfig%2Fneutron%2Fnorthbound%2FNeutronSecurityRulesNorthbound.java;h=9ce98e2b4f343400c8f794e009decebbcd049d76;hp=b2c05e0071d520e1c380644db865bd11798e70c2;hb=72b9cd4df6297f8ffab9453e67781f797f5d1b28;hpb=687598acd2f6b71397b105e93f6a2d1b21a7c0ef 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 b2c05e0071..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 @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; + import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -33,11 +34,6 @@ import org.opendaylight.controller.networkconfig.neutron.INeutronSecurityRuleAwa import org.opendaylight.controller.networkconfig.neutron.INeutronSecurityRuleCRUD; import org.opendaylight.controller.networkconfig.neutron.NeutronCRUDInterfaces; import org.opendaylight.controller.networkconfig.neutron.NeutronSecurityRule; -import org.opendaylight.controller.northbound.commons.RestMessages; -import org.opendaylight.controller.northbound.commons.exception.BadRequestException; -import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException; -import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException; -import org.opendaylight.controller.sal.utils.ServiceHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -203,15 +199,21 @@ public class NeutronSecurityRulesNorthbound { if (securityRuleInterface.neutronSecurityRuleExists(singleton.getSecurityRuleUUID())) { throw new BadRequestException("Security Rule UUID already exists"); } - Object[] instances = ServiceHelper.getGlobalInstances(INeutronSecurityRuleAware.class, this, null); + 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 @@ -235,7 +237,7 @@ public class NeutronSecurityRulesNorthbound { List bulk = input.getBulk(); Iterator i = bulk.iterator(); HashMap testMap = new HashMap(); - Object[] instances = ServiceHelper.getGlobalInstances(INeutronSecurityRuleAware.class, this, null); + Object[] instances = NeutronUtil.getInstances(INeutronSecurityRuleAware.class, this); while (i.hasNext()) { NeutronSecurityRule test = i.next(); @@ -250,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"); } } @@ -330,15 +338,21 @@ public class NeutronSecurityRulesNorthbound { throw new BadRequestException("Attribute edit blocked by Neutron"); } - Object[] instances = ServiceHelper.getGlobalInstances(INeutronSecurityRuleAware.class, this, null); + 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"); } /* @@ -385,17 +399,24 @@ public class NeutronSecurityRulesNorthbound { return Response.status(409).build(); } NeutronSecurityRule singleton = securityRuleInterface.getNeutronSecurityRule(securityRuleUUID); - Object[] instances = ServiceHelper.getGlobalInstances(INeutronSecurityRuleAware.class, this, null); + 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 */ @@ -408,4 +429,4 @@ public class NeutronSecurityRulesNorthbound { } return Response.status(204).build(); } -} \ No newline at end of file +}