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