@Test public void getInstanceStatus () { String instanceId1 = randomUUID().toString(); String instanceId2 = randomUUID().toString(); DescribeDBInstancesResult normalInstance1 = new DescribeDBInstancesResult().withDBInstances(new DBInstance().withDBInstanceIdentifier(instanceId1) .withDBInstanceStatus(AwsRDSConstants.AWS_RDS_AVAILABLE)); DescribeDBInstancesResult normalInstance2 = new DescribeDBInstancesResult().withDBInstances(new DBInstance().withDBInstanceIdentifier(instanceId2) .withDBInstanceStatus(AwsRDSConstants.AWS_RDS_AVAILABLE)); DescribeDBInstancesResult abnormalInstance1 = new DescribeDBInstancesResult().withDBInstances(new DBInstance().withDBInstanceIdentifier(instanceId1) .withDBInstanceStatus(AwsRDSConstants.AWS_RDS_FAILING_OVER)); DescribeDBInstancesResult abnormalInstance2 = new DescribeDBInstancesResult().withDBInstances(new DBInstance().withDBInstanceIdentifier(instanceId2) .withDBInstanceStatus(AwsRDSConstants.AWS_RDS_FAILING_OVER)); DescribeDBInstancesResult emptyDBInstanceresult = new DescribeDBInstancesResult(); doReturn(emptyDBInstanceresult).when(amazonRDS).describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier(instanceId1)); assertEquals(ContainerHealth.DOES_NOT_EXIST, awsRDSPlatform.getInstanceStatus(instanceId1)); reset(amazonRDS); doReturn(normalInstance1).when(amazonRDS).describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier(instanceId1)); doReturn(normalInstance2).when(amazonRDS).describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier(instanceId2)); assertEquals(ContainerHealth.NORMAL, awsRDSPlatform.getInstanceStatus(instanceId1, instanceId2)); reset(amazonRDS); doReturn(normalInstance1).when(amazonRDS).describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier(instanceId1)); doReturn(abnormalInstance2).when(amazonRDS).describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier(instanceId2)); assertEquals(ContainerHealth.RUNNING_EXPERIMENT, awsRDSPlatform.getInstanceStatus(instanceId1, instanceId2)); reset(amazonRDS); doReturn(abnormalInstance1).when(amazonRDS).describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier(instanceId1)); doReturn(normalInstance2).when(amazonRDS).describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier(instanceId2)); assertEquals(ContainerHealth.RUNNING_EXPERIMENT, awsRDSPlatform.getInstanceStatus(instanceId1, instanceId2)); }
public ContainerHealth getInstanceStatus (String... dbInstanceIdentifiers) { log.info("Checking health of instances {}", value("dbInstanceIdentifiers", dbInstanceIdentifiers)); Collection<ContainerHealth> containerHealthCollection = new HashSet<>(); for (String dbInstanceIdentifier : dbInstanceIdentifiers) { ContainerHealth instanceStatus = getInstanceStatus(dbInstanceIdentifier); containerHealthCollection.add(instanceStatus); switch (instanceStatus) { case NORMAL: log.debug("Container {} returned health {}", value(AWS_RDS_INSTANCE_DATADOG_IDENTIFIER, dbInstanceIdentifier), value("ContainerHealth", instanceStatus)); break; case DOES_NOT_EXIST: case RUNNING_EXPERIMENT: log.warn("Container {} returned health {}", value(AWS_RDS_INSTANCE_DATADOG_IDENTIFIER, dbInstanceIdentifier), value("ContainerHealth", instanceStatus)); break; } } return containerHealthCollection.stream().max(Comparator.comparingInt(ContainerHealth::getHealthLevel)).orElse(ContainerHealth.NORMAL); }
AwsRDSPlatform extends Platform { public ContainerHealth getInstanceStatus (String... dbInstanceIdentifiers) { log.info("Checking health of instances {}", value("dbInstanceIdentifiers", dbInstanceIdentifiers)); Collection<ContainerHealth> containerHealthCollection = new HashSet<>(); for (String dbInstanceIdentifier : dbInstanceIdentifiers) { ContainerHealth instanceStatus = getInstanceStatus(dbInstanceIdentifier); containerHealthCollection.add(instanceStatus); switch (instanceStatus) { case NORMAL: log.debug("Container {} returned health {}", value(AWS_RDS_INSTANCE_DATADOG_IDENTIFIER, dbInstanceIdentifier), value("ContainerHealth", instanceStatus)); break; case DOES_NOT_EXIST: case RUNNING_EXPERIMENT: log.warn("Container {} returned health {}", value(AWS_RDS_INSTANCE_DATADOG_IDENTIFIER, dbInstanceIdentifier), value("ContainerHealth", instanceStatus)); break; } } return containerHealthCollection.stream().max(Comparator.comparingInt(ContainerHealth::getHealthLevel)).orElse(ContainerHealth.NORMAL); } }
AwsRDSPlatform extends Platform { public ContainerHealth getInstanceStatus (String... dbInstanceIdentifiers) { log.info("Checking health of instances {}", value("dbInstanceIdentifiers", dbInstanceIdentifiers)); Collection<ContainerHealth> containerHealthCollection = new HashSet<>(); for (String dbInstanceIdentifier : dbInstanceIdentifiers) { ContainerHealth instanceStatus = getInstanceStatus(dbInstanceIdentifier); containerHealthCollection.add(instanceStatus); switch (instanceStatus) { case NORMAL: log.debug("Container {} returned health {}", value(AWS_RDS_INSTANCE_DATADOG_IDENTIFIER, dbInstanceIdentifier), value("ContainerHealth", instanceStatus)); break; case DOES_NOT_EXIST: case RUNNING_EXPERIMENT: log.warn("Container {} returned health {}", value(AWS_RDS_INSTANCE_DATADOG_IDENTIFIER, dbInstanceIdentifier), value("ContainerHealth", instanceStatus)); break; } } return containerHealthCollection.stream().max(Comparator.comparingInt(ContainerHealth::getHealthLevel)).orElse(ContainerHealth.NORMAL); } @Autowired  AwsRDSPlatform();   AwsRDSPlatform(AmazonRDS amazonRDS, AmazonEC2 amazonEC2); }
AwsRDSPlatform extends Platform { public ContainerHealth getInstanceStatus (String... dbInstanceIdentifiers) { log.info("Checking health of instances {}", value("dbInstanceIdentifiers", dbInstanceIdentifiers)); Collection<ContainerHealth> containerHealthCollection = new HashSet<>(); for (String dbInstanceIdentifier : dbInstanceIdentifiers) { ContainerHealth instanceStatus = getInstanceStatus(dbInstanceIdentifier); containerHealthCollection.add(instanceStatus); switch (instanceStatus) { case NORMAL: log.debug("Container {} returned health {}", value(AWS_RDS_INSTANCE_DATADOG_IDENTIFIER, dbInstanceIdentifier), value("ContainerHealth", instanceStatus)); break; case DOES_NOT_EXIST: case RUNNING_EXPERIMENT: log.warn("Container {} returned health {}", value(AWS_RDS_INSTANCE_DATADOG_IDENTIFIER, dbInstanceIdentifier), value("ContainerHealth", instanceStatus)); break; } } return containerHealthCollection.stream().max(Comparator.comparingInt(ContainerHealth::getHealthLevel)).orElse(ContainerHealth.NORMAL); } @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 { public ContainerHealth getInstanceStatus (String... dbInstanceIdentifiers) { log.info("Checking health of instances {}", value("dbInstanceIdentifiers", dbInstanceIdentifiers)); Collection<ContainerHealth> containerHealthCollection = new HashSet<>(); for (String dbInstanceIdentifier : dbInstanceIdentifiers) { ContainerHealth instanceStatus = getInstanceStatus(dbInstanceIdentifier); containerHealthCollection.add(instanceStatus); switch (instanceStatus) { case NORMAL: log.debug("Container {} returned health {}", value(AWS_RDS_INSTANCE_DATADOG_IDENTIFIER, dbInstanceIdentifier), value("ContainerHealth", instanceStatus)); break; case DOES_NOT_EXIST: case RUNNING_EXPERIMENT: log.warn("Container {} returned health {}", value(AWS_RDS_INSTANCE_DATADOG_IDENTIFIER, dbInstanceIdentifier), value("ContainerHealth", instanceStatus)); break; } } return containerHealthCollection.stream().max(Comparator.comparingInt(ContainerHealth::getHealthLevel)).orElse(ContainerHealth.NORMAL); } @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);  }