feat(batch): add update and delete job queue endpoints with corresponding service logic (#2807)

This commit is contained in:
Matheus André authored and GitHub committed 2026-08-30 23:35:09 -04:00
1 parent 66d910c613
commit 6f123e83b8
5 files changed
+211

No files matched your search

+2
View File
@@ -12,6 +12,8 @@ Floci Batch implements the AWS Batch control plane for local integration tests.
| `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 |
| `UpdateJobQueue` | `POST /v1/updatejobqueue` | Update a job queue's state, priority, and compute environment order |
| `DeleteJobQueue` | `POST /v1/deletejobqueue` | Delete a `DISABLED` job queue; deleting a missing queue is a no-op |
| `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 |
@@ -56,6 +56,20 @@ public class BatchController {
Response.ok(service.createJobQueue(request, region)).build());
}
@POST
@Path("/v1/updatejobqueue")
public Response updateJobQueue(@Context HttpHeaders headers, String body) {
return handle(headers, body, (request, region) ->
Response.ok(service.updateJobQueue(request)).build());
}
@POST
@Path("/v1/deletejobqueue")
public Response deleteJobQueue(@Context HttpHeaders headers, String body) {
return handle(headers, body, (request, region) ->
Response.ok(service.deleteJobQueue(request)).build());
}
@POST
@Path("/v1/describejobqueues")
public Response describeJobQueues(@Context HttpHeaders headers, String body) {
@@ -203,6 +203,46 @@ public class BatchService {
return out;
}
public synchronized ObjectNode updateJobQueue(JsonNode request) {
BatchJobQueue queue = resolveJobQueue(requiredText(request, "jobQueue"));
if (request.hasNonNull("state")) {
queue.setState(request.path("state").asText());
}
if (request.hasNonNull("priority")) {
queue.setPriority(request.path("priority").asInt());
}
if (request.hasNonNull("computeEnvironmentOrder")) {
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());
}
}
queue.setComputeEnvironmentOrder(orders);
}
jobQueueStore.put(queue.getJobQueueArn(), queue);
ObjectNode out = objectMapper.createObjectNode();
out.put("jobQueueName", queue.getJobQueueName());
out.put("jobQueueArn", queue.getJobQueueArn());
return out;
}
public synchronized ObjectNode deleteJobQueue(JsonNode request) {
String ref = requiredText(request, "jobQueue");
Optional<BatchJobQueue> queue = resolveJobQueueOptional(ref);
if (queue.isEmpty()) {
return objectMapper.createObjectNode();
}
if ("ENABLED".equals(queue.get().getState())) {
throw client("Cannot delete job queue in ENABLED state: " + queue.get().getJobQueueName());
}
jobQueueStore.delete(queue.get().getJobQueueArn());
return objectMapper.createObjectNode();
}
public ObjectNode describeJobQueues(JsonNode request) {
List<String> refs = stringList(request.path("jobQueues"));
if (refs.size() > DESCRIBE_JOBS_LIMIT) {
@@ -447,6 +447,57 @@ class BatchIntegrationTest {
.body("__type", equalTo("ClientException"));
}
@Test
void updateAndDeleteJobQueueSupportsTeardownFlow() {
String suffix = uniqueSuffix();
String queueName = "teardown-queue-" + suffix;
String queueArn = createQueue(queueName, createComputeEnvironment("teardown-ce-" + suffix));
givenJson("{\"jobQueue\":\"%s\"}".formatted(queueName))
.when()
.post("/v1/deletejobqueue")
.then()
.statusCode(400)
.body("__type", equalTo("ClientException"));
givenJson("{\"jobQueue\":\"%s\",\"state\":\"DISABLED\",\"priority\":9}".formatted(queueName))
.when()
.post("/v1/updatejobqueue")
.then()
.statusCode(200)
.body("jobQueueName", equalTo(queueName))
.body("jobQueueArn", equalTo(queueArn));
givenJson("{\"jobQueues\":[\"%s\"]}".formatted(queueArn))
.when()
.post("/v1/describejobqueues")
.then()
.statusCode(200)
.body("jobQueues", hasSize(1))
.body("jobQueues[0].state", equalTo("DISABLED"))
.body("jobQueues[0].priority", equalTo(9));
givenJson("{\"jobQueue\":\"%s\"}".formatted(queueName))
.when()
.post("/v1/deletejobqueue")
.then()
.statusCode(200)
.body("isEmpty()", equalTo(true));
givenJson("{\"jobQueues\":[\"%s\"]}".formatted(queueArn))
.when()
.post("/v1/describejobqueues")
.then()
.statusCode(200)
.body("jobQueues", hasSize(0));
givenJson("{\"jobQueue\":\"%s\"}".formatted(queueName))
.when()
.post("/v1/deletejobqueue")
.then()
.statusCode(200);
}
@Test
void describeUnknownJobsReturnsEmptyList() {
givenJson("{\"jobs\":[\"does-not-exist\"]}")
@@ -4,6 +4,7 @@ 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.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
@@ -24,6 +25,7 @@ import java.util.function.Predicate;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
@@ -207,6 +209,108 @@ class BatchServiceTest {
assertEquals("b-job", secondPage.path("jobSummaryList").get(0).path("jobId").asText());
}
@Test
void updateJobQueueChangesPriorityStateAndComputeEnvironmentOrder() throws Exception {
BatchService service = immediateService(new InMemoryStorage<String, BatchJob>());
String firstComputeArn = service.createComputeEnvironment(json("""
{"computeEnvironmentName":"update-ce-1","type":"MANAGED"}
"""), REGION).path("computeEnvironmentArn").asText();
String secondComputeArn = service.createComputeEnvironment(json("""
{"computeEnvironmentName":"update-ce-2","type":"MANAGED"}
"""), REGION).path("computeEnvironmentArn").asText();
String queueArn = service.createJobQueue(json("""
{
"jobQueueName":"update-queue",
"priority":1,
"computeEnvironmentOrder":[{"order":1,"computeEnvironment":"%s"}]
}
""".formatted(firstComputeArn)), REGION).path("jobQueueArn").asText();
JsonNode updated = service.updateJobQueue(json("""
{
"jobQueue":"update-queue",
"state":"DISABLED",
"priority":5,
"computeEnvironmentOrder":[{"order":1,"computeEnvironment":"%s"}]
}
""".formatted(secondComputeArn)));
assertEquals("update-queue", updated.path("jobQueueName").asText());
assertEquals(queueArn, updated.path("jobQueueArn").asText());
JsonNode detail = service.describeJobQueues(json("""
{"jobQueues":["%s"]}
""".formatted(queueArn))).path("jobQueues").get(0);
assertEquals("DISABLED", detail.path("state").asText());
assertEquals(5, detail.path("priority").asInt());
assertEquals(secondComputeArn,
detail.path("computeEnvironmentOrder").get(0).path("computeEnvironment").asText());
}
@Test
void updateJobQueueRejectsUnknownQueue() {
BatchService service = immediateService(new InMemoryStorage<String, BatchJob>());
AwsException e = assertThrows(AwsException.class, () -> service.updateJobQueue(json("""
{"jobQueue":"missing-queue","priority":2}
""")));
assertEquals("ClientException", e.getErrorCode());
}
@Test
void deleteJobQueueRejectsEnabledQueue() throws Exception {
BatchService service = immediateService(new InMemoryStorage<String, BatchJob>());
String computeArn = service.createComputeEnvironment(json("""
{"computeEnvironmentName":"delete-enabled-ce","type":"MANAGED"}
"""), REGION).path("computeEnvironmentArn").asText();
service.createJobQueue(json("""
{
"jobQueueName":"delete-enabled-queue",
"priority":1,
"computeEnvironmentOrder":[{"order":1,"computeEnvironment":"%s"}]
}
""".formatted(computeArn)), REGION);
AwsException e = assertThrows(AwsException.class, () -> service.deleteJobQueue(json("""
{"jobQueue":"delete-enabled-queue"}
""")));
assertEquals("ClientException", e.getErrorCode());
}
@Test
void deleteJobQueueRemovesDisabledQueueAndToleratesRepeatDeletes() throws Exception {
BatchService service = immediateService(new InMemoryStorage<String, BatchJob>());
String computeArn = service.createComputeEnvironment(json("""
{"computeEnvironmentName":"delete-ce","type":"MANAGED"}
"""), REGION).path("computeEnvironmentArn").asText();
String queueArn = service.createJobQueue(json("""
{
"jobQueueName":"delete-queue",
"priority":1,
"computeEnvironmentOrder":[{"order":1,"computeEnvironment":"%s"}]
}
""".formatted(computeArn)), REGION).path("jobQueueArn").asText();
service.updateJobQueue(json("""
{"jobQueue":"delete-queue","state":"DISABLED"}
"""));
JsonNode deleted = service.deleteJobQueue(json("""
{"jobQueue":"delete-queue"}
"""));
assertEquals(0, deleted.size());
JsonNode queues = service.describeJobQueues(json("""
{"jobQueues":["%s"]}
""".formatted(queueArn))).path("jobQueues");
assertEquals(0, queues.size());
JsonNode repeated = service.deleteJobQueue(json("""
{"jobQueue":"delete-queue"}
"""));
assertEquals(0, repeated.size());
}
private BatchService dockerService(BatchDockerRunner runner) {
EmulatorConfig config = mock(EmulatorConfig.class);
EmulatorConfig.ServicesConfig services = mock(EmulatorConfig.ServicesConfig.class);