本文整理汇总了Java中com.amazonaws.services.ec2.model.TerminateInstancesRequest.withInstanceIds方法的典型用法代码示例。如果您正苦于以下问题:Java TerminateInstancesRequest.withInstanceIds方法的具体用法?Java TerminateInstancesRequest.withInstanceIds怎么用?Java TerminateInstancesRequest.withInstanceIds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.ec2.model.TerminateInstancesRequest
的用法示例。
在下文中一共展示了TerminateInstancesRequest.withInstanceIds方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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 );
}
}
示例3: 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();
}
示例4: terminate
import com.amazonaws.services.ec2.model.TerminateInstancesRequest; //导入方法依赖的package包/类
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);
}
示例5: terminateInstance
import com.amazonaws.services.ec2.model.TerminateInstancesRequest; //导入方法依赖的package包/类
/**
* 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;
}
示例6: removeInstance
import com.amazonaws.services.ec2.model.TerminateInstancesRequest; //导入方法依赖的package包/类
public static void removeInstance(InstanceObject instance,AmazonEC2 ec2 )
{
TerminateInstancesRequest termInstanceReq = new TerminateInstancesRequest();
termInstanceReq.withInstanceIds(instance.getInstance().getInstanceId());
ec2.terminateInstances(termInstanceReq);
}