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


Java DescribeInstancesRequest.withFilters方法代碼示例

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


在下文中一共展示了DescribeInstancesRequest.withFilters方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: call

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
@Override
public List<Instance> call() {
    List<Instance> instances = new ArrayList<>();
    DescribeInstancesRequest request = new DescribeInstancesRequest();
    request.withInstanceIds(this.instanceIds);
    request.withFilters(this.filters);
    // paginate through result as long as there is another response token
    boolean moreResults = false;
    do {
        DescribeInstancesResult result = getClient().getApi().describeInstances(request);
        instances.addAll(instances(result));
        moreResults = result.getNextToken() != null && !result.getNextToken().equals("");
        request.setNextToken(result.getNextToken());
    } while (moreResults);

    return instances;
}
 
開發者ID:elastisys,項目名稱:scale.cloudpool,代碼行數:18,代碼來源:GetInstances.java

示例3: doWork

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
@Override
public void doWork() {
    log.info("Running " + AutomationReaperTask.NAME);
    DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
    Filter filter = new Filter("tag:LaunchSource");
    filter.withValues("SeleniumGridScalerPlugin");
    describeInstancesRequest.withFilters(filter);
    List<Reservation> reservations = ec2.describeInstances(describeInstancesRequest);
    for(Reservation reservation : reservations) {
        for(Instance instance : reservation.getInstances()) {
            // Look for orphaned nodes
            Date threshold = AutomationUtils.modifyDate(new Date(),-30, Calendar.MINUTE);
            String instanceId = instance.getInstanceId();
            // If we found a node old enough AND we're not internally tracking it, this means this is an orphaned node and we should terminate it
            if(threshold.after(instance.getLaunchTime()) && !AutomationContext.getContext().nodeExists(instanceId)) {
                log.info("Terminating orphaned node: " + instanceId);
                ec2.terminateInstance(instanceId);
            }
        }
    }
}
 
開發者ID:RetailMeNot,項目名稱:SeleniumGridScaler,代碼行數:22,代碼來源:AutomationReaperTask.java

示例4: describeReservations

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
@Override
public List<AbstractResource<?>> describeReservations(Account account, Region region, DateTime dt, Ec2Filter... filters) {
    AmazonEC2 ec2 = findClient(account, region);

    DescribeInstancesRequest req = new DescribeInstancesRequest();
    for (Ec2Filter filter : filters) {
        Filter f = new Filter().withName(filter.getName()).withValues(filter.getValues());
        req.withFilters(f);
    }

    log.debug("start describing instances for account:{} in region:{} via api", account.getId() + "=>" + account.getName(), region);
    DescribeInstancesResult res = ec2.describeInstances(req);
    List<Map<String, Ec2InstanceAttribute>> attributes = new ArrayList<>();
    for (Reservation r : res.getReservations()) {
        Map<String, Ec2InstanceAttribute> attribute = new HashMap<>();
        for (Instance i : r.getInstances()) {
            Boolean terminationProtection = findTerminationProtection(account, region, i.getInstanceId());
            String shutdownBehavior = findShutdownBehavior(account, region, i.getInstanceId());
            String userData = findUserData(account, region, i.getInstanceId());
            Ec2InstanceAttribute ia = new Ec2InstanceAttribute(terminationProtection, shutdownBehavior, userData);
            attribute.put(i.getInstanceId(), ia);
        }
        attributes.add(attribute);
    }
    return converter.toEc2Reservations(res.getReservations(), attributes, account.getId(), region, dt);
}
 
開發者ID:veyronfei,項目名稱:clouck,代碼行數:27,代碼來源:Ec2WrapperImpl.java

示例5: getEC2InstanceIdsAssociatedWithVpcId

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
/**
 * Get a list of all EC2 instance ids associated with a given VPC id.
 */
public static List<String> getEC2InstanceIdsAssociatedWithVpcId(AmazonEC2AsyncClient client, String vpcId) {
    DescribeInstancesRequest req = new DescribeInstancesRequest();
    if (vpcId != null) {
        req.withFilters(new Filter(AWS_VPC_ID_FILTER, Collections.singletonList(vpcId)));
    }

    DescribeInstancesResult instancesResult = client.describeInstances(req);
    return instancesResult == null ? Collections.emptyList()
            : instancesResult.getReservations().get(0).getInstances().stream()
            .map(instance -> instance.getInstanceId())
            .collect(Collectors.toList());

}
 
開發者ID:vmware,項目名稱:photon-model,代碼行數:17,代碼來源:TestAWSSetupUtils.java

示例6: listInstancesWithTags

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
@Override
public Instances listInstancesWithTags(Tags tags)
{
    Instances instances = new Instances ();
    
    if (tags != null && !tags.isEmpty())
    {
        DescribeInstancesRequest request = new DescribeInstancesRequest();
        
        for (org.excalibur.core.cloud.api.domain.Tag tag: tags)
        {
            if (!isNullOrEmpty(tag.getName()))
            {
                request.withFilters(new Filter().withName("tag-key").withValues(tag.getName()));
            }
            
            if (!isNullOrEmpty(tag.getValue()))
            {
                request.withFilters(new Filter().withName("tag-value").withValues(tag.getValue()));
            }
        }
        
       instances = describeInstances(request);
    }
    
    return instances;
}
 
開發者ID:alessandroleite,項目名稱:dohko,代碼行數:28,代碼來源:EC2.java

示例7: get

import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
@Override
public synchronized T get() {
    try {
        setMyRegion();
        Map<String, ConnectionPoint> ipToHost = new HashMap<>();

        DescribeInstancesRequest req = new DescribeInstancesRequest();
        req.withFilters(filter);
        DescribeInstancesResult res = client.describeInstances(req);
        for (Reservation reservation : res.getReservations()) {
            for (Instance instance : reservation.getInstances()) {
                String privateIP = instance.getPrivateIpAddress();
                if (privateIP != null) {

                    ConnectionPoint connectionPoint = new ConnectionPoint(privateIP, port);
                    ipToHost.put(privateIP, connectionPoint);
                }
            }
        }

        ArrayList<ConnectionPoint> currentHosts = new ArrayList<>(ipToHost.values());
        logHostUpdate(previousHosts, currentHosts);
        previousHosts = currentHosts;
        return convertTo(previousHosts);
    } catch (AmazonClientException ex) {
        if (previousHosts == null) {
            throw new RuntimeException(ex);
        }
        LOG.warn(
            "Failed to get hosts for sg: {} in region: {}.  Will use previously known hosts instead",
            Arrays.toString(filter.getValues().toArray()),
            region == null ? DEFAULT_REGION.toString() : region.toString()
        );
        return convertTo(previousHosts);
    }
}
 
開發者ID:iZettle,項目名稱:izettle-toolbox,代碼行數:37,代碼來源:AbstractAwsSecurityGroupHostSupplier.java


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