Java Code Examples for com.amazonaws.services.ec2.model.StopInstancesResult#getStoppingInstances()
The following examples show how to use
com.amazonaws.services.ec2.model.StopInstancesResult#getStoppingInstances() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StopInstancesExample.java From aws-mock with MIT License | 6 votes |
/** * Stop specified instances (power-on the instances). * * @param instanceIDs * IDs of the instances to stop * @return a list of state changes for the instances */ public static List<InstanceStateChange> stopInstances(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 stop request with args as instance IDs to stop running instances StopInstancesRequest request = new StopInstancesRequest(); request.withInstanceIds(instanceIDs); StopInstancesResult result = amazonEC2Client.stopInstances(request); return result.getStoppingInstances(); }
Example 2
Source File: AwsInstanceProcess.java From primecloud-controller with GNU General Public License v2.0 | 5 votes |
public void stop(AwsProcessClient awsProcessClient, Long instanceNo) { AwsInstance awsInstance = awsInstanceDao.read(instanceNo); String instanceId = awsInstance.getInstanceId(); // イベントログ出力 Instance instance = instanceDao.read(instanceNo); processLogger.debug(null, instance, "AwsInstanceStop", new Object[] { awsProcessClient.getPlatform().getPlatformName(), instanceId }); // インスタンスの停止 StopInstancesRequest request = new StopInstancesRequest(); request.withInstanceIds(instanceId); StopInstancesResult result = awsProcessClient.getEc2Client().stopInstances(request); List<InstanceStateChange> stoppingInstances = result.getStoppingInstances(); // API実行結果チェック if (stoppingInstances.size() == 0) { // インスタンス停止失敗時 throw new AutoException("EPROCESS-000128", instanceId); } else if (stoppingInstances.size() > 1) { // 複数のインスタンスが停止した場合 AutoException exception = new AutoException("EPROCESS-000130", instanceId); exception.addDetailInfo("result=" + stoppingInstances); throw exception; } // ログ出力 if (log.isInfoEnabled()) { log.info(MessageUtils.getMessage("IPROCESS-100113", instanceId)); } // データベース更新 awsInstance.setStatus(stoppingInstances.get(0).getCurrentState().getName()); awsInstanceDao.update(awsInstance); }
Example 3
Source File: BaseTest.java From aws-mock with MIT License | 5 votes |
/** * Stop instances. * * @param instanceIds * instances' IDs * @return list of instances change */ protected final List<InstanceStateChange> stopInstances( final Collection<String> instanceIds) { log.info("Stop instances:" + toString(instanceIds)); StopInstancesRequest request = new StopInstancesRequest(); request.setInstanceIds(instanceIds); StopInstancesResult result = amazonEC2Client.stopInstances(request); return result.getStoppingInstances(); }