@Test public void generateExperimentRoster () { Collection<Container> matchSet1 = new HashSet<>(); Collection<Container> matchSet2 = new HashSet<>(); DescribeDBInstancesResult describeDBInstancesResult = new DescribeDBInstancesResult(); String availabilityZone1 = randomUUID().toString(); String availabilityZone2; do { availabilityZone2 = randomUUID().toString(); } while (availabilityZone1.equals(availabilityZone2)); for (int i = 0; i < 25; i++) { String dBInstanceIdentifier = randomUUID().toString(); String engine = randomUUID().toString(); DBInstance dbInstance = new DBInstance().withDBInstanceIdentifier(dBInstanceIdentifier) .withAvailabilityZone(availabilityZone1) .withEngine(engine); describeDBInstancesResult.withDBInstances(dbInstance); matchSet1.add(AwsRDSInstanceContainer.builder() .withAwsRDSPlatform(awsRDSPlatform) .withAvailabilityZone(availabilityZone1) .withDbInstanceIdentifier(dBInstanceIdentifier) .withEngine(engine) .build()); } for (int i = 0; i < 25; i++) { String dBInstanceIdentifier = randomUUID().toString(); String engine = randomUUID().toString(); DBInstance dbInstance = new DBInstance().withDBInstanceIdentifier(dBInstanceIdentifier) .withAvailabilityZone(availabilityZone2) .withEngine(engine); describeDBInstancesResult.withDBInstances(dbInstance); matchSet2.add(AwsRDSInstanceContainer.builder() .withAwsRDSPlatform(awsRDSPlatform) .withAvailabilityZone(availabilityZone2) .withDbInstanceIdentifier(dBInstanceIdentifier) .withEngine(engine) .build()); } DescribeDBClustersResult describeDBClustersResult = new DescribeDBClustersResult(); for (int i = 0; i < 15; i++) { String dbClusterIdentifier = randomUUID().toString(); String engine = randomUUID().toString(); DBCluster dbCluster = new DBCluster().withDBClusterIdentifier(dbClusterIdentifier).withEngine(engine); Container container = AwsRDSClusterContainer.builder() .withAwsRDSPlatform(awsRDSPlatform) .withDbClusterIdentifier(dbClusterIdentifier) .withEngine(engine) .build(); matchSet1.add(container); matchSet2.add(container); describeDBClustersResult.withDBClusters(dbCluster); } doReturn(true).when(awsRDSPlatform).filterDBInstance(any()); doReturn(true).when(awsRDSPlatform).filterDBCluster(any()); doReturn(describeDBInstancesResult).when(amazonRDS).describeDBInstances(any(DescribeDBInstancesRequest.class)); doReturn(describeDBClustersResult).when(amazonRDS).describeDBClusters(any(DescribeDBClustersRequest.class)); assertThat(awsRDSPlatform.generateExperimentRoster(), anyOf(IsIterableContainingInAnyOrder.containsInAnyOrder(matchSet1 .toArray(new Container[]{})), IsIterableContainingInAnyOrder.containsInAnyOrder(matchSet2.toArray(new Container[]{})))); }
@Override public List<Container> generateExperimentRoster () { Map<String, List<AwsContainer>> availabilityZoneMap = getRoster().stream().map(AwsContainer.class::cast).collect(groupingBy(AwsContainer::getAvailabilityZone)); final String[] availabilityZones = availabilityZoneMap.keySet().stream().filter(not(AwsConstants.NO_AZ_INFORMATION::equals)) .collect(toSet()) .toArray(new String[]{}); final String randomAvailabilityZone = availabilityZones[new Random().nextInt(availabilityZones.length)]; log.debug("Experiment on {} will use {}", keyValue(DataDogConstants.DATADOG_PLATFORM_KEY, this.getPlatformType()), keyValue(DataDogConstants.AVAILABILITY_ZONE, randomAvailabilityZone)); List<Container> chosenSet = new ArrayList<>(); chosenSet.addAll(availabilityZoneMap.getOrDefault(randomAvailabilityZone, Collections.emptyList())); chosenSet.addAll(availabilityZoneMap.getOrDefault(AwsConstants.NO_AZ_INFORMATION, Collections.emptyList())); return chosenSet; }
AwsRDSPlatform extends Platform { @Override public List<Container> generateExperimentRoster () { Map<String, List<AwsContainer>> availabilityZoneMap = getRoster().stream().map(AwsContainer.class::cast).collect(groupingBy(AwsContainer::getAvailabilityZone)); final String[] availabilityZones = availabilityZoneMap.keySet().stream().filter(not(AwsConstants.NO_AZ_INFORMATION::equals)) .collect(toSet()) .toArray(new String[]{}); final String randomAvailabilityZone = availabilityZones[new Random().nextInt(availabilityZones.length)]; log.debug("Experiment on {} will use {}", keyValue(DataDogConstants.DATADOG_PLATFORM_KEY, this.getPlatformType()), keyValue(DataDogConstants.AVAILABILITY_ZONE, randomAvailabilityZone)); List<Container> chosenSet = new ArrayList<>(); chosenSet.addAll(availabilityZoneMap.getOrDefault(randomAvailabilityZone, Collections.emptyList())); chosenSet.addAll(availabilityZoneMap.getOrDefault(AwsConstants.NO_AZ_INFORMATION, Collections.emptyList())); return chosenSet; } }
AwsRDSPlatform extends Platform { @Override public List<Container> generateExperimentRoster () { Map<String, List<AwsContainer>> availabilityZoneMap = getRoster().stream().map(AwsContainer.class::cast).collect(groupingBy(AwsContainer::getAvailabilityZone)); final String[] availabilityZones = availabilityZoneMap.keySet().stream().filter(not(AwsConstants.NO_AZ_INFORMATION::equals)) .collect(toSet()) .toArray(new String[]{}); final String randomAvailabilityZone = availabilityZones[new Random().nextInt(availabilityZones.length)]; log.debug("Experiment on {} will use {}", keyValue(DataDogConstants.DATADOG_PLATFORM_KEY, this.getPlatformType()), keyValue(DataDogConstants.AVAILABILITY_ZONE, randomAvailabilityZone)); List<Container> chosenSet = new ArrayList<>(); chosenSet.addAll(availabilityZoneMap.getOrDefault(randomAvailabilityZone, Collections.emptyList())); chosenSet.addAll(availabilityZoneMap.getOrDefault(AwsConstants.NO_AZ_INFORMATION, Collections.emptyList())); return chosenSet; } @Autowired  AwsRDSPlatform();   AwsRDSPlatform(AmazonRDS amazonRDS, AmazonEC2 amazonEC2); }
AwsRDSPlatform extends Platform { @Override public List<Container> generateExperimentRoster () { Map<String, List<AwsContainer>> availabilityZoneMap = getRoster().stream().map(AwsContainer.class::cast).collect(groupingBy(AwsContainer::getAvailabilityZone)); final String[] availabilityZones = availabilityZoneMap.keySet().stream().filter(not(AwsConstants.NO_AZ_INFORMATION::equals)) .collect(toSet()) .toArray(new String[]{}); final String randomAvailabilityZone = availabilityZones[new Random().nextInt(availabilityZones.length)]; log.debug("Experiment on {} will use {}", keyValue(DataDogConstants.DATADOG_PLATFORM_KEY, this.getPlatformType()), keyValue(DataDogConstants.AVAILABILITY_ZONE, randomAvailabilityZone)); List<Container> chosenSet = new ArrayList<>(); chosenSet.addAll(availabilityZoneMap.getOrDefault(randomAvailabilityZone, Collections.emptyList())); chosenSet.addAll(availabilityZoneMap.getOrDefault(AwsConstants.NO_AZ_INFORMATION, Collections.emptyList())); return chosenSet; } @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 { @Override public List<Container> generateExperimentRoster () { Map<String, List<AwsContainer>> availabilityZoneMap = getRoster().stream().map(AwsContainer.class::cast).collect(groupingBy(AwsContainer::getAvailabilityZone)); final String[] availabilityZones = availabilityZoneMap.keySet().stream().filter(not(AwsConstants.NO_AZ_INFORMATION::equals)) .collect(toSet()) .toArray(new String[]{}); final String randomAvailabilityZone = availabilityZones[new Random().nextInt(availabilityZones.length)]; log.debug("Experiment on {} will use {}", keyValue(DataDogConstants.DATADOG_PLATFORM_KEY, this.getPlatformType()), keyValue(DataDogConstants.AVAILABILITY_ZONE, randomAvailabilityZone)); List<Container> chosenSet = new ArrayList<>(); chosenSet.addAll(availabilityZoneMap.getOrDefault(randomAvailabilityZone, Collections.emptyList())); chosenSet.addAll(availabilityZoneMap.getOrDefault(AwsConstants.NO_AZ_INFORMATION, Collections.emptyList())); return chosenSet; } @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);  }