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.<br>
- * This class provides REST APIs for managing the open DOVE
+ * Neutron Northbound REST APIs.<br>
+ * This class provides REST APIs for managing Neutron Floating IPs
*
* <br>
* <br>
+ 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(
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<Neutron_IPs> i = port.getFixedIPs().iterator();
boolean validFixedIP = false;
while (i.hasNext() && !validFixedIP) {
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);
}
}
} else {
- return Response.status(400).build();
+ throw new BadRequestException("only singleton requests allowed.");
}
return Response.status(201).entity(input).build();
}
+ 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());
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
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<Neutron_IPs> i = port.getFixedIPs().iterator();
boolean validFixedIP = false;
while (i.hasNext() && !validFixedIP) {
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);
+ 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);
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.<br>
- * This class provides REST APIs for managing open DOVE internals related to Networks
+ * Neutron Northbound REST APIs for Network.<br>
+ * This class provides REST APIs for managing neutron Networks
*
* <br>
* <br>
+ 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);
* 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);
* 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) {
* 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();
*/
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);
* 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);
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.<br>
- * This class provides REST APIs for managing the open DOVE
+ * Neutron Northbound REST APIs.<br>
+ * This class provides REST APIs for managing neutron port objects
*
* <br>
* <br>
+ 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);
* 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) {
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.");
}
}
}
* 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) {
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");
}
}
}
// 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);
// 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);
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");
}
}
}
// 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) {
// 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 ||
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.<br>
- * This class provides REST APIs for managing the open DOVE
+ * Neutron Northbound REST APIs.<br>
+ * This class provides REST APIs for managing neutron routers
*
* <br>
* <br>
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(
* 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) {
/*
* 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();
}
* 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);
*/
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) {
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");
}
/*
* 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) {
* 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) {
// 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);
/*
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());
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);
}
// 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");
}
}
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.<br>
- * This class provides REST APIs for managing open DOVE internals related to Subnets
+ * Neutron Northbound REST APIs for Subnets.<br>
+ * This class provides REST APIs for managing neutron Subnets
*
* <br>
* <br>
+ 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);
* *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) {
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) {
* 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);
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);
* 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();