Skip to content

Commit

Permalink
Only include diff of ServerlessV2ScalingConfiguration in ModifyDBClus…
Browse files Browse the repository at this point in the history
…ter. (#534)
  • Loading branch information
moataz-mhmd authored Apr 25, 2024
1 parent 546170a commit a372918
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -176,14 +176,65 @@ 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);
assertThat(request.iops()).isEqualTo(100);
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()
Expand Down

0 comments on commit a372918

Please sign in to comment.