From cf44c351d999d0ab180b4c002d9c6f4c9a82d425 Mon Sep 17 00:00:00 2001 From: Valentin Shirshov Date: Wed, 3 Apr 2024 10:09:11 +0200 Subject: [PATCH] [DBInstance] Add support for IO2 storage (#528) * [DBInstance] Add support for IO2 storage Co-authored-by: Valentin Shirshov --- .../amazon/rds/dbinstance/StorageType.java | 3 +- .../amazon/rds/dbinstance/Translator.java | 6 ++- .../amazon/rds/dbinstance/TranslatorTest.java | 11 +++++ .../rds/dbinstance/UpdateHandlerTest.java | 44 +++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/aws-rds-dbinstance/src/main/java/software/amazon/rds/dbinstance/StorageType.java b/aws-rds-dbinstance/src/main/java/software/amazon/rds/dbinstance/StorageType.java index ce292133b..0af87304b 100644 --- a/aws-rds-dbinstance/src/main/java/software/amazon/rds/dbinstance/StorageType.java +++ b/aws-rds-dbinstance/src/main/java/software/amazon/rds/dbinstance/StorageType.java @@ -4,7 +4,8 @@ public enum StorageType { GP2("gp2"), GP3("gp3"), IO1("io1"), - MAGNETIC("magnetic"); + MAGNETIC("magnetic"), + IO2("io2"); private final String value; diff --git a/aws-rds-dbinstance/src/main/java/software/amazon/rds/dbinstance/Translator.java b/aws-rds-dbinstance/src/main/java/software/amazon/rds/dbinstance/Translator.java index 53520d6e3..06a1aaa3d 100644 --- a/aws-rds-dbinstance/src/main/java/software/amazon/rds/dbinstance/Translator.java +++ b/aws-rds-dbinstance/src/main/java/software/amazon/rds/dbinstance/Translator.java @@ -549,7 +549,7 @@ public static ModifyDbInstanceRequest modifyDbInstanceRequest( } private static Boolean isProvisionedIoStorage(final ResourceModel model) { - return isIo1Storage(model) || isGp3Storage(model); + return isIo1Storage(model) || isIo2Storage(model) || isGp3Storage(model); } private static Boolean isGp3Storage(final ResourceModel model) { @@ -561,6 +561,10 @@ private static Boolean isIo1Storage(final ResourceModel model) { (StringUtils.isEmpty(model.getStorageType()) && model.getIops() != null); } + private static Boolean isIo2Storage(final ResourceModel model) { + return StorageType.IO2.toString().equalsIgnoreCase(model.getStorageType()); + } + private static Boolean shouldDisableDomain(final ResourceModel previous, final ResourceModel desired) { return ObjectUtils.allNull(desired.getDomain(), desired.getDomainAuthSecretArn(), desired.getDomainDnsIps(), desired.getDomainFqdn(), desired.getDomainOu(), desired.getDomainIAMRoleName()) diff --git a/aws-rds-dbinstance/src/test/java/software/amazon/rds/dbinstance/TranslatorTest.java b/aws-rds-dbinstance/src/test/java/software/amazon/rds/dbinstance/TranslatorTest.java index c68975aaf..37a0b2562 100644 --- a/aws-rds-dbinstance/src/test/java/software/amazon/rds/dbinstance/TranslatorTest.java +++ b/aws-rds-dbinstance/src/test/java/software/amazon/rds/dbinstance/TranslatorTest.java @@ -927,6 +927,17 @@ public void modifyDbInstanceRequest_shouldIncludeAllocatedStorage_ifStorageTypeI assertThat(request.allocatedStorage()).isEqualTo(ALLOCATED_STORAGE); } + @Test + public void modifyDbInstanceRequest_shouldIncludeAllocatedStorageANdIops_ifStorageTypeIsIo1_andStorageTypeChangedToIo2() { + final ResourceModel previous = RESOURCE_MODEL_BLDR().storageType("io1").iops(1000).allocatedStorage("100").build(); + final ResourceModel desired = RESOURCE_MODEL_BLDR().storageType("io2").iops(1000).allocatedStorage("100").build(); + + final ModifyDbInstanceRequest request = Translator.modifyDbInstanceRequest(previous, desired, false); + + assertThat(request.iops()).isEqualTo(1000); + assertThat(request.allocatedStorage()).isEqualTo(100); + } + @Test public void modifyDbInstanceRequest_shouldIncludeAllocatedStorage_ifStorageTypeIsImplicitIo1_andIopsOnlyChanged() { final ResourceModel previous = RESOURCE_MODEL_BLDR().storageType(null).iops(1000).build(); diff --git a/aws-rds-dbinstance/src/test/java/software/amazon/rds/dbinstance/UpdateHandlerTest.java b/aws-rds-dbinstance/src/test/java/software/amazon/rds/dbinstance/UpdateHandlerTest.java index 65319a8da..24e1950de 100644 --- a/aws-rds-dbinstance/src/test/java/software/amazon/rds/dbinstance/UpdateHandlerTest.java +++ b/aws-rds-dbinstance/src/test/java/software/amazon/rds/dbinstance/UpdateHandlerTest.java @@ -1816,4 +1816,48 @@ public void handleRequest_stopAutomaticBackupReplication() { verifyNoMoreInteractions(crossRegionRdsProxy.client()); verify(rdsProxy.client(), times(4)).describeDBInstances(any(DescribeDbInstancesRequest.class)); } + + @Test + public void handleRequest_updateStorageTypeFromIo1ToIo2() { + final CallbackContext context = new CallbackContext(); + context.setCreated(true); + context.setUpdated(false); + context.setRebooted(true); + context.setUpdatedRoles(true); + context.setAddTagsComplete(true); + context.setAutomaticBackupReplicationStarted(true); + context.setAutomaticBackupReplicationStopped(true); + + when(rdsProxy.client().modifyDBInstance(any(ModifyDbInstanceRequest.class))) + .thenReturn(ModifyDbInstanceResponse.builder().build()); + when(rdsProxy.client().describeEvents(any(DescribeEventsRequest.class))) + .thenReturn(DescribeEventsResponse.builder().build()); + + test_handleRequest_base( + context, + () -> DB_INSTANCE_ACTIVE.toBuilder() + .build(), + () -> RESOURCE_MODEL_BLDR() + .storageType("io1") + .allocatedStorage("100") + .iops(1000) + .build(), + () -> RESOURCE_MODEL_BLDR() + .storageType("io2") + .allocatedStorage("100") + .iops(1000) + .build(), + expectSuccess() + ); + + verify(rdsProxy.client(), times(3)).describeDBInstances(any(DescribeDbInstancesRequest.class)); + + final ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(ModifyDbInstanceRequest.class); + verify(rdsProxy.client()).modifyDBInstance(argumentCaptor.capture()); + Assertions.assertThat(argumentCaptor.getValue().iops()).isEqualTo(1000); + Assertions.assertThat(argumentCaptor.getValue().allocatedStorage()).isEqualTo(100); + Assertions.assertThat(argumentCaptor.getValue().storageType()).isEqualTo("io2"); + + verify(rdsProxy.client(), times(1)).describeEvents(any(DescribeEventsRequest.class)); + } }