9696import software .amazon .awssdk .services .rds .model .DescribeDbEngineVersionsRequest ;
9797import software .amazon .awssdk .services .rds .model .DescribeDbEngineVersionsResponse ;
9898import software .amazon .awssdk .services .rds .model .DescribeDbInstancesResponse ;
99+ import software .amazon .awssdk .services .rds .model .DescribeOrderableDbInstanceOptionsResponse ;
99100import software .amazon .awssdk .services .rds .model .FailoverDbClusterResponse ;
100101import software .amazon .awssdk .services .rds .model .Filter ;
102+ import software .amazon .awssdk .services .rds .model .OrderableDBInstanceOption ;
103+ import software .amazon .awssdk .services .rds .model .RdsException ;
101104import software .amazon .awssdk .services .rds .model .RebootDbClusterResponse ;
102105import software .amazon .awssdk .services .rds .model .RebootDbInstanceResponse ;
103106import software .amazon .awssdk .services .rds .model .Tag ;
@@ -114,8 +117,6 @@ public class AuroraTestUtility {
114117 private static final Logger LOGGER = Logger .getLogger (AuroraTestUtility .class .getName ());
115118 private static final String DUPLICATE_IP_ERROR_CODE = "InvalidPermission.Duplicate" ;
116119 private static final String DEFAULT_SECURITY_GROUP = "default" ;
117- private static final String DEFAULT_STORAGE_TYPE = "gp3" ;
118- private static final int DEFAULT_IOPS = 64000 ;
119120 private static final int MULTI_AZ_SIZE = 3 ;
120121 private static final Random rand = new Random ();
121122
@@ -234,7 +235,7 @@ public void createCluster(
234235 }
235236
236237 createMultiAzCluster (
237- username , password , dbName , identifier , region , engine , instanceClass , version );
238+ username , password , dbName , identifier , region , engine , version );
238239 break ;
239240 default :
240241 throw new UnsupportedOperationException (deployment .toString ());
@@ -330,8 +331,6 @@ public void createAuroraCluster(
330331 * @param region the region that the cluster should be created in
331332 * @param engine the engine to use, refer to
332333 * <a href="https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/rds/model/CreateDbClusterRequest.Builder.html#engine(java.lang.String)">CreateDbClusterRequest.engine</a>
333- * @param instanceClass the instance class, refer to
334- * <a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.DBInstanceClass.Support.html">Supported instance classes</a>
335334 * @param version the database engine's version
336335 * @throws InterruptedException when clusters have not started after 30 minutes
337336 */
@@ -341,9 +340,10 @@ public void createMultiAzCluster(String username,
341340 String identifier ,
342341 String region ,
343342 String engine ,
344- String instanceClass ,
345343 String version )
346344 throws InterruptedException {
345+
346+ final List <OrderableDBInstanceOption > options = getAvailableDBInstances (engine , version );
347347 final Tag testRunnerTag = Tag .builder ().key ("env" ).value ("test-runner" ).build ();
348348 CreateDbClusterRequest .Builder clusterBuilder =
349349 CreateDbClusterRequest .builder ()
@@ -360,13 +360,26 @@ public void createMultiAzCluster(String username,
360360 .storageEncrypted (true )
361361 .tags (testRunnerTag );
362362
363- clusterBuilder =
364- clusterBuilder .allocatedStorage (400 )
365- .dbClusterInstanceClass (instanceClass )
366- .storageType (DEFAULT_STORAGE_TYPE )
367- .iops (DEFAULT_IOPS );
363+ boolean buildSuccess = false ;
364+ for (OrderableDBInstanceOption option : options ) {
365+ try {
366+ clusterBuilder =
367+ clusterBuilder .allocatedStorage (400 )
368+ .dbClusterInstanceClass (option .dbInstanceClass ())
369+ .storageType (option .storageType ());
368370
369- rdsClient .createDBCluster (clusterBuilder .build ());
371+ rdsClient .createDBCluster (clusterBuilder .build ());
372+ buildSuccess = true ;
373+ break ;
374+ } catch (RdsException e ) {
375+ // RDS exception will get thrown if the instance class doesn't Multi-AZ DB clusters.
376+ }
377+ }
378+
379+ if (!buildSuccess ) {
380+ throw new InterruptedException (
381+ "Unable to find compatible instance classes for the specified MultiAZ cluster engine that has at least 3 availabile zones." );
382+ }
370383
371384 // For multi-AZ deployments, the cluster instances are created automatically. Wait for all instances to be up.
372385 final RdsWaiter waiter = rdsClient .waiter ();
@@ -384,6 +397,15 @@ public void createMultiAzCluster(String username,
384397 }
385398 }
386399
400+ private List <OrderableDBInstanceOption > getAvailableDBInstances (String engine , String version ) {
401+ return rdsClient
402+ .describeOrderableDBInstanceOptions ((builder ) -> builder .engineVersion (version ).engine (engine ))
403+ .orderableDBInstanceOptions ()
404+ .stream ()
405+ .filter (o -> !o .supportsIops () && o .availabilityZones ().size () >= 3 )
406+ .collect (Collectors .toList ());
407+ }
408+
387409 /**
388410 * Creates an RDS instance under the current cluster and waits until it is up.
389411 *
0 commit comments