Search in sources :

Example 6 with ClusterProfileProperties

use of com.thoughtworks.gocd.elasticagent.ecs.domain.ClusterProfileProperties 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)

Example 7 with ClusterProfileProperties

use of com.thoughtworks.gocd.elasticagent.ecs.domain.ClusterProfileProperties in project gocd-ecs-elastic-agent by gocd.

the class CreateAgentRequestExecutorTest method shouldAskECSTaskToCreateAnAgent.

@Test
void shouldAskECSTaskToCreateAnAgent() throws Exception {
    ClusterProfileProperties settings = mock(ClusterProfileProperties.class);
    CreateAgentRequest request = mock(CreateAgentRequest.class);
    when(request.clusterProfileProperties()).thenReturn(settings);
    when(request.getJobIdentifier()).thenReturn(new JobIdentifier("test-pipeline", 1L, "Test Pipeline", "test-stage", "1", "test-job", 100L));
    when(request.elasticProfile()).thenReturn(new ElasticAgentProfileProperties());
    ECSTasks agentInstances = mock(ECSTasks.class);
    PluginRequest pluginRequest = mock(PluginRequest.class);
    final EventStream eventStream = mock(EventStream.class);
    new CreateAgentRequestExecutor(request, agentInstances, pluginRequest, eventStream).execute();
    verify(agentInstances).create(eq(request), eq(settings), any(ConsoleLogAppender.class));
}
Also used : ClusterProfileProperties(com.thoughtworks.gocd.elasticagent.ecs.domain.ClusterProfileProperties) CreateAgentRequest(com.thoughtworks.gocd.elasticagent.ecs.requests.CreateAgentRequest) EventStream(com.thoughtworks.gocd.elasticagent.ecs.events.EventStream) JobIdentifier(com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier) ECSTasks(com.thoughtworks.gocd.elasticagent.ecs.ECSTasks) PluginRequest(com.thoughtworks.gocd.elasticagent.ecs.PluginRequest) ConsoleLogAppender(com.thoughtworks.gocd.elasticagent.ecs.domain.ConsoleLogAppender) ElasticAgentProfileProperties(com.thoughtworks.gocd.elasticagent.ecs.domain.ElasticAgentProfileProperties) Test(org.junit.jupiter.api.Test)

Example 8 with ClusterProfileProperties

use of com.thoughtworks.gocd.elasticagent.ecs.domain.ClusterProfileProperties in project gocd-ecs-elastic-agent by gocd.

the class AgentStatusReportRequestTest method shouldDeserializeFromJSON.

@Test
void shouldDeserializeFromJSON() {
    String json = "{\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" + "  \"cluster_profile_properties\": {\n" + "    \"GoServerUrl\": \"https://cd.server.com/go\", \n" + "    \"ClusterName\": \"deployment-cluster\"\n" + "  }\n" + "}";
    AgentStatusReportRequest request = AgentStatusReportRequest.fromJSON(json);
    JobIdentifier expectedJobIdentifier = new JobIdentifier("test-pipeline", 1L, "Test Pipeline", "test-stage", "1", "test-job", 100L);
    JobIdentifier actualJobIdentifier = request.jobIdentifier();
    assertThat(actualJobIdentifier).isEqualTo(expectedJobIdentifier);
    assertThat(request.getElasticAgentId()).isEqualTo("ea1");
    Map<String, String> clusterProfileConfigurations = new HashMap<>();
    clusterProfileConfigurations.put("GoServerUrl", "https://cd.server.com/go");
    clusterProfileConfigurations.put("ClusterName", "deployment-cluster");
    ClusterProfileProperties expectedClusterProfileProperties = ClusterProfileProperties.fromConfiguration(clusterProfileConfigurations);
    assertThat(request.clusterProfileProperties()).isEqualTo(expectedClusterProfileProperties);
}
Also used : ClusterProfileProperties(com.thoughtworks.gocd.elasticagent.ecs.domain.ClusterProfileProperties) HashMap(java.util.HashMap) JobIdentifier(com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier) Test(org.junit.jupiter.api.Test)

Example 9 with ClusterProfileProperties

use of com.thoughtworks.gocd.elasticagent.ecs.domain.ClusterProfileProperties in project gocd-ecs-elastic-agent by gocd.

the class CreateAgentRequestTest method shouldDeserializeFromJSON.

@Test
void shouldDeserializeFromJSON() {
    String json = "{\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" + "}";
    CreateAgentRequest request = CreateAgentRequest.fromJSON(json);
    assertThat(request.autoRegisterKey()).isEqualTo("secret-key");
    assertThat(request.environment()).isEqualTo("prod");
    assertThat(request.elasticProfile().getImage()).isEqualTo("value1");
    assertThat(request.elasticProfile().getMaxMemory()).isEqualTo(2048);
    Map<String, String> clusterProfileConfigurations = new HashMap<>();
    clusterProfileConfigurations.put("GoServerUrl", "https://cd.server.com/go");
    clusterProfileConfigurations.put("ClusterName", "deployment-cluster");
    ClusterProfileProperties expectedClusterProfileProperties = ClusterProfileProperties.fromConfiguration(clusterProfileConfigurations);
    assertThat(request.clusterProfileProperties()).isEqualTo(expectedClusterProfileProperties);
}
Also used : ClusterProfileProperties(com.thoughtworks.gocd.elasticagent.ecs.domain.ClusterProfileProperties) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 10 with ClusterProfileProperties

use of com.thoughtworks.gocd.elasticagent.ecs.domain.ClusterProfileProperties in project gocd-ecs-elastic-agent by gocd.

the class JobCompletionRequestTest method shouldDeserializeFromJSON.

@Test
public void shouldDeserializeFromJSON() {
    String json = "{\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" + "}";
    JobCompletionRequest request = JobCompletionRequest.fromJSON(json);
    JobIdentifier expectedJobIdentifier = new JobIdentifier("test-pipeline", 1L, "Test Pipeline", "test-stage", "1", "test-job", 100L);
    JobIdentifier actualJobIdentifier = request.jobIdentifier();
    assertThat(actualJobIdentifier).isEqualTo(expectedJobIdentifier);
    assertThat(request.getElasticAgentId()).isEqualTo("ea1");
    assertThat(request.elasticAgentProfileProperties().getImage()).isEqualTo("value1");
    assertThat(request.elasticAgentProfileProperties().getMaxMemory()).isEqualTo(2048);
    Map<String, String> clusterProfileConfigurations = new HashMap<>();
    clusterProfileConfigurations.put("GoServerUrl", "https://cd.server.com/go");
    clusterProfileConfigurations.put("ClusterName", "deployment-cluster");
    ClusterProfileProperties expectedClusterProfileProperties = ClusterProfileProperties.fromConfiguration(clusterProfileConfigurations);
    assertThat(request.clusterProfileProperties()).isEqualTo(expectedClusterProfileProperties);
}
Also used : ClusterProfileProperties(com.thoughtworks.gocd.elasticagent.ecs.domain.ClusterProfileProperties) HashMap(java.util.HashMap) JobIdentifier(com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier) Test(org.junit.jupiter.api.Test)

Aggregations

ClusterProfileProperties (com.thoughtworks.gocd.elasticagent.ecs.domain.ClusterProfileProperties)10 Test (org.junit.jupiter.api.Test)8 HashMap (java.util.HashMap)6 JobIdentifier (com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier)5 ElasticAgentProfileProperties (com.thoughtworks.gocd.elasticagent.ecs.domain.ElasticAgentProfileProperties)3 GoPluginApiResponse (com.thoughtworks.go.plugin.api.response.GoPluginApiResponse)2 Agents (com.thoughtworks.gocd.elasticagent.ecs.Agents)2 Agent (com.thoughtworks.gocd.elasticagent.ecs.domain.Agent)2 JobCompletionRequest (com.thoughtworks.gocd.elasticagent.ecs.requests.JobCompletionRequest)2 AmazonEC2Exception (com.amazonaws.services.ec2.model.AmazonEC2Exception)1 Instance (com.amazonaws.services.ec2.model.Instance)1 Cluster (com.amazonaws.services.ecs.model.Cluster)1 ContainerInstance (com.amazonaws.services.ecs.model.ContainerInstance)1 JsonObject (com.google.gson.JsonObject)1 UnhandledRequestTypeException (com.thoughtworks.go.plugin.api.exceptions.UnhandledRequestTypeException)1 DefaultGoPluginApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse)1 ECSTasks (com.thoughtworks.gocd.elasticagent.ecs.ECSTasks)1 PluginRequest (com.thoughtworks.gocd.elasticagent.ecs.PluginRequest)1 ConsoleLogAppender (com.thoughtworks.gocd.elasticagent.ecs.domain.ConsoleLogAppender)1 ECSCluster (com.thoughtworks.gocd.elasticagent.ecs.domain.ECSCluster)1