Example usage for com.amazonaws.services.ecs.model ListClustersResult getClusterArns

List of usage examples for com.amazonaws.services.ecs.model ListClustersResult getClusterArns

Introduction

In this page you can find the example usage for com.amazonaws.services.ecs.model ListClustersResult getClusterArns.

Prototype


public java.util.List<String> getClusterArns() 

Source Link

Document

The list of full Amazon Resource Name (ARN) entries for each cluster associated with your account.

Usage

From source file:com.netflix.spinnaker.clouddriver.ecs.provider.agent.AbstractEcsCachingAgent.java

License:Apache License

/**
 * Provides a set of ECS cluster ARNs.// w ww  .  j  av a  2s  .c o m
 * Either uses the cache, or queries the ECS service.
 * @param ecs The AmazonECS client to use for querying.
 * @param providerCache The ProviderCache to retrieve clusters from.
 * @return A set of ECS cluster ARNs.
 */
Set<String> getClusters(AmazonECS ecs, ProviderCache providerCache) {
    Set<String> clusters = providerCache.getAll(ECS_CLUSTERS.toString()).stream()
            .filter(cacheData -> cacheData.getAttributes().get("region").equals(region)
                    && cacheData.getAttributes().get("account").equals(accountName))
            .map(cacheData -> (String) cacheData.getAttributes().get("clusterArn")).collect(Collectors.toSet());

    if (clusters == null || clusters.isEmpty()) {
        clusters = new HashSet<>();
        String nextToken = null;
        do {
            ListClustersRequest listClustersRequest = new ListClustersRequest();
            if (nextToken != null) {
                listClustersRequest.setNextToken(nextToken);
            }
            ListClustersResult listClustersResult = ecs.listClusters(listClustersRequest);
            clusters.addAll(listClustersResult.getClusterArns());

            nextToken = listClustersResult.getNextToken();
        } while (nextToken != null && nextToken.length() != 0);
    }

    return clusters;
}

From source file:com.netflix.spinnaker.clouddriver.ecs.provider.agent.EcsClusterCachingAgent.java

License:Apache License

@Override
protected List<String> getItems(AmazonECS ecs, ProviderCache providerCache) {
    List<String> allClusterArns = new LinkedList<>();
    String nextToken = null;/*from   w w  w. java 2s  . c  om*/
    do {
        ListClustersRequest listClustersRequest = new ListClustersRequest();
        if (nextToken != null) {
            listClustersRequest.setNextToken(nextToken);
        }

        ListClustersResult listClustersResult = ecs.listClusters(listClustersRequest);
        allClusterArns.addAll(listClustersResult.getClusterArns());

        nextToken = listClustersResult.getNextToken();
    } while (nextToken != null && nextToken.length() != 0);

    return allClusterArns;
}