Search in sources :

Example 21 with Resource

use of com.netflix.simianarmy.Resource in project SimianArmy by Netflix.

the class TestOldEmptyASGRule method testResourceWithExpectedTerminationTimeSet.

@Test
public void testResourceWithExpectedTerminationTimeSet() {
    Resource resource = new AWSResource().withId("asg1").withResourceType(AWSResourceType.ASG);
    resource.setAdditionalField(ASGJanitorCrawler.ASG_FIELD_MAX_SIZE, "0");
    int launchConfiguAgeThreshold = 60;
    MonkeyCalendar calendar = new TestMonkeyCalendar();
    DateTime now = new DateTime(calendar.now().getTimeInMillis());
    int retentionDays = 3;
    OldEmptyASGRule rule = new OldEmptyASGRule(calendar, launchConfiguAgeThreshold, retentionDays, new DummyASGInstanceValidator());
    Date oldTermDate = new Date(now.plusDays(10).getMillis());
    String oldTermReason = "Foo";
    resource.setExpectedTerminationTime(oldTermDate);
    resource.setTerminationReason(oldTermReason);
    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) TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) MonkeyCalendar(com.netflix.simianarmy.MonkeyCalendar) DateTime(org.joda.time.DateTime) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 22 with Resource

use of com.netflix.simianarmy.Resource in project SimianArmy by Netflix.

the class TestOldEmptyASGRule method testASGWithInstances.

@Test
public void testASGWithInstances() {
    Resource resource = new AWSResource().withId("asg1").withResourceType(AWSResourceType.ASG);
    resource.setAdditionalField(ASGJanitorCrawler.ASG_FIELD_LC_NAME, "launchConfig");
    resource.setAdditionalField(ASGJanitorCrawler.ASG_FIELD_MAX_SIZE, "2");
    resource.setAdditionalField(ASGJanitorCrawler.ASG_FIELD_INSTANCES, "123456789012345671,i-123456789012345672");
    int launchConfiguAgeThreshold = 60;
    MonkeyCalendar calendar = new TestMonkeyCalendar();
    DateTime now = new DateTime(calendar.now().getTimeInMillis());
    resource.setAdditionalField(ASGJanitorCrawler.ASG_FIELD_LC_CREATION_TIME, String.valueOf(now.minusDays(launchConfiguAgeThreshold + 1).getMillis()));
    int retentionDays = 3;
    OldEmptyASGRule rule = new OldEmptyASGRule(calendar, launchConfiguAgeThreshold, retentionDays, new DummyASGInstanceValidator());
    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) TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) MonkeyCalendar(com.netflix.simianarmy.MonkeyCalendar) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 23 with Resource

use of com.netflix.simianarmy.Resource in project SimianArmy by Netflix.

the class TestOldEmptyASGRule method testEmptyASGWithValidLaunchConfig.

@Test
public void testEmptyASGWithValidLaunchConfig() {
    Resource resource = new AWSResource().withId("asg1").withResourceType(AWSResourceType.ASG);
    resource.setAdditionalField(ASGJanitorCrawler.ASG_FIELD_LC_NAME, "launchConfig");
    resource.setAdditionalField(ASGJanitorCrawler.ASG_FIELD_MAX_SIZE, "0");
    int launchConfiguAgeThreshold = 60;
    MonkeyCalendar calendar = new TestMonkeyCalendar();
    DateTime now = new DateTime(calendar.now().getTimeInMillis());
    resource.setAdditionalField(ASGJanitorCrawler.ASG_FIELD_LC_CREATION_TIME, String.valueOf(now.minusDays(launchConfiguAgeThreshold - 1).getMillis()));
    int retentionDays = 3;
    OldEmptyASGRule rule = new OldEmptyASGRule(calendar, launchConfiguAgeThreshold, retentionDays, new DummyASGInstanceValidator());
    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) TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) MonkeyCalendar(com.netflix.simianarmy.MonkeyCalendar) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 24 with Resource

use of com.netflix.simianarmy.Resource in project SimianArmy by Netflix.

the class TestEBSSnapshotJanitorCrawler method testSnapshotsWithIds.

@Test
public void testSnapshotsWithIds() {
    Date startTime = new Date();
    List<Snapshot> snapshotList = createSnapshotList(startTime);
    String[] ids = { "snap-12345678901234567", "snap-12345678901234567" };
    EBSSnapshotJanitorCrawler crawler = new EBSSnapshotJanitorCrawler(createMockAWSClient(snapshotList, ids));
    List<Resource> resources = crawler.resources(ids);
    verifySnapshotList(resources, snapshotList, startTime);
}
Also used : Snapshot(com.amazonaws.services.ec2.model.Snapshot) Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 25 with Resource

use of com.netflix.simianarmy.Resource in project SimianArmy by Netflix.

the class TestELBJanitorCrawler method testElbsWithReferencedASGs.

@Test
public void testElbsWithReferencedASGs() {
    boolean includeInstances = true;
    boolean includeELbs = true;
    AWSClient client = createMockAWSClient();
    List<LoadBalancerDescription> elbs = createELBList(includeInstances);
    List<AutoScalingGroup> asgs = createASGList(includeELbs);
    addELBsToMock(client, elbs);
    addASGsToMock(client, asgs);
    ELBJanitorCrawler crawler = new ELBJanitorCrawler(client);
    List<Resource> resources = crawler.resources();
    verifyELBList(resources, elbs, 1);
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) Resource(com.netflix.simianarmy.Resource) AWSClient(com.netflix.simianarmy.client.aws.AWSClient) LoadBalancerDescription(com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription) Test(org.testng.annotations.Test)

Aggregations

Resource (com.netflix.simianarmy.Resource)145 AWSResource (com.netflix.simianarmy.aws.AWSResource)132 Test (org.testng.annotations.Test)110 TestMonkeyCalendar (com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar)64 DateTime (org.joda.time.DateTime)60 Date (java.util.Date)45 MonkeyCalendar (com.netflix.simianarmy.MonkeyCalendar)21 AWSClient (com.netflix.simianarmy.client.aws.AWSClient)18 JsonNode (org.codehaus.jackson.JsonNode)17 AWSResourceType (com.netflix.simianarmy.aws.AWSResourceType)11 BeforeTest (org.testng.annotations.BeforeTest)9 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)8 LoadBalancerDescription (com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription)6 HashSet (java.util.HashSet)6 AutoScalingInstanceDetails (com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails)5 Instance (com.amazonaws.services.ec2.model.Instance)5 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 RowMapper (org.springframework.jdbc.core.RowMapper)5 Snapshot (com.amazonaws.services.ec2.model.Snapshot)4