diff --git a/aws-rds-customdbengineversion/src/main/java/software/amazon/rds/customdbengineversion/ListHandler.java b/aws-rds-customdbengineversion/src/main/java/software/amazon/rds/customdbengineversion/ListHandler.java index f521e66a1..b6d36f133 100644 --- a/aws-rds-customdbengineversion/src/main/java/software/amazon/rds/customdbengineversion/ListHandler.java +++ b/aws-rds-customdbengineversion/src/main/java/software/amazon/rds/customdbengineversion/ListHandler.java @@ -1,7 +1,11 @@ package software.amazon.rds.customdbengineversion; +import java.util.Collection; import java.util.List; +import org.apache.commons.lang3.StringUtils; + +import com.google.common.collect.ImmutableList; import software.amazon.awssdk.services.rds.RdsClient; import software.amazon.cloudformation.proxy.AmazonWebServicesClientProxy; import software.amazon.cloudformation.proxy.Logger; @@ -13,6 +17,14 @@ public class ListHandler extends BaseHandlerStd { + final static Collection CUSTOM_ENGINES = ImmutableList.of( + "custom-oracle-ee", + "custom-oracle-ee-cdb", + "custom-sqlserver-ee", + "custom-sqlserver-se", + "custom-sqlserver-web" + ); + public ListHandler() { this(CUSTOM_ENGINE_VERSION_HANDLER_CONFIG_10H); } @@ -28,13 +40,14 @@ protected ProgressEvent handleRequest(final Amaz final ProxyClient proxyClient, final Logger logger) { return proxy.initiate("rds::list-db-engine-versions", proxyClient, request.getDesiredResourceState(), callbackContext) - .translateToServiceRequest(resourceModel -> Translator.describeDbEngineVersionsRequest(resourceModel, request.getNextToken())) + .translateToServiceRequest(resourceModel -> Translator.describeDbEngineVersionsRequest(resourceModel, CUSTOM_ENGINES, request.getNextToken())) .backoffDelay(config.getBackoff()) .makeServiceCall((describeRequest, proxyInvocation) -> proxyInvocation.injectCredentialsAndInvokeV2( describeRequest, proxyInvocation.client()::describeDBEngineVersions )).done((describeRequest, describeResponse, proxyInvocation, resourceModel, context) -> { - final List resourceModels = Translator.translateFromSdk(describeResponse.dbEngineVersions().stream()); + final List resourceModels = Translator.translateFromSdk(describeResponse.dbEngineVersions().stream() + .filter(dbEngineVersion -> StringUtils.isNotBlank(dbEngineVersion.dbEngineVersionArn()))); return ProgressEvent.builder() .callbackContext(callbackContext) .resourceModels(resourceModels) diff --git a/aws-rds-customdbengineversion/src/main/java/software/amazon/rds/customdbengineversion/Translator.java b/aws-rds-customdbengineversion/src/main/java/software/amazon/rds/customdbengineversion/Translator.java index abc2477fa..f7a15c252 100644 --- a/aws-rds-customdbengineversion/src/main/java/software/amazon/rds/customdbengineversion/Translator.java +++ b/aws-rds-customdbengineversion/src/main/java/software/amazon/rds/customdbengineversion/Translator.java @@ -12,11 +12,15 @@ import software.amazon.awssdk.services.rds.model.DBEngineVersion; import software.amazon.awssdk.services.rds.model.DeleteCustomDbEngineVersionRequest; import software.amazon.awssdk.services.rds.model.DescribeDbEngineVersionsRequest; +import software.amazon.awssdk.services.rds.model.Filter; import software.amazon.awssdk.services.rds.model.ModifyCustomDbEngineVersionRequest; import software.amazon.rds.common.handler.Tagging; import software.amazon.rds.common.util.DifferenceUtils; public class Translator { + + public static final String ENGINE_FILTER_NAME = "engine"; + public static CreateCustomDbEngineVersionRequest createCustomDbEngineVersionRequest( final ResourceModel model, final Tagging.TagSet tags @@ -110,13 +114,17 @@ static ResourceModel translateFromSdk( .build(); } - public static DescribeDbEngineVersionsRequest describeDbEngineVersionsRequest(final ResourceModel model, + public static DescribeDbEngineVersionsRequest describeDbEngineVersionsRequest(final ResourceModel model, final Collection engines, final String nextToken) { return DescribeDbEngineVersionsRequest.builder() .engine(model.getEngine()) .engineVersion(model.getEngineVersion()) - .marker(nextToken) + .filters(Filter.builder() + .name(ENGINE_FILTER_NAME) + .values(engines) + .build()) .includeAll(true) + .marker(nextToken) .build(); } diff --git a/aws-rds-customdbengineversion/src/test/java/software/amazon/rds/customdbengineversion/ListHandlerTest.java b/aws-rds-customdbengineversion/src/test/java/software/amazon/rds/customdbengineversion/ListHandlerTest.java index 0e1682e3a..23d539f06 100644 --- a/aws-rds-customdbengineversion/src/test/java/software/amazon/rds/customdbengineversion/ListHandlerTest.java +++ b/aws-rds-customdbengineversion/src/test/java/software/amazon/rds/customdbengineversion/ListHandlerTest.java @@ -19,6 +19,7 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import com.google.common.collect.ImmutableList; import lombok.Getter; import software.amazon.awssdk.services.rds.RdsClient; import software.amazon.awssdk.services.rds.model.DBEngineVersion; @@ -32,6 +33,7 @@ @ExtendWith(MockitoExtension.class) public class ListHandlerTest extends AbstractHandlerTest { + public static final String ARN_123456789123_UE_EAST_1_RDS_ENGINVEVERSION = "arn:123456789123:ue-east-1:rds:enginveversion:"; final String DB_ENGINE_VERSION = "db-engine-version"; final String ENGINE = "engine"; @@ -74,6 +76,7 @@ public void handleRequest_SimpleSuccess() { DBEngineVersion.builder() .engineVersion(DB_ENGINE_VERSION) .engine(ENGINE) + .dbEngineVersionArn(ARN_123456789123_UE_EAST_1_RDS_ENGINVEVERSION + "test-oracle-ee") .tagList(Lists.newArrayList()) .build() )) @@ -93,6 +96,7 @@ public void handleRequest_SimpleSuccess() { final ResourceModel expectedModel = ResourceModel.builder() .engineVersion(DB_ENGINE_VERSION) .engine(ENGINE) + .dBEngineVersionArn(ARN_123456789123_UE_EAST_1_RDS_ENGINVEVERSION + "test-oracle-ee") .tags(Lists.newArrayList()) .build(); @@ -101,4 +105,51 @@ public void handleRequest_SimpleSuccess() { verify(rdsProxy.client()).describeDBEngineVersions(any(DescribeDbEngineVersionsRequest.class)); } + + @Test + public void handleRequest_retrieveOnlyCustomEngineVersion() { + final DescribeDbEngineVersionsResponse describeDBEngineVersionsResponse = DescribeDbEngineVersionsResponse.builder() + .dbEngineVersions(ImmutableList.of( + DBEngineVersion.builder() + .engineVersion("92.1") + .engine("custom-oracle-ee") + .dbEngineVersionArn(ARN_123456789123_UE_EAST_1_RDS_ENGINVEVERSION + "test-oracle-ee") + .tagList(Lists.newArrayList()) + .build(), + DBEngineVersion.builder() + .engineVersion(DB_ENGINE_VERSION) + .engine("custom-oracle-ee-cdb") + .dbEngineVersionArn(ARN_123456789123_UE_EAST_1_RDS_ENGINVEVERSION + "test-oracle-ee-cdb") + .tagList(Lists.newArrayList()) + .build(), + DBEngineVersion.builder() + .engineVersion(DB_ENGINE_VERSION) + .engine("custom-sqlserver-se") + .dbEngineVersionArn(ARN_123456789123_UE_EAST_1_RDS_ENGINVEVERSION + "test-sqlserver-se") + .tagList(Lists.newArrayList()) + .build(), + DBEngineVersion.builder() + .engineVersion(DB_ENGINE_VERSION) + .engine("custom-sqlserver-web") + .tagList(Lists.newArrayList()) + .build() + )) + .marker(DESCRIBE_DB_ENGINE_VERSIONS_MARKER) + .build(); + when(rdsProxy.client().describeDBEngineVersions(any(DescribeDbEngineVersionsRequest.class))) + .thenReturn(describeDBEngineVersionsResponse); + + final ProgressEvent response = test_handleRequest_base( + new CallbackContext(), + null, + () -> RESOURCE_MODEL_BUILDER().build(), + () -> RESOURCE_MODEL_BUILDER().build(), + expectSuccess() + ); + + assertThat(response.getResourceModels()).isNotNull(); + assertThat(response.getResourceModels().size()).isEqualTo(3); + + verify(rdsProxy.client()).describeDBEngineVersions(any(DescribeDbEngineVersionsRequest.class)); + } }