List of usage examples for com.amazonaws.services.ecs.model Resource getName
public String getName()
The name of the resource, such as CPU
, MEMORY
, PORTS
, PORTS_UDP
, or a user-defined resource.
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 w w w .j a v a2 s . com 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); } }