Skip to content

Commit

Permalink
feat(DBCluster): add SecondsUntilAutoPause to ServerlessV2ScalingConf…
Browse files Browse the repository at this point in the history
…iguration

Adds support for the automatic pause/resume feature of
Aurora Serverless v2.

Also bumping the AWS Java SDK to 2.29.16.
  • Loading branch information
zrfr committed Nov 19, 2024
1 parent 2cfe91a commit bcb37e4
Show file tree
Hide file tree
Showing 18 changed files with 96 additions and 51 deletions.
4 changes: 2 additions & 2 deletions aws-rds-cfn-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>utils</artifactId>
<version>2.28.14</version>
<version>2.29.16</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>rds</artifactId>
<version>2.28.14</version>
<version>2.29.16</version>
</dependency>
<dependency>
<groupId>software.amazon.cloudformation</groupId>
Expand Down
4 changes: 2 additions & 2 deletions aws-rds-customdbengineversion/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>rds</artifactId>
<version>2.28.14</version>
<version>2.29.16</version>
</dependency>
<dependency>
<groupId>software.amazon.rds.common</groupId>
Expand Down Expand Up @@ -54,7 +54,7 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-query-protocol</artifactId>
<version>2.20.138</version>
<version>2.29.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
<dependency>
Expand Down
3 changes: 3 additions & 0 deletions aws-rds-dbcluster/aws-rds-dbcluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions aws-rds-dbcluster/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>rds</artifactId>
<version>2.28.14</version>
<version>2.29.16</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>ec2</artifactId>
<version>2.28.14</version>
<version>2.29.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.awssdk/aws-query-protocol -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-query-protocol</artifactId>
<version>2.28.14</version>
<version>2.29.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.cloudformation/aws-cloudformation-rpdk-java-plugin -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,37 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
"Resource is immutable"
);
}

if (!Objects.equals(request.getDesiredResourceState().getEngineLifecycleSupport(),
request.getPreviousResourceState().getEngineLifecycleSupport()) &&
!request.getRollback()) {
throw new CfnInvalidRequestException("EngineLifecycleSupport cannot be modified.");
}

// Validate SecondsUntilAutoPause to avoid false drift detection.
// Note: we take a different approach with Serverless V1 - see setDefaults.

final var previousServerlessV2ScalingConfiguration = previousResourceState.getServerlessV2ScalingConfiguration();
final var desiredServerlessV2ScalingConfiguration = desiredResourceState.getServerlessV2ScalingConfiguration();

final var isServerlessV2Previous = previousServerlessV2ScalingConfiguration != null;
final var isServerlessV2Desired = desiredServerlessV2ScalingConfiguration != null;

if (isServerlessV2Previous && isServerlessV2Desired) {
final var isAutoPausePrevious = previousServerlessV2ScalingConfiguration.getMinCapacity() == 0;
final var isAutoPauseDesired = desiredServerlessV2ScalingConfiguration.getMinCapacity() == 0;

if (isAutoPausePrevious && isAutoPauseDesired) {
// Only allow SecondsUntilAutoPause to be removed when disabling auto-pause.
if (previousServerlessV2ScalingConfiguration.getSecondsUntilAutoPause() != null
&& desiredServerlessV2ScalingConfiguration.getSecondsUntilAutoPause() == null
&& !request.getRollback()) {
throw new CfnInvalidRequestException("SecondsUntilAutoPause must be specified.");
}
}
}

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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,9 @@ void handleRequest_ServerlessV2ScalingConfiguration_Success() {
.build();

final ServerlessV2ScalingConfiguration desiredServerlessV2ScalingConfiguration = ServerlessV2ScalingConfiguration.builder()
.minCapacity(3.0)
.minCapacity(0.0)
.maxCapacity(4.0)
.secondsUntilAutoPause(600)
.build();

test_handleRequest_base(
Expand Down Expand Up @@ -881,6 +882,7 @@ void handleRequest_ServerlessV2ScalingConfiguration_Success() {
.isEqualTo(software.amazon.awssdk.services.rds.model.ServerlessV2ScalingConfiguration.builder()
.maxCapacity(desiredServerlessV2ScalingConfiguration.getMaxCapacity())
.minCapacity(desiredServerlessV2ScalingConfiguration.getMinCapacity())
.secondsUntilAutoPause(desiredServerlessV2ScalingConfiguration.getSecondsUntilAutoPause())
.build());
}

Expand Down Expand Up @@ -997,7 +999,7 @@ void handleRequest_ModifyDBCluster_HandleException(
}

@Test
public void handleRequest_EngineLifecycleSupportShouldFail() {
void handleRequest_EngineLifecycleSupportShouldFail() {
expectServiceInvocation = false;
test_handleRequest_base(
new CallbackContext(),
Expand All @@ -1008,4 +1010,32 @@ public void handleRequest_EngineLifecycleSupportShouldFail() {
expectFailed(HandlerErrorCode.InvalidRequest)
);
}

@Test
void handleRequest_ServerlessV2ScalingConfiguration_RejectRemoveSecondsUntilAutoPause() {
final ServerlessV2ScalingConfiguration previousServerlessV2ScalingConfiguration = ServerlessV2ScalingConfiguration.builder()
.minCapacity(0.0)
.maxCapacity(2.0)
.secondsUntilAutoPause(300)
.build();

final ServerlessV2ScalingConfiguration desiredServerlessV2ScalingConfiguration = ServerlessV2ScalingConfiguration.builder()
.minCapacity(0.0)
.maxCapacity(4.0)
.build();

expectServiceInvocation = false;
test_handleRequest_base(
new CallbackContext(),
ResourceHandlerRequest.<ResourceModel>builder().rollback(false),
null,
() -> RESOURCE_MODEL.toBuilder()
.serverlessV2ScalingConfiguration(previousServerlessV2ScalingConfiguration)
.build(),
() -> RESOURCE_MODEL.toBuilder()
.serverlessV2ScalingConfiguration(desiredServerlessV2ScalingConfiguration)
.build(),
expectFailed(HandlerErrorCode.InvalidRequest)
);
}
}
4 changes: 2 additions & 2 deletions aws-rds-dbclusterendpoint/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>rds</artifactId>
<version>2.28.14</version>
<version>2.29.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.cloudformation/aws-cloudformation-rpdk-java-plugin -->
<dependency>
Expand Down Expand Up @@ -78,7 +78,7 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-query-protocol</artifactId>
<version>2.20.138</version>
<version>2.29.16</version>
</dependency>
<dependency>
<groupId>software.amazon.rds.common</groupId>
Expand Down
4 changes: 2 additions & 2 deletions aws-rds-dbclusterparametergroup/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>rds</artifactId>
<version>2.28.14</version>
<version>2.29.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.cloudformation/aws-cloudformation-rpdk-java-plugin -->
<dependency>
Expand Down Expand Up @@ -78,7 +78,7 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-query-protocol</artifactId>
<version>2.20.138</version>
<version>2.29.16</version>
</dependency>
<dependency>
<groupId>software.amazon.rds.common</groupId>
Expand Down
6 changes: 3 additions & 3 deletions aws-rds-dbinstance/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>rds</artifactId>
<version>2.28.14</version>
<version>2.29.16</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>ec2</artifactId>
<version>2.21.17</version>
<version>2.29.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.cloudformation/aws-cloudformation-rpdk-java-plugin -->
<dependency>
Expand All @@ -58,7 +58,7 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-query-protocol</artifactId>
<version>2.20.138</version>
<version>2.29.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions aws-rds-dbparametergroup/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-query-protocol</artifactId>
<version>2.20.138</version>
<version>2.29.16</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>rds</artifactId>
<version>2.28.14</version>
<version>2.29.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.cloudformation/aws-cloudformation-rpdk-java-plugin -->
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions aws-rds-dbshardgroup/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>rds</artifactId>
<version>2.28.14</version>
<version>2.29.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.cloudformation/aws-cloudformation-rpdk-java-plugin -->
<dependency>
Expand All @@ -53,7 +53,7 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-query-protocol</artifactId>
<version>2.20.138</version>
<version>2.29.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions aws-rds-dbsubnetgroup/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-query-protocol</artifactId>
<version>2.20.138</version>
<version>2.29.16</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>rds</artifactId>
<version>2.28.14</version>
<version>2.29.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.cloudformation/aws-cloudformation-rpdk-java-plugin -->
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions aws-rds-eventsubscription/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-query-protocol</artifactId>
<version>2.20.138</version>
<version>2.29.16</version>
</dependency>
<dependency>
<groupId>software.amazon.rds.common</groupId>
Expand All @@ -35,7 +35,7 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>rds</artifactId>
<version>2.28.14</version>
<version>2.29.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.cloudformation/aws-cloudformation-rpdk-java-plugin -->
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions aws-rds-globalcluster/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-query-protocol</artifactId>
<version>2.20.138</version>
<version>2.29.16</version>
</dependency>
<dependency>
<groupId>software.amazon.rds.common</groupId>
Expand All @@ -35,7 +35,7 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>rds</artifactId>
<version>2.28.14</version>
<version>2.29.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.cloudformation/aws-cloudformation-rpdk-java-plugin -->
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions aws-rds-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-query-protocol</artifactId>
<version>2.20.138</version>
<version>2.29.16</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>rds</artifactId>
<version>2.28.14</version>
<version>2.29.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.cloudformation/aws-cloudformation-rpdk-java-plugin -->
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions aws-rds-optiongroup/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-query-protocol</artifactId>
<version>2.20.138</version>
<version>2.29.16</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>rds</artifactId>
<version>2.28.14</version>
<version>2.29.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.cloudformation/aws-cloudformation-rpdk-java-plugin -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,20 @@
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;
import software.amazon.rds.common.client.RdsUserAgentProvider;

public class ClientBuilder extends BaseSdkClientProvider<RdsClientBuilder, RdsClient> {

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));
});
}

Expand Down

0 comments on commit bcb37e4

Please sign in to comment.