From dc9cb4b840d084302096ee5f2bc5651814d65e4a Mon Sep 17 00:00:00 2001 From: vet Date: Tue, 19 Nov 2024 14:13:37 +0000 Subject: [PATCH] feat(DBCluster): add SecondsUntilAutoPause to ServerlessV2ScalingConfiguration Adds support for the automatic pause/resume feature of Aurora Serverless v2. Also bumping the AWS Java SDK to 2.29.16. --- aws-rds-cfn-common/pom.xml | 4 ++-- aws-rds-customdbengineversion/pom.xml | 4 ++-- aws-rds-dbcluster/aws-rds-dbcluster.json | 3 +++ aws-rds-dbcluster/pom.xml | 6 ++--- .../amazon/rds/dbcluster/ModelAdapter.java | 8 +++++++ .../amazon/rds/dbcluster/Translator.java | 1 + .../amazon/rds/dbcluster/UpdateHandler.java | 19 ++++++--------- .../rds/dbcluster/UpdateHandlerTest.java | 23 +++++++++++++++---- aws-rds-dbclusterendpoint/pom.xml | 4 ++-- aws-rds-dbclusterparametergroup/pom.xml | 4 ++-- aws-rds-dbinstance/pom.xml | 6 ++--- aws-rds-dbparametergroup/pom.xml | 4 ++-- aws-rds-dbshardgroup/pom.xml | 4 ++-- aws-rds-dbsubnetgroup/pom.xml | 4 ++-- aws-rds-eventsubscription/pom.xml | 4 ++-- aws-rds-globalcluster/pom.xml | 4 ++-- aws-rds-integration/pom.xml | 4 ++-- aws-rds-optiongroup/pom.xml | 4 ++-- .../amazon/rds/optiongroup/ClientBuilder.java | 11 ++------- 19 files changed, 67 insertions(+), 54 deletions(-) diff --git a/aws-rds-cfn-common/pom.xml b/aws-rds-cfn-common/pom.xml index 7e3c63d95..790cbf719 100644 --- a/aws-rds-cfn-common/pom.xml +++ b/aws-rds-cfn-common/pom.xml @@ -28,12 +28,12 @@ software.amazon.awssdk utils - 2.28.14 + 2.29.16 software.amazon.awssdk rds - 2.28.14 + 2.29.16 software.amazon.cloudformation diff --git a/aws-rds-customdbengineversion/pom.xml b/aws-rds-customdbengineversion/pom.xml index 0ed1cb39c..d4e2fb991 100644 --- a/aws-rds-customdbengineversion/pom.xml +++ b/aws-rds-customdbengineversion/pom.xml @@ -23,7 +23,7 @@ software.amazon.awssdk rds - 2.28.14 + 2.29.16 software.amazon.rds.common @@ -54,7 +54,7 @@ software.amazon.awssdk aws-query-protocol - 2.20.138 + 2.29.16 diff --git a/aws-rds-dbcluster/aws-rds-dbcluster.json b/aws-rds-dbcluster/aws-rds-dbcluster.json index f3c5086c4..cd479cad9 100644 --- a/aws-rds-dbcluster/aws-rds-dbcluster.json +++ b/aws-rds-dbcluster/aws-rds-dbcluster.json @@ -338,6 +338,9 @@ "MaxCapacity": { "description": "The maximum number of Aurora capacity units (ACUs) for a DB instance in an Aurora Serverless v2 cluster. You can specify ACU values in half-step increments, such as 40, 40.5, 41, and so on. The largest value that you can use is 128.", "type": "number" + }, + "SecondsUntilAutoPause": { + "type": "integer" } } }, diff --git a/aws-rds-dbcluster/pom.xml b/aws-rds-dbcluster/pom.xml index 80fad90dd..fff8f8678 100644 --- a/aws-rds-dbcluster/pom.xml +++ b/aws-rds-dbcluster/pom.xml @@ -30,18 +30,18 @@ software.amazon.awssdk rds - 2.28.14 + 2.29.16 software.amazon.awssdk ec2 - 2.28.14 + 2.29.16 software.amazon.awssdk aws-query-protocol - 2.28.14 + 2.29.16 diff --git a/aws-rds-dbcluster/src/main/java/software/amazon/rds/dbcluster/ModelAdapter.java b/aws-rds-dbcluster/src/main/java/software/amazon/rds/dbcluster/ModelAdapter.java index 33224e045..0dcd9c1fe 100644 --- a/aws-rds-dbcluster/src/main/java/software/amazon/rds/dbcluster/ModelAdapter.java +++ b/aws-rds-dbcluster/src/main/java/software/amazon/rds/dbcluster/ModelAdapter.java @@ -14,6 +14,7 @@ public class ModelAdapter { private static final int DEFAULT_MAX_CAPACITY = 16; private static final int DEFAULT_MIN_CAPACITY = 2; private static final int DEFAULT_SECONDS_UNTIL_AUTO_PAUSE = 300; + private static final int DEFAULT_SECONDS_UNTIL_AUTO_PAUSE_V2 = 300; private static final int DEFAULT_PORT = 3306; private static final String ENGINE_AURORA = "aurora"; @@ -52,6 +53,13 @@ public static ResourceModel setDefaults(final ResourceModel resourceModel) { resourceModel.setScalingConfiguration(scalingConfiguration == null ? defaultScalingConfiguration : scalingConfiguration); } + final var serverlessV2ScalingConfiguration = resourceModel.getServerlessV2ScalingConfiguration(); + if (serverlessV2ScalingConfiguration != null && serverlessV2ScalingConfiguration.getMinCapacity() == 0) { + if (serverlessV2ScalingConfiguration.getSecondsUntilAutoPause() == null) { + serverlessV2ScalingConfiguration.setSecondsUntilAutoPause(DEFAULT_SECONDS_UNTIL_AUTO_PAUSE_V2); + } + } + final EngineMode engineMode = EngineMode.fromString(resourceModel.getEngineMode()); resourceModel.setPort(port != null ? port : getDefaultPortForEngine(resourceModel.getEngine(), engineMode)); diff --git a/aws-rds-dbcluster/src/main/java/software/amazon/rds/dbcluster/Translator.java b/aws-rds-dbcluster/src/main/java/software/amazon/rds/dbcluster/Translator.java index 059f7423a..a79530ec5 100644 --- a/aws-rds-dbcluster/src/main/java/software/amazon/rds/dbcluster/Translator.java +++ b/aws-rds-dbcluster/src/main/java/software/amazon/rds/dbcluster/Translator.java @@ -468,6 +468,7 @@ static software.amazon.awssdk.services.rds.model.ServerlessV2ScalingConfiguratio return software.amazon.awssdk.services.rds.model.ServerlessV2ScalingConfiguration.builder() .maxCapacity(serverlessV2ScalingConfiguration.getMaxCapacity()) .minCapacity(serverlessV2ScalingConfiguration.getMinCapacity()) + .secondsUntilAutoPause(serverlessV2ScalingConfiguration.getSecondsUntilAutoPause()) .build(); } diff --git a/aws-rds-dbcluster/src/main/java/software/amazon/rds/dbcluster/UpdateHandler.java b/aws-rds-dbcluster/src/main/java/software/amazon/rds/dbcluster/UpdateHandler.java index 5370f3c9c..ef17a1120 100644 --- a/aws-rds-dbcluster/src/main/java/software/amazon/rds/dbcluster/UpdateHandler.java +++ b/aws-rds-dbcluster/src/main/java/software/amazon/rds/dbcluster/UpdateHandler.java @@ -68,19 +68,14 @@ protected ProgressEvent handleRequest( "Resource is immutable" ); } + + if (!Objects.equals(request.getDesiredResourceState().getEngineLifecycleSupport(), + request.getPreviousResourceState().getEngineLifecycleSupport()) && + !request.getRollback()) { + throw new CfnInvalidRequestException("EngineLifecycleSupport cannot be modified."); + } + return ProgressEvent.progress(desiredResourceState, callbackContext) - .then(progress -> { - try { - if(!Objects.equals(request.getDesiredResourceState().getEngineLifecycleSupport(), - request.getPreviousResourceState().getEngineLifecycleSupport()) && - !request.getRollback()) { - throw new CfnInvalidRequestException("EngineLifecycleSupport cannot be modified."); - } - } catch (CfnInvalidRequestException e) { - return Commons.handleException(progress, e, DEFAULT_DB_CLUSTER_ERROR_RULE_SET, requestLogger); - } - return progress; - }) .then(progress -> { if (shouldRemoveFromGlobalCluster(request.getPreviousResourceState(), request.getDesiredResourceState())) { progress.getCallbackContext().timestampOnce(RESOURCE_UPDATED_AT, Instant.now()); diff --git a/aws-rds-dbcluster/src/test/java/software/amazon/rds/dbcluster/UpdateHandlerTest.java b/aws-rds-dbcluster/src/test/java/software/amazon/rds/dbcluster/UpdateHandlerTest.java index ba14cd845..eb7119ea5 100644 --- a/aws-rds-dbcluster/src/test/java/software/amazon/rds/dbcluster/UpdateHandlerTest.java +++ b/aws-rds-dbcluster/src/test/java/software/amazon/rds/dbcluster/UpdateHandlerTest.java @@ -25,6 +25,7 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.ArgumentsProvider; import org.junit.jupiter.params.provider.ArgumentsSource; +import org.junit.jupiter.params.provider.CsvSource; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -824,8 +825,17 @@ void handleRequest_EngineVersionUpdateIfMismatch() { Assertions.assertThat(argument.getValue().allowMajorVersionUpgrade()).isTrue(); } - @Test - void handleRequest_ServerlessV2ScalingConfiguration_Success() { + @ParameterizedTest + @CsvSource({ + "1, , 3, , ", // modify minCapacity + "1, , 0, 600, 600", // enable auto-pause with specific seconds until auto-pause + "1, , 0, , 300", // enable auto-pause with default seconds until auto-pause + "0, 600, 0, , 300" // reset seconds until auto-pause to default + }) + void handleRequest_ServerlessV2ScalingConfiguration_Success( + final double minCapacityBefore, final Integer secondsUntilAutoPauseBefore, + final double minCapacityAfter, final Integer secondsUntilAutoPauseAfter, + final Integer expectedSecondsUntilAutoPause) { when(rdsProxy.client().modifyDBCluster(any(ModifyDbClusterRequest.class))) .thenReturn(ModifyDbClusterResponse.builder().build()); when(rdsProxy.client().removeTagsFromResource(any(RemoveTagsFromResourceRequest.class))) @@ -841,13 +851,15 @@ void handleRequest_ServerlessV2ScalingConfiguration_Success() { transitions.add(DBCLUSTER_ACTIVE_NO_ROLE); final ServerlessV2ScalingConfiguration previousServerlessV2ScalingConfiguration = ServerlessV2ScalingConfiguration.builder() - .minCapacity(1.0) + .minCapacity(minCapacityBefore) .maxCapacity(2.0) + .secondsUntilAutoPause(secondsUntilAutoPauseBefore) .build(); final ServerlessV2ScalingConfiguration desiredServerlessV2ScalingConfiguration = ServerlessV2ScalingConfiguration.builder() - .minCapacity(3.0) + .minCapacity(minCapacityAfter) .maxCapacity(4.0) + .secondsUntilAutoPause(secondsUntilAutoPauseAfter) .build(); test_handleRequest_base( @@ -881,6 +893,7 @@ void handleRequest_ServerlessV2ScalingConfiguration_Success() { .isEqualTo(software.amazon.awssdk.services.rds.model.ServerlessV2ScalingConfiguration.builder() .maxCapacity(desiredServerlessV2ScalingConfiguration.getMaxCapacity()) .minCapacity(desiredServerlessV2ScalingConfiguration.getMinCapacity()) + .secondsUntilAutoPause(expectedSecondsUntilAutoPause) .build()); } @@ -997,7 +1010,7 @@ void handleRequest_ModifyDBCluster_HandleException( } @Test - public void handleRequest_EngineLifecycleSupportShouldFail() { + void handleRequest_EngineLifecycleSupportShouldFail() { expectServiceInvocation = false; test_handleRequest_base( new CallbackContext(), diff --git a/aws-rds-dbclusterendpoint/pom.xml b/aws-rds-dbclusterendpoint/pom.xml index 6161cf303..936c0abe2 100644 --- a/aws-rds-dbclusterendpoint/pom.xml +++ b/aws-rds-dbclusterendpoint/pom.xml @@ -30,7 +30,7 @@ software.amazon.awssdk rds - 2.28.14 + 2.29.16 @@ -78,7 +78,7 @@ software.amazon.awssdk aws-query-protocol - 2.20.138 + 2.29.16 software.amazon.rds.common diff --git a/aws-rds-dbclusterparametergroup/pom.xml b/aws-rds-dbclusterparametergroup/pom.xml index c882f7965..ac0fd1f6d 100644 --- a/aws-rds-dbclusterparametergroup/pom.xml +++ b/aws-rds-dbclusterparametergroup/pom.xml @@ -30,7 +30,7 @@ software.amazon.awssdk rds - 2.28.14 + 2.29.16 @@ -78,7 +78,7 @@ software.amazon.awssdk aws-query-protocol - 2.20.138 + 2.29.16 software.amazon.rds.common diff --git a/aws-rds-dbinstance/pom.xml b/aws-rds-dbinstance/pom.xml index 883c7e291..524b43f53 100644 --- a/aws-rds-dbinstance/pom.xml +++ b/aws-rds-dbinstance/pom.xml @@ -34,12 +34,12 @@ software.amazon.awssdk rds - 2.28.14 + 2.29.16 software.amazon.awssdk ec2 - 2.21.17 + 2.29.16 @@ -58,7 +58,7 @@ software.amazon.awssdk aws-query-protocol - 2.20.138 + 2.29.16 diff --git a/aws-rds-dbparametergroup/pom.xml b/aws-rds-dbparametergroup/pom.xml index 6fc621f85..23c90e1c1 100644 --- a/aws-rds-dbparametergroup/pom.xml +++ b/aws-rds-dbparametergroup/pom.xml @@ -24,12 +24,12 @@ software.amazon.awssdk aws-query-protocol - 2.20.138 + 2.29.16 software.amazon.awssdk rds - 2.28.14 + 2.29.16 diff --git a/aws-rds-dbshardgroup/pom.xml b/aws-rds-dbshardgroup/pom.xml index a04bd236a..aa34625cb 100644 --- a/aws-rds-dbshardgroup/pom.xml +++ b/aws-rds-dbshardgroup/pom.xml @@ -34,7 +34,7 @@ software.amazon.awssdk rds - 2.28.14 + 2.29.16 @@ -53,7 +53,7 @@ software.amazon.awssdk aws-query-protocol - 2.20.138 + 2.29.16 diff --git a/aws-rds-dbsubnetgroup/pom.xml b/aws-rds-dbsubnetgroup/pom.xml index 08e99d52c..c676f80b2 100644 --- a/aws-rds-dbsubnetgroup/pom.xml +++ b/aws-rds-dbsubnetgroup/pom.xml @@ -24,12 +24,12 @@ software.amazon.awssdk aws-query-protocol - 2.20.138 + 2.29.16 software.amazon.awssdk rds - 2.28.14 + 2.29.16 diff --git a/aws-rds-eventsubscription/pom.xml b/aws-rds-eventsubscription/pom.xml index c258780c6..29b79f89d 100644 --- a/aws-rds-eventsubscription/pom.xml +++ b/aws-rds-eventsubscription/pom.xml @@ -24,7 +24,7 @@ software.amazon.awssdk aws-query-protocol - 2.20.138 + 2.29.16 software.amazon.rds.common @@ -35,7 +35,7 @@ software.amazon.awssdk rds - 2.28.14 + 2.29.16 diff --git a/aws-rds-globalcluster/pom.xml b/aws-rds-globalcluster/pom.xml index 963d85c95..4ad0be8ca 100644 --- a/aws-rds-globalcluster/pom.xml +++ b/aws-rds-globalcluster/pom.xml @@ -24,7 +24,7 @@ software.amazon.awssdk aws-query-protocol - 2.20.138 + 2.29.16 software.amazon.rds.common @@ -35,7 +35,7 @@ software.amazon.awssdk rds - 2.28.14 + 2.29.16 diff --git a/aws-rds-integration/pom.xml b/aws-rds-integration/pom.xml index f1c9fb3aa..827b0f1aa 100644 --- a/aws-rds-integration/pom.xml +++ b/aws-rds-integration/pom.xml @@ -23,12 +23,12 @@ software.amazon.awssdk aws-query-protocol - 2.20.138 + 2.29.16 software.amazon.awssdk rds - 2.28.14 + 2.29.16 diff --git a/aws-rds-optiongroup/pom.xml b/aws-rds-optiongroup/pom.xml index dce9d0c62..ffe6fe473 100644 --- a/aws-rds-optiongroup/pom.xml +++ b/aws-rds-optiongroup/pom.xml @@ -24,12 +24,12 @@ software.amazon.awssdk aws-query-protocol - 2.20.138 + 2.29.16 software.amazon.awssdk rds - 2.28.14 + 2.29.16 diff --git a/aws-rds-optiongroup/src/main/java/software/amazon/rds/optiongroup/ClientBuilder.java b/aws-rds-optiongroup/src/main/java/software/amazon/rds/optiongroup/ClientBuilder.java index a8dd6eb56..af55228d0 100644 --- a/aws-rds-optiongroup/src/main/java/software/amazon/rds/optiongroup/ClientBuilder.java +++ b/aws-rds-optiongroup/src/main/java/software/amazon/rds/optiongroup/ClientBuilder.java @@ -3,8 +3,6 @@ import static software.amazon.awssdk.core.client.config.SdkAdvancedClientOption.USER_AGENT_PREFIX; import static software.amazon.awssdk.core.client.config.SdkAdvancedClientOption.USER_AGENT_SUFFIX; -import software.amazon.awssdk.core.retry.RetryPolicy; -import software.amazon.awssdk.core.retry.conditions.RetryCondition; import software.amazon.awssdk.services.rds.RdsClient; import software.amazon.awssdk.services.rds.RdsClientBuilder; import software.amazon.rds.common.client.BaseSdkClientProvider; @@ -12,18 +10,13 @@ public class ClientBuilder extends BaseSdkClientProvider { - private static final int MAX_RETRIES = 5; - - private static final RetryPolicy RETRY_POLICY = RetryPolicy.builder() - .numRetries(MAX_RETRIES) - .retryCondition(RetryCondition.defaultRetryCondition()) - .build(); + private static final int MAX_ATTEMPTS = 6; private RdsClientBuilder setUserAgentAndRetryPolicy(final RdsClientBuilder builder) { return builder.overrideConfiguration(cfg -> { cfg.putAdvancedOption(USER_AGENT_PREFIX, RdsUserAgentProvider.getUserAgentPrefix()) .putAdvancedOption(USER_AGENT_SUFFIX, RdsUserAgentProvider.getUserAgentSuffix()) - .retryPolicy(RETRY_POLICY); + .retryStrategy(b -> b.maxAttempts(MAX_ATTEMPTS)); }); }