Search in sources :

Example 11 with Instance

use of com.google.api.services.notebooks.v1.model.Instance in project gocd-ecs-elastic-agent by gocd.

the class EligibleForTerminationPredicateTest method shouldReturnTrueWhenInstanceIsStoppedLongerThanTheTimeConfiguredInPluginSettings.

@ParameterizedTest
@EnumSource(Platform.class)
void shouldReturnTrueWhenInstanceIsStoppedLongerThanTheTimeConfiguredInPluginSettings(Platform platform) {
    final Clock.TestClock testClock = new Clock.TestClock();
    final Instance instance = instance("i-abcd123", STOPPED, platform.name()).withTags(new Tag(STOPPED_AT, String.valueOf(testClock.now().getMillis())));
    when(pluginSettings.terminateStoppedLinuxInstanceAfter()).thenReturn(Period.seconds(20));
    when(pluginSettings.terminateStoppedWindowsInstanceAfter()).thenReturn(Period.seconds(20));
    testClock.forward(Period.seconds(21));
    final boolean testResult = new EligibleForTerminationPredicate(pluginSettings, testClock).test(instance);
    assertThat(testResult).isTrue();
}
Also used : Instance(com.amazonaws.services.ec2.model.Instance) InstanceMother.linuxInstanceWithTag(com.thoughtworks.gocd.elasticagent.ecs.aws.InstanceMother.linuxInstanceWithTag) Tag(com.amazonaws.services.ec2.model.Tag) Clock(com.thoughtworks.gocd.elasticagent.ecs.Clock) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with Instance

use of com.google.api.services.notebooks.v1.model.Instance in project gocd-ecs-elastic-agent by gocd.

the class SpotInstanceEligibleForTerminationPredicateTest method shouldReturnFalseIfInstanceDoesNotHaveLastSeenIdleLabel.

@Test
void shouldReturnFalseIfInstanceDoesNotHaveLastSeenIdleLabel() {
    final Instance instance = linuxInstanceWithTag("i-abcd123", STOPPED, new Tag("Foo", "Bar"));
    final boolean testResult = new SpotInstanceEligibleForTerminationPredicate(null).test(instance);
    assertThat(testResult).isFalse();
}
Also used : Instance(com.amazonaws.services.ec2.model.Instance) Tag(com.amazonaws.services.ec2.model.Tag) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with Instance

use of com.google.api.services.notebooks.v1.model.Instance in project gocd-ecs-elastic-agent by gocd.

the class SpotInstanceEligibleForTerminationPredicateTest method shouldReturnFalseWhenTerminationTimeIsNotReached.

@ParameterizedTest
@EnumSource(Platform.class)
void shouldReturnFalseWhenTerminationTimeIsNotReached(Platform platform) {
    final Clock.TestClock testClock = new Clock.TestClock();
    final Instance instance = spotInstance("i-abcd123", RUNNING, platform.name()).withTags(new Tag(LAST_SEEN_IDLE, String.valueOf(testClock.now().getMillis())));
    when(pluginSettings.terminateIdleLinuxSpotInstanceAfter()).thenReturn(Period.seconds(20));
    when(pluginSettings.terminateIdleWindowsSpotInstanceAfter()).thenReturn(Period.seconds(20));
    testClock.forward(Period.seconds(19));
    final boolean testResult = new SpotInstanceEligibleForTerminationPredicate(pluginSettings, testClock).test(instance);
    assertThat(testResult).isFalse();
}
Also used : Instance(com.amazonaws.services.ec2.model.Instance) Tag(com.amazonaws.services.ec2.model.Tag) Clock(com.thoughtworks.gocd.elasticagent.ecs.Clock) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with Instance

use of com.google.api.services.notebooks.v1.model.Instance in project gocd-ecs-elastic-agent by gocd.

the class ServerPingRequestExecutorTest method shouldTerminateStoppedIdleInstance.

@ParameterizedTest
@EnumSource(Platform.class)
void shouldTerminateStoppedIdleInstance(Platform platform) throws Exception {
    final List<Instance> allInstances = Arrays.asList(instance("i-abcdxyz", RUNNING, platform.name()), instance("i-abcd123", STOPPED, platform.name()));
    final ContainerInstance stoppedContainerInstance = containerInstance("i-abcd123");
    final List<ContainerInstance> containerInstances = Arrays.asList(containerInstance("i-abcdxyz"), stoppedContainerInstance);
    when(containerInstanceHelper.getAllOnDemandInstances(clusterProfileProperties)).thenReturn(allInstances);
    when(containerInstanceHelper.onDemandContainerInstances(clusterProfileProperties)).thenReturn(containerInstances);
    when(pluginRequest.listAgents()).thenReturn(new Agents(new ArrayList<>()));
    executor.execute();
    verify(terminationOperation).execute(clusterProfileProperties, singletonList(stoppedContainerInstance));
}
Also used : ContainerInstance(com.amazonaws.services.ecs.model.ContainerInstance) ContainerInstance(com.amazonaws.services.ecs.model.ContainerInstance) ContainerInstanceMother.containerInstance(com.thoughtworks.gocd.elasticagent.ecs.aws.ContainerInstanceMother.containerInstance) Instance(com.amazonaws.services.ec2.model.Instance) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with Instance

use of com.google.api.services.notebooks.v1.model.Instance in project gocd-ecs-elastic-agent by gocd.

the class ClusterStatusReportExecutorTest method shouldGenerateHealthView.

@Test
void shouldGenerateHealthView() 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(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(), anyMap())).thenReturn("plugin_health_html");
    final GoPluginApiResponse response = clusterStatusReportExecutor.execute();
    final String expectedJSON = "{\n" + "\"view\" : \"plugin_health_html\"\n" + "}";
    assertThat(response.responseCode()).isEqualTo(200);
    JSONAssert.assertEquals(expectedJSON, response.responseBody(), true);
}
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) GoPluginApiResponse(com.thoughtworks.go.plugin.api.response.GoPluginApiResponse) Test(org.junit.jupiter.api.Test)

Aggregations

Instance (com.amazonaws.services.ec2.model.Instance)185 Reservation (com.amazonaws.services.ec2.model.Reservation)84 ArrayList (java.util.ArrayList)82 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)71 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)48 List (java.util.List)48 Tag (com.amazonaws.services.ec2.model.Tag)41 Test (org.junit.jupiter.api.Test)38 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)36 Map (java.util.Map)36 Collectors (java.util.stream.Collectors)32 HashMap (java.util.HashMap)26 Filter (com.amazonaws.services.ec2.model.Filter)25 Set (java.util.Set)23 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)22 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)20 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)18 InstanceState (com.amazonaws.services.ec2.model.InstanceState)18 Volume (com.amazonaws.services.ec2.model.Volume)18 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)18