mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
feat(redshift): implement Redshift emulation with snapshot and parameter group support (#2472)
* feat: add redshift domain models
* feat: add redshift service and test
* feat: add redshift query handler and routing
* feat(redshift): implement data plane container manager and wire storage
This commit implements Redshift Container Manager, wires the StorageFactory into RedshiftService, uses AwsException for error handling, implements Describe/Delete Clusters, and adds integration tests with AWS SDK in the compatibility tests project.
* feat: add redshift operations models and service logic
* fix: correct yaml indentation for redshift storage config
* fix: remove invalid redshift storage properties
* feat: implement pg_dump and psql for redshift snapshots
* feat: add redshift core operations query actions
* test: add redshift operations integration test
* fix(redshift): Write snapshot SQL dumps to file storage and add Parameter model
* docs: add redshift implementation plan, design spec, and PR description
* chore: remove superpowers working files
* fix(redshift): scope snapshots and cluster recovery per account, restore original password
- Scope snapshot SQL dump files under redshift-dumps/{accountId}/ so
same-identifier snapshots from different accounts no longer collide,
overwrite, or delete each other's data.
- Restore uses the source cluster's real master password instead of a
hardcoded value, falling back to "admin" only when the source cluster
no longer exists.
- Recreate Docker containers for all persisted "available" clusters on
startup, across every account (not just the default), fixing clusters
that were reloaded with stale endpoints but no running container.
- Add AccountAwareStorageBackend.accountId() accessor needed for the
account-scoped dump path.
* fix(redshift): add logging for cleanup failures in RedshiftOperationsTest
* fix(redshift): scope container identity per account, persist snapshot password
- RedshiftContainerManager now keys its in-memory container map and Docker
container name by accountId + clusterIdentifier, instead of just the
cluster identifier. Previously two accounts creating a cluster with the
same identifier would share (and clobber) the same Docker container,
so startup recovery for the second account silently skipped its own
cluster and left it advertised with a stale endpoint.
- Snapshot now captures masterPassword at snapshot-creation time, so
restoreFromClusterSnapshot can recover the original credential even
after the source cluster has been deleted, instead of falling back to
"admin".
- Clean up fully-qualified java.nio.file / commons-compress references in
RedshiftContainerManager in favor of imports.
* feat(redshift): implement adoptOrStart method to reuse existing containers
* chore: gitignore subagent-driven-development scratch workspace
* feat(redshift): add tagging support to RedshiftService
- Add tags field to Cluster, Snapshot, and ClusterParameterGroup models
- Inject RegionResolver into RedshiftService constructor
- Implement tag CRUD methods: createTags, deleteTags, describeTags, listTagsForResource
- Add resolveTagHandle ARN resolver for tagging operations
- Add 6 new unit tests covering tag operations and error cases
* feat(redshift): wire CreateTags/DeleteTags/DescribeTags into the query handler
* feat(redshift): store real parameter values on ClusterParameterGroup
* fix(redshift): use proper imports and preserve parameter metadata on modify
* feat(redshift): wire ModifyClusterParameterGroup, return real DescribeClusterParameters values
* feat(redshift): add ClusterSubnetGroup model and CRUD
* feat(redshift): wire ClusterSubnetGroup CRUD into the query handler
* feat(redshift): add ClusterSubnetGroupName/VpcSecurityGroupIds metadata to Cluster
* feat(redshift): add RedshiftContainerManager.alterUserPassword
* fix(redshift): prevent SQL injection in alterUserPassword via username validation
* feat(redshift): add RedshiftService.modifyCluster
* feat(redshift): add RedshiftService.rebootCluster (dump/restore based, no data loss)
* feat(redshift): wire ModifyCluster/RebootCluster into the query handler
* test(redshift): add compatibility coverage for tagging, subnet groups, modify/reboot
* fix(redshift): use imports and unique names in compatibility test
Follow this file's established conventions: proper imports instead of
fully-qualified SDK types, and TestFixtures.uniqueName() instead of
hardcoded resource names, matching the pattern used by the sibling
test methods.
* fix(redshift): address final whole-branch review findings
* fix(redshift): address PR review feedback and green the CI
Review comments:
- Translate three Vietnamese comments in RedshiftContainerManager and
RedshiftService to English (repo is English-only).
- alterUserPassword: reword the single-quote guard to cite the AWS
ModifyCluster MasterUserPassword constraint rather than the psql SQL
literal, and enforce the full documented set for parity — reject
' " \ / @, require length 8-64 and at least one upper/lower/digit.
- adoptOrStart: LOG.warnv on the container-gone branch so a fresh empty
cluster after a lost container is a searchable line, not a silent one.
- Move the .superpowers/ scratch ignore from the shared .gitignore to
.git/info/exclude (local tooling, not project output).
CI failures:
- Register redshift.model.Parameter for reflection so
PersistedModelReflectionTest passes and native-image persistence works
(fixes CI shard 3 and the native sdk-test-java compat run).
- Convert RedshiftQueryHandler.handle() from an if/else chain to
switch (action) so the docs action-table generator can extract the
action list, matching every other Query handler. Bodies unchanged.
- Register redshift in tools/docs/services.yaml, add docs/services/redshift.md
with the generated action table, and add the Service Matrix row in
docs/services/index.md (fixes Docs Action Tables / Action tables in sync).
* fix(redshift): reject path traversal in SnapshotIdentifier
createSnapshot spliced the request's SnapshotIdentifier straight into a
host path (<persistentPath>/redshift-dumps/<accountId>/<id>.sql). A value
with traversal segments or an absolute prefix escaped the account dump
directory: snapshot creation would write pg_dump output over an arbitrary
host file, and the resulting absolute path was persisted so a later
restore (arbitrary read into an attacker-controlled DB) or delete
(arbitrary unlink) trusted it.
- validateSnapshotIdentifier: enforce AWS's format (1-255 chars, leading
letter, letters/digits/non-consecutive hyphens) — rejects '.', '/', '\'
so no separator can appear.
- Keep a normalise + startsWith(dumpDir) containment check as defence in
depth.
- restore/delete now verify the stored sqlDump path still resolves inside
the account dump dir before touching it, so a path written by the
pre-fix code can't be acted on.
Also replace inline java.* fully-qualified names in RedshiftService and
RedshiftQueryHandler with top-of-file imports.
* fix(redshift): validate snapshot dump path before restore provisioning
The trusted-dump-path check added in the previous commit ran inside the
try block, after restoreFromClusterSnapshot had already persisted the
target cluster as "creating" and started its container. Rejecting an
untrusted path then left the container running and a "failed" cluster
record behind, blocking a retry with the same identifier
(ClusterAlreadyExists).
Move the check ahead of all provisioning — right after the snapshot is
loaded, before clusters.put and containerManager.start — so a rejected
restore creates no resources.
---------
Signed-off-by: Vũ Thế Huy <31652864+vuthehuyht@users.noreply.github.com>
This commit is contained in:
1 parent
08e532ab1a
commit
a1383fdd3d
29 files changed
+4600
No files matched your search
@@ -26,6 +26,7 @@ import software.amazon.awssdk.services.lambda.LambdaClient;
|
||||
import software.amazon.awssdk.services.opensearch.OpenSearchClient;
|
||||
import software.amazon.awssdk.services.neptune.NeptuneClient;
|
||||
import software.amazon.awssdk.services.rds.RdsClient;
|
||||
import software.amazon.awssdk.services.redshift.RedshiftClient;
|
||||
import software.amazon.awssdk.services.guardduty.GuardDutyClient;
|
||||
import software.amazon.awssdk.services.fis.FisClient;
|
||||
import software.amazon.awssdk.services.organizations.OrganizationsClient;
|
||||
@@ -1030,4 +1031,12 @@ public final class TestFixtures {
|
||||
.credentialsProvider(CREDENTIALS)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static RedshiftClient redshiftClient() {
|
||||
return RedshiftClient.builder()
|
||||
.endpointOverride(ENDPOINT)
|
||||
.region(REGION)
|
||||
.credentialsProvider(CREDENTIALS)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
+336
@@ -0,0 +1,336 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import software.amazon.awssdk.services.redshift.RedshiftClient;
|
||||
import software.amazon.awssdk.services.redshift.model.Cluster;
|
||||
import software.amazon.awssdk.services.redshift.model.ClusterParameterGroup;
|
||||
import software.amazon.awssdk.services.redshift.model.CreateClusterParameterGroupRequest;
|
||||
import software.amazon.awssdk.services.redshift.model.CreateClusterParameterGroupResponse;
|
||||
import software.amazon.awssdk.services.redshift.model.CreateClusterRequest;
|
||||
import software.amazon.awssdk.services.redshift.model.CreateClusterResponse;
|
||||
import software.amazon.awssdk.services.redshift.model.CreateClusterSnapshotRequest;
|
||||
import software.amazon.awssdk.services.redshift.model.CreateClusterSnapshotResponse;
|
||||
import software.amazon.awssdk.services.redshift.model.CreateClusterSubnetGroupRequest;
|
||||
import software.amazon.awssdk.services.redshift.model.CreateTagsRequest;
|
||||
import software.amazon.awssdk.services.redshift.model.DeleteClusterParameterGroupRequest;
|
||||
import software.amazon.awssdk.services.redshift.model.DeleteClusterRequest;
|
||||
import software.amazon.awssdk.services.redshift.model.DeleteClusterSnapshotRequest;
|
||||
import software.amazon.awssdk.services.redshift.model.DeleteClusterSubnetGroupRequest;
|
||||
import software.amazon.awssdk.services.redshift.model.DeleteTagsRequest;
|
||||
import software.amazon.awssdk.services.redshift.model.DescribeClusterParameterGroupsRequest;
|
||||
import software.amazon.awssdk.services.redshift.model.DescribeClusterParameterGroupsResponse;
|
||||
import software.amazon.awssdk.services.redshift.model.DescribeClusterSnapshotsRequest;
|
||||
import software.amazon.awssdk.services.redshift.model.DescribeClusterSnapshotsResponse;
|
||||
import software.amazon.awssdk.services.redshift.model.DescribeClusterSubnetGroupsRequest;
|
||||
import software.amazon.awssdk.services.redshift.model.DescribeClustersRequest;
|
||||
import software.amazon.awssdk.services.redshift.model.DescribeClustersResponse;
|
||||
import software.amazon.awssdk.services.redshift.model.DescribeTagsRequest;
|
||||
import software.amazon.awssdk.services.redshift.model.ModifyClusterRequest;
|
||||
import software.amazon.awssdk.services.redshift.model.RebootClusterRequest;
|
||||
import software.amazon.awssdk.services.redshift.model.RestoreFromClusterSnapshotRequest;
|
||||
import software.amazon.awssdk.services.redshift.model.RestoreFromClusterSnapshotResponse;
|
||||
import software.amazon.awssdk.services.redshift.model.Snapshot;
|
||||
import software.amazon.awssdk.services.redshift.model.Tag;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@DisplayName("Redshift Operations")
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class RedshiftOperationsTest {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(RedshiftOperationsTest.class.getName());
|
||||
|
||||
private static final String USERNAME = "admin";
|
||||
private static final String PASSWORD = "password123";
|
||||
private static final String DATABASE = "dev";
|
||||
|
||||
private static RedshiftClient client;
|
||||
private static final List<String> clustersToCleanup = new ArrayList<>();
|
||||
private static final List<String> snapshotsToCleanup = new ArrayList<>();
|
||||
private static final List<String> parameterGroupsToCleanup = new ArrayList<>();
|
||||
private static final List<String> subnetGroupsToCleanup = new ArrayList<>();
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
client = TestFixtures.redshiftClient();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (client != null) {
|
||||
for (String clusterId : clustersToCleanup) {
|
||||
try {
|
||||
client.deleteCluster(DeleteClusterRequest.builder()
|
||||
.clusterIdentifier(clusterId)
|
||||
.build());
|
||||
} catch (Exception e) {
|
||||
LOG.log(Level.WARNING, "Failed to clean up Redshift cluster " + clusterId, e);
|
||||
}
|
||||
}
|
||||
for (String snapId : snapshotsToCleanup) {
|
||||
try {
|
||||
client.deleteClusterSnapshot(DeleteClusterSnapshotRequest.builder()
|
||||
.snapshotIdentifier(snapId)
|
||||
.build());
|
||||
} catch (Exception e) {
|
||||
LOG.log(Level.WARNING, "Failed to clean up Redshift snapshot " + snapId, e);
|
||||
}
|
||||
}
|
||||
for (String pgName : parameterGroupsToCleanup) {
|
||||
try {
|
||||
client.deleteClusterParameterGroup(DeleteClusterParameterGroupRequest.builder()
|
||||
.parameterGroupName(pgName)
|
||||
.build());
|
||||
} catch (Exception e) {
|
||||
LOG.log(Level.WARNING, "Failed to clean up Redshift parameter group " + pgName, e);
|
||||
}
|
||||
}
|
||||
for (String subnetGroupName : subnetGroupsToCleanup) {
|
||||
try {
|
||||
client.deleteClusterSubnetGroup(DeleteClusterSubnetGroupRequest.builder()
|
||||
.clusterSubnetGroupName(subnetGroupName)
|
||||
.build());
|
||||
} catch (Exception e) {
|
||||
LOG.log(Level.WARNING, "Failed to clean up Redshift cluster subnet group " + subnetGroupName, e);
|
||||
}
|
||||
}
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
@DisplayName("Create cluster, insert data, snapshot, restore to new cluster, verify data")
|
||||
void testSnapshotAndRestoreLifecycle() throws Exception {
|
||||
String sourceClusterId = TestFixtures.uniqueName("rs-source");
|
||||
String restoredClusterId = TestFixtures.uniqueName("rs-restored");
|
||||
String snapshotId = TestFixtures.uniqueName("rs-snap");
|
||||
|
||||
clustersToCleanup.add(sourceClusterId);
|
||||
clustersToCleanup.add(restoredClusterId);
|
||||
snapshotsToCleanup.add(snapshotId);
|
||||
|
||||
// 1. Create source cluster
|
||||
CreateClusterResponse createRes = client.createCluster(CreateClusterRequest.builder()
|
||||
.clusterIdentifier(sourceClusterId)
|
||||
.nodeType("dc2.large")
|
||||
.masterUsername(USERNAME)
|
||||
.masterUserPassword(PASSWORD)
|
||||
.build());
|
||||
|
||||
assertThat(createRes.cluster()).isNotNull();
|
||||
assertThat(createRes.cluster().clusterIdentifier()).isEqualTo(sourceClusterId);
|
||||
|
||||
DescribeClustersResponse descRes = client.describeClusters(DescribeClustersRequest.builder()
|
||||
.clusterIdentifier(sourceClusterId)
|
||||
.build());
|
||||
Cluster sourceCluster = descRes.clusters().get(0);
|
||||
assertThat(sourceCluster.endpoint()).isNotNull();
|
||||
String sourceHost = sourceCluster.endpoint().address();
|
||||
int sourcePort = sourceCluster.endpoint().port();
|
||||
|
||||
// 2. Use JDBC to create a table and insert a row
|
||||
try (Connection conn = awaitPostgresConnection(sourceHost, sourcePort, USERNAME, PASSWORD);
|
||||
Statement stmt = conn.createStatement()) {
|
||||
stmt.execute("CREATE TABLE test_data (id INT PRIMARY KEY, name VARCHAR(100));");
|
||||
stmt.execute("INSERT INTO test_data (id, name) VALUES (1, 'floci-redshift-snapshot-val');");
|
||||
}
|
||||
|
||||
// 3. Call createClusterSnapshot via AWS SDK
|
||||
CreateClusterSnapshotResponse snapRes = client.createClusterSnapshot(CreateClusterSnapshotRequest.builder()
|
||||
.snapshotIdentifier(snapshotId)
|
||||
.clusterIdentifier(sourceClusterId)
|
||||
.build());
|
||||
|
||||
Snapshot snapshot = snapRes.snapshot();
|
||||
assertThat(snapshot).isNotNull();
|
||||
assertThat(snapshot.snapshotIdentifier()).isEqualTo(snapshotId);
|
||||
assertThat(snapshot.clusterIdentifier()).isEqualTo(sourceClusterId);
|
||||
assertThat(snapshot.status()).isEqualTo("available");
|
||||
|
||||
DescribeClusterSnapshotsResponse descSnapRes = client.describeClusterSnapshots(DescribeClusterSnapshotsRequest.builder()
|
||||
.snapshotIdentifier(snapshotId)
|
||||
.build());
|
||||
assertThat(descSnapRes.snapshots()).isNotEmpty();
|
||||
assertThat(descSnapRes.snapshots().get(0).snapshotIdentifier()).isEqualTo(snapshotId);
|
||||
|
||||
// 4. Delete source cluster
|
||||
client.deleteCluster(DeleteClusterRequest.builder()
|
||||
.clusterIdentifier(sourceClusterId)
|
||||
.build());
|
||||
clustersToCleanup.remove(sourceClusterId);
|
||||
|
||||
// 5. Restore from snapshot to a new cluster identifier
|
||||
RestoreFromClusterSnapshotResponse restoreRes = client.restoreFromClusterSnapshot(
|
||||
RestoreFromClusterSnapshotRequest.builder()
|
||||
.clusterIdentifier(restoredClusterId)
|
||||
.snapshotIdentifier(snapshotId)
|
||||
.nodeType("dc2.large")
|
||||
.build());
|
||||
|
||||
Cluster restoredCluster = restoreRes.cluster();
|
||||
assertThat(restoredCluster).isNotNull();
|
||||
assertThat(restoredCluster.clusterIdentifier()).isEqualTo(restoredClusterId);
|
||||
assertThat(restoredCluster.endpoint()).isNotNull();
|
||||
|
||||
String restoredHost = restoredCluster.endpoint().address();
|
||||
int restoredPort = restoredCluster.endpoint().port();
|
||||
|
||||
// 6. Use JDBC to query restored cluster and verify row exists
|
||||
try (Connection conn = awaitPostgresConnection(restoredHost, restoredPort, USERNAME, PASSWORD);
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT name FROM test_data WHERE id = 1;")) {
|
||||
assertThat(rs.next()).isTrue();
|
||||
assertThat(rs.getString("name")).isEqualTo("floci-redshift-snapshot-val");
|
||||
}
|
||||
|
||||
// Cleanup restored cluster and snapshot
|
||||
client.deleteCluster(DeleteClusterRequest.builder()
|
||||
.clusterIdentifier(restoredClusterId)
|
||||
.build());
|
||||
clustersToCleanup.remove(restoredClusterId);
|
||||
|
||||
client.deleteClusterSnapshot(DeleteClusterSnapshotRequest.builder()
|
||||
.snapshotIdentifier(snapshotId)
|
||||
.build());
|
||||
snapshotsToCleanup.remove(snapshotId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
@DisplayName("Create, describe, and delete cluster parameter group")
|
||||
void testClusterParameterGroupLifecycle() {
|
||||
String pgName = TestFixtures.uniqueName("rs-pg");
|
||||
parameterGroupsToCleanup.add(pgName);
|
||||
|
||||
// 1. Create cluster parameter group
|
||||
CreateClusterParameterGroupResponse createPgRes = client.createClusterParameterGroup(
|
||||
CreateClusterParameterGroupRequest.builder()
|
||||
.parameterGroupName(pgName)
|
||||
.parameterGroupFamily("redshift-1.0")
|
||||
.description("Test parameter group for Redshift")
|
||||
.build());
|
||||
|
||||
ClusterParameterGroup pg = createPgRes.clusterParameterGroup();
|
||||
assertThat(pg).isNotNull();
|
||||
assertThat(pg.parameterGroupName()).isEqualTo(pgName);
|
||||
assertThat(pg.parameterGroupFamily()).isEqualTo("redshift-1.0");
|
||||
assertThat(pg.description()).isEqualTo("Test parameter group for Redshift");
|
||||
|
||||
// 2. Describe cluster parameter groups
|
||||
DescribeClusterParameterGroupsResponse descPgRes = client.describeClusterParameterGroups(
|
||||
DescribeClusterParameterGroupsRequest.builder()
|
||||
.parameterGroupName(pgName)
|
||||
.build());
|
||||
|
||||
assertThat(descPgRes.parameterGroups()).isNotEmpty();
|
||||
ClusterParameterGroup foundPg = descPgRes.parameterGroups().stream()
|
||||
.filter(g -> pgName.equals(g.parameterGroupName()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
assertThat(foundPg).isNotNull();
|
||||
assertThat(foundPg.parameterGroupFamily()).isEqualTo("redshift-1.0");
|
||||
assertThat(foundPg.description()).isEqualTo("Test parameter group for Redshift");
|
||||
|
||||
// 3. Delete cluster parameter group
|
||||
client.deleteClusterParameterGroup(DeleteClusterParameterGroupRequest.builder()
|
||||
.parameterGroupName(pgName)
|
||||
.build());
|
||||
parameterGroupsToCleanup.remove(pgName);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void testTaggingAndSubnetGroupAndModify() {
|
||||
// Cluster subnet group
|
||||
String subnetGroupName = TestFixtures.uniqueName("rs-subnet-group");
|
||||
client.createClusterSubnetGroup(CreateClusterSubnetGroupRequest.builder()
|
||||
.clusterSubnetGroupName(subnetGroupName)
|
||||
.description("SDK test subnet group")
|
||||
.subnetIds("subnet-aaa", "subnet-bbb")
|
||||
.build());
|
||||
subnetGroupsToCleanup.add(subnetGroupName);
|
||||
|
||||
var describedGroups = client.describeClusterSubnetGroups(
|
||||
DescribeClusterSubnetGroupsRequest.builder()
|
||||
.clusterSubnetGroupName(subnetGroupName)
|
||||
.build());
|
||||
assertThat(describedGroups.clusterSubnetGroups()).hasSize(1);
|
||||
assertThat(describedGroups.clusterSubnetGroups().get(0).subnets()).hasSize(2);
|
||||
|
||||
// Cluster + tagging + modify + reboot
|
||||
String clusterId = TestFixtures.uniqueName("rs-tag-cluster");
|
||||
CreateClusterResponse created = client.createCluster(CreateClusterRequest.builder()
|
||||
.clusterIdentifier(clusterId)
|
||||
.nodeType("dc2.large")
|
||||
.masterUsername(USERNAME)
|
||||
.masterUserPassword(PASSWORD)
|
||||
.build());
|
||||
clustersToCleanup.add(clusterId);
|
||||
String arn = "arn:aws:redshift:us-east-1:000000000000:cluster:" + clusterId;
|
||||
|
||||
client.createTags(CreateTagsRequest.builder()
|
||||
.resourceName(arn)
|
||||
.tags(Tag.builder().key("env").value("test").build())
|
||||
.build());
|
||||
|
||||
var described = client.describeTags(DescribeTagsRequest.builder()
|
||||
.resourceName(arn)
|
||||
.build());
|
||||
assertThat(described.taggedResources()).anyMatch(t -> "env".equals(t.tag().key()) && "test".equals(t.tag().value()));
|
||||
|
||||
client.deleteTags(DeleteTagsRequest.builder()
|
||||
.resourceName(arn)
|
||||
.tagKeys("env")
|
||||
.build());
|
||||
|
||||
var modified = client.modifyCluster(ModifyClusterRequest.builder()
|
||||
.clusterIdentifier(clusterId)
|
||||
.nodeType("ra3.xlplus")
|
||||
.build());
|
||||
assertThat(modified.cluster().nodeType()).isEqualTo("ra3.xlplus");
|
||||
|
||||
var rebooted = client.rebootCluster(RebootClusterRequest.builder()
|
||||
.clusterIdentifier(clusterId)
|
||||
.build());
|
||||
assertThat(rebooted.cluster().clusterStatus()).isEqualTo("available");
|
||||
}
|
||||
|
||||
private static Connection awaitPostgresConnection(String host, int port, String username, String password) throws Exception {
|
||||
Instant deadline = Instant.now().plus(Duration.ofSeconds(60));
|
||||
SQLException last = null;
|
||||
while (Instant.now().isBefore(deadline)) {
|
||||
try {
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("user", username);
|
||||
properties.setProperty("password", password);
|
||||
properties.setProperty("sslmode", "disable");
|
||||
properties.setProperty("connectTimeout", "5");
|
||||
return DriverManager.getConnection("jdbc:postgresql://" + host + ":" + port + "/" + DATABASE, properties);
|
||||
} catch (SQLException e) {
|
||||
last = e;
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
throw last != null ? last : new SQLException("Timed out waiting for PostgreSQL connection at " + host + ":" + port);
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package io.github.hectorvent.floci.compat;
|
||||
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import software.amazon.awssdk.services.redshift.RedshiftClient;
|
||||
import software.amazon.awssdk.services.redshift.model.Cluster;
|
||||
import software.amazon.awssdk.services.redshift.model.CreateClusterRequest;
|
||||
import software.amazon.awssdk.services.redshift.model.CreateClusterResponse;
|
||||
import software.amazon.awssdk.services.redshift.model.DescribeClustersRequest;
|
||||
import software.amazon.awssdk.services.redshift.model.DescribeClustersResponse;
|
||||
import software.amazon.awssdk.services.redshift.model.DeleteClusterRequest;
|
||||
import software.amazon.awssdk.services.redshift.model.DeleteClusterResponse;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
public class RedshiftTest {
|
||||
|
||||
private RedshiftClient getClient() {
|
||||
return RedshiftClient.builder()
|
||||
.region(software.amazon.awssdk.regions.Region.US_EAST_1)
|
||||
.credentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider.create(
|
||||
software.amazon.awssdk.auth.credentials.AwsBasicCredentials.create("test", "test")))
|
||||
.endpointOverride(java.net.URI.create("http://localhost:4566"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
public void testCreateCluster() throws Exception {
|
||||
RedshiftClient client = getClient();
|
||||
CreateClusterResponse res = client.createCluster(CreateClusterRequest.builder()
|
||||
.clusterIdentifier("test-cluster")
|
||||
.nodeType("dc2.large")
|
||||
.masterUsername("admin")
|
||||
.masterUserPassword("Password123")
|
||||
.build());
|
||||
|
||||
assertEquals("test-cluster", res.cluster().clusterIdentifier());
|
||||
|
||||
DescribeClustersResponse describeRes = client.describeClusters(DescribeClustersRequest.builder()
|
||||
.clusterIdentifier("test-cluster")
|
||||
.build());
|
||||
|
||||
Cluster cluster = describeRes.clusters().get(0);
|
||||
assertEquals("test-cluster", cluster.clusterIdentifier());
|
||||
assertNotNull(cluster.endpoint());
|
||||
|
||||
String address = cluster.endpoint().address();
|
||||
int port = cluster.endpoint().port();
|
||||
|
||||
String jdbcUrl = "jdbc:postgresql://" + address + ":" + port + "/dev";
|
||||
try (Connection conn = DriverManager.getConnection(jdbcUrl, "admin", "Password123")) {
|
||||
assertTrue(conn.isValid(5));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
public void testDeleteCluster() {
|
||||
RedshiftClient client = getClient();
|
||||
DeleteClusterResponse res = client.deleteCluster(DeleteClusterRequest.builder()
|
||||
.clusterIdentifier("test-cluster")
|
||||
.build());
|
||||
assertEquals("test-cluster", res.cluster().clusterIdentifier());
|
||||
assertEquals("deleting", res.cluster().clusterStatus());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user