本文整理汇总了Java中com.amazonaws.services.ec2.model.StartInstancesRequest.withInstanceIds方法的典型用法代码示例。如果您正苦于以下问题:Java StartInstancesRequest.withInstanceIds方法的具体用法?Java StartInstancesRequest.withInstanceIds怎么用?Java StartInstancesRequest.withInstanceIds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.ec2.model.StartInstancesRequest
的用法示例。
在下文中一共展示了StartInstancesRequest.withInstanceIds方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startInstance
import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入方法依赖的package包/类
private void startInstance(AmazonEC2AsyncClient client, DefaultAdapterContext c) {
StartInstancesRequest startRequest = new StartInstancesRequest();
startRequest.withInstanceIds(c.child.id);
client.startInstancesAsync(startRequest,
new AWSAsyncHandler<StartInstancesRequest, StartInstancesResult>() {
@Override
protected void handleError(Exception e) {
c.taskManager.patchTaskToFailure(e);
}
@Override
protected void handleSuccess(StartInstancesRequest request, StartInstancesResult result) {
AWSUtils.waitForTransitionCompletion(getHost(),
result.getStartingInstances(), "running",
client, (is, e) -> {
if (e == null) {
c.taskManager.finishTask();
} else {
c.taskManager.patchTaskToFailure(e);
}
});
}
});
}
示例2: startInstances
import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入方法依赖的package包/类
private void startInstances(AmazonEC2Client ec2Client, Exchange exchange) {
Collection instanceIds;
StartInstancesRequest request = new StartInstancesRequest();
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");
}
StartInstancesResult result;
try {
result = ec2Client.startInstances(request);
} catch (AmazonServiceException ase) {
LOG.trace("Start Instances command returned the error code {}", ase.getErrorCode());
throw ase;
}
LOG.trace("Starting instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
Message message = getMessageForResponse(exchange);
message.setBody(result);
}
示例3: startInstances
import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入方法依赖的package包/类
/**
* Start specified instances (power-on the instances).
*
* @param instanceIDs
* IDs of the instances start
* @return a list of state changes for the instances
*/
public static List<InstanceStateChange> startInstances(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 start request with args as instance IDs to start existing instances
StartInstancesRequest request = new StartInstancesRequest();
request.withInstanceIds(instanceIDs);
StartInstancesResult result = amazonEC2Client.startInstances(request);
return result.getStartingInstances();
}
示例4: startInstance
import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入方法依赖的package包/类
/**
* start the instance and on success updates the disk and compute state to reflect the detach information.
*/
private void startInstance(AmazonEC2AsyncClient client, DiskContext c, DeferredResult<DiskContext> dr) {
StartInstancesRequest startRequest = new StartInstancesRequest();
startRequest.withInstanceIds(c.baseAdapterContext.child.id);
client.startInstancesAsync(startRequest,
new AWSAsyncHandler<StartInstancesRequest, StartInstancesResult>() {
@Override
protected void handleError(Exception e) {
dr.fail(e);
}
@Override
protected void handleSuccess(StartInstancesRequest request, StartInstancesResult result) {
AWSUtils.waitForTransitionCompletion(getHost(),
result.getStartingInstances(), "running",
client, (is, e) -> {
if (e != null) {
dr.fail(e);
return;
}
logInfo(() -> String.format(
"[AWSComputeDiskDay2Service] Successfully started the "
+ "instance %s",
result.getStartingInstances().get(0).getInstanceId()));
updateComputeAndDiskState(dr, c);
});
}
});
}
示例5: start
import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入方法依赖的package包/类
public void start(AwsProcessClient awsProcessClient, Long instanceNo) {
AwsInstance awsInstance = awsInstanceDao.read(instanceNo);
String instanceId = awsInstance.getInstanceId();
// イベントログ出力
Instance instance = instanceDao.read(instanceNo);
processLogger.debug(null, instance, "AwsInstanceStart", new Object[] {
awsProcessClient.getPlatform().getPlatformName(), instanceId });
// インスタンスの起動
StartInstancesRequest request = new StartInstancesRequest();
request.withInstanceIds(instanceId);
StartInstancesResult result = awsProcessClient.getEc2Client().startInstances(request);
List<InstanceStateChange> startingInstances = result.getStartingInstances();
// API実行結果チェック
if (startingInstances.size() == 0) {
// インスタンス起動失敗時
throw new AutoException("EPROCESS-000125", instanceId);
} else if (startingInstances.size() > 1) {
// 複数のインスタンスが起動した場合
AutoException exception = new AutoException("EPROCESS-000127", instanceId);
exception.addDetailInfo("result=" + startingInstances);
throw exception;
}
// ログ出力
if (log.isInfoEnabled()) {
log.info(MessageUtils.getMessage("IPROCESS-100111", instanceId));
}
// データベース更新
awsInstance.setStatus(startingInstances.get(0).getCurrentState().getName());
awsInstanceDao.update(awsInstance);
}