@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); }
private void deleteInstance(AWSInstanceContext aws) { if (aws.computeRequest.isMockRequest) { 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); }
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); }
@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; }
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; }
@Override public void terminateMachine( TargetHandlerParameters parameters, String machineId ) throws TargetException { this.logger.fine( "Terminating machine '" + machineId + "'." ); cancelMachineConfigurator( machineId ); try { AmazonEC2 ec2 = createEc2Client( parameters.getTargetProperties()); TerminateInstancesRequest terminateInstancesRequest = new TerminateInstancesRequest(); terminateInstancesRequest.withInstanceIds( machineId ); ec2.terminateInstances( terminateInstancesRequest ); } catch( Exception e ) { this.logger.severe( "An error occurred while terminating a machine on Amazon EC2. " + e.getMessage()); throw new TargetException( e ); } }
void shutdownHostViaEC2Id(String ec2Id) { // now destroy the server with this EC2 id TerminateInstancesRequest req = new TerminateInstancesRequest() .withInstanceIds(ec2Id); ec2Client.terminateInstances(req); // waiting for server to actually start shutting down. try { final int SLEEP_TIME = 100; int timeout = 100;//10 sec should be enough. do { Thread.sleep(SLEEP_TIME); } while(timeout--> 0 && isHostRunningViaId(ec2Id)); if(timeout <= 0) log.warning("While Shutting down host with EC2 Id="+ec2Id+" waited for timeout and server is still active."); } catch(InterruptedException e) { } }
@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); }
@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); }
@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); }
@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); }
/** * 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(); }
@Test public void deleteInstance() throws Exception { parameters.put(PropertyHandler.FLOW_STATE, new Setting(PropertyHandler.FLOW_STATE, FlowState.DELETION_REQUESTED.name())); parameters.put(PropertyHandler.OPERATION, new Setting( PropertyHandler.OPERATION, Operation.EC2_DELETION.name())); ec2mock.createDescribeImagesResult(IMAGE_ID); ec2mock.createRunInstancesResult(INSTANCE_ID); ec2mock.addDescribeInstancesResult(INSTANCE_ID, "pending", "2aws-1-2-3-4"); ec2mock.addDescribeInstanceStatusResult(INSTANCE_ID, "pending", "initializing", "initializing"); ec2mock.addDescribeInstancesResult(INSTANCE_ID, "terminated", "2aws-1-2-3-4"); ec2mock.addDescribeInstanceStatusResult(INSTANCE_ID, "terminated", "ok", "ok"); ec2mock.addDescribeInstancesResult(INSTANCE_ID, "terminated", null); runUntilReady(); ArgumentCaptor<TerminateInstancesRequest> argCapImages = ArgumentCaptor .forClass(TerminateInstancesRequest.class); verify(ec2).terminateInstances(argCapImages.capture()); }
@Test public void process_DELETION_REQUESTED() throws Exception { ph.setOperation(Operation.EC2_DELETION); ph.setState(FlowState.DELETION_REQUESTED); InstanceStatus result = ec2proc.process(); assertFalse(result.isReady()); assertEquals(FlowState.DELETING, ph.getState()); verify(ec2).terminateInstances(any(TerminateInstancesRequest.class)); }
@Test public void testTerminateInstance() throws Exception { ec2comm.terminateInstance("instance1"); ArgumentCaptor<TerminateInstancesRequest> arg1 = ArgumentCaptor .forClass(TerminateInstancesRequest.class); verify(ec2).terminateInstances(arg1.capture()); TerminateInstancesRequest val = arg1.getValue(); assertEquals(1, val.getInstanceIds().size()); assertEquals("instance1", val.getInstanceIds().get(0)); }
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; }
@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()); }
/** * 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); }
@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); } }
@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; }
public void killInstances(List<VMInformation> instances) { List<String> instanceIds = new ArrayList<String>(instances.size()); for (VMInformation instance : instances) { instanceIds.add(instance.getInstanceId()); } asynchEc2Client.terminateInstances(new TerminateInstancesRequest(instanceIds)); }
public void commitSuicide() { if (getMyInstanceID() != null) { logger.info("Commiting suicide. See you in another life when we are both cats."); List<String> instancesID = new ArrayList<String>(); instancesID.add(getMyInstanceID()); TerminateInstancesRequest request = new TerminateInstancesRequest(instancesID); _ec2.terminateInstances(request); } }
private void terminateInstance() throws AmazonServiceException { if (id == null) return; com.amazonaws.services.ec2.AmazonEC2 client = AmazonEC2.connect(); List<String> instanceIds = new ArrayList<String>(); instanceIds.add(id); TerminateInstancesRequest terminateRequest = new TerminateInstancesRequest( instanceIds); client.terminateInstances(terminateRequest); }
public void shutdownInstances() { AmazonEC2 ec2 = new AmazonEC2Client(getAwsCredentials()); ec2.setEndpoint(getOrCry("ec2endpoint")); try { // cancel spot request, so no new instances will be launched DescribeSpotInstanceRequestsRequest describeRequest = new DescribeSpotInstanceRequestsRequest(); DescribeSpotInstanceRequestsResult describeResult = ec2 .describeSpotInstanceRequests(describeRequest); List<SpotInstanceRequest> describeResponses = describeResult .getSpotInstanceRequests(); List<String> spotRequestIds = new ArrayList<String>(); List<String> instanceIds = new ArrayList<String>(); for (SpotInstanceRequest describeResponse : describeResponses) { spotRequestIds.add(describeResponse.getSpotInstanceRequestId()); if ("active".equals(describeResponse.getState())) { instanceIds.add(describeResponse.getInstanceId()); } } ec2.cancelSpotInstanceRequests(new CancelSpotInstanceRequestsRequest() .withSpotInstanceRequestIds(spotRequestIds)); log.info("Cancelled spot request"); if (instanceIds.size() > 0) { ec2.terminateInstances(new TerminateInstancesRequest( instanceIds)); log.info("Shut down " + instanceIds.size() + " instances"); } } catch (Exception e) { log.warn("Failed to shutdown instances - ", e); } }
@Override public void destroy(Member member) throws DestructionException { List<String> terminate = new ArrayList<>(); terminate.add(member.getId()); TerminateInstancesRequest tir = new TerminateInstancesRequest(terminate); this.amazonEC2.terminateInstances(tir); }
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); }
public void terminateInstances (List<String> instanceIDs) { try { System.out.println("Terminate instances"); TerminateInstancesRequest terminateRequest = new TerminateInstancesRequest(instanceIDs); ec2.terminateInstances(terminateRequest); } catch (AmazonServiceException e) { System.out.println("Error terminating instances"); System.out.println("Caught Exception: " + e.getMessage()); System.out.println("Reponse Status Code: " + e.getStatusCode()); System.out.println("Error Code: " + e.getErrorCode()); System.out.println("Request ID: " + e.getRequestId()); } }
@Override public TerminateInstancesResult call() { TerminateInstancesRequest request = new TerminateInstancesRequest().withInstanceIds(this.instanceIds); TerminateInstancesResult result = getClient().getApi().terminateInstances(request); awaitTermination(this.instanceIds); return result; }
@Override public void terminate(String instanceid) { this.setup(); TerminateInstancesRequest tir = new TerminateInstancesRequest() .withInstanceIds(instanceid); EC2.terminateInstances(tir); System.out.println("Terminating the instance : " + instanceid); }
@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(); }
@Override public TerminateInstancesResult terminate( ResultCapture<TerminateInstancesResult> extractor) { TerminateInstancesRequest request = new TerminateInstancesRequest(); return terminate(request, extractor); }
/** * 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; }
public void terminateEc2Instance(AmazonEC2Client ec2Client, String instanceId) throws Exception { try { TerminateInstancesRequest termReq = new TerminateInstancesRequest(); List<String> instanceIds = new ArrayList<String>(); instanceIds.add(instanceId); termReq.setInstanceIds(instanceIds); logger.debug("Terminating EC2 instances...." + Arrays.toString(instanceIds.toArray(new String[]{}))); ec2Client.terminateInstances(termReq); } catch(Exception e) { logger.error("Unexpected error terminating: " + instanceId + " "+ e.getMessage(),e); } }
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); }
@Override public void execute(AmazonEC2 client, Pool pool, DelegateExecution execution) { @SuppressWarnings("unchecked") Optional<List<String>> instanceIds = Optional.fromNullable((List<String>) execution.getVariable(ProcessVariables.INSTANCE_IDS)); LOG.info(">> Terminating instances: {}", instanceIds); if (instanceIds.isPresent() && instanceIds.get().size() > 0) { client.terminateInstances(new TerminateInstancesRequest().withInstanceIds(instanceIds.get())); } }
@Override public void tearDown() throws Exception { @SuppressWarnings("unchecked") List<String> instanceIds = (List<String>) collector.getVariable(ProcessVariables.INSTANCE_IDS); client.terminateInstances(new TerminateInstancesRequest().withInstanceIds(instanceIds)); // TODO: this behaves strangely, if it tries to delete the security group // and the instances are not yet killed, the test fails with an error Uninterruptibles.sleepUninterruptibly(45, TimeUnit.SECONDS); super.tearDown(); }
/** * Terminates instances with given Ids * * @param instanceIds */ @Override public void terminateInstances( final Collection<String> instanceIds ) { if( instanceIds == null || instanceIds.size() == 0 ) { return; } TerminateInstancesRequest request = ( new TerminateInstancesRequest() ).withInstanceIds( instanceIds ); client.terminateInstances( request ); }