Search in sources :

Example 1 with AWSResourceType

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

the class TestASGJanitorCrawler method testInstancesWithResourceType.

@Test
public void testInstancesWithResourceType() {
    List<AutoScalingGroup> asgList = createASGList();
    AWSClient awsMock = createMockAWSClient(asgList);
    ASGJanitorCrawler crawler = new ASGJanitorCrawler(awsMock);
    for (AWSResourceType resourceType : AWSResourceType.values()) {
        List<Resource> resources = crawler.resources(resourceType);
        if (resourceType == AWSResourceType.ASG) {
            verifyASGList(resources, asgList);
        } else {
            Assert.assertTrue(resources.isEmpty());
        }
    }
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) AWSResourceType(com.netflix.simianarmy.aws.AWSResourceType) Resource(com.netflix.simianarmy.Resource) AWSClient(com.netflix.simianarmy.client.aws.AWSClient) Test(org.testng.annotations.Test)

Example 2 with AWSResourceType

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

the class TestInstanceJanitorCrawler method testInstancesWithResourceType.

@Test
public void testInstancesWithResourceType() {
    List<AutoScalingInstanceDetails> instanceDetailsList = createInstanceDetailsList();
    List<Instance> instanceList = createInstanceList();
    AWSClient awsMock = createMockAWSClient(instanceDetailsList, instanceList);
    InstanceJanitorCrawler crawler = new InstanceJanitorCrawler(awsMock);
    for (AWSResourceType resourceType : AWSResourceType.values()) {
        List<Resource> resources = crawler.resources(resourceType);
        if (resourceType == AWSResourceType.INSTANCE) {
            verifyInstanceList(resources, instanceDetailsList);
        } else {
            Assert.assertTrue(resources.isEmpty());
        }
    }
}
Also used : Instance(com.amazonaws.services.ec2.model.Instance) AWSResourceType(com.netflix.simianarmy.aws.AWSResourceType) Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) AutoScalingInstanceDetails(com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails) AWSClient(com.netflix.simianarmy.client.aws.AWSClient) Test(org.testng.annotations.Test)

Example 3 with AWSResourceType

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

the class TestRDSJanitorResourceTracker method testGetResource.

@SuppressWarnings("unchecked")
@Test
public void testGetResource() {
    String id1 = "id-1";
    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";
    AWSResource result1 = mkResource(id1, resourceType, state, description, ownerEmail, region, terminationReason, expectedTerminationTime, markTime, false, fieldName, fieldValue);
    ArrayList<AWSResource> resources = new ArrayList<>();
    resources.add(result1);
    TestRDSJanitorResourceTracker tracker = new TestRDSJanitorResourceTracker();
    when(tracker.getJdbcTemplate().query(Matchers.anyString(), Matchers.any(Object[].class), Matchers.any(RowMapper.class))).thenReturn(resources);
    Resource resource = tracker.getResource(id1);
    ArrayList<Resource> returnResources = new ArrayList<>();
    returnResources.add(resource);
    verifyResources(returnResources, id1, null, resourceType, state, description, ownerEmail, region, terminationReason, expectedTerminationTime, markTime, fieldName, fieldValue);
}
Also used : AWSResourceType(com.netflix.simianarmy.aws.AWSResourceType) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) DateTime(org.joda.time.DateTime) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.testng.annotations.Test)

Example 4 with AWSResourceType

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

the class TestRDSJanitorResourceTracker method testUpdateResource.

@SuppressWarnings("unchecked")
@Test
public void testUpdateResource() {
    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);
    // mock the select query that is issued to see if the record already exists
    ArrayList<Resource> resources = new ArrayList<>();
    resources.add(resource);
    TestRDSJanitorResourceTracker tracker = new TestRDSJanitorResourceTracker();
    when(tracker.getJdbcTemplate().query(Matchers.anyString(), Matchers.any(Object[].class), Matchers.any(RowMapper.class))).thenReturn(resources);
    // update the ownerEmail
    ownerEmail = "owner2@test.com";
    Resource newResource = 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<Object> objCap = ArgumentCaptor.forClass(Object.class);
    ArgumentCaptor<String> sqlCap = ArgumentCaptor.forClass(String.class);
    when(tracker.getJdbcTemplate().update(sqlCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture())).thenReturn(1);
    tracker.addOrUpdate(newResource);
    List<Object> args = objCap.getAllValues();
    Assert.assertEquals(sqlCap.getValue(), "update janitortable set resourceType=?,region=?,ownerEmail=?,description=?,state=?,terminationReason=?,expectedTerminationTime=?,actualTerminationTime=?,notificationTime=?,launchTime=?,markTime=?,optOutOfJanitor=?,additionalFields=? where resourceId=? and region=?");
    Assert.assertEquals(args.size(), 15);
    Assert.assertEquals(args.get(0).toString(), AWSResourceType.INSTANCE.toString());
    Assert.assertEquals(args.get(1).toString(), region);
    Assert.assertEquals(args.get(2).toString(), ownerEmail);
    Assert.assertEquals(args.get(3).toString(), description);
    Assert.assertEquals(args.get(4).toString(), state.toString());
    Assert.assertEquals(args.get(5).toString(), terminationReason);
    Assert.assertEquals(args.get(6).toString(), expectedTerminationTime.getTime() + "");
    Assert.assertEquals(args.get(7).toString(), "0");
    Assert.assertEquals(args.get(8).toString(), "0");
    Assert.assertEquals(args.get(9).toString(), "0");
    Assert.assertEquals(args.get(10).toString(), markTime.getTime() + "");
    Assert.assertEquals(args.get(11).toString(), "false");
    Assert.assertEquals(args.get(12).toString(), "{\"fieldName123\":\"fieldValue456\"}");
    Assert.assertEquals(args.get(13).toString(), id);
    Assert.assertEquals(args.get(14).toString(), region);
}
Also used : Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) DateTime(org.joda.time.DateTime) AWSResourceType(com.netflix.simianarmy.aws.AWSResourceType) AWSResource(com.netflix.simianarmy.aws.AWSResource) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.testng.annotations.Test)

Example 5 with AWSResourceType

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

the class TestRDSJanitorResourceTracker method testInsertNewResource.

@SuppressWarnings("unchecked")
@Test
public void testInsertNewResource() {
    // mock the select query that is issued to see if the record already exists
    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);
    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<Object> objCap = ArgumentCaptor.forClass(Object.class);
    ArgumentCaptor<String> sqlCap = ArgumentCaptor.forClass(String.class);
    when(tracker.getJdbcTemplate().update(sqlCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture())).thenReturn(1);
    tracker.addOrUpdate(resource);
    List<Object> args = objCap.getAllValues();
    Assert.assertEquals(sqlCap.getValue(), "insert into janitortable (resourceId,resourceType,region,ownerEmail,description,state,terminationReason,expectedTerminationTime,actualTerminationTime,notificationTime,launchTime,markTime,optOutOfJanitor,additionalFields) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
    Assert.assertEquals(args.size(), 14);
    Assert.assertEquals(args.get(0).toString(), id);
    Assert.assertEquals(args.get(1).toString(), AWSResourceType.INSTANCE.toString());
    Assert.assertEquals(args.get(2).toString(), region);
    Assert.assertEquals(args.get(3).toString(), ownerEmail);
    Assert.assertEquals(args.get(4).toString(), description);
    Assert.assertEquals(args.get(5).toString(), state.toString());
    Assert.assertEquals(args.get(6).toString(), terminationReason);
    Assert.assertEquals(args.get(7).toString(), expectedTerminationTime.getTime() + "");
    Assert.assertEquals(args.get(8).toString(), "0");
    Assert.assertEquals(args.get(9).toString(), "0");
    Assert.assertEquals(args.get(10).toString(), "0");
    Assert.assertEquals(args.get(11).toString(), markTime.getTime() + "");
    Assert.assertEquals(args.get(12).toString(), "false");
    Assert.assertEquals(args.get(13).toString(), "{\"fieldName123\":\"fieldValue456\"}");
}
Also used : Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) DateTime(org.joda.time.DateTime) AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResourceType(com.netflix.simianarmy.aws.AWSResourceType) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.testng.annotations.Test)

Aggregations

Resource (com.netflix.simianarmy.Resource)11 AWSResourceType (com.netflix.simianarmy.aws.AWSResourceType)11 Test (org.testng.annotations.Test)11 AWSResource (com.netflix.simianarmy.aws.AWSResource)9 DateTime (org.joda.time.DateTime)6 Date (java.util.Date)4 RowMapper (org.springframework.jdbc.core.RowMapper)4 AWSClient (com.netflix.simianarmy.client.aws.AWSClient)2 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)1 AutoScalingInstanceDetails (com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails)1 LaunchConfiguration (com.amazonaws.services.autoscaling.model.LaunchConfiguration)1 Instance (com.amazonaws.services.ec2.model.Instance)1 Snapshot (com.amazonaws.services.ec2.model.Snapshot)1 Volume (com.amazonaws.services.ec2.model.Volume)1 PutAttributesRequest (com.amazonaws.services.simpledb.model.PutAttributesRequest)1 ReplaceableAttribute (com.amazonaws.services.simpledb.model.ReplaceableAttribute)1 SelectRequest (com.amazonaws.services.simpledb.model.SelectRequest)1 SelectResult (com.amazonaws.services.simpledb.model.SelectResult)1 HashMap (java.util.HashMap)1