本文整理汇总了Java中com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest.setInstanceIds方法的典型用法代码示例。如果您正苦于以下问题:Java DescribeInstanceStatusRequest.setInstanceIds方法的具体用法?Java DescribeInstanceStatusRequest.setInstanceIds怎么用?Java DescribeInstanceStatusRequest.setInstanceIds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest
的用法示例。
在下文中一共展示了DescribeInstanceStatusRequest.setInstanceIds方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInstanceStatus
import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest; //导入方法依赖的package包/类
public InstanceStatus getInstanceStatus() {
if (id == null) {
getSpotStatus();
if (id == null)
return InstanceStatus.INSTANCE_NOT_FOUND;
}
com.amazonaws.services.ec2.AmazonEC2 client = AmazonEC2.connect();
DescribeInstanceStatusRequest instanceReq = new DescribeInstanceStatusRequest();
List<String> instanceIds = new ArrayList<String>();
instanceIds.add(id);
instanceReq.setInstanceIds(instanceIds);
DescribeInstanceStatusResult instanceRes = client
.describeInstanceStatus(instanceReq);
List<com.amazonaws.services.ec2.model.InstanceStatus> reqs = instanceRes
.getInstanceStatuses();
if (reqs.size() > 0)
return InstanceStatus.valueFromStatus(reqs.get(0));
else {
return InstanceStatus.INSTANCE_NOT_FOUND;
}
}
示例2: getInstanceStatus
import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest; //导入方法依赖的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();
}
示例3: dumpEc2InstanceStatus
import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest; //导入方法依赖的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;
}
}