96
96
import software .amazon .awssdk .services .rds .model .DescribeDbEngineVersionsRequest ;
97
97
import software .amazon .awssdk .services .rds .model .DescribeDbEngineVersionsResponse ;
98
98
import software .amazon .awssdk .services .rds .model .DescribeDbInstancesResponse ;
99
+ import software .amazon .awssdk .services .rds .model .DescribeOrderableDbInstanceOptionsResponse ;
99
100
import software .amazon .awssdk .services .rds .model .FailoverDbClusterResponse ;
100
101
import 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 ;
101
104
import software .amazon .awssdk .services .rds .model .RebootDbClusterResponse ;
102
105
import software .amazon .awssdk .services .rds .model .RebootDbInstanceResponse ;
103
106
import software .amazon .awssdk .services .rds .model .Tag ;
@@ -114,8 +117,6 @@ public class AuroraTestUtility {
114
117
private static final Logger LOGGER = Logger .getLogger (AuroraTestUtility .class .getName ());
115
118
private static final String DUPLICATE_IP_ERROR_CODE = "InvalidPermission.Duplicate" ;
116
119
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 ;
119
120
private static final int MULTI_AZ_SIZE = 3 ;
120
121
private static final Random rand = new Random ();
121
122
@@ -234,7 +235,7 @@ public void createCluster(
234
235
}
235
236
236
237
createMultiAzCluster (
237
- username , password , dbName , identifier , region , engine , instanceClass , version );
238
+ username , password , dbName , identifier , region , engine , version );
238
239
break ;
239
240
default :
240
241
throw new UnsupportedOperationException (deployment .toString ());
@@ -330,8 +331,6 @@ public void createAuroraCluster(
330
331
* @param region the region that the cluster should be created in
331
332
* @param engine the engine to use, refer to
332
333
* <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>
335
334
* @param version the database engine's version
336
335
* @throws InterruptedException when clusters have not started after 30 minutes
337
336
*/
@@ -341,9 +340,10 @@ public void createMultiAzCluster(String username,
341
340
String identifier ,
342
341
String region ,
343
342
String engine ,
344
- String instanceClass ,
345
343
String version )
346
344
throws InterruptedException {
345
+
346
+ final List <OrderableDBInstanceOption > options = getAvailableDBInstances (engine , version );
347
347
final Tag testRunnerTag = Tag .builder ().key ("env" ).value ("test-runner" ).build ();
348
348
CreateDbClusterRequest .Builder clusterBuilder =
349
349
CreateDbClusterRequest .builder ()
@@ -360,13 +360,27 @@ public void createMultiAzCluster(String username,
360
360
.storageEncrypted (true )
361
361
.tags (testRunnerTag );
362
362
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 (option .maxStorageSize ())
368
+ .dbClusterInstanceClass (option .dbInstanceClass ())
369
+ .storageType (option .storageType ());
368
370
369
- rdsClient .createDBCluster (clusterBuilder .build ());
371
+ rdsClient .createDBCluster (clusterBuilder .build ());
372
+ buildSuccess = true ;
373
+ break ;
374
+ } catch (RdsException e ) {
375
+ LOGGER .finest ("Multi-AZ DB Cluster creation process failed: " + e .getMessage ());
376
+ // RDS exception will get thrown if the instance class doesn't Multi-AZ DB clusters.
377
+ }
378
+ }
379
+
380
+ if (!buildSuccess ) {
381
+ throw new InterruptedException (
382
+ "Unable to find compatible instance classes for the specified MultiAZ cluster engine that has at least 3 availabile zones." );
383
+ }
370
384
371
385
// For multi-AZ deployments, the cluster instances are created automatically. Wait for all instances to be up.
372
386
final RdsWaiter waiter = rdsClient .waiter ();
@@ -384,6 +398,15 @@ public void createMultiAzCluster(String username,
384
398
}
385
399
}
386
400
401
+ private List <OrderableDBInstanceOption > getAvailableDBInstances (String engine , String version ) {
402
+ return rdsClient
403
+ .describeOrderableDBInstanceOptions ((builder ) -> builder .engineVersion (version ).engine (engine ))
404
+ .orderableDBInstanceOptions ()
405
+ .stream ()
406
+ .filter (o -> !o .supportsIops () && o .availabilityZones ().size () >= 3 )
407
+ .collect (Collectors .toList ());
408
+ }
409
+
387
410
/**
388
411
* Creates an RDS instance under the current cluster and waits until it is up.
389
412
*
0 commit comments