use of software.amazon.awssdk.services.ec2.model.TerminateInstancesRequest in project photon-model by vmware.
the class AWSRemoteCleanup method triggerEC2Deletion.
private void triggerEC2Deletion(List<String> instanceIdsToBeDeleted, AmazonEC2 ec2Client) {
if (instanceIdsToBeDeleted.isEmpty()) {
return;
}
TerminateInstancesRequest terminateInstancesRequest = new TerminateInstancesRequest(instanceIdsToBeDeleted);
TerminateInstancesResult terminateInstancesResult = ec2Client.terminateInstances(terminateInstancesRequest);
terminateInstancesResult.getTerminatingInstances().stream().forEach(instanceStateChange -> {
this.host.log("Terminating stale instance: %s", instanceStateChange.getInstanceId());
});
}
use of software.amazon.awssdk.services.ec2.model.TerminateInstancesRequest in project photon-model by vmware.
the class AWSInstanceService method deleteInstance.
private void deleteInstance(AWSInstanceContext aws) {
if (aws.computeRequest.isMockRequest) {
detachPersistentDisks(aws).whenComplete((o, e) -> {
if (e != null) {
aws.taskManager.patchTaskToFailure(e);
} else {
aws.taskManager.finishTask();
}
});
return;
}
final String instanceId = aws.child.id;
if (instanceId == null || !instanceId.startsWith(AWS_INSTANCE_ID_PREFIX)) {
// nothing to delete
aws.taskManager.finishTask();
return;
}
List<String> instanceIdList = new ArrayList<>();
instanceIdList.add(instanceId);
TerminateInstancesRequest termRequest = new TerminateInstancesRequest(instanceIdList);
AWSTerminateHandler terminateHandler = new AWSTerminateHandler(aws, instanceId);
aws.amazonEC2Client.terminateInstancesAsync(termRequest, terminateHandler);
}
use of software.amazon.awssdk.services.ec2.model.TerminateInstancesRequest in project airavata by apache.
the class AmazonUtil method terminateInstances.
/**
* Terminate instances
*
* @param instanceIds
*/
public static void terminateInstances(List<String> instanceIds) {
// terminate
TerminateInstancesRequest request = new TerminateInstancesRequest(instanceIds);
getEC2Client().terminateInstances(request);
}
use of software.amazon.awssdk.services.ec2.model.TerminateInstancesRequest in project cloudbreak by hortonworks.
the class RecoveryUtil method deleteAWSInstance.
public static void deleteAWSInstance(Regions region, String instanceId) {
List<String> idList = new ArrayList<>();
idList.add(instanceId);
AmazonEC2 ec2 = AmazonEC2ClientBuilder.standard().withRegion(region).build();
TerminateInstancesRequest terminateInstancesRequest = new TerminateInstancesRequest(idList);
ec2.terminateInstances(terminateInstancesRequest);
LOGGER.info("Instance was deleted with id:" + instanceId);
}
use of software.amazon.awssdk.services.ec2.model.TerminateInstancesRequest in project aws-doc-sdk-examples by awsdocs.
the class TerminateInstance method terminateEC2.
// snippet-start:[ec2.java2.terminate_instance]
public static void terminateEC2(Ec2Client ec2, String instanceID) {
try {
TerminateInstancesRequest ti = TerminateInstancesRequest.builder().instanceIds(instanceID).build();
TerminateInstancesResponse response = ec2.terminateInstances(ti);
List<InstanceStateChange> list = response.terminatingInstances();
for (int i = 0; i < list.size(); i++) {
InstanceStateChange sc = (list.get(i));
System.out.println("The ID of the terminated instance is " + sc.instanceId());
}
} catch (Ec2Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
Aggregations