当前位置: 首页>>代码示例>>Java>>正文


Java DescribeInstanceStatusRequest类代码示例

本文整理汇总了Java中com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest的典型用法代码示例。如果您正苦于以下问题:Java DescribeInstanceStatusRequest类的具体用法?Java DescribeInstanceStatusRequest怎么用?Java DescribeInstanceStatusRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DescribeInstanceStatusRequest类属于com.amazonaws.services.ec2.model包,在下文中一共展示了DescribeInstanceStatusRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isInstanceReady

import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest; //导入依赖的package包/类
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;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:26,代码来源:EC2Communication.java

示例2: createDescribeInstanceStatusResult

import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest; //导入依赖的package包/类
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));
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:18,代码来源:EC2Mockup.java

示例3: describeInstancesStatus

import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest; //导入依赖的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

示例4: waitForInstance

import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest; //导入依赖的package包/类
private boolean waitForInstance(String instanceId) {
	log.info("Waiting for instance to transition to running");
	for (int i = 0; i < 5; ++i) {

		DescribeInstanceStatusResult result = ec2Client
				.describeInstanceStatus(new DescribeInstanceStatusRequest()
						.withInstanceIds(instanceId));
		if (!result.getInstanceStatuses().isEmpty()) {
			String state = result.getInstanceStatuses().get(0)
					.getInstanceState().getName();

			log.info("Instance state is " + state);

			if (state.equals("running")) {
				return true;
			}
		}

		sleep();

	}
	return false;
}
 
开发者ID:krujos,项目名称:data-lifecycle-service-broker,代码行数:24,代码来源:AWSHelper.java

示例5: 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;
	}
}
 
开发者ID:rickdesantis,项目名称:cloud-runner,代码行数:25,代码来源:Instance.java

示例6: testStartInstance

import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest; //导入依赖的package包/类
@Test
public void testStartInstance() {

	final DescribeInstanceStatusRequest describeInstanceStatusRequest = new DescribeInstanceStatusRequest().withIncludeAllInstances(true).withInstanceIds(INSTANCE_ID);
	final DescribeInstanceStatusResult describeInstanceStatusResult = new DescribeInstanceStatusResult().withInstanceStatuses(new InstanceStatus().withInstanceState(new InstanceState().withName(InstanceStateName.Stopped)));

	final StartInstancesRequest startInstancesRequest = new StartInstancesRequest().withInstanceIds(INSTANCE_ID);
	final StartInstancesResult startInstancesResult = new StartInstancesResult().withStartingInstances(new InstanceStateChange().withCurrentState(new InstanceState().withName(InstanceStateName.Running)));

	Mockito.doReturn(describeInstanceStatusResult).when(amazonEC2Client).describeInstanceStatus(describeInstanceStatusRequest);
	Mockito.doReturn(startInstancesResult).when(amazonEC2Client).startInstances(startInstancesRequest);

	amazonEC2Service.startInstance(INSTANCE_ID);

	final InOrder inOrder = Mockito.inOrder(amazonEC2Client);
	inOrder.verify(amazonEC2Client).describeInstanceStatus(describeInstanceStatusRequest);
	inOrder.verify(amazonEC2Client).startInstances(startInstancesRequest);
}
 
开发者ID:Sylvain-Bugat,项目名称:aws-ec2-start-stop-tools,代码行数:19,代码来源:AmazonEC2ServiceTest.java

示例7: testStopInstanceStopping

import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest; //导入依赖的package包/类
@Test
public void testStopInstanceStopping() {

	final DescribeInstanceStatusRequest describeInstanceStatusRequest = new DescribeInstanceStatusRequest().withIncludeAllInstances(true).withInstanceIds(INSTANCE_ID);
	final DescribeInstanceStatusResult describeInstanceStatusResult = new DescribeInstanceStatusResult().withInstanceStatuses(new InstanceStatus().withInstanceState(new InstanceState().withName(InstanceStateName.Running)));

	final StopInstancesRequest stopInstancesRequest = new StopInstancesRequest().withInstanceIds(INSTANCE_ID);
	final StopInstancesResult stopInstancesResult = new StopInstancesResult().withStoppingInstances(new InstanceStateChange().withCurrentState(new InstanceState().withName(InstanceStateName.Stopping)));

	Mockito.doReturn(describeInstanceStatusResult).when(amazonEC2Client).describeInstanceStatus(describeInstanceStatusRequest);
	Mockito.doReturn(stopInstancesResult).when(amazonEC2Client).stopInstances(stopInstancesRequest);

	amazonEC2Service.stopInstance(INSTANCE_ID);

	final InOrder inOrder = Mockito.inOrder(amazonEC2Client);
	inOrder.verify(amazonEC2Client).describeInstanceStatus(describeInstanceStatusRequest);
	inOrder.verify(amazonEC2Client).stopInstances(stopInstancesRequest);
}
 
开发者ID:Sylvain-Bugat,项目名称:aws-ec2-start-stop-tools,代码行数:19,代码来源:AmazonEC2ServiceTest.java

示例8: testStopInstanceStopped

import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest; //导入依赖的package包/类
@Test
public void testStopInstanceStopped() {

	final DescribeInstanceStatusRequest describeInstanceStatusRequest = new DescribeInstanceStatusRequest().withIncludeAllInstances(true).withInstanceIds(INSTANCE_ID);
	final DescribeInstanceStatusResult describeInstanceStatusResult = new DescribeInstanceStatusResult().withInstanceStatuses(new InstanceStatus().withInstanceState(new InstanceState().withName(InstanceStateName.Running)));

	final StopInstancesRequest stopInstancesRequest = new StopInstancesRequest().withInstanceIds(INSTANCE_ID);
	final StopInstancesResult stopInstancesResult = new StopInstancesResult().withStoppingInstances(new InstanceStateChange().withCurrentState(new InstanceState().withName(InstanceStateName.Stopped)));

	Mockito.doReturn(describeInstanceStatusResult).when(amazonEC2Client).describeInstanceStatus(describeInstanceStatusRequest);
	Mockito.doReturn(stopInstancesResult).when(amazonEC2Client).stopInstances(stopInstancesRequest);

	amazonEC2Service.stopInstance(INSTANCE_ID);

	final InOrder inOrder = Mockito.inOrder(amazonEC2Client);
	inOrder.verify(amazonEC2Client).describeInstanceStatus(describeInstanceStatusRequest);
	inOrder.verify(amazonEC2Client).stopInstances(stopInstancesRequest);
}
 
开发者ID:Sylvain-Bugat,项目名称:aws-ec2-start-stop-tools,代码行数:19,代码来源:AmazonEC2ServiceTest.java

示例9: EC2Mockup

import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest; //导入依赖的package包/类
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));

}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:13,代码来源:EC2Mockup.java

示例10: getInstancesStatusByZone

import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest; //导入依赖的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

示例11: getVMState

import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest; //导入依赖的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

示例12: waitUntilInstanceHasStarted

import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest; //导入依赖的package包/类
/**
 * Waits until the instance has entered a running state.
 *
 * @param ec2InstanceId the EC2 instance id
 * @return true if the instance has entered a running state, false if the instance is shutting down/terminated or
 * the function has timed out waiting for the instance to enter one of these two states.
 */
private boolean waitUntilInstanceHasStarted(String ec2InstanceId) throws InterruptedException {
  // TODO: Add a timeout to this loop.
  while (true) {
    try {
      DescribeInstanceStatusResult result = client.describeInstanceStatus(
          new DescribeInstanceStatusRequest()
              .withIncludeAllInstances(true)
              .withInstanceIds(ec2InstanceId)
      );
      for (InstanceStatus status : result.getInstanceStatuses()) {
        InstanceStateName currentState =
            InstanceStateName.fromValue(status.getInstanceState().getName());

        if (ec2InstanceId.equals(status.getInstanceId())) {
          if (currentState.equals(InstanceStateName.Terminated) ||
              currentState.equals(InstanceStateName.ShuttingDown)) {
            LOG.error("Instance {} has unexpectedly terminated", ec2InstanceId);
            return false;
          } else if (!currentState.equals(InstanceStateName.Pending)) {
            return true;
          }
        }
      }
    } catch (AmazonServiceException e) {
      if (!INVALID_INSTANCE_ID_NOT_FOUND.equals(e.getErrorCode())) {
        AWSExceptions.propagate(e);
      }
    }
    TimeUnit.SECONDS.sleep(5);
  }
}
 
开发者ID:cloudera,项目名称:director-aws-plugin,代码行数:39,代码来源:EC2Provider.java

示例13: waitUntilRunning

import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest; //导入依赖的package包/类
public void waitUntilRunning(List<String> instanceIds) throws InterruptedException {
    int attempts = 0;
    while (true) {
        attempts++;
        Threads.sleepRoughly(Duration.ofSeconds(30));
        List<InstanceStatus> statuses = ec2.describeInstanceStatus(new DescribeInstanceStatusRequest()
            .withInstanceIds(instanceIds)).getInstanceStatuses();

        if (statuses.size() < instanceIds.size()) {
            logger.info("status is not synced, continue to wait");
            continue;
        }

        for (InstanceStatus status : statuses) {
            logger.info("instance status {} => {}, checks => {}, {}",
                status.getInstanceId(),
                status.getInstanceState().getName(),
                status.getSystemStatus().getStatus(),
                status.getInstanceStatus().getStatus());
        }

        boolean allOK = statuses.stream().allMatch(status ->
            "running".equalsIgnoreCase(status.getInstanceState().getName())
                && "ok".equalsIgnoreCase(status.getSystemStatus().getStatus())
                && "ok".equalsIgnoreCase(status.getInstanceStatus().getStatus()));

        if (allOK) {
            break;
        } else if (attempts > 20) { // roughly after 10 mins
            throw new Error("waited too long to get instance status, something is wrong, please check aws console");
        }
    }
}
 
开发者ID:neowu,项目名称:cmn-project,代码行数:34,代码来源:EC2.java

示例14: waitUntilInstanceRunning

import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest; //导入依赖的package包/类
private void waitUntilInstanceRunning(List<String> newInstanceIds) throws InterruptedException {
    while (true) {
        Threads.sleepRoughly(Duration.ofSeconds(30));
        List<InstanceStatus> statuses = AWS.ec2.ec2.describeInstanceStatus(new DescribeInstanceStatusRequest()
            .withInstanceIds(newInstanceIds)).getInstanceStatuses();

        for (InstanceStatus status : statuses) {
            logger.info("instance status {} => {}, checks => {}, {}",
                status.getInstanceId(),
                status.getInstanceState().getName(),
                status.getSystemStatus().getStatus(),
                status.getInstanceStatus().getStatus());
        }

        boolean allOK = statuses.stream().allMatch(status ->
                "running".equalsIgnoreCase(status.getInstanceState().getName())
                    && "ok".equalsIgnoreCase(status.getSystemStatus().getStatus())
                    && "ok".equalsIgnoreCase(status.getInstanceStatus().getStatus())
        );

        if (allOK) {
            logger.info("all new instances are running");
            break;
        } else {
            logger.info("continue to wait, not all new instances are running");
        }
    }
}
 
开发者ID:neowu,项目名称:cmn-project,代码行数:29,代码来源:DeployASGroupTask.java

示例15: testStartInstanceAlreadyRunning

import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest; //导入依赖的package包/类
@Test(expected = AmazonClientException.class)
public void testStartInstanceAlreadyRunning() {

	final DescribeInstanceStatusRequest describeInstanceStatusRequest = new DescribeInstanceStatusRequest().withIncludeAllInstances(true).withInstanceIds(INSTANCE_ID);
	final DescribeInstanceStatusResult describeInstanceStatusResult = new DescribeInstanceStatusResult().withInstanceStatuses(new InstanceStatus().withInstanceState(new InstanceState().withName(InstanceStateName.Running)));

	Mockito.doReturn(describeInstanceStatusResult).when(amazonEC2Client).describeInstanceStatus(describeInstanceStatusRequest);

	try {
		amazonEC2Service.startInstance(INSTANCE_ID);
	}
	finally {
		Mockito.verify(amazonEC2Client).describeInstanceStatus(describeInstanceStatusRequest);
	}
}
 
开发者ID:Sylvain-Bugat,项目名称:aws-ec2-start-stop-tools,代码行数:16,代码来源:AmazonEC2ServiceTest.java


注:本文中的com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。