Search in sources :

Example 1 with EligibleForTerminationPredicate

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);
}
Also used : ContainerInstance(com.amazonaws.services.ecs.model.ContainerInstance) GoPluginApiResponse(com.thoughtworks.go.plugin.api.response.GoPluginApiResponse) ContainerInstanceHelper(com.thoughtworks.gocd.elasticagent.ecs.aws.ContainerInstanceHelper) EventStream(com.thoughtworks.gocd.elasticagent.ecs.events.EventStream) Event(com.thoughtworks.gocd.elasticagent.ecs.events.Event) EventFingerprint(com.thoughtworks.gocd.elasticagent.ecs.events.EventFingerprint) LimitExceededException(com.thoughtworks.gocd.elasticagent.ecs.exceptions.LimitExceededException) java.util(java.util) StopPolicy(com.thoughtworks.gocd.elasticagent.ecs.aws.StopPolicy) EligibleForTerminationPredicate(com.thoughtworks.gocd.elasticagent.ecs.aws.predicate.EligibleForTerminationPredicate) ContainerInstance(com.amazonaws.services.ecs.model.ContainerInstance) MessageFormat.format(java.text.MessageFormat.format) MostIdleInstanceComparator(com.thoughtworks.gocd.elasticagent.ecs.aws.comparator.MostIdleInstanceComparator) ServerRequestFailedException(com.thoughtworks.gocd.elasticagent.ecs.exceptions.ServerRequestFailedException) LOG(com.thoughtworks.gocd.elasticagent.ecs.ECSElasticPlugin.LOG) Instance(com.amazonaws.services.ec2.model.Instance) SpotInstanceService(com.thoughtworks.gocd.elasticagent.ecs.aws.SpotInstanceService) LINUX(com.thoughtworks.gocd.elasticagent.ecs.domain.Platform.LINUX) Collectors.toSet(java.util.stream.Collectors.toSet) DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) StopOperation(com.thoughtworks.gocd.elasticagent.ecs.aws.strategy.StopOperation) InstanceSelectionStrategyFactory(com.thoughtworks.gocd.elasticagent.ecs.aws.strategy.InstanceSelectionStrategyFactory) Collectors(java.util.stream.Collectors) Platform.values(com.thoughtworks.gocd.elasticagent.ecs.domain.Platform.values) Collectors.toList(java.util.stream.Collectors.toList) TerminateOperation(com.thoughtworks.gocd.elasticagent.ecs.aws.strategy.TerminateOperation) com.thoughtworks.gocd.elasticagent.ecs.domain(com.thoughtworks.gocd.elasticagent.ecs.domain) EC2Config(com.thoughtworks.gocd.elasticagent.ecs.aws.EC2Config) com.thoughtworks.gocd.elasticagent.ecs(com.thoughtworks.gocd.elasticagent.ecs) ServerPingRequest(com.thoughtworks.gocd.elasticagent.ecs.requests.ServerPingRequest) ContainerInstance(com.amazonaws.services.ecs.model.ContainerInstance) Instance(com.amazonaws.services.ec2.model.Instance) EligibleForTerminationPredicate(com.thoughtworks.gocd.elasticagent.ecs.aws.predicate.EligibleForTerminationPredicate)

Aggregations

Instance (com.amazonaws.services.ec2.model.Instance)1 ContainerInstance (com.amazonaws.services.ecs.model.ContainerInstance)1 DefaultGoPluginApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse)1 GoPluginApiResponse (com.thoughtworks.go.plugin.api.response.GoPluginApiResponse)1 com.thoughtworks.gocd.elasticagent.ecs (com.thoughtworks.gocd.elasticagent.ecs)1 LOG (com.thoughtworks.gocd.elasticagent.ecs.ECSElasticPlugin.LOG)1 ContainerInstanceHelper (com.thoughtworks.gocd.elasticagent.ecs.aws.ContainerInstanceHelper)1 EC2Config (com.thoughtworks.gocd.elasticagent.ecs.aws.EC2Config)1 SpotInstanceService (com.thoughtworks.gocd.elasticagent.ecs.aws.SpotInstanceService)1 StopPolicy (com.thoughtworks.gocd.elasticagent.ecs.aws.StopPolicy)1 MostIdleInstanceComparator (com.thoughtworks.gocd.elasticagent.ecs.aws.comparator.MostIdleInstanceComparator)1 EligibleForTerminationPredicate (com.thoughtworks.gocd.elasticagent.ecs.aws.predicate.EligibleForTerminationPredicate)1 InstanceSelectionStrategyFactory (com.thoughtworks.gocd.elasticagent.ecs.aws.strategy.InstanceSelectionStrategyFactory)1 StopOperation (com.thoughtworks.gocd.elasticagent.ecs.aws.strategy.StopOperation)1 TerminateOperation (com.thoughtworks.gocd.elasticagent.ecs.aws.strategy.TerminateOperation)1 com.thoughtworks.gocd.elasticagent.ecs.domain (com.thoughtworks.gocd.elasticagent.ecs.domain)1 LINUX (com.thoughtworks.gocd.elasticagent.ecs.domain.Platform.LINUX)1 Platform.values (com.thoughtworks.gocd.elasticagent.ecs.domain.Platform.values)1 Event (com.thoughtworks.gocd.elasticagent.ecs.events.Event)1 EventFingerprint (com.thoughtworks.gocd.elasticagent.ecs.events.EventFingerprint)1