use of com.thoughtworks.gocd.elasticagent.ecs.aws.strategy.TerminateOperation in project gocd-ecs-elastic-agent by gocd.
the class ContainerInstanceHelper method terminateMostIdleStoppedInstance.
private void terminateMostIdleStoppedInstance(PluginSettings pluginSettings, List<Instance> stoppedInstances) {
stoppedInstances.sort(new MostIdleInstanceComparator(Clock.DEFAULT.now()));
final String instanceId = stoppedInstances.get(0).getInstanceId();
LOG.info(format("Terminating stopped instance as max cluster limit is reached {0}.", instanceId));
final Optional<ContainerInstance> containerInstance = getContainerInstances(pluginSettings).stream().filter(ci -> ci.getEc2InstanceId().equals(instanceId)).findFirst();
containerInstance.ifPresent(self -> new TerminateOperation().execute(pluginSettings, self));
}
Aggregations