mirror of
https://github.com/floci-io/floci.git
synced 2026-11-26 15:21:05 -05:00
feat(redshift-serverless): add running workgroups and Data API WorkgroupName support (#5012)
* feat(redshift-serverless): add running workgroups and Data API WorkgroupName support Redshift Serverless workgroups get full CRUD (Create/Get/List/Update/Delete), tagging by ARN, and the AWS::RedshiftServerless::Namespace and ::Workgroup CloudFormation types with dotted Fn::GetAtt keys taken from the registry schema. A namespace has at most one workgroup, and DeleteNamespace is refused while one is attached. Each workgroup runs a PostgreSQL container behind an authenticating proxy, sharing the managers and the proxy port pool with provisioned Redshift. Add GetCredentials, accept WorkgroupName (name or ARN) in the Redshift Data API, and push a changed namespace adminUserPassword down to the running backend. The runtime is re-attached when Floci restarts. Not covered: snapshots, usage limits, endpoint access, and COPY/UNLOAD/Spectrum on workgroups. * fix(redshift-serverless): stop the runtime when workgroup creation fails after it started If persisting the workgroup record failed after the container and proxy were already running, the runtime was left behind with no record. createWorkgroup now stops it (best effort) and releases the endpoint on the failure path. Fix the CloudFormation error for a NamespaceName change: suggesting a new WorkgroupName can never succeed because a namespace holds only one workgroup. * fix(redshift-serverless): reset omitted CloudFormation properties and order startup observers When UpdateStack drops a property from the template, the provisioner now sends its default (BaseCapacity, EnhancedVpcRouting, PubliclyAccessible, Port, TrackName, PricePerformanceTarget) instead of keeping the stored value, which matches CloudFormation semantics. MaxCapacity has no default and keeps its stored value. Give the workgroup StartupEvent observer a @Priority after RedshiftService so every persisted cluster has reserved its proxy port before workgroups restore theirs. Also remove an unused import and move DEFAULT_DATABASE to the top of RedshiftContainerManager. * fix(redshift-serverless): address review findings on password rotation and namespace updates - Roll the backend password back when a rotation cannot be completed or stored, and apply it last so validation failures never leave the backend ahead of the stored namespace. - Keep a workgroup endpoint reserved when its runtime cannot be stopped during clear(). - Reject an in-place DbName change in CloudFormation, since it is fixed at creation. - Reset an omitted KmsKeyId and DefaultIamRoleArn on CloudFormation updates. * fix(redshift-serverless): keep rollback failures from masking errors and drop stale GetAtt role - Do not reset the proxy password when the role restore fails, and attach restore failures to the original exception instead of replacing it. - Remove Namespace.DefaultIamRoleArn from the stack resource when an update no longer declares a default role. * docs: correct the Redshift Serverless operation count in the service matrix * fix(redshift-serverless): expose Workgroup.ConfigParameters through Fn::GetAtt * fix(redshift-serverless): parse ConfigParameters resolved from a GetAtt attribute * docs(redshift-serverless): list every unsupported operation group
This commit is contained in:
1 parent
a84a8a0435
commit
99a6b4050c
36 files changed
+4028
-81
No files matched your search
+100
-1
@@ -3,19 +3,28 @@ package com.floci.test;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.services.redshiftdata.RedshiftDataClient;
|
||||
import software.amazon.awssdk.services.redshiftdata.model.DescribeStatementResponse;
|
||||
import software.amazon.awssdk.services.redshiftdata.model.ExecuteStatementResponse;
|
||||
import software.amazon.awssdk.services.redshiftdata.model.StatusString;
|
||||
import software.amazon.awssdk.services.redshiftserverless.RedshiftServerlessClient;
|
||||
import software.amazon.awssdk.services.redshiftserverless.model.GetCredentialsResponse;
|
||||
import software.amazon.awssdk.services.redshiftserverless.model.ConflictException;
|
||||
import software.amazon.awssdk.services.redshiftserverless.model.Namespace;
|
||||
import software.amazon.awssdk.services.redshiftserverless.model.NamespaceStatus;
|
||||
import software.amazon.awssdk.services.redshiftserverless.model.ResourceNotFoundException;
|
||||
import software.amazon.awssdk.services.redshiftserverless.model.Tag;
|
||||
import software.amazon.awssdk.services.redshiftserverless.model.Workgroup;
|
||||
import software.amazon.awssdk.services.redshiftserverless.model.WorkgroupStatus;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.Assertions.tuple;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
||||
|
||||
@DisplayName("Redshift Serverless namespace lifecycle")
|
||||
@DisplayName("Redshift Serverless namespace and workgroup lifecycle")
|
||||
class RedshiftServerlessTest {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(RedshiftServerlessTest.class);
|
||||
@@ -70,6 +79,96 @@ class RedshiftServerlessTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void workgroupLifecycleUsesAwsSdk() {
|
||||
assumeFalse(TestFixtures.isRealAws(), "Creates a workgroup and asserts emulator-local defaults");
|
||||
|
||||
try (RedshiftServerlessClient client = TestFixtures.redshiftServerlessClient();
|
||||
RedshiftDataClient dataClient = TestFixtures.redshiftDataClient()) {
|
||||
String namespaceName = "floci-compat-wg-ns";
|
||||
String workgroupName = "floci-compat-wg";
|
||||
try {
|
||||
client.createNamespace(request -> request
|
||||
.namespaceName(namespaceName)
|
||||
.adminUsername("admin")
|
||||
.adminUserPassword("Secret123!"));
|
||||
|
||||
Workgroup created = client.createWorkgroup(request -> request
|
||||
.workgroupName(workgroupName)
|
||||
.namespaceName(namespaceName)
|
||||
.baseCapacity(32)
|
||||
.tags(Tag.builder().key("env").value("dev").build())).workgroup();
|
||||
|
||||
assertThat(created.workgroupName()).isEqualTo(workgroupName);
|
||||
assertThat(created.namespaceName()).isEqualTo(namespaceName);
|
||||
assertThat(created.status()).isEqualTo(WorkgroupStatus.AVAILABLE);
|
||||
assertThat(created.baseCapacity()).isEqualTo(32);
|
||||
assertThat(created.port()).isEqualTo(5439);
|
||||
assertThat(created.trackName()).isEqualTo("current");
|
||||
assertThat(created.workgroupArn()).contains(":redshift-serverless:").contains(":workgroup/");
|
||||
assertThat(created.creationDate()).isNotNull();
|
||||
assertThat(created.endpoint().address()).isNotBlank();
|
||||
assertThat(created.endpoint().port()).isPositive();
|
||||
|
||||
Workgroup fetched = client.getWorkgroup(request -> request.workgroupName(workgroupName)).workgroup();
|
||||
assertThat(fetched.workgroupId()).isEqualTo(created.workgroupId());
|
||||
|
||||
assertThat(client.listWorkgroups(request -> {}).workgroups())
|
||||
.extracting(Workgroup::workgroupName)
|
||||
.contains(workgroupName);
|
||||
|
||||
Workgroup updated = client.updateWorkgroup(request -> request
|
||||
.workgroupName(workgroupName)
|
||||
.baseCapacity(64)).workgroup();
|
||||
assertThat(updated.baseCapacity()).isEqualTo(64);
|
||||
|
||||
assertThatThrownBy(() -> client.createWorkgroup(request -> request
|
||||
.workgroupName(workgroupName)
|
||||
.namespaceName(namespaceName)))
|
||||
.isInstanceOf(ConflictException.class);
|
||||
assertThatThrownBy(() -> client.deleteNamespace(request -> request.namespaceName(namespaceName)))
|
||||
.isInstanceOf(ConflictException.class);
|
||||
|
||||
GetCredentialsResponse credentials = client.getCredentials(request -> request
|
||||
.workgroupName(workgroupName)
|
||||
.dbName("dev"));
|
||||
assertThat(credentials.dbUser()).isNotBlank();
|
||||
assertThat(credentials.dbPassword()).isNotBlank();
|
||||
assertThat(credentials.expiration()).isAfter(Instant.now());
|
||||
|
||||
ExecuteStatementResponse executed = dataClient.executeStatement(request -> request
|
||||
.workgroupName(workgroupName)
|
||||
.database("dev")
|
||||
.sql("select 1"));
|
||||
assertThat(executed.workgroupName()).isEqualTo(workgroupName);
|
||||
assertThat(executed.clusterIdentifier()).isNull();
|
||||
DescribeStatementResponse described = dataClient.describeStatement(request -> request.id(executed.id()));
|
||||
assertThat(described.status()).isEqualTo(StatusString.FINISHED);
|
||||
|
||||
String arn = created.workgroupArn();
|
||||
client.tagResource(request -> request.resourceArn(arn)
|
||||
.tags(Tag.builder().key("team").value("data").build()));
|
||||
assertThat(client.listTagsForResource(request -> request.resourceArn(arn)).tags())
|
||||
.extracting(Tag::key)
|
||||
.contains("env", "team");
|
||||
} finally {
|
||||
deleteWorkgroupBestEffort(client, workgroupName);
|
||||
deleteBestEffort(client, namespaceName);
|
||||
}
|
||||
|
||||
assertThatThrownBy(() -> client.getWorkgroup(request -> request.workgroupName(workgroupName)))
|
||||
.isInstanceOf(ResourceNotFoundException.class);
|
||||
}
|
||||
}
|
||||
|
||||
private static void deleteWorkgroupBestEffort(RedshiftServerlessClient client, String workgroupName) {
|
||||
try {
|
||||
client.deleteWorkgroup(request -> request.workgroupName(workgroupName));
|
||||
} catch (Exception cleanupError) {
|
||||
LOG.warnf(cleanupError, "Best-effort cleanup failed for workgroupName=%s", workgroupName);
|
||||
}
|
||||
}
|
||||
|
||||
private static void deleteBestEffort(RedshiftServerlessClient client, String namespaceName) {
|
||||
try {
|
||||
client.deleteNamespace(request -> request.namespaceName(namespaceName));
|
||||
|
||||
Reference in new issue
Block a user