Search in sources :

Example 1 with JobIdentifier

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

the class AgentStatusReportViewTest method shouldCreateAgentStatusReport.

@Test
void shouldCreateAgentStatusReport() throws ParseException, IOException, TemplateException {
    final JobIdentifier jobIdentifier = new JobIdentifier("up42", 1L, "foo", "up42_stage", "2", "up42_job", 2L);
    final ECSContainer container = containerWith("arn/container-instance-1", "alpine-container", "alpine", 100, 200, "13/05/2017 12:55:00", "13/05/2017 12:56:30", jobIdentifier);
    final PluginStatusReportViewBuilder statusReportViewBuilder = PluginStatusReportViewBuilder.instance();
    final Template template = statusReportViewBuilder.getTemplate("agent-status-report.template.ftlh");
    final String view = statusReportViewBuilder.build(template, container);
    assertView(view, container, jobIdentifier);
}
Also used : ECSContainer(com.thoughtworks.gocd.elasticagent.ecs.domain.ECSContainer) JobIdentifier(com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier) Template(freemarker.template.Template) Test(org.junit.jupiter.api.Test)

Example 2 with JobIdentifier

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

the class PluginStatusReportViewTest method shouldBuildStatusReportView.

@Test
void shouldBuildStatusReportView() throws Exception {
    final Cluster cluster = clusterWith("GoCD", 5, 10, 0);
    final ContainerInstance containerInstance = containerInstance("instance-id-1", "arn/container-instance-1", "ACTIVE", 8, 4096, 4, 1024);
    final Instance instance = instance("instance-id-1", C3Large, "ami-2dad3da", toDate("13/05/2017 12:50:20"));
    final ECSContainer alpineContainer = containerWith("arn/container-instance-1", "alpine-container", "alpine", 100, 200, "13/05/2017 12:55:00", "13/05/2017 12:56:30", new JobIdentifier("up42", 1L, "foo", "up42_stage", "2", "up42_job", 25632868237L));
    final ECSCluster ecsCluster = new ECSCluster(cluster, singletonList(containerInstance), singletonList(instance), singletonList(alpineContainer), 2, 3, 0, 0);
    Map<String, Object> dataModel = new HashMap<>();
    dataModel.put("cluster", ecsCluster);
    dataModel.put("errors", Collections.emptyList());
    dataModel.put("region", "us-east-2");
    final PluginStatusReportViewBuilder statusReportViewBuilder = PluginStatusReportViewBuilder.instance();
    final Template template = statusReportViewBuilder.getTemplate("status-report.template.ftlh");
    final String view = statusReportViewBuilder.build(template, dataModel);
    assertThat(view).contains("/go/admin/status_reports/com.thoughtworks.gocd.elastic-agent.ecs/agent/alpine-container?job_id=25632868237");
    assertView(view, ecsCluster);
}
Also used : ContainerInstance(com.amazonaws.services.ecs.model.ContainerInstance) ECSContainerInstance(com.thoughtworks.gocd.elasticagent.ecs.domain.ECSContainerInstance) ECSContainer(com.thoughtworks.gocd.elasticagent.ecs.domain.ECSContainer) ContainerInstance(com.amazonaws.services.ecs.model.ContainerInstance) ContainerInstanceMother.containerInstance(com.thoughtworks.gocd.elasticagent.ecs.aws.ContainerInstanceMother.containerInstance) Instance(com.amazonaws.services.ec2.model.Instance) ECSContainerInstance(com.thoughtworks.gocd.elasticagent.ecs.domain.ECSContainerInstance) ECSCluster(com.thoughtworks.gocd.elasticagent.ecs.domain.ECSCluster) Cluster(com.amazonaws.services.ecs.model.Cluster) JobIdentifier(com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier) ECSCluster(com.thoughtworks.gocd.elasticagent.ecs.domain.ECSCluster) Template(freemarker.template.Template) Test(org.junit.jupiter.api.Test)

Example 3 with JobIdentifier

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

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

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

JobIdentifier (com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier)9 Test (org.junit.jupiter.api.Test)8 ClusterProfileProperties (com.thoughtworks.gocd.elasticagent.ecs.domain.ClusterProfileProperties)5 ECSContainer (com.thoughtworks.gocd.elasticagent.ecs.domain.ECSContainer)4 Template (freemarker.template.Template)4 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 JobCompletionRequest (com.thoughtworks.gocd.elasticagent.ecs.requests.JobCompletionRequest)2 HashMap (java.util.HashMap)2 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 ECSTasks (com.thoughtworks.gocd.elasticagent.ecs.ECSTasks)1 PluginRequest (com.thoughtworks.gocd.elasticagent.ecs.PluginRequest)1 ContainerInstanceMother.containerInstance (com.thoughtworks.gocd.elasticagent.ecs.aws.ContainerInstanceMother.containerInstance)1 AWSModelMother.containerWith (com.thoughtworks.gocd.elasticagent.ecs.domain.AWSModelMother.containerWith)1 Agent (com.thoughtworks.gocd.elasticagent.ecs.domain.Agent)1 ConsoleLogAppender (com.thoughtworks.gocd.elasticagent.ecs.domain.ConsoleLogAppender)1