mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(mq): return CreateBroker members from DescribeBroker (#5211)
* fix(mq): return CreateBroker members from DescribeBroker CreateBroker accepted securityGroups, subnetIds, logs, maintenanceWindowStartTime, storageType, authenticationStrategy, encryptionOptions and configuration, but discarded them, so DescribeBroker never returned them. Carry them through CreateBrokerParams to the persisted Broker and into the DescribeBroker response, with configuration reported as configurations.current as in the AWS shape. Absent members are omitted, and brokers persisted before this change still load. RabbitMQ users stay out of DescribeBroker (#1951). * fix(mq): report DescribeBroker logs as a LogsSummary general and generalLogGroup are required in LogsSummary; general defaults to false and the log group is /aws/amazonmq/broker/<broker-id>/general. audit/auditLogGroup are reported only when audit logging was requested. * fix(mq): report only the general log group in LogsSummary Audit logs are ActiveMQ-only, and Floci emulates RabbitMQ brokers. Document DescribeBroker's logs as a LogsSummary rather than an echo. * fix(mq): stream broker logs to the general log group DescribeBroker reports RabbitMqManager streamed container logs to /aws/amazonmq/broker/<id> while DescribeBroker named /aws/amazonmq/broker/<id>/general. Both now take the name from Broker.generalLogGroup().
This commit is contained in:
1 parent
5fc8b0418c
commit
73133b472a
9 files changed
+263
-4
No files matched your search
@@ -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 |
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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(
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
+65
@@ -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");
|
||||
|
||||
+32
@@ -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
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user