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);
}
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);
}
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();
}
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());
}
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));
}
Aggregations