com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest Java Examples

The following examples show how to use com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest. 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: EC2Communication.java    From development with Apache License 2.0 6 votes vote down vote up
public boolean isInstanceReady(String instanceId) {
    LOGGER.debug("isInstanceReady('{}') entered", instanceId);
    DescribeInstanceStatusResult result = getEC2()
            .describeInstanceStatus(
                    new DescribeInstanceStatusRequest()
                            .withInstanceIds(instanceId));
    List<InstanceStatus> statusList = result.getInstanceStatuses();
    boolean instanceStatus = false;
    boolean systemStatus = false;

    for (InstanceStatus status : statusList) {
        LOGGER.debug("  InstanceState:    {}", status.getInstanceState());
        LOGGER.debug("  InstanceStatus:   {}", status.getInstanceStatus()
                .getStatus());
        LOGGER.debug("  SystemStatus:     {}", status.getSystemStatus()
                .getStatus());
        LOGGER.debug("  AvailabilityZone: {}", status.getAvailabilityZone());

        instanceStatus = ("ok".equals(status.getInstanceStatus()
                .getStatus()));
        systemStatus = ("ok".equals(status.getSystemStatus().getStatus()));
    }
    LOGGER.debug("isInstanceReady('{}') left", instanceId);
    return instanceStatus && systemStatus;
}
 
Example #2
Source File: EC2Mockup.java    From development with Apache License 2.0 6 votes vote down vote up
public void createDescribeInstanceStatusResult(String instanceId,
        String stateName, String instanceStatusName,
        String systemStatusName) {
    InstanceState state = new InstanceState().withName(stateName);
    InstanceStatusSummary instanceSummary = new InstanceStatusSummary()
            .withStatus(instanceStatusName);
    InstanceStatusSummary systemSummary = new InstanceStatusSummary()
            .withStatus(systemStatusName);
    InstanceStatus instanceStatus = new com.amazonaws.services.ec2.model.InstanceStatus()
            .withInstanceId(instanceId).withInstanceState(state)
            .withInstanceStatus(instanceSummary)
            .withSystemStatus(systemSummary);
    DescribeInstanceStatusResult instanceStatusResult = new DescribeInstanceStatusResult()
            .withInstanceStatuses(instanceStatus);
    doReturn(instanceStatusResult).when(ec2).describeInstanceStatus(
            any(DescribeInstanceStatusRequest.class));
}
 
Example #3
Source File: Ec2InstanceStore.java    From soundwave with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #4
Source File: EC2Mockup.java    From development with Apache License 2.0 5 votes vote down vote up
public EC2Mockup() {
    ec2 = mock(AmazonEC2Client.class);

    answerDescribeInstances = new FifoAnswer<DescribeInstancesResult>();
    doAnswer(answerDescribeInstances).when(ec2)
            .describeInstances(any(DescribeInstancesRequest.class));

    answerDescribeInstanceStatus = new FifoAnswer<DescribeInstanceStatusResult>();
    doAnswer(answerDescribeInstanceStatus).when(ec2).describeInstanceStatus(
            any(DescribeInstanceStatusRequest.class));

}
 
Example #5
Source File: Ec2Util.java    From s3-bucket-loader with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #6
Source File: Ec2Util.java    From s3-bucket-loader with Apache License 2.0 5 votes vote down vote up
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;
	}
	
}