diff --git a/api/src/com/cloud/api/commands/DeleteVPCCmd.java b/api/src/com/cloud/api/commands/DeleteVPCCmd.java index d4ad1ae3208..b85fadd6417 100644 --- a/api/src/com/cloud/api/commands/DeleteVPCCmd.java +++ b/api/src/com/cloud/api/commands/DeleteVPCCmd.java @@ -22,6 +22,9 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; import com.cloud.event.EventTypes; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.vpc.Vpc; import com.cloud.user.Account; @@ -66,12 +69,24 @@ public class DeleteVPCCmd extends BaseAsyncCmd{ @Override public void execute() { - boolean result = _vpcService.deleteVpc(getId()); - if (result) { - SuccessResponse response = new SuccessResponse(getCommandName()); - this.setResponseObject(response); - } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete VPC"); + try { + boolean result = _vpcService.deleteVpc(getId()); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete VPC"); + } + }catch (ResourceUnavailableException ex) { + s_logger.warn("Exception: ", ex); + throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + } catch (ConcurrentOperationException ex) { + s_logger.warn("Exception: ", ex); + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); + } catch (InsufficientCapacityException ex) { + s_logger.info(ex); + s_logger.trace(ex); + throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } } diff --git a/api/src/com/cloud/network/element/VpcProvider.java b/api/src/com/cloud/network/element/VpcProvider.java index 9243836e667..e40d188f5e1 100644 --- a/api/src/com/cloud/network/element/VpcProvider.java +++ b/api/src/com/cloud/network/element/VpcProvider.java @@ -33,7 +33,7 @@ public interface VpcProvider extends NetworkElement{ * @param vpc fully specified vpc configuration. * @throws InsufficientNetworkCapacityException TODO */ - boolean startVpc(Vpc vpc, DeployDestination dest, ReservationContext context) + boolean implementVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; /** @@ -42,7 +42,7 @@ public interface VpcProvider extends NetworkElement{ * @throws ConcurrentOperationException * @throws ResourceUnavailableException */ - boolean stopVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException; + boolean shutdownVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException; } diff --git a/api/src/com/cloud/network/vpc/VpcService.java b/api/src/com/cloud/network/vpc/VpcService.java index 2272464daf8..5c1ebb3ad4c 100644 --- a/api/src/com/cloud/network/vpc/VpcService.java +++ b/api/src/com/cloud/network/vpc/VpcService.java @@ -71,8 +71,11 @@ public interface VpcService { /** * @param vpcId * @return + * @throws InsufficientCapacityException + * @throws ResourceUnavailableException + * @throws ConcurrentOperationException */ - public boolean deleteVpc(long vpcId); + public boolean deleteVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; /** * @param vpcId @@ -113,4 +116,13 @@ public interface VpcService { */ Vpc startVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + /** + * @param vpcId + * @return + * @throws ConcurrentOperationException + * @throws ResourceUnavailableException + * @throws InsufficientCapacityException + */ + Vpc shutdownVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + } diff --git a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java index 8f6b43526b7..89a297e0754 100644 --- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java @@ -64,7 +64,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc VpcVirtualNetworkApplianceManager _vpcRouterMgr; @Override - public boolean startVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, + public boolean implementVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { Map params = new HashMap(1); @@ -76,7 +76,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc } @Override - public boolean stopVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException { + public boolean shutdownVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException { List routers = _routerDao.listRoutersByVpcId(vpc.getId()); if (routers == null || routers.isEmpty()) { return true; diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java index c8e7f042130..70c36ac2dac 100644 --- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -476,7 +476,7 @@ public class VpcManagerImpl implements VpcManager, Manager{ @Override @ActionEvent(eventType = EventTypes.EVENT_VPC_DELETE, eventDescription = "deleting VPC") - public boolean deleteVpc(long vpcId) { + public boolean deleteVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { UserContext.current().setEventDetails(" Id: " + vpcId); // Verify vpc id @@ -490,6 +490,9 @@ public class VpcManagerImpl implements VpcManager, Manager{ if (networksCount > 0) { throw new InvalidParameterValueException("Can't delete VPC " + vpcId + " as its used by " + networksCount + " networks"); } + + //shutdown VPC + shutdownVpc(vpcId); if (_vpcDao.remove(vpcId)) { return true; @@ -664,7 +667,7 @@ public class VpcManagerImpl implements VpcManager, Manager{ _accountMgr.getAccount(vpc.getAccountId())); //deploy provider - if (getVpcElement().startVpc(vpc, dest, context)) { + if (getVpcElement().implementVpc(vpc, dest, context)) { s_logger.debug("Vpc " + vpc + " has started succesfully"); return getVpc(vpc.getId()); } else { @@ -673,6 +676,35 @@ public class VpcManagerImpl implements VpcManager, Manager{ } } + + @Override + public Vpc shutdownVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + UserContext ctx = UserContext.current(); + Account caller = ctx.getCaller(); + + //check if vpc exists + Vpc vpc = getVpc(vpcId); + if (vpc == null) { + throw new InvalidParameterValueException("Unable to find vpc by id " + vpcId); + } + + //permission check + _accountMgr.checkAccess(caller, null, false, vpc); + + //shutdown provider + boolean success = getVpcElement().shutdownVpc(vpc); + + //FIXME - once more features are added to vpc (gateway/firewall rules, etc - cleanup them here) + + if (success) { + s_logger.debug("Vpc " + vpc + " has been stopped succesfully"); + return getVpc(vpc.getId()); + } else { + throw new CloudRuntimeException("Failed to stop vpc " + vpc); + } + } + @Override @DB public void validateGuestNtkwForVpc(NetworkOffering guestNtwkOff, String cidr, String networkDomain, diff --git a/wscript b/wscript index 474cf75e905..1f58c524567 100644 --- a/wscript +++ b/wscript @@ -3,7 +3,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-05-24T22:26:07Z' +VERSION = '3.0.3.2012-05-24T22:43:32Z' APPNAME = 'cloud' import shutil,os