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 784926105..772adc1c7 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 @@ -281,7 +281,12 @@ static ModifyDbClusterRequest modifyDbClusterRequest( .preferredBackupWindow(diff(previousModel.getPreferredBackupWindow(), desiredModel.getPreferredBackupWindow())) .preferredMaintenanceWindow(diff(previousModel.getPreferredMaintenanceWindow(), desiredModel.getPreferredMaintenanceWindow())) .scalingConfiguration(translateScalingConfigurationToSdk(desiredModel.getScalingConfiguration())) - .serverlessV2ScalingConfiguration(translateServerlessV2ScalingConfiguration(desiredModel.getServerlessV2ScalingConfiguration())) + .serverlessV2ScalingConfiguration( + diff( + translateServerlessV2ScalingConfiguration(previousModel.getServerlessV2ScalingConfiguration()), + translateServerlessV2ScalingConfiguration(desiredModel.getServerlessV2ScalingConfiguration()) + ) + ) .storageType(desiredModel.getStorageType()); if (!(isRollback || Objects.equals(previousModel.getEngineVersion(), desiredModel.getEngineVersion()))) { diff --git a/aws-rds-dbcluster/src/test/java/software/amazon/rds/dbcluster/TranslatorTest.java b/aws-rds-dbcluster/src/test/java/software/amazon/rds/dbcluster/TranslatorTest.java index b2ecff742..bbb5a9cd7 100644 --- a/aws-rds-dbcluster/src/test/java/software/amazon/rds/dbcluster/TranslatorTest.java +++ b/aws-rds-dbcluster/src/test/java/software/amazon/rds/dbcluster/TranslatorTest.java @@ -10,8 +10,8 @@ import com.google.common.collect.ImmutableList; import software.amazon.awssdk.services.ec2.Ec2Client; import software.amazon.awssdk.services.rds.RdsClient; -import software.amazon.awssdk.services.rds.model.DBCluster; import software.amazon.awssdk.services.rds.model.CreateDbClusterRequest; +import software.amazon.awssdk.services.rds.model.DBCluster; import software.amazon.awssdk.services.rds.model.DomainMembership; import software.amazon.awssdk.services.rds.model.ModifyDbClusterRequest; import software.amazon.awssdk.services.rds.model.RestoreDbClusterFromSnapshotRequest; @@ -176,7 +176,7 @@ public void modifyDbClusterRequest_setStorageType() { .storageType(STORAGE_TYPE_GP3) .iops(100) .allocatedStorage(300) - .build(); + .build(); final ModifyDbClusterRequest request = Translator.modifyDbClusterRequest(previousModel, desiredModel, IS_NOT_ROLLBACK); assertThat(request.storageType()).isEqualTo(STORAGE_TYPE_GP3); @@ -184,6 +184,57 @@ public void modifyDbClusterRequest_setStorageType() { assertThat(request.allocatedStorage()).isEqualTo(300); } + @Test + public void modifyDbClusterRequest_setServerlessV2ScalingConfiguration() { + Double previousMax = 10.0; + Double desiredMax = 20.0; + Double previousMin = 1.0; + Double desiredMin = 2.0; + + final ResourceModel previousModel = RESOURCE_MODEL.toBuilder().serverlessV2ScalingConfiguration( + ServerlessV2ScalingConfiguration.builder() + .maxCapacity(previousMax) + .minCapacity(previousMin) + .build() + ).build(); + + final ResourceModel desiredModel = RESOURCE_MODEL.toBuilder().serverlessV2ScalingConfiguration( + ServerlessV2ScalingConfiguration.builder() + .maxCapacity(desiredMax) + .minCapacity(desiredMin) + .build() + ).build(); + + final ModifyDbClusterRequest request = Translator.modifyDbClusterRequest(previousModel, desiredModel, IS_NOT_ROLLBACK); + assertThat(request.serverlessV2ScalingConfiguration().minCapacity()).isEqualTo(desiredMin); + assertThat(request.serverlessV2ScalingConfiguration().maxCapacity()).isEqualTo(desiredMax); + } + + @Test + public void modifyDbClusterRequest_sameServerlessV2ScalingConfiguration() { + Double previousMax = 10.0; + Double desiredMax = 10.0; + Double previousMin = 1.0; + Double desiredMin = 1.0; + + final ResourceModel previousModel = RESOURCE_MODEL.toBuilder().serverlessV2ScalingConfiguration( + ServerlessV2ScalingConfiguration.builder() + .maxCapacity(previousMax) + .minCapacity(previousMin) + .build() + ).build(); + + final ResourceModel desiredModel = RESOURCE_MODEL.toBuilder().serverlessV2ScalingConfiguration( + ServerlessV2ScalingConfiguration.builder() + .maxCapacity(desiredMax) + .minCapacity(desiredMin) + .build() + ).build(); + + final ModifyDbClusterRequest request = Translator.modifyDbClusterRequest(previousModel, desiredModel, IS_NOT_ROLLBACK); + assertThat(request.serverlessV2ScalingConfiguration()).isEqualTo(null); + } + @Test public void test_translateDbClusterFromSdk_emptyDomainMembership() { final DBCluster cluster = DBCluster.builder()