本文整理汇总了Java中com.amazonaws.services.ec2.AmazonEC2Client.describeInstanceStatus方法的典型用法代码示例。如果您正苦于以下问题:Java AmazonEC2Client.describeInstanceStatus方法的具体用法?Java AmazonEC2Client.describeInstanceStatus怎么用?Java AmazonEC2Client.describeInstanceStatus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.ec2.AmazonEC2Client
的用法示例。
在下文中一共展示了AmazonEC2Client.describeInstanceStatus方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: describeInstancesStatus
import com.amazonaws.services.ec2.AmazonEC2Client; //导入方法依赖的package包/类
private void describeInstancesStatus(AmazonEC2Client ec2Client, Exchange exchange) {
Collection instanceIds;
DescribeInstanceStatusRequest request = new DescribeInstanceStatusRequest();
if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS))) {
instanceIds = exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS, Collection.class);
request.withInstanceIds(instanceIds);
}
DescribeInstanceStatusResult result;
try {
result = ec2Client.describeInstanceStatus(request);
} catch (AmazonServiceException ase) {
LOG.trace("Describe Instances Status command returned the error code {}", ase.getErrorCode());
throw ase;
}
Message message = getMessageForResponse(exchange);
message.setBody(result);
}
示例2: getInstancesStatusByZone
import com.amazonaws.services.ec2.AmazonEC2Client; //导入方法依赖的package包/类
private List<InstanceStatus> getInstancesStatusByZone(AvailabilityZone zone,
AmazonEC2Client client) {
// Create this list to capture paginated async results from aws sdk
List<InstanceStatus> statusList = new ArrayList<>();
// Create an initial request object
DescribeInstanceStatusRequest statusRequest = new DescribeInstanceStatusRequest()
.withMaxResults(1000)
.withFilters(new Filter("availability-zone", Arrays.asList(zone.getZoneName())))
.withSdkClientExecutionTimeout(600 * 1000)
.withSdkRequestTimeout(300 * 1000);
// Make the request for instanceStatus
DescribeInstanceStatusResult result = client.describeInstanceStatus(statusRequest);
// Until more results are available we loop through this code
while (result != null) {
statusList.addAll(result.getInstanceStatuses());
if (result.getNextToken() != null) {
statusRequest.setNextToken(result.getNextToken());
result = client.describeInstanceStatus(statusRequest);
} else {
result = null;
}
}
// Return all statuses as a list of InstanceStatus objects
return statusList;
}
示例3: getVMState
import com.amazonaws.services.ec2.AmazonEC2Client; //导入方法依赖的package包/类
/**
* Get the state of the EC2 instance.
*/
public static String getVMState(AmazonEC2Client client,String id) {
DescribeInstanceStatusRequest request = new DescribeInstanceStatusRequest();
request.withInstanceIds(id);
request.withIncludeAllInstances(Boolean.TRUE);
DescribeInstanceStatusResult result = client.describeInstanceStatus(request);
return result.getInstanceStatuses().get(0).getInstanceState().getName();
}
示例4: getInstanceStatus
import com.amazonaws.services.ec2.AmazonEC2Client; //导入方法依赖的package包/类
public InstanceStatus getInstanceStatus(AmazonEC2Client ec2Client, String instanceId) {
List<String> instanceIds = new ArrayList<String>();
instanceIds.add(instanceId);
DescribeInstanceStatusRequest statusReq = new DescribeInstanceStatusRequest();
statusReq.setInstanceIds(instanceIds);
DescribeInstanceStatusResult result = ec2Client.describeInstanceStatus(statusReq);
List<InstanceStatus> statuses = result.getInstanceStatuses();
if (statuses == null || statuses.size() == 0) {
return null;
}
return statuses.iterator().next();
}
示例5: dumpEc2InstanceStatus
import com.amazonaws.services.ec2.AmazonEC2Client; //导入方法依赖的package包/类
public List<String> dumpEc2InstanceStatus(AmazonEC2Client ec2Client, List<Instance> ec2Instances) {
try {
List<String> instanceIds = new ArrayList<String>();
for (Instance ec2node : ec2Instances) {
instanceIds.add(ec2node.getInstanceId());
}
DescribeInstanceStatusRequest statusReq = new DescribeInstanceStatusRequest();
statusReq.setInstanceIds(instanceIds);
DescribeInstanceStatusResult result = ec2Client.describeInstanceStatus(statusReq);
List<InstanceStatus> statuses = result.getInstanceStatuses();
List<String> impairedInstances = new ArrayList<String>();
StringBuffer sb = new StringBuffer("EC2 worker instance STATUS:\n");
for (InstanceStatus status : statuses) {
sb.append("\tid:"+status.getInstanceId() +
"\taz:" + status.getAvailabilityZone() +
"\tstate:" + status.getInstanceState().getName() +
"\tstatus:" + status.getInstanceStatus().getStatus() +
"\tsystem_status: " + status.getSystemStatus().getStatus() + "\n");
if (status.getInstanceStatus().getStatus().equalsIgnoreCase("impaired")) {
impairedInstances.add(status.getInstanceId());
}
}
logger.info(sb.toString()+"\n");
return impairedInstances;
} catch(Exception e) {
logger.error("Error getting instance state: " + e.getMessage(),e);
return null;
}
}
示例6: doCall
import com.amazonaws.services.ec2.AmazonEC2Client; //导入方法依赖的package包/类
@Override
protected Boolean doCall() {
LOGGER.info("Checking status of Auto Scaling group '{}'", autoScalingGroupName);
AmazonEC2Client amazonEC2Client = awsClient.createAccess(new AwsCredentialView(getAuthenticatedContext().getCloudCredential()),
getAuthenticatedContext().getCloudContext().getLocation().getRegion().value());
List<String> instanceIds = cloudFormationStackUtil.getInstanceIds(autoScalingClient, autoScalingGroupName);
if (instanceIds.size() < requiredInstances) {
LOGGER.debug("Instances in AS group: {}, needed: {}", instanceIds.size(), requiredInstances);
List<Activity> activities = getAutoScalingActivities();
if (latestActivity.isPresent()) {
checkForSpotRequest(latestActivity.get(), amazonEC2Client);
activities = activities.stream().filter(activity -> activity.getStartTime().after(latestActivity.get().getStartTime()))
.collect(Collectors.toList());
}
updateLatestActivity(activities);
checkFailedActivities(activities);
return false;
}
List<DescribeInstanceStatusResult> describeInstanceStatusResultList = new ArrayList<>();
List<List<String>> partitionedInstanceIdsList = Lists.partition(instanceIds, MAX_INSTANCE_ID_SIZE);
for (List<String> partitionedInstanceIds : partitionedInstanceIdsList) {
DescribeInstanceStatusRequest describeInstanceStatusRequest = new DescribeInstanceStatusRequest().withInstanceIds(partitionedInstanceIds);
DescribeInstanceStatusResult describeResult = amazonEC2Client.describeInstanceStatus(describeInstanceStatusRequest);
describeInstanceStatusResultList.add(describeResult);
}
List<InstanceStatus> instanceStatusList = describeInstanceStatusResultList.stream()
.flatMap(describeInstanceStatusResult -> describeInstanceStatusResult.getInstanceStatuses().stream())
.collect(Collectors.toList());
if (instanceStatusList.size() < requiredInstances) {
LOGGER.debug("Instances up: {}, needed: {}", instanceStatusList.size(), requiredInstances);
return false;
}
for (InstanceStatus status : instanceStatusList) {
if (INSTANCE_RUNNING != status.getInstanceState().getCode()) {
LOGGER.debug("Instances are up but not all of them are in running state.");
return false;
}
}
return true;
}