CLOUDSTACK-1133: [EC2 Query API] In StopInstances add support for parameter 'force'

Propagate this parameter to CS to force stop an instance
This commit is contained in:
Likitha Shetty 2013-02-12 14:03:51 -08:00 committed by Prachi Damle
parent 3337106693
commit 57969843d6
4 changed files with 19 additions and 1 deletions

View File

@ -1269,6 +1269,11 @@ public class EC2RestServlet extends HttpServlet {
}
if (0 == count) { response.sendError(530, "Missing InstanceId parameter" ); return; }
String[] force = request.getParameterValues("Force");
if ( force != null) {
EC2request.setForce( Boolean.parseBoolean(force[0]));
}
// -> execute the request
StopInstancesResponse EC2response = EC2SoapServiceImpl.toStopInstancesResponse( ServiceProvider.getInstance().getEC2Engine().stopInstances( EC2request ));
serializeResponse(response, EC2response);

View File

@ -773,6 +773,7 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
public StopInstancesResponse stopInstances(StopInstances stopInstances) {
EC2StopInstances request = new EC2StopInstances();
StopInstancesType sit = stopInstances.getStopInstances();
Boolean force = sit.getForce();
// -> toEC2StopInstances
InstanceIdSetType iist = sit.getInstancesSet();
@ -780,6 +781,8 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
if (null != items) { // -> should not be empty
for( int i=0; i < items.length; i++ ) request.addInstanceId( items[i].getInstanceId());
}
if (force) request.setForce(sit.getForce());
return toStopInstancesResponse( engine.stopInstances( request ));
}

View File

@ -1512,6 +1512,7 @@ public class EC2Engine extends ManagerBase {
// -> first determine the current state of each VM (becomes it previous state)
try {
String[] instanceSet = request.getInstancesSet();
Boolean forced = request.getForce();
EC2DescribeInstancesResponse previousState = listVirtualMachines( instanceSet, null, null );
virtualMachines = previousState.getInstanceSet();
@ -1533,7 +1534,7 @@ public class EC2Engine extends ManagerBase {
instances.addInstance(vm);
continue;
}
resp = getApi().stopVirtualMachine(vm.getId(), false);
resp = getApi().stopVirtualMachine(vm.getId(), forced);
if(logger.isDebugEnabled())
logger.debug("Stopping VM " + vm.getId() + " job " + resp.getJobId());
}

View File

@ -23,6 +23,7 @@ public class EC2StopInstances {
private List<String> instancesSet = new ArrayList<String>(); // a list of strings identifying instances
private boolean destroyInstances; // we are destroying the instances rather than stopping them
private Boolean force = false;
public EC2StopInstances() {
destroyInstances = false;
@ -43,5 +44,13 @@ public class EC2StopInstances {
public boolean getDestroyInstances() {
return this.destroyInstances;
}
public void setForce( Boolean force ) {
this.force = force;
}
public Boolean getForce() {
return this.force;
}
}