Skip to content

Commit

Permalink
[GlobalCluster] Added major version upgrade support to globalCluster … (
Browse files Browse the repository at this point in the history
#360)

Allow in-place Major Version Upgrade of Global Clusters

Authored-by: Charles Ren <rfei@amazon.com>
  • Loading branch information
feiyuren233 authored Nov 24, 2022
1 parent 3726860 commit b3f18f6
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 12 deletions.
3 changes: 1 addition & 2 deletions aws-rds-globalcluster/aws-rds-globalcluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@
"/properties/GlobalClusterIdentifier",
"/properties/SourceDBClusterIdentifier",
"/properties/StorageEncrypted",
"/properties/Engine",
"/properties/EngineVersion"
"/properties/Engine"
],
"primaryIdentifier": [
"/properties/GlobalClusterIdentifier"
Expand Down
2 changes: 1 addition & 1 deletion aws-rds-globalcluster/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ _Required_: No

_Type_: String

_Update requires_: [Replacement](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-replacement)
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

#### DeletionProtection

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package software.amazon.rds.globalcluster;

import java.util.Objects;

import software.amazon.awssdk.services.rds.model.CreateGlobalClusterRequest;
import software.amazon.awssdk.services.rds.model.ModifyGlobalClusterRequest;
import software.amazon.awssdk.services.rds.model.DescribeGlobalClustersRequest;
Expand Down Expand Up @@ -33,11 +35,23 @@ static CreateGlobalClusterRequest createGlobalClusterRequest(final ResourceModel
.build();
}

static ModifyGlobalClusterRequest modifyGlobalClusterRequest(final ResourceModel model) {
return ModifyGlobalClusterRequest.builder()
.globalClusterIdentifier(model.getGlobalClusterIdentifier())
.deletionProtection(model.getDeletionProtection())
.build();
static ModifyGlobalClusterRequest modifyGlobalClusterRequest(
final ResourceModel previousModel,
final ResourceModel desiredModel,
final boolean isRollback
) {
ModifyGlobalClusterRequest.Builder builder = ModifyGlobalClusterRequest.builder()
.globalClusterIdentifier(desiredModel.getGlobalClusterIdentifier())
.deletionProtection(desiredModel.getDeletionProtection());

if (previousModel != null) {
if (!(isRollback || Objects.equals(previousModel.getEngineVersion(), desiredModel.getEngineVersion()))) {
builder.engineVersion(desiredModel.getEngineVersion());
builder.allowMajorVersionUpgrade(true);
}
}

return builder.build();
}

static DeleteGlobalClusterRequest deleteGlobalClusterRequest(final ResourceModel model) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package software.amazon.rds.globalcluster;

import org.apache.commons.lang3.BooleanUtils;

import software.amazon.awssdk.services.rds.RdsClient;
import software.amazon.awssdk.services.rds.model.DescribeGlobalClustersRequest;
import software.amazon.cloudformation.proxy.Logger;
import software.amazon.cloudformation.proxy.ProgressEvent;
import software.amazon.cloudformation.proxy.AmazonWebServicesClientProxy;
Expand All @@ -15,15 +16,16 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(final Amaz
final ProxyClient<RdsClient> proxyClient,
final Logger logger) {

ResourceModel model = request.getDesiredResourceState();
ResourceModel previousModel = request.getPreviousResourceState();
ResourceModel desiredModel = request.getDesiredResourceState();

return proxy.initiate("rds::update-global-cluster", proxyClient, request.getDesiredResourceState(), callbackContext)
// request to update global cluster
.translateToServiceRequest(Translator::modifyGlobalClusterRequest)
.translateToServiceRequest(model -> Translator.modifyGlobalClusterRequest(previousModel, desiredModel, BooleanUtils.isTrue(request.getRollback())))
.backoffDelay(BACKOFF_STRATEGY)
.makeServiceCall((modifyGlobalClusterRequest, proxyClient1) -> proxyClient1.injectCredentialsAndInvokeV2(modifyGlobalClusterRequest, proxyClient1.client()::modifyGlobalCluster))
.stabilize(((modifyGlobalClusterRequest, modifyGlobalClusterResponse, proxyClient1, resourceModel, callbackContext1) ->
isGlobalClusterStabilized(proxyClient1, model)))
isGlobalClusterStabilized(proxyClient1, desiredModel)))
.progress()
.then(progress -> new ReadHandler().handleRequest(proxy, request, callbackContext, proxyClient, logger));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ public class AbstractTestBase {
protected static final String SOURCECLUSTER_IDENTIFIER;
protected static final String SOURCECLUSTER_ARN;
protected static final String ENGINE_VERSION;
protected static final String ENGINE_VERSION_MVU;
protected static final String ENGINE;
protected static final boolean DELETION_PROTECTION;

protected static final ResourceModel RESOURCE_MODEL;
protected static final ResourceModel RESOURCE_MODEL_UPDATE;
protected static final ResourceModel RESOURCE_MODEL_UPDATE_MVU;
protected static final ResourceModel RESOURCE_MODEL_ALTERNATIVE;
protected static final ResourceModel RESOURCE_MODEL_WITH_MASTER;
protected static final ResourceModel RESOURCE_MODEL_WITH_MASTER_ARN;
Expand All @@ -59,6 +61,7 @@ public class AbstractTestBase {
SOURCECLUSTER_ARN = "arn:aws:rds:us-east-1:340834135580:cluster:sample-globalcluster";
ENGINE = "aurora";
ENGINE_VERSION = "5.6.mysql_aurora.1.22.2";
ENGINE_VERSION_MVU = "5.7.mysql_aurora.2.10.2";
DELETION_PROTECTION = false;


Expand Down Expand Up @@ -109,6 +112,13 @@ public class AbstractTestBase {
RESOURCE_MODEL_UPDATE = ResourceModel.builder()
.globalClusterIdentifier(GLOBALCLUSTER_IDENTIFIER)
.deletionProtection(DELETION_PROTECTION)
.engineVersion(ENGINE_VERSION)
.build();

RESOURCE_MODEL_UPDATE_MVU = ResourceModel.builder()
.globalClusterIdentifier(GLOBALCLUSTER_IDENTIFIER)
.deletionProtection(DELETION_PROTECTION)
.engineVersion(ENGINE_VERSION_MVU)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,31 @@ public void handleRequest_SimpleSuccess() {
verifyNoMoreInteractions(rds);
}

@Test
public void handleRequest_EngineVersionUpgrade() {
final ModifyGlobalClusterResponse modifyGlobalClusterResponse = ModifyGlobalClusterResponse.builder().build();
when(proxyRdsClient.client().modifyGlobalCluster(any(ModifyGlobalClusterRequest.class))).thenReturn(modifyGlobalClusterResponse);
final DescribeGlobalClustersResponse describeGlobalClustersResponse = DescribeGlobalClustersResponse.builder().globalClusters(GLOBAL_CLUSTER_ACTIVE).build();
when(proxyRdsClient.client().describeGlobalClusters(any(DescribeGlobalClustersRequest.class))).thenReturn(describeGlobalClustersResponse);

final ResourceHandlerRequest<ResourceModel> request = ResourceHandlerRequest.<ResourceModel>builder()
.previousResourceState(RESOURCE_MODEL_UPDATE)
.desiredResourceState(RESOURCE_MODEL_UPDATE_MVU)
.build();
final ProgressEvent<ResourceModel, CallbackContext> response = handler.handleRequest(proxy, request, new CallbackContext(), proxyRdsClient, logger);
assertThat(response).isNotNull();
assertThat(response.getStatus()).isEqualTo(OperationStatus.SUCCESS);
assertThat(response.getCallbackDelaySeconds()).isEqualTo(0);
assertThat(response.getResourceModels()).isNull();
assertThat(response.getMessage()).isNull();
assertThat(response.getErrorCode()).isNull();

verify(proxyRdsClient.client()).modifyGlobalCluster(any(ModifyGlobalClusterRequest.class));
verify(proxyRdsClient.client(), times(2)).describeGlobalClusters(any(DescribeGlobalClustersRequest.class));
verify(rds, times(2)).serviceName();
verifyNoMoreInteractions(rds);
}

@Test
public void handleRequest_ReturnsFailedResponse_WhenRdsClientThrowsClusterNotFoundException() {
AwsErrorDetails awsErr = AwsErrorDetails.builder().sdkHttpResponse(SdkHttpResponse.builder().statusCode(404).build()).build();
Expand Down

0 comments on commit b3f18f6

Please sign in to comment.