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 22, 2024
1 parent c499488 commit dc9cb4b
Show file tree
Hide file tree
Showing 19 changed files with 67 additions and 54 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 @@ -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";
Expand Down Expand Up @@ -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));
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,14 @@ 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.");
}

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 @@ -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;
Expand Down Expand Up @@ -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)))
Expand All @@ -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(
Expand Down Expand Up @@ -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());
}

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

@Test
public void handleRequest_EngineLifecycleSupportShouldFail() {
void handleRequest_EngineLifecycleSupportShouldFail() {
expectServiceInvocation = false;
test_handleRequest_base(
new CallbackContext(),
Expand Down
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 dc9cb4b

Please sign in to comment.