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


Java DescribeInstancesResult类代码示例

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


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

示例1: getInstanceState

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //导入依赖的package包/类
public String getInstanceState(String instanceId) {
    LOGGER.debug("getInstanceState('{}') entered", instanceId);
    DescribeInstancesResult result = getEC2().describeInstances(
            new DescribeInstancesRequest().withInstanceIds(instanceId));
    List<Reservation> reservations = result.getReservations();
    Set<Instance> instances = new HashSet<Instance>();

    for (Reservation reservation : reservations) {
        instances.addAll(reservation.getInstances());
        if (instances.size() > 0) {
            String state = instances.iterator().next().getState().getName();
            LOGGER.debug("  InstanceState: {}", state);
            return state;
        }
    }
    LOGGER.debug("getInstanceState('{}') left", instanceId);
    return null;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:19,代码来源:EC2Communication.java

示例2: processResponse

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //导入依赖的package包/类
private List<Instance> processResponse(DescribeInstancesResult response) {
    List<Instance> returnedInstances = new ArrayList<>();

    for (Reservation reservation : response.getReservations()) {
        for (com.amazonaws.services.ec2.model.Instance instance : reservation.getInstances()) {

            // Don't show dead servers or servers not tagged as belonging to Swordfish
            if (instance.getState().getName().equals("terminated") || !instance.getTags().contains(new Tag().withKey("Swordfish").withValue("true"))) {
                continue;
            }

            Instance instanceDetails = getInstanceDetails(instance);
            returnedInstances.add(instanceDetails);
            instanceRepository.save(instanceDetails);
            refreshClient(instanceDetails);
        }
    }

    return returnedInstances;
}
 
开发者ID:peavers,项目名称:swordfish-service,代码行数:21,代码来源:EC2SyncImpl.java

示例3: listsInstances

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //导入依赖的package包/类
/**
 * InstanceList can list instances.
 */
@Test
public void listsInstances() {
    Mockito.when(
        this.client.describeInstances(
            Mockito.any(DescribeInstancesRequest.class)
        )
    ).thenReturn(
        new DescribeInstancesResult()
            .withReservations(
                Collections.singletonList(this.fakeReservation())
            )
    );

    final List<Instance> instances = new InstanceList(
        "blah",
        this.fakeConfig(),
        this.provider
    ).get();
    Assertions.assertThat(instances).hasSize(1);
}
 
开发者ID:ContaAzul,项目名称:turbine-ec2,代码行数:24,代码来源:InstanceListTest.java

示例4: listsInstancesFromMultipleReservartions

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //导入依赖的package包/类
/**
 * InstanceList can list instances.
 */
@Test
public void listsInstancesFromMultipleReservartions() {
    Mockito.when(
        this.client.describeInstances(
            Mockito.any(DescribeInstancesRequest.class)
        )
    ).thenReturn(
        new DescribeInstancesResult()
            .withReservations(
                Arrays.asList(
                    this.fakeReservation(),
                    this.fakeReservation(),
                    this.fakeReservation(),
                    this.fakeReservation()
                )
            )
    );

    final List<Instance> instances = new InstanceList(
        "blah",
        this.fakeConfig(),
        this.provider
    ).get();
    Assertions.assertThat(instances).hasSize(4);
}
 
开发者ID:ContaAzul,项目名称:turbine-ec2,代码行数:29,代码来源:InstanceListTest.java

示例5: getInstanceStateName

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //导入依赖的package包/类
public String getInstanceStateName(InstanceRequest instanceRequest, Context context) {

		AmazonEC2Async client = createEC2Client();
		try {
			DescribeInstancesResult result = client
					.describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceRequest.getInstanceId()));
			List<Instance> instances = result.getReservations().get(0).getInstances();
			if (instances.size() != 1) {
				throw new RuntimeException("instance can not be found.");
			}
			return instances.get(0).getState().getName();

		} finally {
			client.shutdown();
		}
	}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:17,代码来源:InstanceOperation.java

示例6: getRemoteInstances

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //导入依赖的package包/类
/**
 * Get the instances from AWS filtered by the instances Ids known to the local system.
 */
public void getRemoteInstances(EnumerationDeletionContext aws,
        AWSEnumerationDeletionSubStage next) {
    if (aws.localInstanceIds == null || aws.localInstanceIds.size() == 0) {
        logFine(() -> "No local records found. No states need to be fetched from the AWS"
                + " endpoint.");
        aws.subStage = next;
        deleteResourcesInLocalSystem(aws);
        return;
    }
    DescribeInstancesRequest request = new DescribeInstancesRequest();
    Filter runningInstanceFilter = getAWSNonTerminatedInstancesFilter();
    request.getFilters().add(runningInstanceFilter);
    // Get only the instances from the remote system for which a compute state exists in the
    // local system.
    logFine(() -> String.format("Fetching instance details for %d instances on the AWS"
                    + " endpoint.", aws.localInstanceIds.keySet().size()));
    request.getInstanceIds().addAll(new ArrayList<>(aws.localInstanceIds.keySet()));
    AsyncHandler<DescribeInstancesRequest, DescribeInstancesResult> resultHandler =
            new AWSEnumerationAsyncHandler(this, aws, next);
    aws.amazonEC2Client.describeInstancesAsync(request,
            resultHandler);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:26,代码来源:AWSEnumerationAndDeletionAdapterService.java

示例7: onSuccess

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //导入依赖的package包/类
@Override
public void onSuccess(DescribeInstancesRequest request,
        DescribeInstancesResult result) {
    OperationContext.restoreOperationContext(this.opContext);
    int totalNumberOfInstances = 0;
    // Print the details of the instances discovered on the AWS endpoint
    for (Reservation r : result.getReservations()) {
        for (Instance i : r.getInstances()) {
            ++totalNumberOfInstances;
            final int finalTotal1 = totalNumberOfInstances;
            this.service.logFine(() -> String.format("%d=====Instance details %s =====",
                    finalTotal1, i.getInstanceId()));
            this.aws.remoteInstanceIds.add(i.getInstanceId());
        }
    }
    final int finalTotal2 = totalNumberOfInstances;
    this.service.logFine(() -> String.format("Successfully enumerated %d instances on the"
                    + " AWS host.", finalTotal2));
    this.aws.subStage = this.next;
    ((AWSEnumerationAndDeletionAdapterService) this.service)
            .deleteResourcesInLocalSystem(this.aws);
    return;
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:24,代码来源:AWSEnumerationAndDeletionAdapterService.java

示例8: getAwsInstancesByIds

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //导入依赖的package包/类
/**
 * Method to get Instance details directly from Amazon
 *
 * @throws Throwable
 */
public static List<Instance> getAwsInstancesByIds(AmazonEC2AsyncClient client,
        VerificationHost host, List<String> instanceIds)
        throws Throwable {
    host.log("Getting instances with ids " + instanceIds
            + " from the AWS endpoint using the EC2 client.");

    DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
            .withInstanceIds(instanceIds);

    DescribeInstancesResult describeInstancesResult = client
            .describeInstances(describeInstancesRequest);

    return describeInstancesResult.getReservations().stream()
            .flatMap(r -> r.getInstances().stream()).collect(Collectors.toList());
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:21,代码来源:TestAWSSetupUtils.java

示例9: getPublicDnsForAutoScalingGroup

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //导入依赖的package包/类
/**
 * For a given AutoScaling group logical id, get the public dns names associated with each instance.
 *
 * @param logicalId AutoScaling group logical id
 * @return List of public dns names
 */
public List<String> getPublicDnsForAutoScalingGroup(final String logicalId) {
    final List<String> instanceIds = Lists.newLinkedList();
    final Optional<AutoScalingGroup> autoScalingGroup = describeAutoScalingGroup(logicalId);
    final List<String> publicDnsNames = Lists.newLinkedList();

    if (autoScalingGroup.isPresent()) {
        autoScalingGroup.get()
                .getInstances().stream().forEach(instance -> instanceIds.add(instance.getInstanceId()));

        final DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
                .withInstanceIds(instanceIds);
        final DescribeInstancesResult describeInstancesResult =
                ec2Client.describeInstances(describeInstancesRequest);

        describeInstancesResult.getReservations().forEach(reservation ->
                reservation.getInstances().stream().forEach(instance ->
                        publicDnsNames.add(instance.getPublicDnsName()))
        );
    }

    return publicDnsNames;
}
 
开发者ID:Nike-Inc,项目名称:cerberus-lifecycle-cli,代码行数:29,代码来源:AutoScalingService.java

示例10: getInstancesByTag

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //导入依赖的package包/类
/**
 * Gets all EC2 instances with the given tag key/value pair
 * @param tagKey - Key of the tag
 * @param tagValue - Value of the tag
 * @param filters - Array of EC2 filters
 * @return - List of instances with the given tag
 */
public List<Instance> getInstancesByTag(final String tagKey, final String tagValue, final Filter... filters) {
    final String filterName = String.format(FILTER_NAME_TEMPL_FOR_EC2_TAGS, tagKey);
    final Filter tagFilter = new Filter().withName(filterName).withValues(tagValue);

    final Set<Filter> filterSet = Sets.newHashSet(filters);
    filterSet.add(tagFilter);
    final DescribeInstancesRequest request = new DescribeInstancesRequest().withFilters(filterSet);

    DescribeInstancesResult result = ec2Client.describeInstances(request);
    List<Instance> instances = Lists.newArrayList();

    result.getReservations().forEach(reservation -> {
        instances.addAll(reservation.getInstances());
    });

    return instances;
}
 
开发者ID:Nike-Inc,项目名称:cerberus-lifecycle-cli,代码行数:25,代码来源:Ec2Service.java

示例11: testGetInstancesByTagHappy

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

    String tagKey = "tag key";
    String tagValue = "tag value";
    Filter filter = new Filter().withName(INSTANCE_STATE_FILTER_NAME).withValues(INSTANCE_STATE_RUNNING_FILTER_VALUE);
    Instance instance = mock(Instance.class);

    when(ec2Client.describeInstances(new DescribeInstancesRequest()
            .withFilters(
                    filter,
                    new Filter()
                            .withName(String.format(FILTER_NAME_TEMPL_FOR_EC2_TAGS, tagKey))
                            .withValues(tagValue)
            )
    )).thenReturn(
            new DescribeInstancesResult()
                    .withReservations(
                            new Reservation()
                                    .withInstances(instance))
    );

    List<Instance> instances = ec2Service.getInstancesByTag(tagKey, tagValue, filter);

    assertTrue(instances.contains(instance));
}
 
开发者ID:Nike-Inc,项目名称:cerberus-lifecycle-cli,代码行数:27,代码来源:Ec2ServiceTest.java

示例12: describeInstances

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //导入依赖的package包/类
private void describeInstances(AmazonEC2Client ec2Client, Exchange exchange) {
    Collection instanceIds;
    DescribeInstancesRequest request = new DescribeInstancesRequest();
    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS))) {
        instanceIds = exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS, Collection.class);
        request.withInstanceIds(instanceIds);
    } 
    DescribeInstancesResult result;
    try {
        result = ec2Client.describeInstances(request);
    } catch (AmazonServiceException ase) {
        LOG.trace("Describe Instances command returned the error code {}", ase.getErrorCode());
        throw ase;
    }
    Message message = getMessageForResponse(exchange);
    message.setBody(result);        
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:EC2Producer.java

示例13: forEachInstance

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //导入依赖的package包/类
/**
 * Iterates through the instances in the specified {@code DescribeInstancesResult}
 * and calls the specified handler on each instance. This method will retrieve the
 * follow-on {@code DescribeInstanceResult}s if the result holds a {@code nextToken}.
 *
 * @param result          the {@code DescribeInstancesResult}
 * @param instanceHandler the instance handler
 */
@VisibleForTesting
void forEachInstance(DescribeInstancesResult result, InstanceHandler instanceHandler) {
  List<Reservation> reservations;
  while (!(reservations = result.getReservations()).isEmpty()) {
    for (Reservation reservation : reservations) {
      for (Instance instance : reservation.getInstances()) {
        LOG.debug("Calling instance handler with instance {}", instance);
        instanceHandler.handle(instance);
      }
    }

    if (result.getNextToken() != null) {
      result = client.describeInstances(
          new DescribeInstancesRequest().withNextToken(result.getNextToken()));
    } else {
      break;
    }
  }
}
 
开发者ID:cloudera,项目名称:director-aws-plugin,代码行数:28,代码来源:EC2Provider.java

示例14: describeInstances

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //导入依赖的package包/类
/**
 * 
 * @{inheritDoc
 */
@Override
public List<VMInformation> describeInstances(String... instanceIds) {
    List<VMInformation> result = new ArrayList<VMInformation>();
    try {

        DescribeInstancesResult results = asynchEc2Client.describeInstances();
        HashSet<String> ids = new HashSet<String>(Arrays.asList(instanceIds));
        for (Reservation reservationDescription : results.getReservations()) {
            for (com.amazonaws.services.ec2.model.Instance instance : reservationDescription.getInstances()) {
                if (ids.contains(instance.getInstanceId())) {
                    result.add(new AmazonDataConverter().instanceToVmInformation(reservationDescription, instance, vmRegion));
                }
            }
            // result.addAll(TypicaDataConverter.processReservationDescription(reservationDescription));
        }
    } catch (Exception e) {
        LOG.error("Failed to retrieve instance from Amazon: " + e.getMessage());
        throw new RuntimeException(e);
    }

    return result;
}
 
开发者ID:intuit,项目名称:Tank,代码行数:27,代码来源:AmazonInstance.java

示例15: findInstancesOfType

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //导入依赖的package包/类
/**
 * @{inheritDoc
 */
@Override
public List<VMInformation> findInstancesOfType(VMRegion region, VMImageType type) {
    List<VMInformation> ret = new ArrayList<VMInformation>();
    try {
        DescribeInstancesResult instances = asynchEc2Client.describeInstances();
        InstanceDescription instanceForRegionAndType = new TankConfig().getVmManagerConfig().getInstanceForRegionAndType(region, type);
        for (Reservation res : instances.getReservations()) {
            if (res.getInstances() != null) {
                for (com.amazonaws.services.ec2.model.Instance inst : res.getInstances()) {
                    if ((inst.getState().getName().equalsIgnoreCase("running") || inst.getState().getName().equalsIgnoreCase("pending"))
                            && inst.getImageId().equals(instanceForRegionAndType.getAmi())) {
                        ret.add(new AmazonDataConverter().instanceToVmInformation(res, inst, region));
                    }
                }
            }
        }
    } catch (Exception e) {
        LOG.error("Error getting instances: " + e.toString(), e);
        throw new RuntimeException(e);
    }
    return ret;
}
 
开发者ID:intuit,项目名称:Tank,代码行数:26,代码来源:AmazonInstance.java


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