Search in sources :

Example 6 with ECSContainer

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

the class ClusterStatusReportExecutorTest method shouldFetchClusterInformation.

@Test
void shouldFetchClusterInformation() throws Exception {
    final List<ContainerInstance> containerInstances = Collections.emptyList();
    final List<Instance> ec2Instances = Collections.emptyList();
    final List<ECSContainer> ecsContainers = Collections.emptyList();
    final Cluster cluster = mock(Cluster.class);
    when(cluster.getRegisteredContainerInstancesCount()).thenReturn(2);
    when(request.clusterProfileProperties()).thenReturn(clusterProfileProperties);
    when(containerInstanceHelper.getCluster(clusterProfileProperties)).thenReturn(cluster);
    when(containerInstanceHelper.getContainerInstances(clusterProfileProperties)).thenReturn(containerInstances);
    when(containerInstanceHelper.ec2InstancesFromContainerInstances(clusterProfileProperties, containerInstances)).thenReturn(ec2Instances);
    when(taskHelper.allRunningContainers(clusterProfileProperties)).thenReturn(ecsContainers);
    when(pluginStatusReportViewBuilder.build(any(Template.class), anyMap())).thenReturn("plugin_health_html");
    clusterStatusReportExecutor.execute();
    verify(ecsTasks).refreshAll(clusterProfileProperties);
    verify(containerInstanceHelper).getCluster(clusterProfileProperties);
    verify(containerInstanceHelper).getContainerInstances(clusterProfileProperties);
    verify(containerInstanceHelper).ec2InstancesFromContainerInstances(eq(clusterProfileProperties), anyList());
    verify(taskHelper).allRunningContainers(clusterProfileProperties);
}
Also used : ContainerInstance(com.amazonaws.services.ecs.model.ContainerInstance) ECSContainer(com.thoughtworks.gocd.elasticagent.ecs.domain.ECSContainer) ContainerInstance(com.amazonaws.services.ecs.model.ContainerInstance) Instance(com.amazonaws.services.ec2.model.Instance) Cluster(com.amazonaws.services.ecs.model.Cluster) Template(freemarker.template.Template) Test(org.junit.jupiter.api.Test)

Example 7 with ECSContainer

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

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

the class PluginStatusReportViewTest method shouldBuildStatusReportViewWithDefaultValues.

@Test
void shouldBuildStatusReportViewWithDefaultValues() throws Exception {
    final Cluster cluster = clusterWith("GoCD", 0, 0, 0);
    final ContainerInstance containerInstance = containerInstance("instance-id", "arn/container-instance-1", "ACTIVE", 0, 0, 0, 0);
    final Instance instance = instance("instance-id", C3Large, "ami-23456", toDate("13/05/2017 12:50:20"));
    final ECSContainer alpineContainer = containerWith("arn/container-instance-1", "container-name", "alpine", 100, 200, "13/05/2017 12:55:20", null);
    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("maxAllowedInstances", 5);
    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);
    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) ECSCluster(com.thoughtworks.gocd.elasticagent.ecs.domain.ECSCluster) Template(freemarker.template.Template) Test(org.junit.jupiter.api.Test)

Example 9 with ECSContainer

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

Aggregations

ECSContainer (com.thoughtworks.gocd.elasticagent.ecs.domain.ECSContainer)9 Template (freemarker.template.Template)7 Test (org.junit.jupiter.api.Test)6 Instance (com.amazonaws.services.ec2.model.Instance)5 Cluster (com.amazonaws.services.ecs.model.Cluster)5 ContainerInstance (com.amazonaws.services.ecs.model.ContainerInstance)5 JobIdentifier (com.thoughtworks.gocd.elasticagent.ecs.domain.JobIdentifier)4 ECSCluster (com.thoughtworks.gocd.elasticagent.ecs.domain.ECSCluster)3 JsonObject (com.google.gson.JsonObject)2 ContainerInstanceMother.containerInstance (com.thoughtworks.gocd.elasticagent.ecs.aws.ContainerInstanceMother.containerInstance)2 ECSContainerInstance (com.thoughtworks.gocd.elasticagent.ecs.domain.ECSContainerInstance)2 TemplateException (freemarker.template.TemplateException)2 IOException (java.io.IOException)2 Element (org.jsoup.nodes.Element)2 Elements (org.jsoup.select.Elements)2 GoPluginApiResponse (com.thoughtworks.go.plugin.api.response.GoPluginApiResponse)1 AWSModelMother.containerWith (com.thoughtworks.gocd.elasticagent.ecs.domain.AWSModelMother.containerWith)1 ClusterProfileProperties (com.thoughtworks.gocd.elasticagent.ecs.domain.ClusterProfileProperties)1 ServerRequestFailedException (com.thoughtworks.gocd.elasticagent.ecs.exceptions.ServerRequestFailedException)1 StatusReportGenerationException (com.thoughtworks.gocd.elasticagent.ecs.reports.StatusReportGenerationException)1