Example usage for com.amazonaws.services.ecs.model ListContainerInstancesResult getContainerInstanceArns

List of usage examples for com.amazonaws.services.ecs.model ListContainerInstancesResult getContainerInstanceArns

Introduction

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

Prototype


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

Source Link

Document

The list of container instances with full ARN entries for each container instance associated with the specified cluster.

Usage

From source file:com.cloudbees.jenkins.plugins.amazonecs.ECSService.java

License:Open Source License

void waitForSufficientClusterResources(Date timeout, ECSTaskTemplate template, String clusterArn)
        throws InterruptedException, AbortException {
    AmazonECSClient client = getAmazonECSClient();

    boolean hasEnoughResources = false;
    WHILE: do {/*ww w  .  j  av a2  s . co  m*/
        ListContainerInstancesResult listContainerInstances = client
                .listContainerInstances(new ListContainerInstancesRequest().withCluster(clusterArn));
        DescribeContainerInstancesResult containerInstancesDesc = client
                .describeContainerInstances(new DescribeContainerInstancesRequest()
                        .withContainerInstances(listContainerInstances.getContainerInstanceArns())
                        .withCluster(clusterArn));
        LOGGER.log(Level.INFO, "Found {0} instances", containerInstancesDesc.getContainerInstances().size());
        for (ContainerInstance instance : containerInstancesDesc.getContainerInstances()) {
            LOGGER.log(Level.INFO, "Resources found in instance {1}: {0}",
                    new Object[] { instance.getRemainingResources(), instance.getContainerInstanceArn() });
            Resource memoryResource = null;
            Resource cpuResource = null;
            for (Resource resource : instance.getRemainingResources()) {
                if ("MEMORY".equals(resource.getName())) {
                    memoryResource = resource;
                } else if ("CPU".equals(resource.getName())) {
                    cpuResource = resource;
                }
            }

            LOGGER.log(Level.INFO, "Instance {0} has {1}mb of free memory. {2}mb are required",
                    new Object[] { instance.getContainerInstanceArn(), memoryResource.getIntegerValue(),
                            template.getMemory() });
            LOGGER.log(Level.INFO, "Instance {0} has {1} units of free cpu. {2} units are required",
                    new Object[] { instance.getContainerInstanceArn(), cpuResource.getIntegerValue(),
                            template.getCpu() });
            if (memoryResource.getIntegerValue() >= template.getMemory()
                    && cpuResource.getIntegerValue() >= template.getCpu()) {
                hasEnoughResources = true;
                break WHILE;
            }
        }

        // sleep 10s and check memory again
        Thread.sleep(10000);
    } while (!hasEnoughResources && timeout.after(new Date()));

    if (!hasEnoughResources) {
        final String msg = MessageFormat.format(
                "Timeout while waiting for sufficient resources: {0} cpu units, {1}mb free memory",
                template.getCpu(), template.getMemory());
        LOGGER.log(Level.WARNING, msg);
        throw new AbortException(msg);
    }
}

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

License:Apache License

@Override
protected List<ContainerInstance> getItems(AmazonECS ecs, ProviderCache providerCache) {
    List<ContainerInstance> containerInstanceList = new LinkedList<>();
    Set<String> clusters = getClusters(ecs, providerCache);

    for (String cluster : clusters) {
        String nextToken = null;//from w  w  w  .j a v  a2 s  .co m
        do {
            ListContainerInstancesRequest listContainerInstancesRequest = new ListContainerInstancesRequest()
                    .withCluster(cluster);
            if (nextToken != null) {
                listContainerInstancesRequest.setNextToken(nextToken);
            }

            ListContainerInstancesResult listContainerInstancesResult = ecs
                    .listContainerInstances(listContainerInstancesRequest);
            List<String> containerInstanceArns = listContainerInstancesResult.getContainerInstanceArns();
            if (containerInstanceArns.size() == 0) {
                continue;
            }

            List<ContainerInstance> containerInstances = ecs
                    .describeContainerInstances(new DescribeContainerInstancesRequest().withCluster(cluster)
                            .withContainerInstances(containerInstanceArns))
                    .getContainerInstances();
            containerInstanceList.addAll(containerInstances);

            nextToken = listContainerInstancesResult.getNextToken();
        } while (nextToken != null && nextToken.length() != 0);
    }
    return containerInstanceList;
}

From source file:com.steelbridgelabs.oss.neo4j.cluster.ecs.AutoscalingGroupMembers.java

License:Apache License

private static List<String> containerInstanceArns(AmazonECS client, String cluster) {
    // create request
    ListContainerInstancesRequest request = new ListContainerInstancesRequest();
    // specify cluster name
    request.withCluster(cluster);/*  ww  w .j  a  v  a2 s.  c  om*/
    // next token
    String token = null;
    // container instance arns
    List<String> list = new ArrayList<>();
    do {
        // set next token
        request.setNextToken(token);
        // describe instances
        ListContainerInstancesResult result = client.listContainerInstances(request);
        // get container instance arns
        list.addAll(result.getContainerInstanceArns());
        // check we have more data to retrieve
        token = result.getNextToken();
    } while (token != null);
    // return arns
    return list;
}