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