Search in sources :

Example 86 with AWSResource

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

the class TestOrphanedELBRule method testELBWithInstancesNoASGs.

@Test
public void testELBWithInstancesNoASGs() {
    DateTime now = DateTime.now();
    Resource resource = new AWSResource().withId("test-elb").withResourceType(AWSResourceType.ELB).withOwnerEmail("owner@foo.com");
    resource.setAdditionalField("referencedASGCount", "0");
    resource.setAdditionalField("instanceCount", "4");
    OrphanedELBRule rule = new OrphanedELBRule(new TestMonkeyCalendar(), 7);
    Assert.assertTrue(rule.isValid(resource));
}
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) Test(org.testng.annotations.Test)

Example 87 with AWSResource

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

the class TestTagValueExclusionRule method testExcludeTaggedResourceAllNullTags.

@Test
public void testExcludeTaggedResourceAllNullTags() {
    Resource r1 = new AWSResource().withId("i-12345678901234567").withResourceType(AWSResourceType.INSTANCE).withOwnerEmail("owner@foo.com");
    r1.setTag("tag", null);
    r1.setTag("tag1", null);
    r1.setTag("tag2", null);
    TagValueExclusionRule rule = new TagValueExclusionRule(exclusionTags);
    Assert.assertFalse(rule.isValid(r1));
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 88 with AWSResource

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

the class TestTagValueExclusionRule method testExcludeTaggedResourceWithTagAndValueMatch2.

@Test
public void testExcludeTaggedResourceWithTagAndValueMatch2() {
    Resource r1 = new AWSResource().withId("i-12345678901234567").withResourceType(AWSResourceType.INSTANCE).withOwnerEmail("owner@foo.com");
    r1.setTag("tag", null);
    r1.setTag("tag1", "somethingelse");
    r1.setTag("tag2", "excludeme2");
    TagValueExclusionRule rule = new TagValueExclusionRule(exclusionTags);
    Assert.assertTrue(rule.isValid(r1));
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 89 with AWSResource

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

the class TestTagValueExclusionRule method testExcludeUntaggedResource.

@Test
public void testExcludeUntaggedResource() {
    Resource r1 = new AWSResource().withId("i-12345678901234567").withResourceType(AWSResourceType.INSTANCE).withOwnerEmail("owner@foo.com");
    TagValueExclusionRule rule = new TagValueExclusionRule(exclusionTags);
    Assert.assertFalse(rule.isValid(r1));
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 90 with AWSResource

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

the class TestUntaggedRule method testResourceWithExpectedTerminationTimeSet.

@Test
public void testResourceWithExpectedTerminationTimeSet() {
    DateTime now = DateTime.now();
    Date oldTermDate = new Date(now.plusDays(10).getMillis());
    String oldTermReason = "Foo";
    Resource resource = new AWSResource().withId("i-12345678901234567").withResourceType(AWSResourceType.INSTANCE).withExpectedTerminationTime(oldTermDate).withTerminationReason(oldTermReason);
    ((AWSResource) resource).setAWSResourceState("running");
    Set<String> tags = new HashSet<String>();
    tags.add("tag1");
    tags.add("tag2");
    int retentionDaysWithOwner = 4;
    int retentionDaysWithoutOwner = 8;
    UntaggedRule rule = new UntaggedRule(new TestMonkeyCalendar(), tags, 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) HashSet(java.util.HashSet) 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