diff --git a/compatibility-tests/sdk-test-java/pom.xml b/compatibility-tests/sdk-test-java/pom.xml
index 1a610ecbdd..da06eddedc 100644
--- a/compatibility-tests/sdk-test-java/pom.xml
+++ b/compatibility-tests/sdk-test-java/pom.xml
@@ -162,6 +162,11 @@
software.amazon.awssdk
eventbridge
+
+
+ software.amazon.awssdk
+ servicediscovery
+
software.amazon.awssdk
diff --git a/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java b/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
index 33d4a1d2ce..ee0de0478f 100644
--- a/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
+++ b/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
@@ -8,7 +8,9 @@ import software.amazon.awssdk.services.cloudwatch.CloudWatchClient;
import software.amazon.awssdk.services.cloudwatchlogs.CloudWatchLogsClient;
import software.amazon.awssdk.services.cognitoidentityprovider.CognitoIdentityProviderClient;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
+import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption;
import software.amazon.awssdk.services.eventbridge.EventBridgeClient;
+import software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryClient;
import software.amazon.awssdk.services.iam.IamClient;
import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;
import software.amazon.awssdk.services.kinesis.KinesisClient;
@@ -454,6 +456,18 @@ public final class TestFixtures {
.build();
}
+ public static ServiceDiscoveryClient serviceDiscoveryClient() {
+ return ServiceDiscoveryClient.builder()
+ .endpointOverride(ENDPOINT)
+ .region(REGION)
+ .credentialsProvider(CREDENTIALS)
+ // DiscoverInstances carries a "data-" host prefix; injecting it would
+ // rewrite the custom endpoint host (data-) and break resolution.
+ .overrideConfiguration(o -> o.putAdvancedOption(
+ SdkAdvancedClientOption.DISABLE_HOST_PREFIX_INJECTION, Boolean.TRUE))
+ .build();
+ }
+
public static SfnClient sfnClient() {
return SfnClient.builder()
.endpointOverride(ENDPOINT)
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/CloudMapTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/CloudMapTest.java
new file mode 100644
index 0000000000..f571d418c0
--- /dev/null
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/CloudMapTest.java
@@ -0,0 +1,196 @@
+package com.floci.test;
+
+import org.junit.jupiter.api.*;
+import software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryClient;
+import software.amazon.awssdk.services.servicediscovery.model.*;
+
+import java.util.List;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.*;
+
+/**
+ * Cloud Map (servicediscovery) validated through the real AWS SDK v2 client.
+ * Exercises the Phase 1 flow: create namespace → poll operation → create service →
+ * register instance → discover → deregister → delete.
+ */
+@DisplayName("Cloud Map")
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+class CloudMapTest {
+
+ private static ServiceDiscoveryClient sd;
+ private static String namespaceName;
+ private static String serviceName;
+ private static String namespaceId;
+ private static String serviceId;
+ private static final String INSTANCE_ID = "i-cm-sdk-1";
+
+ @BeforeAll
+ static void setup() {
+ sd = TestFixtures.serviceDiscoveryClient();
+ namespaceName = TestFixtures.uniqueName("cm-ns");
+ serviceName = TestFixtures.uniqueName("cm-svc");
+ }
+
+ @AfterAll
+ static void cleanup() {
+ try {
+ sd.deregisterInstance(r -> r.serviceId(serviceId).instanceId(INSTANCE_ID));
+ } catch (Exception ignored) {}
+ try {
+ sd.deleteService(r -> r.id(serviceId));
+ } catch (Exception ignored) {}
+ try {
+ sd.deleteNamespace(r -> r.id(namespaceId));
+ } catch (Exception ignored) {}
+ sd.close();
+ }
+
+ private static void awaitSuccess(String operationId) {
+ for (int i = 0; i < 20; i++) {
+ GetOperationResponse op = sd.getOperation(r -> r.operationId(operationId));
+ if (op.operation().status() == OperationStatus.SUCCESS) {
+ return;
+ }
+ if (op.operation().status() == OperationStatus.FAIL) {
+ fail("Operation " + operationId + " failed: " + op.operation().errorMessage());
+ }
+ try { Thread.sleep(100); } catch (InterruptedException ignored) {}
+ }
+ fail("Operation " + operationId + " did not reach SUCCESS");
+ }
+
+ @Test
+ @Order(1)
+ void createHttpNamespace() {
+ CreateHttpNamespaceResponse resp = sd.createHttpNamespace(
+ r -> r.name(namespaceName).description("floci sdk compat"));
+ assertThat(resp.operationId()).isNotBlank();
+ awaitSuccess(resp.operationId());
+ }
+
+ @Test
+ @Order(2)
+ void listNamespacesFindsIt() {
+ ListNamespacesResponse resp = sd.listNamespaces(ListNamespacesRequest.builder().build());
+ NamespaceSummary found = resp.namespaces().stream()
+ .filter(n -> n.name().equals(namespaceName))
+ .findFirst().orElseThrow();
+ namespaceId = found.id();
+ assertThat(namespaceId).startsWith("ns-");
+ assertThat(found.type()).isEqualTo(NamespaceType.HTTP);
+ assertThat(found.arn()).contains("servicediscovery");
+ }
+
+ @Test
+ @Order(3)
+ void getNamespace() {
+ GetNamespaceResponse resp = sd.getNamespace(r -> r.id(namespaceId));
+ assertThat(resp.namespace().name()).isEqualTo(namespaceName);
+ assertThat(resp.namespace().properties().httpProperties().httpName()).isEqualTo(namespaceName);
+ }
+
+ @Test
+ @Order(4)
+ void createService() {
+ CreateServiceResponse resp = sd.createService(
+ r -> r.name(serviceName).namespaceId(namespaceId).type(ServiceTypeOption.HTTP));
+ serviceId = resp.service().id();
+ assertThat(serviceId).startsWith("srv-");
+ assertThat(resp.service().name()).isEqualTo(serviceName);
+ assertThat(resp.service().namespaceId()).isEqualTo(namespaceId);
+ }
+
+ @Test
+ @Order(5)
+ void registerInstance() {
+ RegisterInstanceResponse resp = sd.registerInstance(r -> r
+ .serviceId(serviceId)
+ .instanceId(INSTANCE_ID)
+ .attributes(Map.of("AWS_INSTANCE_IPV4", "10.0.0.7", "AWS_INSTANCE_PORT", "9090")));
+ assertThat(resp.operationId()).isNotBlank();
+ awaitSuccess(resp.operationId());
+ }
+
+ @Test
+ @Order(6)
+ void listInstances() {
+ ListInstancesResponse resp = sd.listInstances(r -> r.serviceId(serviceId));
+ assertThat(resp.instances()).hasSize(1);
+ InstanceSummary summary = resp.instances().get(0);
+ assertThat(summary.id()).isEqualTo(INSTANCE_ID);
+ assertThat(summary.attributes()).containsEntry("AWS_INSTANCE_IPV4", "10.0.0.7");
+ }
+
+ @Test
+ @Order(7)
+ void getInstance() {
+ GetInstanceResponse resp = sd.getInstance(r -> r.serviceId(serviceId).instanceId(INSTANCE_ID));
+ assertThat(resp.instance().id()).isEqualTo(INSTANCE_ID);
+ assertThat(resp.instance().attributes()).containsEntry("AWS_INSTANCE_PORT", "9090");
+ }
+
+ @Test
+ @Order(8)
+ void discoverInstances() {
+ DiscoverInstancesResponse resp = sd.discoverInstances(r -> r
+ .namespaceName(namespaceName)
+ .serviceName(serviceName)
+ .healthStatus(HealthStatusFilter.HEALTHY_OR_ELSE_ALL));
+ assertThat(resp.instances()).hasSize(1);
+ HttpInstanceSummary inst = resp.instances().get(0);
+ assertThat(inst.instanceId()).isEqualTo(INSTANCE_ID);
+ assertThat(inst.healthStatus()).isEqualTo(HealthStatus.HEALTHY);
+ assertThat(resp.instancesRevision()).isNotNull();
+
+ long revision = sd.discoverInstancesRevision(r -> r
+ .namespaceName(namespaceName).serviceName(serviceName)).instancesRevision();
+ assertThat(revision).isEqualTo(resp.instancesRevision());
+ }
+
+ @Test
+ @Order(9)
+ void getInstancesHealthStatus() {
+ GetInstancesHealthStatusResponse resp = sd.getInstancesHealthStatus(r -> r.serviceId(serviceId));
+ assertThat(resp.status()).containsEntry(INSTANCE_ID, HealthStatus.HEALTHY);
+ }
+
+ @Test
+ @Order(10)
+ void listOperationsFilteredByNamespace() {
+ ListOperationsResponse resp = sd.listOperations(r -> r.filters(
+ OperationFilter.builder()
+ .name(OperationFilterName.NAMESPACE_ID)
+ .condition(FilterCondition.EQ)
+ .values(namespaceId)
+ .build()));
+ assertThat(resp.operations()).isNotEmpty();
+ }
+
+ @Test
+ @Order(11)
+ void deleteServiceWhileInstancesRegisteredFails() {
+ assertThatThrownBy(() -> sd.deleteService(r -> r.id(serviceId)))
+ .isInstanceOf(ResourceInUseException.class);
+ }
+
+ @Test
+ @Order(12)
+ void teardown() {
+ DeregisterInstanceResponse dereg = sd.deregisterInstance(
+ r -> r.serviceId(serviceId).instanceId(INSTANCE_ID));
+ assertThat(dereg.operationId()).isNotBlank();
+ awaitSuccess(dereg.operationId());
+
+ sd.deleteService(r -> r.id(serviceId));
+ DeleteNamespaceResponse del = sd.deleteNamespace(r -> r.id(namespaceId));
+ assertThat(del.operationId()).isNotBlank();
+ }
+
+ @Test
+ @Order(13)
+ void getMissingNamespaceThrows() {
+ assertThatThrownBy(() -> sd.getNamespace(r -> r.id("ns-doesnotexist00000")))
+ .isInstanceOf(NamespaceNotFoundException.class);
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
index fe6f02fcb0..13db3ed8ff 100644
--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
@@ -322,6 +322,7 @@ public interface EmulatorConfig {
ElastiCacheServiceConfig elasticache();
RdsServiceConfig rds();
EventBridgeServiceConfig eventbridge();
+ CloudMapServiceConfig cloudmap();
SchedulerServiceConfig scheduler();
CloudWatchLogsServiceConfig cloudwatchlogs();
CloudWatchMetricsServiceConfig cloudwatchmetrics();
@@ -549,6 +550,16 @@ public interface EmulatorConfig {
boolean enabled();
}
+ interface CloudMapServiceConfig {
+ @WithDefault("true")
+ boolean enabled();
+
+ /** Delay before an async operation (CreateNamespace, RegisterInstance, …)
+ * transitions from PENDING to SUCCESS. 0 = complete immediately. */
+ @WithDefault("0")
+ int operationCompletionDelaySeconds();
+ }
+
interface SchedulerServiceConfig {
@WithDefault("true")
boolean enabled();
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/AwsJson11Controller.java b/src/main/java/io/github/hectorvent/floci/core/common/AwsJson11Controller.java
index f01017d1a7..cdd72ee890 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/AwsJson11Controller.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/AwsJson11Controller.java
@@ -22,6 +22,7 @@ import io.github.hectorvent.floci.services.transcribe.TranscribeJsonHandler;
import io.github.hectorvent.floci.services.apigatewayv2.ApiGatewayV2JsonHandler;
import io.github.hectorvent.floci.services.cloudwatch.logs.CloudWatchLogsHandler;
import io.github.hectorvent.floci.services.cognito.CognitoJsonHandler;
+import io.github.hectorvent.floci.services.cloudmap.CloudMapHandler;
import io.github.hectorvent.floci.services.eventbridge.EventBridgeHandler;
import io.github.hectorvent.floci.services.kinesis.KinesisJsonHandler;
import io.github.hectorvent.floci.services.kms.KmsJsonHandler;
@@ -54,6 +55,7 @@ public class AwsJson11Controller {
private final RegionResolver regionResolver;
private final SsmJsonHandler ssmJsonHandler;
private final EventBridgeHandler eventBridgeHandler;
+ private final CloudMapHandler cloudMapHandler;
private final CloudWatchLogsHandler cloudWatchLogsHandler;
private final SecretsManagerJsonHandler secretsManagerJsonHandler;
private final KinesisJsonHandler kinesisJsonHandler;
@@ -83,6 +85,7 @@ public class AwsJson11Controller {
public AwsJson11Controller(ObjectMapper objectMapper, ResolvedServiceCatalog catalog,
RegionResolver regionResolver,
SsmJsonHandler ssmJsonHandler, EventBridgeHandler eventBridgeHandler,
+ CloudMapHandler cloudMapHandler,
CloudWatchLogsHandler cloudWatchLogsHandler,
SecretsManagerJsonHandler secretsManagerJsonHandler,
KinesisJsonHandler kinesisJsonHandler,
@@ -109,6 +112,7 @@ public class AwsJson11Controller {
this.regionResolver = regionResolver;
this.ssmJsonHandler = ssmJsonHandler;
this.eventBridgeHandler = eventBridgeHandler;
+ this.cloudMapHandler = cloudMapHandler;
this.cloudWatchLogsHandler = cloudWatchLogsHandler;
this.secretsManagerJsonHandler = secretsManagerJsonHandler;
this.kinesisJsonHandler = kinesisJsonHandler;
@@ -163,6 +167,7 @@ public class AwsJson11Controller {
Response delegated = switch (serviceKey) {
case "ssm" -> ssmJsonHandler.handle(action, request, region);
case "events" -> eventBridgeHandler.handle(action, request, region);
+ case "servicediscovery" -> cloudMapHandler.handle(action, request, region);
case "logs" -> cloudWatchLogsHandler.handle(action, request, region);
case "secretsmanager" -> secretsManagerJsonHandler.handle(action, request, region);
case "kinesis" -> kinesisJsonHandler.handle(action, request, region);
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
index 445d4275f4..41fc672ded 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
@@ -98,6 +98,10 @@ public class ResolvedServiceCatalog {
"eventbridge", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,
protocols(ServiceProtocol.JSON),
Set.of("AWSEvents."), Set.of("events"), Set.of(), Set.of()),
+ descriptor("servicediscovery", "cloudmap", config.services().cloudmap().enabled(), true,
+ "cloudmap", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,
+ protocols(ServiceProtocol.JSON),
+ Set.of("Route53AutoNaming_v20170314."), Set.of("servicediscovery"), Set.of(), Set.of()),
descriptor("scheduler", "scheduler", config.services().scheduler().enabled(), true,
"scheduler", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,
protocols(ServiceProtocol.JSON),
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudmap/CloudMapHandler.java b/src/main/java/io/github/hectorvent/floci/services/cloudmap/CloudMapHandler.java
new file mode 100644
index 0000000000..2835eacf45
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudmap/CloudMapHandler.java
@@ -0,0 +1,429 @@
+package io.github.hectorvent.floci.services.cloudmap;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.core.common.AwsErrorResponse;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.AwsJson11Controller;
+import io.github.hectorvent.floci.services.cloudmap.model.Instance;
+import io.github.hectorvent.floci.services.cloudmap.model.Namespace;
+import io.github.hectorvent.floci.services.cloudmap.model.Operation;
+import io.github.hectorvent.floci.services.cloudmap.model.Service;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.core.Response;
+import org.jboss.logging.Logger;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Cloud Map (servicediscovery) JSON 1.1 handler. Dispatched from
+ * {@link AwsJson11Controller} under the {@code Route53AutoNaming_v20170314.} target prefix.
+ */
+@ApplicationScoped
+public class CloudMapHandler {
+
+ private static final Logger LOG = Logger.getLogger(CloudMapHandler.class);
+
+ private final CloudMapService service;
+ private final ObjectMapper objectMapper;
+
+ @Inject
+ public CloudMapHandler(CloudMapService service, ObjectMapper objectMapper) {
+ this.service = service;
+ this.objectMapper = objectMapper;
+ }
+
+ public Response handle(String action, JsonNode request, String region) {
+ LOG.debugv("CloudMap action: {0}", action);
+ try {
+ return switch (action) {
+ case "CreateHttpNamespace" -> opResponse(service.createHttpNamespace(
+ text(request, "Name"), text(request, "CreatorRequestId"),
+ text(request, "Description"), parseTags(request), region));
+ case "CreatePublicDnsNamespace" -> opResponse(service.createPublicDnsNamespace(
+ text(request, "Name"), text(request, "CreatorRequestId"),
+ text(request, "Description"), parseTags(request), region));
+ case "CreatePrivateDnsNamespace" -> opResponse(service.createPrivateDnsNamespace(
+ text(request, "Name"), text(request, "Vpc"), text(request, "CreatorRequestId"),
+ text(request, "Description"), parseTags(request), region));
+ case "GetNamespace" -> handleGetNamespace(request);
+ case "ListNamespaces" -> handleListNamespaces(region);
+ case "DeleteNamespace" -> opResponse(service.deleteNamespace(text(request, "Id"), region));
+ case "GetOperation" -> handleGetOperation(request);
+ case "ListOperations" -> handleListOperations(request, region);
+ case "CreateService" -> handleCreateService(request, region);
+ case "GetService" -> handleGetService(request);
+ case "ListServices" -> handleListServices(request, region);
+ case "DeleteService" -> handleDeleteService(request);
+ case "RegisterInstance" -> opResponse(service.registerInstance(
+ text(request, "ServiceId"), text(request, "InstanceId"),
+ text(request, "CreatorRequestId"), parseAttributes(request.path("Attributes")), region));
+ case "DeregisterInstance" -> opResponse(service.deregisterInstance(
+ text(request, "ServiceId"), text(request, "InstanceId"), region));
+ case "GetInstance" -> handleGetInstance(request);
+ case "ListInstances" -> handleListInstances(request);
+ case "GetInstancesHealthStatus" -> handleGetInstancesHealthStatus(request);
+ case "DiscoverInstances" -> handleDiscoverInstances(request, region);
+ case "DiscoverInstancesRevision" -> handleDiscoverInstancesRevision(request, region);
+ case "TagResource" -> handleTagResource(request);
+ case "UntagResource" -> handleUntagResource(request);
+ case "ListTagsForResource" -> handleListTagsForResource(request);
+ default -> Response.status(400)
+ .entity(new AwsErrorResponse("UnknownOperationException",
+ "Operation " + action + " is not supported."))
+ .build();
+ };
+ } catch (AwsException e) {
+ return Response.status(e.getHttpStatus())
+ .entity(new AwsErrorResponse(e.jsonType(), e.getMessage()))
+ .build();
+ } catch (Exception e) {
+ LOG.errorv("CloudMap error processing action {0}: {1}", action, e.getMessage());
+ return Response.status(500)
+ .entity(new AwsErrorResponse("InternalFailure", e.getMessage()))
+ .build();
+ }
+ }
+
+ // ──────────────────────────── Namespaces ────────────────────────────
+
+ private Response handleGetNamespace(JsonNode request) {
+ Namespace ns = service.getNamespace(text(request, "Id"));
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("Namespace", buildNamespaceNode(ns));
+ return Response.ok(response).build();
+ }
+
+ private Response handleListNamespaces(String region) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode arr = response.putArray("Namespaces");
+ for (Namespace ns : service.listNamespaces(region)) {
+ arr.add(buildNamespaceNode(ns));
+ }
+ return Response.ok(response).build();
+ }
+
+ // ──────────────────────────── Operations ────────────────────────────
+
+ private Response handleGetOperation(JsonNode request) {
+ Operation op = service.getOperation(text(request, "OperationId"));
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("Operation", buildOperationNode(op));
+ return Response.ok(response).build();
+ }
+
+ private Response handleListOperations(JsonNode request, String region) {
+ Map> filters = parseFilters(request);
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode arr = response.putArray("Operations");
+ for (Operation op : service.listOperations(region, filters)) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("Id", op.getId());
+ node.put("Status", op.getStatus());
+ arr.add(node);
+ }
+ return Response.ok(response).build();
+ }
+
+ // ──────────────────────────── Services ────────────────────────────
+
+ private Response handleCreateService(JsonNode request, String region) {
+ Service created = service.createService(
+ text(request, "Name"), text(request, "NamespaceId"), text(request, "CreatorRequestId"),
+ text(request, "Description"), rawJson(request.path("DnsConfig")),
+ rawJson(request.path("HealthCheckConfig")), rawJson(request.path("HealthCheckCustomConfig")),
+ text(request, "Type"), parseTags(request), region);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("Service", buildServiceNode(created));
+ return Response.ok(response).build();
+ }
+
+ private Response handleGetService(JsonNode request) {
+ Service s = service.getService(text(request, "Id"));
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("Service", buildServiceNode(s));
+ return Response.ok(response).build();
+ }
+
+ private Response handleListServices(JsonNode request, String region) {
+ Map> filters = parseFilters(request);
+ String namespaceId = filters.containsKey("NAMESPACE_ID") && !filters.get("NAMESPACE_ID").isEmpty()
+ ? filters.get("NAMESPACE_ID").get(0) : null;
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode arr = response.putArray("Services");
+ for (Service s : service.listServices(region, namespaceId)) {
+ arr.add(buildServiceSummaryNode(s));
+ }
+ return Response.ok(response).build();
+ }
+
+ private Response handleDeleteService(JsonNode request) {
+ service.deleteService(text(request, "Id"));
+ return Response.ok(objectMapper.createObjectNode()).build();
+ }
+
+ // ──────────────────────────── Instances ────────────────────────────
+
+ private Response handleGetInstance(JsonNode request) {
+ Instance instance = service.getInstance(text(request, "ServiceId"), text(request, "InstanceId"));
+ ObjectNode response = objectMapper.createObjectNode();
+ ObjectNode node = response.putObject("Instance");
+ node.put("Id", instance.getInstanceId());
+ if (instance.getCreatorRequestId() != null) {
+ node.put("CreatorRequestId", instance.getCreatorRequestId());
+ }
+ node.set("Attributes", attributesNode(instance.getAttributes()));
+ return Response.ok(response).build();
+ }
+
+ private Response handleListInstances(JsonNode request) {
+ List instances = service.listInstances(text(request, "ServiceId"));
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode arr = response.putArray("Instances");
+ for (Instance i : instances) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("Id", i.getInstanceId());
+ node.set("Attributes", attributesNode(i.getAttributes()));
+ arr.add(node);
+ }
+ return Response.ok(response).build();
+ }
+
+ private Response handleGetInstancesHealthStatus(JsonNode request) {
+ List ids = new ArrayList<>();
+ request.path("Instances").forEach(n -> ids.add(n.asText()));
+ Map status = service.getInstancesHealthStatus(text(request, "ServiceId"), ids);
+ ObjectNode response = objectMapper.createObjectNode();
+ ObjectNode statusNode = response.putObject("Status");
+ status.forEach(statusNode::put);
+ return Response.ok(response).build();
+ }
+
+ // ──────────────────────────── Discovery ────────────────────────────
+
+ private Response handleDiscoverInstances(JsonNode request, String region) {
+ Integer maxResults = request.has("MaxResults") ? request.path("MaxResults").asInt() : null;
+ CloudMapService.DiscoverResult result = service.discoverInstances(
+ text(request, "NamespaceName"), text(request, "ServiceName"),
+ text(request, "HealthStatus"), parseAttributes(request.path("QueryParameters")),
+ maxResults, region);
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode arr = response.putArray("Instances");
+ for (Instance i : result.instances()) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("InstanceId", i.getInstanceId());
+ node.put("NamespaceName", text(request, "NamespaceName"));
+ node.put("ServiceName", text(request, "ServiceName"));
+ node.put("HealthStatus", i.getHealthStatus());
+ node.set("Attributes", attributesNode(i.getAttributes()));
+ arr.add(node);
+ }
+ response.put("InstancesRevision", result.revision());
+ return Response.ok(response).build();
+ }
+
+ private Response handleDiscoverInstancesRevision(JsonNode request, String region) {
+ long revision = service.discoverInstancesRevision(
+ text(request, "NamespaceName"), text(request, "ServiceName"), region);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.put("InstancesRevision", revision);
+ return Response.ok(response).build();
+ }
+
+ // ──────────────────────────── Tags ────────────────────────────
+
+ private Response handleTagResource(JsonNode request) {
+ service.tagResource(text(request, "ResourceARN"), parseTags(request));
+ return Response.ok(objectMapper.createObjectNode()).build();
+ }
+
+ private Response handleUntagResource(JsonNode request) {
+ List keys = new ArrayList<>();
+ request.path("TagKeys").forEach(k -> keys.add(k.asText()));
+ service.untagResource(text(request, "ResourceARN"), keys);
+ return Response.ok(objectMapper.createObjectNode()).build();
+ }
+
+ private Response handleListTagsForResource(JsonNode request) {
+ Map tags = service.listTagsForResource(text(request, "ResourceARN"));
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode arr = response.putArray("Tags");
+ tags.forEach((k, v) -> {
+ ObjectNode tagNode = objectMapper.createObjectNode();
+ tagNode.put("Key", k);
+ tagNode.put("Value", v);
+ arr.add(tagNode);
+ });
+ return Response.ok(response).build();
+ }
+
+ // ──────────────────────────── Builders ────────────────────────────
+
+ private Response opResponse(Operation op) {
+ ObjectNode response = objectMapper.createObjectNode();
+ response.put("OperationId", op.getId());
+ return Response.ok(response).build();
+ }
+
+ private ObjectNode buildNamespaceNode(Namespace ns) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("Id", ns.getId());
+ node.put("Arn", ns.getArn());
+ node.put("Name", ns.getName());
+ node.put("Type", ns.getType());
+ if (ns.getDescription() != null) {
+ node.put("Description", ns.getDescription());
+ }
+ node.put("ServiceCount", ns.getServiceCount());
+ if (ns.getCreateDate() != null) {
+ node.put("CreateDate", ns.getCreateDate().getEpochSecond());
+ }
+ if (ns.getCreatorRequestId() != null) {
+ node.put("CreatorRequestId", ns.getCreatorRequestId());
+ }
+ node.set("Properties", buildNamespaceProperties(ns));
+ return node;
+ }
+
+ private ObjectNode buildNamespaceProperties(Namespace ns) {
+ ObjectNode props = objectMapper.createObjectNode();
+ if (!"HTTP".equals(ns.getType())) {
+ ObjectNode dns = props.putObject("DnsProperties");
+ if (ns.getHostedZoneId() != null) {
+ dns.put("HostedZoneId", ns.getHostedZoneId());
+ }
+ dns.putObject("SOA").put("TTL", 15);
+ }
+ props.putObject("HttpProperties").put("HttpName", ns.getName());
+ return props;
+ }
+
+ private ObjectNode buildServiceNode(Service s) {
+ ObjectNode node = buildServiceSummaryNode(s);
+ if (s.getNamespaceId() != null) {
+ node.put("NamespaceId", s.getNamespaceId());
+ }
+ if (s.getCreatorRequestId() != null) {
+ node.put("CreatorRequestId", s.getCreatorRequestId());
+ }
+ return node;
+ }
+
+ private ObjectNode buildServiceSummaryNode(Service s) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("Id", s.getId());
+ node.put("Arn", s.getArn());
+ node.put("Name", s.getName());
+ if (s.getType() != null) {
+ node.put("Type", s.getType());
+ }
+ if (s.getDescription() != null) {
+ node.put("Description", s.getDescription());
+ }
+ node.put("InstanceCount", s.getInstanceCount());
+ setRawJson(node, "DnsConfig", s.getDnsConfig());
+ setRawJson(node, "HealthCheckConfig", s.getHealthCheckConfig());
+ setRawJson(node, "HealthCheckCustomConfig", s.getHealthCheckCustomConfig());
+ if (s.getCreateDate() != null) {
+ node.put("CreateDate", s.getCreateDate().getEpochSecond());
+ }
+ return node;
+ }
+
+ private ObjectNode buildOperationNode(Operation op) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("Id", op.getId());
+ node.put("Type", op.getType());
+ node.put("Status", op.getStatus());
+ if (op.getErrorMessage() != null) {
+ node.put("ErrorMessage", op.getErrorMessage());
+ }
+ if (op.getErrorCode() != null) {
+ node.put("ErrorCode", op.getErrorCode());
+ }
+ if (op.getCreateDate() != null) {
+ node.put("CreateDate", op.getCreateDate().getEpochSecond());
+ }
+ if (op.getUpdateDate() != null) {
+ node.put("UpdateDate", op.getUpdateDate().getEpochSecond());
+ }
+ ObjectNode targets = node.putObject("Targets");
+ op.getTargets().forEach(targets::put);
+ return node;
+ }
+
+ private ObjectNode attributesNode(Map attributes) {
+ ObjectNode node = objectMapper.createObjectNode();
+ if (attributes != null) {
+ attributes.forEach(node::put);
+ }
+ return node;
+ }
+
+ // ──────────────────────────── Parsing ────────────────────────────
+
+ private Map> parseFilters(JsonNode request) {
+ Map> filters = new LinkedHashMap<>();
+ JsonNode filtersNode = request.path("Filters");
+ if (filtersNode.isArray()) {
+ for (JsonNode f : filtersNode) {
+ String name = f.path("Name").asText(null);
+ if (name == null) {
+ continue;
+ }
+ List values = new ArrayList<>();
+ f.path("Values").forEach(v -> values.add(v.asText()));
+ filters.put(name, values);
+ }
+ }
+ return filters;
+ }
+
+ private Map parseAttributes(JsonNode attributesNode) {
+ Map attributes = new LinkedHashMap<>();
+ if (attributesNode != null && attributesNode.isObject()) {
+ attributesNode.fields().forEachRemaining(e -> attributes.put(e.getKey(), e.getValue().asText()));
+ }
+ return attributes;
+ }
+
+ private Map parseTags(JsonNode request) {
+ Map tags = new LinkedHashMap<>();
+ JsonNode tagsNode = request.path("Tags");
+ if (tagsNode.isArray()) {
+ for (JsonNode tag : tagsNode) {
+ String key = tag.path("Key").asText(null);
+ if (key != null) {
+ tags.put(key, tag.path("Value").asText(null));
+ }
+ }
+ }
+ return tags;
+ }
+
+ private String text(JsonNode request, String field) {
+ JsonNode node = request.path(field);
+ return node.isMissingNode() || node.isNull() ? null : node.asText(null);
+ }
+
+ private String rawJson(JsonNode node) {
+ return (node != null && node.isObject() && !node.isEmpty()) ? node.toString() : null;
+ }
+
+ private void setRawJson(ObjectNode target, String field, String rawJson) {
+ if (rawJson == null) {
+ return;
+ }
+ try {
+ target.set(field, objectMapper.readTree(rawJson));
+ } catch (Exception e) {
+ LOG.warnv("Failed to parse stored {0} JSON; field omitted. Value: {1}", field, rawJson);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudmap/CloudMapService.java b/src/main/java/io/github/hectorvent/floci/services/cloudmap/CloudMapService.java
new file mode 100644
index 0000000000..d6957bb420
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudmap/CloudMapService.java
@@ -0,0 +1,556 @@
+package io.github.hectorvent.floci.services.cloudmap;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import io.github.hectorvent.floci.config.EmulatorConfig;
+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.cloudmap.model.Instance;
+import io.github.hectorvent.floci.services.cloudmap.model.Namespace;
+import io.github.hectorvent.floci.services.cloudmap.model.Operation;
+import io.github.hectorvent.floci.services.cloudmap.model.Service;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import org.jboss.logging.Logger;
+
+import java.security.SecureRandom;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.UUID;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Cloud Map (AWS service discovery) business logic. Mirrors the EventBridge service
+ * pattern: ID-keyed account-aware storage, {@link AwsException} for domain errors.
+ * Async operations apply their effect synchronously and record an {@link Operation}
+ * whose status reaches SUCCESS immediately (or after a configurable delay).
+ */
+@ApplicationScoped
+public class CloudMapService {
+
+ private static final Logger LOG = Logger.getLogger(CloudMapService.class);
+ private static final String ALNUM = "abcdefghijklmnopqrstuvwxyz0123456789";
+ private static final SecureRandom RANDOM = new SecureRandom();
+
+ private final StorageBackend namespaceStore;
+ private final StorageBackend serviceStore;
+ private final StorageBackend instanceStore;
+ private final StorageBackend operationStore;
+ private final RegionResolver regionResolver;
+ private final int completionDelaySeconds;
+ private final ScheduledExecutorService scheduler;
+
+ @Inject
+ public CloudMapService(StorageFactory storageFactory, EmulatorConfig config,
+ RegionResolver regionResolver) {
+ this.namespaceStore = storageFactory.create("cloudmap", "cloudmap-namespaces.json",
+ new TypeReference