use of com.amazonaws.services.ecs.AmazonECS in project gocd-ecs-elastic-agent by gocd.
the class TaskHelper method listAllTasks.
public Map<Task, TaskDefinition> listAllTasks(PluginSettings settings) {
String clusterName = settings.getClusterName();
AmazonECS ecsClient = settings.ecsClient();
List<String> taskArns = ecsClient.listTasks(new ListTasksRequest().withCluster(clusterName)).getTaskArns();
if (taskArns.isEmpty()) {
return Collections.emptyMap();
}
List<Task> tasks = ecsClient.describeTasks(new DescribeTasksRequest().withTasks(taskArns).withCluster(clusterName)).getTasks();
return tasks.stream().collect(Collectors.toMap(task -> task, task -> ecsClient.describeTaskDefinition(new DescribeTaskDefinitionRequest().withTaskDefinition(task.getTaskDefinitionArn())).getTaskDefinition()));
}
use of com.amazonaws.services.ecs.AmazonECS in project gocd-ecs-elastic-agent by gocd.
the class TaskHelper method allRunningContainers.
public List<ECSContainer> allRunningContainers(PluginSettings settings) {
String clusterName = settings.getClusterName();
AmazonECS ecsClient = settings.ecsClient();
List<String> taskArns = ecsClient.listTasks(new ListTasksRequest().withCluster(clusterName).withDesiredStatus(DesiredStatus.RUNNING)).getTaskArns();
if (taskArns.isEmpty()) {
return Collections.emptyList();
}
List<Task> tasks = ecsClient.describeTasks(new DescribeTasksRequest().withTasks(taskArns).withCluster(clusterName)).getTasks();
return tasks.stream().map(t -> {
final TaskDefinition taskDefinition = ecsClient.describeTaskDefinition(new DescribeTaskDefinitionRequest().withTaskDefinition(t.getTaskDefinitionArn())).getTaskDefinition();
return new ECSContainer(t, taskDefinition);
}).collect(Collectors.toList());
}
use of com.amazonaws.services.ecs.AmazonECS in project gocd-ecs-elastic-agent by gocd.
the class TaskHelper method refreshTask.
public Optional<Task> refreshTask(PluginSettings settings, String taskArn) {
String clusterName = settings.getClusterName();
AmazonECS ecsClient = settings.ecsClient();
List<Task> tasks = ecsClient.describeTasks(new DescribeTasksRequest().withTasks(taskArn).withCluster(clusterName)).getTasks();
if (tasks.isEmpty()) {
return empty();
}
return Optional.of(tasks.get(0));
}
Aggregations