})
+ * to and from {@link DataSyncService}.
+ *
+ * The task-execution data plane ({@code StartTaskExecution}, {@code DescribeTaskExecution},
+ * {@code ListTaskExecutions}, {@code CancelTaskExecution}, {@code UpdateTaskExecution}) moves
+ * real bytes between real storage systems and is not emulated. Those operations fall through
+ * to a clean {@code UnknownOperationException} rather than a stub success, so callers fail
+ * fast instead of stranding a waiter on a transfer that will never progress.
+ *
+ *
Every location action is spelled out as its own switch label rather than matched by
+ * prefix: the action tables in {@code docs/services/datasync.md} are generated from these
+ * labels, and a prefix match would document none of them.
+ */
+@ApplicationScoped
+public class DataSyncJsonHandler {
+
+ private static final String CREATE_LOCATION = "CreateLocation";
+ private static final String DESCRIBE_LOCATION = "DescribeLocation";
+ private static final String UPDATE_LOCATION = "UpdateLocation";
+
+ private final DataSyncService dataSyncService;
+ private final ObjectMapper mapper;
+
+ @Inject
+ public DataSyncJsonHandler(DataSyncService dataSyncService, ObjectMapper mapper) {
+ this.dataSyncService = dataSyncService;
+ this.mapper = mapper;
+ }
+
+ public Response handle(String action, JsonNode request, String region) {
+ return switch (action) {
+ case "CreateAgent" -> {
+ DataSyncAgent agent = dataSyncService.createAgent(request, region);
+ yield ok(mapper.createObjectNode().put("AgentArn", agent.getAgentArn()));
+ }
+ case "DescribeAgent" -> ok(describeAgent(dataSyncService.getAgent(text(request, "AgentArn"))));
+ case "UpdateAgent" -> {
+ dataSyncService.updateAgent(text(request, "AgentArn"), text(request, "Name"));
+ yield ok(mapper.createObjectNode());
+ }
+ case "DeleteAgent" -> {
+ dataSyncService.deleteAgent(text(request, "AgentArn"));
+ yield ok(mapper.createObjectNode());
+ }
+ case "ListAgents" -> {
+ var page = dataSyncService.listAgents(text(request, "NextToken"),
+ request.path("MaxResults").asInt(0));
+ ObjectNode response = mapper.createObjectNode();
+ ArrayNode entries = response.putArray("Agents");
+ for (DataSyncAgent agent : page.items()) {
+ ObjectNode entry = entries.addObject();
+ entry.put("AgentArn", agent.getAgentArn());
+ entry.put("Name", agent.getName() != null ? agent.getName() : "");
+ entry.put("Status", agent.getStatus());
+ entry.putObject("Platform").put("Version", agent.getPlatformVersion());
+ }
+ putNextToken(response, page.nextToken());
+ yield ok(response);
+ }
+
+ case "CreateLocationAzureBlob", "CreateLocationEfs", "CreateLocationFsxLustre",
+ "CreateLocationFsxOntap", "CreateLocationFsxOpenZfs", "CreateLocationFsxWindows",
+ "CreateLocationHdfs", "CreateLocationNfs", "CreateLocationObjectStorage",
+ "CreateLocationS3", "CreateLocationSmb" -> {
+ DataSyncLocation location = dataSyncService.createLocation(
+ locationType(action, CREATE_LOCATION), request, region);
+ yield ok(mapper.createObjectNode().put("LocationArn", location.getLocationArn()));
+ }
+ case "DescribeLocationAzureBlob", "DescribeLocationEfs", "DescribeLocationFsxLustre",
+ "DescribeLocationFsxOntap", "DescribeLocationFsxOpenZfs", "DescribeLocationFsxWindows",
+ "DescribeLocationHdfs", "DescribeLocationNfs", "DescribeLocationObjectStorage",
+ "DescribeLocationS3", "DescribeLocationSmb" -> ok(describeLocation(dataSyncService.getLocation(
+ text(request, "LocationArn"), locationType(action, DESCRIBE_LOCATION))));
+ case "UpdateLocationAzureBlob", "UpdateLocationEfs", "UpdateLocationFsxLustre",
+ "UpdateLocationFsxOntap", "UpdateLocationFsxOpenZfs", "UpdateLocationFsxWindows",
+ "UpdateLocationHdfs", "UpdateLocationNfs", "UpdateLocationObjectStorage",
+ "UpdateLocationS3", "UpdateLocationSmb" -> {
+ dataSyncService.updateLocation(locationType(action, UPDATE_LOCATION), request);
+ yield ok(mapper.createObjectNode());
+ }
+ case "ListLocations" -> {
+ var page = dataSyncService.listLocations(request.get("Filters"),
+ text(request, "NextToken"), request.path("MaxResults").asInt(0));
+ ObjectNode response = mapper.createObjectNode();
+ ArrayNode entries = response.putArray("Locations");
+ for (DataSyncLocation location : page.items()) {
+ ObjectNode entry = entries.addObject();
+ entry.put("LocationArn", location.getLocationArn());
+ entry.put("LocationUri", location.getLocationUri());
+ }
+ putNextToken(response, page.nextToken());
+ yield ok(response);
+ }
+ case "DeleteLocation" -> {
+ dataSyncService.deleteLocation(text(request, "LocationArn"));
+ yield ok(mapper.createObjectNode());
+ }
+
+ case "CreateTask" -> {
+ DataSyncTask task = dataSyncService.createTask(request, region);
+ yield ok(mapper.createObjectNode().put("TaskArn", task.getTaskArn()));
+ }
+ case "DescribeTask" -> ok(describeTask(dataSyncService.getTask(text(request, "TaskArn"))));
+ case "UpdateTask" -> {
+ dataSyncService.updateTask(request);
+ yield ok(mapper.createObjectNode());
+ }
+ case "DeleteTask" -> {
+ dataSyncService.deleteTask(text(request, "TaskArn"));
+ yield ok(mapper.createObjectNode());
+ }
+ case "ListTasks" -> {
+ var page = dataSyncService.listTasks(request.get("Filters"),
+ text(request, "NextToken"), request.path("MaxResults").asInt(0));
+ ObjectNode response = mapper.createObjectNode();
+ ArrayNode entries = response.putArray("Tasks");
+ for (DataSyncTask task : page.items()) {
+ ObjectNode entry = entries.addObject();
+ entry.put("TaskArn", task.getTaskArn());
+ entry.put("Status", task.getStatus());
+ entry.put("Name", task.getName() != null ? task.getName() : "");
+ entry.put("TaskMode", task.getTaskMode());
+ }
+ putNextToken(response, page.nextToken());
+ yield ok(response);
+ }
+
+ case "TagResource" -> {
+ dataSyncService.tagResource(text(request, "ResourceArn"),
+ DataSyncService.tagsOf(request.path("Tags")));
+ yield ok(mapper.createObjectNode());
+ }
+ case "UntagResource" -> {
+ dataSyncService.untagResource(text(request, "ResourceArn"),
+ DataSyncService.stringList(request.path("Keys")));
+ yield ok(mapper.createObjectNode());
+ }
+ case "ListTagsForResource" -> {
+ Map tags = dataSyncService.listTagsForResource(text(request, "ResourceArn"));
+ ObjectNode response = mapper.createObjectNode();
+ ArrayNode entries = response.putArray("Tags");
+ tags.forEach((key, value) -> entries.addObject().put("Key", key).put("Value", value));
+ yield ok(response);
+ }
+
+ default -> throw new AwsException("UnknownOperationException",
+ "Operation " + action + " is not supported by floci", 400);
+ };
+ }
+
+ private static DataSyncLocationType locationType(String action, String operationPrefix) {
+ String suffix = action.substring(operationPrefix.length());
+ return DataSyncLocationType.fromOperationSuffix(suffix)
+ .orElseThrow(() -> new AwsException("UnknownOperationException",
+ "Operation " + action + " is not supported by floci", 400));
+ }
+
+ private ObjectNode describeAgent(DataSyncAgent agent) {
+ ObjectNode response = mapper.createObjectNode();
+ response.put("AgentArn", agent.getAgentArn());
+ response.put("Name", agent.getName() != null ? agent.getName() : "");
+ response.put("Status", agent.getStatus());
+ response.put("CreationTime", epochSeconds(agent.getCreationTime()));
+ response.put("LastConnectionTime", epochSeconds(agent.getLastConnectionTime()));
+ response.put("EndpointType", agent.getEndpointType());
+ response.putObject("Platform").put("Version", agent.getPlatformVersion());
+ if (agent.getVpcEndpointId() != null) {
+ ObjectNode privateLink = response.putObject("PrivateLinkConfig");
+ privateLink.put("VpcEndpointId", agent.getVpcEndpointId());
+ putStrings(privateLink, "SubnetArns", agent.getSubnetArns());
+ putStrings(privateLink, "SecurityGroupArns", agent.getSecurityGroupArns());
+ }
+ return response;
+ }
+
+ private ObjectNode describeLocation(DataSyncLocation location) {
+ ObjectNode response = mapper.createObjectNode();
+ response.put("LocationArn", location.getLocationArn());
+ response.put("LocationUri", location.getLocationUri());
+ JsonNode configuration = location.getConfiguration();
+ for (String member : location.getLocationType().describeMembers()) {
+ JsonNode value = configuration.get(member);
+ if (value != null && !value.isNull()) {
+ response.set(member, value.deepCopy());
+ }
+ }
+ response.put("CreationTime", epochSeconds(location.getCreationTime()));
+ return response;
+ }
+
+ private ObjectNode describeTask(DataSyncTask task) {
+ ObjectNode response = mapper.createObjectNode();
+ response.put("TaskArn", task.getTaskArn());
+ response.put("Status", task.getStatus());
+ response.put("Name", task.getName() != null ? task.getName() : "");
+ response.put("TaskMode", task.getTaskMode());
+ response.put("SourceLocationArn", task.getSourceLocationArn());
+ response.put("DestinationLocationArn", task.getDestinationLocationArn());
+ if (task.getCloudWatchLogGroupArn() != null) {
+ response.put("CloudWatchLogGroupArn", task.getCloudWatchLogGroupArn());
+ }
+ response.putArray("SourceNetworkInterfaceArns");
+ response.putArray("DestinationNetworkInterfaceArns");
+ response.set("Options", task.getOptions() != null
+ ? task.getOptions().deepCopy() : mapper.createObjectNode());
+ response.set("Excludes", task.getExcludes() != null
+ ? task.getExcludes().deepCopy() : mapper.createArrayNode());
+ response.set("Includes", task.getIncludes() != null
+ ? task.getIncludes().deepCopy() : mapper.createArrayNode());
+ if (task.getSchedule() != null) {
+ response.set("Schedule", task.getSchedule().deepCopy());
+ }
+ if (task.getManifestConfig() != null) {
+ response.set("ManifestConfig", task.getManifestConfig().deepCopy());
+ }
+ if (task.getTaskReportConfig() != null) {
+ response.set("TaskReportConfig", task.getTaskReportConfig().deepCopy());
+ }
+ response.put("CreationTime", epochSeconds(task.getCreationTime()));
+ return response;
+ }
+
+ private static void putStrings(ObjectNode parent, String member, List values) {
+ ArrayNode array = parent.putArray(member);
+ values.forEach(array::add);
+ }
+
+ private static void putNextToken(ObjectNode response, String nextToken) {
+ if (nextToken != null) {
+ response.put("NextToken", nextToken);
+ }
+ }
+
+ private static double epochSeconds(Instant instant) {
+ return (instant != null ? instant : Instant.EPOCH).toEpochMilli() / 1000.0;
+ }
+
+ private static String text(JsonNode request, String member) {
+ return request.hasNonNull(member) ? request.get(member).asText() : null;
+ }
+
+ private static Response ok(ObjectNode body) {
+ return Response.ok(body).build();
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/datasync/DataSyncService.java b/src/main/java/io/github/hectorvent/floci/services/datasync/DataSyncService.java
new file mode 100644
index 0000000000..1b082b1ae1
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/datasync/DataSyncService.java
@@ -0,0 +1,739 @@
+package io.github.hectorvent.floci.services.datasync;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.storage.StorageBackend;
+import io.github.hectorvent.floci.core.storage.StorageFactory;
+import io.github.hectorvent.floci.services.datasync.model.DataSyncAgent;
+import io.github.hectorvent.floci.services.datasync.model.DataSyncLocation;
+import io.github.hectorvent.floci.services.datasync.model.DataSyncLocationType;
+import io.github.hectorvent.floci.services.datasync.model.DataSyncTaggable;
+import io.github.hectorvent.floci.services.datasync.model.DataSyncTask;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import org.jboss.logging.Logger;
+
+import java.security.SecureRandom;
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+/**
+ * AWS DataSync management plane.
+ *
+ * Agents report {@code ONLINE} and tasks {@code AVAILABLE} from the moment they are
+ * created, so SDK and Terraform waiters finish on their first poll. Every
+ * {@code DescribeLocation*} answer is projected out of the create request that produced
+ * the location, with the location's {@code LocationUri} derived from the same request.
+ * Credential members ({@code Password}, {@code SecretKey}, SAS tokens, Kerberos files)
+ * are dropped before the configuration is stored, matching AWS, which never reads them
+ * back.
+ */
+@ApplicationScoped
+public class DataSyncService {
+
+ private static final Logger LOG = Logger.getLogger(DataSyncService.class);
+
+ private static final String HEX_ALPHABET = "0123456789abcdef";
+ private static final int RESOURCE_ID_LENGTH = 17;
+ private static final SecureRandom RANDOM = new SecureRandom();
+
+ public static final String AGENT_STATUS_ONLINE = "ONLINE";
+ public static final String TASK_STATUS_AVAILABLE = "AVAILABLE";
+ public static final String DEFAULT_TASK_MODE = "BASIC";
+ public static final String TASK_MODE_ENHANCED = "ENHANCED";
+ public static final String VERIFY_MODE_POINT_IN_TIME_CONSISTENT = "POINT_IN_TIME_CONSISTENT";
+ public static final String VERIFY_MODE_ONLY_FILES_TRANSFERRED = "ONLY_FILES_TRANSFERRED";
+
+ private static final Set TASK_MODES = Set.of(DEFAULT_TASK_MODE, TASK_MODE_ENHANCED);
+
+ /** Reported by DescribeAgent and ListAgents; floci runs no agent software. */
+ public static final String AGENT_PLATFORM_VERSION = "1.0.0";
+
+ private static final int DEFAULT_MAX_RESULTS = 100;
+
+ private static final Set CREDENTIAL_MEMBERS = Set.of(
+ "Password", "SecretKey", "SasConfiguration", "KerberosKeytab", "KerberosKrb5Conf");
+
+ private final StorageBackend agents;
+ private final StorageBackend locations;
+ private final StorageBackend tasks;
+ private final RegionResolver regionResolver;
+ private final ObjectMapper mapper;
+
+ @Inject
+ public DataSyncService(StorageFactory storageFactory, RegionResolver regionResolver, ObjectMapper mapper) {
+ this.agents = storageFactory.create("datasync", "datasync-agents.json",
+ new TypeReference