Skip to content

armgit / floci

Public Imported from GitHub
0

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

fix(mq): return CreateBroker members from DescribeBroker (#5211)

Allen Sanborn73133b472a54
diff --git a/docs/services/amazonmq.md b/docs/services/amazonmq.md
index 5b853c44e8..5b23e34909 100644
--- a/docs/services/amazonmq.md
+++ b/docs/services/amazonmq.md
@@ -15,7 +15,7 @@ Only the **RabbitMQ** engine and the `SINGLE_INSTANCE` deployment mode are suppo
| Action | Description |
|---|---|
| `CreateBroker` | Provisions a RabbitMQ container and seeds the admin user |
-| `DescribeBroker` | Get broker metadata, state, and connection endpoints |
+| `DescribeBroker` | Get broker metadata, state, and connection endpoints; echoes the `CreateBroker` settings (security groups, subnets, maintenance window, storage type, authentication strategy, encryption options, and the configuration as `Configurations.Current`), and logs as a `LogsSummary` with the general log group |
| `ListBrokers` | List all emulated brokers |
| `DeleteBroker` | Stops and removes the RabbitMQ container |
| `RebootBroker` | Reboots the broker |
diff --git a/src/main/java/io/github/hectorvent/floci/services/amazonmq/AmazonMqController.java b/src/main/java/io/github/hectorvent/floci/services/amazonmq/AmazonMqController.java
index 115d68f29f..27c07cd3a9 100644
--- a/src/main/java/io/github/hectorvent/floci/services/amazonmq/AmazonMqController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/amazonmq/AmazonMqController.java
@@ -40,7 +40,15 @@ public class AmazonMqController {
bool(request, "publiclyAccessible"),
bool(request, "autoMinorVersionUpgrade"),
parseUsers(request.get("users")),
- tags(request.get("tags")));
+ tags(request.get("tags")),
+ strList(request.get("securityGroups")),
+ strList(request.get("subnetIds")),
+ map(request.get("logs")),
+ map(request.get("maintenanceWindowStartTime")),
+ str(request, "storageType"),
+ str(request, "authenticationStrategy"),
+ map(request.get("encryptionOptions")),
+ map(request.get("configuration")));
Broker broker = service.createBroker(params);
return Response.ok(Map.of(
"brokerArn", broker.getBrokerArn(),
@@ -91,9 +99,37 @@ public class AmazonMqController {
body.put("created", b.getCreated());
body.put("brokerInstances", b.getBrokerInstances());
body.put("tags", b.getTags());
+ // Optional CreateBroker members: omitted when the request did not set them.
+ putIfPresent(body, "securityGroups", b.getSecurityGroups());
+ putIfPresent(body, "subnetIds", b.getSubnetIds());
+ body.put("logs", logsSummary(b));
+ putIfPresent(body, "maintenanceWindowStartTime", b.getMaintenanceWindowStartTime());
+ putIfPresent(body, "storageType", b.getStorageType());
+ putIfPresent(body, "authenticationStrategy", b.getAuthenticationStrategy());
+ putIfPresent(body, "encryptionOptions", b.getEncryptionOptions());
+ // DescribeBroker reports the CreateBroker configuration as configurations.current.
+ if (b.getConfiguration() != null) {
+ body.put("configurations", Map.of("current", b.getConfiguration()));
+ }
return body;
}
+ // LogsSummary: general and generalLogGroup are required. Audit logs are ActiveMQ-only,
+ // so a RabbitMQ broker reports the general log group alone.
+ private static Map<String, Object> logsSummary(Broker b) {
+ boolean general = b.getLogs() != null && Boolean.TRUE.equals(b.getLogs().get("general"));
+ Map<String, Object> logs = new LinkedHashMap<>();
+ logs.put("general", general);
+ logs.put("generalLogGroup", b.generalLogGroup());
+ return logs;
+ }
+
+ private static void putIfPresent(Map<String, Object> body, String key, Object value) {
+ if (value != null) {
+ body.put(key, value);
+ }
+ }
+
@DELETE
@Path("/v1/brokers/{broker-id}")
public Response deleteBroker(@PathParam("broker-id") String brokerId) {
@@ -189,6 +225,15 @@ public class AmazonMqController {
return null;
}
+ private static Map<String, Object> map(Object raw) {
+ if (raw instanceof Map<?, ?> m) {
+ Map<String, Object> result = new LinkedHashMap<>();
+ m.forEach((k, v) -> result.put(String.valueOf(k), v));
+ return result;
+ }
+ return null;
+ }
+
@SuppressWarnings("unchecked")
private static List<MqUser> parseUsers(Object raw) {
if (!(raw instanceof List<?> list)) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/amazonmq/AmazonMqService.java b/src/main/java/io/github/hectorvent/floci/services/amazonmq/AmazonMqService.java
index 9f771401be..8652bddb8d 100644
--- a/src/main/java/io/github/hectorvent/floci/services/amazonmq/AmazonMqService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/amazonmq/AmazonMqService.java
@@ -141,6 +141,14 @@ public class AmazonMqService implements ResourceProvider {
if (params.tags() != null) {
broker.setTags(new HashMap<>(params.tags()));
}
+ broker.setSecurityGroups(params.securityGroups());
+ broker.setSubnetIds(params.subnetIds());
+ broker.setLogs(params.logs());
+ broker.setMaintenanceWindowStartTime(params.maintenanceWindowStartTime());
+ broker.setStorageType(params.storageType());
+ broker.setAuthenticationStrategy(params.authenticationStrategy());
+ broker.setEncryptionOptions(params.encryptionOptions());
+ broker.setConfiguration(params.configuration());
if (config.services().amazonmq().mock()) {
// No backing container: come up immediately with synthetic endpoints.
diff --git a/src/main/java/io/github/hectorvent/floci/services/amazonmq/CreateBrokerParams.java b/src/main/java/io/github/hectorvent/floci/services/amazonmq/CreateBrokerParams.java
index 0d988462cb..afceb9543b 100644
--- a/src/main/java/io/github/hectorvent/floci/services/amazonmq/CreateBrokerParams.java
+++ b/src/main/java/io/github/hectorvent/floci/services/amazonmq/CreateBrokerParams.java
@@ -20,5 +20,23 @@ public record CreateBrokerParams(
boolean publiclyAccessible,
boolean autoMinorVersionUpgrade,
List<MqUser> users,
- Map<String, String> tags) {
+ Map<String, String> tags,
+ List<String> securityGroups,
+ List<String> subnetIds,
+ Map<String, Object> logs,
+ Map<String, Object> maintenanceWindowStartTime,
+ String storageType,
+ String authenticationStrategy,
+ Map<String, Object> encryptionOptions,
+ Map<String, Object> configuration) {
+
+ /** The members every broker needs; the optional ones default to absent. */
+ public CreateBrokerParams(String brokerName, String engineType, String engineVersion,
+ String deploymentMode, String hostInstanceType,
+ boolean publiclyAccessible, boolean autoMinorVersionUpgrade,
+ List<MqUser> users, Map<String, String> tags) {
+ this(brokerName, engineType, engineVersion, deploymentMode, hostInstanceType,
+ publiclyAccessible, autoMinorVersionUpgrade, users, tags,
+ null, null, null, null, null, null, null, null);
+ }
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/amazonmq/container/RabbitMqManager.java b/src/main/java/io/github/hectorvent/floci/services/amazonmq/container/RabbitMqManager.java
index a1089cc5f0..8e9ebb6219 100644
--- a/src/main/java/io/github/hectorvent/floci/services/amazonmq/container/RabbitMqManager.java
+++ b/src/main/java/io/github/hectorvent/floci/services/amazonmq/container/RabbitMqManager.java
@@ -176,7 +176,7 @@ public class RabbitMqManager {
String shortId = info.containerId().length() >= 8
? info.containerId().substring(0, 8)
: info.containerId();
- String logGroup = "/aws/amazonmq/broker/" + broker.getBrokerId();
+ String logGroup = broker.generalLogGroup();
String logStream = logStreamer.generateLogStreamName(shortId);
String region = brokerRegion(broker);
Closeable logHandle = logStreamer.attach(
diff --git a/src/main/java/io/github/hectorvent/floci/services/amazonmq/model/Broker.java b/src/main/java/io/github/hectorvent/floci/services/amazonmq/model/Broker.java
index 0d1fa1f2b9..fc914638f1 100644
--- a/src/main/java/io/github/hectorvent/floci/services/amazonmq/model/Broker.java
+++ b/src/main/java/io/github/hectorvent/floci/services/amazonmq/model/Broker.java
@@ -63,6 +63,32 @@ public class Broker {
@JsonProperty("tags")
private Map<String, String> tags;
+ // Optional CreateBroker members, echoed back by DescribeBroker. Null when the
+ // request omitted them, and on records persisted before they were stored.
+ @JsonProperty("securityGroups")
+ private List<String> securityGroups;
+
+ @JsonProperty("subnetIds")
+ private List<String> subnetIds;
+
+ @JsonProperty("logs")
+ private Map<String, Object> logs;
+
+ @JsonProperty("maintenanceWindowStartTime")
+ private Map<String, Object> maintenanceWindowStartTime;
+
+ @JsonProperty("storageType")
+ private String storageType;
+
+ @JsonProperty("authenticationStrategy")
+ private String authenticationStrategy;
+
+ @JsonProperty("encryptionOptions")
+ private Map<String, Object> encryptionOptions;
+
+ @JsonProperty("configuration")
+ private Map<String, Object> configuration;
+
// Internal bookkeeping. These are NOT part of the AWS response shape, but they ARE
// persisted so the broker stays manageable after an emulator restart in persistent
// mode (container teardown, volume cleanup, account-aware storage routing). The
@@ -101,6 +127,12 @@ public class Broker {
}
public String getBrokerId() { return brokerId; }
+
+ /**
+ * The CloudWatch log group the broker's general logs go to, as DescribeBroker
+ * reports it. Not a getter, so Jackson neither persists nor returns it.
+ */
+ public String generalLogGroup() { return "/aws/amazonmq/broker/" + brokerId + "/general"; }
public void setBrokerId(String brokerId) { this.brokerId = brokerId; }
public String getBrokerArn() { return brokerArn; }
@@ -142,6 +174,30 @@ public class Broker {
public Map<String, String> getTags() { return tags; }
public void setTags(Map<String, String> tags) { this.tags = tags; }
+ public List<String> getSecurityGroups() { return securityGroups; }
+ public void setSecurityGroups(List<String> securityGroups) { this.securityGroups = securityGroups; }
+
+ public List<String> getSubnetIds() { return subnetIds; }
+ public void setSubnetIds(List<String> subnetIds) { this.subnetIds = subnetIds; }
+
+ public Map<String, Object> getLogs() { return logs; }
+ public void setLogs(Map<String, Object> logs) { this.logs = logs; }
+
+ public Map<String, Object> getMaintenanceWindowStartTime() { return maintenanceWindowStartTime; }
+ public void setMaintenanceWindowStartTime(Map<String, Object> maintenanceWindowStartTime) { this.maintenanceWindowStartTime = maintenanceWindowStartTime; }
+
+ public String getStorageType() { return storageType; }
+ public void setStorageType(String storageType) { this.storageType = storageType; }
+
+ public String getAuthenticationStrategy() { return authenticationStrategy; }
+ public void setAuthenticationStrategy(String authenticationStrategy) { this.authenticationStrategy = authenticationStrategy; }
+
+ public Map<String, Object> getEncryptionOptions() { return encryptionOptions; }
+ public void setEncryptionOptions(Map<String, Object> encryptionOptions) { this.encryptionOptions = encryptionOptions; }
+
+ public Map<String, Object> getConfiguration() { return configuration; }
+ public void setConfiguration(Map<String, Object> configuration) { this.configuration = configuration; }
+
public String getContainerId() { return containerId; }
public void setContainerId(String containerId) { this.containerId = containerId; }
diff --git a/src/test/java/io/github/hectorvent/floci/services/amazonmq/AmazonMqControllerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/amazonmq/AmazonMqControllerIntegrationTest.java
index 3596cc2e90..3745e9b418 100644
--- a/src/test/java/io/github/hectorvent/floci/services/amazonmq/AmazonMqControllerIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/amazonmq/AmazonMqControllerIntegrationTest.java
@@ -3,9 +3,13 @@ package io.github.hectorvent.floci.services.amazonmq;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
+import java.util.List;
+
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.hasKey;
+import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.startsWith;
@@ -50,6 +54,67 @@ class AmazonMqControllerIntegrationTest {
.body("volumeId", nullValue());
}
+ @Test
+ void describeBrokerReturnsCreateBrokerMembers() {
+ String brokerId = given()
+ .contentType("application/json")
+ .body("""
+ {"brokerName": "it-members", "engineType": "RABBITMQ",
+ "deploymentMode": "SINGLE_INSTANCE", "hostInstanceType": "mq.t3.micro",
+ "publiclyAccessible": false,
+ "securityGroups": ["sg-0123"], "subnetIds": ["subnet-0abc"],
+ "logs": {"general": true},
+ "maintenanceWindowStartTime": {"dayOfWeek": "MONDAY", "timeOfDay": "02:00", "timeZone": "UTC"},
+ "storageType": "EBS", "authenticationStrategy": "SIMPLE",
+ "encryptionOptions": {"kmsKeyId": "arn:aws:kms:us-east-1:000000000000:key/k1", "useAwsOwnedKey": false},
+ "configuration": {"id": "c-123", "revision": 2},
+ "users": [{"username": "admin", "password": "AdminPass123", "consoleAccess": true}]}
+ """)
+ .when()
+ .post("/v1/brokers")
+ .then()
+ .statusCode(200)
+ .extract().path("brokerId");
+
+ given()
+ .when()
+ .get("/v1/brokers/{id}", brokerId)
+ .then()
+ .statusCode(200)
+ .body("securityGroups", equalTo(List.of("sg-0123")))
+ .body("subnetIds", equalTo(List.of("subnet-0abc")))
+ .body("logs.general", equalTo(true))
+ .body("logs.generalLogGroup", equalTo("/aws/amazonmq/broker/" + brokerId + "/general"))
+ .body("maintenanceWindowStartTime.dayOfWeek", equalTo("MONDAY"))
+ .body("maintenanceWindowStartTime.timeOfDay", equalTo("02:00"))
+ .body("maintenanceWindowStartTime.timeZone", equalTo("UTC"))
+ .body("storageType", equalTo("EBS"))
+ .body("authenticationStrategy", equalTo("SIMPLE"))
+ .body("encryptionOptions.kmsKeyId", equalTo("arn:aws:kms:us-east-1:000000000000:key/k1"))
+ .body("encryptionOptions.useAwsOwnedKey", equalTo(false))
+ .body("configurations.current.id", equalTo("c-123"))
+ .body("configurations.current.revision", equalTo(2))
+ .body("configuration", nullValue())
+ // RabbitMQ users stay out of DescribeBroker (see createThenDescribeBroker).
+ .body("users", nullValue());
+ }
+
+ @Test
+ void describeBrokerOmitsUnsetOptionalMembers() {
+ String brokerId = createRabbitBroker("it-minimal");
+
+ given()
+ .when()
+ .get("/v1/brokers/{id}", brokerId)
+ .then()
+ .statusCode(200)
+ .body("$", not(hasKey("securityGroups")))
+ .body("logs.general", equalTo(false))
+ .body("logs.generalLogGroup", equalTo("/aws/amazonmq/broker/" + brokerId + "/general"))
+ .body("$", not(hasKey("configurations")))
+ .body("$", not(hasKey("encryptionOptions")));
+ }
+
@Test
void listBrokersIncludesCreated() {
createRabbitBroker("it-list");
diff --git a/src/test/java/io/github/hectorvent/floci/services/amazonmq/container/RabbitMqManagerTest.java b/src/test/java/io/github/hectorvent/floci/services/amazonmq/container/RabbitMqManagerTest.java
index 83ad8388de..c2d7512732 100644
--- a/src/test/java/io/github/hectorvent/floci/services/amazonmq/container/RabbitMqManagerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/amazonmq/container/RabbitMqManagerTest.java
@@ -20,6 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
@@ -161,6 +162,37 @@ class RabbitMqManagerTest {
assertEquals("http://172.17.0.5:15672", broker.getBrokerInstances().get(0).getConsoleURL());
}
+ /** Container logs stream to the log group DescribeBroker names as generalLogGroup. */
+ @Test
+ void startContainerStreamsLogsToGeneralLogGroup() {
+ EmulatorConfig config = configWithDefaultPortRanges();
+
+ ContainerLifecycleManager lifecycleManager = Mockito.mock(ContainerLifecycleManager.class);
+ when(lifecycleManager.createAndStart(any())).thenReturn(
+ new ContainerLifecycleManager.ContainerInfo("container-id", Map.of(
+ 5672, new ContainerLifecycleManager.EndpointInfo("localhost", 5672),
+ 15672, new ContainerLifecycleManager.EndpointInfo("localhost", 15672))));
+
+ ContainerBuilder containerBuilder = Mockito.mock(ContainerBuilder.class);
+ selfReturningBuilder(containerBuilder);
+
+ PortAllocator portAllocator = Mockito.mock(PortAllocator.class);
+ when(portAllocator.allocate(5672, 5699)).thenReturn(5672);
+ when(portAllocator.allocate(15672, 15699)).thenReturn(15672);
+
+ ContainerLogStreamer logStreamer = Mockito.mock(ContainerLogStreamer.class);
+ RabbitMqManager manager = new RabbitMqManager(containerBuilder, lifecycleManager,
+ logStreamer, Mockito.mock(ContainerDetector.class),
+ portAllocator, config, regionResolver());
+
+ Broker broker = broker("b-1");
+ manager.startContainer(broker);
+
+ assertEquals("/aws/amazonmq/broker/b-1/general", broker.generalLogGroup());
+ verify(logStreamer).attach(eq("container-id"), eq(broker.generalLogGroup()),
+ any(), any(), eq("amazonmq:b-1"));
+ }
+
/**
* The reservation must die with the container: without the release, repeated
* create/delete cycles exhaust the configured ranges and later brokers can
diff --git a/src/test/java/io/github/hectorvent/floci/services/amazonmq/model/BrokerTest.java b/src/test/java/io/github/hectorvent/floci/services/amazonmq/model/BrokerTest.java
index b52b9f0498..0a7b2c661c 100644
--- a/src/test/java/io/github/hectorvent/floci/services/amazonmq/model/BrokerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/amazonmq/model/BrokerTest.java
@@ -3,7 +3,11 @@ package io.github.hectorvent.floci.services.amazonmq.model;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
+import java.util.List;
+import java.util.Map;
+
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
class BrokerTest {
@@ -29,4 +33,35 @@ class BrokerTest {
assertEquals("000000000000", roundTripped.getAccountId());
assertEquals("a1b2c3", roundTripped.getVolumeId());
}
+
+ @Test
+ void createBrokerMembersPersistAcrossSerialization() throws Exception {
+ ObjectMapper mapper = new ObjectMapper().findAndRegisterModules();
+ Broker broker = new Broker("b-1", "arn", "n", "RABBITMQ", "3.13", "SINGLE_INSTANCE", "mq.t3.micro");
+ broker.setSecurityGroups(List.of("sg-1"));
+ broker.setMaintenanceWindowStartTime(Map.of("dayOfWeek", "MONDAY"));
+ broker.setConfiguration(Map.of("id", "c-1", "revision", 2));
+ broker.setStorageType("EBS");
+
+ Broker roundTripped = mapper.readValue(mapper.writeValueAsString(broker), Broker.class);
+
+ assertEquals(List.of("sg-1"), roundTripped.getSecurityGroups());
+ assertEquals(Map.of("dayOfWeek", "MONDAY"), roundTripped.getMaintenanceWindowStartTime());
+ assertEquals(Map.of("id", "c-1", "revision", 2), roundTripped.getConfiguration());
+ assertEquals("EBS", roundTripped.getStorageType());
+ }
+
+ /** A broker persisted before these members existed must still load, with them absent. */
+ @Test
+ void brokerPersistedWithoutNewMembersStillLoads() throws Exception {
+ ObjectMapper mapper = new ObjectMapper().findAndRegisterModules();
+ Broker old = mapper.readValue(
+ "{\"brokerId\":\"b-1\",\"brokerName\":\"n\",\"engineType\":\"RABBITMQ\",\"containerId\":\"c\"}",
+ Broker.class);
+
+ assertEquals("b-1", old.getBrokerId());
+ assertNull(old.getSecurityGroups());
+ assertNull(old.getConfiguration());
+ assertNull(old.getEncryptionOptions());
+ }
}