use of com.netflix.simianarmy.Resource in project SimianArmy by Netflix.
the class TestOldDetachedVolumeRule method testAttachedVolume.
@Test
public void testAttachedVolume() {
int ageThreshold = 5;
DateTime now = DateTime.now();
Resource resource = new AWSResource().withId("vol-12345678901234567").withResourceType(AWSResourceType.EBS_VOLUME).withLaunchTime(new Date(now.minusDays(ageThreshold + 1).getMillis()));
((AWSResource) resource).setAWSResourceState("available");
String metaTag = VolumeTaggingMonkey.makeMetaTag("i-12345678901234567", "owner", null);
resource.setTag(JanitorMonkey.JANITOR_META_TAG, metaTag);
int retentionDays = 4;
OldDetachedVolumeRule rule = new OldDetachedVolumeRule(new TestMonkeyCalendar(), ageThreshold, retentionDays);
Assert.assertTrue(rule.isValid(resource));
Assert.assertNull(resource.getExpectedTerminationTime());
}
use of com.netflix.simianarmy.Resource in project SimianArmy by Netflix.
the class TestOldDetachedVolumeRule method testTaggedAsNotMark.
@Test
public void testTaggedAsNotMark() {
int ageThreshold = 5;
DateTime now = DateTime.now();
Resource resource = new AWSResource().withId("vol-12345678901234567").withResourceType(AWSResourceType.EBS_VOLUME).withLaunchTime(new Date(now.minusDays(ageThreshold + 1).getMillis()));
((AWSResource) resource).setAWSResourceState("available");
Date lastDetachTime = new Date(now.minusDays(ageThreshold + 1).getMillis());
String metaTag = VolumeTaggingMonkey.makeMetaTag(null, null, lastDetachTime);
resource.setTag(JanitorMonkey.JANITOR_META_TAG, metaTag);
int retentionDays = 4;
OldDetachedVolumeRule rule = new OldDetachedVolumeRule(new TestMonkeyCalendar(), ageThreshold, retentionDays);
resource.setTag(JanitorMonkey.JANITOR_TAG, "donotmark");
Assert.assertTrue(rule.isValid(resource));
Assert.assertNull(resource.getExpectedTerminationTime());
}
use of com.netflix.simianarmy.Resource in project SimianArmy by Netflix.
the class TestOldDetachedVolumeRule method testUnavailableVolume.
@Test
public void testUnavailableVolume() {
Resource resource = new AWSResource().withId("vol-12345678901234567").withResourceType(AWSResourceType.EBS_VOLUME);
((AWSResource) resource).setAWSResourceState("stopped");
OldDetachedVolumeRule rule = new OldDetachedVolumeRule(new TestMonkeyCalendar(), 0, 0);
Assert.assertTrue(rule.isValid(resource));
Assert.assertNull(resource.getExpectedTerminationTime());
}
use of com.netflix.simianarmy.Resource in project SimianArmy by Netflix.
the class TestOldDetachedVolumeRule method testResourceWithExpectedTerminationTimeSet.
@Test
public void testResourceWithExpectedTerminationTimeSet() {
DateTime now = DateTime.now();
Date oldTermDate = new Date(now.plusDays(10).getMillis());
String oldTermReason = "Foo";
int ageThreshold = 5;
Resource resource = new AWSResource().withId("vol-12345678901234567").withResourceType(AWSResourceType.EBS_VOLUME).withLaunchTime(new Date(now.minusDays(ageThreshold + 1).getMillis()));
((AWSResource) resource).setAWSResourceState("available");
Date lastDetachTime = new Date(now.minusDays(ageThreshold + 1).getMillis());
String metaTag = VolumeTaggingMonkey.makeMetaTag(null, null, lastDetachTime);
resource.setTag(JanitorMonkey.JANITOR_META_TAG, metaTag);
int retentionDays = 4;
OldDetachedVolumeRule rule = new OldDetachedVolumeRule(new TestMonkeyCalendar(), ageThreshold, retentionDays);
resource.setExpectedTerminationTime(oldTermDate);
resource.setTerminationReason(oldTermReason);
Assert.assertFalse(rule.isValid(resource));
Assert.assertEquals(oldTermDate, resource.getExpectedTerminationTime());
Assert.assertEquals(oldTermReason, resource.getTerminationReason());
}
use of com.netflix.simianarmy.Resource in project SimianArmy by Netflix.
the class RDSJanitorResourceTracker method getResource.
@Override
public Resource getResource(String resourceId, String region) {
Validate.notEmpty(resourceId);
Validate.notEmpty(region);
StringBuilder query = new StringBuilder();
query.append(String.format("select * from %s where resourceId=? and region=?", table));
LOGGER.debug(String.format("Query is '%s'", query));
List<Resource> resources = jdbcTemplate.query(query.toString(), new String[] { resourceId, region }, new RowMapper<Resource>() {
public Resource mapRow(ResultSet rs, int rowNum) throws SQLException {
return mapResource(rs);
}
});
Resource resource = null;
Validate.isTrue(resources.size() <= 1);
if (resources.size() == 0) {
LOGGER.info(String.format("Not found resource with id %s", resourceId));
} else {
resource = resources.get(0);
}
return resource;
}
Aggregations