Search in sources :

Example 31 with Resource

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

the class AlwaysInvalidRule method testWithExclusionRuleMatch2.

@Test
void testWithExclusionRuleMatch2() {
    Resource resource = new AWSResource().withId("id");
    DateTime now = DateTime.now();
    BasicJanitorRuleEngine engine = new BasicJanitorRuleEngine().addExclusionRule(new AlwaysValidRule()).addRule(new AlwaysValidRule());
    Assert.assertTrue(engine.isValid(resource));
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 32 with Resource

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

the class AlwaysInvalidRule method testMixed.

@Test
public void testMixed() {
    Resource resource = new AWSResource().withId("id");
    DateTime now = DateTime.now();
    BasicJanitorRuleEngine engine = new BasicJanitorRuleEngine().addRule(new AlwaysValidRule()).addRule(new AlwaysInvalidRule(now, 1)).addRule(new AlwaysValidRule());
    Assert.assertFalse(engine.isValid(resource));
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 33 with Resource

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

the class AlwaysInvalidRule method testWithExclusionRuleNotMatch2.

@Test
void testWithExclusionRuleNotMatch2() {
    Resource resource = new AWSResource().withId("id");
    DateTime now = DateTime.now();
    BasicJanitorRuleEngine engine = new BasicJanitorRuleEngine().addExclusionRule(new AlwaysInvalidRule(now, 1)).addRule(new AlwaysValidRule());
    Assert.assertTrue(engine.isValid(resource));
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 34 with Resource

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

the class TestOldEmptyASGRule method testNonASGResource.

@Test
public void testNonASGResource() {
    Resource resource = new AWSResource().withId("i-12345678901234567").withResourceType(AWSResourceType.INSTANCE);
    OldEmptyASGRule rule = new OldEmptyASGRule(new TestMonkeyCalendar(), 3, 60, 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) Test(org.testng.annotations.Test)

Example 35 with Resource

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

the class TestOldEmptyASGRule method testEmptyASGWithObsoleteLaunchConfig.

@Test
public void testEmptyASGWithObsoleteLaunchConfig() {
    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.assertFalse(rule.isValid(resource));
    TestUtils.verifyTerminationTimeRough(resource, retentionDays, 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) TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) MonkeyCalendar(com.netflix.simianarmy.MonkeyCalendar) DateTime(org.joda.time.DateTime) 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