本文整理汇总了Java中com.amazonaws.services.ec2.model.TerminateInstancesResult类的典型用法代码示例。如果您正苦于以下问题:Java TerminateInstancesResult类的具体用法?Java TerminateInstancesResult怎么用?Java TerminateInstancesResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TerminateInstancesResult类属于com.amazonaws.services.ec2.model包,在下文中一共展示了TerminateInstancesResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import com.amazonaws.services.ec2.model.TerminateInstancesResult; //导入依赖的package包/类
@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);
}
示例2: terminateInstances
import com.amazonaws.services.ec2.model.TerminateInstancesResult; //导入依赖的package包/类
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);
}
示例3: terminateInstances
import com.amazonaws.services.ec2.model.TerminateInstancesResult; //导入依赖的package包/类
@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;
}
示例4: killForRegion
import com.amazonaws.services.ec2.model.TerminateInstancesResult; //导入依赖的package包/类
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;
}
示例5: terminateInstances
import com.amazonaws.services.ec2.model.TerminateInstancesResult; //导入依赖的package包/类
@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;
}
示例6: testTerminateInstance
import com.amazonaws.services.ec2.model.TerminateInstancesResult; //导入依赖的package包/类
@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);
}
示例7: testTerminateInstanceInvalidRunningCode
import com.amazonaws.services.ec2.model.TerminateInstancesResult; //导入依赖的package包/类
@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);
}
示例8: testTerminateInstanceNoMatchingInstance
import com.amazonaws.services.ec2.model.TerminateInstancesResult; //导入依赖的package包/类
@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);
}
示例9: testTerminateInstanceNoInstanceEmpty
import com.amazonaws.services.ec2.model.TerminateInstancesResult; //导入依赖的package包/类
@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);
}
示例10: terminateInstances
import com.amazonaws.services.ec2.model.TerminateInstancesResult; //导入依赖的package包/类
/**
* 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();
}
示例11: terminateInstance
import com.amazonaws.services.ec2.model.TerminateInstancesResult; //导入依赖的package包/类
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;
}
示例12: onSuccess
import com.amazonaws.services.ec2.model.TerminateInstancesResult; //导入依赖的package包/类
@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());
}
示例13: deleteVMsUsingEC2Client
import com.amazonaws.services.ec2.model.TerminateInstancesResult; //导入依赖的package包/类
/**
* 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);
}
示例14: delete
import com.amazonaws.services.ec2.model.TerminateInstancesResult; //导入依赖的package包/类
@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);
}
}
示例15: kill
import com.amazonaws.services.ec2.model.TerminateInstancesResult; //导入依赖的package包/类
@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;
}