Java 类com.amazonaws.services.ec2.model.TerminateInstancesResult 实例源码

项目:swordfish-service    文件:EC2TerminateImpl.java   
@Override
public void process(Instance instance) {
    if (instance.getKeyName().contains("swordfish-")) {
        ec2KeyPair.delete(instance);
    }

    ec2UserClient.amazonEC2Async().terminateInstancesAsync(
            new TerminateInstancesRequest().withInstanceIds(instance.getInstanceId()),
            new AsyncHandler<TerminateInstancesRequest, TerminateInstancesResult>() {
                @Override
                public void onError(Exception exception) {
                    log.warn("something went wrong terminating the server {}",
                            exception.getLocalizedMessage());
                }

                @Override
                public void onSuccess(TerminateInstancesRequest request, TerminateInstancesResult result) {
                    ec2UserClient.amazonEC2Async().waiters()
                            .instanceRunning()
                            .runAsync(ec2Waiter.describeInstancesRequestWaiterParameters(instance.getInstanceId()), ec2Waiter.describeInstancesRequestWaiterHandler());
                }
            });

    instanceRepository.delete(instance);
}
项目:Camel    文件:EC2Producer.java   
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);        
}
项目:Camel    文件:AmazonEC2ClientMock.java   
@Override
public TerminateInstancesResult terminateInstances(TerminateInstancesRequest terminateInstancesRequest) {
    TerminateInstancesResult result = new TerminateInstancesResult();
    if (terminateInstancesRequest.getInstanceIds().contains("test-1")) {
        Collection<InstanceStateChange> coll = new ArrayList<InstanceStateChange>();
        InstanceStateChange sc = new InstanceStateChange();
        InstanceState previousState = new InstanceState();
        previousState.setCode(80);
        previousState.setName(InstanceStateName.Running);
        InstanceState newState = new InstanceState();
        newState.setCode(16);
        newState.setName(InstanceStateName.Terminated);
        sc.setPreviousState(previousState);
        sc.setCurrentState(newState);
        sc.setInstanceId("test-1");
        coll.add(sc);
        result.setTerminatingInstances(coll);
    } else {
        throw new AmazonServiceException("The image-id doesn't exists");
    }
    return result;    
}
项目:Tank    文件:AmazonInstance.java   
private List<VMInformation> killForRegion(VMRegion region, List<String> instanceIds) {
    List<VMInformation> result = new ArrayList<VMInformation>();
    try {
        asynchEc2Client.setEndpoint(region.getEndpoint());
        List<VMInformation> instances = describeInstances(instanceIds.toArray(new String[instanceIds.size()]));
        List<String> ids = new ArrayList<String>();
        for (VMInformation info : instances) {
            ids.add(info.getInstanceId());
        }
        if (ids.size() > 0) {
            TerminateInstancesRequest terminateInstancesRequest = new TerminateInstancesRequest(ids);
            TerminateInstancesResult terminateInstances = asynchEc2Client.terminateInstances(terminateInstancesRequest);
            result = new AmazonDataConverter().processStateChange(terminateInstances.getTerminatingInstances());
        }
    } catch (Exception ex) {
        LOG.error(ex.getMessage(), ex);
        throw new RuntimeException(ex);
    }
    return result;
}
项目:scale.cloudpool    文件:FakeSpotClient.java   
@Override
public TerminateInstancesResult terminateInstances(List<String> instanceIds)
        throws NotFoundException, AmazonClientException {
    TerminateInstancesResult result = new TerminateInstancesResult();
    for (String instanceId : instanceIds) {
        if (!this.instances.containsKey(instanceId)) {
            throw new AmazonServiceException(String.format(
                    "The instance ID '%s' does not exist " + "(Service: AmazonEC2; Status Code: 400; Error Code: "
                            + "InvalidInstanceID.NotFound;" + " Request ID: 12a2ebaf-c480-4998-95fb-6d47b4393e00)",
                    instanceId));
        }
        this.instances.remove(instanceId);

        result.withTerminatingInstances(new InstanceStateChange().withInstanceId(instanceId)
                .withCurrentState(new InstanceState().withName(InstanceStateName.ShuttingDown)));

    }
    return result;
}
项目:SeleniumGridScaler    文件:VmManagerTest.java   
@Test
// Test terminating instances works correctly
public void testTerminateInstance() {
    MockAmazonEc2Client client = new MockAmazonEc2Client(null);
    String instanceId="foo";
    TerminateInstancesResult terminateInstancesResult = new TerminateInstancesResult();
    client.setTerminateInstancesResult(terminateInstancesResult);
    InstanceStateChange stateChange = new InstanceStateChange();
    stateChange.withInstanceId(instanceId);
    stateChange.setCurrentState(new InstanceState().withCode(32));
    terminateInstancesResult.setTerminatingInstances(Arrays.asList(stateChange));
    Properties properties = new Properties();
    String region = "east";
    MockManageVm manageEC2 = new MockManageVm(client,properties,region);

    boolean success = manageEC2.terminateInstance(instanceId);
    TerminateInstancesRequest request = client.getTerminateInstancesRequest();
    Assert.assertEquals("Instance id size should match", 1, request.getInstanceIds().size());
    Assert.assertEquals("Instance ids should match", instanceId, request.getInstanceIds().get(0));
    Assert.assertTrue("Termination call should have been successful", success);
}
项目:SeleniumGridScaler    文件:VmManagerTest.java   
@Test
// Tests terminating an invalid instance is handled correctly
public void testTerminateInstanceInvalidRunningCode() {
    MockAmazonEc2Client client = new MockAmazonEc2Client(null);
    String instanceId="foo";
    TerminateInstancesResult terminateInstancesResult = new TerminateInstancesResult();
    client.setTerminateInstancesResult(terminateInstancesResult);
    InstanceStateChange stateChange = new InstanceStateChange();
    stateChange.withInstanceId(instanceId);
    stateChange.setCurrentState(new InstanceState().withCode(8));
    terminateInstancesResult.setTerminatingInstances(Arrays.asList(stateChange));
    Properties properties = new Properties();
    String region = "east";
    MockManageVm manageEC2 = new MockManageVm(client,properties,region);

    boolean success = manageEC2.terminateInstance(instanceId);
    TerminateInstancesRequest request = client.getTerminateInstancesRequest();
    Assert.assertEquals("Instance id size should match", 1, request.getInstanceIds().size());
    Assert.assertEquals("Instance ids should match", instanceId, request.getInstanceIds().get(0));
    Assert.assertFalse("Termination call should have not been successful", success);
}
项目:SeleniumGridScaler    文件:VmManagerTest.java   
@Test
// Test terminating a valid but not matching instances is handled correctly
public void testTerminateInstanceNoMatchingInstance() {
    MockAmazonEc2Client client = new MockAmazonEc2Client(null);
    String instanceId="foo";
    TerminateInstancesResult terminateInstancesResult = new TerminateInstancesResult();
    client.setTerminateInstancesResult(terminateInstancesResult);
    InstanceStateChange stateChange = new InstanceStateChange();
    stateChange.withInstanceId("notMatching");
    stateChange.setCurrentState(new InstanceState().withCode(8));
    terminateInstancesResult.setTerminatingInstances(Arrays.asList(stateChange));
    Properties properties = new Properties();
    String region = "east";
    MockManageVm manageEC2 = new MockManageVm(client,properties,region);

    boolean success = manageEC2.terminateInstance(instanceId);
    TerminateInstancesRequest request = client.getTerminateInstancesRequest();
    Assert.assertEquals("Instance id size should match", 1, request.getInstanceIds().size());
    Assert.assertEquals("Instance ids should match", instanceId, request.getInstanceIds().get(0));
    Assert.assertFalse("Termination call should have not been successful", success);
}
项目:SeleniumGridScaler    文件:VmManagerTest.java   
@Test
// Tests that the terminate code works when no matching results are returned by the client
public void testTerminateInstanceNoInstanceEmpty() {
    MockAmazonEc2Client client = new MockAmazonEc2Client(null);
    String instanceId="foo";
    TerminateInstancesResult terminateInstancesResult = new TerminateInstancesResult();
    client.setTerminateInstancesResult(terminateInstancesResult);
    terminateInstancesResult.setTerminatingInstances(CollectionUtils.EMPTY_COLLECTION);
    Properties properties = new Properties();
    String region = "east";
    MockManageVm manageEC2 = new MockManageVm(client,properties,region);

    boolean success = manageEC2.terminateInstance(instanceId);
    TerminateInstancesRequest request = client.getTerminateInstancesRequest();
    Assert.assertEquals("Instance id size should match",1,request.getInstanceIds().size());
    Assert.assertEquals("Instance ids should match", instanceId, request.getInstanceIds().get(0));
    Assert.assertFalse("Termination call should have not been successful", success);
}
项目:aws-mock    文件:TerminateInstancesExample.java   
/**
 * Terminate specified instances (power-on the instances).
 *
 * @param instanceIDs
 *            IDs of the instances to terminate
 * @return a list of state changes for the instances
 */
public static List<InstanceStateChange> terminateInstances(final List<String> instanceIDs) {
    // pass any credentials as aws-mock does not authenticate them at all
    AWSCredentials credentials = new BasicAWSCredentials("foo", "bar");
    AmazonEC2Client amazonEC2Client = new AmazonEC2Client(credentials);

    // the mock endpoint for ec2 which runs on your computer
    String ec2Endpoint = "http://localhost:8000/aws-mock/ec2-endpoint/";
    amazonEC2Client.setEndpoint(ec2Endpoint);

    // send the terminate request with args as instance IDs
    TerminateInstancesRequest request = new TerminateInstancesRequest();
    request.withInstanceIds(instanceIDs);
    TerminateInstancesResult result = amazonEC2Client.terminateInstances(request);

    return result.getTerminatingInstances();
}
项目:ec2-spot-jenkins-plugin    文件:EC2FleetCloud.java   
public synchronized boolean terminateInstance(final String instanceId) {
    LOGGER.log(Level.INFO, "Attempting to terminate instance: " + instanceId);

    final FleetStateStats stats=updateStatus();

    if (!instancesSeen.contains(instanceId)) {
        LOGGER.log(Level.INFO, "Unknown instance terminated: " + instanceId);
        return false;
    }

    final AmazonEC2 ec2 = connect(credentialsId, region);

    if (!instancesDying.contains(instanceId)) {
        // We can't remove instances beyond minSize
        if (stats.getNumDesired() == this.getMinSize() || !"active".equals(stats.getState())) {
            LOGGER.log(Level.INFO, "Not terminating " + instanceId + " because we need a minimum of " + Integer.toString(this.getMinSize()) + " instances running.");
            return false;
        }

        // These operations aren't idempotent so only do them once
        final ModifySpotFleetRequestRequest request=new ModifySpotFleetRequestRequest();
        request.setSpotFleetRequestId(fleet);
        request.setTargetCapacity(stats.getNumDesired() - 1);
        request.setExcessCapacityTerminationPolicy("NoTermination");
        ec2.modifySpotFleetRequest(request);

        //And remove the instance
        instancesDying.add(instanceId);
    }

    // terminateInstances is idempotent so it can be called until it's successful
    final TerminateInstancesResult result = ec2.terminateInstances(new TerminateInstancesRequest(Collections.singletonList(instanceId)));
    LOGGER.log(Level.INFO, "Instance " + instanceId + " termination result: " + result.toString());

    return true;
}
项目:photon-model    文件:AWSInstanceService.java   
@Override
public void onSuccess(TerminateInstancesRequest request,
        TerminateInstancesResult result) {

    Consumer<Object> postTerminationCallback = (instance) -> {

        OperationContext.restoreOperationContext(AWSTerminateHandler.this.opContext);

        if (instance == null) {
            this.context.taskManager.patchTaskToFailure(
                    new IllegalStateException("Error getting instance"));
            return;
        }

        deleteConstructsReferredByInstance()
                .whenComplete((aVoid, exc) -> {
                    if (exc != null) {
                        this.context.taskManager.patchTaskToFailure(
                                new IllegalStateException("Error deleting AWS subnet",
                                        exc));
                    } else {
                        AWSInstanceService.this.logInfo(() -> String.format("Deleting"
                                        + " subnets 'created-by' [%s]: SUCCESS",
                                this.context.computeRequest.resourceLink()));

                        this.context.taskManager.finishTask();
                    }
                });
    };

    AWSTaskStatusChecker.create(this.context.amazonEC2Client, this.instanceId,
            AWSTaskStatusChecker.AWS_TERMINATED_NAME, postTerminationCallback,
            this.context.taskManager, AWSInstanceService.this,
            this.context.taskExpirationMicros).start(new Instance());
}
项目:photon-model    文件:TestAWSSetupUtils.java   
/**
 * 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);

}
项目:director-aws-plugin    文件:EC2Provider.java   
@Override
@SuppressWarnings("PMD.UnusedFormalParameter")
public void delete(EC2InstanceTemplate template,
    Collection<String> virtualInstanceIds) throws InterruptedException {

  if (virtualInstanceIds.isEmpty()) {
    return;
  }

  Map<String, String> ec2InstanceIdsByVirtualInstanceId =
      getEC2InstanceIdsByVirtualInstanceId(virtualInstanceIds);
  Collection<String> ec2InstanceIds = ec2InstanceIdsByVirtualInstanceId.values();
  if (ec2InstanceIds.isEmpty()) {
    LOG.info("Unable to terminate instances, all unknown {}", virtualInstanceIds);
    return;
  }

  LOG.info(">> Terminating {}", ec2InstanceIds);
  TerminateInstancesResult terminateResult;
  try {
    terminateResult = client.terminateInstances(
        new TerminateInstancesRequest().withInstanceIds(ec2InstanceIds));
  } catch (AmazonClientException e) {
    throw AWSExceptions.propagate(e);
  }

  LOG.info("<< Result {}", terminateResult);

  if (ec2InstanceIdsByVirtualInstanceId.size() != virtualInstanceIds.size()) {
    Set<String> missingVirtualInstanceIds = Sets.newLinkedHashSet();
    for (String virtualInstanceId : virtualInstanceIds) {
      if (!ec2InstanceIdsByVirtualInstanceId.containsKey(virtualInstanceId)) {
        missingVirtualInstanceIds.add(virtualInstanceId);
      }
    }
    LOG.info("Unable to terminate unknown instances {}", missingVirtualInstanceIds);
  }
}
项目:Tank    文件:AmazonInstance.java   
@Override
public List<VMInformation> kill() {
    List<VMInformation> result = null;
    try {
        VMKillRequest killRequest = (VMKillRequest) request;
        TerminateInstancesRequest terminateInstancesRequest = new TerminateInstancesRequest(killRequest.getInstances());
        TerminateInstancesResult terminateInstances = asynchEc2Client.terminateInstances(terminateInstancesRequest);
        result = new AmazonDataConverter().processStateChange(terminateInstances.getTerminatingInstances());
    } catch (Exception ex) {
        LOG.error(ex.getMessage());
        throw new RuntimeException(ex);
    }
    return result;
}
项目:primecloud-controller    文件:AwsInstanceProcess.java   
public void terminate(AwsProcessClient awsProcessClient, Long instanceNo) {
    AwsInstance awsInstance = awsInstanceDao.read(instanceNo);
    String instanceId = awsInstance.getInstanceId();

    // イベントログ出力
    Instance instance = instanceDao.read(instanceNo);
    processLogger.debug(null, instance, "AwsInstanceDelete", new Object[] {
            awsProcessClient.getPlatform().getPlatformName(), instanceId });

    // インスタンスの削除
    TerminateInstancesRequest request = new TerminateInstancesRequest();
    request.withInstanceIds(instanceId);
    TerminateInstancesResult result = awsProcessClient.getEc2Client().terminateInstances(request);
    List<InstanceStateChange> terminatingInstances = result.getTerminatingInstances();

    // API実行結果チェック
    if (terminatingInstances.size() == 0) {
        // インスタンス削除失敗時
        throw new AutoException("EPROCESS-000107", instanceId);

    } else if (terminatingInstances.size() > 1) {
        // 複数のインスタンスが削除された場合
        AutoException exception = new AutoException("EPROCESS-000108", instanceId);
        exception.addDetailInfo("result=" + terminatingInstances);
        throw exception;
    }

    // ログ出力
    if (log.isInfoEnabled()) {
        log.info(MessageUtils.getMessage("IPROCESS-100117", instanceId));
    }

    // データベース更新
    awsInstance.setStatus(terminatingInstances.get(0).getCurrentState().getName());
    awsInstanceDao.update(awsInstance);
}
项目:scale.cloudpool    文件:FakeEc2Client.java   
@Override
public TerminateInstancesResult terminateInstances(List<String> instanceIds) throws AmazonClientException {
    TerminateInstancesResult result = new TerminateInstancesResult();
    for (String instanceId : instanceIds) {
        Instance instance = getInstanceMetadata(instanceId);
        this.instances.remove(instance);
        InstanceStateChange instanceStateChange = new InstanceStateChange().withInstanceId(instance.getInstanceId())
                .withCurrentState(new InstanceState().withName(InstanceStateName.ShuttingDown));
        result.withTerminatingInstances(instanceStateChange);
    }
    return result;
}
项目:scale.cloudpool    文件:TerminateInstances.java   
@Override
public TerminateInstancesResult call() {
    TerminateInstancesRequest request = new TerminateInstancesRequest().withInstanceIds(this.instanceIds);
    TerminateInstancesResult result = getClient().getApi().terminateInstances(request);

    awaitTermination(this.instanceIds);

    return result;
}
项目:aws-sdk-java-resources    文件:InstanceImpl.java   
@Override
public TerminateInstancesResult terminate(TerminateInstancesRequest request,
        ResultCapture<TerminateInstancesResult> extractor) {

    ActionResult result = resource.performAction("Terminate", request,
            extractor);

    if (result == null) return null;
    return (TerminateInstancesResult) result.getData();
}
项目:aws-sdk-java-resources    文件:InstanceImpl.java   
@Override
public TerminateInstancesResult terminate(
        ResultCapture<TerminateInstancesResult> extractor) {

    TerminateInstancesRequest request = new TerminateInstancesRequest();
    return terminate(request, extractor);
}
项目:SeleniumGridScaler    文件:AwsVmManager.java   
/**
 * Terminates the specified instance.
 *
 * @param  instanceId  Id of the instance to terminate
 */
public boolean terminateInstance(final String instanceId) {
    TerminateInstancesRequest terminateRequest = new TerminateInstancesRequest();
    terminateRequest.withInstanceIds(instanceId);

    if(client == null){
        throw new RuntimeException("The client is not initialized");
    }
    TerminateInstancesResult result = client.terminateInstances(terminateRequest);
    List<InstanceStateChange> stateChanges = result.getTerminatingInstances();
    boolean terminatedInstance = false;
    for (InstanceStateChange stateChange : stateChanges) {
        if (instanceId.equals(stateChange.getInstanceId())) {
            terminatedInstance = true;

            InstanceState currentState = stateChange.getCurrentState();
            if (currentState.getCode() != 32 && currentState.getCode() != 48) {
                log.error(String.format(
                        "Machine state for id %s should be terminated (48) or shutting down (32) but was %s instead",
                        instanceId, currentState.getCode()));
                return false;
            }
        }
    }

    if (!terminatedInstance) {
        log.error("Matching terminated instance was not found for instance " + instanceId);
        return false;
    }

    return true;
}
项目:aws-mock    文件:BaseTest.java   
/**
 * Terminate instances.
 *
 * @param instanceIds
 *            instances' IDs
 * @return list of instances change
 */
protected final List<InstanceStateChange> terminateInstances(
        final Collection<String> instanceIds) {
    log.info("Terminate instances:" + toString(instanceIds));
    TerminateInstancesRequest request = new TerminateInstancesRequest();
    request.setInstanceIds(instanceIds);
    TerminateInstancesResult result = amazonEC2Client
            .terminateInstances(request);
    return result.getTerminatingInstances();
}
项目:elasticsearch_my    文件:AmazonEC2Mock.java   
@Override
public TerminateInstancesResult terminateInstances(TerminateInstancesRequest terminateInstancesRequest) throws AmazonServiceException, AmazonClientException {
    throw new UnsupportedOperationException("Not supported in mock");
}
项目:photon-model    文件:TestAWSSetupUtils.java   
@Override
public void onSuccess(TerminateInstancesRequest request,
        TerminateInstancesResult result) {
    this.host.log("Successfully deleted instances from the AWS endpoint %s",
            result.getTerminatingInstances().toString());
}
项目:photon-model    文件:AWSRemoteCleanup.java   
@Test
public void cleanUpAWSEC2() {
    if (this.isMock) {
        return;
    }

    for (AmazonEC2 ec2Client : this.ec2Clients.values()) {
        try {
            DescribeVpcsResult describeVpcsRequest = ec2Client.describeVpcs();

            List<Vpc> vpcs = describeVpcsRequest.getVpcs();
            List<String> enumTestVpcIds = new ArrayList<>();
            List<String> instanceIdsToBeDeleted = new ArrayList<>();

            vpcs.stream()
                    .forEach(vpc -> {
                        vpc.getTags().stream()
                                .forEach(tag -> {
                                    if (tag.getKey().equalsIgnoreCase("name")
                                            && tag.getValue()
                                            .equalsIgnoreCase("enumtest-vpc")) {
                                        enumTestVpcIds.add(vpc.getVpcId());
                                    }
                                });
                    });

            DescribeInstancesResult describeInstancesResult = ec2Client.describeInstances();

            List<Reservation> reservations = describeInstancesResult.getReservations();
            for (Reservation reservation : reservations) {
                List<Instance> instances = reservation.getInstances();
                for (Instance instance : instances) {
                    long instanceLaunchTimeMicros = TimeUnit.MILLISECONDS
                            .toMicros(instance.getLaunchTime().getTime());
                    long timeDifference = Utils.getNowMicrosUtc() - instanceLaunchTimeMicros;

                    if (timeDifference > TimeUnit.HOURS.toMicros(1)
                            && enumTestVpcIds.contains(instance.getVpcId())
                            && shouldDelete(instance)) {
                        instanceIdsToBeDeleted.add(instance.getInstanceId());
                    }
                }
            }

            if (instanceIdsToBeDeleted.isEmpty()) {
                continue;
            }

            TerminateInstancesRequest terminateInstancesRequest = new
                    TerminateInstancesRequest(instanceIdsToBeDeleted);
            TerminateInstancesResult terminateInstancesResult = ec2Client
                    .terminateInstances(terminateInstancesRequest);

            terminateInstancesResult.getTerminatingInstances().stream()
                    .forEach(instanceStateChange -> {
                        this.host.log("Terminating stale instance: %s",
                                instanceStateChange.getInstanceId());
                    });
        } catch (Exception e) {
            this.host.log(Level.INFO, e.getMessage());
            continue;
        }
    }
}
项目:scale.cloudpool    文件:AwsEc2Client.java   
@Override
public TerminateInstancesResult terminateInstances(List<String> instanceIds) throws AmazonClientException {
    checkArgument(isConfigured(), "can't use client before it's configured");

    return new TerminateInstances(awsCredentials(), region(), clientConfig(), instanceIds).call();
}
项目:scale.cloudpool    文件:TerminateInstanceMain.java   
public static void main(String[] args) throws Exception {
    logger.info(format("Terminating instance %s in region %s", instanceId, region));
    TerminateInstancesResult result = new TerminateInstances(AWS_CREDENTIALS, region, new ClientConfiguration(),
            instanceId).call();
    logger.info("Terminating instances: {}", result);
}
项目:aws-sdk-java-resources    文件:InstanceImpl.java   
@Override
public TerminateInstancesResult terminate(TerminateInstancesRequest request)
        {

    return terminate(request, null);
}
项目:aws-sdk-java-resources    文件:InstanceImpl.java   
@Override
public TerminateInstancesResult terminate() {
    return terminate((ResultCapture<TerminateInstancesResult>)null);
}
项目:SeleniumGridScaler    文件:MockAmazonEc2Client.java   
@Override
public TerminateInstancesResult terminateInstances(TerminateInstancesRequest terminateInstancesRequest) throws AmazonServiceException, AmazonClientException {
    this.terminateInstancesRequest = terminateInstancesRequest;
    return terminateInstancesResult;
}
项目:SeleniumGridScaler    文件:MockAmazonEc2Client.java   
public void setTerminateInstancesResult(TerminateInstancesResult terminateInstancesResult) {
    this.terminateInstancesResult = terminateInstancesResult;
}
项目:wildfly-camel    文件:EC2IntegrationTest.java   
@Test
public void testCreateInstance() throws Exception {

    AmazonEC2Client ec2Client = provider.getClient();
    Assume.assumeNotNull("AWS client not null", ec2Client);

    assertNoStaleInstances(ec2Client, "before");

    try {
        WildFlyCamelContext camelctx = new WildFlyCamelContext();
        camelctx.getNamingContext().bind("ec2Client", ec2Client);
        camelctx.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:createAndRun").to("aws-ec2://TestDomain?amazonEc2Client=#ec2Client&operation=createAndRunInstances");
                from("direct:terminate").to("aws-ec2://TestDomain?amazonEc2Client=#ec2Client&operation=terminateInstances");
            }
        });

        camelctx.start();
        try {

            // Create and run an instance
            Map<String, Object> headers = new HashMap<>();
            headers.put(EC2Constants.IMAGE_ID, "ami-02ace471");
            headers.put(EC2Constants.INSTANCE_TYPE, InstanceType.T2Micro);
            headers.put(EC2Constants.SUBNET_ID, EC2Utils.getSubnetId(ec2Client));
            headers.put(EC2Constants.INSTANCE_MIN_COUNT, 1);
            headers.put(EC2Constants.INSTANCE_MAX_COUNT, 1);
            headers.put(EC2Constants.INSTANCES_TAGS, Arrays.asList(new Tag("Name", "wildfly-camel")));

            ProducerTemplate template = camelctx.createProducerTemplate();
            RunInstancesResult result1 = template.requestBodyAndHeaders("direct:createAndRun", null, headers, RunInstancesResult.class);
            String instanceId = result1.getReservation().getInstances().get(0).getInstanceId();
            System.out.println("InstanceId: " + instanceId);

            // Terminate the instance
            headers = new HashMap<>();
            headers.put(EC2Constants.INSTANCES_IDS, Collections.singleton(instanceId));

            TerminateInstancesResult result2 = template.requestBodyAndHeaders("direct:terminate", null, headers, TerminateInstancesResult.class);
            Assert.assertEquals(instanceId, result2.getTerminatingInstances().get(0).getInstanceId());
        } finally {
            camelctx.stop();
        }
    } finally {
        assertNoStaleInstances(ec2Client, "after");
    }
}
项目:scale.cloudpool    文件:Ec2Client.java   
/**
 * Terminates a collection of EC2 {@link Instance}s.
 *
 * @param instanceIds
 *            The identifiers of the {@link Instance}s to be terminated.
 * @return The result of the termination request.
 * @throws AmazonClientException
 *             if the request failed
 */
TerminateInstancesResult terminateInstances(List<String> instanceIds) throws AmazonClientException;
项目:aws-sdk-java-resources    文件:Instance.java   
/**
 * Performs the <code>Terminate</code> action.
 *
 * <p>
 * The following request parameters will be populated from the data of this
 * <code>Instance</code> resource, and any conflicting parameter value set
 * in the request will be overridden:
 * <ul>
 *   <li>
 *     <b><code>InstanceIds.0</code></b>
 *         - mapped from the <code>Id</code> identifier.
 *   </li>
 * </ul>
 *
 * <p>
 *
 * @return The response of the low-level client operation associated with
 *         this resource action.
 * @see TerminateInstancesRequest
 */
TerminateInstancesResult terminate(TerminateInstancesRequest request);
项目:aws-sdk-java-resources    文件:Instance.java   
/**
 * Performs the <code>Terminate</code> action and use a ResultCapture to
 * retrieve the low-level client response.
 *
 * <p>
 * The following request parameters will be populated from the data of this
 * <code>Instance</code> resource, and any conflicting parameter value set
 * in the request will be overridden:
 * <ul>
 *   <li>
 *     <b><code>InstanceIds.0</code></b>
 *         - mapped from the <code>Id</code> identifier.
 *   </li>
 * </ul>
 *
 * <p>
 *
 * @return The response of the low-level client operation associated with
 *         this resource action.
 * @see TerminateInstancesRequest
 */
TerminateInstancesResult terminate(TerminateInstancesRequest request,
        ResultCapture<TerminateInstancesResult> extractor);
项目:aws-sdk-java-resources    文件:Instance.java   
/**
 * The convenient method form for the <code>Terminate</code> action.
 *
 * @see #terminate(TerminateInstancesRequest)
 */
TerminateInstancesResult terminate();
项目:aws-sdk-java-resources    文件:Instance.java   
/**
 * The convenient method form for the <code>Terminate</code> action.
 *
 * @see #terminate(TerminateInstancesRequest, ResultCapture)
 */
TerminateInstancesResult terminate(ResultCapture<TerminateInstancesResult>
        extractor);