use of com.thoughtworks.gocd.elasticagent.ecs.aws.predicate.EligibleForTerminationPredicate in project gocd-ecs-elastic-agent by gocd.
the class ServerPingRequestExecutor method terminateStoppedInstances.
private void terminateStoppedInstances(PluginSettings pluginSettings) {
final List<Instance> allInstances = containerInstanceHelper.getAllOnDemandInstances(pluginSettings);
final EligibleForTerminationPredicate predicate = new EligibleForTerminationPredicate(pluginSettings);
final Set<String> instancesToTerminate = allInstances.stream().filter(predicate).map(Instance::getInstanceId).collect(Collectors.toSet());
if (instancesToTerminate.isEmpty()) {
LOG.debug("[server-ping] None of the instance is eligible for termination.");
}
final List<ContainerInstance> containerInstances = containerInstanceHelper.onDemandContainerInstances(pluginSettings);
final List<ContainerInstance> containerInstanceList = containerInstances.stream().filter(containerInstance -> instancesToTerminate.contains(containerInstance.getEc2InstanceId())).collect(toList());
terminateOperation.execute(pluginSettings, containerInstanceList);
}
Aggregations