use of com.thoughtworks.gocd.elasticagent.ecs.aws.comparator.MostIdleInstanceComparator in project gocd-ecs-elastic-agent by gocd.
the class ServerPingRequestExecutor method terminateIdleContainerInstance.
private void terminateIdleContainerInstance(PluginSettings pluginSettings, List<Instance> instancesForPlatform) {
final Instance instance = instancesForPlatform.stream().sorted(new MostIdleInstanceComparator(Clock.DEFAULT.now())).collect(toList()).get(0);
final Optional<ContainerInstance> containerInstance = containerInstanceHelper.onDemandContainerInstances(pluginSettings).stream().filter(ci -> ci.getEc2InstanceId().equals(instance.getInstanceId())).findFirst();
containerInstance.ifPresent(self -> terminateOperation.execute(pluginSettings, self));
}
use of com.thoughtworks.gocd.elasticagent.ecs.aws.comparator.MostIdleInstanceComparator 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));
}
use of com.thoughtworks.gocd.elasticagent.ecs.aws.comparator.MostIdleInstanceComparator in project gocd-ecs-elastic-agent by gocd.
the class StopIdleInstanceSelectionStrategy method findInstancesToStop.
@Override
protected List<ContainerInstance> findInstancesToStop(PluginSettings pluginSettings, Platform platform, Map<String, ContainerInstance> instanceIdToContainerInstance, List<Instance> idleInstances) {
final Period timeInstanceCanStayIdle = platform == Platform.LINUX ? pluginSettings.stopLinuxInstanceAfter() : pluginSettings.stopWindowsInstanceAfter();
idleInstances.sort(new MostIdleInstanceComparator(clock.now()));
return idleInstances.stream().filter(isIdlePeriodIsMoreThan(timeInstanceCanStayIdle)).map(instance -> instanceIdToContainerInstance.get(instance.getInstanceId())).collect(Collectors.toList());
}
Aggregations