當前位置: 首頁>>代碼示例>>Java>>正文


Java AmazonEC2Client.describeInstanceStatus方法代碼示例

本文整理匯總了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);        
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:18,代碼來源:EC2Producer.java

示例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;
}
 
開發者ID:pinterest,項目名稱:soundwave,代碼行數:35,代碼來源:Ec2InstanceStore.java

示例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();
}
 
開發者ID:vmware,項目名稱:photon-model,代碼行數:11,代碼來源:TestAWSSetupUtils.java

示例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();
}
 
開發者ID:bitsofinfo,項目名稱:s3-bucket-loader,代碼行數:13,代碼來源:Ec2Util.java

示例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;
	}
	
}
 
開發者ID:bitsofinfo,項目名稱:s3-bucket-loader,代碼行數:40,代碼來源:Ec2Util.java

示例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;
}
 
開發者ID:hortonworks,項目名稱:cloudbreak,代碼行數:46,代碼來源:ASGroupStatusCheckerTask.java


注:本文中的com.amazonaws.services.ec2.AmazonEC2Client.describeInstanceStatus方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。