Light, fluffy, and always free - The AWS Local Emulator alternative
feat(batch): add AWS Batch service support (#1332)
devansh-jain-18022436eaae54
diff --git a/docs/index.md b/docs/index.mdindex b56974c8d5..f559926ca0 100644--- a/docs/index.md+++ b/docs/index.md@@ -12,7 +12,7 @@ Floci is a fast, free, and open-source local AWS service emulator built for deve## Supported Services-Floci emulates 54 AWS services. See the [Services Overview](services/index.md) for per-service operation counts, endpoints, and full protocol details.+Floci emulates 55 AWS services. See the [Services Overview](services/index.md) for per-service operation counts, endpoints, and full protocol details.| Service | Protocol ||---|---|diff --git a/docs/services/batch.md b/docs/services/batch.mdnew file mode 100644index 0000000000..b64cd7aa2f--- /dev/null+++ b/docs/services/batch.md@@ -0,0 +1,104 @@+# AWS Batch++**Protocol:** REST JSON+**Endpoint:** `http://localhost:4566/v1/...`++Floci Batch implements the AWS Batch control plane for local integration tests. It supports queue and job-definition metadata, immediate job completion for fast contract tests, Docker-backed execution when enabled, CloudFormation resource provisioning, and EventBridge rule targets with `BatchParameters`.++## Supported Operations++| Operation | Endpoint | Description |+|---|---|---|+| `CreateComputeEnvironment` | `POST /v1/createcomputeenvironment` | Store a local compute environment and return its ARN |+| `DescribeComputeEnvironments` | `POST /v1/describecomputeenvironments` | Describe all or selected compute environments |+| `CreateJobQueue` | `POST /v1/createjobqueue` | Store a local job queue attached to compute environments |+| `DescribeJobQueues` | `POST /v1/describejobqueues` | Describe all or selected job queues |+| `RegisterJobDefinition` | `POST /v1/registerjobdefinition` | Register a revisioned container job definition |+| `DeregisterJobDefinition` | `POST /v1/deregisterjobdefinition` | Mark a job definition revision inactive |+| `DescribeJobDefinitions` | `POST /v1/describejobdefinitions` | List job definitions by name, ARN, revision, and status |+| `SubmitJob` | `POST /v1/submitjob` | Submit a local Batch job |+| `DescribeJobs` | `POST /v1/describejobs` | Describe jobs by job ID |+| `ListJobs` | `POST /v1/listjobs` | List jobs by queue, status, AWS `filters`, and pagination |++## Runner Modes++Batch uses `floci.services.batch.runner-mode`.++| Value | Behavior |+|---|---|+| `immediate` | Default. `SubmitJob` persists the job, records lifecycle timestamps, creates one successful attempt, and returns after the job is `SUCCEEDED`. |+| `docker` | Starts one Docker container per attempt from the job-definition image, passes resolved command and environment values, applies `MEMORY` resource requirements as Docker memory limits, captures a CloudWatch Logs stream name, and sets `SUCCEEDED` or `FAILED` from the container exit code. Timed-out jobs fail without retry, matching AWS Batch timeout behavior. |++`process` mode is not implemented.++## Submit Behavior++Supported `SubmitJob` fields:++- `jobName`+- `jobDefinition`+- `jobQueue`+- `parameters`+- `containerOverrides.command`+- `containerOverrides.environment`+- `timeout.attemptDurationSeconds`+- `retryStrategy.attempts`+- `tags`++`containerOverrides.command` replaces the job-definition command. Command entries like `Ref::inputKey` are resolved from the merged parameter map before execution. Submit-time environment overrides merge over job-definition environment variables.++Jobs move through these local statuses:++```text+SUBMITTED -> PENDING -> RUNNABLE -> STARTING -> RUNNING -> SUCCEEDED|FAILED+```++Driving every immediate-mode job through `PENDING` is a local simplification for tests. AWS may skip that state when there are no dependency or capacity waits.++## EventBridge++EventBridge targets whose ARN points at a Batch job queue can include:++```json+{+ "BatchParameters": {+ "JobDefinition": "my-job:1",+ "JobName": "nightly-job",+ "ArrayProperties": {"Size": 2},+ "RetryStrategy": {"Attempts": 2}+ }+}+```++When the rule fires, Floci submits an equivalent Batch job to the target queue. If the target payload contains a root `Parameters` object, those key/value pairs are stringified and passed as Batch submit parameters. Flat payload fields are not converted into Batch parameters.++`ArrayProperties` is accepted and returned as target metadata for local deployment compatibility, but Batch still submits one local job and does not fan out array children.++## CloudFormation++Floci provisions these resource types:++- `AWS::Batch::ComputeEnvironment`+- `AWS::Batch::JobQueue`+- `AWS::Batch::JobDefinition`++IAM roles, VPC fields, Fargate declarations, log configuration, storage, and resource requirements are accepted as metadata. Docker mode applies `MEMORY` requirements as container memory limits; local scheduling does not simulate AWS capacity, VCPU allocation, or VPC networking.++## Configuration++| Variable | Default | Description |+|---|---|---|+| `FLOCI_SERVICES_BATCH_ENABLED` | `true` | Enable or disable Batch |+| `FLOCI_SERVICES_BATCH_RUNNER_MODE` | `immediate` | `immediate` or `docker` |+| `FLOCI_SERVICES_BATCH_DOCKER_NETWORK` | *(unset)* | Docker network for Batch containers |+| `FLOCI_STORAGE_SERVICES_BATCH_MODE` | *(inherits global)* | Optional storage mode override |+| `FLOCI_STORAGE_SERVICES_BATCH_FLUSH_INTERVAL_MS` | `5000` | Persistent storage flush interval |++## Limitations++- No IAM enforcement.+- No VPC/subnet/security-group simulation.+- No AWS-faithful capacity scheduling.+- No array job fan-out or multi-node jobs.+- `CancelJob` and `TerminateJob` are not implemented.+- EventBridge input transformers work through the existing EventBridge target input path; full Batch-specific input-transformer parity is not implemented.diff --git a/docs/services/index.md b/docs/services/index.mdindex f8d450a484..e7e480060c 100644--- a/docs/services/index.md+++ b/docs/services/index.md@@ -1,6 +1,6 @@# Services Overview-Floci emulates 54 AWS services on a single port (`4566`). All services use the real AWS wire protocol, your existing AWS CLI commands and SDK clients work without modification.+Floci emulates 55 AWS services on a single port (`4566`). All services use the real AWS wire protocol, your existing AWS CLI commands and SDK clients work without modification.This page is the canonical reference for supported service and operation counts. Some services expose separate control-plane and data-plane rows below. Other docs (and the README) should link here rather than duplicating the table.@@ -56,6 +56,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac| [ELB v2](elb.md) | `POST /` with `Action=` param | Query | 34 || [Auto Scaling](autoscaling.md) | `POST /` with `Action=` param | Query | 33 || [CodeBuild](codebuild.md) | `POST /` + `X-Amz-Target: CodeBuild_20161006.*` | JSON 1.1 | 20 |+| [AWS Batch](batch.md) | `/v1/...` | REST JSON | 10 || [CodeDeploy](codedeploy.md) | `POST /` + `X-Amz-Target: CodeDeploy_20141006.*` | JSON 1.1 | 30 || [AWS Backup](backup.md) | `/backup-vaults/*`, `/backup/plans/*`, `/backup-jobs/*`, `/supported-resource-types` | REST JSON | 20 || [CloudFront](cloudfront.md) | `/2020-05-31/distribution/*`, `/2020-05-31/cache-policy/*`, `/2020-05-31/function/*` | REST XML | 50 |diff --git a/mkdocs.yml b/mkdocs.ymlindex 10edc52341..76324cced8 100644--- a/mkdocs.yml+++ b/mkdocs.yml@@ -114,6 +114,7 @@ nav:- ELB v2: services/elb.md- Auto Scaling: services/autoscaling.md- CodeBuild: services/codebuild.md+ - AWS Batch: services/batch.md- CodeDeploy: services/codedeploy.md- AWS Backup: services/backup.md- CloudFront: services/cloudfront.mddiff --git a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.javaindex 531296d076..8ae11ba62f 100644--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java@@ -172,6 +172,7 @@ public interface EmulatorConfig {BackupStorageConfig backup();CloudFrontStorageConfig cloudfront();AppSyncStorageConfig appsync();+ BatchStorageConfig batch();}interface SsmStorageConfig {@@ -292,6 +293,13 @@ public interface EmulatorConfig {long flushIntervalMs();}+ interface BatchStorageConfig {+ Optional<String> mode();++ @WithDefault("5000")+ long flushIntervalMs();+ }+interface WalConfig {@WithDefault("30000")long compactionIntervalMs();@@ -370,6 +378,7 @@ public interface EmulatorConfig {CloudTrailServiceConfig cloudtrail();CloudFrontServiceConfig cloudfront();AppSyncServiceConfig appsync();+ BatchServiceConfig batch();}interface CloudTrailServiceConfig {@@ -424,6 +433,16 @@ public interface EmulatorConfig {Optional<String> dockerNetwork();}+ interface BatchServiceConfig {+ @WithDefault("true")+ boolean enabled();++ @WithDefault("immediate")+ String runnerMode();++ Optional<String> dockerNetwork();+ }+interface CodeDeployServiceConfig {@WithDefault("true")boolean enabled();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.javaindex 8957c47039..2e2c838c70 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@@ -4,6 +4,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;import io.github.hectorvent.floci.services.appconfig.AppConfigController;import io.github.hectorvent.floci.services.backup.BackupController;import io.github.hectorvent.floci.services.appconfig.AppConfigDataController;+import io.github.hectorvent.floci.services.batch.BatchController;import io.github.hectorvent.floci.services.bedrockruntime.BedrockRuntimeController;import io.github.hectorvent.floci.services.cognito.CognitoOAuthController;import io.github.hectorvent.floci.services.cognito.CognitoWellKnownController;@@ -240,6 +241,11 @@ public class ResolvedServiceCatalog {null, null, 5000L, null, ServiceProtocol.JSON,protocols(ServiceProtocol.JSON),Set.of("CodeBuild_20161006."), Set.of("codebuild"), Set.of(), Set.of()),+ descriptor("batch", "batch", config.services().batch().enabled(), true,+ "batch", storageMode(config.storage().services().batch().mode(), config.storage().mode()),+ config.storage().services().batch().flushIntervalMs(), null, ServiceProtocol.REST_JSON,+ protocols(ServiceProtocol.REST_JSON),+ Set.of(), Set.of("batch"), Set.of(), Set.of(BatchController.class)),descriptor("codedeploy", "codedeploy", config.services().codedeploy().enabled(), true,null, null, 5000L, null, ServiceProtocol.JSON,protocols(ServiceProtocol.JSON),diff --git a/src/main/java/io/github/hectorvent/floci/services/batch/BatchController.java b/src/main/java/io/github/hectorvent/floci/services/batch/BatchController.javanew file mode 100644index 0000000000..acf4f75067--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/batch/BatchController.java@@ -0,0 +1,136 @@+package io.github.hectorvent.floci.services.batch;++import com.fasterxml.jackson.core.JsonProcessingException;+import com.fasterxml.jackson.databind.JsonNode;+import com.fasterxml.jackson.databind.ObjectMapper;+import io.github.hectorvent.floci.core.common.AwsErrorResponse;+import io.github.hectorvent.floci.core.common.AwsException;+import io.github.hectorvent.floci.core.common.RegionResolver;+import jakarta.inject.Inject;+import jakarta.ws.rs.Consumes;+import jakarta.ws.rs.POST;+import jakarta.ws.rs.Path;+import jakarta.ws.rs.Produces;+import jakarta.ws.rs.core.Context;+import jakarta.ws.rs.core.HttpHeaders;+import jakarta.ws.rs.core.MediaType;+import jakarta.ws.rs.core.Response;+import org.jboss.logging.Logger;++@Path("/")+@Produces(MediaType.APPLICATION_JSON)+@Consumes(MediaType.WILDCARD)+public class BatchController {++ private static final Logger LOG = Logger.getLogger(BatchController.class);++ private final BatchService service;+ private final RegionResolver regionResolver;+ private final ObjectMapper objectMapper;++ @Inject+ public BatchController(BatchService service, RegionResolver regionResolver, ObjectMapper objectMapper) {+ this.service = service;+ this.regionResolver = regionResolver;+ this.objectMapper = objectMapper;+ }++ @POST+ @Path("/v1/createcomputeenvironment")+ public Response createComputeEnvironment(@Context HttpHeaders headers, String body) {+ return handle(headers, body, (request, region) ->+ Response.ok(service.createComputeEnvironment(request, region)).build());+ }++ @POST+ @Path("/v1/describecomputeenvironments")+ public Response describeComputeEnvironments(@Context HttpHeaders headers, String body) {+ return handle(headers, body, (request, region) ->+ Response.ok(service.describeComputeEnvironments(request)).build());+ }++ @POST+ @Path("/v1/createjobqueue")+ public Response createJobQueue(@Context HttpHeaders headers, String body) {+ return handle(headers, body, (request, region) ->+ Response.ok(service.createJobQueue(request, region)).build());+ }++ @POST+ @Path("/v1/describejobqueues")+ public Response describeJobQueues(@Context HttpHeaders headers, String body) {+ return handle(headers, body, (request, region) ->+ Response.ok(service.describeJobQueues(request)).build());+ }++ @POST+ @Path("/v1/registerjobdefinition")+ public Response registerJobDefinition(@Context HttpHeaders headers, String body) {+ return handle(headers, body, (request, region) ->+ Response.ok(service.registerJobDefinition(request, region)).build());+ }++ @POST+ @Path("/v1/deregisterjobdefinition")+ public Response deregisterJobDefinition(@Context HttpHeaders headers, String body) {+ return handle(headers, body, (request, region) ->+ Response.ok(service.deregisterJobDefinition(request)).build());+ }++ @POST+ @Path("/v1/describejobdefinitions")+ public Response describeJobDefinitions(@Context HttpHeaders headers, String body) {+ return handle(headers, body, (request, region) ->+ Response.ok(service.describeJobDefinitions(request)).build());+ }++ @POST+ @Path("/v1/submitjob")+ public Response submitJob(@Context HttpHeaders headers, String body) {+ return handle(headers, body, (request, region) ->+ Response.ok(service.submitJob(request, region)).build());+ }++ @POST+ @Path("/v1/describejobs")+ public Response describeJobs(@Context HttpHeaders headers, String body) {+ return handle(headers, body, (request, region) ->+ Response.ok(service.describeJobs(request)).build());+ }++ @POST+ @Path("/v1/listjobs")+ public Response listJobs(@Context HttpHeaders headers, String body) {+ return handle(headers, body, (request, region) ->+ Response.ok(service.listJobs(request)).build());+ }++ private Response handle(HttpHeaders headers, String body, Handler handler) {+ try {+ JsonNode request = body == null || body.isBlank()+ ? objectMapper.createObjectNode()+ : objectMapper.readTree(body);+ return handler.handle(request, regionResolver.resolveRegion(headers));+ } catch (AwsException e) {+ return error(e.getHttpStatus(), e.getErrorCode(), e.getMessage());+ } catch (JsonProcessingException e) {+ return error(400, "ClientException", "Malformed JSON request body.");+ } catch (Exception e) {+ LOG.error("Error processing AWS Batch request", e);+ return error(500, "ServerException", e.getMessage());+ }+ }++ private static Response error(int status, String code, String message) {+ return Response.status(status)+ .type(MediaType.APPLICATION_JSON)+ .header("X-Amzn-Errortype", code)+ .entity(new AwsErrorResponse(code, message))+ .build();+ }++ @FunctionalInterface+ private interface Handler {+ Response handle(JsonNode request, String region);+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/batch/BatchDockerRunner.java b/src/main/java/io/github/hectorvent/floci/services/batch/BatchDockerRunner.javanew file mode 100644index 0000000000..9f43c369d6--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/batch/BatchDockerRunner.java@@ -0,0 +1,183 @@+package io.github.hectorvent.floci.services.batch;++import com.github.dockerjava.api.command.InspectContainerResponse;+import com.github.dockerjava.api.exception.NotFoundException;+import io.github.hectorvent.floci.config.EmulatorConfig;+import io.github.hectorvent.floci.core.common.dns.EmbeddedDnsServer;+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.ContainerLogStreamer;+import io.github.hectorvent.floci.core.common.docker.ContainerSpec;+import io.github.hectorvent.floci.services.batch.model.BatchJob;+import io.github.hectorvent.floci.services.batch.model.BatchKeyValue;+import io.github.hectorvent.floci.services.batch.model.BatchResourceRequirement;+import io.github.hectorvent.floci.services.batch.model.BatchRunResult;+import jakarta.enterprise.context.ApplicationScoped;+import jakarta.inject.Inject;+import org.jboss.logging.Logger;++import java.io.Closeable;+import java.time.Duration;+import java.util.ArrayList;+import java.util.List;++@ApplicationScoped+public class BatchDockerRunner {++ private static final Logger LOG = Logger.getLogger(BatchDockerRunner.class);+ private static final String LOG_GROUP = "/aws/batch/job";++ private final ContainerBuilder containerBuilder;+ private final ContainerLifecycleManager lifecycleManager;+ private final ContainerLogStreamer logStreamer;+ private final EmulatorConfig config;+ private final ContainerDetector containerDetector;++ @Inject+ public BatchDockerRunner(ContainerBuilder containerBuilder,+ ContainerLifecycleManager lifecycleManager,+ ContainerLogStreamer logStreamer,+ EmulatorConfig config,+ ContainerDetector containerDetector) {+ this.containerBuilder = containerBuilder;+ this.lifecycleManager = lifecycleManager;+ this.logStreamer = logStreamer;+ this.config = config;+ this.containerDetector = containerDetector;+ }++ public BatchRunResult run(BatchJob job, int attemptNumber) {+ long startedAt = System.currentTimeMillis();+ String logStreamName = logStreamer.generateLogStreamName(+ job.getJobDefinitionName() + "/default/" + job.getJobId());+ String containerName = "floci-batch-" + job.getJobId() + "-" + attemptNumber;+ Closeable logHandle = null;+ String containerId = null;++ try {+ if (job.getContainerImage() == null || job.getContainerImage().isBlank()) {+ return failed(startedAt, logStreamName, "Job definition container image is missing");+ }++ ContainerBuilder.Builder builder = containerBuilder.newContainer(job.getContainerImage())+ .withName(containerName)+ .withEnv(buildEnvironment(job, attemptNumber))+ .withDockerNetwork(config.services().batch().dockerNetwork())+ .withHostDockerInternalOnLinux()+ .withEmbeddedDns()+ .withLogRotation();++ if (job.getResolvedCommand() != null && !job.getResolvedCommand().isEmpty()) {+ builder.withCmd(job.getResolvedCommand());+ }+ applyResourceRequirements(builder, job);++ ContainerSpec spec = builder.build();+ containerId = lifecycleManager.createAndStart(spec).containerId();+ logHandle = logStreamer.attach(containerId, LOG_GROUP, logStreamName, job.getRegion(),+ "batch:" + job.getJobName() + ":" + job.getJobId());++ Integer exitCode = waitForExit(containerId, timeout(job));+ long stoppedAt = System.currentTimeMillis();+ if (exitCode == null) {+ lifecycleManager.stopAndRemove(containerId, logHandle);+ return new BatchRunResult(137, "Job timed out", logStreamName, startedAt, stoppedAt, true);+ }+ lifecycleManager.stopAndRemove(containerId, logHandle);+ return new BatchRunResult(exitCode, exitCode == 0 ? null : "Container exited with code " + exitCode,+ logStreamName, startedAt, stoppedAt, false);+ } catch (Exception e) {+ LOG.warnv("Batch Docker job {0} failed: {1}", job.getJobId(), e.getMessage());+ if (containerId != null) {+ lifecycleManager.stopAndRemove(containerId, logHandle);+ }+ return failed(startedAt, logStreamName, e.getMessage());+ }+ }++ private BatchRunResult failed(long startedAt, String logStreamName, String reason) {+ return new BatchRunResult(1, reason, logStreamName, startedAt, System.currentTimeMillis(), false);+ }++ private List<String> buildEnvironment(BatchJob job, int attemptNumber) {+ List<String> env = new ArrayList<>();+ env.add("AWS_REGION=" + job.getRegion());+ env.add("AWS_DEFAULT_REGION=" + job.getRegion());+ env.add("AWS_ACCESS_KEY_ID=test");+ env.add("AWS_SECRET_ACCESS_KEY=test");+ env.add("AWS_SESSION_TOKEN=test");+ String hostname = resolveEndpointHostname();+ String endpoint = "http://" + hostname + ":" + config.port();+ env.add("FLOCI_ENDPOINT=" + endpoint);+ env.add("AWS_ENDPOINT_URL=" + endpoint);+ env.add("FLOCI_HOSTNAME=" + hostname);+ env.add("AWS_BATCH_JOB_ID=" + job.getJobId());+ env.add("AWS_BATCH_JOB_ATTEMPT=" + attemptNumber);+ env.add("AWS_BATCH_JQ_NAME=" + job.getJobQueueName());+ env.add("AWS_BATCH_CE_NAME=local");+ if (job.getResolvedEnvironment() != null) {+ for (BatchKeyValue kv : job.getResolvedEnvironment()) {+ env.add(kv.getName() + "=" + (kv.getValue() != null ? kv.getValue() : ""));+ }+ }+ return env;+ }++ String resolveEndpointHostname() {+ if (containerDetector.isRunningInContainer()) {+ return config.hostname().orElse(EmbeddedDnsServer.DEFAULT_SUFFIX);+ }+ return "host.docker.internal";+ }++ private void applyResourceRequirements(ContainerBuilder.Builder builder, BatchJob job) {+ if (job.getResourceRequirements() == null) {+ return;+ }+ for (BatchResourceRequirement requirement : job.getResourceRequirements()) {+ if (!"MEMORY".equalsIgnoreCase(requirement.getType()) || requirement.getValue() == null) {+ continue;+ }+ try {+ builder.withMemoryMb(Integer.parseInt(requirement.getValue()));+ } catch (NumberFormatException e) {+ LOG.warnv("Ignoring invalid Batch MEMORY resource value for job {0}: {1}",+ job.getJobId(), requirement.getValue());+ }+ return;+ }+ }++ private Duration timeout(BatchJob job) {+ if (job.getTimeout() == null || job.getTimeout().getAttemptDurationSeconds() == null) {+ return Duration.ZERO;+ }+ return Duration.ofSeconds(job.getTimeout().getAttemptDurationSeconds());+ }++ private Integer waitForExit(String containerId, Duration timeout) throws InterruptedException {+ long deadline = timeout.isZero() ? Long.MAX_VALUE : System.currentTimeMillis() + timeout.toMillis();+ while (System.currentTimeMillis() <= deadline) {+ Integer exitCode = getExitCodeIfStopped(containerId);+ if (exitCode != null) {+ return exitCode;+ }+ Thread.sleep(250);+ }+ return null;+ }++ private Integer getExitCodeIfStopped(String containerId) {+ try {+ InspectContainerResponse inspect = lifecycleManager.getDockerClient().inspectContainerCmd(containerId).exec();+ if (Boolean.TRUE.equals(inspect.getState().getRunning())) {+ return null;+ }+ Long exitCode = inspect.getState().getExitCodeLong();+ return exitCode != null ? exitCode.intValue() : 0;+ } catch (NotFoundException e) {+ return 1;+ }+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/batch/BatchService.java b/src/main/java/io/github/hectorvent/floci/services/batch/BatchService.javanew file mode 100644index 0000000000..9d789c223e--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/batch/BatchService.java@@ -0,0 +1,1191 @@+package io.github.hectorvent.floci.services.batch;++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.ArrayNode;+import com.fasterxml.jackson.databind.node.ObjectNode;+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.batch.model.BatchAttempt;+import io.github.hectorvent.floci.services.batch.model.BatchAttemptContainer;+import io.github.hectorvent.floci.services.batch.model.BatchComputeEnvironment;+import io.github.hectorvent.floci.services.batch.model.BatchComputeEnvironmentOrder;+import io.github.hectorvent.floci.services.batch.model.BatchContainerOverrides;+import io.github.hectorvent.floci.services.batch.model.BatchContainerProperties;+import io.github.hectorvent.floci.services.batch.model.BatchJob;+import io.github.hectorvent.floci.services.batch.model.BatchJobDefinition;+import io.github.hectorvent.floci.services.batch.model.BatchJobQueue;+import io.github.hectorvent.floci.services.batch.model.BatchKeyValue;+import io.github.hectorvent.floci.services.batch.model.BatchResourceRequirement;+import io.github.hectorvent.floci.services.batch.model.BatchRetryStrategy;+import io.github.hectorvent.floci.services.batch.model.BatchRunResult;+import io.github.hectorvent.floci.services.batch.model.BatchStatus;+import io.github.hectorvent.floci.services.batch.model.BatchTimeout;+import jakarta.enterprise.context.ApplicationScoped;+import jakarta.inject.Inject;+import org.jboss.logging.Logger;++import java.util.ArrayList;+import java.util.Comparator;+import java.util.HashMap;+import java.util.LinkedHashMap;+import java.util.List;+import java.util.Map;+import java.util.Optional;+import java.util.Set;+import java.util.UUID;+import java.util.regex.Pattern;++@ApplicationScoped+public class BatchService {++ private static final Logger LOG = Logger.getLogger(BatchService.class);+ private static final int DESCRIBE_JOBS_LIMIT = 100;+ private static final int DEFAULT_MAX_RESULTS = 1000;+ private static final int FILTERED_MAX_RESULTS = 100;+ private static final int MAX_TAGS = 50;+ private static final Pattern JOB_NAME_PATTERN = Pattern.compile("[A-Za-z0-9][A-Za-z0-9_-]{0,127}");+ private static final Set<String> SUPPORTED_JOB_DEFINITION_TYPES = Set.of("container");+ private static final Set<String> SUPPORTED_COMPUTE_ENVIRONMENT_TYPES = Set.of("MANAGED", "UNMANAGED");+ private static final Set<String> SUPPORTED_LIST_FILTERS = Set.of(+ "JOB_NAME", "JOB_DEFINITION", "BEFORE_CREATED_AT", "AFTER_CREATED_AT", "SHARE_IDENTIFIER");++ private final StorageBackend<String, BatchJobDefinition> jobDefinitionStore;+ private final StorageBackend<String, BatchJobQueue> jobQueueStore;+ private final StorageBackend<String, BatchComputeEnvironment> computeEnvironmentStore;+ private final StorageBackend<String, BatchJob> jobStore;+ private final RegionResolver regionResolver;+ private final EmulatorConfig config;+ private final ObjectMapper objectMapper;+ private final BatchDockerRunner dockerRunner;++ @Inject+ public BatchService(StorageFactory storageFactory,+ RegionResolver regionResolver,+ EmulatorConfig config,+ ObjectMapper objectMapper,+ BatchDockerRunner dockerRunner) {+ this(+ storageFactory.create("batch", "batch-job-definitions.json",+ new TypeReference<Map<String, BatchJobDefinition>>() {}),+ storageFactory.create("batch", "batch-job-queues.json",+ new TypeReference<Map<String, BatchJobQueue>>() {}),+ storageFactory.create("batch", "batch-compute-environments.json",+ new TypeReference<Map<String, BatchComputeEnvironment>>() {}),+ storageFactory.create("batch", "batch-jobs.json",+ new TypeReference<Map<String, BatchJob>>() {}),+ regionResolver,+ config,+ objectMapper,+ dockerRunner+ );+ }++ BatchService(StorageBackend<String, BatchJobDefinition> jobDefinitionStore,+ StorageBackend<String, BatchJobQueue> jobQueueStore,+ StorageBackend<String, BatchComputeEnvironment> computeEnvironmentStore,+ StorageBackend<String, BatchJob> jobStore,+ RegionResolver regionResolver,+ EmulatorConfig config,+ ObjectMapper objectMapper,+ BatchDockerRunner dockerRunner) {+ this.jobDefinitionStore = jobDefinitionStore;+ this.jobQueueStore = jobQueueStore;+ this.computeEnvironmentStore = computeEnvironmentStore;+ this.jobStore = jobStore;+ this.regionResolver = regionResolver;+ this.config = config;+ this.objectMapper = objectMapper;+ this.dockerRunner = dockerRunner;+ }++ public synchronized ObjectNode createComputeEnvironment(JsonNode request, String region) {+ String name = requiredText(request, "computeEnvironmentName");+ String type = requiredText(request, "type");+ validateComputeEnvironmentType(type);+ if (resolveComputeEnvironmentOptional(name).isPresent()) {+ throw client("Compute environment already exists: " + name);+ }+ BatchComputeEnvironment env = new BatchComputeEnvironment();+ env.setComputeEnvironmentName(name);+ env.setComputeEnvironmentArn(arn(region, "compute-environment/" + name));+ env.setType(type);+ env.setState(text(request, "state", "ENABLED"));+ env.setStatus("VALID");+ env.setStatusReason("Compute environment is available");+ env.setComputeResources(map(request.path("computeResources")));+ env.setServiceRole(textOrNull(request, "serviceRole"));+ env.setTags(stringMap(request.path("tags")));+ validateTags(env.getTags());+ env.setCreatedAt(now());+ env.setRegion(region);+ env.setAccountId(regionResolver.getAccountId());+ computeEnvironmentStore.put(env.getComputeEnvironmentArn(), env);++ ObjectNode out = objectMapper.createObjectNode();+ out.put("computeEnvironmentName", env.getComputeEnvironmentName());+ out.put("computeEnvironmentArn", env.getComputeEnvironmentArn());+ return out;+ }++ public ObjectNode describeComputeEnvironments(JsonNode request) {+ List<String> refs = stringList(request.path("computeEnvironments"));+ if (refs.size() > DESCRIBE_JOBS_LIMIT) {+ throw client("DescribeComputeEnvironments accepts at most 100 compute environments");+ }+ int maxResults = describeMaxResults(request);+ int offset = parseNextToken(textOrNull(request, "nextToken"));+ List<BatchComputeEnvironment> envs;+ if (refs.isEmpty()) {+ envs = computeEnvironmentStore.scan(k -> true).stream()+ .sorted(Comparator.comparing(BatchComputeEnvironment::getComputeEnvironmentName))+ .toList();+ } else {+ envs = refs.stream()+ .map(this::resolveComputeEnvironmentOptional)+ .flatMap(Optional::stream)+ .toList();+ }+ ArrayNode list = objectMapper.createArrayNode();+ int end = Math.min(envs.size(), offset + maxResults);+ for (int i = offset; i < end; i++) {+ list.add(computeEnvironmentDetail(envs.get(i)));+ }+ ObjectNode out = objectMapper.createObjectNode();+ out.set("computeEnvironments", list);+ if (end < envs.size()) {+ out.put("nextToken", String.valueOf(end));+ }+ return out;+ }++ public synchronized ObjectNode createJobQueue(JsonNode request, String region) {+ String name = requiredText(request, "jobQueueName");+ if (resolveJobQueueOptional(name).isPresent()) {+ throw client("Job queue already exists: " + name);+ }+ if (!request.hasNonNull("priority")) {+ throw client("priority is required");+ }+ List<BatchComputeEnvironmentOrder> orders = computeEnvironmentOrder(request.path("computeEnvironmentOrder"));+ for (BatchComputeEnvironmentOrder order : orders) {+ BatchComputeEnvironment env = resolveComputeEnvironment(order.getComputeEnvironment());+ if (!"VALID".equals(env.getStatus())) {+ throw client("Compute environment is not VALID: " + order.getComputeEnvironment());+ }+ }++ BatchJobQueue queue = new BatchJobQueue();+ queue.setJobQueueName(name);+ queue.setJobQueueArn(arn(region, "job-queue/" + name));+ queue.setState(text(request, "state", "ENABLED"));+ queue.setStatus("VALID");+ queue.setStatusReason("Job queue is available");+ queue.setPriority(request.path("priority").asInt());+ queue.setJobQueueType(text(request, "jobQueueType", "ECS"));+ queue.setComputeEnvironmentOrder(orders);+ queue.setTags(stringMap(request.path("tags")));+ validateTags(queue.getTags());+ queue.setCreatedAt(now());+ queue.setRegion(region);+ queue.setAccountId(regionResolver.getAccountId());+ jobQueueStore.put(queue.getJobQueueArn(), queue);++ ObjectNode out = objectMapper.createObjectNode();+ out.put("jobQueueName", queue.getJobQueueName());+ out.put("jobQueueArn", queue.getJobQueueArn());+ return out;+ }++ public ObjectNode describeJobQueues(JsonNode request) {+ List<String> refs = stringList(request.path("jobQueues"));+ if (refs.size() > DESCRIBE_JOBS_LIMIT) {+ throw client("DescribeJobQueues accepts at most 100 job queues");+ }+ int maxResults = describeMaxResults(request);+ int offset = parseNextToken(textOrNull(request, "nextToken"));+ List<BatchJobQueue> queues;+ if (refs.isEmpty()) {+ queues = jobQueueStore.scan(k -> true).stream()+ .sorted(Comparator.comparing(BatchJobQueue::getJobQueueName))+ .toList();+ } else {+ queues = refs.stream()+ .map(this::resolveJobQueueOptional)+ .flatMap(Optional::stream)+ .toList();+ }+ ArrayNode list = objectMapper.createArrayNode();+ int end = Math.min(queues.size(), offset + maxResults);+ for (int i = offset; i < end; i++) {+ list.add(jobQueueDetail(queues.get(i)));+ }+ ObjectNode out = objectMapper.createObjectNode();+ out.set("jobQueues", list);+ if (end < queues.size()) {+ out.put("nextToken", String.valueOf(end));+ }+ return out;+ }++ public synchronized ObjectNode registerJobDefinition(JsonNode request, String region) {+ String name = requiredText(request, "jobDefinitionName");+ String type = requiredText(request, "type");+ validateJobDefinitionType(type);+ BatchContainerProperties container = tree(request.path("containerProperties"), BatchContainerProperties.class);+ if (container == null) {+ throw client("containerProperties is required for container job definitions");+ }+ validateEnvironment(container.getEnvironment());++ int revision = nextRevision(name);+ BatchJobDefinition def = new BatchJobDefinition();+ def.setJobDefinitionName(name);+ def.setRevision(revision);+ def.setJobDefinitionArn(arn(region, "job-definition/" + name + ":" + revision));+ def.setStatus("ACTIVE");+ def.setType(type);+ def.setContainerProperties(container);+ def.setParameters(stringMap(request.path("parameters")));+ def.setRetryStrategy(tree(request.path("retryStrategy"), BatchRetryStrategy.class));+ validateRetryStrategy(def.getRetryStrategy());+ def.setTimeout(tree(request.path("timeout"), BatchTimeout.class));+ validateTimeout(def.getTimeout());+ def.setPlatformCapabilities(stringList(request.path("platformCapabilities")));+ def.setTags(stringMap(request.path("tags")));+ validateTags(def.getTags());+ def.setCreatedAt(now());+ def.setRegion(region);+ def.setAccountId(regionResolver.getAccountId());+ jobDefinitionStore.put(def.getJobDefinitionArn(), def);++ ObjectNode out = objectMapper.createObjectNode();+ out.put("jobDefinitionName", def.getJobDefinitionName());+ out.put("jobDefinitionArn", def.getJobDefinitionArn());+ out.put("revision", def.getRevision());+ return out;+ }++ public synchronized ObjectNode deregisterJobDefinition(JsonNode request) {+ String ref = requiredText(request, "jobDefinition");+ validateDeregisterJobDefinitionRef(ref);+ BatchJobDefinition def = resolveJobDefinition(ref, true);+ def.setStatus("INACTIVE");+ putJobDefinition(def);+ return objectMapper.createObjectNode();+ }++ public ObjectNode describeJobDefinitions(JsonNode request) {+ String status = textOrNull(request, "status");+ String name = textOrNull(request, "jobDefinitionName");+ List<String> refs = stringList(request.path("jobDefinitions"));+ if (!refs.isEmpty() && (status != null || name != null)) {+ throw client("jobDefinitions can't be used with other parameters");+ }+ if (refs.size() > DESCRIBE_JOBS_LIMIT) {+ throw client("DescribeJobDefinitions accepts at most 100 job definitions");+ }+ int maxResults = describeMaxResults(request);+ int offset = parseNextToken(textOrNull(request, "nextToken"));+ List<BatchJobDefinition> definitions = jobDefinitionStore.scan(k -> true).stream()+ .filter(def -> status == null || status.equals(def.getStatus()))+ .filter(def -> name == null || name.equals(def.getJobDefinitionName()))+ .filter(def -> refs.isEmpty() || refs.stream().anyMatch(ref -> matchesJobDefinition(def, ref)))+ .sorted(Comparator.comparing(BatchJobDefinition::getJobDefinitionName)+ .thenComparing(BatchJobDefinition::getRevision))+ .toList();+ ArrayNode list = objectMapper.createArrayNode();+ int end = Math.min(definitions.size(), offset + maxResults);+ for (int i = offset; i < end; i++) {+ list.add(jobDefinitionDetail(definitions.get(i)));+ }+ ObjectNode out = objectMapper.createObjectNode();+ out.set("jobDefinitions", list);+ if (end < definitions.size()) {+ out.put("nextToken", String.valueOf(end));+ }+ return out;+ }++ public ObjectNode submitJob(JsonNode request, String region) {+ rejectUnsupportedSubmitFields(request);+ String jobName = requiredText(request, "jobName");+ validateJobName(jobName);+ BatchJobQueue queue = resolveJobQueue(requiredText(request, "jobQueue"));+ if (!"ENABLED".equals(queue.getState()) || !"VALID".equals(queue.getStatus())) {+ throw client("Job queue is not enabled and valid: " + queue.getJobQueueName());+ }+ BatchJobDefinition def = resolveJobDefinition(requiredText(request, "jobDefinition"), false);+ if (!"ACTIVE".equals(def.getStatus())) {+ throw client("Job definition is not ACTIVE: " + def.getJobDefinitionArn());+ }++ BatchContainerOverrides overrides = tree(request.path("containerOverrides"), BatchContainerOverrides.class);+ if (overrides == null) {+ overrides = new BatchContainerOverrides();+ }+ validateEnvironment(overrides.getEnvironment());++ Map<String, String> parameters = new LinkedHashMap<>(def.getParameters());+ parameters.putAll(stringMap(request.path("parameters")));++ BatchContainerProperties container = def.getContainerProperties() != null+ ? def.getContainerProperties() : new BatchContainerProperties();+ List<String> command = overrides.getCommand() != null && !overrides.getCommand().isEmpty()+ ? overrides.getCommand()+ : container.getCommand();++ BatchJob job = new BatchJob();+ job.setJobId(UUID.randomUUID().toString());+ job.setJobArn(arn(region, "job/" + job.getJobId()));+ job.setJobName(jobName);+ job.setJobQueue(queue.getJobQueueArn());+ job.setJobQueueName(queue.getJobQueueName());+ job.setJobDefinition(def.getJobDefinitionArn());+ job.setJobDefinitionName(def.getJobDefinitionName());+ job.setJobDefinitionRevision(def.getRevision());+ job.setStatus(BatchStatus.SUBMITTED.name());+ job.setCreatedAt(now());+ job.setParameters(parameters);+ job.setContainerOverrides(overrides);+ job.setResolvedCommand(resolveCommand(command, parameters));+ job.setResolvedEnvironment(resolveEnvironment(container.getEnvironment(), overrides.getEnvironment()));+ job.setResourceRequirements(resolveResourceRequirements(container, overrides));+ job.setRetryStrategy(treeOrDefault(request.path("retryStrategy"), def.getRetryStrategy(), BatchRetryStrategy.class));+ validateRetryStrategy(job.getRetryStrategy());+ job.setTimeout(treeOrDefault(request.path("timeout"), def.getTimeout(), BatchTimeout.class));+ validateTimeout(job.getTimeout());+ job.setTags(stringMap(request.path("tags")));+ validateTags(job.getTags());+ job.setRegion(region);+ job.setAccountId(regionResolver.getAccountId());+ job.setContainerImage(container.getImage());+ putJob(job);+ if (shouldRunDocker()) {+ Thread.startVirtualThread(() -> runJob(job.getAccountId(), job.getJobId()));+ } else {+ runJob(job.getAccountId(), job.getJobId());+ }++ ObjectNode out = objectMapper.createObjectNode();+ out.put("jobArn", job.getJobArn());+ out.put("jobId", job.getJobId());+ out.put("jobName", job.getJobName());+ return out;+ }++ public synchronized ObjectNode describeJobs(JsonNode request) {+ List<String> ids = stringList(request.path("jobs"));+ if (ids.isEmpty()) {+ throw client("jobs is required");+ }+ if (ids.size() > DESCRIBE_JOBS_LIMIT) {+ throw client("DescribeJobs accepts at most 100 job IDs");+ }+ ArrayNode list = objectMapper.createArrayNode();+ for (String id : ids) {+ getJob(id).ifPresent(job -> list.add(jobDetail(job)));+ }+ ObjectNode out = objectMapper.createObjectNode();+ out.set("jobs", list);+ return out;+ }++ public synchronized ObjectNode listJobs(JsonNode request) {+ if (!request.hasNonNull("jobQueue")) {+ throw client("jobQueue is required");+ }+ if (request.hasNonNull("arrayJobId") || request.hasNonNull("multiNodeJobId")) {+ throw client("arrayJobId and multiNodeJobId are not supported");+ }+ BatchJobQueue queue = resolveJobQueue(requiredText(request, "jobQueue"));+ String status = textOrNull(request, "jobStatus");+ ListFilter filter = listFilter(request);+ String effectiveStatus = filter == null && status == null ? BatchStatus.RUNNING.name() : status;+ int maxResults = request.hasNonNull("maxResults")+ ? Math.max(1, Math.min(filter == null ? DEFAULT_MAX_RESULTS : FILTERED_MAX_RESULTS,+ request.path("maxResults").asInt()))+ : filter == null ? DEFAULT_MAX_RESULTS : FILTERED_MAX_RESULTS;+ int offset = parseNextToken(textOrNull(request, "nextToken"));++ List<BatchJob> jobs = jobStore.scan(k -> true).stream()+ .filter(job -> queue.getJobQueueArn().equals(job.getJobQueue()))+ .filter(job -> (filter != null && !"SHARE_IDENTIFIER".equals(filter.name()))+ || effectiveStatus == null+ || effectiveStatus.equals(job.getStatus()))+ .filter(job -> matchesListFilter(job, filter))+ .sorted(Comparator.comparingLong(BatchJob::getCreatedAt)+ .reversed()+ .thenComparing(BatchJob::getJobId))+ .toList();++ ArrayNode summaries = objectMapper.createArrayNode();+ int end = Math.min(jobs.size(), offset + maxResults);+ for (int i = offset; i < end; i++) {+ summaries.add(jobSummary(jobs.get(i)));+ }+ ObjectNode out = objectMapper.createObjectNode();+ out.set("jobSummaryList", summaries);+ if (end < jobs.size()) {+ out.put("nextToken", String.valueOf(end));+ }+ return out;+ }++ public void submitFromEventBridge(String jobQueueArn, String jobDefinition, String jobName,+ Map<String, String> parameters, JsonNode retryStrategy, String region) {+ ObjectNode request = objectMapper.createObjectNode();+ request.put("jobQueue", jobQueueArn);+ request.put("jobDefinition", jobDefinition);+ request.put("jobName", jobName);+ ObjectNode params = request.putObject("parameters");+ parameters.forEach(params::put);+ ObjectNode retry = eventBridgeRetryStrategy(retryStrategy);+ if (!retry.isEmpty()) {+ request.set("retryStrategy", retry);+ }+ submitJob(request, region);+ }++ private ObjectNode eventBridgeRetryStrategy(JsonNode retryStrategy) {+ ObjectNode retry = objectMapper.createObjectNode();+ if (retryStrategy == null || !retryStrategy.isObject()) {+ return retry;+ }+ if (retryStrategy.has("Attempts")) {+ retry.set("attempts", retryStrategy.get("Attempts"));+ }+ return retry;+ }++ private void runJob(String accountId, String jobId) {+ try {+ BatchJob job = getJobForAccount(accountId, jobId).orElse(null);+ if (job == null) {+ return;+ }+ int maxAttempts = maxAttempts(job);+ for (int attemptNumber = 1; attemptNumber <= maxAttempts; attemptNumber++) {+ transition(accountId, jobId, BatchStatus.PENDING, null, false);+ sleepQuietly();+ transition(accountId, jobId, BatchStatus.RUNNABLE, null, false);+ sleepQuietly();+ transition(accountId, jobId, BatchStatus.STARTING, null, false);+ sleepQuietly();+ transition(accountId, jobId, BatchStatus.RUNNING, null, true);+ BatchJob attemptJob = getJobForAccount(accountId, jobId).orElse(null);+ if (attemptJob == null) {+ return;+ }+ BatchRunResult result = shouldRunDocker()+ ? dockerRunner.run(attemptJob, attemptNumber)+ : immediateSuccess(attemptJob);+ if (finishAttempt(accountId, jobId, result, attemptNumber >= maxAttempts)) {+ return;+ }+ }+ } catch (Exception e) {+ LOG.warnv("Batch job {0} failed while running: {1}", jobId, e.getMessage());+ failJob(accountId, jobId, e.getMessage());+ }+ }++ private boolean shouldRunDocker() {+ return "docker".equalsIgnoreCase(config.services().batch().runnerMode());+ }++ private BatchRunResult immediateSuccess(BatchJob job) {+ long started = job.getStartedAt() != null ? job.getStartedAt() : now();+ sleepQuietly();+ return new BatchRunResult(0, null, job.getJobDefinitionName() + "/default/" + job.getJobId(),+ started, now(), false);+ }++ private synchronized boolean finishAttempt(String accountId, String jobId, BatchRunResult result, boolean finalAttempt) {+ BatchJob job = getJobForAccount(accountId, jobId).orElse(null);+ if (job == null) {+ return true;+ }+ BatchAttemptContainer container = new BatchAttemptContainer();+ container.setExitCode(result.exitCode());+ container.setReason(result.reason());+ container.setLogStreamName(result.logStreamName());++ BatchAttempt attempt = new BatchAttempt();+ attempt.setStartedAt(result.startedAt());+ attempt.setStoppedAt(result.stoppedAt());+ attempt.setStatusReason(result.reason());+ attempt.setContainer(container);++ job.getAttempts().add(attempt);+ job.setContainer(container);+ if (result.exitCode() == 0) {+ job.setStoppedAt(result.stoppedAt());+ job.setStatus(BatchStatus.SUCCEEDED.name());+ job.setStatusReason("Job completed successfully");+ putJobForAccount(accountId, job);+ return true;+ }+ if (result.timedOut() || finalAttempt) {+ job.setStoppedAt(result.stoppedAt());+ job.setStatus(BatchStatus.FAILED.name());+ job.setStatusReason(result.reason());+ putJobForAccount(accountId, job);+ return true;+ }+ job.setStatus(BatchStatus.RUNNABLE.name());+ job.setStatusReason("Attempt failed; retrying");+ putJobForAccount(accountId, job);+ return false;+ }++ private int maxAttempts(BatchJob job) {+ if (job.getRetryStrategy() == null || job.getRetryStrategy().getAttempts() == null) {+ return 1;+ }+ return job.getRetryStrategy().getAttempts();+ }++ private synchronized void failJob(String accountId, String jobId, String reason) {+ BatchJob job = getJobForAccount(accountId, jobId).orElse(null);+ if (job == null) {+ return;+ }+ job.setStatus(BatchStatus.FAILED.name());+ job.setStatusReason(reason);+ job.setStoppedAt(now());+ putJobForAccount(accountId, job);+ }++ private synchronized void transition(String accountId, String jobId, BatchStatus status, String reason, boolean started) {+ BatchJob job = getJobForAccount(accountId, jobId).orElse(null);+ if (job == null) {+ return;+ }+ job.setStatus(status.name());+ if (reason != null) {+ job.setStatusReason(reason);+ }+ if (started && job.getStartedAt() == null) {+ job.setStartedAt(now());+ }+ putJobForAccount(accountId, job);+ }++ private void sleepQuietly() {+ try {+ Thread.sleep(10);+ } catch (InterruptedException e) {+ Thread.currentThread().interrupt();+ }+ }++ private BatchJobQueue resolveJobQueue(String ref) {+ return resolveJobQueueOptional(ref).orElseThrow(() -> client("Job queue not found: " + ref));+ }++ private Optional<BatchJobQueue> resolveJobQueueOptional(String ref) {+ if (ref == null || ref.isBlank()) {+ return Optional.empty();+ }+ Optional<BatchJobQueue> byArn = jobQueueStore.get(ref);+ if (byArn.isPresent()) {+ return byArn;+ }+ return jobQueueStore.scan(k -> true).stream()+ .filter(q -> ref.equals(q.getJobQueueName()) || ref.equals(q.getJobQueueArn()))+ .findFirst();+ }++ private BatchComputeEnvironment resolveComputeEnvironment(String ref) {+ return resolveComputeEnvironmentOptional(ref)+ .orElseThrow(() -> client("Compute environment not found: " + ref));+ }++ private Optional<BatchComputeEnvironment> resolveComputeEnvironmentOptional(String ref) {+ if (ref == null || ref.isBlank()) {+ return Optional.empty();+ }+ Optional<BatchComputeEnvironment> byArn = computeEnvironmentStore.get(ref);+ if (byArn.isPresent()) {+ return byArn;+ }+ return computeEnvironmentStore.scan(k -> true).stream()+ .filter(env -> ref.equals(env.getComputeEnvironmentName()) || ref.equals(env.getComputeEnvironmentArn()))+ .findFirst();+ }++ private BatchJobDefinition resolveJobDefinition(String ref, boolean includeInactive) {+ return resolveJobDefinitionOptional(ref, includeInactive)+ .orElseThrow(() -> client("Job definition not found: " + ref));+ }++ private Optional<BatchJobDefinition> resolveJobDefinitionOptional(String ref, boolean includeInactive) {+ if (ref == null || ref.isBlank()) {+ return Optional.empty();+ }+ Optional<BatchJobDefinition> byArn = jobDefinitionStore.get(ref);+ if (byArn.isPresent() && (includeInactive || "ACTIVE".equals(byArn.get().getStatus()))) {+ return byArn;+ }+ String logical = ref;+ if (ref.startsWith("arn:")) {+ try {+ String resource = AwsArnUtils.parse(ref).resource();+ if (resource.startsWith("job-definition/")) {+ logical = resource.substring("job-definition/".length());+ }+ } catch (IllegalArgumentException ignored) {+ return Optional.empty();+ }+ }+ String name = logical;+ Integer revision = null;+ int colon = logical.lastIndexOf(':');+ if (colon > 0) {+ name = logical.substring(0, colon);+ try {+ revision = Integer.parseInt(logical.substring(colon + 1));+ } catch (NumberFormatException e) {+ return Optional.empty();+ }+ }+ String finalName = name;+ Integer finalRevision = revision;+ return jobDefinitionStore.scan(k -> true).stream()+ .filter(def -> finalName.equals(def.getJobDefinitionName()))+ .filter(def -> finalRevision == null || finalRevision == def.getRevision())+ .filter(def -> includeInactive || "ACTIVE".equals(def.getStatus()))+ .max(Comparator.comparingInt(BatchJobDefinition::getRevision));+ }++ private boolean matchesJobDefinition(BatchJobDefinition def, String ref) {+ if (ref == null || ref.isBlank()) {+ return false;+ }+ if (ref.equals(def.getJobDefinitionArn())) {+ return true;+ }+ String logical = ref;+ if (ref.startsWith("arn:")) {+ try {+ String resource = AwsArnUtils.parse(ref).resource();+ if (!resource.startsWith("job-definition/")) {+ return false;+ }+ logical = resource.substring("job-definition/".length());+ } catch (IllegalArgumentException ignored) {+ return false;+ }+ }+ int colon = logical.lastIndexOf(':');+ if (colon > 0) {+ String name = logical.substring(0, colon);+ try {+ int revision = Integer.parseInt(logical.substring(colon + 1));+ return name.equals(def.getJobDefinitionName()) && revision == def.getRevision();+ } catch (NumberFormatException e) {+ return false;+ }+ }+ return logical.equals(def.getJobDefinitionName());+ }++ private int nextRevision(String name) {+ return jobDefinitionStore.scan(k -> true).stream()+ .filter(def -> name.equals(def.getJobDefinitionName()))+ .mapToInt(BatchJobDefinition::getRevision)+ .max()+ .orElse(0) + 1;+ }++ private List<String> resolveCommand(List<String> command, Map<String, String> parameters) {+ if (command == null) {+ return List.of();+ }+ List<String> resolved = new ArrayList<>();+ for (String token : command) {+ if (token != null && token.startsWith("Ref::")) {+ resolved.add(parameters.getOrDefault(token.substring("Ref::".length()), token));+ } else {+ resolved.add(token);+ }+ }+ return resolved;+ }++ private List<BatchKeyValue> resolveEnvironment(List<BatchKeyValue> defaults, List<BatchKeyValue> overrides) {+ Map<String, String> merged = new LinkedHashMap<>();+ if (defaults != null) {+ defaults.forEach(kv -> merged.put(kv.getName(), kv.getValue()));+ }+ if (overrides != null) {+ overrides.forEach(kv -> merged.put(kv.getName(), kv.getValue()));+ }+ return merged.entrySet().stream().map(e -> new BatchKeyValue(e.getKey(), e.getValue())).toList();+ }++ private List<BatchResourceRequirement> resolveResourceRequirements(BatchContainerProperties container,+ BatchContainerOverrides overrides) {+ if (overrides.getResourceRequirements() != null && !overrides.getResourceRequirements().isEmpty()) {+ return overrides.getResourceRequirements();+ }+ return container.getResourceRequirements();+ }++ private void validateJobDefinitionType(String type) {+ if (!SUPPORTED_JOB_DEFINITION_TYPES.contains(type)) {+ throw client("Only container job definitions are supported");+ }+ }++ private void validateComputeEnvironmentType(String type) {+ if (!SUPPORTED_COMPUTE_ENVIRONMENT_TYPES.contains(type)) {+ throw client("type must be MANAGED or UNMANAGED");+ }+ }++ private void validateDeregisterJobDefinitionRef(String ref) {+ String logical = ref;+ if (ref.startsWith("arn:")) {+ try {+ String resource = AwsArnUtils.parse(ref).resource();+ if (!resource.startsWith("job-definition/")) {+ throw client("jobDefinition must be a job definition ARN or name:revision");+ }+ logical = resource.substring("job-definition/".length());+ } catch (IllegalArgumentException e) {+ throw client("jobDefinition must be a job definition ARN or name:revision");+ }+ }+ int colon = logical.lastIndexOf(':');+ if (colon <= 0 || colon == logical.length() - 1) {+ throw client("jobDefinition must include a revision");+ }+ try {+ Integer.parseInt(logical.substring(colon + 1));+ } catch (NumberFormatException e) {+ throw client("jobDefinition must include a numeric revision");+ }+ }++ private void validateJobName(String jobName) {+ if (!JOB_NAME_PATTERN.matcher(jobName).matches()) {+ throw client("jobName must be 1-128 characters and contain only letters, numbers, hyphens, and underscores");+ }+ }++ private void validateTags(Map<String, String> tags) {+ if (tags == null || tags.isEmpty()) {+ return;+ }+ if (tags.size() > MAX_TAGS) {+ throw client("tags can contain at most 50 entries");+ }+ tags.forEach((key, value) -> {+ if (key == null || key.isBlank() || key.length() > 128) {+ throw client("tag keys must be 1-128 characters");+ }+ if (key.toLowerCase().startsWith("aws:")) {+ throw client("tag keys must not start with aws:");+ }+ if (value != null && value.length() > 256) {+ throw client("tag values must be at most 256 characters");+ }+ });+ }++ private void validateEnvironment(List<BatchKeyValue> env) {+ if (env == null) {+ return;+ }+ for (BatchKeyValue kv : env) {+ if (kv.getName() != null && kv.getName().startsWith("AWS_BATCH")) {+ throw client("Environment variables must not start with AWS_BATCH");+ }+ }+ }++ private void validateTimeout(BatchTimeout timeout) {+ if (timeout != null && timeout.getAttemptDurationSeconds() != null+ && timeout.getAttemptDurationSeconds() < 60) {+ throw client("timeout.attemptDurationSeconds must be at least 60");+ }+ }++ private void validateRetryStrategy(BatchRetryStrategy retryStrategy) {+ if (retryStrategy != null && retryStrategy.getAttempts() != null+ && (retryStrategy.getAttempts() < 1 || retryStrategy.getAttempts() > 10)) {+ throw client("retryStrategy.attempts must be between 1 and 10");+ }+ }++ private void rejectUnsupportedSubmitFields(JsonNode request) {+ if (request.hasNonNull("arrayProperties") || request.hasNonNull("dependsOn")+ || request.hasNonNull("nodeOverrides") || request.hasNonNull("nodeProperties")) {+ throw client("Array, dependency, and multi-node jobs are not supported");+ }+ }++ private ObjectNode jobSummary(BatchJob job) {+ ObjectNode summary = objectMapper.createObjectNode();+ summary.put("jobArn", job.getJobArn());+ summary.put("jobId", job.getJobId());+ summary.put("jobName", job.getJobName());+ summary.put("jobDefinition", job.getJobDefinition());+ summary.put("status", job.getStatus());+ summary.put("createdAt", job.getCreatedAt());+ if (job.getStartedAt() != null) {+ summary.put("startedAt", job.getStartedAt());+ }+ if (job.getStoppedAt() != null) {+ summary.put("stoppedAt", job.getStoppedAt());+ }+ if (job.getStatusReason() != null) {+ summary.put("statusReason", job.getStatusReason());+ }+ if (job.getContainer() != null) {+ ObjectNode container = objectMapper.createObjectNode();+ if (job.getContainer().getExitCode() != null) {+ container.put("exitCode", job.getContainer().getExitCode());+ }+ if (job.getContainer().getReason() != null) {+ container.put("reason", job.getContainer().getReason());+ }+ if (!container.isEmpty()) {+ summary.set("container", container);+ }+ }+ return summary;+ }++ private ObjectNode computeEnvironmentDetail(BatchComputeEnvironment env) {+ ObjectNode detail = objectMapper.createObjectNode();+ detail.put("computeEnvironmentName", env.getComputeEnvironmentName());+ detail.put("computeEnvironmentArn", env.getComputeEnvironmentArn());+ detail.put("type", env.getType());+ detail.put("state", env.getState());+ detail.put("status", env.getStatus());+ detail.put("statusReason", env.getStatusReason());+ if (env.getComputeResources() != null && !env.getComputeResources().isEmpty()) {+ detail.set("computeResources", objectMapper.valueToTree(env.getComputeResources()));+ }+ if (env.getServiceRole() != null) {+ detail.put("serviceRole", env.getServiceRole());+ }+ if (env.getTags() != null && !env.getTags().isEmpty()) {+ detail.set("tags", objectMapper.valueToTree(env.getTags()));+ }+ return detail;+ }++ private ObjectNode jobQueueDetail(BatchJobQueue queue) {+ ObjectNode detail = objectMapper.createObjectNode();+ detail.put("jobQueueName", queue.getJobQueueName());+ detail.put("jobQueueArn", queue.getJobQueueArn());+ detail.put("state", queue.getState());+ detail.put("status", queue.getStatus());+ detail.put("statusReason", queue.getStatusReason());+ detail.put("priority", queue.getPriority());+ if (queue.getJobQueueType() != null) {+ detail.put("jobQueueType", queue.getJobQueueType());+ }+ detail.set("computeEnvironmentOrder", objectMapper.valueToTree(queue.getComputeEnvironmentOrder()));+ if (queue.getTags() != null && !queue.getTags().isEmpty()) {+ detail.set("tags", objectMapper.valueToTree(queue.getTags()));+ }+ return detail;+ }++ private ObjectNode jobDefinitionDetail(BatchJobDefinition def) {+ ObjectNode detail = objectMapper.createObjectNode();+ detail.put("jobDefinitionName", def.getJobDefinitionName());+ detail.put("jobDefinitionArn", def.getJobDefinitionArn());+ detail.put("revision", def.getRevision());+ detail.put("status", def.getStatus());+ detail.put("type", def.getType());+ if (def.getContainerProperties() != null) {+ detail.set("containerProperties", objectMapper.valueToTree(def.getContainerProperties()));+ }+ if (def.getParameters() != null && !def.getParameters().isEmpty()) {+ detail.set("parameters", objectMapper.valueToTree(def.getParameters()));+ }+ if (def.getPlatformCapabilities() != null && !def.getPlatformCapabilities().isEmpty()) {+ detail.set("platformCapabilities", objectMapper.valueToTree(def.getPlatformCapabilities()));+ }+ if (def.getRetryStrategy() != null) {+ detail.set("retryStrategy", objectMapper.valueToTree(def.getRetryStrategy()));+ }+ if (def.getTimeout() != null) {+ detail.set("timeout", objectMapper.valueToTree(def.getTimeout()));+ }+ if (def.getTags() != null && !def.getTags().isEmpty()) {+ detail.set("tags", objectMapper.valueToTree(def.getTags()));+ }+ return detail;+ }++ private ObjectNode jobDetail(BatchJob job) {+ ObjectNode detail = objectMapper.createObjectNode();+ detail.put("jobArn", job.getJobArn());+ detail.put("jobId", job.getJobId());+ detail.put("jobName", job.getJobName());+ detail.put("jobQueue", job.getJobQueue());+ detail.put("jobDefinition", job.getJobDefinition());+ detail.put("status", job.getStatus());+ detail.put("createdAt", job.getCreatedAt());+ if (job.getStatusReason() != null) {+ detail.put("statusReason", job.getStatusReason());+ }+ if (job.getStartedAt() != null) {+ detail.put("startedAt", job.getStartedAt());+ }+ if (job.getStoppedAt() != null) {+ detail.put("stoppedAt", job.getStoppedAt());+ }+ detail.set("parameters", objectMapper.valueToTree(job.getParameters()));+ detail.set("attempts", objectMapper.valueToTree(job.getAttempts()));+ if (job.getRetryStrategy() != null) {+ detail.set("retryStrategy", objectMapper.valueToTree(job.getRetryStrategy()));+ }+ if (job.getTimeout() != null) {+ detail.set("timeout", objectMapper.valueToTree(job.getTimeout()));+ }+ if (job.getTags() != null && !job.getTags().isEmpty()) {+ detail.set("tags", objectMapper.valueToTree(job.getTags()));+ }++ ObjectNode container = detail.putObject("container");+ if (job.getContainerImage() != null) {+ container.put("image", job.getContainerImage());+ }+ container.set("command", objectMapper.valueToTree(job.getResolvedCommand()));+ container.set("environment", objectMapper.valueToTree(job.getResolvedEnvironment()));+ if (job.getContainer() != null) {+ if (job.getContainer().getExitCode() != null) {+ container.put("exitCode", job.getContainer().getExitCode());+ }+ if (job.getContainer().getReason() != null) {+ container.put("reason", job.getContainer().getReason());+ }+ if (job.getContainer().getLogStreamName() != null) {+ container.put("logStreamName", job.getContainer().getLogStreamName());+ }+ }+ return detail;+ }++ private List<BatchComputeEnvironmentOrder> computeEnvironmentOrder(JsonNode node) {+ if (node == null || !node.isArray()) {+ return List.of();+ }+ List<BatchComputeEnvironmentOrder> orders = new ArrayList<>();+ for (JsonNode item : node) {+ BatchComputeEnvironmentOrder order = new BatchComputeEnvironmentOrder();+ order.setOrder(item.path("order").asInt());+ order.setComputeEnvironment(item.path("computeEnvironment").asText(null));+ orders.add(order);+ }+ return orders;+ }++ private int parseNextToken(String token) {+ if (token == null || token.isBlank()) {+ return 0;+ }+ try {+ int value = Integer.parseInt(token);+ if (value < 0) {+ throw client("Invalid nextToken");+ }+ return value;+ } catch (NumberFormatException e) {+ throw client("Invalid nextToken");+ }+ }++ private ListFilter listFilter(JsonNode request) {+ JsonNode filters = request.path("filters");+ if (!filters.isArray() || filters.isEmpty()) {+ return null;+ }+ if (filters.size() > 1) {+ throw client("Only one filter can be used at a time");+ }+ JsonNode filter = filters.get(0);+ String name = textOrNull(filter, "name");+ if (name == null || !SUPPORTED_LIST_FILTERS.contains(name)) {+ throw client("Unsupported ListJobs filter: " + name);+ }+ return new ListFilter(name, stringList(filter.path("values")));+ }++ private boolean matchesListFilter(BatchJob job, ListFilter filter) {+ if (filter == null || filter.values().isEmpty()) {+ return true;+ }+ return switch (filter.name()) {+ case "JOB_NAME" -> filter.values().stream().anyMatch(value -> matchesJobNameFilter(job, value));+ case "JOB_DEFINITION" -> filter.values().stream().anyMatch(value -> matchesJobDefinitionFilter(job, value));+ case "BEFORE_CREATED_AT" -> filter.values().stream()+ .anyMatch(value -> job.getCreatedAt() < parseLong(value, "Invalid BEFORE_CREATED_AT filter value"));+ case "AFTER_CREATED_AT" -> filter.values().stream()+ .anyMatch(value -> job.getCreatedAt() > parseLong(value, "Invalid AFTER_CREATED_AT filter value"));+ case "SHARE_IDENTIFIER" -> false;+ default -> true;+ };+ }++ private boolean matchesJobNameFilter(BatchJob job, String value) {+ if (job.getJobName() == null || value == null) {+ return false;+ }+ String expected = value.endsWith("*") ? value.substring(0, value.length() - 1) : value;+ if (value.endsWith("*")) {+ return job.getJobName().regionMatches(true, 0, expected, 0, expected.length());+ }+ return job.getJobName().equalsIgnoreCase(expected);+ }++ private boolean matchesJobDefinitionFilter(BatchJob job, String value) {+ if (value == null || value.isBlank()) {+ return false;+ }+ if (value.startsWith("arn:")) {+ return value.equals(job.getJobDefinition());+ }+ if (value.endsWith("*")) {+ return job.getJobDefinitionName() != null+ && job.getJobDefinitionName().startsWith(value.substring(0, value.length() - 1));+ }+ int colon = value.lastIndexOf(':');+ if (colon > 0) {+ String name = value.substring(0, colon);+ try {+ int revision = Integer.parseInt(value.substring(colon + 1));+ return name.equals(job.getJobDefinitionName()) && revision == job.getJobDefinitionRevision();+ } catch (NumberFormatException e) {+ return false;+ }+ }+ return value.equals(job.getJobDefinitionName());+ }++ private long parseLong(String value, String message) {+ try {+ return Long.parseLong(value);+ } catch (NumberFormatException e) {+ throw client(message);+ }+ }++ private int describeMaxResults(JsonNode request) {+ if (!request.hasNonNull("maxResults")) {+ return DEFAULT_MAX_RESULTS;+ }+ return Math.max(1, Math.min(DESCRIBE_JOBS_LIMIT, request.path("maxResults").asInt()));+ }++ private Optional<BatchJob> getJob(String jobId) {+ return jobStore.get(jobId);+ }++ @SuppressWarnings("unchecked")+ private Optional<BatchJob> getJobForAccount(String accountId, String jobId) {+ if (jobStore instanceof AccountAwareStorageBackend<?> aware) {+ return ((AccountAwareStorageBackend<BatchJob>) aware).getForAccount(accountId, jobId);+ }+ return jobStore.get(jobId);+ }++ private void putJob(BatchJob job) {+ jobStore.put(job.getJobId(), job);+ }++ @SuppressWarnings("unchecked")+ private void putJobForAccount(String accountId, BatchJob job) {+ if (jobStore instanceof AccountAwareStorageBackend<?> aware) {+ ((AccountAwareStorageBackend<BatchJob>) aware).putForAccount(accountId, job.getJobId(), job);+ } else {+ jobStore.put(job.getJobId(), job);+ }+ }++ private void putJobDefinition(BatchJobDefinition def) {+ jobDefinitionStore.put(def.getJobDefinitionArn(), def);+ }++ private String requiredText(JsonNode node, String field) {+ String value = textOrNull(node, field);+ if (value == null || value.isBlank()) {+ throw client(field + " is required");+ }+ return value;+ }++ private String text(JsonNode node, String field, String defaultValue) {+ String value = textOrNull(node, field);+ return value != null ? value : defaultValue;+ }++ private String textOrNull(JsonNode node, String field) {+ return node != null && node.hasNonNull(field) ? node.path(field).asText() : null;+ }++ private List<String> stringList(JsonNode node) {+ if (node == null || !node.isArray()) {+ return List.of();+ }+ List<String> out = new ArrayList<>();+ node.forEach(v -> out.add(v.asText()));+ return out;+ }++ private Map<String, String> stringMap(JsonNode node) {+ Map<String, String> out = new LinkedHashMap<>();+ if (node != null && node.isObject()) {+ node.fields().forEachRemaining(e -> out.put(e.getKey(), e.getValue().asText()));+ }+ return out;+ }++ private Map<String, Object> map(JsonNode node) {+ if (node == null || !node.isObject()) {+ return new HashMap<>();+ }+ return objectMapper.convertValue(node, new TypeReference<Map<String, Object>>() {});+ }++ private <T> T tree(JsonNode node, Class<T> type) {+ if (node == null || node.isMissingNode() || node.isNull()) {+ return null;+ }+ return objectMapper.convertValue(node, type);+ }++ private <T> T treeOrDefault(JsonNode node, T defaultValue, Class<T> type) {+ T value = tree(node, type);+ return value != null ? value : defaultValue;+ }++ private String arn(String region, String resource) {+ return AwsArnUtils.Arn.of("batch", region, regionResolver.getAccountId(), resource).toString();+ }++ private long now() {+ return System.currentTimeMillis();+ }++ private AwsException client(String message) {+ return new AwsException("ClientException", message, 400);+ }++ private record ListFilter(String name, List<String> values) {+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchAttempt.java b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchAttempt.javanew file mode 100644index 0000000000..fceda5ca1d--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchAttempt.java@@ -0,0 +1,47 @@+package io.github.hectorvent.floci.services.batch.model;++import com.fasterxml.jackson.annotation.JsonIgnoreProperties;+import com.fasterxml.jackson.annotation.JsonInclude;+import io.quarkus.runtime.annotations.RegisterForReflection;++@RegisterForReflection+@JsonIgnoreProperties(ignoreUnknown = true)+@JsonInclude(JsonInclude.Include.NON_EMPTY)+public class BatchAttempt {+ private Long startedAt;+ private Long stoppedAt;+ private String statusReason;+ private BatchAttemptContainer container;++ public Long getStartedAt() {+ return startedAt;+ }++ public void setStartedAt(Long startedAt) {+ this.startedAt = startedAt;+ }++ public Long getStoppedAt() {+ return stoppedAt;+ }++ public void setStoppedAt(Long stoppedAt) {+ this.stoppedAt = stoppedAt;+ }++ public String getStatusReason() {+ return statusReason;+ }++ public void setStatusReason(String statusReason) {+ this.statusReason = statusReason;+ }++ public BatchAttemptContainer getContainer() {+ return container;+ }++ public void setContainer(BatchAttemptContainer container) {+ this.container = container;+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchAttemptContainer.java b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchAttemptContainer.javanew file mode 100644index 0000000000..e1a06bfaf5--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchAttemptContainer.java@@ -0,0 +1,56 @@+package io.github.hectorvent.floci.services.batch.model;++import com.fasterxml.jackson.annotation.JsonIgnoreProperties;+import com.fasterxml.jackson.annotation.JsonInclude;+import io.quarkus.runtime.annotations.RegisterForReflection;++@RegisterForReflection+@JsonIgnoreProperties(ignoreUnknown = true)+@JsonInclude(JsonInclude.Include.NON_NULL)+public class BatchAttemptContainer {+ private Integer exitCode;+ private String reason;+ private String logStreamName;+ private String taskArn;+ private String containerInstanceArn;++ public Integer getExitCode() {+ return exitCode;+ }++ public void setExitCode(Integer exitCode) {+ this.exitCode = exitCode;+ }++ public String getReason() {+ return reason;+ }++ public void setReason(String reason) {+ this.reason = reason;+ }++ public String getLogStreamName() {+ return logStreamName;+ }++ public void setLogStreamName(String logStreamName) {+ this.logStreamName = logStreamName;+ }++ public String getTaskArn() {+ return taskArn;+ }++ public void setTaskArn(String taskArn) {+ this.taskArn = taskArn;+ }++ public String getContainerInstanceArn() {+ return containerInstanceArn;+ }++ public void setContainerInstanceArn(String containerInstanceArn) {+ this.containerInstanceArn = containerInstanceArn;+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchComputeEnvironment.java b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchComputeEnvironment.javanew file mode 100644index 0000000000..85ca900070--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchComputeEnvironment.java@@ -0,0 +1,122 @@+package io.github.hectorvent.floci.services.batch.model;++import com.fasterxml.jackson.annotation.JsonIgnoreProperties;+import com.fasterxml.jackson.annotation.JsonInclude;+import io.quarkus.runtime.annotations.RegisterForReflection;++import java.util.HashMap;+import java.util.Map;++@RegisterForReflection+@JsonIgnoreProperties(ignoreUnknown = true)+@JsonInclude(JsonInclude.Include.NON_EMPTY)+public class BatchComputeEnvironment {+ private String computeEnvironmentName;+ private String computeEnvironmentArn;+ private String type;+ private String state;+ private String status;+ private String statusReason;+ private Map<String, Object> computeResources = new HashMap<>();+ private String serviceRole;+ private Map<String, String> tags = new HashMap<>();+ private long createdAt;+ private String region;+ private String accountId;++ public String getComputeEnvironmentName() {+ return computeEnvironmentName;+ }++ public void setComputeEnvironmentName(String computeEnvironmentName) {+ this.computeEnvironmentName = computeEnvironmentName;+ }++ public String getComputeEnvironmentArn() {+ return computeEnvironmentArn;+ }++ public void setComputeEnvironmentArn(String computeEnvironmentArn) {+ this.computeEnvironmentArn = computeEnvironmentArn;+ }++ public String getType() {+ return type;+ }++ public void setType(String type) {+ this.type = type;+ }++ public String getState() {+ return state;+ }++ public void setState(String state) {+ this.state = state;+ }++ public String getStatus() {+ return status;+ }++ public void setStatus(String status) {+ this.status = status;+ }++ public String getStatusReason() {+ return statusReason;+ }++ public void setStatusReason(String statusReason) {+ this.statusReason = statusReason;+ }++ public Map<String, Object> getComputeResources() {+ return computeResources;+ }++ public void setComputeResources(Map<String, Object> computeResources) {+ this.computeResources = computeResources != null ? computeResources : new HashMap<>();+ }++ public String getServiceRole() {+ return serviceRole;+ }++ public void setServiceRole(String serviceRole) {+ this.serviceRole = serviceRole;+ }++ public Map<String, String> getTags() {+ return tags;+ }++ public void setTags(Map<String, String> tags) {+ this.tags = tags != null ? tags : new HashMap<>();+ }++ public long getCreatedAt() {+ return createdAt;+ }++ public void setCreatedAt(long createdAt) {+ this.createdAt = createdAt;+ }++ public String getRegion() {+ return region;+ }++ public void setRegion(String region) {+ this.region = region;+ }++ public String getAccountId() {+ return accountId;+ }++ public void setAccountId(String accountId) {+ this.accountId = accountId;+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchComputeEnvironmentOrder.java b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchComputeEnvironmentOrder.javanew file mode 100644index 0000000000..214e03220c--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchComputeEnvironmentOrder.java@@ -0,0 +1,29 @@+package io.github.hectorvent.floci.services.batch.model;++import com.fasterxml.jackson.annotation.JsonIgnoreProperties;+import com.fasterxml.jackson.annotation.JsonInclude;+import io.quarkus.runtime.annotations.RegisterForReflection;++@RegisterForReflection+@JsonIgnoreProperties(ignoreUnknown = true)+@JsonInclude(JsonInclude.Include.NON_EMPTY)+public class BatchComputeEnvironmentOrder {+ private int order;+ private String computeEnvironment;++ public int getOrder() {+ return order;+ }++ public void setOrder(int order) {+ this.order = order;+ }++ public String getComputeEnvironment() {+ return computeEnvironment;+ }++ public void setComputeEnvironment(String computeEnvironment) {+ this.computeEnvironment = computeEnvironment;+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchContainerOverrides.java b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchContainerOverrides.javanew file mode 100644index 0000000000..4a2abe3f2c--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchContainerOverrides.java@@ -0,0 +1,41 @@+package io.github.hectorvent.floci.services.batch.model;++import com.fasterxml.jackson.annotation.JsonIgnoreProperties;+import com.fasterxml.jackson.annotation.JsonInclude;+import io.quarkus.runtime.annotations.RegisterForReflection;++import java.util.ArrayList;+import java.util.List;++@RegisterForReflection+@JsonIgnoreProperties(ignoreUnknown = true)+@JsonInclude(JsonInclude.Include.NON_EMPTY)+public class BatchContainerOverrides {+ private List<String> command = new ArrayList<>();+ private List<BatchKeyValue> environment = new ArrayList<>();+ private List<BatchResourceRequirement> resourceRequirements = new ArrayList<>();++ public List<String> getCommand() {+ return command;+ }++ public void setCommand(List<String> command) {+ this.command = command != null ? command : new ArrayList<>();+ }++ public List<BatchKeyValue> getEnvironment() {+ return environment;+ }++ public void setEnvironment(List<BatchKeyValue> environment) {+ this.environment = environment != null ? environment : new ArrayList<>();+ }++ public List<BatchResourceRequirement> getResourceRequirements() {+ return resourceRequirements;+ }++ public void setResourceRequirements(List<BatchResourceRequirement> resourceRequirements) {+ this.resourceRequirements = resourceRequirements != null ? resourceRequirements : new ArrayList<>();+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchContainerProperties.java b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchContainerProperties.javanew file mode 100644index 0000000000..d9be01549a--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchContainerProperties.java@@ -0,0 +1,96 @@+package io.github.hectorvent.floci.services.batch.model;++import com.fasterxml.jackson.annotation.JsonIgnoreProperties;+import com.fasterxml.jackson.annotation.JsonInclude;+import io.quarkus.runtime.annotations.RegisterForReflection;++import java.util.ArrayList;+import java.util.List;+import java.util.Map;++@RegisterForReflection+@JsonIgnoreProperties(ignoreUnknown = true)+@JsonInclude(JsonInclude.Include.NON_EMPTY)+public class BatchContainerProperties {+ private String image;+ private List<String> command = new ArrayList<>();+ private List<BatchKeyValue> environment = new ArrayList<>();+ private List<BatchResourceRequirement> resourceRequirements = new ArrayList<>();+ private String jobRoleArn;+ private String executionRoleArn;+ private Map<String, Object> logConfiguration;+ private Map<String, Object> networkConfiguration;+ private Map<String, Object> ephemeralStorage;++ public String getImage() {+ return image;+ }++ public void setImage(String image) {+ this.image = image;+ }++ public List<String> getCommand() {+ return command;+ }++ public void setCommand(List<String> command) {+ this.command = command != null ? command : new ArrayList<>();+ }++ public List<BatchKeyValue> getEnvironment() {+ return environment;+ }++ public void setEnvironment(List<BatchKeyValue> environment) {+ this.environment = environment != null ? environment : new ArrayList<>();+ }++ public List<BatchResourceRequirement> getResourceRequirements() {+ return resourceRequirements;+ }++ public void setResourceRequirements(List<BatchResourceRequirement> resourceRequirements) {+ this.resourceRequirements = resourceRequirements != null ? resourceRequirements : new ArrayList<>();+ }++ public String getJobRoleArn() {+ return jobRoleArn;+ }++ public void setJobRoleArn(String jobRoleArn) {+ this.jobRoleArn = jobRoleArn;+ }++ public String getExecutionRoleArn() {+ return executionRoleArn;+ }++ public void setExecutionRoleArn(String executionRoleArn) {+ this.executionRoleArn = executionRoleArn;+ }++ public Map<String, Object> getLogConfiguration() {+ return logConfiguration;+ }++ public void setLogConfiguration(Map<String, Object> logConfiguration) {+ this.logConfiguration = logConfiguration;+ }++ public Map<String, Object> getNetworkConfiguration() {+ return networkConfiguration;+ }++ public void setNetworkConfiguration(Map<String, Object> networkConfiguration) {+ this.networkConfiguration = networkConfiguration;+ }++ public Map<String, Object> getEphemeralStorage() {+ return ephemeralStorage;+ }++ public void setEphemeralStorage(Map<String, Object> ephemeralStorage) {+ this.ephemeralStorage = ephemeralStorage;+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchJob.java b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchJob.javanew file mode 100644index 0000000000..d5a6bc0e94--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchJob.java@@ -0,0 +1,250 @@+package io.github.hectorvent.floci.services.batch.model;++import com.fasterxml.jackson.annotation.JsonIgnoreProperties;+import com.fasterxml.jackson.annotation.JsonInclude;+import io.quarkus.runtime.annotations.RegisterForReflection;++import java.util.ArrayList;+import java.util.HashMap;+import java.util.List;+import java.util.Map;++@RegisterForReflection+@JsonIgnoreProperties(ignoreUnknown = true)+@JsonInclude(JsonInclude.Include.NON_EMPTY)+public class BatchJob {+ private String jobId;+ private String jobArn;+ private String jobName;+ private String jobQueue;+ private String jobQueueName;+ private String jobDefinition;+ private String jobDefinitionName;+ private int jobDefinitionRevision;+ private String status;+ private String statusReason;+ private long createdAt;+ private Long startedAt;+ private Long stoppedAt;+ private Map<String, String> parameters = new HashMap<>();+ private BatchContainerOverrides containerOverrides;+ private List<String> resolvedCommand = new ArrayList<>();+ private List<BatchKeyValue> resolvedEnvironment = new ArrayList<>();+ private List<BatchResourceRequirement> resourceRequirements = new ArrayList<>();+ private BatchRetryStrategy retryStrategy;+ private BatchTimeout timeout;+ private List<BatchAttempt> attempts = new ArrayList<>();+ private BatchAttemptContainer container = new BatchAttemptContainer();+ private Map<String, String> tags = new HashMap<>();+ private String region;+ private String accountId;+ private String containerImage;++ public String getJobId() {+ return jobId;+ }++ public void setJobId(String jobId) {+ this.jobId = jobId;+ }++ public String getJobArn() {+ return jobArn;+ }++ public void setJobArn(String jobArn) {+ this.jobArn = jobArn;+ }++ public String getJobName() {+ return jobName;+ }++ public void setJobName(String jobName) {+ this.jobName = jobName;+ }++ public String getJobQueue() {+ return jobQueue;+ }++ public void setJobQueue(String jobQueue) {+ this.jobQueue = jobQueue;+ }++ public String getJobQueueName() {+ return jobQueueName;+ }++ public void setJobQueueName(String jobQueueName) {+ this.jobQueueName = jobQueueName;+ }++ public String getJobDefinition() {+ return jobDefinition;+ }++ public void setJobDefinition(String jobDefinition) {+ this.jobDefinition = jobDefinition;+ }++ public String getJobDefinitionName() {+ return jobDefinitionName;+ }++ public void setJobDefinitionName(String jobDefinitionName) {+ this.jobDefinitionName = jobDefinitionName;+ }++ public int getJobDefinitionRevision() {+ return jobDefinitionRevision;+ }++ public void setJobDefinitionRevision(int jobDefinitionRevision) {+ this.jobDefinitionRevision = jobDefinitionRevision;+ }++ public String getStatus() {+ return status;+ }++ public void setStatus(String status) {+ this.status = status;+ }++ public String getStatusReason() {+ return statusReason;+ }++ public void setStatusReason(String statusReason) {+ this.statusReason = statusReason;+ }++ public long getCreatedAt() {+ return createdAt;+ }++ public void setCreatedAt(long createdAt) {+ this.createdAt = createdAt;+ }++ public Long getStartedAt() {+ return startedAt;+ }++ public void setStartedAt(Long startedAt) {+ this.startedAt = startedAt;+ }++ public Long getStoppedAt() {+ return stoppedAt;+ }++ public void setStoppedAt(Long stoppedAt) {+ this.stoppedAt = stoppedAt;+ }++ public Map<String, String> getParameters() {+ return parameters;+ }++ public void setParameters(Map<String, String> parameters) {+ this.parameters = parameters != null ? parameters : new HashMap<>();+ }++ public BatchContainerOverrides getContainerOverrides() {+ return containerOverrides;+ }++ public void setContainerOverrides(BatchContainerOverrides containerOverrides) {+ this.containerOverrides = containerOverrides;+ }++ public List<String> getResolvedCommand() {+ return resolvedCommand;+ }++ public void setResolvedCommand(List<String> resolvedCommand) {+ this.resolvedCommand = resolvedCommand != null ? resolvedCommand : new ArrayList<>();+ }++ public List<BatchKeyValue> getResolvedEnvironment() {+ return resolvedEnvironment;+ }++ public void setResolvedEnvironment(List<BatchKeyValue> resolvedEnvironment) {+ this.resolvedEnvironment = resolvedEnvironment != null ? resolvedEnvironment : new ArrayList<>();+ }++ public List<BatchResourceRequirement> getResourceRequirements() {+ return resourceRequirements;+ }++ public void setResourceRequirements(List<BatchResourceRequirement> resourceRequirements) {+ this.resourceRequirements = resourceRequirements != null ? resourceRequirements : new ArrayList<>();+ }++ public BatchRetryStrategy getRetryStrategy() {+ return retryStrategy;+ }++ public void setRetryStrategy(BatchRetryStrategy retryStrategy) {+ this.retryStrategy = retryStrategy;+ }++ public BatchTimeout getTimeout() {+ return timeout;+ }++ public void setTimeout(BatchTimeout timeout) {+ this.timeout = timeout;+ }++ public List<BatchAttempt> getAttempts() {+ return attempts;+ }++ public void setAttempts(List<BatchAttempt> attempts) {+ this.attempts = attempts != null ? attempts : new ArrayList<>();+ }++ public BatchAttemptContainer getContainer() {+ return container;+ }++ public void setContainer(BatchAttemptContainer container) {+ this.container = container;+ }++ public Map<String, String> getTags() {+ return tags;+ }++ public void setTags(Map<String, String> tags) {+ this.tags = tags != null ? tags : new HashMap<>();+ }++ public String getRegion() {+ return region;+ }++ public void setRegion(String region) {+ this.region = region;+ }++ public String getAccountId() {+ return accountId;+ }++ public void setAccountId(String accountId) {+ this.accountId = accountId;+ }++ public String getContainerImage() {+ return containerImage;+ }++ public void setContainerImage(String containerImage) {+ this.containerImage = containerImage;+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchJobDefinition.java b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchJobDefinition.javanew file mode 100644index 0000000000..f892385c0b--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchJobDefinition.java@@ -0,0 +1,141 @@+package io.github.hectorvent.floci.services.batch.model;++import com.fasterxml.jackson.annotation.JsonIgnoreProperties;+import com.fasterxml.jackson.annotation.JsonInclude;+import io.quarkus.runtime.annotations.RegisterForReflection;++import java.util.HashMap;+import java.util.List;+import java.util.Map;++@RegisterForReflection+@JsonIgnoreProperties(ignoreUnknown = true)+@JsonInclude(JsonInclude.Include.NON_EMPTY)+public class BatchJobDefinition {+ private String jobDefinitionName;+ private String jobDefinitionArn;+ private int revision;+ private String status;+ private String type;+ private BatchContainerProperties containerProperties;+ private Map<String, String> parameters = new HashMap<>();+ private BatchRetryStrategy retryStrategy;+ private BatchTimeout timeout;+ private List<String> platformCapabilities = List.of();+ private Map<String, String> tags = new HashMap<>();+ private long createdAt;+ private String region;+ private String accountId;++ public String getJobDefinitionName() {+ return jobDefinitionName;+ }++ public void setJobDefinitionName(String jobDefinitionName) {+ this.jobDefinitionName = jobDefinitionName;+ }++ public String getJobDefinitionArn() {+ return jobDefinitionArn;+ }++ public void setJobDefinitionArn(String jobDefinitionArn) {+ this.jobDefinitionArn = jobDefinitionArn;+ }++ public int getRevision() {+ return revision;+ }++ public void setRevision(int revision) {+ this.revision = revision;+ }++ public String getStatus() {+ return status;+ }++ public void setStatus(String status) {+ this.status = status;+ }++ public String getType() {+ return type;+ }++ public void setType(String type) {+ this.type = type;+ }++ public BatchContainerProperties getContainerProperties() {+ return containerProperties;+ }++ public void setContainerProperties(BatchContainerProperties containerProperties) {+ this.containerProperties = containerProperties;+ }++ public Map<String, String> getParameters() {+ return parameters;+ }++ public void setParameters(Map<String, String> parameters) {+ this.parameters = parameters != null ? parameters : new HashMap<>();+ }++ public BatchRetryStrategy getRetryStrategy() {+ return retryStrategy;+ }++ public void setRetryStrategy(BatchRetryStrategy retryStrategy) {+ this.retryStrategy = retryStrategy;+ }++ public BatchTimeout getTimeout() {+ return timeout;+ }++ public void setTimeout(BatchTimeout timeout) {+ this.timeout = timeout;+ }++ public List<String> getPlatformCapabilities() {+ return platformCapabilities;+ }++ public void setPlatformCapabilities(List<String> platformCapabilities) {+ this.platformCapabilities = platformCapabilities != null ? platformCapabilities : List.of();+ }++ public Map<String, String> getTags() {+ return tags;+ }++ public void setTags(Map<String, String> tags) {+ this.tags = tags != null ? tags : new HashMap<>();+ }++ public long getCreatedAt() {+ return createdAt;+ }++ public void setCreatedAt(long createdAt) {+ this.createdAt = createdAt;+ }++ public String getRegion() {+ return region;+ }++ public void setRegion(String region) {+ this.region = region;+ }++ public String getAccountId() {+ return accountId;+ }++ public void setAccountId(String accountId) {+ this.accountId = accountId;+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchJobQueue.java b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchJobQueue.javanew file mode 100644index 0000000000..5eb6504250--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchJobQueue.java@@ -0,0 +1,124 @@+package io.github.hectorvent.floci.services.batch.model;++import com.fasterxml.jackson.annotation.JsonIgnoreProperties;+import com.fasterxml.jackson.annotation.JsonInclude;+import io.quarkus.runtime.annotations.RegisterForReflection;++import java.util.ArrayList;+import java.util.HashMap;+import java.util.List;+import java.util.Map;++@RegisterForReflection+@JsonIgnoreProperties(ignoreUnknown = true)+@JsonInclude(JsonInclude.Include.NON_EMPTY)+public class BatchJobQueue {+ private String jobQueueName;+ private String jobQueueArn;+ private String state;+ private String status;+ private String statusReason;+ private int priority;+ private String jobQueueType;+ private List<BatchComputeEnvironmentOrder> computeEnvironmentOrder = new ArrayList<>();+ private Map<String, String> tags = new HashMap<>();+ private long createdAt;+ private String region;+ private String accountId;++ public String getJobQueueName() {+ return jobQueueName;+ }++ public void setJobQueueName(String jobQueueName) {+ this.jobQueueName = jobQueueName;+ }++ public String getJobQueueArn() {+ return jobQueueArn;+ }++ public void setJobQueueArn(String jobQueueArn) {+ this.jobQueueArn = jobQueueArn;+ }++ public String getState() {+ return state;+ }++ public void setState(String state) {+ this.state = state;+ }++ public String getStatus() {+ return status;+ }++ public void setStatus(String status) {+ this.status = status;+ }++ public String getStatusReason() {+ return statusReason;+ }++ public void setStatusReason(String statusReason) {+ this.statusReason = statusReason;+ }++ public int getPriority() {+ return priority;+ }++ public void setPriority(int priority) {+ this.priority = priority;+ }++ public String getJobQueueType() {+ return jobQueueType;+ }++ public void setJobQueueType(String jobQueueType) {+ this.jobQueueType = jobQueueType;+ }++ public List<BatchComputeEnvironmentOrder> getComputeEnvironmentOrder() {+ return computeEnvironmentOrder;+ }++ public void setComputeEnvironmentOrder(List<BatchComputeEnvironmentOrder> computeEnvironmentOrder) {+ this.computeEnvironmentOrder = computeEnvironmentOrder != null ? computeEnvironmentOrder : new ArrayList<>();+ }++ public Map<String, String> getTags() {+ return tags;+ }++ public void setTags(Map<String, String> tags) {+ this.tags = tags != null ? tags : new HashMap<>();+ }++ public long getCreatedAt() {+ return createdAt;+ }++ public void setCreatedAt(long createdAt) {+ this.createdAt = createdAt;+ }++ public String getRegion() {+ return region;+ }++ public void setRegion(String region) {+ this.region = region;+ }++ public String getAccountId() {+ return accountId;+ }++ public void setAccountId(String accountId) {+ this.accountId = accountId;+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchKeyValue.java b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchKeyValue.javanew file mode 100644index 0000000000..dfd95d5993--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchKeyValue.java@@ -0,0 +1,37 @@+package io.github.hectorvent.floci.services.batch.model;++import com.fasterxml.jackson.annotation.JsonIgnoreProperties;+import com.fasterxml.jackson.annotation.JsonInclude;+import io.quarkus.runtime.annotations.RegisterForReflection;++@RegisterForReflection+@JsonIgnoreProperties(ignoreUnknown = true)+@JsonInclude(JsonInclude.Include.NON_NULL)+public class BatchKeyValue {+ private String name;+ private String value;++ public BatchKeyValue() {+ }++ public BatchKeyValue(String name, String value) {+ this.name = name;+ this.value = value;+ }++ public String getName() {+ return name;+ }++ public void setName(String name) {+ this.name = name;+ }++ public String getValue() {+ return value;+ }++ public void setValue(String value) {+ this.value = value;+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchResourceRequirement.java b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchResourceRequirement.javanew file mode 100644index 0000000000..05a5388827--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchResourceRequirement.java@@ -0,0 +1,37 @@+package io.github.hectorvent.floci.services.batch.model;++import com.fasterxml.jackson.annotation.JsonIgnoreProperties;+import com.fasterxml.jackson.annotation.JsonInclude;+import io.quarkus.runtime.annotations.RegisterForReflection;++@RegisterForReflection+@JsonIgnoreProperties(ignoreUnknown = true)+@JsonInclude(JsonInclude.Include.NON_NULL)+public class BatchResourceRequirement {+ private String type;+ private String value;++ public BatchResourceRequirement() {+ }++ public BatchResourceRequirement(String type, String value) {+ this.type = type;+ this.value = value;+ }++ public String getType() {+ return type;+ }++ public void setType(String type) {+ this.type = type;+ }++ public String getValue() {+ return value;+ }++ public void setValue(String value) {+ this.value = value;+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchRetryStrategy.java b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchRetryStrategy.javanew file mode 100644index 0000000000..c8edc40476--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchRetryStrategy.java@@ -0,0 +1,33 @@+package io.github.hectorvent.floci.services.batch.model;++import com.fasterxml.jackson.annotation.JsonIgnoreProperties;+import com.fasterxml.jackson.annotation.JsonInclude;+import io.quarkus.runtime.annotations.RegisterForReflection;++import java.util.ArrayList;+import java.util.List;+import java.util.Map;++@RegisterForReflection+@JsonIgnoreProperties(ignoreUnknown = true)+@JsonInclude(JsonInclude.Include.NON_EMPTY)+public class BatchRetryStrategy {+ private Integer attempts;+ private List<Map<String, Object>> evaluateOnExit = new ArrayList<>();++ public Integer getAttempts() {+ return attempts;+ }++ public void setAttempts(Integer attempts) {+ this.attempts = attempts;+ }++ public List<Map<String, Object>> getEvaluateOnExit() {+ return evaluateOnExit;+ }++ public void setEvaluateOnExit(List<Map<String, Object>> evaluateOnExit) {+ this.evaluateOnExit = evaluateOnExit != null ? evaluateOnExit : new ArrayList<>();+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchRunResult.java b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchRunResult.javanew file mode 100644index 0000000000..afca7f82d4--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchRunResult.java@@ -0,0 +1,11 @@+package io.github.hectorvent.floci.services.batch.model;++public record BatchRunResult(+ int exitCode,+ String reason,+ String logStreamName,+ long startedAt,+ long stoppedAt,+ boolean timedOut+) {+}diff --git a/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchStatus.java b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchStatus.javanew file mode 100644index 0000000000..0c2cb6c980--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchStatus.java@@ -0,0 +1,11 @@+package io.github.hectorvent.floci.services.batch.model;++public enum BatchStatus {+ SUBMITTED,+ PENDING,+ RUNNABLE,+ STARTING,+ RUNNING,+ SUCCEEDED,+ FAILED+}diff --git a/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchTimeout.java b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchTimeout.javanew file mode 100644index 0000000000..2c97eec5a4--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/batch/model/BatchTimeout.java@@ -0,0 +1,20 @@+package io.github.hectorvent.floci.services.batch.model;++import com.fasterxml.jackson.annotation.JsonIgnoreProperties;+import com.fasterxml.jackson.annotation.JsonInclude;+import io.quarkus.runtime.annotations.RegisterForReflection;++@RegisterForReflection+@JsonIgnoreProperties(ignoreUnknown = true)+@JsonInclude(JsonInclude.Include.NON_NULL)+public class BatchTimeout {+ private Integer attemptDurationSeconds;++ public Integer getAttemptDurationSeconds() {+ return attemptDurationSeconds;+ }++ public void setAttemptDurationSeconds(Integer attemptDurationSeconds) {+ this.attemptDurationSeconds = attemptDurationSeconds;+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.javaindex 7c15283114..8c23bd21d8 100644--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java@@ -1,9 +1,11 @@package io.github.hectorvent.floci.services.cloudformation;import io.github.hectorvent.floci.core.common.AwsArnUtils;+import io.github.hectorvent.floci.services.batch.BatchService;import io.github.hectorvent.floci.services.cloudformation.model.StackResource;import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;import io.github.hectorvent.floci.services.eventbridge.EventBridgeService;+import io.github.hectorvent.floci.services.eventbridge.model.BatchParameters;import io.github.hectorvent.floci.services.eventbridge.model.RuleState;import io.github.hectorvent.floci.services.eventbridge.model.SqsParameters;import io.github.hectorvent.floci.services.eventbridge.model.Target;@@ -60,6 +62,8 @@ import io.github.hectorvent.floci.services.lambda.model.InvocationType;import io.github.hectorvent.floci.services.lambda.model.InvokeResult;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.JsonNodeFactory;import com.fasterxml.jackson.databind.node.ObjectNode;import jakarta.enterprise.context.ApplicationScoped;import jakarta.inject.Inject;@@ -124,6 +128,7 @@ public class CloudFormationResourceProvisioner {private final EcsService ecsService;private final ElbV2Service elbV2Service;private final StepFunctionsService stepFunctionsService;+ private final BatchService batchService;@Injectpublic CloudFormationResourceProvisioner(S3Service s3Service, SqsService sqsService,@@ -143,7 +148,8 @@ public class CloudFormationResourceProvisioner {ContainerReachableEndpoint reachableEndpoint,EcsService ecsService,ElbV2Service elbV2Service,- StepFunctionsService stepFunctionsService) {+ StepFunctionsService stepFunctionsService,+ BatchService batchService) {this.s3Service = s3Service;this.sqsService = sqsService;this.snsService = snsService;@@ -166,6 +172,7 @@ public class CloudFormationResourceProvisioner {this.ecsService = ecsService;this.elbV2Service = elbV2Service;this.stepFunctionsService = stepFunctionsService;+ this.batchService = batchService;}/**@@ -256,6 +263,12 @@ public class CloudFormationResourceProvisioner {provisionListener(resource, properties, engine, region);case "AWS::ElasticLoadBalancingV2::ListenerRule" ->provisionListenerRule(resource, properties, engine, region);+ case "AWS::Batch::ComputeEnvironment" ->+ provisionBatchComputeEnvironment(resource, properties, engine, region, stackName);+ case "AWS::Batch::JobQueue" ->+ provisionBatchJobQueue(resource, properties, engine, region, stackName);+ case "AWS::Batch::JobDefinition" ->+ provisionBatchJobDefinition(resource, properties, engine, region, stackName);default -> {if (resourceType != null && resourceType.startsWith("Custom::")) {provisionCustomResource(resource, properties, engine, region, accountId, stackName);@@ -1333,6 +1346,20 @@ public class CloudFormationResourceProvisioner {target.setSqsParameters(sqsParameters);}}+ JsonNode batchParamsNode = resolved.path("BatchParameters");+ if (!batchParamsNode.isMissingNode() && batchParamsNode.isObject()) {+ JsonNode arrayProperties = batchParamsNode.path("ArrayProperties");+ BatchParameters batchParameters = new BatchParameters();+ batchParameters.setJobDefinition(batchParamsNode.path("JobDefinition").asText(null));+ batchParameters.setJobName(batchParamsNode.path("JobName").asText(null));+ if (arrayProperties.isObject()) {+ batchParameters.setArrayProperties(jsonObjectToMap(arrayProperties));+ }+ if (batchParamsNode.has("RetryStrategy")) {+ batchParameters.setRetryStrategy(batchParamsNode.get("RetryStrategy"));+ }+ target.setBatchParameters(batchParameters);+ }targets.add(target);}}@@ -1356,6 +1383,216 @@ public class CloudFormationResourceProvisioner {}}+ // ── Batch ────────────────────────────────────────────────────────────────++ private void provisionBatchComputeEnvironment(StackResource r, JsonNode props,+ CloudFormationTemplateEngine engine,+ String region, String stackName) {+ String name = resolveOptional(props, "ComputeEnvironmentName", engine);+ if (name == null || name.isBlank()) {+ name = generatePhysicalName(stackName, r.getLogicalId(), 128, false);+ }++ ObjectNode req = JsonNodeFactory.instance.objectNode();+ req.put("computeEnvironmentName", name);+ putResolvedText(req, "type", props, "Type", engine);+ putResolvedText(req, "state", props, "State", engine);+ putResolvedText(req, "serviceRole", props, "ServiceRole", engine);+ putResolvedObject(req, "computeResources", props, "ComputeResources", engine);+ putTagsObject(req, props, engine);++ ObjectNode response = batchService.createComputeEnvironment(req, region);+ String arn = response.path("computeEnvironmentArn").asText();+ r.setPhysicalId(arn);+ r.getAttributes().put("Arn", arn);+ r.getAttributes().put("ComputeEnvironmentArn", arn);+ r.getAttributes().put("ComputeEnvironmentName", name);+ }++ private void provisionBatchJobQueue(StackResource r, JsonNode props,+ CloudFormationTemplateEngine engine,+ String region, String stackName) {+ String name = resolveOptional(props, "JobQueueName", engine);+ if (name == null || name.isBlank()) {+ name = generatePhysicalName(stackName, r.getLogicalId(), 128, false);+ }++ ObjectNode req = JsonNodeFactory.instance.objectNode();+ req.put("jobQueueName", name);+ String priority = resolveOptional(props, "Priority", engine);+ req.put("priority", priority != null ? Integer.parseInt(priority) : 1);+ putResolvedText(req, "state", props, "State", engine);+ putResolvedText(req, "jobQueueType", props, "JobQueueType", engine);+ req.set("computeEnvironmentOrder", batchComputeEnvironmentOrder(props, engine));+ putTagsObject(req, props, engine);++ ObjectNode response = batchService.createJobQueue(req, region);+ String arn = response.path("jobQueueArn").asText();+ r.setPhysicalId(arn);+ r.getAttributes().put("Arn", arn);+ r.getAttributes().put("JobQueueArn", arn);+ r.getAttributes().put("JobQueueName", name);+ }++ private void provisionBatchJobDefinition(StackResource r, JsonNode props,+ CloudFormationTemplateEngine engine,+ String region, String stackName) {+ String name = resolveOptional(props, "JobDefinitionName", engine);+ if (name == null || name.isBlank()) {+ name = generatePhysicalName(stackName, r.getLogicalId(), 128, false);+ }++ ObjectNode req = JsonNodeFactory.instance.objectNode();+ req.put("jobDefinitionName", name);+ req.put("type", resolveOrDefault(props, "Type", engine, "container"));+ putResolvedArray(req, "platformCapabilities", props, "PlatformCapabilities", engine);+ if (props != null && props.has("ContainerProperties")) {+ req.set("containerProperties", batchContainerProperties(+ engine.resolveNode(props.get("ContainerProperties")), engine));+ }+ putStringMapFromObject(req, "parameters", props, "Parameters", engine);+ if (props != null && props.has("RetryStrategy")) {+ req.set("retryStrategy", batchRetryStrategy(engine.resolveNode(props.get("RetryStrategy"))));+ }+ if (props != null && props.has("Timeout")) {+ ObjectNode timeout = JsonNodeFactory.instance.objectNode();+ JsonNode resolved = engine.resolveNode(props.get("Timeout"));+ if (resolved.has("AttemptDurationSeconds")) {+ timeout.set("attemptDurationSeconds", resolved.get("AttemptDurationSeconds"));+ }+ req.set("timeout", timeout);+ }+ putTagsObject(req, props, engine);++ ObjectNode response = batchService.registerJobDefinition(req, region);+ String arn = response.path("jobDefinitionArn").asText();+ r.setPhysicalId(arn);+ r.getAttributes().put("Arn", arn);+ r.getAttributes().put("JobDefinitionArn", arn);+ r.getAttributes().put("JobDefinitionName", name);+ r.getAttributes().put("Revision", response.path("revision").asText());+ }++ private ArrayNode batchComputeEnvironmentOrder(JsonNode props, CloudFormationTemplateEngine engine) {+ ArrayNode out = JsonNodeFactory.instance.arrayNode();+ if (props == null || !props.has("ComputeEnvironmentOrder")) {+ return out;+ }+ JsonNode resolved = engine.resolveNode(props.get("ComputeEnvironmentOrder"));+ if (!resolved.isArray()) {+ return out;+ }+ for (JsonNode item : resolved) {+ ObjectNode order = out.addObject();+ order.put("order", item.path("Order").asInt());+ order.put("computeEnvironment", item.path("ComputeEnvironment").asText(null));+ }+ return out;+ }++ private ObjectNode batchContainerProperties(JsonNode resolved, CloudFormationTemplateEngine engine) {+ ObjectNode container = JsonNodeFactory.instance.objectNode();+ if (resolved == null || !resolved.isObject()) {+ return container;+ }+ copyIfPresent(container, "image", resolved, "Image");+ copyIfPresent(container, "command", resolved, "Command");+ copyIfPresent(container, "jobRoleArn", resolved, "JobRoleArn");+ copyIfPresent(container, "executionRoleArn", resolved, "ExecutionRoleArn");+ copyIfPresent(container, "logConfiguration", resolved, "LogConfiguration");+ copyIfPresent(container, "networkConfiguration", resolved, "NetworkConfiguration");+ copyIfPresent(container, "ephemeralStorage", resolved, "EphemeralStorage");+ if (resolved.has("ResourceRequirements") && resolved.get("ResourceRequirements").isArray()) {+ ArrayNode resources = container.putArray("resourceRequirements");+ for (JsonNode item : resolved.get("ResourceRequirements")) {+ ObjectNode requirement = resources.addObject();+ requirement.put("type", item.path("Type").asText(null));+ requirement.put("value", item.path("Value").asText(null));+ }+ }+ if (resolved.has("Environment") && resolved.get("Environment").isArray()) {+ ArrayNode env = container.putArray("environment");+ for (JsonNode item : resolved.get("Environment")) {+ ObjectNode entry = env.addObject();+ entry.put("name", item.path("Name").asText(null));+ entry.put("value", item.path("Value").asText(null));+ }+ }+ return container;+ }++ private ObjectNode batchRetryStrategy(JsonNode resolved) {+ ObjectNode retry = JsonNodeFactory.instance.objectNode();+ if (resolved == null || !resolved.isObject()) {+ return retry;+ }+ if (resolved.has("Attempts")) {+ retry.set("attempts", resolved.get("Attempts"));+ }+ if (resolved.has("EvaluateOnExit")) {+ retry.set("evaluateOnExit", resolved.get("EvaluateOnExit"));+ }+ return retry;+ }++ private void putResolvedText(ObjectNode req, String target, JsonNode props, String source,+ CloudFormationTemplateEngine engine) {+ String value = resolveOptional(props, source, engine);+ if (value != null) {+ req.put(target, value);+ }+ }++ private void putResolvedObject(ObjectNode req, String target, JsonNode props, String source,+ CloudFormationTemplateEngine engine) {+ if (props == null || !props.has(source) || props.get(source).isNull()) {+ return;+ }+ JsonNode resolved = engine.resolveNode(props.get(source));+ if (resolved != null && resolved.isObject()) {+ req.set(target, resolved);+ }+ }++ private void putResolvedArray(ObjectNode req, String target, JsonNode props, String source,+ CloudFormationTemplateEngine engine) {+ if (props == null || !props.has(source) || props.get(source).isNull()) {+ return;+ }+ JsonNode resolved = engine.resolveNode(props.get(source));+ if (resolved != null && resolved.isArray()) {+ req.set(target, resolved);+ }+ }++ private void putStringMapFromObject(ObjectNode req, String target, JsonNode props, String source,+ CloudFormationTemplateEngine engine) {+ if (props == null || !props.has(source) || props.get(source).isNull()) {+ return;+ }+ JsonNode resolved = engine.resolveNode(props.get(source));+ if (!resolved.isObject()) {+ return;+ }+ ObjectNode out = JsonNodeFactory.instance.objectNode();+ resolved.fields().forEachRemaining(e -> out.put(e.getKey(), e.getValue().asText()));+ req.set(target, out);+ }++ private void putTagsObject(ObjectNode req, JsonNode props, CloudFormationTemplateEngine engine) {+ Map<String, String> tags = parseCfnTags(props != null ? props.get("Tags") : null, engine);+ if (!tags.isEmpty()) {+ ObjectNode tagNode = req.putObject("tags");+ tags.forEach(tagNode::put);+ }+ }++ private void copyIfPresent(ObjectNode target, String targetName, JsonNode source, String sourceName) {+ if (source.has(sourceName) && !source.get(sourceName).isNull()) {+ target.set(targetName, source.get(sourceName));+ }+ }+// ── Lambda EventSourceMapping ─────────────────────────────────────────────private void provisionLambdaEventSourceMapping(StackResource r, JsonNode props,diff --git a/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeHandler.java b/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeHandler.javaindex 10baa164a6..2f72bcb235 100644--- a/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeHandler.java+++ b/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeHandler.java@@ -5,6 +5,7 @@ import io.github.hectorvent.floci.core.common.AwsException;import io.github.hectorvent.floci.core.common.AwsJson11Controller;import io.github.hectorvent.floci.services.eventbridge.model.Archive;import io.github.hectorvent.floci.services.eventbridge.model.ArchiveState;+import io.github.hectorvent.floci.services.eventbridge.model.BatchParameters;import io.github.hectorvent.floci.services.eventbridge.model.EventBus;import io.github.hectorvent.floci.services.eventbridge.model.InputTransformer;import io.github.hectorvent.floci.services.eventbridge.model.Replay;@@ -234,6 +235,10 @@ public class EventBridgeHandler {target.setSqsParameters(sqsParameters);}}+ JsonNode batchParamsNode = t.path("BatchParameters");+ if (!batchParamsNode.isMissingNode() && batchParamsNode.isObject()) {+ target.setBatchParameters(objectMapper.convertValue(batchParamsNode, BatchParameters.class));+ }targets.add(target);}}@@ -291,6 +296,9 @@ public class EventBridgeHandler {if (t.getSqsParameters() != null && t.getSqsParameters().getMessageGroupId() != null) {node.putObject("SqsParameters").put("MessageGroupId", t.getSqsParameters().getMessageGroupId());}+ if (t.getBatchParameters() != null) {+ node.set("BatchParameters", objectMapper.valueToTree(t.getBatchParameters()));+ }targetsArray.add(node);}return Response.ok(response).build();diff --git a/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeInvoker.java b/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeInvoker.javaindex 38c83ccc70..78293cee10 100644--- a/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeInvoker.java+++ b/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeInvoker.java@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;import com.fasterxml.jackson.databind.ObjectMapper;import io.github.hectorvent.floci.config.EmulatorConfig;import io.github.hectorvent.floci.core.common.AwsArnUtils;+import io.github.hectorvent.floci.services.batch.BatchService;import io.github.hectorvent.floci.services.eventbridge.model.InputTransformer;import io.github.hectorvent.floci.services.eventbridge.model.Target;import io.github.hectorvent.floci.services.lambda.LambdaService;@@ -14,6 +15,9 @@ import jakarta.enterprise.context.ApplicationScoped;import jakarta.inject.Inject;import org.jboss.logging.Logger;+import java.util.LinkedHashMap;+import java.util.Map;+@ApplicationScopedpublic class EventBridgeInvoker {@@ -22,6 +26,7 @@ public class EventBridgeInvoker {private final LambdaService lambdaService;private final SqsService sqsService;private final SnsService snsService;+ private final BatchService batchService;private final ObjectMapper objectMapper;private final String baseUrl;@@ -29,15 +34,25 @@ public class EventBridgeInvoker {public EventBridgeInvoker(LambdaService lambdaService,SqsService sqsService,SnsService snsService,+ BatchService batchService,ObjectMapper objectMapper,EmulatorConfig config) {this.lambdaService = lambdaService;this.sqsService = sqsService;this.snsService = snsService;+ this.batchService = batchService;this.objectMapper = objectMapper;this.baseUrl = config.baseUrl();}+ EventBridgeInvoker(LambdaService lambdaService,+ SqsService sqsService,+ SnsService snsService,+ ObjectMapper objectMapper,+ EmulatorConfig config) {+ this(lambdaService, sqsService, snsService, null, objectMapper, config);+ }+public void invokeTarget(Target target, String eventJson, String region) {String arn = target.getArn();String payload;@@ -67,6 +82,21 @@ public class EventBridgeInvoker {String topicRegion = extractRegionFromArn(arn, region);snsService.publish(arn, null, payload, "EventBridge", topicRegion);LOG.debugv("EventBridge delivered to SNS: {0}", arn);+ } else if (arn.contains(":batch:") && arn.contains(":job-queue/")) {+ if (batchService == null || target.getBatchParameters() == null) {+ LOG.warnv("EventBridge Batch target missing Batch service or parameters: {0}", arn);+ return;+ }+ String targetRegion = extractRegionFromArn(arn, region);+ batchService.submitFromEventBridge(+ arn,+ target.getBatchParameters().getJobDefinition(),+ target.getBatchParameters().getJobName(),+ parametersFromBatchPayload(payload),+ target.getBatchParameters().getRetryStrategy(),+ targetRegion+ );+ LOG.debugv("EventBridge delivered to Batch: {0}", arn);} else {LOG.warnv("EventBridge: unsupported target ARN type: {0}", arn);}@@ -114,6 +144,26 @@ public class EventBridgeInvoker {}}+ private Map<String, String> parametersFromBatchPayload(String payload) {+ Map<String, String> parameters = new LinkedHashMap<>();+ if (payload == null || payload.isBlank()) {+ return parameters;+ }+ try {+ JsonNode node = objectMapper.readTree(payload);+ JsonNode parametersNode = node.path("Parameters");+ if (parametersNode.isObject()) {+ parametersNode.fields().forEachRemaining(entry -> {+ JsonNode value = entry.getValue();+ parameters.put(entry.getKey(), value.isTextual() ? value.asText() : value.toString());+ });+ }+ } catch (Exception e) {+ LOG.debugv("EventBridge Batch payload is not a JSON object with Parameters: {0}", e.getMessage());+ }+ return parameters;+ }+private static String extractRegionFromArn(String arn, String defaultRegion) {String[] parts = arn.split(":");return parts.length >= 4 && !parts[3].isEmpty() ? parts[3] : defaultRegion;diff --git a/src/main/java/io/github/hectorvent/floci/services/eventbridge/model/BatchParameters.java b/src/main/java/io/github/hectorvent/floci/services/eventbridge/model/BatchParameters.javanew file mode 100644index 0000000000..12616cda62--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/eventbridge/model/BatchParameters.java@@ -0,0 +1,73 @@+package io.github.hectorvent.floci.services.eventbridge.model;++import com.fasterxml.jackson.annotation.JsonIgnoreProperties;+import com.fasterxml.jackson.annotation.JsonInclude;+import com.fasterxml.jackson.annotation.JsonProperty;+import com.fasterxml.jackson.databind.JsonNode;+import com.fasterxml.jackson.databind.node.JsonNodeFactory;+import com.fasterxml.jackson.databind.node.ObjectNode;+import io.quarkus.runtime.annotations.RegisterForReflection;++import java.util.Map;++@RegisterForReflection+@JsonIgnoreProperties(ignoreUnknown = true)+@JsonInclude(JsonInclude.Include.NON_EMPTY)+public class BatchParameters {++ private String jobDefinition;+ private String jobName;+ private Map<String, Object> arrayProperties;+ private JsonNode retryStrategy;++ public BatchParameters() {+ }++ @JsonProperty("JobDefinition")+ public String getJobDefinition() {+ return jobDefinition;+ }++ @JsonProperty("JobDefinition")+ public void setJobDefinition(String jobDefinition) {+ this.jobDefinition = jobDefinition;+ }++ @JsonProperty("JobName")+ public String getJobName() {+ return jobName;+ }++ @JsonProperty("JobName")+ public void setJobName(String jobName) {+ this.jobName = jobName;+ }++ @JsonProperty("ArrayProperties")+ public Map<String, Object> getArrayProperties() {+ return arrayProperties;+ }++ @JsonProperty("ArrayProperties")+ public void setArrayProperties(Map<String, Object> arrayProperties) {+ this.arrayProperties = arrayProperties;+ }++ @JsonProperty("RetryStrategy")+ public JsonNode getRetryStrategy() {+ return retryStrategy;+ }++ @JsonProperty("RetryStrategy")+ public void setRetryStrategy(JsonNode retryStrategy) {+ if (retryStrategy == null || retryStrategy.isNull()) {+ this.retryStrategy = null;+ return;+ }+ ObjectNode allowed = JsonNodeFactory.instance.objectNode();+ if (retryStrategy.has("Attempts")) {+ allowed.set("Attempts", retryStrategy.get("Attempts"));+ }+ this.retryStrategy = allowed.isEmpty() ? null : allowed;+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/eventbridge/model/Target.java b/src/main/java/io/github/hectorvent/floci/services/eventbridge/model/Target.javaindex ef888d0084..bdccb79820 100644--- a/src/main/java/io/github/hectorvent/floci/services/eventbridge/model/Target.java+++ b/src/main/java/io/github/hectorvent/floci/services/eventbridge/model/Target.java@@ -13,6 +13,7 @@ public class Target {private String inputPath;private InputTransformer inputTransformer;private SqsParameters sqsParameters;+ private BatchParameters batchParameters;public Target() {}@@ -40,4 +41,7 @@ public class Target {public SqsParameters getSqsParameters() { return sqsParameters; }public void setSqsParameters(SqsParameters sqsParameters) { this.sqsParameters = sqsParameters; }++ public BatchParameters getBatchParameters() { return batchParameters; }+ public void setBatchParameters(BatchParameters batchParameters) { this.batchParameters = batchParameters; }}diff --git a/src/main/resources/application.yml b/src/main/resources/application.ymlindex db8e9436fc..619e0b027a 100644--- a/src/main/resources/application.yml+++ b/src/main/resources/application.yml@@ -83,6 +83,8 @@ floci:flush-interval-ms: 5000opensearch:flush-interval-ms: 5000+ batch:+ flush-interval-ms: 5000rds:# Override storage mode for RDS (memory = no Docker volumes; hybrid/persistent = named volume per instance)# mode: memory@@ -292,6 +294,10 @@ floci:codebuild:enabled: true# docker-network: floci-network+ batch:+ enabled: true+ runner-mode: immediate+ # docker-network: floci-networkcodedeploy:enabled: trueautoscaling:diff --git a/src/test/java/io/github/hectorvent/floci/services/batch/BatchDockerRunnerDockerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/batch/BatchDockerRunnerDockerIntegrationTest.javanew file mode 100644index 0000000000..57d6a529b4--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/batch/BatchDockerRunnerDockerIntegrationTest.java@@ -0,0 +1,75 @@+package io.github.hectorvent.floci.services.batch;++import com.github.dockerjava.api.DockerClient;+import io.github.hectorvent.floci.config.EmulatorConfig;+import io.github.hectorvent.floci.core.common.dns.EmbeddedDnsServer;+import io.github.hectorvent.floci.core.common.docker.ContainerDetector;+import io.github.hectorvent.floci.services.batch.model.BatchJob;+import io.github.hectorvent.floci.services.batch.model.BatchRunResult;+import io.quarkus.test.junit.QuarkusTest;+import jakarta.inject.Inject;+import org.junit.jupiter.api.Assumptions;+import org.junit.jupiter.api.BeforeEach;+import org.junit.jupiter.api.Test;++import java.util.List;++import static org.junit.jupiter.api.Assertions.assertEquals;++@QuarkusTest+class BatchDockerRunnerDockerIntegrationTest {++ private static final String IMAGE = "public.ecr.aws/docker/library/busybox:latest";++ @Inject+ BatchDockerRunner runner;++ @Inject+ DockerClient dockerClient;++ @Inject+ EmulatorConfig config;++ @Inject+ ContainerDetector containerDetector;++ @BeforeEach+ void requireDocker() {+ Assumptions.assumeTrue(isDockerAvailable(), "Docker daemon must be available for Batch Docker runner tests");+ }++ @Test+ void dockerRunnerInjectsContainerReachableEndpoint() {+ String suffix = Long.toString(System.nanoTime(), 36);+ String expectedHostname = containerDetector.isRunningInContainer()+ ? config.hostname().orElse(EmbeddedDnsServer.DEFAULT_SUFFIX)+ : "host.docker.internal";+ String expectedEndpoint = "http://" + expectedHostname + ":" + config.port();++ BatchJob job = new BatchJob();+ job.setJobId("docker-env-" + suffix);+ job.setJobName("docker-env-" + suffix);+ job.setJobDefinitionName("docker-env-test");+ job.setJobQueueName("docker-env-test-queue");+ job.setRegion(config.defaultRegion());+ job.setContainerImage(IMAGE);+ job.setResolvedCommand(List.of("sh", "-c", """+ test "$AWS_ENDPOINT_URL" = "%s" &&+ test "$FLOCI_ENDPOINT" = "%s" &&+ test "$FLOCI_HOSTNAME" = "%s"+ """.formatted(expectedEndpoint, expectedEndpoint, expectedHostname)));++ BatchRunResult result = runner.run(job, 1);++ assertEquals(0, result.exitCode(), result.reason());+ }++ private boolean isDockerAvailable() {+ try {+ dockerClient.pingCmd().exec();+ return true;+ } catch (Exception e) {+ return false;+ }+ }+}diff --git a/src/test/java/io/github/hectorvent/floci/services/batch/BatchDockerRunnerTest.java b/src/test/java/io/github/hectorvent/floci/services/batch/BatchDockerRunnerTest.javanew file mode 100644index 0000000000..d78644ab0a--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/batch/BatchDockerRunnerTest.java@@ -0,0 +1,57 @@+package io.github.hectorvent.floci.services.batch;++import io.github.hectorvent.floci.config.EmulatorConfig;+import io.github.hectorvent.floci.core.common.dns.EmbeddedDnsServer;+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.ContainerLogStreamer;+import org.junit.jupiter.api.Test;++import java.util.Optional;++import static org.junit.jupiter.api.Assertions.assertEquals;+import static org.mockito.Mockito.mock;+import static org.mockito.Mockito.when;++class BatchDockerRunnerTest {++ @Test+ void resolveEndpointHostnameUsesHostGatewayWhenFlociRunsNatively() {+ ContainerDetector detector = mock(ContainerDetector.class);+ when(detector.isRunningInContainer()).thenReturn(false);++ assertEquals("host.docker.internal", runner(config(Optional.empty()), detector).resolveEndpointHostname());+ }++ @Test+ void resolveEndpointHostnameUsesConfiguredHostnameWhenFlociRunsInContainer() {+ ContainerDetector detector = mock(ContainerDetector.class);+ when(detector.isRunningInContainer()).thenReturn(true);++ assertEquals("floci.internal", runner(config(Optional.of("floci.internal")), detector).resolveEndpointHostname());+ }++ @Test+ void resolveEndpointHostnameUsesEmbeddedDnsSuffixWhenContainerizedWithoutHostname() {+ ContainerDetector detector = mock(ContainerDetector.class);+ when(detector.isRunningInContainer()).thenReturn(true);++ assertEquals(EmbeddedDnsServer.DEFAULT_SUFFIX, runner(config(Optional.empty()), detector).resolveEndpointHostname());+ }++ private BatchDockerRunner runner(EmulatorConfig config, ContainerDetector detector) {+ return new BatchDockerRunner(+ mock(ContainerBuilder.class),+ mock(ContainerLifecycleManager.class),+ mock(ContainerLogStreamer.class),+ config,+ detector);+ }++ private EmulatorConfig config(Optional<String> hostname) {+ EmulatorConfig config = mock(EmulatorConfig.class);+ when(config.hostname()).thenReturn(hostname);+ return config;+ }+}diff --git a/src/test/java/io/github/hectorvent/floci/services/batch/BatchIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/batch/BatchIntegrationTest.javanew file mode 100644index 0000000000..57b37b2de6--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/batch/BatchIntegrationTest.java@@ -0,0 +1,539 @@+package io.github.hectorvent.floci.services.batch;++import io.quarkus.test.junit.QuarkusTest;+import org.junit.jupiter.api.Test;++import java.util.Map;++import static io.restassured.RestAssured.given;+import static org.hamcrest.Matchers.containsString;+import static org.hamcrest.Matchers.equalTo;+import static org.hamcrest.Matchers.greaterThan;+import static org.hamcrest.Matchers.hasSize;+import static org.hamcrest.Matchers.notNullValue;+import static org.hamcrest.Matchers.nullValue;++@QuarkusTest+class BatchIntegrationTest {++ private static final String AUTH =+ "AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/batch/aws4_request";++ @Test+ void submitDescribeAndListImmediateJob() {+ String suffix = uniqueSuffix();+ String queueArn = createQueue("batch-queue-" + suffix, createComputeEnvironment("batch-ce-" + suffix));+ String definitionArn = registerJobDefinition("batch-job-" + suffix,+ "[\"Ref::inputKey\",\"Ref::outputKey\",\"--literal\"]",+ "[{\"name\":\"MODE\",\"value\":\"definition\"}]");++ String jobId = givenJson("""+ {+ "jobName": "batch-submit-%s",+ "jobQueue": "%s",+ "jobDefinition": "%s",+ "parameters": {+ "inputKey": "payloads/input.json",+ "outputKey": "payloads/output.json"+ },+ "containerOverrides": {+ "environment": [{"name":"MODE","value":"override"}]+ },+ "timeout": {"attemptDurationSeconds": 60}+ }+ """.formatted(suffix, queueArn, definitionArn))+ .when()+ .post("/v1/submitjob")+ .then()+ .statusCode(200)+ .body("jobId", notNullValue())+ .body("jobArn", containsString(":batch:us-east-1:000000000000:job/"))+ .extract().path("jobId");++ givenJson("{\"jobs\":[\"%s\"]}".formatted(jobId))+ .when()+ .post("/v1/describejobs")+ .then()+ .statusCode(200)+ .body("jobs", hasSize(1))+ .body("jobs[0].status", equalTo("SUCCEEDED"))+ .body("jobs[0].jobQueue", equalTo(queueArn))+ .body("jobs[0].jobDefinition", equalTo(definitionArn))+ .body("jobs[0].container.command[0]", equalTo("payloads/input.json"))+ .body("jobs[0].container.command[1]", equalTo("payloads/output.json"))+ .body("jobs[0].container.command[2]", equalTo("--literal"))+ .body("jobs[0].container.environment.find { it.name == 'MODE' }.value", equalTo("override"))+ .body("jobs[0].attempts", hasSize(1))+ .body("jobs[0].attempts[0].container.exitCode", equalTo(0))+ .body("jobs[0].attempts[0].container.taskArn", nullValue());++ givenJson("{\"jobQueue\":\"%s\",\"jobStatus\":\"SUCCEEDED\"}".formatted(queueArn))+ .when()+ .post("/v1/listjobs")+ .then()+ .statusCode(200)+ .body("jobSummaryList", hasSize(greaterThan(0)))+ .body("jobSummaryList.find { it.jobId == '%s' }.status".formatted(jobId), equalTo("SUCCEEDED"))+ .body("jobSummaryList.find { it.jobId == '%s' }.jobQueue".formatted(jobId), nullValue())+ .body("jobSummaryList.find { it.jobId == '%s' }.container.exitCode".formatted(jobId), equalTo(0))+ .body("jobSummaryList.find { it.jobId == '%s' }.container.logStreamName".formatted(jobId), nullValue())+ .body("jobSummaryList.find { it.jobId == '%s' }.container.taskArn".formatted(jobId), nullValue());+ }++ @Test+ void jobDefinitionRevisionsAndDeregister() {+ String suffix = uniqueSuffix();+ String queueArn = createQueue("batch-rev-queue-" + suffix, createComputeEnvironment("batch-rev-ce-" + suffix));+ String jobName = "batch-rev-job-" + suffix;+ String revisionOne = registerJobDefinition(jobName, "[\"rev1\"]", "[]");+ String revisionTwo = registerJobDefinition(jobName, "[\"rev2\"]", "[]");++ givenJson("{\"jobDefinition\":\"%s\"}".formatted(jobName))+ .when()+ .post("/v1/deregisterjobdefinition")+ .then()+ .statusCode(400)+ .body("__type", equalTo("ClientException"));++ givenJson("{\"jobDefinition\":\"%s\"}".formatted(revisionTwo))+ .when()+ .post("/v1/deregisterjobdefinition")+ .then()+ .statusCode(200);++ givenJson("{\"jobDefinitionName\":\"%s\",\"status\":\"ACTIVE\"}".formatted(jobName))+ .when()+ .post("/v1/describejobdefinitions")+ .then()+ .statusCode(200)+ .body("jobDefinitions", hasSize(1))+ .body("jobDefinitions[0].jobDefinitionArn", equalTo(revisionOne))+ .body("jobDefinitions[0].revision", equalTo(1));++ String jobId = givenJson("""+ {"jobName":"latest-active-%s","jobQueue":"%s","jobDefinition":"%s"}+ """.formatted(suffix, queueArn, jobName))+ .when()+ .post("/v1/submitjob")+ .then()+ .statusCode(200)+ .extract().path("jobId");++ givenJson("{\"jobs\":[\"%s\"]}".formatted(jobId))+ .when()+ .post("/v1/describejobs")+ .then()+ .statusCode(200)+ .body("jobs[0].jobDefinition", equalTo(revisionOne))+ .body("jobs[0].container.command[0]", equalTo("rev1"));+ }++ @Test+ void submitResolvesJobDefinitionNameRevisionAndArns() {+ String suffix = uniqueSuffix();+ String queueArn = createQueue("batch-resolve-queue-" + suffix, createComputeEnvironment("batch-resolve-ce-" + suffix));+ String jobName = "batch-resolve-job-" + suffix;+ String revisionOne = registerJobDefinition(jobName, "[\"rev1\"]", "[]");+ String revisionTwo = registerJobDefinition(jobName, "[\"rev2\"]", "[]");+ String arnWithoutRevision = revisionTwo.substring(0, revisionTwo.lastIndexOf(':'));++ String byNameRevision = submit(queueArn, jobName + ":1", "batch-resolve-name-rev-" + suffix);+ String byFullArn = submit(queueArn, revisionTwo, "batch-resolve-full-arn-" + suffix);+ String byArnWithoutRevision = submit(queueArn, arnWithoutRevision, "batch-resolve-arn-latest-" + suffix);++ givenJson("{\"jobs\":[\"%s\",\"%s\",\"%s\"]}".formatted(byNameRevision, byFullArn, byArnWithoutRevision))+ .when()+ .post("/v1/describejobs")+ .then()+ .statusCode(200)+ .body("jobs.find { it.jobId == '%s' }.jobDefinition".formatted(byNameRevision), equalTo(revisionOne))+ .body("jobs.find { it.jobId == '%s' }.container.command[0]".formatted(byNameRevision), equalTo("rev1"))+ .body("jobs.find { it.jobId == '%s' }.jobDefinition".formatted(byFullArn), equalTo(revisionTwo))+ .body("jobs.find { it.jobId == '%s' }.container.command[0]".formatted(byFullArn), equalTo("rev2"))+ .body("jobs.find { it.jobId == '%s' }.jobDefinition".formatted(byArnWithoutRevision), equalTo(revisionTwo))+ .body("jobs.find { it.jobId == '%s' }.container.command[0]".formatted(byArnWithoutRevision), equalTo("rev2"));+ }++ @Test+ void listJobsPaginatesNewestFirst() throws Exception {+ String suffix = uniqueSuffix();+ String queueArn = createQueue("batch-page-queue-" + suffix, createComputeEnvironment("batch-page-ce-" + suffix));+ String definitionArn = registerJobDefinition("batch-page-job-" + suffix, "[\"ok\"]", "[]");+ String firstName = "batch-page-first-" + suffix;+ String secondName = "batch-page-second-" + suffix;++ submit(queueArn, definitionArn, firstName);+ Thread.sleep(5);+ submit(queueArn, definitionArn, secondName);++ String nextToken = givenJson("""+ {"jobQueue":"%s","jobStatus":"SUCCEEDED","maxResults":1}+ """.formatted(queueArn))+ .when()+ .post("/v1/listjobs")+ .then()+ .statusCode(200)+ .body("jobSummaryList", hasSize(1))+ .body("jobSummaryList[0].jobName", equalTo(secondName))+ .body("nextToken", equalTo("1"))+ .extract().path("nextToken");++ givenJson("""+ {"jobQueue":"%s","jobStatus":"SUCCEEDED","maxResults":1,"nextToken":"%s"}+ """.formatted(queueArn, nextToken))+ .when()+ .post("/v1/listjobs")+ .then()+ .statusCode(200)+ .body("jobSummaryList", hasSize(1))+ .body("jobSummaryList[0].jobName", equalTo(firstName));+ }++ @Test+ void listJobsUsesAwsFilters() throws Exception {+ String suffix = uniqueSuffix();+ String queueArn = createQueue("batch-dedupe-queue-" + suffix, createComputeEnvironment("batch-dedupe-ce-" + suffix));+ String definitionArn = registerJobDefinition("batch-dedupe-job-" + suffix, "[\"ok\"]", "[]");+ String prefix = "batch-dedupe-match-" + suffix;+ String oldName = prefix + "-old";+ String newName = prefix + "-new";++ submit(queueArn, definitionArn, oldName);+ Thread.sleep(5);+ long createdAfter = System.currentTimeMillis();+ Thread.sleep(5);+ submit(queueArn, definitionArn, newName);+ submit(queueArn, definitionArn, "batch-dedupe-other-" + suffix);++ givenJson("""+ {+ "jobQueue":"%s",+ "jobStatus":"RUNNING",+ "filters":[{"name":"JOB_NAME","values":["%s*"]}]+ }+ """.formatted(queueArn, prefix.toUpperCase()))+ .when()+ .post("/v1/listjobs")+ .then()+ .statusCode(200)+ .body("jobSummaryList", hasSize(2))+ .body("jobSummaryList.find { it.jobName == '%s' }.jobId".formatted(oldName), notNullValue())+ .body("jobSummaryList.find { it.jobName == '%s' }.jobId".formatted(newName), notNullValue());++ givenJson("""+ {+ "jobQueue":"%s",+ "jobStatus":"SUCCEEDED",+ "filters":[{"name":"AFTER_CREATED_AT","values":["%d"]}]+ }+ """.formatted(queueArn, createdAfter))+ .when()+ .post("/v1/listjobs")+ .then()+ .statusCode(200)+ .body("jobSummaryList", hasSize(2))+ .body("jobSummaryList.find { it.jobName == '%s' }.jobId".formatted(newName), notNullValue())+ .body("jobSummaryList.find { it.jobName == 'batch-dedupe-other-%s' }.jobId".formatted(suffix), notNullValue());++ givenJson("""+ {+ "jobQueue":"%s",+ "filters":[+ {"name":"JOB_NAME","values":["%s*"]},+ {"name":"AFTER_CREATED_AT","values":["%d"]}+ ]+ }+ """.formatted(queueArn, prefix, createdAfter))+ .when()+ .post("/v1/listjobs")+ .then()+ .statusCode(400)+ .body("__type", equalTo("ClientException"));+ }++ @Test+ void describeControlPlaneResourcesPaginateAndValidateJobDefinitionFilters() {+ String suffix = uniqueSuffix();+ String firstCompute = createComputeEnvironment("batch-desc-ce-a-" + suffix);+ String secondCompute = createComputeEnvironment("batch-desc-ce-b-" + suffix);+ createQueue("batch-desc-queue-a-" + suffix, firstCompute);+ createQueue("batch-desc-queue-b-" + suffix, secondCompute);+ String definitionOne = registerJobDefinition("batch-desc-job-a-" + suffix, "[\"a\"]", "[]");+ String definitionTwo = registerJobDefinition("batch-desc-job-b-" + suffix, "[\"b\"]", "[]");++ givenJson("{\"computeEnvironments\":[\"%s\",\"%s\"],\"maxResults\":1}".formatted(firstCompute, secondCompute))+ .when()+ .post("/v1/describecomputeenvironments")+ .then()+ .statusCode(200)+ .body("computeEnvironments", hasSize(1))+ .body("computeEnvironments[0].createdAt", nullValue())+ .body("computeEnvironments[0].region", nullValue())+ .body("computeEnvironments[0].accountId", nullValue())+ .body("nextToken", equalTo("1"));++ givenJson("{\"jobQueues\":[\"batch-desc-queue-a-%s\"],\"maxResults\":1}".formatted(suffix))+ .when()+ .post("/v1/describejobqueues")+ .then()+ .statusCode(200)+ .body("jobQueues", hasSize(1))+ .body("jobQueues[0].createdAt", nullValue())+ .body("jobQueues[0].region", nullValue())+ .body("jobQueues[0].accountId", nullValue());++ givenJson("""+ {"jobDefinitions":["%s","%s"],"maxResults":1}+ """.formatted(definitionOne, definitionTwo))+ .when()+ .post("/v1/describejobdefinitions")+ .then()+ .statusCode(200)+ .body("jobDefinitions", hasSize(1))+ .body("jobDefinitions[0].createdAt", nullValue())+ .body("jobDefinitions[0].region", nullValue())+ .body("jobDefinitions[0].accountId", nullValue())+ .body("jobDefinitions[0].containerProperties.jobRoleArn", nullValue())+ .body("jobDefinitions[0].retryStrategy.evaluateOnExit", nullValue())+ .body("nextToken", equalTo("1"));++ givenJson("""+ {"jobDefinitions":["%s"],"status":"ACTIVE"}+ """.formatted(definitionOne))+ .when()+ .post("/v1/describejobdefinitions")+ .then()+ .statusCode(400)+ .body("__type", equalTo("ClientException"));+ }++ @Test+ void validationErrorsUseClientException() {+ String suffix = uniqueSuffix();+ String queueArn = createQueue("batch-error-queue-" + suffix, createComputeEnvironment("batch-error-ce-" + suffix));+ String definitionArn = registerJobDefinition("batch-error-job-" + suffix, "[\"ok\"]", "[]");++ givenJson("{}")+ .when()+ .post("/v1/listjobs")+ .then()+ .statusCode(400)+ .body("__type", equalTo("ClientException"));++ givenJson("""+ {"jobName":"missing-queue-%s","jobQueue":"missing","jobDefinition":"%s"}+ """.formatted(suffix, definitionArn))+ .when()+ .post("/v1/submitjob")+ .then()+ .statusCode(400)+ .body("__type", equalTo("ClientException"));++ givenJson("""+ {+ "jobName":"bad-env-%s",+ "jobQueue":"%s",+ "jobDefinition":"%s",+ "containerOverrides": {+ "environment": [{"name":"AWS_BATCH_BAD","value":"nope"}]+ }+ }+ """.formatted(suffix, queueArn, definitionArn))+ .when()+ .post("/v1/submitjob")+ .then()+ .statusCode(400)+ .body("__type", equalTo("ClientException"));++ givenJson("""+ {+ "jobDefinitionName": "bad-retry-%s",+ "type": "container",+ "containerProperties": {"image":"public.ecr.aws/example/job:latest"},+ "retryStrategy": {"attempts": 11}+ }+ """.formatted(suffix))+ .when()+ .post("/v1/registerjobdefinition")+ .then()+ .statusCode(400)+ .body("__type", equalTo("ClientException"));++ givenJson("""+ {+ "jobDefinitionName": "bad-timeout-%s",+ "type": "container",+ "containerProperties": {"image":"public.ecr.aws/example/job:latest"},+ "timeout": {"attemptDurationSeconds": 59}+ }+ """.formatted(suffix))+ .when()+ .post("/v1/registerjobdefinition")+ .then()+ .statusCode(400)+ .body("__type", equalTo("ClientException"));++ givenJson("""+ {+ "jobDefinitionName": "bad-type-%s",+ "type": "multinode"+ }+ """.formatted(suffix))+ .when()+ .post("/v1/registerjobdefinition")+ .then()+ .statusCode(400)+ .body("__type", equalTo("ClientException"));++ givenJson("""+ {+ "computeEnvironmentName": "bad-ce-missing-type-%s"+ }+ """.formatted(suffix))+ .when()+ .post("/v1/createcomputeenvironment")+ .then()+ .statusCode(400)+ .body("__type", equalTo("ClientException"));++ givenJson("""+ {+ "jobDefinitionName": "bad-missing-container-%s",+ "type": "container"+ }+ """.formatted(suffix))+ .when()+ .post("/v1/registerjobdefinition")+ .then()+ .statusCode(400)+ .body("__type", equalTo("ClientException"));++ givenJson("""+ {+ "jobDefinitionName": "bad-register-env-%s",+ "type": "container",+ "containerProperties": {+ "environment": [{"name":"AWS_BATCH_BAD","value":"nope"}]+ }+ }+ """.formatted(suffix))+ .when()+ .post("/v1/registerjobdefinition")+ .then()+ .statusCode(400)+ .body("__type", equalTo("ClientException"));++ givenJson("""+ {"jobName":"bad/name-%s","jobQueue":"%s","jobDefinition":"%s"}+ """.formatted(suffix, queueArn, definitionArn))+ .when()+ .post("/v1/submitjob")+ .then()+ .statusCode(400)+ .body("__type", equalTo("ClientException"));++ givenJson("{\"jobDefinition\":\"batch-error-job-%s\"}".formatted(suffix))+ .when()+ .post("/v1/deregisterjobdefinition")+ .then()+ .statusCode(400)+ .body("__type", equalTo("ClientException"));++ givenJson("{\"jobDefinitions\":[\"%s\"],\"nextToken\":\"not-a-number\"}".formatted(definitionArn))+ .when()+ .post("/v1/describejobdefinitions")+ .then()+ .statusCode(400)+ .body("__type", equalTo("ClientException"));+ }++ @Test+ void describeUnknownJobsReturnsEmptyList() {+ givenJson("{\"jobs\":[\"does-not-exist\"]}")+ .when()+ .post("/v1/describejobs")+ .then()+ .statusCode(200)+ .body("jobs", hasSize(0));+ }++ private static io.restassured.specification.RequestSpecification givenJson(String body) {+ return given()+ .header("Authorization", AUTH)+ .contentType("application/json")+ .body(body);+ }++ private String createComputeEnvironment(String name) {+ return givenJson("""+ {+ "computeEnvironmentName": "%s",+ "type": "MANAGED",+ "computeResources": {"type":"FARGATE","maxvCpus":4}+ }+ """.formatted(name))+ .when()+ .post("/v1/createcomputeenvironment")+ .then()+ .statusCode(200)+ .extract().path("computeEnvironmentArn");+ }++ private String createQueue(String name, String computeEnvironmentArn) {+ return givenJson("""+ {+ "jobQueueName": "%s",+ "priority": 1,+ "computeEnvironmentOrder": [{+ "order": 1,+ "computeEnvironment": "%s"+ }]+ }+ """.formatted(name, computeEnvironmentArn))+ .when()+ .post("/v1/createjobqueue")+ .then()+ .statusCode(200)+ .extract().path("jobQueueArn");+ }++ private String registerJobDefinition(String name, String commandJson, String environmentJson) {+ return givenJson("""+ {+ "jobDefinitionName": "%s",+ "type": "container",+ "platformCapabilities": ["FARGATE"],+ "containerProperties": {+ "image": "public.ecr.aws/example/job:latest",+ "command": %s,+ "environment": %s,+ "resourceRequirements": [+ {"type":"VCPU","value":"1"},+ {"type":"MEMORY","value":"512"}+ ]+ },+ "retryStrategy": {"attempts": 2}+ }+ """.formatted(name, commandJson, environmentJson))+ .when()+ .post("/v1/registerjobdefinition")+ .then()+ .statusCode(200)+ .extract().path("jobDefinitionArn");+ }++ private String submit(String queueArn, String definitionArn, String jobName) {+ return givenJson("""+ {"jobName":"%s","jobQueue":"%s","jobDefinition":"%s"}+ """.formatted(jobName, queueArn, definitionArn))+ .when()+ .post("/v1/submitjob")+ .then()+ .statusCode(200)+ .extract().path("jobId");+ }++ private static String uniqueSuffix() {+ return Long.toString(System.nanoTime(), 36);+ }+}diff --git a/src/test/java/io/github/hectorvent/floci/services/batch/BatchServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/batch/BatchServiceTest.javanew file mode 100644index 0000000000..40f973c383--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/batch/BatchServiceTest.java@@ -0,0 +1,313 @@+package io.github.hectorvent.floci.services.batch;++import com.fasterxml.jackson.databind.JsonNode;+import com.fasterxml.jackson.databind.ObjectMapper;+import com.fasterxml.jackson.databind.node.ObjectNode;+import io.github.hectorvent.floci.config.EmulatorConfig;+import io.github.hectorvent.floci.core.common.RegionResolver;+import io.github.hectorvent.floci.core.storage.InMemoryStorage;+import io.github.hectorvent.floci.core.storage.StorageBackend;+import io.github.hectorvent.floci.services.batch.model.BatchComputeEnvironment;+import io.github.hectorvent.floci.services.batch.model.BatchJob;+import io.github.hectorvent.floci.services.batch.model.BatchJobDefinition;+import io.github.hectorvent.floci.services.batch.model.BatchJobQueue;+import io.github.hectorvent.floci.services.batch.model.BatchRunResult;+import org.junit.jupiter.api.Test;++import java.util.ArrayList;+import java.util.Collections;+import java.util.LinkedHashMap;+import java.util.List;+import java.util.Optional;+import java.util.Set;+import java.util.function.Predicate;++import static org.junit.jupiter.api.Assertions.assertEquals;+import static org.junit.jupiter.api.Assertions.assertNotNull;+import static org.mockito.ArgumentMatchers.any;+import static org.mockito.ArgumentMatchers.anyInt;+import static org.mockito.Mockito.mock;+import static org.mockito.Mockito.times;+import static org.mockito.Mockito.verify;+import static org.mockito.Mockito.when;++class BatchServiceTest {++ private static final String REGION = "us-east-1";+ private static final String ACCOUNT = "000000000000";++ private final ObjectMapper objectMapper = new ObjectMapper();++ @Test+ void dockerTimeoutFailsWithoutRetryingRemainingAttempts() throws Exception {+ BatchDockerRunner runner = mock(BatchDockerRunner.class);+ when(runner.run(any(BatchJob.class), anyInt()))+ .thenReturn(new BatchRunResult(137, "Job timed out", "log-stream", 1L, 2L, true));+ BatchService service = dockerService(runner);++ String computeArn = service.createComputeEnvironment(json("""+ {"computeEnvironmentName":"timeout-ce","type":"MANAGED"}+ """), REGION).path("computeEnvironmentArn").asText();+ String queueArn = service.createJobQueue(json("""+ {+ "jobQueueName":"timeout-queue",+ "priority":1,+ "computeEnvironmentOrder":[{"order":1,"computeEnvironment":"%s"}]+ }+ """.formatted(computeArn)), REGION).path("jobQueueArn").asText();+ String definitionArn = service.registerJobDefinition(json("""+ {+ "jobDefinitionName":"timeout-job",+ "type":"container",+ "containerProperties":{"image":"public.ecr.aws/example/job:latest"},+ "retryStrategy":{"attempts":3}+ }+ """), REGION).path("jobDefinitionArn").asText();++ String jobId = service.submitJob(json("""+ {+ "jobName":"timeout-submit",+ "jobQueue":"%s",+ "jobDefinition":"%s",+ "timeout":{"attemptDurationSeconds":60}+ }+ """.formatted(queueArn, definitionArn)), REGION).path("jobId").asText();++ JsonNode job = waitForJobStatus(service, jobId, "FAILED");+ assertNotNull(job);+ assertEquals("Job timed out", job.path("statusReason").asText());+ assertEquals(1, job.path("attempts").size());+ verify(runner, times(1)).run(any(BatchJob.class), anyInt());+ }++ @Test+ void dockerRetriesFailedAttemptAndCanSucceed() throws Exception {+ BatchDockerRunner runner = mock(BatchDockerRunner.class);+ when(runner.run(any(BatchJob.class), anyInt()))+ .thenReturn(new BatchRunResult(1, "first failed", "log-1", 1L, 2L, false))+ .thenReturn(new BatchRunResult(0, null, "log-2", 3L, 4L, false));+ BatchService service = dockerService(runner);++ String computeArn = service.createComputeEnvironment(json("""+ {"computeEnvironmentName":"retry-ce","type":"MANAGED"}+ """), REGION).path("computeEnvironmentArn").asText();+ String queueArn = service.createJobQueue(json("""+ {+ "jobQueueName":"retry-queue",+ "priority":1,+ "computeEnvironmentOrder":[{"order":1,"computeEnvironment":"%s"}]+ }+ """.formatted(computeArn)), REGION).path("jobQueueArn").asText();+ String definitionArn = service.registerJobDefinition(json("""+ {+ "jobDefinitionName":"retry-job",+ "type":"container",+ "containerProperties":{"image":"public.ecr.aws/example/job:latest"},+ "retryStrategy":{"attempts":2}+ }+ """), REGION).path("jobDefinitionArn").asText();++ String jobId = service.submitJob(json("""+ {"jobName":"retry-submit","jobQueue":"%s","jobDefinition":"%s"}+ """.formatted(queueArn, definitionArn)), REGION).path("jobId").asText();++ JsonNode job = waitForJobStatus(service, jobId, "SUCCEEDED");+ assertNotNull(job);+ assertEquals(2, job.path("attempts").size());+ assertEquals(0, job.path("attempts").get(1).path("container").path("exitCode").asInt());+ verify(runner, times(2)).run(any(BatchJob.class), anyInt());+ }++ @Test+ void dockerRetryExhaustionFailsJobAndKeepsAttempts() throws Exception {+ BatchDockerRunner runner = mock(BatchDockerRunner.class);+ when(runner.run(any(BatchJob.class), anyInt()))+ .thenReturn(new BatchRunResult(1, "failed once", "log-1", 1L, 2L, false))+ .thenReturn(new BatchRunResult(2, "failed twice", "log-2", 3L, 4L, false));+ BatchService service = dockerService(runner);++ String computeArn = service.createComputeEnvironment(json("""+ {"computeEnvironmentName":"exhaust-ce","type":"MANAGED"}+ """), REGION).path("computeEnvironmentArn").asText();+ String queueArn = service.createJobQueue(json("""+ {+ "jobQueueName":"exhaust-queue",+ "priority":1,+ "computeEnvironmentOrder":[{"order":1,"computeEnvironment":"%s"}]+ }+ """.formatted(computeArn)), REGION).path("jobQueueArn").asText();+ String definitionArn = service.registerJobDefinition(json("""+ {+ "jobDefinitionName":"exhaust-job",+ "type":"container",+ "containerProperties":{"image":"public.ecr.aws/example/job:latest"},+ "retryStrategy":{"attempts":2}+ }+ """), REGION).path("jobDefinitionArn").asText();++ String jobId = service.submitJob(json("""+ {"jobName":"exhaust-submit","jobQueue":"%s","jobDefinition":"%s"}+ """.formatted(queueArn, definitionArn)), REGION).path("jobId").asText();++ JsonNode job = waitForJobStatus(service, jobId, "FAILED");+ assertNotNull(job);+ assertEquals("failed twice", job.path("statusReason").asText());+ assertEquals(2, job.path("attempts").size());+ assertEquals(2, job.path("attempts").get(1).path("container").path("exitCode").asInt());+ verify(runner, times(2)).run(any(BatchJob.class), anyInt());+ }++ @Test+ void listJobsUsesStableJobIdTiebreakerForSameCreatedAt() throws Exception {+ ReverseScanJobStorage jobStore = new ReverseScanJobStorage();+ BatchService service = immediateService(jobStore);++ String computeArn = service.createComputeEnvironment(json("""+ {"computeEnvironmentName":"page-tie-ce","type":"MANAGED"}+ """), REGION).path("computeEnvironmentArn").asText();+ String queueArn = service.createJobQueue(json("""+ {+ "jobQueueName":"page-tie-queue",+ "priority":1,+ "computeEnvironmentOrder":[{"order":1,"computeEnvironment":"%s"}]+ }+ """.formatted(computeArn)), REGION).path("jobQueueArn").asText();+ String definitionArn = service.registerJobDefinition(json("""+ {+ "jobDefinitionName":"page-tie-job",+ "type":"container",+ "containerProperties":{"image":"public.ecr.aws/example/job:latest"}+ }+ """), REGION).path("jobDefinitionArn").asText();++ service.submitJob(json("""+ {"jobName":"page-tie-first","jobQueue":"%s","jobDefinition":"%s"}+ """.formatted(queueArn, definitionArn)), REGION);+ service.submitJob(json("""+ {"jobName":"page-tie-second","jobQueue":"%s","jobDefinition":"%s"}+ """.formatted(queueArn, definitionArn)), REGION);++ List<BatchJob> jobs = jobStore.scan(k -> true);+ assertEquals(2, jobs.size());+ BatchJob secondInserted = jobs.get(0);+ BatchJob firstInserted = jobs.get(1);+ secondInserted.setCreatedAt(123L);+ secondInserted.setJobId("b-job");+ firstInserted.setCreatedAt(123L);+ firstInserted.setJobId("a-job");++ JsonNode firstPage = service.listJobs(json("""+ {"jobQueue":"%s","jobStatus":"SUCCEEDED","maxResults":1}+ """.formatted(queueArn)));+ assertEquals("a-job", firstPage.path("jobSummaryList").get(0).path("jobId").asText());++ JsonNode secondPage = service.listJobs(json("""+ {"jobQueue":"%s","jobStatus":"SUCCEEDED","maxResults":1,"nextToken":"%s"}+ """.formatted(queueArn, firstPage.path("nextToken").asText())));+ assertEquals("b-job", secondPage.path("jobSummaryList").get(0).path("jobId").asText());+ }++ private BatchService dockerService(BatchDockerRunner runner) {+ EmulatorConfig config = mock(EmulatorConfig.class);+ EmulatorConfig.ServicesConfig services = mock(EmulatorConfig.ServicesConfig.class);+ EmulatorConfig.BatchServiceConfig batch = mock(EmulatorConfig.BatchServiceConfig.class);+ when(config.services()).thenReturn(services);+ when(services.batch()).thenReturn(batch);+ when(batch.runnerMode()).thenReturn("docker");++ return new BatchService(+ new InMemoryStorage<String, BatchJobDefinition>(),+ new InMemoryStorage<String, BatchJobQueue>(),+ new InMemoryStorage<String, BatchComputeEnvironment>(),+ new InMemoryStorage<String, BatchJob>(),+ new RegionResolver(REGION, ACCOUNT),+ config,+ objectMapper,+ runner);+ }++ private BatchService immediateService(StorageBackend<String, BatchJob> jobStore) {+ EmulatorConfig config = mock(EmulatorConfig.class);+ EmulatorConfig.ServicesConfig services = mock(EmulatorConfig.ServicesConfig.class);+ EmulatorConfig.BatchServiceConfig batch = mock(EmulatorConfig.BatchServiceConfig.class);+ when(config.services()).thenReturn(services);+ when(services.batch()).thenReturn(batch);+ when(batch.runnerMode()).thenReturn("immediate");++ return new BatchService(+ new InMemoryStorage<String, BatchJobDefinition>(),+ new InMemoryStorage<String, BatchJobQueue>(),+ new InMemoryStorage<String, BatchComputeEnvironment>(),+ jobStore,+ new RegionResolver(REGION, ACCOUNT),+ config,+ objectMapper,+ mock(BatchDockerRunner.class));+ }++ private ObjectNode json(String body) throws Exception {+ return (ObjectNode) objectMapper.readTree(body);+ }++ private JsonNode waitForJobStatus(BatchService service, String jobId, String status) throws Exception {+ ObjectNode request = objectMapper.createObjectNode();+ request.putArray("jobs").add(jobId);+ for (int i = 0; i < 100; i++) {+ JsonNode job = service.describeJobs(request).path("jobs").get(0);+ if (job != null && status.equals(job.path("status").asText())) {+ return job;+ }+ Thread.sleep(10);+ }+ return null;+ }++ private static final class ReverseScanJobStorage implements StorageBackend<String, BatchJob> {+ private final LinkedHashMap<String, BatchJob> store = new LinkedHashMap<>();++ @Override+ public void put(String key, BatchJob value) {+ store.put(key, value);+ }++ @Override+ public Optional<BatchJob> get(String key) {+ return Optional.ofNullable(store.get(key));+ }++ @Override+ public void delete(String key) {+ store.remove(key);+ }++ @Override+ public List<BatchJob> scan(Predicate<String> keyFilter) {+ List<BatchJob> values = new ArrayList<>();+ store.forEach((key, value) -> {+ if (keyFilter.test(key)) {+ values.add(value);+ }+ });+ Collections.reverse(values);+ return values;+ }++ @Override+ public Set<String> keys() {+ return Set.copyOf(store.keySet());+ }++ @Override+ public void flush() {+ }++ @Override+ public void load() {+ }++ @Override+ public void clear() {+ store.clear();+ }+ }+}diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationBatchIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationBatchIntegrationTest.javanew file mode 100644index 0000000000..a5e0444d95--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationBatchIntegrationTest.java@@ -0,0 +1,199 @@+package io.github.hectorvent.floci.services.cloudformation;++import io.quarkus.test.junit.QuarkusTest;+import org.junit.jupiter.api.Test;++import static io.restassured.RestAssured.given;+import static org.hamcrest.Matchers.containsString;+import static org.hamcrest.Matchers.equalTo;+import static org.hamcrest.Matchers.hasSize;+import static org.hamcrest.Matchers.notNullValue;++@QuarkusTest+class CloudFormationBatchIntegrationTest {++ private static final String BATCH_AUTH =+ "AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/batch/aws4_request";++ @Test+ void createStackWithBatchResourcesRegistersUsableQueueAndDefinition() {+ String suffix = Long.toString(System.nanoTime(), 36);+ String computeName = "cfn-batch-ce-" + suffix;+ String queueName = "cfn-batch-queue-" + suffix;+ String definitionName = "cfn-batch-job-" + suffix;+ String stackName = "cfn-batch-stack-" + suffix;++ String template = """+ {+ "Resources": {+ "Compute": {+ "Type": "AWS::Batch::ComputeEnvironment",+ "Properties": {+ "ComputeEnvironmentName": "%s",+ "Type": "MANAGED",+ "ComputeResources": {+ "Type": "FARGATE",+ "MaxvCpus": 4,+ "Subnets": ["subnet-local"],+ "SecurityGroupIds": ["sg-local"]+ }+ }+ },+ "Queue": {+ "Type": "AWS::Batch::JobQueue",+ "Properties": {+ "JobQueueName": "%s",+ "Priority": 1,+ "ComputeEnvironmentOrder": [{+ "Order": 1,+ "ComputeEnvironment": {"Ref": "Compute"}+ }]+ }+ },+ "Definition": {+ "Type": "AWS::Batch::JobDefinition",+ "Properties": {+ "JobDefinitionName": "%s",+ "Type": "container",+ "PlatformCapabilities": ["FARGATE"],+ "ContainerProperties": {+ "Image": "public.ecr.aws/example/job:latest",+ "Command": ["Ref::inputKey"],+ "Environment": [{"Name":"FROM_CFN","Value":"yes"}],+ "ResourceRequirements": [+ {"Type":"VCPU","Value":"1"},+ {"Type":"MEMORY","Value":"512"}+ ]+ }+ }+ }+ },+ "Outputs": {+ "ComputeArn": {"Value": {"Fn::GetAtt": ["Compute", "ComputeEnvironmentArn"]}},+ "QueueArn": {"Value": {"Fn::GetAtt": ["Queue", "JobQueueArn"]}},+ "DefinitionArn": {"Value": {"Fn::GetAtt": ["Definition", "JobDefinitionArn"]}}+ }+ }+ """.formatted(computeName, queueName, definitionName);++ given()+ .contentType("application/x-www-form-urlencoded")+ .formParam("Action", "CreateStack")+ .formParam("StackName", stackName)+ .formParam("TemplateBody", template)+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body(containsString("<StackId>"));++ given()+ .contentType("application/x-www-form-urlencoded")+ .formParam("Action", "DescribeStacks")+ .formParam("StackName", stackName)+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body(containsString("compute-environment/" + computeName))+ .body(containsString("job-queue/" + queueName))+ .body(containsString("job-definition/" + definitionName + ":1"));++ givenBatchJson("{\"jobQueues\":[\"%s\"]}".formatted(queueName))+ .when()+ .post("/v1/describejobqueues")+ .then()+ .statusCode(200)+ .body("jobQueues", hasSize(1))+ .body("jobQueues[0].jobQueueName", equalTo(queueName));++ String jobId = givenBatchJson("""+ {+ "jobName": "cfn-batch-submit-%s",+ "jobQueue": "%s",+ "jobDefinition": "%s",+ "parameters": {"inputKey":"from-cfn.json"}+ }+ """.formatted(suffix, queueName, definitionName))+ .when()+ .post("/v1/submitjob")+ .then()+ .statusCode(200)+ .body("jobId", notNullValue())+ .extract().path("jobId");++ givenBatchJson("{\"jobs\":[\"%s\"]}".formatted(jobId))+ .when()+ .post("/v1/describejobs")+ .then()+ .statusCode(200)+ .body("jobs[0].status", equalTo("SUCCEEDED"))+ .body("jobs[0].container.command[0]", equalTo("from-cfn.json"))+ .body("jobs[0].container.environment.find { it.name == 'FROM_CFN' }.value", equalTo("yes"));+ }++ @Test+ void createStackWithBatchArrayTargetPreservesMetadataWithoutArrayFanout() {+ String suffix = Long.toString(System.nanoTime(), 36);+ String stackName = "cfn-batch-array-target-" + suffix;+ String template = """+ {+ "Resources": {+ "Rule": {+ "Type": "AWS::Events::Rule",+ "Properties": {+ "Name": "%s",+ "EventPattern": {"source": ["local.test"]},+ "Targets": [{+ "Id": "batch-target",+ "Arn": "arn:aws:batch:us-east-1:000000000000:job-queue/local",+ "BatchParameters": {+ "JobDefinition": "local-job",+ "JobName": "array-job",+ "ArrayProperties": {"Size": 2}+ }+ }]+ }+ }+ }+ }+ """.formatted("cfn-batch-array-rule-" + suffix);++ given()+ .contentType("application/x-www-form-urlencoded")+ .formParam("Action", "CreateStack")+ .formParam("StackName", stackName)+ .formParam("TemplateBody", template)+ .when()+ .post("/")+ .then()+ .statusCode(200);++ given()+ .contentType("application/x-www-form-urlencoded")+ .formParam("Action", "DescribeStacks")+ .formParam("StackName", stackName)+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"));++ given()+ .contentType("application/x-www-form-urlencoded")+ .formParam("Action", "DescribeStackResources")+ .formParam("StackName", stackName)+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body(containsString("CREATE_COMPLETE"));+ }++ private static io.restassured.specification.RequestSpecification givenBatchJson(String body) {+ return given()+ .header("Authorization", BATCH_AUTH)+ .contentType("application/json")+ .body(body);+ }+}diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CustomResourceProvisionerTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CustomResourceProvisionerTest.javaindex 53148eb96e..37fb5c85e9 100644--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CustomResourceProvisionerTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CustomResourceProvisionerTest.java@@ -48,7 +48,7 @@ class CustomResourceProvisionerTest {provisioner = new CloudFormationResourceProvisioner(null, null, null, null, lambdaService, null, null, null, null, null,- null, null, null, null, null, null, mapper, store, endpoint, null, null, null);+ null, null, null, null, null, null, mapper, store, endpoint, null, null, null, null);}private CloudFormationTemplateEngine engine() {diff --git a/src/test/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeBatchIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeBatchIntegrationTest.javanew file mode 100644index 0000000000..397d61ad9b--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeBatchIntegrationTest.java@@ -0,0 +1,171 @@+package io.github.hectorvent.floci.services.eventbridge;++import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;+import io.quarkus.test.junit.QuarkusTest;+import org.junit.jupiter.api.BeforeAll;+import org.junit.jupiter.api.Test;++import static io.restassured.RestAssured.given;+import static org.hamcrest.Matchers.equalTo;+import static org.hamcrest.Matchers.notNullValue;+import static org.hamcrest.Matchers.nullValue;++@QuarkusTest+class EventBridgeBatchIntegrationTest {++ private static final String EVENT_BRIDGE_CONTENT_TYPE = "application/x-amz-json-1.1";+ private static final String BATCH_AUTH =+ "AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/batch/aws4_request";++ @BeforeAll+ static void configureRestAssured() {+ RestAssuredJsonUtils.configureAwsContentTypes();+ }++ @Test+ void putEventsBatchTargetSubmitsVisibleBatchJob() {+ String suffix = Long.toString(System.nanoTime(), 36);+ String computeArn = createComputeEnvironment("eb-batch-ce-" + suffix);+ String queueArn = createQueue("eb-batch-queue-" + suffix, computeArn);+ String definitionArn = registerJobDefinition("eb-batch-job-" + suffix);+ String ruleName = "eb-batch-rule-" + suffix;+ String submittedJobName = "eb-batch-submitted-" + suffix;++ given()+ .contentType(EVENT_BRIDGE_CONTENT_TYPE)+ .header("X-Amz-Target", "AWSEvents.PutRule")+ .body("""+ {"Name":"%s","EventPattern":"{\\"source\\":[\\"local.batch\\"]}"}+ """.formatted(ruleName))+ .when()+ .post("/")+ .then()+ .statusCode(200);++ given()+ .contentType(EVENT_BRIDGE_CONTENT_TYPE)+ .header("X-Amz-Target", "AWSEvents.PutTargets")+ .body("""+ {+ "Rule": "%s",+ "Targets": [{+ "Id": "batch",+ "Arn": "%s",+ "Input": "{\\"Parameters\\":{\\"inputKey\\":\\"from-event.json\\"}}",+ "BatchParameters": {+ "JobDefinition": "%s",+ "JobName": "%s",+ "ArrayProperties": {"Size": 2},+ "RetryStrategy": {"Attempts": 2, "EvaluateOnExit": [{"Action": "EXIT"}]}+ }+ }]+ }+ """.formatted(ruleName, queueArn, definitionArn, submittedJobName))+ .when()+ .post("/")+ .then()+ .statusCode(200);++ given()+ .contentType(EVENT_BRIDGE_CONTENT_TYPE)+ .header("X-Amz-Target", "AWSEvents.ListTargetsByRule")+ .body("""+ {"Rule": "%s"}+ """.formatted(ruleName))+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body("Targets[0].BatchParameters.ArrayProperties.Size", equalTo(2))+ .body("Targets[0].BatchParameters.RetryStrategy.Attempts", equalTo(2))+ .body("Targets[0].BatchParameters.RetryStrategy.EvaluateOnExit", nullValue());++ given()+ .contentType(EVENT_BRIDGE_CONTENT_TYPE)+ .header("X-Amz-Target", "AWSEvents.PutEvents")+ .body("""+ {+ "Entries": [{+ "Source": "local.batch",+ "DetailType": "BatchRequested",+ "Detail": "{}"+ }]+ }+ """)+ .when()+ .post("/")+ .then()+ .statusCode(200);++ String jobId = givenBatchJson("""+ {"jobQueue":"%s","jobStatus":"SUCCEEDED"}+ """.formatted(queueArn))+ .when()+ .post("/v1/listjobs")+ .then()+ .statusCode(200)+ .body("jobSummaryList.find { it.jobName == '%s' }.jobId".formatted(submittedJobName), notNullValue())+ .extract().path("jobSummaryList.find { it.jobName == '%s' }.jobId".formatted(submittedJobName));++ givenBatchJson("{\"jobs\":[\"%s\"]}".formatted(jobId))+ .when()+ .post("/v1/describejobs")+ .then()+ .statusCode(200)+ .body("jobs[0].jobName", equalTo(submittedJobName))+ .body("jobs[0].retryStrategy.attempts", equalTo(2))+ .body("jobs[0].retryStrategy.evaluateOnExit", nullValue())+ .body("jobs[0].container.command[0]", equalTo("from-event.json"));+ }++ private String createComputeEnvironment(String name) {+ return givenBatchJson("""+ {"computeEnvironmentName":"%s","type":"MANAGED"}+ """.formatted(name))+ .when()+ .post("/v1/createcomputeenvironment")+ .then()+ .statusCode(200)+ .extract().path("computeEnvironmentArn");+ }++ private String createQueue(String name, String computeEnvironmentArn) {+ return givenBatchJson("""+ {+ "jobQueueName":"%s",+ "priority":1,+ "computeEnvironmentOrder":[{"order":1,"computeEnvironment":"%s"}]+ }+ """.formatted(name, computeEnvironmentArn))+ .when()+ .post("/v1/createjobqueue")+ .then()+ .statusCode(200)+ .extract().path("jobQueueArn");+ }++ private String registerJobDefinition(String name) {+ return givenBatchJson("""+ {+ "jobDefinitionName":"%s",+ "type":"container",+ "containerProperties": {+ "image":"public.ecr.aws/example/job:latest",+ "command":["Ref::inputKey"]+ }+ }+ """.formatted(name))+ .when()+ .post("/v1/registerjobdefinition")+ .then()+ .statusCode(200)+ .extract().path("jobDefinitionArn");+ }++ private static io.restassured.specification.RequestSpecification givenBatchJson(String body) {+ return given()+ .header("Authorization", BATCH_AUTH)+ .contentType("application/json")+ .body(body);+ }+}diff --git a/src/test/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeInvokerTest.java b/src/test/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeInvokerTest.javaindex 9fd5be02f0..eb2771d3a7 100644--- a/src/test/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeInvokerTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeInvokerTest.java@@ -1,6 +1,9 @@package io.github.hectorvent.floci.services.eventbridge;import com.fasterxml.jackson.databind.ObjectMapper;+import com.fasterxml.jackson.databind.JsonNode;+import io.github.hectorvent.floci.services.batch.BatchService;+import io.github.hectorvent.floci.services.eventbridge.model.BatchParameters;import io.github.hectorvent.floci.services.eventbridge.model.InputTransformer;import io.github.hectorvent.floci.services.eventbridge.model.Target;import io.github.hectorvent.floci.services.lambda.LambdaService;@@ -19,16 +22,19 @@ class EventBridgeInvokerTest {private EventBridgeInvoker invoker;private SqsService sqsService;+ private BatchService batchService;@BeforeEachvoid setUp() {LambdaService lambdaService = mock(LambdaService.class);sqsService = mock(SqsService.class);SnsService snsService = mock(SnsService.class);+ batchService = mock(BatchService.class);invoker = new EventBridgeInvoker(lambdaService,sqsService,snsService,+ batchService,new ObjectMapper(),mock(io.github.hectorvent.floci.config.EmulatorConfig.class));@@ -44,6 +50,79 @@ class EventBridgeInvokerTest {verify(sqsService).sendMessage(anyString(), eq(event), anyInt(), isNull(), isNull(), eq("eu-west-1"));}+ @Test+ void invokeTarget_batchTarget_submitsBatchJobWithParametersFromPayload() throws Exception {+ JsonNode retryStrategy = new ObjectMapper().readTree("{\"Attempts\":2}");+ Target target = new Target("id1",+ "arn:aws:batch:us-west-2:000000000000:job-queue/my-queue",+ "{\"Parameters\":{\"inputKey\":\"inputs/1.json\",\"count\":2}}",+ null);+ BatchParameters batchParameters = new BatchParameters();+ batchParameters.setJobDefinition("my-job:1");+ batchParameters.setJobName("scheduled-job");+ batchParameters.setRetryStrategy(retryStrategy);+ target.setBatchParameters(batchParameters);++ invoker.invokeTarget(target, "{\"ignored\":true}", "us-east-1");++ verify(batchService).submitFromEventBridge(+ eq("arn:aws:batch:us-west-2:000000000000:job-queue/my-queue"),+ eq("my-job:1"),+ eq("scheduled-job"),+ eq(Map.of("inputKey", "inputs/1.json", "count", "2")),+ eq(retryStrategy),+ eq("us-west-2")+ );+ }++ @Test+ void invokeTarget_batchTargetDoesNotMapFlatPayloadToParameters() {+ Target target = new Target("id1",+ "arn:aws:batch:us-west-2:000000000000:job-queue/my-queue",+ "{\"inputKey\":\"ignored\"}",+ null);+ BatchParameters batchParameters = new BatchParameters();+ batchParameters.setJobDefinition("my-job:1");+ batchParameters.setJobName("scheduled-job");+ target.setBatchParameters(batchParameters);++ invoker.invokeTarget(target, "{\"ignored\":true}", "us-east-1");++ verify(batchService).submitFromEventBridge(+ eq("arn:aws:batch:us-west-2:000000000000:job-queue/my-queue"),+ eq("my-job:1"),+ eq("scheduled-job"),+ eq(Map.of()),+ isNull(),+ eq("us-west-2")+ );+ }++ @Test+ void invokeTarget_batchTargetWithoutExplicitInputDoesNotMapEventEnvelopeToParameters() {+ Target target = new Target("id1",+ "arn:aws:batch:us-west-2:000000000000:job-queue/my-queue",+ null,+ null);+ BatchParameters batchParameters = new BatchParameters();+ batchParameters.setJobDefinition("my-job:1");+ batchParameters.setJobName("scheduled-job");+ target.setBatchParameters(batchParameters);++ invoker.invokeTarget(target, """+ {"source":"local.test","region":"us-east-1","detail":{"inputKey":"ignored"}}+ """, "us-east-1");++ verify(batchService).submitFromEventBridge(+ eq("arn:aws:batch:us-west-2:000000000000:job-queue/my-queue"),+ eq("my-job:1"),+ eq("scheduled-job"),+ eq(Map.of()),+ isNull(),+ eq("us-west-2")+ );+ }+@Testvoid extractJsonPath_topLevelField() {String event = "{\"source\":\"aws.s3\",\"detail-type\":\"Object Created\"}";diff --git a/src/test/resources/application.yml b/src/test/resources/application.ymlindex 76123df335..03d7eaa3ed 100644--- a/src/test/resources/application.yml+++ b/src/test/resources/application.yml@@ -34,6 +34,8 @@ floci:flush-interval-ms: 60000opensearch:flush-interval-ms: 60000+ batch:+ flush-interval-ms: 60000cloudfront:auth:@@ -181,6 +183,9 @@ floci:codebuild:enabled: true# docker-network: floci-network+ batch:+ enabled: true+ runner-mode: immediatecodedeploy:enabled: trueautoscaling: