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

[CustomDBEngineVersion] Update ListHandler logic to return only created custom #481

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
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,6 +17,14 @@

public class ListHandler extends BaseHandlerStd {

final static Collection<String> CUSTOM_ENGINES = ImmutableList.of(
moataz-mhmd marked this conversation as resolved.
Show resolved Hide resolved
"custom-oracle-ee",
"custom-oracle-ee-cdb",
"custom-sqlserver-ee",
"custom-sqlserver-se",
"custom-sqlserver-web"
moataz-mhmd marked this conversation as resolved.
Show resolved Hide resolved
);

public ListHandler() {
this(CUSTOM_ENGINE_VERSION_HANDLER_CONFIG_10H);
}
Expand All @@ -28,13 +40,14 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(final Amaz
final ProxyClient<RdsClient> 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<ResourceModel> resourceModels = Translator.translateFromSdk(describeResponse.dbEngineVersions().stream());
final List<ResourceModel> resourceModels = Translator.translateFromSdk(describeResponse.dbEngineVersions().stream()
.filter(dbEngineVersion -> StringUtils.isNotBlank(dbEngineVersion.dbEngineVersionArn())));
return ProgressEvent.<ResourceModel, CallbackContext>builder()
.callbackContext(callbackContext)
.resourceModels(resourceModels)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -110,13 +114,17 @@ static ResourceModel translateFromSdk(
.build();
}

public static DescribeDbEngineVersionsRequest describeDbEngineVersionsRequest(final ResourceModel model,
public static DescribeDbEngineVersionsRequest describeDbEngineVersionsRequest(final ResourceModel model, final Collection<String> 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)
moataz-mhmd marked this conversation as resolved.
Show resolved Hide resolved
.marker(nextToken)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";

Expand Down Expand Up @@ -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()
))
Expand All @@ -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();

Expand All @@ -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<ResourceModel, CallbackContext> 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));
}
}
Loading