Search in sources :

Example 36 with AWSResource

use of com.netflix.simianarmy.aws.AWSResource in project SimianArmy by Netflix.

the class TestOrphanedInstanceRule method testOrphanedInstancesWithLaunchTimeNotExpires.

@Test
public void testOrphanedInstancesWithLaunchTimeNotExpires() {
    int ageThreshold = 5;
    DateTime now = DateTime.now();
    Resource resource = new AWSResource().withId("i-12345678901234567").withResourceType(AWSResourceType.INSTANCE).withLaunchTime(new Date(now.minusDays(ageThreshold - 1).getMillis()));
    ((AWSResource) resource).setAWSResourceState("running");
    int retentionDaysWithOwner = 4;
    int retentionDaysWithoutOwner = 8;
    OrphanedInstanceRule rule = new OrphanedInstanceRule(new TestMonkeyCalendar(), ageThreshold, retentionDaysWithOwner, retentionDaysWithoutOwner);
    Assert.assertTrue(rule.isValid(resource));
    Assert.assertNull(resource.getExpectedTerminationTime());
}
Also used : TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) DateTime(org.joda.time.DateTime) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 37 with AWSResource

use of com.netflix.simianarmy.aws.AWSResource in project SimianArmy by Netflix.

the class TestOrphanedInstanceRule method testOrphanedInstancesWithoutOwner.

@Test
public void testOrphanedInstancesWithoutOwner() {
    int ageThreshold = 5;
    DateTime now = DateTime.now();
    Resource resource = new AWSResource().withId("i-12345678901234567").withResourceType(AWSResourceType.INSTANCE).withLaunchTime(new Date(now.minusDays(ageThreshold + 1).getMillis()));
    ((AWSResource) resource).setAWSResourceState("running");
    int retentionDaysWithOwner = 4;
    int retentionDaysWithoutOwner = 8;
    OrphanedInstanceRule rule = new OrphanedInstanceRule(new TestMonkeyCalendar(), ageThreshold, retentionDaysWithOwner, retentionDaysWithoutOwner);
    Assert.assertFalse(rule.isValid(resource));
    TestUtils.verifyTerminationTimeRough(resource, retentionDaysWithoutOwner, now);
}
Also used : TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) DateTime(org.joda.time.DateTime) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 38 with AWSResource

use of com.netflix.simianarmy.aws.AWSResource in project SimianArmy by Netflix.

the class TestOrphanedInstanceRule method testNonInstanceResource.

@Test
public void testNonInstanceResource() {
    Resource resource = new AWSResource().withId("asg1").withResourceType(AWSResourceType.ASG);
    ((AWSResource) resource).setAWSResourceState("running");
    OrphanedInstanceRule rule = new OrphanedInstanceRule(new TestMonkeyCalendar(), 0, 0, 0);
    Assert.assertTrue(rule.isValid(resource));
    Assert.assertNull(resource.getExpectedTerminationTime());
}
Also used : TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) Test(org.testng.annotations.Test)

Example 39 with AWSResource

use of com.netflix.simianarmy.aws.AWSResource in project SimianArmy by Netflix.

the class TestOrphanedInstanceRule method testResourceWithExpectedTerminationTimeSet.

@Test
public void testResourceWithExpectedTerminationTimeSet() {
    DateTime now = DateTime.now();
    Date oldTermDate = new Date(now.plusDays(10).getMillis());
    String oldTermReason = "Foo";
    int ageThreshold = 5;
    Resource resource = new AWSResource().withId("i-12345678901234567").withResourceType(AWSResourceType.INSTANCE).withLaunchTime(new Date(now.minusDays(ageThreshold + 1).getMillis())).withExpectedTerminationTime(oldTermDate).withTerminationReason(oldTermReason);
    ((AWSResource) resource).setAWSResourceState("running");
    int retentionDaysWithOwner = 4;
    int retentionDaysWithoutOwner = 8;
    OrphanedInstanceRule rule = new OrphanedInstanceRule(new TestMonkeyCalendar(), ageThreshold, retentionDaysWithOwner, retentionDaysWithoutOwner);
    Assert.assertFalse(rule.isValid(resource));
    Assert.assertEquals(oldTermDate, resource.getExpectedTerminationTime());
    Assert.assertEquals(oldTermReason, resource.getTerminationReason());
}
Also used : TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) DateTime(org.joda.time.DateTime) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 40 with AWSResource

use of com.netflix.simianarmy.aws.AWSResource in project SimianArmy by Netflix.

the class TestOldUnusedLaunchConfigRule method testNonLaunchConfigResource.

@Test
public void testNonLaunchConfigResource() {
    Resource resource = new AWSResource().withId("i-12345678901234567").withResourceType(AWSResourceType.INSTANCE);
    OldUnusedLaunchConfigRule rule = new OldUnusedLaunchConfigRule(new TestMonkeyCalendar(), 3, 60);
    Assert.assertTrue(rule.isValid(resource));
    Assert.assertNull(resource.getExpectedTerminationTime());
}
Also used : TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) Test(org.testng.annotations.Test)

Aggregations

AWSResource (com.netflix.simianarmy.aws.AWSResource)109 Resource (com.netflix.simianarmy.Resource)102 Test (org.testng.annotations.Test)89 TestMonkeyCalendar (com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar)64 DateTime (org.joda.time.DateTime)63 Date (java.util.Date)41 MonkeyCalendar (com.netflix.simianarmy.MonkeyCalendar)21 BeforeTest (org.testng.annotations.BeforeTest)9 JsonNode (org.codehaus.jackson.JsonNode)7 AWSClient (com.netflix.simianarmy.client.aws.AWSClient)6 AWSResourceType (com.netflix.simianarmy.aws.AWSResourceType)5 HashSet (java.util.HashSet)5 RowMapper (org.springframework.jdbc.core.RowMapper)5 LinkedList (java.util.LinkedList)4 Tag (com.amazonaws.services.ec2.model.Tag)3 HashMap (java.util.HashMap)3 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)2 LaunchConfiguration (com.amazonaws.services.autoscaling.model.LaunchConfiguration)2 AutoScalingInstanceDetails (com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails)1 Instance (com.amazonaws.services.autoscaling.model.Instance)1