use of com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier in project gocd-ecs-elastic-agent by gocd.
the class AgentStatusReportViewTest method assertView.
private void assertView(String view, ECSContainer container, JobIdentifier jobIdentifier) {
final Document document = Jsoup.parse(view);
assertJobIdentifier(document, container.getName(), jobIdentifier);
assertThat(document.select(".sub_tabs_container .tabs li")).hasSize(3);
assertThat(document.select(".sub_tabs_container .tabs li").text()).isEqualTo("Details Environment Variables Log Configuration");
assertThat(document.select(".tab-content-outer .container-details li label").text()).isEqualTo("Name Hostname Container Arn Task name Image Container Instance Arn CPU Units Max Memory(MB) Min Memory(MB) Privileged Docker Command Created At Started At Last status");
final List<String> detailsProperties = document.select(".tab-content-outer .container-details li span").stream().map(e -> e.text()).collect(toList());
assertThat(detailsProperties).containsExactly(container.getName(), container.getHostname(), container.getContainerArn(), container.getTaskName(), container.getImage(), container.getContainerInstanceArn(), container.getCpu().toString(), container.getMemory().toString(), container.getMemoryReservation().toString(), Boolean.toString(container.isPrivileged()), container.getDockerCommand(), toDateTimeString(container.getCreatedAt()), toDateTimeString(container.getStartedAt()), container.getLastStatus());
assertThat(document.select(".tab-content-outer .container-environment-vars ul").text()).isEqualTo("ENV_FOO ENV_FOO_VALUE");
assertThat(document.select(".tab-content-outer .container-log-configuration ul").text()).isEqualTo("Log Driver awslogs Log Options log-group build-logs");
}
use of com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier in project gocd-ecs-elastic-agent by gocd.
the class AgentStatusReportExecutor method execute.
public GoPluginApiResponse execute() {
String elasticAgentId = request.getElasticAgentId();
JobIdentifier jobIdentifier = request.jobIdentifier();
LOG.info(String.format("[status-report] Generating status report for agent: %s with job: %s", elasticAgentId, jobIdentifier));
try {
agentInstances.refreshAll(request.clusterProfileProperties());
final ECSContainer container = getECSContainer(elasticAgentId, jobIdentifier);
final Template template = statusReportViewBuilder.getTemplate("agent-status-report.template.ftlh");
final String statusReportView = statusReportViewBuilder.build(template, container);
JsonObject responseJSON = new JsonObject();
responseJSON.addProperty("view", statusReportView);
return DefaultGoPluginApiResponse.success(responseJSON.toString());
} catch (Exception e) {
return StatusReportGenerationErrorHandler.handle(statusReportViewBuilder, e);
}
}
use of com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier 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);
}
use of com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier 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);
}
Aggregations