@Test public void cleanupOldInstanceSnapshots () { DBSnapshot dbSnapshot1 = new DBSnapshot().withDBSnapshotIdentifier("ChaosSnapshot-instance-1970-01-01T01-02-03Z"); DBSnapshot dbSnapshot2 = new DBSnapshot().withDBSnapshotIdentifier("ChaosSnapshot-instance-2199-01-01T01-02-03Z"); DBSnapshot dbSnapshot3 = new DBSnapshot().withDBSnapshotIdentifier("RegularSnapshot-instance-1970-01-01T01-02-03Z"); DescribeDBSnapshotsResult describeDBSnapshotsResult = Mockito.mock(DescribeDBSnapshotsResult.class); doReturn(Arrays.asList(dbSnapshot1, dbSnapshot2, dbSnapshot3), Collections.singletonList(dbSnapshot2), Collections .singletonList(dbSnapshot3)).when(describeDBSnapshotsResult).getDBSnapshots(); doReturn(describeDBSnapshotsResult).when(amazonRDS).describeDBSnapshots(); doNothing().when(awsRDSPlatform).deleteInstanceSnapshot(any()); awsRDSPlatform.cleanupOldInstanceSnapshots(60); verify(awsRDSPlatform, times(1)).deleteInstanceSnapshot(dbSnapshot1); reset(awsRDSPlatform); awsRDSPlatform.cleanupOldInstanceSnapshots(60); verify(awsRDSPlatform, never()).deleteInstanceSnapshot(any()); reset(awsRDSPlatform); awsRDSPlatform.cleanupOldInstanceSnapshots(60); verify(awsRDSPlatform, never()).deleteInstanceSnapshot(any()); }
void cleanupOldInstanceSnapshots (int olderThanMinutes) { amazonRDS.describeDBSnapshots() .getDBSnapshots() .stream() .filter(dbSnapshot -> AwsRDSUtils.isChaosSnapshot(dbSnapshot.getDBSnapshotIdentifier())) .filter(dbSnapshot -> snapshotIsOlderThan(dbSnapshot.getDBSnapshotIdentifier(), olderThanMinutes)) .peek(dbSnapshot -> log.info("Deleting instance snapshot {} since it is out of date", v("dbSnapshot", dbSnapshot))) .parallel() .forEach(this::deleteInstanceSnapshot); }
AwsRDSPlatform extends Platform { void cleanupOldInstanceSnapshots (int olderThanMinutes) { amazonRDS.describeDBSnapshots() .getDBSnapshots() .stream() .filter(dbSnapshot -> AwsRDSUtils.isChaosSnapshot(dbSnapshot.getDBSnapshotIdentifier())) .filter(dbSnapshot -> snapshotIsOlderThan(dbSnapshot.getDBSnapshotIdentifier(), olderThanMinutes)) .peek(dbSnapshot -> log.info("Deleting instance snapshot {} since it is out of date", v("dbSnapshot", dbSnapshot))) .parallel() .forEach(this::deleteInstanceSnapshot); } }
AwsRDSPlatform extends Platform { void cleanupOldInstanceSnapshots (int olderThanMinutes) { amazonRDS.describeDBSnapshots() .getDBSnapshots() .stream() .filter(dbSnapshot -> AwsRDSUtils.isChaosSnapshot(dbSnapshot.getDBSnapshotIdentifier())) .filter(dbSnapshot -> snapshotIsOlderThan(dbSnapshot.getDBSnapshotIdentifier(), olderThanMinutes)) .peek(dbSnapshot -> log.info("Deleting instance snapshot {} since it is out of date", v("dbSnapshot", dbSnapshot))) .parallel() .forEach(this::deleteInstanceSnapshot); } @Autowired  AwsRDSPlatform();   AwsRDSPlatform(AmazonRDS amazonRDS, AmazonEC2 amazonEC2); }
AwsRDSPlatform extends Platform { void cleanupOldInstanceSnapshots (int olderThanMinutes) { amazonRDS.describeDBSnapshots() .getDBSnapshots() .stream() .filter(dbSnapshot -> AwsRDSUtils.isChaosSnapshot(dbSnapshot.getDBSnapshotIdentifier())) .filter(dbSnapshot -> snapshotIsOlderThan(dbSnapshot.getDBSnapshotIdentifier(), olderThanMinutes)) .peek(dbSnapshot -> log.info("Deleting instance snapshot {} since it is out of date", v("dbSnapshot", dbSnapshot))) .parallel() .forEach(this::deleteInstanceSnapshot); } @Autowired  AwsRDSPlatform();   AwsRDSPlatform(AmazonRDS amazonRDS, AmazonEC2 amazonEC2); Map<String, String> getVpcToSecurityGroupMap(); @Override ApiStatus getApiStatus(); @Override PlatformLevel getPlatformLevel(); @Override PlatformHealth getPlatformHealth(); @Override List<Container> generateExperimentRoster(); @Override boolean isContainerRecycled(Container container); Map<String, String> getFilter(); void setFilter(Map<String, String> filter); void failoverCluster(String dbClusterIdentifier); void restartInstance(String... dbInstanceIdentifiers); Set<String> getClusterInstances(String dbClusterIdentifier); ContainerHealth getInstanceStatus(String... dbInstanceIdentifiers); void setVpcSecurityGroupIds(String dbInstanceIdentifier, String vpcSecurityGroupId); void setVpcSecurityGroupIds(String dbInstanceIdentifier, Collection<String> vpcSecurityGroupIds); ContainerHealth checkVpcSecurityGroupIds(String dbInstanceIdentifier, Collection<String> vpcSecurityGroupIds); Collection<String> getVpcSecurityGroupIds(String dbInstanceIdentifier); String getChaosSecurityGroup(String dbInstanceIdentifier); DBSnapshot snapshotDBInstance(String dbInstanceIdentifier); DBClusterSnapshot snapshotDBCluster(String dbClusterIdentifier); void deleteInstanceSnapshot(DBSnapshot dbSnapshot); void deleteClusterSnapshot(DBClusterSnapshot dbClusterSnapshot); boolean isInstanceSnapshotRunning(String dbInstanceIdentifier); boolean isClusterSnapshotRunning(String dbClusterIdentifier); }
AwsRDSPlatform extends Platform { void cleanupOldInstanceSnapshots (int olderThanMinutes) { amazonRDS.describeDBSnapshots() .getDBSnapshots() .stream() .filter(dbSnapshot -> AwsRDSUtils.isChaosSnapshot(dbSnapshot.getDBSnapshotIdentifier())) .filter(dbSnapshot -> snapshotIsOlderThan(dbSnapshot.getDBSnapshotIdentifier(), olderThanMinutes)) .peek(dbSnapshot -> log.info("Deleting instance snapshot {} since it is out of date", v("dbSnapshot", dbSnapshot))) .parallel() .forEach(this::deleteInstanceSnapshot); } @Autowired  AwsRDSPlatform();   AwsRDSPlatform(AmazonRDS amazonRDS, AmazonEC2 amazonEC2); Map<String, String> getVpcToSecurityGroupMap(); @Override ApiStatus getApiStatus(); @Override PlatformLevel getPlatformLevel(); @Override PlatformHealth getPlatformHealth(); @Override List<Container> generateExperimentRoster(); @Override boolean isContainerRecycled(Container container); Map<String, String> getFilter(); void setFilter(Map<String, String> filter); void failoverCluster(String dbClusterIdentifier); void restartInstance(String... dbInstanceIdentifiers); Set<String> getClusterInstances(String dbClusterIdentifier); ContainerHealth getInstanceStatus(String... dbInstanceIdentifiers); void setVpcSecurityGroupIds(String dbInstanceIdentifier, String vpcSecurityGroupId); void setVpcSecurityGroupIds(String dbInstanceIdentifier, Collection<String> vpcSecurityGroupIds); ContainerHealth checkVpcSecurityGroupIds(String dbInstanceIdentifier, Collection<String> vpcSecurityGroupIds); Collection<String> getVpcSecurityGroupIds(String dbInstanceIdentifier); String getChaosSecurityGroup(String dbInstanceIdentifier); DBSnapshot snapshotDBInstance(String dbInstanceIdentifier); DBClusterSnapshot snapshotDBCluster(String dbClusterIdentifier); void deleteInstanceSnapshot(DBSnapshot dbSnapshot); void deleteClusterSnapshot(DBClusterSnapshot dbClusterSnapshot); boolean isInstanceSnapshotRunning(String dbInstanceIdentifier); boolean isClusterSnapshotRunning(String dbClusterIdentifier);  }