Example usage for com.amazonaws.services.ecs.model ContainerInstance getContainerInstanceArn

List of usage examples for com.amazonaws.services.ecs.model ContainerInstance getContainerInstanceArn

Introduction

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

Prototype


public String getContainerInstanceArn() 

Source Link

Document

The Amazon Resource Name (ARN) of the container instance.

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 {//from   www .  ja va 2s  . c o 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 Map<String, Collection<CacheData>> generateFreshData(
        Collection<ContainerInstance> containerInstances) {
    Collection<CacheData> dataPoints = new LinkedList<>();

    for (ContainerInstance containerInstance : containerInstances) {
        Map<String, Object> attributes = convertContainerInstanceToAttributes(containerInstance);

        String key = Keys.getContainerInstanceKey(accountName, region,
                containerInstance.getContainerInstanceArn());
        dataPoints.add(new DefaultCacheData(key, attributes, Collections.emptyMap()));
    }/*from  w  w w.j  ava2  s  . com*/

    log.info("Caching " + dataPoints.size() + " container instances in " + getAgentType());
    Map<String, Collection<CacheData>> dataMap = new HashMap<>();
    dataMap.put(CONTAINER_INSTANCES.toString(), dataPoints);

    return dataMap;
}

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

License:Apache License

public static Map<String, Object> convertContainerInstanceToAttributes(ContainerInstance containerInstance) {
    Map<String, Object> attributes = new HashMap<>();
    attributes.put("containerInstanceArn", containerInstance.getContainerInstanceArn());
    attributes.put("ec2InstanceId", containerInstance.getEc2InstanceId());
    for (Attribute containerAttribute : containerInstance.getAttributes()) {
        if (containerAttribute.getName().equals("ecs.availability-zone")) {
            attributes.put("availabilityZone", containerAttribute.getValue());
        }//from   w  ww .  j  av a 2  s. co m
    }
    return attributes;
}