Search in sources :

Example 1 with JobCompletionRequest

use of com.thoughtworks.gocd.elasticagent.ecs.requests.JobCompletionRequest in project gocd-ecs-elastic-agent by gocd.

the class JobCompletionRequestExecutorTest method shouldTerminateElasticAgentOnJobCompletion.

@Test
public void shouldTerminateElasticAgentOnJobCompletion() throws Exception {
    JobIdentifier jobIdentifier = new JobIdentifier("test", 1L, "test", "test_stage", "1", "test_job", 100L);
    String elasticAgentId = "agent-1";
    ClusterProfileProperties clusterProfileProperties = new ClusterProfileProperties();
    JobCompletionRequest request = new JobCompletionRequest(elasticAgentId, jobIdentifier, new ElasticAgentProfileProperties(), clusterProfileProperties);
    JobCompletionRequestExecutor executor = new JobCompletionRequestExecutor(request, mockAgentInstances, mockPluginRequest);
    Agents agents = new Agents();
    agents.add(new Agent(elasticAgentId));
    when(mockPluginRequest.listAgents()).thenReturn(agents);
    GoPluginApiResponse response = executor.execute();
    InOrder inOrder = inOrder(mockPluginRequest, mockAgentInstances);
    inOrder.verify(mockPluginRequest).disableAgents(agentsArgumentCaptor.capture());
    inOrder.verify(mockAgentInstances).terminate(elasticAgentId, clusterProfileProperties);
    inOrder.verify(mockPluginRequest).deleteAgents(agentsArgumentCaptor.capture());
    List<Agent> agentsToDisabled = agentsArgumentCaptor.getValue();
    assertThat(1).isEqualTo(agentsToDisabled.size());
    assertThat(elasticAgentId).isEqualTo(agentsToDisabled.get(0).elasticAgentId());
    List<Agent> agentsToDelete = agentsArgumentCaptor.getValue();
    assertThat(agentsToDisabled).isEqualTo(agentsToDelete);
    assertThat(200).isEqualTo(response.responseCode());
    assertThat(response.responseBody().isEmpty()).isTrue();
}
Also used : ClusterProfileProperties(com.thoughtworks.gocd.elasticagent.ecs.domain.ClusterProfileProperties) Agent(com.thoughtworks.gocd.elasticagent.ecs.domain.Agent) InOrder(org.mockito.InOrder) Agents(com.thoughtworks.gocd.elasticagent.ecs.Agents) JobCompletionRequest(com.thoughtworks.gocd.elasticagent.ecs.requests.JobCompletionRequest) JobIdentifier(com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier) GoPluginApiResponse(com.thoughtworks.go.plugin.api.response.GoPluginApiResponse) ElasticAgentProfileProperties(com.thoughtworks.gocd.elasticagent.ecs.domain.ElasticAgentProfileProperties) Test(org.junit.jupiter.api.Test)

Example 2 with JobCompletionRequest

use of com.thoughtworks.gocd.elasticagent.ecs.requests.JobCompletionRequest in project gocd-ecs-elastic-agent by gocd.

the class ClusterProfilePropertiesTest method shouldGenerateSameUUIDAcrossRequests.

@Test
void shouldGenerateSameUUIDAcrossRequests() {
    String createAgentRequestJSON = "{\n" + "  \"auto_register_key\": \"secret-key\",\n" + "  \"elastic_agent_profile_properties\": {\n" + "    \"Image\": \"value1\",\n" + "    \"MaxMemory\": \"2G\",\n" + "    \"ReservedMemory\": \"150M\",\n" + "    \"TerminationPolicy\": \"\"\n" + "  },\n" + "  \"cluster_profile_properties\": {\n" + "    \"GoServerUrl\": \"https://cd.server.com/go\", \n" + "    \"ClusterName\": \"deployment-cluster\"\n" + "  },\n" + "  \"environment\": \"prod\"\n" + "}";
    String jobCompletionRequestJSON = "{\n" + "  \"elastic_agent_id\": \"ea1\",\n" + "  \"job_identifier\": {\n" + "    \"pipeline_name\": \"test-pipeline\",\n" + "    \"pipeline_counter\": 1,\n" + "    \"pipeline_label\": \"Test Pipeline\",\n" + "    \"stage_name\": \"test-stage\",\n" + "    \"stage_counter\": \"1\",\n" + "    \"job_name\": \"test-job\",\n" + "    \"job_id\": 100\n" + "  },\n" + "  \"elastic_agent_profile_properties\": {\n" + "    \"Image\": \"value1\",\n" + "    \"MaxMemory\": \"2G\",\n" + "    \"ReservedMemory\": \"150M\",\n" + "    \"TerminationPolicy\": \"\"\n" + "  },\n" + "  \"cluster_profile_properties\": {\n" + "    \"GoServerUrl\": \"https://cd.server.com/go\", \n" + "    \"ClusterName\": \"deployment-cluster\"\n" + "  }\n" + "}";
    CreateAgentRequest createAgentRequest = CreateAgentRequest.fromJSON(createAgentRequestJSON);
    String createAgentRequestUUID = createAgentRequest.clusterProfileProperties().uuid();
    JobCompletionRequest jobCompletionRequest = JobCompletionRequest.fromJSON(jobCompletionRequestJSON);
    String jobCompletionRequestUUID = jobCompletionRequest.clusterProfileProperties().uuid();
    assertThat(createAgentRequestUUID).isEqualTo(jobCompletionRequestUUID);
}
Also used : CreateAgentRequest(com.thoughtworks.gocd.elasticagent.ecs.requests.CreateAgentRequest) JobCompletionRequest(com.thoughtworks.gocd.elasticagent.ecs.requests.JobCompletionRequest) Test(org.junit.jupiter.api.Test)

Example 3 with JobCompletionRequest

use of com.thoughtworks.gocd.elasticagent.ecs.requests.JobCompletionRequest in project gocd-ecs-elastic-agent by gocd.

the class JobCompletionRequestExecutorTest method shouldSkipTerminatingANonExistingAgent.

@Test
void shouldSkipTerminatingANonExistingAgent() throws Exception {
    JobIdentifier jobIdentifier = new JobIdentifier("test", 1L, "test", "test_stage", "1", "test_job", 100L);
    String elasticAgentId = "agent-1";
    JobCompletionRequest request = new JobCompletionRequest(elasticAgentId, jobIdentifier, new ElasticAgentProfileProperties(), new ClusterProfileProperties());
    JobCompletionRequestExecutor executor = new JobCompletionRequestExecutor(request, mockAgentInstances, mockPluginRequest);
    when(mockPluginRequest.listAgents()).thenReturn(new Agents());
    GoPluginApiResponse response = executor.execute();
    verify(mockPluginRequest, never()).disableAgents(anyCollection());
    verify(mockPluginRequest, never()).deleteAgents(anyCollection());
    verifyNoInteractions(mockAgentInstances);
    assertThat(200).isEqualTo(response.responseCode());
}
Also used : ClusterProfileProperties(com.thoughtworks.gocd.elasticagent.ecs.domain.ClusterProfileProperties) Agents(com.thoughtworks.gocd.elasticagent.ecs.Agents) JobCompletionRequest(com.thoughtworks.gocd.elasticagent.ecs.requests.JobCompletionRequest) JobIdentifier(com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier) GoPluginApiResponse(com.thoughtworks.go.plugin.api.response.GoPluginApiResponse) ElasticAgentProfileProperties(com.thoughtworks.gocd.elasticagent.ecs.domain.ElasticAgentProfileProperties) Test(org.junit.jupiter.api.Test)

Aggregations

JobCompletionRequest (com.thoughtworks.gocd.elasticagent.ecs.requests.JobCompletionRequest)3 Test (org.junit.jupiter.api.Test)3 GoPluginApiResponse (com.thoughtworks.go.plugin.api.response.GoPluginApiResponse)2 Agents (com.thoughtworks.gocd.elasticagent.ecs.Agents)2 ClusterProfileProperties (com.thoughtworks.gocd.elasticagent.ecs.domain.ClusterProfileProperties)2 ElasticAgentProfileProperties (com.thoughtworks.gocd.elasticagent.ecs.domain.ElasticAgentProfileProperties)2 JobIdentifier (com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier)2 Agent (com.thoughtworks.gocd.elasticagent.ecs.domain.Agent)1 CreateAgentRequest (com.thoughtworks.gocd.elasticagent.ecs.requests.CreateAgentRequest)1 InOrder (org.mockito.InOrder)1