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


Java InstanceStatus类代码示例

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


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

示例1: isInstanceReady

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

import com.amazonaws.services.ec2.model.InstanceStatus; //导入依赖的package包/类
public void addDescribeInstanceStatusResult(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);
    com.amazonaws.services.ec2.model.InstanceStatus instanceStatus = new com.amazonaws.services.ec2.model.InstanceStatus()
            .withInstanceId(instanceId).withInstanceState(state)
            .withInstanceStatus(instanceSummary)
            .withSystemStatus(systemSummary);
    DescribeInstanceStatusResult instanceStatusResult = new DescribeInstanceStatusResult()
            .withInstanceStatuses(instanceStatus);
    answerDescribeInstanceStatus.add(instanceStatusResult);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:17,代码来源:EC2Mockup.java

示例4: itShouldStartAnEC2InstanceFromAnAMI

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

	when(
			ec2Client.runInstances(awsRqst(r -> r.getImageId().equals(
					"test_image")))).thenReturn(runInstanceResult);

	when(ec2Client.describeAddresses()).thenReturn(
			new DescribeAddressesResult().withAddresses(Collections
					.singleton(new Address().withPublicIp("10.10.10.10"))));

	when(ec2Client.describeInstanceStatus(any())).thenReturn(
			new DescribeInstanceStatusResult()
					.withInstanceStatuses(Collections
							.singleton(new InstanceStatus()
									.withInstanceState(new InstanceState()
											.withName("running")))));

	when(hostUtils.waitForBoot(anyString(), anyInt())).thenReturn(true);
	assertThat(aws.startEC2Instance("test_image"),
			is(equalTo("test_instance")));
}
 
开发者ID:krujos,项目名称:data-lifecycle-service-broker,代码行数:24,代码来源:AWSHelperTest.java

示例5: testStartInstance

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

示例6: testStopInstanceStopping

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

示例7: testStopInstanceStopped

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

示例8: describeInstancesStatusAsync

import com.amazonaws.services.ec2.model.InstanceStatus; //导入依赖的package包/类
/**
 * This function is a wrapper to the ec2 describeInstanceStatus function.
 *
 * @param region
 * @return List of InstanceStatus
 */
public List<InstanceStatus> describeInstancesStatusAsync(Region region) throws Exception {

  Preconditions.checkNotNull(region);
  List<InstanceStatus> statusList = new ArrayList<>();
  List<AvailabilityZone> zones = getAvailabilityZones(region);
  AmazonEC2Client client = getClient(region);
  ExecutorService executor = Executors.newFixedThreadPool(zones.size());
  OperationStats op = new OperationStats("ec2InstanceStore", "describeInstancesStatusAsync");
  try {
    List<Callable<List<InstanceStatus>>> retrieveFunction = new ArrayList<>(zones.size());
    for (AvailabilityZone zone : zones) {
      retrieveFunction.add(new Callable<List<InstanceStatus>>() {
        @Override
        public List<InstanceStatus> call() throws Exception {
          return getInstancesStatusByZone(zone, client);
        }
      });
    }

    List<Future<List<InstanceStatus>>> futures = executor.invokeAll(retrieveFunction);
    for (Future<List<InstanceStatus>> future : futures) {
      statusList.addAll(future.get());
    }
    op.succeed();
  } catch (Exception ex) {
    op.failed();
    throw ex;
  } finally {
    executor.shutdown();
  }

  return statusList;
}
 
开发者ID:pinterest,项目名称:soundwave,代码行数:40,代码来源:Ec2InstanceStore.java

示例9: getInstancesStatusByZone

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

示例10: waitUntilInstanceHasStarted

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

示例11: waitUntilRunning

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

示例12: waitUntilInstanceRunning

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

示例13: testStartInstanceAlreadyRunning

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

示例14: testStopInstanceAlreadyStopped

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

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

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

示例15: testGetInstanceStatusMultipleInstances

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

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

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

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


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