Search in sources :

Example 11 with AWSResource

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

the class TestAWSResource method testParseFieldToValueMap.

@Test
public void testParseFieldToValueMap() throws Exception {
    Date now = new Date();
    Map<String, String> map = getTestingFieldValueMap(now, getTestingFields());
    AWSResource resource = AWSResource.parseFieldtoValueMap(map);
    Map<String, String> resourceFieldValueMap = resource.getFieldToValueMap();
    verifyMapsAreEqual(resourceFieldValueMap, map);
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 12 with AWSResource

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

the class TestRDSJanitorResourceTracker method testGetResourceNotFound.

@SuppressWarnings("unchecked")
@Test
public void testGetResourceNotFound() {
    ArrayList<AWSResource> resources = new ArrayList<>();
    TestRDSJanitorResourceTracker tracker = new TestRDSJanitorResourceTracker();
    when(tracker.getJdbcTemplate().query(Matchers.anyString(), Matchers.any(Object[].class), Matchers.any(RowMapper.class))).thenReturn(resources);
    Resource resource = tracker.getResource("id-2");
    Assert.assertNull(resource);
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.testng.annotations.Test)

Example 13 with AWSResource

use of com.netflix.simianarmy.aws.AWSResource 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 14 with AWSResource

use of com.netflix.simianarmy.aws.AWSResource 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 15 with AWSResource

use of com.netflix.simianarmy.aws.AWSResource 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)

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