Support for delete VPC

This commit is contained in:
Alena Prokharchyk 2012-05-24 16:12:45 -07:00
parent aa0c0cb260
commit d7f0689bcb
6 changed files with 73 additions and 14 deletions

View File

@ -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());
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(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<DomainRouterVO> routers = _routerDao.listRoutersByVpcId(vpc.getId());
if (routers == null || routers.isEmpty()) {
return true;

View File

@ -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,

View File

@ -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