当前位置: 首页>>代码示例>>Java>>正文


Java TerminateInstancesRequest.withInstanceIds方法代码示例

本文整理汇总了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);        
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:EC2Producer.java

示例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 );
	}
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:17,代码来源:Ec2IaasHandler.java

示例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();
}
 
开发者ID:treelogic-swe,项目名称:aws-mock,代码行数:24,代码来源:TerminateInstancesExample.java

示例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);
}
 
开发者ID:primecloud-controller-org,项目名称:primecloud-controller,代码行数:37,代码来源:AwsInstanceProcess.java

示例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;
}
 
开发者ID:RetailMeNot,项目名称:SeleniumGridScaler,代码行数:37,代码来源:AwsVmManager.java

示例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);
}
 
开发者ID:carlosfaria94,项目名称:CloudPrime,代码行数:7,代码来源:AutoScaling.java


注:本文中的com.amazonaws.services.ec2.model.TerminateInstancesRequest.withInstanceIds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。