From: Ryan Moats Date: Mon, 24 Feb 2014 15:39:03 +0000 (-0600) Subject: Fix for bugs 446 and 456 X-Git-Tag: autorelease-tag-v20140601202136_82eb3f9~379^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=04112a9b9591ef8d2e68694fe7ed3a771efd2960;hp=90fe8acf33840e84a50d6df1ed56b6f066879acf Fix for bugs 446 and 456 Fix for "Null pointer exception on remove_router_interface" (Bug 446) and "Return better error messages from NeutronAPIService" (Bug 456) Change-Id: I60c24ac37a91653e4c6f5ff2d654e8f85ad78d44 Signed-off-by: Ryan Moats --- diff --git a/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronFloatingIPsNorthbound.java b/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronFloatingIPsNorthbound.java index 680b028f9a..f93191220b 100644 --- a/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronFloatingIPsNorthbound.java +++ b/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronFloatingIPsNorthbound.java @@ -37,12 +37,15 @@ import org.opendaylight.controller.networkconfig.neutron.NeutronPort; import org.opendaylight.controller.networkconfig.neutron.NeutronSubnet; import org.opendaylight.controller.networkconfig.neutron.Neutron_IPs; import org.opendaylight.controller.northbound.commons.RestMessages; +import org.opendaylight.controller.northbound.commons.exception.BadRequestException; +import org.opendaylight.controller.northbound.commons.exception.ResourceConflictException; +import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException; import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException; import org.opendaylight.controller.sal.utils.ServiceHelper; /** - * Open DOVE Northbound REST APIs.
- * This class provides REST APIs for managing the open DOVE + * Neutron Northbound REST APIs.
+ * This class provides REST APIs for managing Neutron Floating IPs * *
*
@@ -139,7 +142,7 @@ public class NeutronFloatingIPsNorthbound { + RestMessages.SERVICEUNAVAILABLE.toString()); } if (!floatingIPInterface.floatingIPExists(floatingipUUID)) - return Response.status(404).build(); + throw new ResourceNotFoundException("Floating IP UUID doesn't exist."); if (fields.size() > 0) { NeutronFloatingIP ans = floatingIPInterface.getFloatingIP(floatingipUUID); return Response.status(200).entity( @@ -187,42 +190,42 @@ public class NeutronFloatingIPsNorthbound { NeutronFloatingIP singleton = input.getSingleton(); // check existence of id in cache and return badrequest if exists if (floatingIPInterface.floatingIPExists(singleton.getID())) - return Response.status(400).build(); + throw new BadRequestException("Floating IP UUID already exists."); // check if the external network is specified, exists, and is an external network String externalNetworkUUID = singleton.getFloatingNetworkUUID(); if (externalNetworkUUID == null) - return Response.status(400).build(); + throw new BadRequestException("external network UUID doesn't exist."); if (!networkInterface.networkExists(externalNetworkUUID)) - return Response.status(400).build(); + throw new BadRequestException("external network UUID doesn't exist."); NeutronNetwork externNetwork = networkInterface.getNetwork(externalNetworkUUID); if (!externNetwork.isRouterExternal()) - return Response.status(400).build(); + throw new BadRequestException("external network isn't marked router:external"); // if floating IP is specified, make sure it can come from the network String floatingIP = singleton.getFloatingIPAddress(); if (floatingIP != null) { if (externNetwork.getSubnets().size() > 1) - return Response.status(400).build(); + throw new BadRequestException("external network doesn't have a subnet"); NeutronSubnet externSubnet = subnetInterface.getSubnet(externNetwork.getSubnets().get(0)); if (!externSubnet.isValidIP(floatingIP)) - return Response.status(400).build(); + throw new BadRequestException("external IP isn't valid for the specified subnet."); if (externSubnet.isIPInUse(floatingIP)) - return Response.status(409).build(); + throw new ResourceConflictException("floating IP is in use."); } // if port_id is specified, then check that the port exists and has at least one IP String port_id = singleton.getPortUUID(); if (port_id != null) { String fixedIP = null; // used for the fixedIP calculation if (!portInterface.portExists(port_id)) - return Response.status(404).build(); + throw new ResourceNotFoundException("Port UUID doesn't exist."); NeutronPort port = portInterface.getPort(port_id); if (port.getFixedIPs().size() < 1) - return Response.status(400).build(); + throw new BadRequestException("port UUID doesn't have an IP address."); // if there is more than one fixed IP then check for fixed_ip_address // and that it is in the list of port addresses if (port.getFixedIPs().size() > 1) { fixedIP = singleton.getFixedIPAddress(); if (fixedIP == null) - return Response.status(400).build(); + throw new BadRequestException("fixed IP address doesn't exist."); Iterator i = port.getFixedIPs().iterator(); boolean validFixedIP = false; while (i.hasNext() && !validFixedIP) { @@ -231,15 +234,15 @@ public class NeutronFloatingIPsNorthbound { validFixedIP = true; } if (!validFixedIP) - return Response.status(400).build(); + throw new BadRequestException("can't find a valid fixed IP address"); } else { fixedIP = port.getFixedIPs().get(0).getIpAddress(); if (singleton.getFixedIPAddress() != null && !fixedIP.equalsIgnoreCase(singleton.getFixedIPAddress())) - return Response.status(400).build(); + throw new BadRequestException("mismatched fixed IP address in request"); } //lastly check that this fixed IP address isn't already used if (port.isBoundToFloatingIP(fixedIP)) - return Response.status(409).build(); + throw new ResourceConflictException("fixed IP is in use."); singleton.setFixedIPAddress(fixedIP); } Object[] instances = ServiceHelper.getGlobalInstances(INeutronFloatingIPAware.class, this, null); @@ -259,7 +262,7 @@ public class NeutronFloatingIPsNorthbound { } } } else { - return Response.status(400).build(); + throw new BadRequestException("only singleton requests allowed."); } return Response.status(201).entity(input).build(); } @@ -303,14 +306,14 @@ public class NeutronFloatingIPsNorthbound { + RestMessages.SERVICEUNAVAILABLE.toString()); } if (!floatingIPInterface.floatingIPExists(floatingipUUID)) - return Response.status(404).build(); + throw new ResourceNotFoundException("Floating IP UUID doesn't exist."); NeutronFloatingIP sourceFloatingIP = floatingIPInterface.getFloatingIP(floatingipUUID); if (!input.isSingleton()) - return Response.status(400).build(); + throw new BadRequestException("only singleton requests allowed."); NeutronFloatingIP singleton = input.getSingleton(); if (singleton.getID() != null) - return Response.status(400).build(); + throw new BadRequestException("singleton UUID doesn't exist."); NeutronNetwork externNetwork = networkInterface.getNetwork( sourceFloatingIP.getFloatingNetworkUUID()); @@ -319,12 +322,12 @@ public class NeutronFloatingIPsNorthbound { String floatingIP = singleton.getFloatingIPAddress(); if (floatingIP != null) { if (externNetwork.getSubnets().size() > 1) - return Response.status(400).build(); + throw new BadRequestException("external network doesn't have a subnet."); NeutronSubnet externSubnet = subnetInterface.getSubnet(externNetwork.getSubnets().get(0)); if (!externSubnet.isValidIP(floatingIP)) - return Response.status(400).build(); + throw new BadRequestException("floating IP not valid for external subnet"); if (externSubnet.isIPInUse(floatingIP)) - return Response.status(409).build(); + throw new ResourceConflictException("floating IP is in use."); } // if port_id is specified, then check that the port exists and has at least one IP @@ -332,16 +335,16 @@ public class NeutronFloatingIPsNorthbound { if (port_id != null) { String fixedIP = null; // used for the fixedIP calculation if (!portInterface.portExists(port_id)) - return Response.status(404).build(); + throw new ResourceNotFoundException("Port UUID doesn't exist."); NeutronPort port = portInterface.getPort(port_id); if (port.getFixedIPs().size() < 1) - return Response.status(400).build(); + throw new BadRequestException("port ID doesn't have a fixed IP address."); // if there is more than one fixed IP then check for fixed_ip_address // and that it is in the list of port addresses if (port.getFixedIPs().size() > 1) { fixedIP = singleton.getFixedIPAddress(); if (fixedIP == null) - return Response.status(400).build(); + throw new BadRequestException("request doesn't have a fixed IP address"); Iterator i = port.getFixedIPs().iterator(); boolean validFixedIP = false; while (i.hasNext() && !validFixedIP) { @@ -350,16 +353,16 @@ public class NeutronFloatingIPsNorthbound { validFixedIP = true; } if (!validFixedIP) - return Response.status(400).build(); + throw new BadRequestException("couldn't find a valid fixed IP address"); } else { fixedIP = port.getFixedIPs().get(0).getIpAddress(); if (singleton.getFixedIPAddress() != null && !fixedIP.equalsIgnoreCase(singleton.getFixedIPAddress())) - return Response.status(400).build(); + throw new BadRequestException("mismatch in fixed IP addresses"); } //lastly check that this fixed IP address isn't already used if (port.isBoundToFloatingIP(fixedIP)) - return Response.status(409).build(); + throw new ResourceConflictException("fixed IP is in use."); singleton.setFixedIPAddress(fixedIP); } NeutronFloatingIP target = floatingIPInterface.getFloatingIP(floatingipUUID); @@ -403,7 +406,7 @@ public class NeutronFloatingIPsNorthbound { + RestMessages.SERVICEUNAVAILABLE.toString()); } if (!floatingIPInterface.floatingIPExists(floatingipUUID)) - return Response.status(404).build(); + throw new ResourceNotFoundException("Floating IP UUID doesn't exist."); // TODO: need to undo port association if it exists NeutronFloatingIP singleton = floatingIPInterface.getFloatingIP(floatingipUUID); Object[] instances = ServiceHelper.getGlobalInstances(INeutronFloatingIPAware.class, this, null); diff --git a/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronNetworksNorthbound.java b/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronNetworksNorthbound.java index c08ee80e24..d7437c831d 100644 --- a/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronNetworksNorthbound.java +++ b/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronNetworksNorthbound.java @@ -33,12 +33,15 @@ import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD; import org.opendaylight.controller.networkconfig.neutron.NeutronCRUDInterfaces; import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork; import org.opendaylight.controller.northbound.commons.RestMessages; +import org.opendaylight.controller.northbound.commons.exception.BadRequestException; +import org.opendaylight.controller.northbound.commons.exception.ResourceConflictException; +import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException; import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException; import org.opendaylight.controller.sal.utils.ServiceHelper; /** - * Open DOVE Northbound REST APIs for Network.
- * This class provides REST APIs for managing open DOVE internals related to Networks + * Neutron Northbound REST APIs for Network.
+ * This class provides REST APIs for managing neutron Networks * *
*
@@ -154,7 +157,7 @@ public class NeutronNetworksNorthbound { + RestMessages.SERVICEUNAVAILABLE.toString()); } if (!networkInterface.networkExists(netUUID)) { - return Response.status(404).build(); + throw new ResourceNotFoundException("network UUID does not exist."); } if (fields.size() > 0) { NeutronNetwork ans = networkInterface.getNetwork(netUUID); @@ -189,7 +192,7 @@ public class NeutronNetworksNorthbound { * network ID can't already exist */ if (networkInterface.networkExists(singleton.getID())) { - return Response.status(400).build(); + throw new BadRequestException("network UUID already exists"); } Object[] instances = ServiceHelper.getGlobalInstances(INeutronNetworkAware.class, this, null); @@ -226,10 +229,10 @@ public class NeutronNetworksNorthbound { * already in this bulk request */ if (networkInterface.networkExists(test.getID())) { - return Response.status(400).build(); + throw new BadRequestException("network UUID already exists"); } if (testMap.containsKey(test.getID())) { - return Response.status(400).build(); + throw new BadRequestException("network UUID already exists"); } if (instances != null) { for (Object instance: instances) { @@ -285,10 +288,10 @@ public class NeutronNetworksNorthbound { * network has to exist and only a single delta is supported */ if (!networkInterface.networkExists(netUUID)) { - return Response.status(404).build(); + throw new ResourceNotFoundException("network UUID does not exist."); } if (!input.isSingleton()) { - return Response.status(400).build(); + throw new BadRequestException("only singleton edits supported"); } NeutronNetwork delta = input.getSingleton(); @@ -297,7 +300,7 @@ public class NeutronNetworksNorthbound { */ if (delta.getID() != null || delta.getTenantID() != null || delta.getStatus() != null) { - return Response.status(400).build(); + throw new BadRequestException("attribute edit blocked by Neutron"); } Object[] instances = ServiceHelper.getGlobalInstances(INeutronNetworkAware.class, this, null); @@ -347,10 +350,10 @@ public class NeutronNetworksNorthbound { * network has to exist and not be in use before it can be removed */ if (!networkInterface.networkExists(netUUID)) { - return Response.status(404).build(); + throw new ResourceNotFoundException("network UUID does not exist."); } if (networkInterface.networkInUse(netUUID)) { - return Response.status(409).build(); + throw new ResourceConflictException("Network ID in use"); } NeutronNetwork singleton = networkInterface.getNetwork(netUUID); diff --git a/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronPortsNorthbound.java b/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronPortsNorthbound.java index c26e0229d0..9f24e79ea0 100644 --- a/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronPortsNorthbound.java +++ b/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronPortsNorthbound.java @@ -36,12 +36,15 @@ import org.opendaylight.controller.networkconfig.neutron.NeutronPort; import org.opendaylight.controller.networkconfig.neutron.NeutronSubnet; import org.opendaylight.controller.networkconfig.neutron.Neutron_IPs; import org.opendaylight.controller.northbound.commons.RestMessages; +import org.opendaylight.controller.northbound.commons.exception.BadRequestException; +import org.opendaylight.controller.northbound.commons.exception.ResourceConflictException; +import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException; import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException; import org.opendaylight.controller.sal.utils.ServiceHelper; /** - * Open DOVE Northbound REST APIs.
- * This class provides REST APIs for managing the open DOVE + * Neutron Northbound REST APIs.
+ * This class provides REST APIs for managing neutron port objects * *
*
@@ -148,7 +151,7 @@ public class NeutronPortsNorthbound { + RestMessages.SERVICEUNAVAILABLE.toString()); } if (!portInterface.portExists(portUUID)) { - return Response.status(404).build(); + throw new ResourceNotFoundException("port UUID does not exist."); } if (fields.size() > 0) { NeutronPort ans = portInterface.getPort(portUUID); @@ -200,20 +203,20 @@ public class NeutronPortsNorthbound { * have a valid MAC and the MAC not be in use */ if (singleton.getNetworkUUID() == null) { - return Response.status(400).build(); + throw new BadRequestException("network UUID musy be specified"); } if (portInterface.portExists(singleton.getID())) { - return Response.status(400).build(); + throw new BadRequestException("port UUID already exists"); } if (!networkInterface.networkExists(singleton.getNetworkUUID())) { - return Response.status(404).build(); + throw new ResourceNotFoundException("network UUID does not exist."); } if (singleton.getMacAddress() == null || !singleton.getMacAddress().matches(mac_regex)) { - return Response.status(400).build(); + throw new BadRequestException("MAC address not properly formatted"); } if (portInterface.macInUse(singleton.getMacAddress())) { - return Response.status(409).build(); + throw new ResourceConflictException("MAC Address is in use."); } Object[] instances = ServiceHelper.getGlobalInstances(INeutronPortAware.class, this, null); if (instances != null) { @@ -237,21 +240,21 @@ public class NeutronPortsNorthbound { while (fixedIPIterator.hasNext()) { Neutron_IPs ip = fixedIPIterator.next(); if (ip.getSubnetUUID() == null) { - return Response.status(400).build(); + throw new BadRequestException("subnet UUID not specified"); } if (!subnetInterface.subnetExists(ip.getSubnetUUID())) { - return Response.status(400).build(); + throw new BadRequestException("subnet UUID must exists"); } NeutronSubnet subnet = subnetInterface.getSubnet(ip.getSubnetUUID()); if (!singleton.getNetworkUUID().equalsIgnoreCase(subnet.getNetworkUUID())) { - return Response.status(400).build(); + throw new BadRequestException("network UUID must match that of subnet"); } if (ip.getIpAddress() != null) { if (!subnet.isValidIP(ip.getIpAddress())) { - return Response.status(400).build(); + throw new BadRequestException("IP address is not valid"); } if (subnet.isIPInUse(ip.getIpAddress())) { - return Response.status(409).build(); + throw new ResourceConflictException("IP address is in use."); } } } @@ -279,32 +282,32 @@ public class NeutronPortsNorthbound { * can't already contain a new port with the same UUID */ if (portInterface.portExists(test.getID())) { - return Response.status(400).build(); + throw new BadRequestException("port UUID already exists"); } if (testMap.containsKey(test.getID())) { - return Response.status(400).build(); + throw new BadRequestException("port UUID already exists"); } for (NeutronPort check : testMap.values()) { if (test.getMacAddress().equalsIgnoreCase(check.getMacAddress())) { - return Response.status(409).build(); + throw new ResourceConflictException("MAC address already allocated"); } for (Neutron_IPs test_fixedIP : test.getFixedIPs()) { for (Neutron_IPs check_fixedIP : check.getFixedIPs()) { if (test_fixedIP.getIpAddress().equals(check_fixedIP.getIpAddress())) { - return Response.status(409).build(); + throw new ResourceConflictException("IP address already allocated"); } } } } testMap.put(test.getID(), test); if (!networkInterface.networkExists(test.getNetworkUUID())) { - return Response.status(404).build(); + throw new ResourceNotFoundException("network UUID does not exist."); } if (!test.getMacAddress().matches(mac_regex)) { - return Response.status(400).build(); + throw new BadRequestException("MAC address not properly formatted"); } if (portInterface.macInUse(test.getMacAddress())) { - return Response.status(409).build(); + throw new ResourceConflictException("MAC address in use"); } if (instances != null) { for (Object instance : instances) { @@ -327,23 +330,23 @@ public class NeutronPortsNorthbound { while (fixedIPIterator.hasNext()) { Neutron_IPs ip = fixedIPIterator.next(); if (ip.getSubnetUUID() == null) { - return Response.status(400).build(); + throw new BadRequestException("subnet UUID must be specified"); } if (!subnetInterface.subnetExists(ip.getSubnetUUID())) { - return Response.status(400).build(); + throw new BadRequestException("subnet UUID doesn't exists"); } NeutronSubnet subnet = subnetInterface.getSubnet(ip.getSubnetUUID()); if (!test.getNetworkUUID().equalsIgnoreCase(subnet.getNetworkUUID())) { - return Response.status(400).build(); + throw new BadRequestException("network UUID must match that of subnet"); } if (ip.getIpAddress() != null) { if (!subnet.isValidIP(ip.getIpAddress())) { - return Response.status(400).build(); + throw new BadRequestException("ip address not valid"); } //TODO: need to add consideration for a fixed IP being assigned the same address as a allocated IP in the //same bulk create if (subnet.isIPInUse(ip.getIpAddress())) { - return Response.status(409).build(); + throw new ResourceConflictException("IP address in use"); } } } @@ -399,11 +402,11 @@ public class NeutronPortsNorthbound { // port has to exist and only a single delta is supported if (!portInterface.portExists(portUUID)) { - return Response.status(404).build(); + throw new ResourceNotFoundException("port UUID does not exist."); } NeutronPort target = portInterface.getPort(portUUID); if (!input.isSingleton()) { - return Response.status(400).build(); + throw new BadRequestException("only singleton edit suported"); } NeutronPort singleton = input.getSingleton(); NeutronPort original = portInterface.getPort(portUUID); @@ -411,7 +414,7 @@ public class NeutronPortsNorthbound { // deltas restricted by Neutron if (singleton.getID() != null || singleton.getTenantID() != null || singleton.getStatus() != null) { - return Response.status(400).build(); + throw new BadRequestException("attribute change blocked by Neutron"); } Object[] instances = ServiceHelper.getGlobalInstances(INeutronPortAware.class, this, null); @@ -432,21 +435,21 @@ public class NeutronPortsNorthbound { while (fixedIPIterator.hasNext()) { Neutron_IPs ip = fixedIPIterator.next(); if (ip.getSubnetUUID() == null) { - return Response.status(400).build(); + throw new BadRequestException("subnet UUID must be specified"); } if (!subnetInterface.subnetExists(ip.getSubnetUUID())) { - return Response.status(400).build(); + throw new BadRequestException("subnet UUID doesn't exist."); } NeutronSubnet subnet = subnetInterface.getSubnet(ip.getSubnetUUID()); if (!target.getNetworkUUID().equalsIgnoreCase(subnet.getNetworkUUID())) { - return Response.status(400).build(); + throw new BadRequestException("network UUID must match that of subnet"); } if (ip.getIpAddress() != null) { if (!subnet.isValidIP(ip.getIpAddress())) { - return Response.status(400).build(); + throw new BadRequestException("invalid IP address"); } if (subnet.isIPInUse(ip.getIpAddress())) { - return Response.status(409).build(); + throw new ResourceConflictException("IP address in use"); } } } @@ -454,7 +457,7 @@ public class NeutronPortsNorthbound { // TODO: Support change of security groups // update the port and return the modified object - portInterface.updatePort(portUUID, singleton); + portInterface.updatePort(portUUID, singleton); NeutronPort updatedPort = portInterface.getPort(portUUID); if (instances != null) { for (Object instance : instances) { @@ -488,7 +491,7 @@ public class NeutronPortsNorthbound { // port has to exist and not be owned by anyone. then it can be removed from the cache if (!portInterface.portExists(portUUID)) { - return Response.status(404).build(); + throw new ResourceNotFoundException("port UUID does not exist."); } NeutronPort port = portInterface.getPort(portUUID); if (port.getDeviceID() != null || diff --git a/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronRoutersNorthbound.java b/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronRoutersNorthbound.java index fc7e0f7efb..17b2fcfcf9 100644 --- a/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronRoutersNorthbound.java +++ b/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronRoutersNorthbound.java @@ -37,13 +37,16 @@ import org.opendaylight.controller.networkconfig.neutron.NeutronRouter; import org.opendaylight.controller.networkconfig.neutron.NeutronRouter_Interface; import org.opendaylight.controller.networkconfig.neutron.NeutronSubnet; import org.opendaylight.controller.northbound.commons.RestMessages; +import org.opendaylight.controller.northbound.commons.exception.BadRequestException; +import org.opendaylight.controller.northbound.commons.exception.ResourceConflictException; +import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException; import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException; import org.opendaylight.controller.sal.utils.ServiceHelper; /** - * Open DOVE Northbound REST APIs.
- * This class provides REST APIs for managing the open DOVE + * Neutron Northbound REST APIs.
+ * This class provides REST APIs for managing neutron routers * *
*
@@ -141,8 +144,9 @@ public class NeutronRoutersNorthbound { throw new ServiceUnavailableException("Router CRUD Interface " + RestMessages.SERVICEUNAVAILABLE.toString()); } - if (!routerInterface.routerExists(routerUUID)) - return Response.status(404).build(); + if (!routerInterface.routerExists(routerUUID)) { + throw new ResourceNotFoundException("Router UUID not found"); + } if (fields.size() > 0) { NeutronRouter ans = routerInterface.getRouter(routerUUID); return Response.status(200).entity( @@ -184,14 +188,14 @@ public class NeutronRoutersNorthbound { * exists and has been designated as "router:external" */ if (routerInterface.routerExists(singleton.getID())) - return Response.status(400).build(); + throw new BadRequestException("router UUID already exists"); if (singleton.getExternalGatewayInfo() != null) { String externNetworkPtr = singleton.getExternalGatewayInfo().getNetworkID(); if (!networkInterface.networkExists(externNetworkPtr)) - return Response.status(400).build(); + throw new BadRequestException("External Network Pointer doesn't exist"); NeutronNetwork externNetwork = networkInterface.getNetwork(externNetworkPtr); if (!externNetwork.isRouterExternal()) - return Response.status(400).build(); + throw new BadRequestException("External Network Pointer isn't marked as router:external"); } Object[] instances = ServiceHelper.getGlobalInstances(INeutronRouterAware.class, this, null); if (instances != null) { @@ -218,7 +222,7 @@ public class NeutronRoutersNorthbound { /* * only singleton router creates supported */ - return Response.status(400).build(); + throw new BadRequestException("Only singleton router creates supported"); } return Response.status(201).entity(input).build(); } @@ -256,9 +260,9 @@ public class NeutronRoutersNorthbound { * router has to exist and only a single delta can be supplied */ if (!routerInterface.routerExists(routerUUID)) - return Response.status(404).build(); + throw new ResourceNotFoundException("Router UUID not found"); if (!input.isSingleton()) - return Response.status(400).build(); + throw new BadRequestException("Only single router deltas supported"); NeutronRouter singleton = input.getSingleton(); NeutronRouter original = routerInterface.getRouter(routerUUID); @@ -267,7 +271,7 @@ public class NeutronRoutersNorthbound { */ if (singleton.getID() != null || singleton.getTenantID() != null || singleton.getStatus() != null) - return Response.status(400).build(); + throw new BadRequestException("Request attribute change not allowed"); Object[] instances = ServiceHelper.getGlobalInstances(INeutronRouterAware.class, this, null); if (instances != null) { @@ -285,10 +289,10 @@ public class NeutronRoutersNorthbound { if (singleton.getExternalGatewayInfo() != null) { String externNetworkPtr = singleton.getExternalGatewayInfo().getNetworkID(); if (!networkInterface.networkExists(externNetworkPtr)) - return Response.status(400).build(); + throw new BadRequestException("External Network Pointer does not exist"); NeutronNetwork externNetwork = networkInterface.getNetwork(externNetworkPtr); if (!externNetwork.isRouterExternal()) - return Response.status(400).build(); + throw new BadRequestException("External Network Pointer isn't marked as router:external"); } /* @@ -330,9 +334,9 @@ public class NeutronRoutersNorthbound { * verify that the router exists and is not in use before removing it */ if (!routerInterface.routerExists(routerUUID)) - return Response.status(404).build(); + throw new ResourceNotFoundException("Router UUID not found"); if (routerInterface.routerInUse(routerUUID)) - return Response.status(409).build(); + throw new ResourceConflictException("Router UUID in Use"); NeutronRouter singleton = routerInterface.getRouter(routerUUID); Object[] instances = ServiceHelper.getGlobalInstances(INeutronRouterAware.class, this, null); if (instances != null) { @@ -393,28 +397,27 @@ public class NeutronRoutersNorthbound { * or a port id, but not both, this code assumes that the plugin has filled everything in for us and so both must be present */ if (!routerInterface.routerExists(routerUUID)) - return Response.status(400).build(); + throw new BadRequestException("Router UUID doesn't exist"); NeutronRouter target = routerInterface.getRouter(routerUUID); if (input.getSubnetUUID() == null || input.getPortUUID() == null) - return Response.status(400).build(); + throw new BadRequestException("Must specify at subnet id, port id or both"); // check that the port is part of the subnet NeutronSubnet targetSubnet = subnetInterface.getSubnet(input.getSubnetUUID()); if (targetSubnet == null) - return Response.status(400).build(); + throw new BadRequestException("Subnet id doesn't exist"); NeutronPort targetPort = portInterface.getPort(input.getPortUUID()); if (targetPort == null) - return Response.status(400).build(); + throw new BadRequestException("Port id doesn't exist"); if (!targetSubnet.getPortsInSubnet().contains(targetPort)) - return Response.status(400).build(); + throw new BadRequestException("Port id not part of subnet id"); if (targetPort.getFixedIPs().size() != 1) - return Response.status(400).build(); + throw new BadRequestException("Port id must have a single fixedIP address"); if (targetPort.getDeviceID() != null || targetPort.getDeviceOwner() != null) - return Response.status(409).build(); - + throw new ResourceConflictException("Target Port already allocated"); Object[] instances = ServiceHelper.getGlobalInstances(INeutronRouterAware.class, this, null); if (instances != null) { for (Object instance : instances) { @@ -475,7 +478,7 @@ public class NeutronRoutersNorthbound { // verify the router exists if (!routerInterface.routerExists(routerUUID)) - return Response.status(400).build(); + throw new BadRequestException("Router does not exist"); NeutronRouter target = routerInterface.getRouter(routerUUID); /* @@ -486,7 +489,7 @@ public class NeutronRoutersNorthbound { input.getSubnetUUID() != null) { NeutronPort port = portInterface.getGatewayPort(input.getSubnetUUID()); if (port == null) - return Response.status(404).build(); + throw new ResourceNotFoundException("Port UUID not found"); input.setPortUUID(port.getID()); input.setID(target.getID()); input.setTenantID(target.getTenantID()); @@ -543,9 +546,18 @@ public class NeutronRoutersNorthbound { if (input.getPortUUID() != null && input.getSubnetUUID() != null) { NeutronPort port = portInterface.getPort(input.getPortUUID()); + if (port == null) { + throw new ResourceNotFoundException("Port UUID not found"); + } + if (port.getFixedIPs() == null) { + throw new ResourceNotFoundException("Port UUID jas no fixed IPs"); + } NeutronSubnet subnet = subnetInterface.getSubnet(input.getSubnetUUID()); + if (subnet == null) { + throw new ResourceNotFoundException("Subnet UUID not found"); + } if (!subnet.isValidIP(port.getFixedIPs().get(0).getIpAddress())) - return Response.status(409).build(); + throw new ResourceConflictException("Target Port IP not in Target Subnet"); input.setID(target.getID()); input.setTenantID(target.getTenantID()); Object[] instances = ServiceHelper.getGlobalInstances(INeutronRouterAware.class, this, null); @@ -566,6 +578,6 @@ public class NeutronRoutersNorthbound { } // have to specify either a port ID or a subnet ID - return Response.status(400).build(); + throw new BadRequestException("Must specify port id or subnet id or both"); } } 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 dffac55c50..224fcb5f01 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,13 +33,16 @@ 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; /** - * Open DOVE Northbound REST APIs.
- * This class provides REST APIs for managing open DOVE internals related to Subnets + * Neutron Northbound REST APIs for Subnets.
+ * This class provides REST APIs for managing neutron Subnets * *
*
@@ -142,7 +145,7 @@ public class NeutronSubnetsNorthbound { + RestMessages.SERVICEUNAVAILABLE.toString()); } if (!subnetInterface.subnetExists(subnetUUID)) { - return Response.status(404).build(); + throw new ResourceNotFoundException("subnet UUID does not exist."); } if (fields.size() > 0) { NeutronSubnet ans = subnetInterface.getSubnet(subnetUUID); @@ -190,19 +193,19 @@ public class NeutronSubnetsNorthbound { * *then* add the subnet to the cache */ if (subnetInterface.subnetExists(singleton.getID())) { - return Response.status(400).build(); + throw new BadRequestException("subnet UUID already exists"); } if (!networkInterface.networkExists(singleton.getNetworkUUID())) { - return Response.status(404).build(); + throw new ResourceNotFoundException("network UUID does not exist."); } if (!singleton.isValidCIDR()) { - return Response.status(400).build(); + throw new BadRequestException("invaild CIDR"); } if (!singleton.initDefaults()) { throw new InternalServerErrorException("subnet object could not be initialized properly"); } if (singleton.gatewayIP_Pool_overlap()) { - return Response.status(409).build(); + throw new ResourceConflictException("IP pool overlaps with gateway"); } Object[] instances = ServiceHelper.getGlobalInstances(INeutronSubnetAware.class, this, null); if (instances != null) { @@ -240,20 +243,20 @@ public class NeutronSubnetsNorthbound { throw new InternalServerErrorException("subnet object could not be initialized properly"); } if (subnetInterface.subnetExists(test.getID())) { - return Response.status(400).build(); + throw new BadRequestException("subnet UUID already exists"); } if (testMap.containsKey(test.getID())) { - return Response.status(400).build(); + throw new BadRequestException("subnet UUID already exists"); } testMap.put(test.getID(), test); if (!networkInterface.networkExists(test.getNetworkUUID())) { - return Response.status(404).build(); + throw new ResourceNotFoundException("network UUID does not exist."); } if (!test.isValidCIDR()) { - return Response.status(400).build(); + throw new BadRequestException("Invalid CIDR"); } if (test.gatewayIP_Pool_overlap()) { - return Response.status(409).build(); + throw new ResourceConflictException("IP pool overlaps with gateway"); } if (instances != null) { for (Object instance : instances) { @@ -312,10 +315,10 @@ public class NeutronSubnetsNorthbound { * verify the subnet exists and there is only one delta provided */ if (!subnetInterface.subnetExists(subnetUUID)) { - return Response.status(404).build(); + throw new ResourceNotFoundException("subnet UUID does not exist."); } if (!input.isSingleton()) { - return Response.status(400).build(); + throw new BadRequestException("Only singleton edit supported"); } NeutronSubnet delta = input.getSingleton(); NeutronSubnet original = subnetInterface.getSubnet(subnetUUID); @@ -326,7 +329,7 @@ public class NeutronSubnetsNorthbound { if (delta.getID() != null || delta.getTenantID() != null || delta.getIpVersion() != null || delta.getCidr() != null || delta.getAllocationPools() != null) { - return Response.status(400).build(); + throw new BadRequestException("Attribute edit blocked by Neutron"); } Object[] instances = ServiceHelper.getGlobalInstances(INeutronSubnetAware.class, this, null); @@ -378,7 +381,7 @@ public class NeutronSubnetsNorthbound { * verify the subnet exists and it isn't currently in use */ if (!subnetInterface.subnetExists(subnetUUID)) { - return Response.status(404).build(); + throw new ResourceNotFoundException("subnet UUID does not exist."); } if (subnetInterface.subnetInUse(subnetUUID)) { return Response.status(409).build();