use of com.thoughtworks.gocd.elasticagent.ecs.domain.Agent in project gocd-ecs-elastic-agent by gocd.
the class JobCompletionRequestExecutor method execute.
@Override
public GoPluginApiResponse execute() throws Exception {
PluginSettings clusterProfileProperties = jobCompletionRequest.clusterProfileProperties();
String elasticAgentId = jobCompletionRequest.getElasticAgentId();
Agents agents = pluginRequest.listAgents();
if (!agents.agentIds().contains(elasticAgentId)) {
LOG.debug("[Job Completion] Skipping request to delete agent with id '{}' as the agent does not exist on the server.", elasticAgentId);
return DefaultGoPluginApiResponse.success("");
}
Agent agent = new Agent(elasticAgentId);
LOG.debug("[Job Completion] Disabling elastic agent with id {} on job completion {}.", agent.elasticAgentId(), jobCompletionRequest.jobIdentifier());
pluginRequest.disableAgents(Collections.singletonList(agent));
LOG.debug("[Job Completion] Terminating elastic agent with id {} on job completion {}.", agent.elasticAgentId(), jobCompletionRequest.jobIdentifier());
agentInstances.terminate(agent.elasticAgentId(), clusterProfileProperties);
LOG.debug("[Job Completion] Deleting elastic agent with id {} on job completion {}.", agent.elasticAgentId(), jobCompletionRequest.jobIdentifier());
pluginRequest.deleteAgents(Collections.singletonList(agent));
return DefaultGoPluginApiResponse.success("");
}
use of com.thoughtworks.gocd.elasticagent.ecs.domain.Agent in project gocd-ecs-elastic-agent by gocd.
the class ShouldAssignWorkRequestExecutorTest method shouldNotAssignWorkToContainerWithDifferentJobIdentifier.
@Test
void shouldNotAssignWorkToContainerWithDifferentJobIdentifier() {
ShouldAssignWorkRequest request = new ShouldAssignWorkRequest(new Agent(task.name(), null, null, null), "FooEnv", elasticAgentProfileProperties, getJobIdentifierWithId(2), clusterProfileProperties);
GoPluginApiResponse response = new ShouldAssignWorkRequestExecutor(request, agentInstances).execute();
assertThat(response.responseCode()).isEqualTo(200);
assertThat(response.responseBody()).isEqualTo("false");
}
Aggregations