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


Java DescribeInstancesRequest類代碼示例

本文整理匯總了Java中com.amazonaws.services.ec2.model.DescribeInstancesRequest的典型用法代碼示例。如果您正苦於以下問題:Java DescribeInstancesRequest類的具體用法?Java DescribeInstancesRequest怎麽用?Java DescribeInstancesRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DescribeInstancesRequest類屬於com.amazonaws.services.ec2.model包,在下文中一共展示了DescribeInstancesRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildDescribeInstancesRequest

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入依賴的package包/類
private DescribeInstancesRequest buildDescribeInstancesRequest() {
    DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
        .withFilters(
            new Filter("instance-state-name").withValues("running", "pending")
        );

    for (Map.Entry<String, String> tagFilter : tags.entrySet()) {
        // for a given tag key, OR relationship for multiple different values
        describeInstancesRequest.withFilters(
            new Filter("tag:" + tagFilter.getKey()).withValues(tagFilter.getValue())
        );
    }

    if (!availabilityZones.isEmpty()) {
        // OR relationship amongst multiple values of the availability-zone filter
        describeInstancesRequest.withFilters(
            new Filter("availability-zone").withValues(availabilityZones)
        );
    }

    return describeInstancesRequest;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:AwsEc2UnicastHostsProvider.java

示例2: getInstanceState

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入依賴的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

示例3: process_STOPING

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入依賴的package包/類
@Test
public void process_STOPING() throws Exception {
    // given
    ec2mock.createDescribeInstancesResult("instance1", "stopped", "1.2.3.4");
    ec2mock.createDescribeInstanceStatusResult("instance1", "ok", "ok",
            "ok");
    ph.setOperation(Operation.EC2_OPERATION);
    ph.setState(FlowState.STOPPING);

    // when
    InstanceStatus result = ec2proc.process();

    // then
    assertTrue(result.isReady());
    assertEquals(FlowState.FINISHED, ph.getState());

    verify(ec2).describeInstances(any(DescribeInstancesRequest.class));
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:19,代碼來源:EC2ProcessorTest.java

示例4: describeInstancesRequestWaiterHandler

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入依賴的package包/類
@Override
public WaiterHandler<DescribeInstancesRequest> describeInstancesRequestWaiterHandler() {
    return new WaiterHandler<DescribeInstancesRequest>() {
        @Override
        public void onWaitSuccess(DescribeInstancesRequest request) {
            List<String> instanceIds = request.getInstanceIds();

            for (String instanceId : instanceIds) {
                ec2Sync.syncByInstanceId(instanceId);
            }
        }

        @Override
        public void onWaitFailure(Exception e) {
            log.warn("something went wrong waiting for AWS {}", e.getLocalizedMessage());
        }
    };
}
 
開發者ID:peavers,項目名稱:swordfish-service,代碼行數:19,代碼來源:EC2WaiterImpl.java

示例5: listsInstances

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入依賴的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

示例6: listsInstancesFromMultipleReservartions

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入依賴的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

示例7: getInstanceStateName

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入依賴的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

示例8: runSearch

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入依賴的package包/類
private void runSearch(T type) {
    AmazonWebServiceRequest descRequest = buildRequest(type);
    AsyncHandler describeHandler = buildHandler(type);
    if (type instanceof Instance) {
        this.amazonEC2Client.describeInstancesAsync(
                (DescribeInstancesRequest) descRequest, describeHandler);
    } else if (type instanceof NatGateway) {
        this.amazonEC2Client.describeNatGatewaysAsync(
                (DescribeNatGatewaysRequest) descRequest, describeHandler);
    } else if (type instanceof Volume) {
        this.amazonEC2Client.describeVolumesAsync(
                (DescribeVolumesRequest) descRequest, describeHandler);
    } else {
        AWSTaskStatusChecker.this.taskManager.patchTaskToFailure(
                new IllegalArgumentException("Invalid type " + type));
    }
}
 
開發者ID:vmware,項目名稱:photon-model,代碼行數:18,代碼來源:AWSTaskStatusChecker.java

示例9: getRemoteInstances

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入依賴的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

示例10: onSuccess

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入依賴的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

示例11: getAwsInstancesByIds

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入依賴的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

示例12: getBaseLineInstanceCount

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入依賴的package包/類
/**
 * Gets the instance count of non-terminated instances on the AWS endpoint. This is used to run
 * the asserts and validate the results for the data that is collected during enumeration.This
 * also calculates the compute descriptions that will be used to represent the instances that
 * were discovered on the AWS endpoint. Further factoring in the
 *
 * @throws Throwable
 */
public static BaseLineState getBaseLineInstanceCount(VerificationHost host,
        AmazonEC2AsyncClient client,
        List<String> testComputeDescriptions)
        throws Throwable {
    BaseLineState baseLineState = new BaseLineState();
    AWSEnumerationAsyncHandler enumerationHandler = new AWSEnumerationAsyncHandler(host,
            AWSEnumerationAsyncHandler.MODE.GET_COUNT, null, null, null,
            testComputeDescriptions,
            baseLineState);
    DescribeInstancesRequest request = new DescribeInstancesRequest();
    Filter runningInstanceFilter = getAWSNonTerminatedInstancesFilter();
    request.getFilters().add(runningInstanceFilter);
    client.describeInstancesAsync(request, enumerationHandler);
    host.waitFor("Error waiting to get base line instance count from AWS in test ", () -> {
        return baseLineState.isCountPopulated;
    });
    return baseLineState;
}
 
開發者ID:vmware,項目名稱:photon-model,代碼行數:27,代碼來源:TestAWSSetupUtils.java

示例13: checkInstancesDeleted

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入依賴的package包/類
/**
 * Checks if a newly deleted instance has its status set to terminated.
 *
 * @return
 */
public static void checkInstancesDeleted(AmazonEC2AsyncClient client,
        VerificationHost host, List<String> instanceIdsToDelete,
        ArrayList<Boolean> deletionFlags) throws Throwable {
    AWSEnumerationAsyncHandler enumerationHandler = new AWSEnumerationAsyncHandler(host,
            AWSEnumerationAsyncHandler.MODE.CHECK_TERMINATION, null, deletionFlags, null, null,
            null);
    DescribeInstancesRequest request = new DescribeInstancesRequest()
            .withInstanceIds(instanceIdsToDelete);
    client.describeInstancesAsync(request, enumerationHandler);
    // Waiting to get a response from AWS before the state computation is done for the list of
    // VMs.
    host.waitFor("Waiting to get response from AWS ", () -> {
        return enumerationHandler.responseReceived;
    });
}
 
開發者ID:vmware,項目名稱:photon-model,代碼行數:21,代碼來源:TestAWSSetupUtils.java

示例14: getPublicDnsForAutoScalingGroup

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入依賴的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

示例15: getInstancesByTag

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入依賴的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


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