Search in sources :

Example 6 with TerminateInstancesRequest

use of software.amazon.awssdk.services.ec2.model.TerminateInstancesRequest in project druid by druid-io.

the class EC2AutoScaler method terminateWithIds.

@Override
public AutoScalingData terminateWithIds(List<String> ids) {
    if (ids.isEmpty()) {
        return new AutoScalingData(Lists.<String>newArrayList());
    }
    try {
        log.info("Terminating instances[%s]", ids);
        amazonEC2Client.terminateInstances(new TerminateInstancesRequest(ids));
        return new AutoScalingData(ids);
    } catch (Exception e) {
        log.error(e, "Unable to terminate any instances.");
    }
    return null;
}
Also used : AutoScalingData(io.druid.indexing.overlord.autoscaling.AutoScalingData) TerminateInstancesRequest(com.amazonaws.services.ec2.model.TerminateInstancesRequest)

Example 7 with TerminateInstancesRequest

use of software.amazon.awssdk.services.ec2.model.TerminateInstancesRequest in project GNS by MobilityFirst.

the class AWSEC2 method terminateInstance.

/**
   * Terminate an instance
   *
   * @param ec2
   * @param createdInstanceId
   */
public static void terminateInstance(AmazonEC2 ec2, String createdInstanceId) {
    System.out.println("Terminating Instance:" + createdInstanceId);
    List<String> instanceIds = new LinkedList<>();
    instanceIds.add(createdInstanceId);
    TerminateInstancesRequest tir = new TerminateInstancesRequest(instanceIds);
    ec2.terminateInstances(tir);
}
Also used : LinkedList(java.util.LinkedList) TerminateInstancesRequest(com.amazonaws.services.ec2.model.TerminateInstancesRequest)

Example 8 with TerminateInstancesRequest

use of software.amazon.awssdk.services.ec2.model.TerminateInstancesRequest in project camel by apache.

the class EC2Producer method terminateInstances.

private void terminateInstances(AmazonEC2Client ec2Client, Exchange exchange) {
    Collection instanceIds;
    TerminateInstancesRequest request = new TerminateInstancesRequest();
    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS))) {
        instanceIds = exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS, Collection.class);
        request.withInstanceIds(instanceIds);
    } else {
        throw new IllegalArgumentException("Instances Ids must be specified");
    }
    TerminateInstancesResult result;
    try {
        result = ec2Client.terminateInstances(request);
    } catch (AmazonServiceException ase) {
        LOG.trace("Terminate Instances command returned the error code {}", ase.getErrorCode());
        throw ase;
    }
    LOG.trace("Terminating instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
    Message message = getMessageForResponse(exchange);
    message.setBody(result);
}
Also used : Message(org.apache.camel.Message) AmazonServiceException(com.amazonaws.AmazonServiceException) Collection(java.util.Collection) TerminateInstancesResult(com.amazonaws.services.ec2.model.TerminateInstancesResult) TerminateInstancesRequest(com.amazonaws.services.ec2.model.TerminateInstancesRequest)

Example 9 with TerminateInstancesRequest

use of software.amazon.awssdk.services.ec2.model.TerminateInstancesRequest in project photon-model by vmware.

the class TestAWSSetupUtils method deleteVMsUsingEC2Client.

/**
 * Deletes instances on the AWS endpoint for the set of instance Ids that are passed in.
 *
 * @param instanceIdsToDelete
 * @throws Throwable
 */
public static void deleteVMsUsingEC2Client(AmazonEC2AsyncClient client, VerificationHost host, List<String> instanceIdsToDelete) throws Throwable {
    TerminateInstancesRequest termRequest = new TerminateInstancesRequest(instanceIdsToDelete);
    AsyncHandler<TerminateInstancesRequest, TerminateInstancesResult> terminateHandler = new AWSTerminateHandlerAsync(host);
    client.terminateInstancesAsync(termRequest, terminateHandler);
    waitForInstancesToBeTerminated(client, host, instanceIdsToDelete);
}
Also used : TerminateInstancesResult(com.amazonaws.services.ec2.model.TerminateInstancesResult) TerminateInstancesRequest(com.amazonaws.services.ec2.model.TerminateInstancesRequest)

Example 10 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(String... instanceIds) {
    // terminate
    TerminateInstancesRequest request = new TerminateInstancesRequest();
    getEC2Client().terminateInstances(request.withInstanceIds(instanceIds));
}
Also used : TerminateInstancesRequest(com.amazonaws.services.ec2.model.TerminateInstancesRequest)

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