@Test public void cleanupOldClusterSnapshots () { DBClusterSnapshot dbClusterSnapshot1 = new DBClusterSnapshot().withDBClusterSnapshotIdentifier("ChaosSnapshot-instance-1970-01-01T01-02-03Z"); DBClusterSnapshot dbClusterSnapshot2 = new DBClusterSnapshot().withDBClusterSnapshotIdentifier("ChaosSnapshot-instance-2199-01-01T01-02-03Z"); DBClusterSnapshot dbClusterSnapshot3 = new DBClusterSnapshot().withDBClusterSnapshotIdentifier("RegularSnapshot-instance-1970-01-01T01-02-03Z"); DescribeDBClusterSnapshotsResult describeDBClusterSnapshotsResult = Mockito.mock(DescribeDBClusterSnapshotsResult.class); doReturn(Arrays.asList(dbClusterSnapshot1, dbClusterSnapshot2, dbClusterSnapshot3), Collections.singletonList(dbClusterSnapshot2), Collections .singletonList(dbClusterSnapshot3)).when(describeDBClusterSnapshotsResult).getDBClusterSnapshots(); doReturn(describeDBClusterSnapshotsResult).when(amazonRDS).describeDBClusterSnapshots(); doNothing().when(awsRDSPlatform).deleteClusterSnapshot(any()); awsRDSPlatform.cleanupOldClusterSnapshots(60); verify(awsRDSPlatform, times(1)).deleteClusterSnapshot(dbClusterSnapshot1); reset(awsRDSPlatform); awsRDSPlatform.cleanupOldClusterSnapshots(60); verify(awsRDSPlatform, never()).deleteClusterSnapshot(any()); reset(awsRDSPlatform); awsRDSPlatform.cleanupOldClusterSnapshots(60); verify(awsRDSPlatform, never()).deleteClusterSnapshot(any()); reset(awsRDSPlatform); }
void cleanupOldClusterSnapshots (int olderThanMinutes) { amazonRDS.describeDBClusterSnapshots() .getDBClusterSnapshots() .stream() .filter(dbClusterSnapshot -> AwsRDSUtils.isChaosSnapshot(dbClusterSnapshot.getDBClusterSnapshotIdentifier())) .filter(dbClusterSnapshot -> snapshotIsOlderThan(dbClusterSnapshot.getDBClusterSnapshotIdentifier(), olderThanMinutes)) .peek(dbClusterSnapshot -> log.info("Deleting cluster snapshot {} since it is out of date", v("dbClusterSnapshot", dbClusterSnapshot))) .parallel() .forEach(this::deleteClusterSnapshot); }
AwsRDSPlatform extends Platform { void cleanupOldClusterSnapshots (int olderThanMinutes) { amazonRDS.describeDBClusterSnapshots() .getDBClusterSnapshots() .stream() .filter(dbClusterSnapshot -> AwsRDSUtils.isChaosSnapshot(dbClusterSnapshot.getDBClusterSnapshotIdentifier())) .filter(dbClusterSnapshot -> snapshotIsOlderThan(dbClusterSnapshot.getDBClusterSnapshotIdentifier(), olderThanMinutes)) .peek(dbClusterSnapshot -> log.info("Deleting cluster snapshot {} since it is out of date", v("dbClusterSnapshot", dbClusterSnapshot))) .parallel() .forEach(this::deleteClusterSnapshot); } }
AwsRDSPlatform extends Platform { void cleanupOldClusterSnapshots (int olderThanMinutes) { amazonRDS.describeDBClusterSnapshots() .getDBClusterSnapshots() .stream() .filter(dbClusterSnapshot -> AwsRDSUtils.isChaosSnapshot(dbClusterSnapshot.getDBClusterSnapshotIdentifier())) .filter(dbClusterSnapshot -> snapshotIsOlderThan(dbClusterSnapshot.getDBClusterSnapshotIdentifier(), olderThanMinutes)) .peek(dbClusterSnapshot -> log.info("Deleting cluster snapshot {} since it is out of date", v("dbClusterSnapshot", dbClusterSnapshot))) .parallel() .forEach(this::deleteClusterSnapshot); } @Autowired  AwsRDSPlatform();   AwsRDSPlatform(AmazonRDS amazonRDS, AmazonEC2 amazonEC2); }
AwsRDSPlatform extends Platform { void cleanupOldClusterSnapshots (int olderThanMinutes) { amazonRDS.describeDBClusterSnapshots() .getDBClusterSnapshots() .stream() .filter(dbClusterSnapshot -> AwsRDSUtils.isChaosSnapshot(dbClusterSnapshot.getDBClusterSnapshotIdentifier())) .filter(dbClusterSnapshot -> snapshotIsOlderThan(dbClusterSnapshot.getDBClusterSnapshotIdentifier(), olderThanMinutes)) .peek(dbClusterSnapshot -> log.info("Deleting cluster snapshot {} since it is out of date", v("dbClusterSnapshot", dbClusterSnapshot))) .parallel() .forEach(this::deleteClusterSnapshot); } @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 cleanupOldClusterSnapshots (int olderThanMinutes) { amazonRDS.describeDBClusterSnapshots() .getDBClusterSnapshots() .stream() .filter(dbClusterSnapshot -> AwsRDSUtils.isChaosSnapshot(dbClusterSnapshot.getDBClusterSnapshotIdentifier())) .filter(dbClusterSnapshot -> snapshotIsOlderThan(dbClusterSnapshot.getDBClusterSnapshotIdentifier(), olderThanMinutes)) .peek(dbClusterSnapshot -> log.info("Deleting cluster snapshot {} since it is out of date", v("dbClusterSnapshot", dbClusterSnapshot))) .parallel() .forEach(this::deleteClusterSnapshot); } @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);  }