Search in sources :

Example 11 with Agent

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("");
}
Also used : Agent(com.thoughtworks.gocd.elasticagent.ecs.domain.Agent) PluginSettings(com.thoughtworks.gocd.elasticagent.ecs.domain.PluginSettings) Agents(com.thoughtworks.gocd.elasticagent.ecs.Agents)

Example 12 with Agent

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");
}
Also used : ShouldAssignWorkRequest(com.thoughtworks.gocd.elasticagent.ecs.requests.ShouldAssignWorkRequest) Agent(com.thoughtworks.gocd.elasticagent.ecs.domain.Agent) GoPluginApiResponse(com.thoughtworks.go.plugin.api.response.GoPluginApiResponse) Test(org.junit.jupiter.api.Test)

Aggregations

Agent (com.thoughtworks.gocd.elasticagent.ecs.domain.Agent)12 Test (org.junit.jupiter.api.Test)11 GoPluginApiResponse (com.thoughtworks.go.plugin.api.response.GoPluginApiResponse)3 Agents (com.thoughtworks.gocd.elasticagent.ecs.Agents)2 ClusterProfileProperties (com.thoughtworks.gocd.elasticagent.ecs.domain.ClusterProfileProperties)2 ShouldAssignWorkRequest (com.thoughtworks.gocd.elasticagent.ecs.requests.ShouldAssignWorkRequest)2 ElasticAgentProfileProperties (com.thoughtworks.gocd.elasticagent.ecs.domain.ElasticAgentProfileProperties)1 JobIdentifier (com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier)1 PluginSettings (com.thoughtworks.gocd.elasticagent.ecs.domain.PluginSettings)1 JobCompletionRequest (com.thoughtworks.gocd.elasticagent.ecs.requests.JobCompletionRequest)1 HashMap (java.util.HashMap)1 InOrder (org.mockito.InOrder)1