Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(DBCluster): add SecondsUntilAutoPause to ServerlessV2ScalingConfiguration #582

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import software.amazon.awssdk.awscore.AwsResponse;
import software.amazon.awssdk.awscore.exception.AwsErrorDetails;
import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.cloudformation.exceptions.BaseHandlerException;
import software.amazon.cloudformation.proxy.HandlerErrorCode;
import software.amazon.cloudformation.proxy.OperationStatus;
import software.amazon.cloudformation.proxy.ProgressEvent;
Expand Down Expand Up @@ -109,7 +110,12 @@ protected ProgressEvent<ModelT, ContextT> test_handleRequest_base(
builder.clientRequestToken(newClientRequestToken());
builder.stackId(newStackId());

final ProgressEvent<ModelT, ContextT> response = invokeHandleRequest(builder.build(), context);
ProgressEvent<ModelT, ContextT> response;
try {
response = invokeHandleRequest(builder.build(), context);
} catch (final BaseHandlerException e) {
response = ProgressEvent.defaultFailureHandler(e, e.getErrorCode());
}
expect.accept(response);

return response;
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 @@ -720,16 +720,14 @@ public void handleRequest_CreateDBCluster_HandleException(
public void handleRequest_CreateDBCluster_DBClusterInTerminalState() {
final CallbackContext context = new CallbackContext();

Assertions.assertThatThrownBy(() -> {
test_handleRequest_base(
context,
() -> DBCLUSTER_ACTIVE.toBuilder()
.status(DBClusterStatus.InaccessibleEncryptionCredentials.toString())
.build(),
() -> RESOURCE_MODEL,
expectFailed(HandlerErrorCode.NotStabilized)
);
}).isInstanceOf(CfnNotStabilizedException.class);
test_handleRequest_base(
context,
() -> DBCLUSTER_ACTIVE.toBuilder()
.status(DBClusterStatus.InaccessibleEncryptionCredentials.toString())
.build(),
() -> RESOURCE_MODEL,
expectFailed(HandlerErrorCode.NotStabilized)
);

verify(rdsProxy.client(), times(1)).createDBCluster(any(CreateDbClusterRequest.class));
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -1344,18 +1344,16 @@ public void handleRequest_CreateDBInstance_OptionGroupInTerminalState() {
final CallbackContext context = new CallbackContext();
context.setCreated(false);

Assertions.assertThatThrownBy(() -> {
test_handleRequest_base(
context,
() -> DB_INSTANCE_ACTIVE.toBuilder()
.optionGroupMemberships(OptionGroupMembership.builder()
.status(OptionGroupStatus.Failed.toString())
.optionGroupName(OPTION_GROUP_NAME_MYSQL_DEFAULT)
.build()).build(),
() -> RESOURCE_MODEL_BLDR().build(),
expectFailed(HandlerErrorCode.NotStabilized)
);
}).isInstanceOf(CfnNotStabilizedException.class);
test_handleRequest_base(
context,
() -> DB_INSTANCE_ACTIVE.toBuilder()
.optionGroupMemberships(OptionGroupMembership.builder()
.status(OptionGroupStatus.Failed.toString())
.optionGroupName(OPTION_GROUP_NAME_MYSQL_DEFAULT)
.build()).build(),
() -> RESOURCE_MODEL_BLDR().build(),
expectFailed(HandlerErrorCode.NotStabilized)
);

verify(rdsProxy.client(), times(1)).createDBInstance(any(CreateDbInstanceRequest.class));
}
Expand All @@ -1365,18 +1363,16 @@ public void handleRequest_CreateDBInstance_DomainMembershipInTerminalState() {
final CallbackContext context = new CallbackContext();
context.setCreated(false);

Assertions.assertThatThrownBy(() -> {
test_handleRequest_base(
context,
() -> DB_INSTANCE_ACTIVE.toBuilder()
.domainMemberships(DomainMembership.builder()
.status(DomainMembershipStatus.Failed.toString())
.domain("domain")
.build()).build(),
() -> RESOURCE_MODEL_BLDR().build(),
expectFailed(HandlerErrorCode.NotStabilized)
);
}).isInstanceOf(CfnNotStabilizedException.class);
test_handleRequest_base(
context,
() -> DB_INSTANCE_ACTIVE.toBuilder()
.domainMemberships(DomainMembership.builder()
.status(DomainMembershipStatus.Failed.toString())
.domain("domain")
.build()).build(),
() -> RESOURCE_MODEL_BLDR().build(),
expectFailed(HandlerErrorCode.NotStabilized)
);

verify(rdsProxy.client(), times(1)).createDBInstance(any(CreateDbInstanceRequest.class));
}
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
Loading
Loading