X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnorthbound%2Fnetworkconfiguration%2Fneutron%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetworkconfig%2Fneutron%2Fnorthbound%2FNeutronSubnetsNorthbound.java;h=699aee9fc3a7d3503e7b1a6d464926da1aefd24f;hp=d2d7a5a671c62325ce1a0d2f8966901867357878;hb=e6d4ee9b3b12a9f1b815bacb0cc9268416451afb;hpb=5961c8a1321aef9945a69677081f02a6b08edc18 diff --git a/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronSubnetsNorthbound.java b/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronSubnetsNorthbound.java index d2d7a5a671..699aee9fc3 100644 --- a/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronSubnetsNorthbound.java +++ b/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronSubnetsNorthbound.java @@ -33,6 +33,7 @@ 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.InternalServerErrorException; import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException; import org.opendaylight.controller.sal.utils.ServiceHelper; @@ -107,10 +108,11 @@ public class NeutronSubnetsNorthbound { (queryGatewayIP == null || queryGatewayIP.equals(oSS.getGatewayIP())) && (queryEnableDHCP == null || queryEnableDHCP.equals(oSS.getEnableDHCP())) && (queryTenantID == null || queryTenantID.equals(oSS.getTenantID()))) { - if (fields.size() > 0) + if (fields.size() > 0) { ans.add(extractFields(oSS,fields)); - else + } else { ans.add(oSS); + } } } //TODO: apply pagination to results @@ -139,15 +141,17 @@ public class NeutronSubnetsNorthbound { throw new ServiceUnavailableException("Subnet CRUD Interface " + RestMessages.SERVICEUNAVAILABLE.toString()); } - if (!subnetInterface.subnetExists(subnetUUID)) + if (!subnetInterface.subnetExists(subnetUUID)) { return Response.status(404).build(); + } if (fields.size() > 0) { NeutronSubnet ans = subnetInterface.getSubnet(subnetUUID); return Response.status(200).entity( new NeutronSubnetRequest(extractFields(ans, fields))).build(); - } else + } else { return Response.status(200).entity( new NeutronSubnetRequest(subnetInterface.getSubnet(subnetUUID))).build(); + } } /** @@ -185,22 +189,29 @@ public class NeutronSubnetsNorthbound { * and that the gateway IP doesn't overlap with the allocation pools * *then* add the subnet to the cache */ - if (subnetInterface.subnetExists(singleton.getID())) + if (subnetInterface.subnetExists(singleton.getID())) { return Response.status(400).build(); - if (!networkInterface.networkExists(singleton.getNetworkUUID())) + } + if (!networkInterface.networkExists(singleton.getNetworkUUID())) { return Response.status(404).build(); - if (!singleton.isValidCIDR()) + } + if (!singleton.isValidCIDR()) { return Response.status(400).build(); - singleton.initDefaults(); - if (singleton.gatewayIP_Pool_overlap()) + } + if (!singleton.initDefaults()) { + throw new InternalServerErrorException("subnet object could not be initialized properly"); + } + if (singleton.gatewayIP_Pool_overlap()) { return Response.status(409).build(); + } Object[] instances = ServiceHelper.getGlobalInstances(INeutronSubnetAware.class, this, null); if (instances != null) { for (Object instance : instances) { INeutronSubnetAware service = (INeutronSubnetAware) instance; int status = service.canCreateSubnet(singleton); - if (status < 200 || status > 299) + if (status < 200 || status > 299) { return Response.status(status).build(); + } } } subnetInterface.addSubnet(singleton); @@ -225,24 +236,32 @@ public class NeutronSubnetsNorthbound { * and that the bulk request doesn't already contain a subnet with this id */ - test.initDefaults(); - if (subnetInterface.subnetExists(test.getID())) + if (!test.initDefaults()) { + throw new InternalServerErrorException("subnet object could not be initialized properly"); + } + if (subnetInterface.subnetExists(test.getID())) { return Response.status(400).build(); - if (testMap.containsKey(test.getID())) + } + if (testMap.containsKey(test.getID())) { return Response.status(400).build(); + } testMap.put(test.getID(), test); - if (!networkInterface.networkExists(test.getNetworkUUID())) + if (!networkInterface.networkExists(test.getNetworkUUID())) { return Response.status(404).build(); - if (!test.isValidCIDR()) + } + if (!test.isValidCIDR()) { return Response.status(400).build(); - if (test.gatewayIP_Pool_overlap()) + } + if (test.gatewayIP_Pool_overlap()) { return Response.status(409).build(); + } if (instances != null) { for (Object instance : instances) { INeutronSubnetAware service = (INeutronSubnetAware) instance; int status = service.canCreateSubnet(test); - if (status < 200 || status > 299) + if (status < 200 || status > 299) { return Response.status(status).build(); + } } } } @@ -292,10 +311,12 @@ public class NeutronSubnetsNorthbound { /* * verify the subnet exists and there is only one delta provided */ - if (!subnetInterface.subnetExists(subnetUUID)) + if (!subnetInterface.subnetExists(subnetUUID)) { return Response.status(404).build(); - if (!input.isSingleton()) + } + if (!input.isSingleton()) { return Response.status(400).build(); + } NeutronSubnet delta = input.getSingleton(); NeutronSubnet original = subnetInterface.getSubnet(subnetUUID); @@ -304,16 +325,18 @@ public class NeutronSubnetsNorthbound { */ if (delta.getID() != null || delta.getTenantID() != null || delta.getIpVersion() != null || delta.getCidr() != null || - delta.getAllocationPools() != null) + delta.getAllocationPools() != null) { return Response.status(400).build(); + } Object[] instances = ServiceHelper.getGlobalInstances(INeutronSubnetAware.class, this, null); if (instances != null) { for (Object instance : instances) { INeutronSubnetAware service = (INeutronSubnetAware) instance; int status = service.canUpdateSubnet(delta, original); - if (status < 200 || status > 299) + if (status < 200 || status > 299) { return Response.status(status).build(); + } } } @@ -354,18 +377,21 @@ public class NeutronSubnetsNorthbound { /* * verify the subnet exists and it isn't currently in use */ - if (!subnetInterface.subnetExists(subnetUUID)) + if (!subnetInterface.subnetExists(subnetUUID)) { return Response.status(404).build(); - if (subnetInterface.subnetInUse(subnetUUID)) + } + if (subnetInterface.subnetInUse(subnetUUID)) { return Response.status(409).build(); + } NeutronSubnet singleton = subnetInterface.getSubnet(subnetUUID); Object[] instances = ServiceHelper.getGlobalInstances(INeutronSubnetAware.class, this, null); if (instances != null) { for (Object instance : instances) { INeutronSubnetAware service = (INeutronSubnetAware) instance; int status = service.canDeleteSubnet(singleton); - if (status < 200 || status > 299) + if (status < 200 || status > 299) { return Response.status(status).build(); + } } }