Skip to content

Commit 5796984

Browse files
Likitha ShettyPrachi Damle
authored andcommitted
CLOUDSTACK-1133: [EC2 Query API] In StopInstances add support for parameter 'force'
Propagate this parameter to CS to force stop an instance
1 parent 3337106 commit 5796984

4 files changed

Lines changed: 19 additions & 1 deletion

File tree

awsapi/src/com/cloud/bridge/service/EC2RestServlet.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,11 @@ private void stopInstances( HttpServletRequest request, HttpServletResponse resp
12691269
}
12701270
if (0 == count) { response.sendError(530, "Missing InstanceId parameter" ); return; }
12711271

1272+
String[] force = request.getParameterValues("Force");
1273+
if ( force != null) {
1274+
EC2request.setForce( Boolean.parseBoolean(force[0]));
1275+
}
1276+
12721277
// -> execute the request
12731278
StopInstancesResponse EC2response = EC2SoapServiceImpl.toStopInstancesResponse( ServiceProvider.getInstance().getEC2Engine().stopInstances( EC2request ));
12741279
serializeResponse(response, EC2response);

awsapi/src/com/cloud/bridge/service/EC2SoapServiceImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,13 +773,16 @@ public StartInstancesResponse startInstances(StartInstances startInstances) {
773773
public StopInstancesResponse stopInstances(StopInstances stopInstances) {
774774
EC2StopInstances request = new EC2StopInstances();
775775
StopInstancesType sit = stopInstances.getStopInstances();
776+
Boolean force = sit.getForce();
776777

777778
// -> toEC2StopInstances
778779
InstanceIdSetType iist = sit.getInstancesSet();
779780
InstanceIdType[] items = iist.getItem();
780781
if (null != items) { // -> should not be empty
781782
for( int i=0; i < items.length; i++ ) request.addInstanceId( items[i].getInstanceId());
782783
}
784+
785+
if (force) request.setForce(sit.getForce());
783786
return toStopInstancesResponse( engine.stopInstances( request ));
784787
}
785788

awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,7 @@ public EC2StopInstancesResponse stopInstances(EC2StopInstances request) {
15121512
// -> first determine the current state of each VM (becomes it previous state)
15131513
try {
15141514
String[] instanceSet = request.getInstancesSet();
1515+
Boolean forced = request.getForce();
15151516

15161517
EC2DescribeInstancesResponse previousState = listVirtualMachines( instanceSet, null, null );
15171518
virtualMachines = previousState.getInstanceSet();
@@ -1533,7 +1534,7 @@ public EC2StopInstancesResponse stopInstances(EC2StopInstances request) {
15331534
instances.addInstance(vm);
15341535
continue;
15351536
}
1536-
resp = getApi().stopVirtualMachine(vm.getId(), false);
1537+
resp = getApi().stopVirtualMachine(vm.getId(), forced);
15371538
if(logger.isDebugEnabled())
15381539
logger.debug("Stopping VM " + vm.getId() + " job " + resp.getJobId());
15391540
}

awsapi/src/com/cloud/bridge/service/core/ec2/EC2StopInstances.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class EC2StopInstances {
2323

2424
private List<String> instancesSet = new ArrayList<String>(); // a list of strings identifying instances
2525
private boolean destroyInstances; // we are destroying the instances rather than stopping them
26+
private Boolean force = false;
2627

2728
public EC2StopInstances() {
2829
destroyInstances = false;
@@ -43,5 +44,13 @@ public void setDestroyInstances( boolean destroyInstances ) {
4344
public boolean getDestroyInstances() {
4445
return this.destroyInstances;
4546
}
47+
48+
public void setForce( Boolean force ) {
49+
this.force = force;
50+
}
51+
52+
public Boolean getForce() {
53+
return this.force;
54+
}
4655

4756
}

0 commit comments

Comments
 (0)