Search in sources :

Example 6 with JobIdentifier

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");
}
Also used : ECSContainer(com.thoughtworks.gocd.elasticagent.ecs.domain.ECSContainer) AWSModelMother.containerWith(com.thoughtworks.gocd.elasticagent.ecs.domain.AWSModelMother.containerWith) Date(java.util.Date) TemplateException(freemarker.template.TemplateException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) JobIdentifier(com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier) Test(org.junit.jupiter.api.Test) List(java.util.List) MessageFormat.format(java.text.MessageFormat.format) Collectors.toList(java.util.stream.Collectors.toList) Attribute(org.jsoup.nodes.Attribute) Document(org.jsoup.nodes.Document) Element(org.jsoup.nodes.Element) Jsoup(org.jsoup.Jsoup) Elements(org.jsoup.select.Elements) Template(freemarker.template.Template) ParseException(java.text.ParseException) Document(org.jsoup.nodes.Document)

Example 7 with JobIdentifier

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);
    }
}
Also used : ECSContainer(com.thoughtworks.gocd.elasticagent.ecs.domain.ECSContainer) JsonObject(com.google.gson.JsonObject) JobIdentifier(com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier) StatusReportGenerationException(com.thoughtworks.gocd.elasticagent.ecs.reports.StatusReportGenerationException) ServerRequestFailedException(com.thoughtworks.gocd.elasticagent.ecs.exceptions.ServerRequestFailedException) Template(freemarker.template.Template)

Example 8 with JobIdentifier

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);
}
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 JobIdentifier

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

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