mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(amazonmq): add Amazon MQ broker control plane backed by RabbitMQ (#1642)
* feat(amazonmq): add Amazon MQ broker control plane for RabbitMQ
* feat(amazonmq): provision RabbitMQ container with rollback
Back a broker with a real rabbitmq:3-management container, following the
MSK/ElastiCache container-manager pattern.
- RabbitMqManager starts the container, publishes AMQP (5672) and
management (15672) ports, and resolves the broker endpoints
- Service branches on the mock flag; real brokers stay
CREATION_IN_PROGRESS until a readiness poller observes the management
API answering, then flip to RUNNING
- Rollback on failed provisioning: the manager removes the half-built
container and the broker is persisted as CREATION_FAILED
- @PreDestroy stops containers on shutdown; DeleteBroker stops and
removes the container and its storage
Readiness probes the management UI root (no auth) to avoid RabbitMQ's
loopback-only guest user over Docker port mapping.
* feat(amazonmq): seed broker admin user and reject ActiveMQ-only User API
Amazon MQ's standalone User API (CreateUser/DescribeUser/ListUsers/
DeleteUser) applies only to ActiveMQ brokers; AWS rejects it for RabbitMQ
and directs callers to the RabbitMQ web console. CreateBroker now requires
exactly one broker user (validated against AWS password rules) which is
seeded into the container via RABBITMQ_DEFAULT_USER/PASS, sidestepping
RabbitMQ's loopback-only guest restriction.
* test(amazonmq): SDK compatibility test against live RabbitMQ broker
Adds AmazonMqTest exercising the real container path via the AWS SDK MqClient:
CreateBroker provisions a rabbitmq:3-management container, the broker
transitions to RUNNING once its management API answers, endpoints are
published, the ActiveMQ-only User API is rejected, and DeleteBroker tears the
container down. Uses JUnit Assumptions to skip cleanly when Docker is absent.
* fix(amazonmq): harden error handling, persistence, and shutdown teardown
- Redact the provisioning failure 500: log the cause, return a generic AWS
error envelope instead of leaking e.getMessage() (which can be null).
- Add @JsonIgnoreProperties(ignoreUnknown = true) to Broker, MqUser, and
BrokerInstance so old persisted snapshots survive field changes.
- Wire RabbitMQ container teardown into EmulatorLifecycle.onStop() via
RabbitMqManager.stopAll(), alongside the other container managers; the
service @PreDestroy now only stops the readiness poller.
* docs(amazonmq): add Amazon MQ service page and bump service count to 66
Adds docs/services/amazonmq.md, lists Amazon MQ in the services overview and
README service tables, and updates the "65 -> 66 AWS services" count across
docs/index.md, docs/services/index.md, and README.md.
* fix(amazonmq): reject RebootBroker unless the broker is RUNNING
RebootBroker unconditionally set the broker to RUNNING, so a non-RUNNING
broker (e.g. CREATION_FAILED, which has no backing container) was silently
promoted to RUNNING and never reconciled by the readiness poller. AWS allows
RebootBroker only on a broker in the RUNNING state; guard it and return a 400
otherwise, matching the Amazon MQ API ("You can reboot only a broker with the
RUNNING status").
* fix(amazonmq): close readiness-probe connection and log tolerated failures
isReady() opened an HttpURLConnection but never disconnected it; since the
probe runs every 2s per pending broker this leaked sockets. Disconnect in a
finally block, and log the tolerated failure at debug with broker/URL context
(AGENTS.md: no empty catch; avoid noise in hot paths) instead of swallowing it.
* fix(amazonmq): tear down broker container by deterministic name after restart
containerId is in-memory bookkeeping (intentionally not persisted, since the
Broker model is serialized straight to DescribeBroker and must not leak it).
After an emulator restart it is null, so stopContainer() previously returned
early and left the container running. It now falls back to the deterministic
container name (floci-amazonmq-{brokerId}) so an explicit DeleteBroker still
removes a container left over from a previous run. Documented the field and
added RabbitMqManagerTest covering both the id and name-fallback paths.
* fix(amazonmq): keep admin password in-memory only and fail loudly if absent
The admin password is a secret used solely to seed the RabbitMQ container at
create time. Persisting it (to make it survive a restart) would write the
credential in cleartext to amazonmq-brokers.json, which the project's security
rule prohibits. It stays in-memory only via @JsonIgnore; startContainer (the
only consumer, called from CreateBroker) now throws if the password is absent
rather than seeding a null credential. Added MqUserTest asserting the password
is never serialized and round-trips to null.
* fix(amazonmq): persist broker volumeId/accountId/containerId without leaking them
These internal fields were @JsonIgnore'd, so they were absent from
amazonmq-brokers.json. After a restart in persistent mode volumeId was null
(removeBrokerStorage could not locate the named volume, leaking it) and
accountId was null (the readiness poller wrote brokers via the non-account-aware
path). Unlike the admin password, these are not secrets, so they should persist.
Remove @JsonIgnore so they round-trip through storage, and build the
DescribeBroker response explicitly in the controller so they are still never
exposed to clients (matches MskCluster, which persists volumeId/containerId).
Adds BrokerTest (round-trip) and asserts the describe response omits them.
This commit is contained in:
1 parent
b3c54c1854
commit
188854f2df
26 files changed
+1744
-6
No files matched your search
@@ -416,6 +416,7 @@ public interface EmulatorConfig {
|
||||
ApiGatewayServiceConfig apigateway();
|
||||
IamServiceConfig iam();
|
||||
MskServiceConfig msk();
|
||||
AmazonMqServiceConfig amazonmq();
|
||||
ElastiCacheServiceConfig elasticache();
|
||||
MemoryDbServiceConfig memorydb();
|
||||
RdsServiceConfig rds();
|
||||
@@ -659,6 +660,17 @@ public interface EmulatorConfig {
|
||||
int kafkaHostPortMax();
|
||||
}
|
||||
|
||||
interface AmazonMqServiceConfig {
|
||||
@WithDefault("true")
|
||||
boolean enabled();
|
||||
|
||||
@WithDefault("false")
|
||||
boolean mock();
|
||||
|
||||
@WithDefault("rabbitmq:3-management")
|
||||
String defaultImage();
|
||||
}
|
||||
|
||||
interface ElastiCacheServiceConfig {
|
||||
@WithDefault("true")
|
||||
boolean enabled();
|
||||
|
||||
@@ -80,6 +80,10 @@ public class ResolvedServiceCatalog {
|
||||
"msk", config.storage().mode(), 5000L, null, ServiceProtocol.REST_JSON,
|
||||
protocols(ServiceProtocol.REST_JSON),
|
||||
Set.of(), Set.of("kafka"), Set.of(), Set.of(io.github.hectorvent.floci.services.msk.MskController.class)),
|
||||
descriptor("mq", "amazonmq", config.services().amazonmq().enabled(), true,
|
||||
"amazonmq", config.storage().mode(), 5000L, null, ServiceProtocol.REST_JSON,
|
||||
protocols(ServiceProtocol.REST_JSON),
|
||||
Set.of(), Set.of("mq"), Set.of(), Set.of(io.github.hectorvent.floci.services.amazonmq.AmazonMqController.class)),
|
||||
descriptor("sts", "iam", config.services().iam().enabled(), false,
|
||||
null, null, 5000L, AwsNamespaces.STS, ServiceProtocol.QUERY,
|
||||
protocols(ServiceProtocol.QUERY),
|
||||
|
||||
@@ -8,6 +8,7 @@ import io.github.hectorvent.floci.lifecycle.inithook.InitializationHooksRunner;
|
||||
import io.github.hectorvent.floci.services.ec2.Ec2MetadataServer;
|
||||
import io.github.hectorvent.floci.services.ecr.registry.EcrRegistryManager;
|
||||
import io.github.hectorvent.floci.services.floci.ui.FlociUiManager;
|
||||
import io.github.hectorvent.floci.services.amazonmq.container.RabbitMqManager;
|
||||
import io.github.hectorvent.floci.services.elasticache.container.ElastiCacheContainerManager;
|
||||
import io.github.hectorvent.floci.services.elasticache.container.ElastiCacheMemcachedContainerManager;
|
||||
import io.github.hectorvent.floci.services.elasticache.proxy.ElastiCacheProxyManager;
|
||||
@@ -69,6 +70,7 @@ public class EmulatorLifecycle {
|
||||
private final DocDbContainerManager docDbContainerManager;
|
||||
private final NeptuneContainerManager neptuneContainerManager;
|
||||
private final NeptuneProxyManager neptuneProxyManager;
|
||||
private final RabbitMqManager rabbitMqManager;
|
||||
private final RdsService rdsService;
|
||||
private final InitializationHooksRunner initializationHooksRunner;
|
||||
private final SqsEventSourcePoller sqsPoller;
|
||||
@@ -93,6 +95,7 @@ public class EmulatorLifecycle {
|
||||
DocDbContainerManager docDbContainerManager,
|
||||
NeptuneContainerManager neptuneContainerManager,
|
||||
NeptuneProxyManager neptuneProxyManager,
|
||||
RabbitMqManager rabbitMqManager,
|
||||
RdsService rdsService,
|
||||
InitializationHooksRunner initializationHooksRunner,
|
||||
SqsEventSourcePoller sqsPoller,
|
||||
@@ -116,6 +119,7 @@ public class EmulatorLifecycle {
|
||||
this.docDbContainerManager = docDbContainerManager;
|
||||
this.neptuneContainerManager = neptuneContainerManager;
|
||||
this.neptuneProxyManager = neptuneProxyManager;
|
||||
this.rabbitMqManager = rabbitMqManager;
|
||||
this.rdsService = rdsService;
|
||||
this.initializationHooksRunner = initializationHooksRunner;
|
||||
this.sqsPoller = sqsPoller;
|
||||
@@ -252,6 +256,7 @@ public class EmulatorLifecycle {
|
||||
memoryDbContainerManager.stopAll();
|
||||
docDbContainerManager.stopAll();
|
||||
neptuneContainerManager.stopAll();
|
||||
rabbitMqManager.stopAll();
|
||||
ecrRegistryManager.shutdown();
|
||||
flociUiManager.shutdown();
|
||||
storageFactory.shutdownAll();
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
package io.github.hectorvent.floci.services.amazonmq;
|
||||
|
||||
import io.github.hectorvent.floci.services.amazonmq.model.Broker;
|
||||
import io.github.hectorvent.floci.services.amazonmq.model.MqUser;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Amazon MQ control plane (REST JSON). Paths and wire keys mirror the AWS
|
||||
* {@code mq} API (camelCase bodies under {@code /v1/brokers}).
|
||||
*/
|
||||
@Path("/")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public class AmazonMqController {
|
||||
|
||||
private final AmazonMqService service;
|
||||
|
||||
@Inject
|
||||
public AmazonMqController(AmazonMqService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/v1/brokers")
|
||||
public Response createBroker(Map<String, Object> request) {
|
||||
CreateBrokerParams params = new CreateBrokerParams(
|
||||
str(request, "brokerName"),
|
||||
str(request, "engineType"),
|
||||
str(request, "engineVersion"),
|
||||
str(request, "deploymentMode"),
|
||||
str(request, "hostInstanceType"),
|
||||
bool(request, "publiclyAccessible"),
|
||||
bool(request, "autoMinorVersionUpgrade"),
|
||||
parseUsers(request.get("users")),
|
||||
tags(request.get("tags")));
|
||||
Broker broker = service.createBroker(params);
|
||||
return Response.ok(Map.of(
|
||||
"brokerArn", broker.getBrokerArn(),
|
||||
"brokerId", broker.getBrokerId())).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/v1/brokers")
|
||||
public Response listBrokers() {
|
||||
List<Map<String, Object>> summaries = new ArrayList<>();
|
||||
for (Broker b : service.listBrokers()) {
|
||||
Map<String, Object> summary = new LinkedHashMap<>();
|
||||
summary.put("brokerArn", b.getBrokerArn());
|
||||
summary.put("brokerId", b.getBrokerId());
|
||||
summary.put("brokerName", b.getBrokerName());
|
||||
summary.put("brokerState", b.getBrokerState());
|
||||
summary.put("created", b.getCreated());
|
||||
summary.put("deploymentMode", b.getDeploymentMode());
|
||||
summary.put("engineType", b.getEngineType());
|
||||
summary.put("hostInstanceType", b.getHostInstanceType());
|
||||
summaries.add(summary);
|
||||
}
|
||||
return Response.ok(Map.of("brokerSummaries", summaries)).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/v1/brokers/{broker-id}")
|
||||
public Response describeBroker(@PathParam("broker-id") String brokerId) {
|
||||
return Response.ok(brokerResponse(service.describeBroker(brokerId))).build();
|
||||
}
|
||||
|
||||
// Builds the DescribeBroker response explicitly. The Broker model persists
|
||||
// internal bookkeeping (containerId, accountId, volumeId) so the broker can be
|
||||
// managed after a restart, but those fields are not part of the AWS shape — hand-
|
||||
// building the response keeps them out of the client-facing payload.
|
||||
private static Map<String, Object> brokerResponse(Broker b) {
|
||||
Map<String, Object> body = new LinkedHashMap<>();
|
||||
body.put("brokerId", b.getBrokerId());
|
||||
body.put("brokerArn", b.getBrokerArn());
|
||||
body.put("brokerName", b.getBrokerName());
|
||||
body.put("brokerState", b.getBrokerState());
|
||||
body.put("engineType", b.getEngineType());
|
||||
body.put("engineVersion", b.getEngineVersion());
|
||||
body.put("deploymentMode", b.getDeploymentMode());
|
||||
body.put("hostInstanceType", b.getHostInstanceType());
|
||||
body.put("publiclyAccessible", b.isPubliclyAccessible());
|
||||
body.put("autoMinorVersionUpgrade", b.isAutoMinorVersionUpgrade());
|
||||
body.put("created", b.getCreated());
|
||||
body.put("brokerInstances", b.getBrokerInstances());
|
||||
body.put("users", b.getUsers());
|
||||
body.put("tags", b.getTags());
|
||||
return body;
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/v1/brokers/{broker-id}")
|
||||
public Response deleteBroker(@PathParam("broker-id") String brokerId) {
|
||||
service.deleteBroker(brokerId);
|
||||
return Response.ok(Map.of("brokerId", brokerId)).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/v1/brokers/{broker-id}/reboot")
|
||||
public Response rebootBroker(@PathParam("broker-id") String brokerId) {
|
||||
service.rebootBroker(brokerId);
|
||||
return Response.ok(Map.of()).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/v1/brokers/{broker-id}/users/{username}")
|
||||
public Response createUser(@PathParam("broker-id") String brokerId,
|
||||
@PathParam("username") String username,
|
||||
Map<String, Object> request) {
|
||||
MqUser user = new MqUser(
|
||||
username,
|
||||
str(request, "password"),
|
||||
bool(request, "consoleAccess"),
|
||||
strList(request.get("groups")));
|
||||
service.createUser(brokerId, user);
|
||||
return Response.ok(Map.of()).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/v1/brokers/{broker-id}/users/{username}")
|
||||
public Response describeUser(@PathParam("broker-id") String brokerId,
|
||||
@PathParam("username") String username) {
|
||||
MqUser user = service.describeUser(brokerId, username);
|
||||
Map<String, Object> body = new LinkedHashMap<>();
|
||||
body.put("brokerId", brokerId);
|
||||
body.put("username", user.getUsername());
|
||||
body.put("consoleAccess", user.isConsoleAccess());
|
||||
body.put("groups", user.getGroups());
|
||||
return Response.ok(body).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/v1/brokers/{broker-id}/users")
|
||||
public Response listUsers(@PathParam("broker-id") String brokerId) {
|
||||
List<Map<String, Object>> users = new ArrayList<>();
|
||||
for (MqUser u : service.listUsers(brokerId)) {
|
||||
users.add(Map.of("username", u.getUsername()));
|
||||
}
|
||||
Map<String, Object> body = new LinkedHashMap<>();
|
||||
body.put("brokerId", brokerId);
|
||||
body.put("users", users);
|
||||
return Response.ok(body).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/v1/brokers/{broker-id}/users/{username}")
|
||||
public Response deleteUser(@PathParam("broker-id") String brokerId,
|
||||
@PathParam("username") String username) {
|
||||
service.deleteUser(brokerId, username);
|
||||
return Response.ok(Map.of()).build();
|
||||
}
|
||||
|
||||
// --- request parsing helpers ---
|
||||
|
||||
private static String str(Map<String, Object> request, String key) {
|
||||
Object value = request.get(key);
|
||||
return value == null ? null : value.toString();
|
||||
}
|
||||
|
||||
private static boolean bool(Map<String, Object> request, String key) {
|
||||
return Boolean.TRUE.equals(request.get(key));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static List<String> strList(Object raw) {
|
||||
if (raw instanceof List<?> list) {
|
||||
List<String> result = new ArrayList<>();
|
||||
for (Object o : list) {
|
||||
result.add(String.valueOf(o));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<String, String> tags(Object raw) {
|
||||
if (raw instanceof Map<?, ?> map) {
|
||||
Map<String, String> result = new LinkedHashMap<>();
|
||||
map.forEach((k, v) -> result.put(String.valueOf(k), String.valueOf(v)));
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static List<MqUser> parseUsers(Object raw) {
|
||||
if (!(raw instanceof List<?> list)) {
|
||||
return null;
|
||||
}
|
||||
List<MqUser> users = new ArrayList<>();
|
||||
for (Object item : list) {
|
||||
if (item instanceof Map<?, ?> map) {
|
||||
Map<String, Object> u = (Map<String, Object>) map;
|
||||
users.add(new MqUser(
|
||||
str(u, "username"),
|
||||
str(u, "password"),
|
||||
bool(u, "consoleAccess"),
|
||||
strList(u.get("groups"))));
|
||||
}
|
||||
}
|
||||
return users;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,274 @@
|
||||
package io.github.hectorvent.floci.services.amazonmq;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.amazonmq.container.RabbitMqManager;
|
||||
import io.github.hectorvent.floci.services.amazonmq.model.Broker;
|
||||
import io.github.hectorvent.floci.services.amazonmq.model.BrokerInstance;
|
||||
import io.github.hectorvent.floci.services.amazonmq.model.BrokerState;
|
||||
import io.github.hectorvent.floci.services.amazonmq.model.MqUser;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ApplicationScoped
|
||||
public class AmazonMqService {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(AmazonMqService.class);
|
||||
private static final String ENGINE_RABBITMQ = "RABBITMQ";
|
||||
private static final String DEFAULT_ENGINE_VERSION = "3.13";
|
||||
private static final String DEPLOYMENT_SINGLE_INSTANCE = "SINGLE_INSTANCE";
|
||||
|
||||
private final StorageBackend<String, Broker> storage;
|
||||
private final EmulatorConfig config;
|
||||
private final RegionResolver regionResolver;
|
||||
private final RabbitMqManager rabbitMqManager;
|
||||
private final ScheduledExecutorService poller = Executors.newSingleThreadScheduledExecutor();
|
||||
|
||||
@Inject
|
||||
public AmazonMqService(StorageFactory storageFactory, EmulatorConfig config,
|
||||
RegionResolver regionResolver, RabbitMqManager rabbitMqManager) {
|
||||
this.storage = storageFactory.create("amazonmq", "amazonmq-brokers.json",
|
||||
new TypeReference<Map<String, Broker>>() {});
|
||||
this.config = config;
|
||||
this.regionResolver = regionResolver;
|
||||
this.rabbitMqManager = rabbitMqManager;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
startReadinessPoller();
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void shutdown() {
|
||||
// Container teardown is wired into EmulatorLifecycle.onStop() via
|
||||
// RabbitMqManager.stopAll() (ordered with the other container managers);
|
||||
// here we only stop the readiness poller.
|
||||
poller.shutdown();
|
||||
}
|
||||
|
||||
public Broker createBroker(CreateBrokerParams params) {
|
||||
String name = params.brokerName();
|
||||
if (name == null || name.isBlank()) {
|
||||
throw new AwsException("BadRequestException", "BrokerName is required", 400);
|
||||
}
|
||||
if (!ENGINE_RABBITMQ.equals(params.engineType())) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"Only RABBITMQ EngineType is supported", 400);
|
||||
}
|
||||
String deploymentMode = params.deploymentMode() == null
|
||||
? DEPLOYMENT_SINGLE_INSTANCE : params.deploymentMode();
|
||||
if (!DEPLOYMENT_SINGLE_INSTANCE.equals(deploymentMode)) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"Only SINGLE_INSTANCE DeploymentMode is supported", 400);
|
||||
}
|
||||
// RabbitMQ brokers require exactly one user at creation; that user becomes the
|
||||
// broker's RabbitMQ administrator (seeded into the container). This mirrors AWS,
|
||||
// which rejects CreateBroker for RabbitMQ unless exactly one user is supplied.
|
||||
List<MqUser> requestedUsers = params.users() == null ? List.of() : params.users();
|
||||
if (requestedUsers.size() != 1) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"Exactly one broker user is required for a RabbitMQ broker", 400);
|
||||
}
|
||||
MqUser admin = requestedUsers.get(0);
|
||||
if (admin.getUsername() == null || admin.getUsername().isBlank()) {
|
||||
throw new AwsException("BadRequestException", "Broker user username is required", 400);
|
||||
}
|
||||
validateUserPassword(admin.getPassword());
|
||||
|
||||
if (storage.scan(k -> true).stream().anyMatch(b -> name.equals(b.getBrokerName()))) {
|
||||
throw new AwsException("ConflictException", "Broker already exists: " + name, 409);
|
||||
}
|
||||
|
||||
String brokerId = "b-" + UUID.randomUUID();
|
||||
String accountId = regionResolver.getAccountId();
|
||||
String brokerArn = AwsArnUtils.Arn.of("mq", config.defaultRegion(), accountId,
|
||||
"broker:" + name + ":" + brokerId).toString();
|
||||
String engineVersion = (params.engineVersion() == null || params.engineVersion().isBlank())
|
||||
? DEFAULT_ENGINE_VERSION : params.engineVersion();
|
||||
|
||||
Broker broker = new Broker(brokerId, brokerArn, name, ENGINE_RABBITMQ,
|
||||
engineVersion, deploymentMode, params.hostInstanceType());
|
||||
broker.setAccountId(accountId);
|
||||
broker.setVolumeId(String.format("%06x", new SecureRandom().nextInt(0xFFFFFF)));
|
||||
broker.setPubliclyAccessible(params.publiclyAccessible());
|
||||
broker.setAutoMinorVersionUpgrade(params.autoMinorVersionUpgrade());
|
||||
if (params.users() != null) {
|
||||
broker.setUsers(new ArrayList<>(params.users()));
|
||||
}
|
||||
if (params.tags() != null) {
|
||||
broker.setTags(new HashMap<>(params.tags()));
|
||||
}
|
||||
|
||||
if (config.services().amazonmq().mock()) {
|
||||
// No backing container: come up immediately with synthetic endpoints.
|
||||
applyLocalEndpoints(broker);
|
||||
broker.setBrokerState(BrokerState.RUNNING);
|
||||
} else {
|
||||
try {
|
||||
// Start the container; the broker stays CREATION_IN_PROGRESS until
|
||||
// the readiness poller observes the management API answering.
|
||||
rabbitMqManager.startContainer(broker);
|
||||
} catch (RuntimeException e) {
|
||||
broker.setBrokerState(BrokerState.CREATION_FAILED);
|
||||
storage.put(brokerId, broker);
|
||||
// Keep the cause in the logs; don't leak internal details (or a null
|
||||
// message) into the AWS error envelope returned to the client.
|
||||
LOG.errorv(e, "Failed to provision broker {0} ({1})", name, brokerId);
|
||||
throw new AwsException("InternalServerErrorException",
|
||||
"Failed to provision broker " + name, 500);
|
||||
}
|
||||
}
|
||||
|
||||
storage.put(brokerId, broker);
|
||||
LOG.infov("Created Amazon MQ broker {0} ({1})", name, brokerId);
|
||||
return broker;
|
||||
}
|
||||
|
||||
public Broker describeBroker(String brokerId) {
|
||||
return storage.get(brokerId)
|
||||
.orElseThrow(() -> new AwsException("NotFoundException",
|
||||
"Broker not found: " + brokerId, 404));
|
||||
}
|
||||
|
||||
public List<Broker> listBrokers() {
|
||||
return storage.scan(k -> true);
|
||||
}
|
||||
|
||||
public void deleteBroker(String brokerId) {
|
||||
Broker broker = describeBroker(brokerId);
|
||||
broker.setBrokerState(BrokerState.DELETION_IN_PROGRESS);
|
||||
if (!config.services().amazonmq().mock()) {
|
||||
rabbitMqManager.stopContainer(broker);
|
||||
rabbitMqManager.removeBrokerStorage(broker);
|
||||
}
|
||||
storage.delete(brokerId);
|
||||
LOG.infov("Deleted Amazon MQ broker {0}", brokerId);
|
||||
}
|
||||
|
||||
public Broker rebootBroker(String brokerId) {
|
||||
Broker broker = describeBroker(brokerId);
|
||||
// AWS allows RebootBroker only on a broker in the RUNNING state. Without
|
||||
// this guard a non-RUNNING broker (e.g. CREATION_FAILED, which has no
|
||||
// backing container) would be silently promoted to RUNNING and never
|
||||
// reconciled by the readiness poller.
|
||||
if (broker.getBrokerState() != BrokerState.RUNNING) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"Broker " + brokerId + " cannot be rebooted while in state "
|
||||
+ broker.getBrokerState() + "; it must be RUNNING", 400);
|
||||
}
|
||||
// RebootBroker is asynchronous and returns the broker to RUNNING. This tier
|
||||
// does not cycle the container, so the broker simply stays RUNNING.
|
||||
return broker;
|
||||
}
|
||||
|
||||
private void applyLocalEndpoints(Broker broker) {
|
||||
BrokerInstance instance = new BrokerInstance(
|
||||
"http://localhost:15672",
|
||||
List.of("amqp://localhost:5672"),
|
||||
"localhost");
|
||||
broker.setBrokerInstances(new ArrayList<>(List.of(instance)));
|
||||
}
|
||||
|
||||
private void startReadinessPoller() {
|
||||
poller.scheduleAtFixedRate(() -> {
|
||||
try {
|
||||
if (config.services().amazonmq().mock()) {
|
||||
return;
|
||||
}
|
||||
for (Broker broker : allBrokers()) {
|
||||
if (broker.getBrokerState() == BrokerState.CREATION_IN_PROGRESS
|
||||
&& rabbitMqManager.isReady(broker)) {
|
||||
LOG.infov("Amazon MQ broker {0} is now RUNNING", broker.getBrokerName());
|
||||
broker.setBrokerState(BrokerState.RUNNING);
|
||||
putBroker(broker);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error in Amazon MQ readiness poller", e);
|
||||
}
|
||||
}, 1, 2, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
private List<Broker> allBrokers() {
|
||||
if (storage instanceof AccountAwareStorageBackend<Broker> aware) {
|
||||
return aware.scanAllAccounts();
|
||||
}
|
||||
return storage.scan(k -> true);
|
||||
}
|
||||
|
||||
private void putBroker(Broker broker) {
|
||||
if (broker.getAccountId() != null && storage instanceof AccountAwareStorageBackend<Broker> aware) {
|
||||
aware.putForAccount(broker.getAccountId(), broker.getBrokerId(), broker);
|
||||
} else {
|
||||
storage.put(broker.getBrokerId(), broker);
|
||||
}
|
||||
}
|
||||
|
||||
// --- Users ---
|
||||
// Amazon MQ's standalone User API (CreateUser/DescribeUser/ListUsers/UpdateUser/
|
||||
// DeleteUser) applies only to ActiveMQ brokers. For RabbitMQ, AWS rejects these
|
||||
// operations and directs callers to the RabbitMQ web console. Every broker we host
|
||||
// is RabbitMQ, so they always reject. The broker's admin user is seeded once at
|
||||
// CreateBroker time; additional users are managed through the RabbitMQ console.
|
||||
|
||||
public MqUser createUser(String brokerId, MqUser user) {
|
||||
throw userApiNotSupported();
|
||||
}
|
||||
|
||||
public MqUser describeUser(String brokerId, String username) {
|
||||
throw userApiNotSupported();
|
||||
}
|
||||
|
||||
public List<MqUser> listUsers(String brokerId) {
|
||||
throw userApiNotSupported();
|
||||
}
|
||||
|
||||
public void deleteUser(String brokerId, String username) {
|
||||
throw userApiNotSupported();
|
||||
}
|
||||
|
||||
private static AwsException userApiNotSupported() {
|
||||
return new AwsException("BadRequestException",
|
||||
"User management API operations do not apply to RabbitMQ brokers. "
|
||||
+ "Manage users through the RabbitMQ web console.", 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enforces Amazon MQ's broker-user password rule: at least 12 characters, at
|
||||
* least 4 unique characters, and no commas, colons, or equal signs.
|
||||
*/
|
||||
private static void validateUserPassword(String password) {
|
||||
if (password == null || password.length() < 12) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"Broker user password must be at least 12 characters long", 400);
|
||||
}
|
||||
if (password.chars().distinct().count() < 4) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"Broker user password must contain at least 4 unique characters", 400);
|
||||
}
|
||||
if (password.contains(",") || password.contains(":") || password.contains("=")) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"Broker user password must not contain commas, colons, or equal signs", 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package io.github.hectorvent.floci.services.amazonmq;
|
||||
|
||||
import io.github.hectorvent.floci.services.amazonmq.model.MqUser;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Immutable carrier for the fields the controller parses out of a CreateBroker
|
||||
* request body. A record fits here because the request is read once and never
|
||||
* mutated — the opposite of {@link io.github.hectorvent.floci.services.amazonmq.model.Broker},
|
||||
* whose state evolves after creation.
|
||||
*/
|
||||
public record CreateBrokerParams(
|
||||
String brokerName,
|
||||
String engineType,
|
||||
String engineVersion,
|
||||
String deploymentMode,
|
||||
String hostInstanceType,
|
||||
boolean publiclyAccessible,
|
||||
boolean autoMinorVersionUpgrade,
|
||||
List<MqUser> users,
|
||||
Map<String, String> tags) {
|
||||
}
|
||||
+235
@@ -0,0 +1,235 @@
|
||||
package io.github.hectorvent.floci.services.amazonmq.container;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerBuilder;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerDetector;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager.ContainerInfo;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager.EndpointInfo;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLogStreamer;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerSpec;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerStorageHelper;
|
||||
import io.github.hectorvent.floci.services.amazonmq.model.Broker;
|
||||
import io.github.hectorvent.floci.services.amazonmq.model.BrokerInstance;
|
||||
import io.github.hectorvent.floci.services.amazonmq.model.MqUser;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Manages the backing RabbitMQ Docker container for an Amazon MQ broker.
|
||||
* In native (dev) mode it publishes the AMQP (5672) and management (15672)
|
||||
* ports to dynamic host ports; in Docker mode sibling containers reach the
|
||||
* broker over the docker network.
|
||||
*
|
||||
* <p>Unlike {@code RedpandaManager}, RabbitMQ does not advertise a self-perceived
|
||||
* address back to clients, so no pre-allocated/advertised port is needed —
|
||||
* dynamic ports (the ElastiCache pattern) are enough.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class RabbitMqManager {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(RabbitMqManager.class);
|
||||
private static final int AMQP_PORT = 5672;
|
||||
private static final int MGMT_PORT = 15672;
|
||||
|
||||
private final ContainerBuilder containerBuilder;
|
||||
private final ContainerLifecycleManager lifecycleManager;
|
||||
private final ContainerLogStreamer logStreamer;
|
||||
private final ContainerDetector containerDetector;
|
||||
private final EmulatorConfig config;
|
||||
private final RegionResolver regionResolver;
|
||||
private final Map<String, Closeable> logStreams = new ConcurrentHashMap<>();
|
||||
private final Map<String, String> containerIds = new ConcurrentHashMap<>();
|
||||
|
||||
@Inject
|
||||
public RabbitMqManager(ContainerBuilder containerBuilder,
|
||||
ContainerLifecycleManager lifecycleManager,
|
||||
ContainerLogStreamer logStreamer,
|
||||
ContainerDetector containerDetector,
|
||||
EmulatorConfig config,
|
||||
RegionResolver regionResolver) {
|
||||
this.containerBuilder = containerBuilder;
|
||||
this.lifecycleManager = lifecycleManager;
|
||||
this.logStreamer = logStreamer;
|
||||
this.containerDetector = containerDetector;
|
||||
this.config = config;
|
||||
this.regionResolver = regionResolver;
|
||||
}
|
||||
|
||||
/** Deterministic container name for a broker, stable across emulator restarts. */
|
||||
private static String containerName(String brokerId) {
|
||||
return "floci-amazonmq-" + brokerId;
|
||||
}
|
||||
|
||||
public void startContainer(Broker broker) {
|
||||
String image = config.services().amazonmq().defaultImage();
|
||||
String containerName = containerName(broker.getBrokerId());
|
||||
LOG.infov("Starting RabbitMQ container for broker {0} using image {1}",
|
||||
broker.getBrokerName(), image);
|
||||
|
||||
// Remove any stale container with the same name (e.g. leftover from a crash).
|
||||
lifecycleManager.removeIfExists(containerName);
|
||||
|
||||
ContainerBuilder.Builder specBuilder = containerBuilder.newContainer(image)
|
||||
.withName(containerName)
|
||||
.withDockerNetwork(config.services().dockerNetwork())
|
||||
.withLogRotation();
|
||||
|
||||
// Seed the broker's admin user. RabbitMQ's built-in `guest` user is
|
||||
// loopback-only, so it cannot authenticate over the mapped host port; a user
|
||||
// created via RABBITMQ_DEFAULT_USER/PASS is not loopback-restricted and can.
|
||||
if (!broker.getUsers().isEmpty()) {
|
||||
MqUser admin = broker.getUsers().get(0);
|
||||
if (admin.getPassword() == null) {
|
||||
// The password is in-memory only (a secret we do not persist). It is
|
||||
// present when CreateBroker provisions the container but null for a
|
||||
// broker reloaded from persistent storage. Fail loudly rather than
|
||||
// create a container seeded with a null credential.
|
||||
throw new IllegalStateException("Admin password unavailable for broker "
|
||||
+ broker.getBrokerId() + " (secrets are not persisted); cannot "
|
||||
+ "provision the RabbitMQ container");
|
||||
}
|
||||
specBuilder.withEnv("RABBITMQ_DEFAULT_USER", admin.getUsername());
|
||||
specBuilder.withEnv("RABBITMQ_DEFAULT_PASS", admin.getPassword());
|
||||
}
|
||||
|
||||
if (!containerDetector.isRunningInContainer()) {
|
||||
specBuilder.withDynamicPort(AMQP_PORT).withDynamicPort(MGMT_PORT);
|
||||
} else {
|
||||
specBuilder.withExposedPort(AMQP_PORT).withExposedPort(MGMT_PORT);
|
||||
}
|
||||
|
||||
if (ContainerStorageHelper.isNamedVolumeMode(config)) {
|
||||
ContainerStorageHelper.applyStorage(specBuilder, lifecycleManager,
|
||||
"amazonmq", broker.getVolumeId(), broker.getBrokerId(),
|
||||
"/var/lib/rabbitmq");
|
||||
} else {
|
||||
String hostDataPath = Path.of(config.storage().hostPersistentPath(), "amazonmq", broker.getBrokerId())
|
||||
.toAbsolutePath().toString();
|
||||
ContainerStorageHelper.ensureHostDir(hostDataPath);
|
||||
specBuilder.withBind(hostDataPath, "/var/lib/rabbitmq");
|
||||
}
|
||||
|
||||
ContainerSpec spec = specBuilder.build();
|
||||
|
||||
ContainerInfo info;
|
||||
try {
|
||||
info = lifecycleManager.createAndStart(spec);
|
||||
} catch (RuntimeException e) {
|
||||
// Roll back a partially-created container so a failed CreateBroker
|
||||
// does not leave an orphaned container behind.
|
||||
lifecycleManager.removeIfExists(containerName);
|
||||
throw e;
|
||||
}
|
||||
broker.setContainerId(info.containerId());
|
||||
containerIds.put(broker.getBrokerId(), info.containerId());
|
||||
|
||||
EndpointInfo amqp = info.getEndpoint(AMQP_PORT);
|
||||
EndpointInfo mgmt = info.getEndpoint(MGMT_PORT);
|
||||
BrokerInstance instance = new BrokerInstance(
|
||||
"http://" + mgmt.host() + ":" + mgmt.port(),
|
||||
List.of("amqp://" + amqp.host() + ":" + amqp.port()),
|
||||
amqp.host());
|
||||
broker.setBrokerInstances(new java.util.ArrayList<>(List.of(instance)));
|
||||
LOG.infov("RabbitMQ container {0} started for broker {1}: amqp={2}",
|
||||
info.containerId(), broker.getBrokerName(), instance.getEndpoints().get(0));
|
||||
|
||||
String shortId = info.containerId().length() >= 8
|
||||
? info.containerId().substring(0, 8)
|
||||
: info.containerId();
|
||||
String logGroup = "/aws/amazonmq/broker/" + broker.getBrokerId();
|
||||
String logStream = logStreamer.generateLogStreamName(shortId);
|
||||
String region = regionResolver.getDefaultRegion();
|
||||
Closeable logHandle = logStreamer.attach(
|
||||
info.containerId(), logGroup, logStream, region, "amazonmq:" + broker.getBrokerId());
|
||||
if (logHandle != null) {
|
||||
logStreams.put(broker.getBrokerId(), logHandle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ready once the RabbitMQ management UI answers on its port. The management
|
||||
* plugin starts after the broker core, so a 200 here implies AMQP is also up.
|
||||
* The root path needs no auth, sidestepping RabbitMQ's loopback-only guest user.
|
||||
*/
|
||||
public boolean isReady(Broker broker) {
|
||||
if (broker.getBrokerInstances().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
String consoleUrl = broker.getBrokerInstances().get(0).getConsoleURL();
|
||||
if (consoleUrl == null) {
|
||||
return false;
|
||||
}
|
||||
HttpURLConnection conn = null;
|
||||
try {
|
||||
conn = (HttpURLConnection) URI.create(consoleUrl).toURL().openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setConnectTimeout(1000);
|
||||
conn.setReadTimeout(1000);
|
||||
return conn.getResponseCode() == 200;
|
||||
} catch (Exception e) {
|
||||
// Expected while the broker is still booting (connection refused/timeout).
|
||||
// Logged at debug so a genuinely stuck probe is diagnosable without
|
||||
// spamming this 2s-interval hot path (AGENTS.md: no empty catch).
|
||||
LOG.debugf("Readiness probe for broker %s at %s not ready: %s",
|
||||
broker.getBrokerId(), consoleUrl, e.toString());
|
||||
return false;
|
||||
} finally {
|
||||
// Release the socket; isReady() is polled every 2s per pending broker.
|
||||
if (conn != null) {
|
||||
conn.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void stopContainer(Broker broker) {
|
||||
containerIds.remove(broker.getBrokerId());
|
||||
Closeable logHandle = logStreams.remove(broker.getBrokerId());
|
||||
String containerId = broker.getContainerId();
|
||||
if (containerId != null) {
|
||||
lifecycleManager.stopAndRemove(containerId, logHandle);
|
||||
LOG.infov("RabbitMQ container {0} stopped and removed", containerId);
|
||||
} else {
|
||||
// containerId is in-memory bookkeeping and is null after an emulator
|
||||
// restart (it is intentionally not persisted; see Broker). Fall back to
|
||||
// the deterministic container name so an explicit DeleteBroker still
|
||||
// removes a container left running from a previous run.
|
||||
lifecycleManager.removeIfExists(containerName(broker.getBrokerId()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops and removes every running broker container. Wired into
|
||||
* {@code EmulatorLifecycle.onStop()} so containers are torn down on shutdown
|
||||
* alongside the other container managers.
|
||||
*/
|
||||
public void stopAll() {
|
||||
if (!containerIds.isEmpty()) {
|
||||
LOG.infov("Stopping {0} RabbitMQ container(s) on shutdown", containerIds.size());
|
||||
}
|
||||
for (String brokerId : new ArrayList<>(containerIds.keySet())) {
|
||||
String containerId = containerIds.remove(brokerId);
|
||||
if (containerId == null) {
|
||||
continue;
|
||||
}
|
||||
Closeable logHandle = logStreams.remove(brokerId);
|
||||
lifecycleManager.stopAndRemove(containerId, logHandle);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeBrokerStorage(Broker broker) {
|
||||
ContainerStorageHelper.removeStorage(config, lifecycleManager,
|
||||
"amazonmq", broker.getVolumeId(), broker.getBrokerId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
package io.github.hectorvent.floci.services.amazonmq.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* In-memory representation of an Amazon MQ broker. Mirrors the
|
||||
* {@code msk/model/MskCluster} shape: a mutable POJO whose state transitions
|
||||
* in place (CREATION_IN_PROGRESS -> RUNNING) as the backing container comes up.
|
||||
*
|
||||
* <p>Wire keys are camelCase to match the Amazon MQ REST-JSON protocol
|
||||
* (e.g. {@code brokerName}, {@code brokerInstances}).
|
||||
*/
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Broker {
|
||||
|
||||
@JsonProperty("brokerId")
|
||||
private String brokerId;
|
||||
|
||||
@JsonProperty("brokerArn")
|
||||
private String brokerArn;
|
||||
|
||||
@JsonProperty("brokerName")
|
||||
private String brokerName;
|
||||
|
||||
@JsonProperty("brokerState")
|
||||
private BrokerState brokerState;
|
||||
|
||||
@JsonProperty("engineType")
|
||||
private String engineType;
|
||||
|
||||
@JsonProperty("engineVersion")
|
||||
private String engineVersion;
|
||||
|
||||
@JsonProperty("deploymentMode")
|
||||
private String deploymentMode;
|
||||
|
||||
@JsonProperty("hostInstanceType")
|
||||
private String hostInstanceType;
|
||||
|
||||
@JsonProperty("publiclyAccessible")
|
||||
private boolean publiclyAccessible;
|
||||
|
||||
@JsonProperty("autoMinorVersionUpgrade")
|
||||
private boolean autoMinorVersionUpgrade;
|
||||
|
||||
@JsonProperty("created")
|
||||
private Instant created;
|
||||
|
||||
@JsonProperty("brokerInstances")
|
||||
private List<BrokerInstance> brokerInstances = new ArrayList<>();
|
||||
|
||||
@JsonProperty("users")
|
||||
private List<MqUser> users = new ArrayList<>();
|
||||
|
||||
@JsonProperty("tags")
|
||||
private Map<String, String> tags;
|
||||
|
||||
// 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
|
||||
// controller builds the DescribeBroker response explicitly, so these are never
|
||||
// exposed to clients despite being written to storage.
|
||||
private String containerId;
|
||||
|
||||
private String accountId;
|
||||
|
||||
// 6-char hex generated once at creation for stable, collision-free volume/container
|
||||
// naming (same convention as MskCluster.volumeId, which is likewise persisted so
|
||||
// removeBrokerStorage can locate the named volume after a restart).
|
||||
private String volumeId;
|
||||
|
||||
public Broker() {}
|
||||
|
||||
public Broker(String brokerId, String brokerArn, String brokerName,
|
||||
String engineType, String engineVersion, String deploymentMode,
|
||||
String hostInstanceType) {
|
||||
this.brokerId = brokerId;
|
||||
this.brokerArn = brokerArn;
|
||||
this.brokerName = brokerName;
|
||||
this.engineType = engineType;
|
||||
this.engineVersion = engineVersion;
|
||||
this.deploymentMode = deploymentMode;
|
||||
this.hostInstanceType = hostInstanceType;
|
||||
this.brokerState = BrokerState.CREATION_IN_PROGRESS;
|
||||
this.created = Instant.now();
|
||||
}
|
||||
|
||||
public String getBrokerId() { return brokerId; }
|
||||
public void setBrokerId(String brokerId) { this.brokerId = brokerId; }
|
||||
|
||||
public String getBrokerArn() { return brokerArn; }
|
||||
public void setBrokerArn(String brokerArn) { this.brokerArn = brokerArn; }
|
||||
|
||||
public String getBrokerName() { return brokerName; }
|
||||
public void setBrokerName(String brokerName) { this.brokerName = brokerName; }
|
||||
|
||||
public BrokerState getBrokerState() { return brokerState; }
|
||||
public void setBrokerState(BrokerState brokerState) { this.brokerState = brokerState; }
|
||||
|
||||
public String getEngineType() { return engineType; }
|
||||
public void setEngineType(String engineType) { this.engineType = engineType; }
|
||||
|
||||
public String getEngineVersion() { return engineVersion; }
|
||||
public void setEngineVersion(String engineVersion) { this.engineVersion = engineVersion; }
|
||||
|
||||
public String getDeploymentMode() { return deploymentMode; }
|
||||
public void setDeploymentMode(String deploymentMode) { this.deploymentMode = deploymentMode; }
|
||||
|
||||
public String getHostInstanceType() { return hostInstanceType; }
|
||||
public void setHostInstanceType(String hostInstanceType) { this.hostInstanceType = hostInstanceType; }
|
||||
|
||||
public boolean isPubliclyAccessible() { return publiclyAccessible; }
|
||||
public void setPubliclyAccessible(boolean publiclyAccessible) { this.publiclyAccessible = publiclyAccessible; }
|
||||
|
||||
public boolean isAutoMinorVersionUpgrade() { return autoMinorVersionUpgrade; }
|
||||
public void setAutoMinorVersionUpgrade(boolean autoMinorVersionUpgrade) { this.autoMinorVersionUpgrade = autoMinorVersionUpgrade; }
|
||||
|
||||
public Instant getCreated() { return created; }
|
||||
public void setCreated(Instant created) { this.created = created; }
|
||||
|
||||
public List<BrokerInstance> getBrokerInstances() { return brokerInstances; }
|
||||
public void setBrokerInstances(List<BrokerInstance> brokerInstances) { this.brokerInstances = brokerInstances; }
|
||||
|
||||
public List<MqUser> getUsers() { return users; }
|
||||
public void setUsers(List<MqUser> users) { this.users = users; }
|
||||
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags; }
|
||||
|
||||
public String getContainerId() { return containerId; }
|
||||
public void setContainerId(String containerId) { this.containerId = containerId; }
|
||||
|
||||
public String getAccountId() { return accountId; }
|
||||
public void setAccountId(String accountId) { this.accountId = accountId; }
|
||||
|
||||
public String getVolumeId() { return volumeId; }
|
||||
public void setVolumeId(String volumeId) { this.volumeId = volumeId; }
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package io.github.hectorvent.floci.services.amazonmq.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A single broker instance's connection info, as returned inside
|
||||
* {@code DescribeBroker.BrokerInstances[]}. Clients read {@code Endpoints}
|
||||
* to connect (AMQP) and {@code ConsoleURL} to open the management UI.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class BrokerInstance {
|
||||
|
||||
@JsonProperty("consoleURL")
|
||||
private String consoleURL;
|
||||
|
||||
@JsonProperty("endpoints")
|
||||
private List<String> endpoints;
|
||||
|
||||
@JsonProperty("ipAddress")
|
||||
private String ipAddress;
|
||||
|
||||
public BrokerInstance() {}
|
||||
|
||||
public BrokerInstance(String consoleURL, List<String> endpoints, String ipAddress) {
|
||||
this.consoleURL = consoleURL;
|
||||
this.endpoints = endpoints;
|
||||
this.ipAddress = ipAddress;
|
||||
}
|
||||
|
||||
public String getConsoleURL() { return consoleURL; }
|
||||
public void setConsoleURL(String consoleURL) { this.consoleURL = consoleURL; }
|
||||
|
||||
public List<String> getEndpoints() { return endpoints; }
|
||||
public void setEndpoints(List<String> endpoints) { this.endpoints = endpoints; }
|
||||
|
||||
public String getIpAddress() { return ipAddress; }
|
||||
public void setIpAddress(String ipAddress) { this.ipAddress = ipAddress; }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package io.github.hectorvent.floci.services.amazonmq.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
public enum BrokerState {
|
||||
@JsonProperty("CREATION_IN_PROGRESS")
|
||||
CREATION_IN_PROGRESS,
|
||||
@JsonProperty("CREATION_FAILED")
|
||||
CREATION_FAILED,
|
||||
@JsonProperty("DELETION_IN_PROGRESS")
|
||||
DELETION_IN_PROGRESS,
|
||||
@JsonProperty("RUNNING")
|
||||
RUNNING,
|
||||
@JsonProperty("REBOOT_IN_PROGRESS")
|
||||
REBOOT_IN_PROGRESS,
|
||||
@JsonProperty("CRITICAL_ACTION_REQUIRED")
|
||||
CRITICAL_ACTION_REQUIRED,
|
||||
@JsonProperty("REPLICA")
|
||||
REPLICA
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package io.github.hectorvent.floci.services.amazonmq.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A broker user. Amazon MQ never returns the password in any response
|
||||
* (DescribeUser / ListUsers omit it), so the password is stored for later
|
||||
* projection into the real broker but is never serialized back to the client.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class MqUser {
|
||||
|
||||
@JsonProperty("username")
|
||||
private String username;
|
||||
|
||||
// The admin password is a secret used only to seed the RabbitMQ container at
|
||||
// create time (RABBITMQ_DEFAULT_USER/PASS). It is deliberately kept in memory
|
||||
// only and never serialized — to the API or to StorageBackend — so it is not
|
||||
// written in cleartext to amazonmq-brokers.json (per the project rule against
|
||||
// persisting secrets). A broker reloaded from persistent storage therefore has a
|
||||
// null password; RabbitMqManager#startContainer fails loudly rather than seed a
|
||||
// null credential.
|
||||
@JsonIgnore
|
||||
private String password;
|
||||
|
||||
@JsonProperty("consoleAccess")
|
||||
private boolean consoleAccess;
|
||||
|
||||
@JsonProperty("groups")
|
||||
private List<String> groups;
|
||||
|
||||
public MqUser() {}
|
||||
|
||||
public MqUser(String username, String password, boolean consoleAccess, List<String> groups) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.consoleAccess = consoleAccess;
|
||||
this.groups = groups;
|
||||
}
|
||||
|
||||
public String getUsername() { return username; }
|
||||
public void setUsername(String username) { this.username = username; }
|
||||
|
||||
@JsonIgnore
|
||||
public String getPassword() { return password; }
|
||||
public void setPassword(String password) { this.password = password; }
|
||||
|
||||
public boolean isConsoleAccess() { return consoleAccess; }
|
||||
public void setConsoleAccess(boolean consoleAccess) { this.consoleAccess = consoleAccess; }
|
||||
|
||||
public List<String> getGroups() { return groups; }
|
||||
public void setGroups(List<String> groups) { this.groups = groups; }
|
||||
}
|
||||
Reference in new issue
Block a user