use of com.thoughtworks.gocd.elasticagent.ecs.domain.ECSCluster in project gocd-ecs-elastic-agent by gocd.
the class ClusterStatusReportExecutor method execute.
@Override
public GoPluginApiResponse execute() throws IOException, TemplateException {
final Map<String, Object> dataModel = new HashMap<>();
try {
final ClusterProfileProperties clusterProfileProperties = request.clusterProfileProperties();
agentInstances.refreshAll(clusterProfileProperties);
if (clusterProfileProperties == null || !clusterProfileProperties.isConfigured()) {
throw new RuntimeException("Please configure the cluster profile properly before using the plugin.");
}
final Cluster cluster = helper.getCluster(clusterProfileProperties);
final List<ContainerInstance> containerInstances = new ArrayList<>();
final List<Instance> instances = new ArrayList<>();
final List<ECSContainer> ecsContainers = new ArrayList<>();
if (cluster.getRegisteredContainerInstancesCount() != 0) {
containerInstances.addAll(helper.getContainerInstances(clusterProfileProperties));
instances.addAll(helper.ec2InstancesFromContainerInstances(clusterProfileProperties, containerInstances));
ecsContainers.addAll(taskHelper.allRunningContainers(clusterProfileProperties));
}
dataModel.put("region", clusterProfileProperties.getRegion());
final ECSCluster ecsCluster = new ECSCluster(cluster, containerInstances, instances, ecsContainers, clusterProfileProperties.getMaxLinuxInstancesAllowed(), clusterProfileProperties.getMaxWindowsInstancesAllowed(), clusterProfileProperties.getMaxLinuxSpotInstanceAllowed(), clusterProfileProperties.getMaxWindowsSpotInstanceAllowed());
dataModel.put("cluster", ecsCluster);
eventStream.remove(EventFingerprint.forStatusReport());
} catch (Exception e) {
LOG.error("[status report] Error accessing ECS cluster details", e);
final String errorMessage = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
eventStream.update(Event.errorEvent(EventFingerprint.forStatusReport(), "Error accessing ECS cluster details", errorMessage));
}
addPluginVersionInformation(dataModel);
dataModel.put("errors", eventStream.allErrors());
dataModel.put("warnings", eventStream.allWarnings());
final Template template = pluginStatusReportViewBuilder.getTemplate("status-report.template.ftlh");
final String view = pluginStatusReportViewBuilder.build(template, dataModel);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("view", view);
return DefaultGoPluginApiResponse.success(jsonObject.toString());
}
use of com.thoughtworks.gocd.elasticagent.ecs.domain.ECSCluster 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.ECSCluster in project gocd-ecs-elastic-agent by gocd.
the class PluginStatusReportViewTest method shouldBuildViewWithoutContainerInstanceAndPrintNoRunningContainerInstanceMessage.
@Test
void shouldBuildViewWithoutContainerInstanceAndPrintNoRunningContainerInstanceMessage() throws Exception {
final Cluster cluster = clusterWith("GoCD", 0, 0, 0);
final ECSCluster ecsCluster = new ECSCluster(cluster, emptyList(), emptyList(), emptyList(), 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);
assertView(view, ecsCluster);
}
use of com.thoughtworks.gocd.elasticagent.ecs.domain.ECSCluster 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);
}
Aggregations