Search in sources :

Example 1 with TerminateInstancesRequest

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());
    });
}
Also used : TerminateInstancesResult(com.amazonaws.services.ec2.model.TerminateInstancesResult) TerminateInstancesRequest(com.amazonaws.services.ec2.model.TerminateInstancesRequest)

Example 2 with TerminateInstancesRequest

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);
}
Also used : ArrayList(java.util.ArrayList) TerminateInstancesRequest(com.amazonaws.services.ec2.model.TerminateInstancesRequest)

Example 3 with TerminateInstancesRequest

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);
}
Also used : TerminateInstancesRequest(com.amazonaws.services.ec2.model.TerminateInstancesRequest)

Example 4 with TerminateInstancesRequest

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);
}
Also used : ArrayList(java.util.ArrayList) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) TerminateInstancesRequest(com.amazonaws.services.ec2.model.TerminateInstancesRequest)

Example 5 with TerminateInstancesRequest

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);
    }
}
Also used : Ec2Exception(software.amazon.awssdk.services.ec2.model.Ec2Exception) TerminateInstancesResponse(software.amazon.awssdk.services.ec2.model.TerminateInstancesResponse) TerminateInstancesRequest(software.amazon.awssdk.services.ec2.model.TerminateInstancesRequest) InstanceStateChange(software.amazon.awssdk.services.ec2.model.InstanceStateChange)

Aggregations

TerminateInstancesRequest (com.amazonaws.services.ec2.model.TerminateInstancesRequest)13 TerminateInstancesResult (com.amazonaws.services.ec2.model.TerminateInstancesResult)3 ArrayList (java.util.ArrayList)3 AmazonServiceException (com.amazonaws.AmazonServiceException)2 AmazonAutoScalingClient (com.amazonaws.services.autoscaling.AmazonAutoScalingClient)1 DetachInstancesRequest (com.amazonaws.services.autoscaling.model.DetachInstancesRequest)1 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)1 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)1 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 AutoScalingData (io.druid.indexing.overlord.autoscaling.AutoScalingData)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 Message (org.apache.camel.Message)1 AutoScalingData (org.apache.druid.indexing.overlord.autoscaling.AutoScalingData)1 Ec2Exception (software.amazon.awssdk.services.ec2.model.Ec2Exception)1 InstanceStateChange (software.amazon.awssdk.services.ec2.model.InstanceStateChange)1 TerminateInstancesRequest (software.amazon.awssdk.services.ec2.model.TerminateInstancesRequest)1 TerminateInstancesResponse (software.amazon.awssdk.services.ec2.model.TerminateInstancesResponse)1