Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(redshift): emit ClusterAvailabilityStatus and AvailabilityZoneRelocationStatus (#3109)

Vũ Thế Huy025ac714f6ba
diff --git a/compatibility-tests/sdk-test-java/src/test/java/io/github/hectorvent/floci/compat/RedshiftTest.java b/compatibility-tests/sdk-test-java/src/test/java/io/github/hectorvent/floci/compat/RedshiftTest.java
index 0d8f044e0b..28fa758ee9 100644
--- a/compatibility-tests/sdk-test-java/src/test/java/io/github/hectorvent/floci/compat/RedshiftTest.java
+++ b/compatibility-tests/sdk-test-java/src/test/java/io/github/hectorvent/floci/compat/RedshiftTest.java
@@ -44,6 +44,9 @@ public class RedshiftTest {
Cluster cluster = describeRes.clusters().get(0);
assertEquals("test-cluster", cluster.clusterIdentifier());
+ // Terraform's AWS provider polls these two on create and validates them on read (issue #3098).
+ assertEquals("Available", cluster.clusterAvailabilityStatus());
+ assertEquals("disabled", cluster.availabilityZoneRelocationStatus());
assertNotNull(cluster.endpoint());
String address = cluster.endpoint().address();
int port = cluster.endpoint().port();
diff --git a/src/main/java/io/github/hectorvent/floci/services/redshift/RedshiftQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/redshift/RedshiftQueryHandler.java
index c57252fa6a..b974fa0729 100644
--- a/src/main/java/io/github/hectorvent/floci/services/redshift/RedshiftQueryHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/redshift/RedshiftQueryHandler.java
@@ -425,6 +425,8 @@ public class RedshiftQueryHandler {
.elem("NodeType", cluster.getNodeType())
.elem("MasterUsername", cluster.getMasterUsername())
.elem("ClusterStatus", cluster.getClusterStatus())
+ .elem("ClusterAvailabilityStatus", availabilityStatus(cluster.getClusterStatus()))
+ .elem("AvailabilityZoneRelocationStatus", "disabled")
.elem("ClusterSubnetGroupName", cluster.getClusterSubnetGroupName());
if (cluster.getVpcSecurityGroupIds() != null && !cluster.getVpcSecurityGroupIds().isEmpty()) {
@@ -465,6 +467,21 @@ public class RedshiftQueryHandler {
return builder.end("Cluster").build();
}
+ // Terraform's AWS provider polls ClusterAvailabilityStatus during create and validates it on
+ // read, so DescribeClusters must always carry it. Floci has no maintenance window concept, and
+ // every transient lifecycle state (creating, deleting, rebooting, modifying) maps to Modifying.
+ private static String availabilityStatus(String clusterStatus) {
+ if (clusterStatus == null) {
+ return "Modifying";
+ }
+ return switch (clusterStatus) {
+ case "available" -> "Available";
+ case "unavailable" -> "Unavailable";
+ case "failed" -> "Failed";
+ default -> "Modifying";
+ };
+ }
+
private String buildSnapshotXml(Snapshot snapshot) {
XmlBuilder builder = new XmlBuilder()
.start("Snapshot")
diff --git a/src/test/java/io/github/hectorvent/floci/services/redshift/RedshiftOperationsTest.java b/src/test/java/io/github/hectorvent/floci/services/redshift/RedshiftOperationsTest.java
index c6a15db510..c47a26f99b 100644
--- a/src/test/java/io/github/hectorvent/floci/services/redshift/RedshiftOperationsTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/redshift/RedshiftOperationsTest.java
@@ -133,7 +133,9 @@ public class RedshiftOperationsTest {
.statusCode(200)
.contentType("application/xml")
.body(containsString("<ClusterIdentifier>cluster-src</ClusterIdentifier>"))
- .body(containsString("<ClusterStatus>available</ClusterStatus>"));
+ .body(containsString("<ClusterStatus>available</ClusterStatus>"))
+ .body(containsString("<ClusterAvailabilityStatus>Available</ClusterAvailabilityStatus>"))
+ .body(containsString("<AvailabilityZoneRelocationStatus>disabled</AvailabilityZoneRelocationStatus>"));
// 1b. RebootCluster — must preserve data (no Docker volume backs this container)
when(containerManager.getContainer(any(), eq("cluster-src")))
diff --git a/src/test/java/io/github/hectorvent/floci/services/redshift/RedshiftQueryHandlerTest.java b/src/test/java/io/github/hectorvent/floci/services/redshift/RedshiftQueryHandlerTest.java
index b062eeeacf..06807ed2b0 100644
--- a/src/test/java/io/github/hectorvent/floci/services/redshift/RedshiftQueryHandlerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/redshift/RedshiftQueryHandlerTest.java
@@ -69,7 +69,53 @@ class RedshiftQueryHandlerTest {
String xml = (String) response.getEntity();
assertTrue(xml.contains("<ClusterIdentifier>test-cluster</ClusterIdentifier>"));
}
-
+
+ @Test
+ void testDescribeClustersIncludesAvailabilityStatuses() {
+ MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
+ params.putSingle("ClusterIdentifier", "test-cluster");
+
+ Cluster cluster = new Cluster();
+ cluster.setClusterIdentifier("test-cluster");
+ cluster.setClusterStatus("available");
+ when(service.describeClusters(any())).thenReturn(List.of(cluster));
+
+ Response response = handler.handle("DescribeClusters", params);
+ String xml = (String) response.getEntity();
+ assertTrue(xml.contains("<ClusterAvailabilityStatus>Available</ClusterAvailabilityStatus>"));
+ assertTrue(xml.contains("<AvailabilityZoneRelocationStatus>disabled</AvailabilityZoneRelocationStatus>"));
+ }
+
+ @Test
+ void testClusterAvailabilityStatusMapsTransientStatesToModifying() {
+ MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
+ params.putSingle("ClusterIdentifier", "test-cluster");
+
+ Cluster cluster = new Cluster();
+ cluster.setClusterIdentifier("test-cluster");
+ cluster.setClusterStatus("creating");
+ when(service.createCluster(any(), any(), any(), any(), any(), any())).thenReturn(cluster);
+
+ Response response = handler.handle("CreateCluster", params);
+ String xml = (String) response.getEntity();
+ assertTrue(xml.contains("<ClusterAvailabilityStatus>Modifying</ClusterAvailabilityStatus>"));
+ }
+
+ @Test
+ void testClusterAvailabilityStatusMapsFailed() {
+ MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
+ params.putSingle("ClusterIdentifier", "test-cluster");
+
+ Cluster cluster = new Cluster();
+ cluster.setClusterIdentifier("test-cluster");
+ cluster.setClusterStatus("failed");
+ when(service.describeClusters(any())).thenReturn(List.of(cluster));
+
+ Response response = handler.handle("DescribeClusters", params);
+ String xml = (String) response.getEntity();
+ assertTrue(xml.contains("<ClusterAvailabilityStatus>Failed</ClusterAvailabilityStatus>"));
+ }
+
@Test
void testDeleteCluster() {
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();