Search in sources :

Example 76 with AWSResource

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

the class TestSimpleDBJanitorResourceTracker method testAddResource.

@Test
public void testAddResource() {
    String id = "i-12345678901234567";
    AWSResourceType resourceType = AWSResourceType.INSTANCE;
    Resource.CleanupState state = Resource.CleanupState.MARKED;
    String description = "This is a test resource.";
    String ownerEmail = "owner@test.com";
    String region = "us-east-1";
    String terminationReason = "This is a test termination reason.";
    DateTime now = DateTime.now();
    Date expectedTerminationTime = new Date(now.plusDays(10).getMillis());
    Date markTime = new Date(now.getMillis());
    String fieldName = "fieldName123";
    String fieldValue = "fieldValue456";
    Resource resource = new AWSResource().withId(id).withResourceType(resourceType).withDescription(description).withOwnerEmail(ownerEmail).withRegion(region).withState(state).withTerminationReason(terminationReason).withExpectedTerminationTime(expectedTerminationTime).withMarkTime(markTime).withOptOutOfJanitor(false).setAdditionalField(fieldName, fieldValue);
    ArgumentCaptor<PutAttributesRequest> arg = ArgumentCaptor.forClass(PutAttributesRequest.class);
    TestSimpleDBJanitorResourceTracker tracker = new TestSimpleDBJanitorResourceTracker();
    tracker.addOrUpdate(resource);
    verify(tracker.sdbMock).putAttributes(arg.capture());
    PutAttributesRequest req = arg.getValue();
    Assert.assertEquals(req.getDomainName(), "DOMAIN");
    Assert.assertEquals(req.getItemName(), getSimpleDBItemName(resource));
    Map<String, String> map = new HashMap<String, String>();
    for (ReplaceableAttribute attr : req.getAttributes()) {
        map.put(attr.getName(), attr.getValue());
    }
    Assert.assertEquals(map.remove(AWSResource.FIELD_RESOURCE_ID), id);
    Assert.assertEquals(map.remove(AWSResource.FIELD_DESCRIPTION), description);
    Assert.assertEquals(map.remove(AWSResource.FIELD_EXPECTED_TERMINATION_TIME), AWSResource.DATE_FORMATTER.print(expectedTerminationTime.getTime()));
    Assert.assertEquals(map.remove(AWSResource.FIELD_MARK_TIME), AWSResource.DATE_FORMATTER.print(markTime.getTime()));
    Assert.assertEquals(map.remove(AWSResource.FIELD_REGION), region);
    Assert.assertEquals(map.remove(AWSResource.FIELD_OWNER_EMAIL), ownerEmail);
    Assert.assertEquals(map.remove(AWSResource.FIELD_RESOURCE_TYPE), resourceType.name());
    Assert.assertEquals(map.remove(AWSResource.FIELD_STATE), state.name());
    Assert.assertEquals(map.remove(AWSResource.FIELD_TERMINATION_REASON), terminationReason);
    Assert.assertEquals(map.remove(AWSResource.FIELD_OPT_OUT_OF_JANITOR), "false");
    Assert.assertEquals(map.remove(fieldName), fieldValue);
    Assert.assertEquals(map.size(), 0);
}
Also used : HashMap(java.util.HashMap) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) DateTime(org.joda.time.DateTime) Date(java.util.Date) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) AWSResourceType(com.netflix.simianarmy.aws.AWSResourceType) AWSResource(com.netflix.simianarmy.aws.AWSResource) PutAttributesRequest(com.amazonaws.services.simpledb.model.PutAttributesRequest) Test(org.testng.annotations.Test)

Example 77 with AWSResource

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

the class TestAWSResource method testFieldToValueMapWithNull.

/**
     * When all fields are null, the map returned is empty.
     */
@Test
public void testFieldToValueMapWithNull() {
    Resource resource = new AWSResource();
    Map<String, String> resourceFieldValueMap = resource.getFieldToValueMap();
    // The only value in the map is the boolean of opt out
    Assert.assertEquals(resourceFieldValueMap.size(), 1);
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) Test(org.testng.annotations.Test)

Example 78 with AWSResource

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

the class TestAWSResource method getTestingResource.

private Resource getTestingResource(Date now) {
    String id = "resourceId";
    Resource resource = new AWSResource().withId(id).withRegion("region").withResourceType(AWSResourceType.INSTANCE).withState(Resource.CleanupState.MARKED).withDescription("description").withExpectedTerminationTime(now).withActualTerminationTime(now).withLaunchTime(now).withMarkTime(now).withNnotificationTime(now).withOwnerEmail("ownerEmail").withTerminationReason("terminationReason").withOptOutOfJanitor(false);
    ((AWSResource) resource).setAWSResourceState("awsResourceState");
    for (Map.Entry<String, String> field : getTestingFields().entrySet()) {
        resource.setAdditionalField(field.getKey(), field.getValue());
    }
    for (int i = 1; i < 10; i++) {
        resource.setTag("tagKey_" + i, "tagValue_" + i);
    }
    return resource;
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) Map(java.util.Map) HashMap(java.util.HashMap)

Example 79 with AWSResource

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

the class TestOldEmptyASGRule method testEmptyASGWithLaunchConfigWithoutCreateTime.

@Test
public void testEmptyASGWithLaunchConfigWithoutCreateTime() {
    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();
    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) Test(org.testng.annotations.Test)

Example 80 with AWSResource

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

the class TestOldEmptyASGRule method testEmptyASGWithoutLaunchConfig.

@Test
public void testEmptyASGWithoutLaunchConfig() {
    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());
    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

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