Search in sources :

Example 1 with ElasticAgentProfileProperties

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

the class ProfileValidateRequestExecutor method validate.

private ValidationResult validate(Map<String, String> configuration) {
    ElasticAgentProfileProperties elasticAgentProfileProperties = ElasticAgentProfileProperties.fromJson(GSON.toJson(configuration));
    ValidationResult validationResult = validateMetadata(configuration);
    validateReservedMemory(elasticAgentProfileProperties, validationResult);
    validateBindMounts(elasticAgentProfileProperties, validationResult);
    validateSpotInstanceConfiguration(elasticAgentProfileProperties, validationResult);
    return validationResult;
}
Also used : ElasticAgentProfileProperties(com.thoughtworks.gocd.elasticagent.ecs.domain.ElasticAgentProfileProperties)

Example 2 with ElasticAgentProfileProperties

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

the class ContainerDefinitionBuilder method build.

public ContainerDefinition build() {
    final ElasticAgentProfileProperties elasticAgentProfileProperties = request.elasticProfile();
    final Integer memoryReservation = elasticAgentProfileProperties.platform() == LINUX ? elasticAgentProfileProperties.getReservedMemory() : null;
    return new ContainerDefinition().withName(taskName).withImage(image(elasticAgentProfileProperties.getImage())).withMemory(elasticAgentProfileProperties.getMaxMemory()).withMemoryReservation(memoryReservation).withEnvironment(environmentFrom()).withDockerLabels(labelsFrom()).withCommand(elasticAgentProfileProperties.getCommand()).withCpu(elasticAgentProfileProperties.getCpu()).withPrivileged(elasticAgentProfileProperties.platform() != WINDOWS && elasticAgentProfileProperties.isPrivileged()).withLogConfiguration(pluginSettings.logConfiguration());
}
Also used : ContainerDefinition(com.amazonaws.services.ecs.model.ContainerDefinition) ElasticAgentProfileProperties(com.thoughtworks.gocd.elasticagent.ecs.domain.ElasticAgentProfileProperties)

Example 3 with ElasticAgentProfileProperties

use of com.thoughtworks.gocd.elasticagent.ecs.domain.ElasticAgentProfileProperties 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 4 with ElasticAgentProfileProperties

use of com.thoughtworks.gocd.elasticagent.ecs.domain.ElasticAgentProfileProperties 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 5 with ElasticAgentProfileProperties

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

Aggregations

ElasticAgentProfileProperties (com.thoughtworks.gocd.elasticagent.ecs.domain.ElasticAgentProfileProperties)6 ClusterProfileProperties (com.thoughtworks.gocd.elasticagent.ecs.domain.ClusterProfileProperties)3 JobIdentifier (com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier)3 Test (org.junit.jupiter.api.Test)3 ContainerDefinition (com.amazonaws.services.ecs.model.ContainerDefinition)2 GoPluginApiResponse (com.thoughtworks.go.plugin.api.response.GoPluginApiResponse)2 Agents (com.thoughtworks.gocd.elasticagent.ecs.Agents)2 JobCompletionRequest (com.thoughtworks.gocd.elasticagent.ecs.requests.JobCompletionRequest)2 Instance (com.amazonaws.services.ec2.model.Instance)1 ContainerInstance (com.amazonaws.services.ecs.model.ContainerInstance)1 LOG (com.thoughtworks.gocd.elasticagent.ecs.ECSElasticPlugin.LOG)1 ECSTasks (com.thoughtworks.gocd.elasticagent.ecs.ECSTasks)1 PluginRequest (com.thoughtworks.gocd.elasticagent.ecs.PluginRequest)1 ContainerInstanceHelper (com.thoughtworks.gocd.elasticagent.ecs.aws.ContainerInstanceHelper)1 EC2Config (com.thoughtworks.gocd.elasticagent.ecs.aws.EC2Config)1 ContainerInstanceMatcher (com.thoughtworks.gocd.elasticagent.ecs.aws.matcher.ContainerInstanceMatcher)1 InstanceMatcher (com.thoughtworks.gocd.elasticagent.ecs.aws.matcher.InstanceMatcher)1 Agent (com.thoughtworks.gocd.elasticagent.ecs.domain.Agent)1 ConsoleLogAppender (com.thoughtworks.gocd.elasticagent.ecs.domain.ConsoleLogAppender)1 PENDING (com.thoughtworks.gocd.elasticagent.ecs.domain.EC2InstanceState.PENDING)1