mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(glue): start, read and stop job runs, and list and batch get jobs (#4382)
A job could be created but never run: StartJobRun and the other run actions answered InvalidAction. Add StartJobRun, GetJobRun, GetJobRuns, BatchStopJobRun, ListJobs and BatchGetJobs. Runs follow Glue's state machine without executing the script. They are settled on read, so floci.services.glue.job-run-duration-seconds (default 0, succeed at once) can keep a run RUNNING long enough to stop it or hit MaxConcurrentRuns. DeleteJob also removes the job's runs. Part of #4380
This commit is contained in:
1 parent
c9c01729f2
commit
14ae1dfbdb
12 files changed
+1309
-4
No files matched your search
@@ -0,0 +1,62 @@
|
||||
package io.github.hectorvent.floci.services.glue;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.matchesPattern;
|
||||
|
||||
@QuarkusTest
|
||||
class GlueJobRunIntegrationTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String ROLE = "arn:aws:iam::000000000000:role/my-role";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static ValidatableResponse call(String action, String body) {
|
||||
return given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSGlue." + action)
|
||||
.body(body)
|
||||
.when().post("/")
|
||||
.then();
|
||||
}
|
||||
|
||||
@Test
|
||||
void jobRunStartsSucceedsAndIsRemovedWithItsJob() {
|
||||
String jobName = "run-job-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
call("CreateJob", """
|
||||
{ "Name": "%s", "Role": "%s", "Command": { "Name": "glueetl" } }
|
||||
""".formatted(jobName, ROLE)).statusCode(200);
|
||||
|
||||
String runId = call("StartJobRun", "{ \"JobName\": \"" + jobName + "\" }")
|
||||
.statusCode(200)
|
||||
.body("JobRunId", matchesPattern("jr_[0-9a-f]{64}"))
|
||||
.extract().path("JobRunId");
|
||||
|
||||
call("GetJobRun", "{ \"JobName\": \"" + jobName + "\", \"RunId\": \"" + runId + "\" }")
|
||||
.statusCode(200)
|
||||
.body("JobRun.Id", equalTo(runId))
|
||||
.body("JobRun.JobRunState", equalTo("SUCCEEDED"));
|
||||
|
||||
call("ListJobs", "{}")
|
||||
.statusCode(200)
|
||||
.body("JobNames", hasItem(jobName));
|
||||
|
||||
call("DeleteJob", "{ \"JobName\": \"" + jobName + "\" }").statusCode(200);
|
||||
|
||||
call("GetJobRuns", "{ \"JobName\": \"" + jobName + "\" }")
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("EntityNotFoundException"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,465 @@
|
||||
package io.github.hectorvent.floci.services.glue;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
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.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.glue.model.ExecutionProperty;
|
||||
import io.github.hectorvent.floci.services.glue.model.Job;
|
||||
import io.github.hectorvent.floci.services.glue.model.JobCommand;
|
||||
import io.github.hectorvent.floci.services.glue.model.JobRun;
|
||||
import io.github.hectorvent.floci.services.glue.schemaregistry.GlueSchemaRegistryService;
|
||||
import io.github.hectorvent.floci.services.kms.KmsService;
|
||||
import io.github.hectorvent.floci.services.resourcegroupstagging.ResourceGroupsTaggingService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class GlueJobRunServiceTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String ACCOUNT_ID = "000000000000";
|
||||
private static final String ROLE = "arn:aws:iam::000000000000:role/glue";
|
||||
private static final Instant T0 = Instant.parse("2026-09-25T12:00:00Z");
|
||||
|
||||
private GlueService glueService;
|
||||
private InMemoryStorage<String, JobRun> runStore;
|
||||
private MutableClock clock;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
RegionResolver regionResolver = new RegionResolver(REGION, ACCOUNT_ID);
|
||||
StorageFactory storageFactory = new InMemoryStorageFactory();
|
||||
glueService = new GlueService(storageFactory, new GlueSchemaRegistryService(storageFactory, regionResolver),
|
||||
regionResolver, new ResourceGroupsTaggingService(storageFactory),
|
||||
new KmsService(storageFactory, regionResolver));
|
||||
runStore = new InMemoryStorage<>();
|
||||
clock = new MutableClock(T0);
|
||||
}
|
||||
|
||||
private GlueJobRunService service(int runDurationSeconds) {
|
||||
return new GlueJobRunService(runStore, glueService, runDurationSeconds, clock);
|
||||
}
|
||||
|
||||
private Job createJob(String name, Integer maxConcurrentRuns, Integer timeoutMinutes) {
|
||||
Job job = new Job();
|
||||
job.setName(name);
|
||||
job.setRole(ROLE);
|
||||
job.setCommand(new JobCommand());
|
||||
job.setWorkerType("G.1X");
|
||||
job.setNumberOfWorkers(2);
|
||||
job.setTimeout(timeoutMinutes);
|
||||
if (maxConcurrentRuns != null) {
|
||||
ExecutionProperty property = new ExecutionProperty();
|
||||
property.setMaxConcurrentRuns(maxConcurrentRuns);
|
||||
job.setExecutionProperty(property);
|
||||
}
|
||||
glueService.createJob(job, null, REGION);
|
||||
return job;
|
||||
}
|
||||
|
||||
@Test
|
||||
void runSucceedsAsSoonAsItStartsByDefault() {
|
||||
createJob("etl", null, null);
|
||||
|
||||
JobRun run = service(0).startJobRun("etl", null, new JobRun());
|
||||
|
||||
assertTrue(run.getId().matches("jr_[0-9a-f]{64}"), run.getId());
|
||||
assertEquals("SUCCEEDED", run.getJobRunState());
|
||||
assertEquals(T0, run.getStartedOn());
|
||||
assertEquals(T0, run.getCompletedOn());
|
||||
assertEquals(0, run.getExecutionTime());
|
||||
assertEquals(0, run.getAttempt());
|
||||
assertEquals("G.1X", run.getWorkerType());
|
||||
assertEquals(2, run.getNumberOfWorkers());
|
||||
assertEquals(480, run.getTimeout());
|
||||
assertEquals("5.1", run.getGlueVersion());
|
||||
assertEquals("/aws-glue/jobs", run.getLogGroupName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void requestFieldsOverrideTheJobDefinitionForThatRunOnly() {
|
||||
createJob("etl", null, null);
|
||||
JobRun overrides = new JobRun();
|
||||
overrides.setArguments(Map.of("--day", "2026-09-25"));
|
||||
overrides.setWorkerType("G.2X");
|
||||
overrides.setNumberOfWorkers(10);
|
||||
overrides.setTimeout(30);
|
||||
|
||||
JobRun run = service(0).startJobRun("etl", null, overrides);
|
||||
|
||||
assertEquals(Map.of("--day", "2026-09-25"), run.getArguments());
|
||||
assertEquals("G.2X", run.getWorkerType());
|
||||
assertEquals(10, run.getNumberOfWorkers());
|
||||
assertEquals(30, run.getTimeout());
|
||||
assertEquals("G.1X", glueService.getJob("etl").getWorkerType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void runStaysRunningUntilTheConfiguredDurationHasPassed() {
|
||||
createJob("etl", null, null);
|
||||
GlueJobRunService service = service(60);
|
||||
String runId = service.startJobRun("etl", null, new JobRun()).getId();
|
||||
|
||||
clock.set(T0.plusSeconds(59));
|
||||
JobRun running = service.getJobRun("etl", runId);
|
||||
assertEquals("RUNNING", running.getJobRunState());
|
||||
assertNull(running.getCompletedOn());
|
||||
|
||||
clock.set(T0.plusSeconds(90));
|
||||
JobRun finished = service.getJobRun("etl", runId);
|
||||
assertEquals("SUCCEEDED", finished.getJobRunState());
|
||||
assertEquals(T0.plusSeconds(60), finished.getCompletedOn());
|
||||
assertEquals(60, finished.getExecutionTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
void runLongerThanTheJobTimeoutEndsInTimeout() {
|
||||
createJob("etl", null, 1);
|
||||
GlueJobRunService service = service(120);
|
||||
String runId = service.startJobRun("etl", null, new JobRun()).getId();
|
||||
|
||||
clock.set(T0.plusSeconds(61));
|
||||
JobRun run = service.getJobRun("etl", runId);
|
||||
|
||||
assertEquals("TIMEOUT", run.getJobRunState());
|
||||
assertEquals(T0.plusSeconds(60), run.getCompletedOn());
|
||||
assertEquals(60, run.getExecutionTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
void secondRunIsRejectedWhileMaxConcurrentRunsDefaultsToOne() {
|
||||
createJob("etl", null, null);
|
||||
GlueJobRunService service = service(60);
|
||||
service.startJobRun("etl", null, new JobRun());
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.startJobRun("etl", null, new JobRun()));
|
||||
assertEquals("ConcurrentRunsExceededException", error.getErrorCode());
|
||||
|
||||
clock.set(T0.plusSeconds(60));
|
||||
assertEquals("RUNNING", service.startJobRun("etl", null, new JobRun()).getJobRunState());
|
||||
}
|
||||
|
||||
@Test
|
||||
void maxConcurrentRunsAndQueuingBothAdmitAnotherRun() {
|
||||
createJob("wide", 2, null);
|
||||
createJob("queued", null, null);
|
||||
GlueJobRunService service = service(60);
|
||||
|
||||
service.startJobRun("wide", null, new JobRun());
|
||||
service.startJobRun("wide", null, new JobRun());
|
||||
assertThrows(AwsException.class, () -> service.startJobRun("wide", null, new JobRun()));
|
||||
|
||||
JobRun queuing = new JobRun();
|
||||
queuing.setJobRunQueuingEnabled(true);
|
||||
service.startJobRun("queued", null, new JobRun());
|
||||
assertTrue(service.startJobRun("queued", null, queuing).getJobRunQueuingEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void batchStopStopsARunningRunAndReportsTheRest() {
|
||||
createJob("etl", 5, null);
|
||||
GlueJobRunService service = service(60);
|
||||
String finished = service.startJobRun("etl", null, new JobRun()).getId();
|
||||
clock.set(T0.plusSeconds(60));
|
||||
String stillRunning = service.startJobRun("etl", null, new JobRun()).getId();
|
||||
clock.set(T0.plusSeconds(70));
|
||||
|
||||
GlueJobRunService.StopResult result =
|
||||
service.batchStopJobRun("etl", List.of(stillRunning, finished, "jr_missing"));
|
||||
|
||||
assertEquals(List.of(new GlueJobRunService.StoppedRun("etl", stillRunning)), result.stopped());
|
||||
assertEquals(2, result.errors().size());
|
||||
assertEquals("InvalidInputException", result.errors().get(0).errorCode());
|
||||
assertEquals("EntityNotFoundException", result.errors().get(1).errorCode());
|
||||
JobRun stopped = service.getJobRun("etl", stillRunning);
|
||||
assertEquals("STOPPED", stopped.getJobRunState());
|
||||
assertEquals(10, stopped.getExecutionTime());
|
||||
assertEquals("SUCCEEDED", service.getJobRun("etl", finished).getJobRunState());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getJobRunsListsNewestFirstAndPages() {
|
||||
createJob("etl", 10, null);
|
||||
GlueJobRunService service = service(0);
|
||||
String first = service.startJobRun("etl", null, new JobRun()).getId();
|
||||
clock.set(T0.plusSeconds(1));
|
||||
String second = service.startJobRun("etl", null, new JobRun()).getId();
|
||||
|
||||
GlueService.Page<JobRun> page = service.getJobRuns("etl", 1, null);
|
||||
assertEquals(second, page.items().getFirst().getId());
|
||||
GlueService.Page<JobRun> next = service.getJobRuns("etl", 1, page.nextToken());
|
||||
assertEquals(first, next.items().getFirst().getId());
|
||||
assertNull(next.nextToken());
|
||||
|
||||
AwsException tooMany = assertThrows(AwsException.class, () -> service.getJobRuns("etl", 201, null));
|
||||
assertEquals("InvalidInputException", tooMany.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void runsAreScopedToTheirJob() {
|
||||
createJob("a", null, null);
|
||||
createJob("b", null, null);
|
||||
GlueJobRunService service = service(0);
|
||||
String runOfA = service.startJobRun("a", null, new JobRun()).getId();
|
||||
|
||||
AwsException error = assertThrows(AwsException.class, () -> service.getJobRun("b", runOfA));
|
||||
assertEquals("EntityNotFoundException", error.getErrorCode());
|
||||
assertTrue(service.getJobRuns("b", null, null).items().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void unknownJobOrRetriedRunIsEntityNotFound() {
|
||||
createJob("etl", null, null);
|
||||
GlueJobRunService service = service(0);
|
||||
|
||||
assertEquals("EntityNotFoundException", assertThrows(AwsException.class,
|
||||
() -> service.startJobRun("missing", null, new JobRun())).getErrorCode());
|
||||
assertEquals("EntityNotFoundException", assertThrows(AwsException.class,
|
||||
() -> service.startJobRun("etl", "jr_missing", new JobRun())).getErrorCode());
|
||||
|
||||
String first = service.startJobRun("etl", null, new JobRun()).getId();
|
||||
assertEquals(first, service.startJobRun("etl", first, new JobRun()).getPreviousRunId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletingTheJobRemovesItsRuns() {
|
||||
createJob("etl", null, null);
|
||||
GlueJobRunService service = service(0);
|
||||
service.startJobRun("etl", null, new JobRun());
|
||||
|
||||
glueService.deleteJob("etl", REGION);
|
||||
service.deleteRuns("etl");
|
||||
createJob("etl", null, null);
|
||||
|
||||
assertTrue(service.getJobRuns("etl", null, null).items().isEmpty());
|
||||
assertTrue(runStore.scan(key -> true).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void concurrentStartsAdmitNoMoreThanMaxConcurrentRuns() throws Exception {
|
||||
createJob("etl", null, null);
|
||||
GlueJobRunService service = service(60);
|
||||
int threads = 16;
|
||||
CountDownLatch go = new CountDownLatch(1);
|
||||
AtomicInteger admitted = new AtomicInteger();
|
||||
AtomicInteger rejected = new AtomicInteger();
|
||||
ExecutorService pool = Executors.newFixedThreadPool(threads);
|
||||
try {
|
||||
List<Future<?>> futures = new ArrayList<>();
|
||||
for (int i = 0; i < threads; i++) {
|
||||
futures.add(pool.submit(() -> {
|
||||
go.await();
|
||||
try {
|
||||
service.startJobRun("etl", null, new JobRun());
|
||||
admitted.incrementAndGet();
|
||||
} catch (AwsException expected) {
|
||||
// ConcurrentRunsExceededException is the outcome under test for all but one start.
|
||||
rejected.incrementAndGet();
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
go.countDown();
|
||||
for (Future<?> future : futures) {
|
||||
future.get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
} finally {
|
||||
pool.shutdownNow();
|
||||
}
|
||||
|
||||
assertEquals(1, admitted.get());
|
||||
assertEquals(threads - 1, rejected.get());
|
||||
assertEquals(1, runStore.scan(key -> true).size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds the run write inside StartJobRun open while DeleteJob runs. Without the service lock,
|
||||
* deleteRuns scans before the run is stored and the run outlives its job; with it, deleteRuns
|
||||
* waits for the write and removes the run.
|
||||
*/
|
||||
@Test
|
||||
void startRacingDeleteNeverLeavesARunBehind() throws Exception {
|
||||
createJob("etl", null, null);
|
||||
PausingStore store = new PausingStore(runStore);
|
||||
GlueJobRunService service = new GlueJobRunService(store, glueService, 60, clock);
|
||||
ExecutorService pool = Executors.newFixedThreadPool(2);
|
||||
try {
|
||||
Future<?> start = pool.submit(() -> service.startJobRun("etl", null, new JobRun()));
|
||||
assertTrue(store.putStarted.await(10, TimeUnit.SECONDS));
|
||||
|
||||
Future<?> delete = pool.submit(() -> {
|
||||
glueService.deleteJob("etl", REGION);
|
||||
service.deleteRuns("etl");
|
||||
return null;
|
||||
});
|
||||
try {
|
||||
delete.get(500, TimeUnit.MILLISECONDS);
|
||||
} catch (TimeoutException expected) {
|
||||
// With the lock held by the paused start, the delete is still waiting here.
|
||||
}
|
||||
store.release.countDown();
|
||||
start.get(10, TimeUnit.SECONDS);
|
||||
delete.get(10, TimeUnit.SECONDS);
|
||||
} finally {
|
||||
pool.shutdownNow();
|
||||
}
|
||||
|
||||
assertTrue(runStore.scan(key -> true).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void timeoutBelowOneMinuteIsRejected() {
|
||||
createJob("etl", null, null);
|
||||
JobRun overrides = new JobRun();
|
||||
overrides.setTimeout(-5);
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service(0).startJobRun("etl", null, overrides));
|
||||
|
||||
assertEquals("InvalidInputException", error.getErrorCode());
|
||||
assertTrue(runStore.scan(key -> true).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void zeroTimeoutInheritedFromTheJobIsRejected() {
|
||||
createJob("etl", null, 0);
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service(0).startJobRun("etl", null, new JobRun()));
|
||||
|
||||
assertEquals("InvalidInputException", error.getErrorCode());
|
||||
assertTrue(runStore.scan(key -> true).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void negativeRunDurationIsRefusedAtConstruction() {
|
||||
assertThrows(IllegalArgumentException.class, () -> service(-1));
|
||||
}
|
||||
|
||||
/** Delegates to a store, pausing the first put until {@code release} opens. */
|
||||
private static final class PausingStore implements StorageBackend<String, JobRun> {
|
||||
private final StorageBackend<String, JobRun> delegate;
|
||||
private final CountDownLatch putStarted = new CountDownLatch(1);
|
||||
private final CountDownLatch release = new CountDownLatch(1);
|
||||
|
||||
private PausingStore(StorageBackend<String, JobRun> delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(String key, JobRun value) {
|
||||
if (putStarted.getCount() > 0) {
|
||||
putStarted.countDown();
|
||||
try {
|
||||
release.await(10, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IllegalStateException("interrupted while paused", e);
|
||||
}
|
||||
}
|
||||
delegate.put(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<JobRun> get(String key) {
|
||||
return delegate.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String key) {
|
||||
delegate.delete(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JobRun> scan(Predicate<String> keyFilter) {
|
||||
return delegate.scan(keyFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> keys() {
|
||||
return delegate.keys();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
delegate.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
delegate.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
delegate.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class InMemoryStorageFactory extends StorageFactory {
|
||||
private InMemoryStorageFactory() {
|
||||
super(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> AccountAwareStorageBackend<V> create(String serviceName,
|
||||
String fileName,
|
||||
TypeReference<Map<String, V>> typeReference) {
|
||||
return AccountAwareStorageBackend.inMemory(ACCOUNT_ID);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class MutableClock extends Clock {
|
||||
private Instant now;
|
||||
|
||||
private MutableClock(Instant now) {
|
||||
this.now = now;
|
||||
}
|
||||
|
||||
void set(Instant now) {
|
||||
this.now = now;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZoneOffset getZone() {
|
||||
return ZoneOffset.UTC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Clock withZone(ZoneId zone) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instant instant() {
|
||||
return now;
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -15,6 +15,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import java.time.Clock;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -44,7 +45,9 @@ class GlueJsonHandlerEmptyListTest {
|
||||
GlueService glueService = new GlueService(
|
||||
storageFactory, schemaRegistryService, regionResolver,
|
||||
new ResourceGroupsTaggingService(storageFactory), new KmsService(storageFactory, regionResolver));
|
||||
handler = new GlueJsonHandler(glueService, schemaRegistryService, mapper);
|
||||
handler = new GlueJsonHandler(glueService,
|
||||
new GlueJobRunService(new InMemoryStorage<>(), glueService, 0, Clock.systemUTC()),
|
||||
schemaRegistryService, mapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.glue.schemaregistry.GlueSchemaRegistryService;
|
||||
import io.github.hectorvent.floci.services.kms.KmsService;
|
||||
@@ -16,6 +17,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import java.time.Clock;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -44,7 +46,9 @@ class GlueJsonHandlerTest {
|
||||
GlueService glueService = new GlueService(
|
||||
storageFactory, schemaRegistryService, regionResolver, new ResourceGroupsTaggingService(storageFactory),
|
||||
new KmsService(storageFactory, regionResolver));
|
||||
handler = new GlueJsonHandler(glueService, schemaRegistryService, mapper);
|
||||
handler = new GlueJsonHandler(glueService,
|
||||
new GlueJobRunService(new InMemoryStorage<>(), glueService, 0, Clock.systemUTC()),
|
||||
schemaRegistryService, mapper);
|
||||
}
|
||||
|
||||
private void createDatabaseAndTable(String dbName, String tableName) throws Exception {
|
||||
@@ -793,4 +797,82 @@ class GlueJsonHandlerTest {
|
||||
assertEquals("alias/glue", after.get("ConnectionPasswordEncryption").get("AwsKmsKeyId").asText());
|
||||
assertEquals("DISABLED", after.get("EncryptionAtRest").get("CatalogEncryptionMode").asText());
|
||||
}
|
||||
|
||||
private void createJobWithTags(String name, Map<String, String> tags) throws Exception {
|
||||
ObjectNode create = mapper.createObjectNode();
|
||||
create.put("Name", name);
|
||||
create.put("Role", "arn:aws:iam::000000000000:role/glue");
|
||||
create.putObject("Command").put("Name", "glueetl");
|
||||
ObjectNode tagNode = create.putObject("Tags");
|
||||
tags.forEach(tagNode::put);
|
||||
assertEquals(200, handler.handle("CreateJob", create, REGION).getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* The wire shape a job run client reads: StartJobRun answers with the run id alone, GetJobRun
|
||||
* nests the run under "JobRun" with numeric timestamps, and stopping a finished run is an entry
|
||||
* in Errors rather than a failed request.
|
||||
*/
|
||||
@Test
|
||||
void jobRunOperationsAnswerWithTheDocumentedBodies() throws Exception {
|
||||
createJobWithTags("nightly", Map.of());
|
||||
|
||||
ObjectNode start = mapper.createObjectNode();
|
||||
start.put("JobName", "nightly");
|
||||
start.putObject("Arguments").put("--day", "2026-09-25");
|
||||
JsonNode started = mapper.valueToTree(handler.handle("StartJobRun", start, REGION).getEntity());
|
||||
assertEquals(1, started.size());
|
||||
String runId = started.get("JobRunId").asText();
|
||||
|
||||
ObjectNode get = mapper.createObjectNode().put("JobName", "nightly").put("RunId", runId);
|
||||
JsonNode run = mapper.valueToTree(handler.handle("GetJobRun", get, REGION).getEntity()).get("JobRun");
|
||||
assertEquals(runId, run.get("Id").asText());
|
||||
assertEquals("nightly", run.get("JobName").asText());
|
||||
assertEquals("SUCCEEDED", run.get("JobRunState").asText());
|
||||
assertEquals("2026-09-25", run.get("Arguments").get("--day").asText());
|
||||
assertTrue(run.get("StartedOn").isNumber());
|
||||
assertTrue(run.get("CompletedOn").isNumber());
|
||||
assertFalse(run.has("ErrorMessage"));
|
||||
|
||||
JsonNode runs = mapper.valueToTree(handler.handle(
|
||||
"GetJobRuns", mapper.createObjectNode().put("JobName", "nightly"), REGION).getEntity());
|
||||
assertEquals(1, runs.get("JobRuns").size());
|
||||
assertFalse(runs.has("NextToken"));
|
||||
|
||||
ObjectNode stop = mapper.createObjectNode().put("JobName", "nightly");
|
||||
stop.putArray("JobRunIds").add(runId);
|
||||
JsonNode stopped = mapper.valueToTree(handler.handle("BatchStopJobRun", stop, REGION).getEntity());
|
||||
assertEquals(0, stopped.get("SuccessfulSubmissions").size());
|
||||
JsonNode error = stopped.get("Errors").get(0);
|
||||
assertEquals("nightly", error.get("JobName").asText());
|
||||
assertEquals(runId, error.get("JobRunId").asText());
|
||||
assertEquals("InvalidInputException", error.get("ErrorDetail").get("ErrorCode").asText());
|
||||
|
||||
handler.handle("DeleteJob", mapper.createObjectNode().put("JobName", "nightly"), REGION);
|
||||
AwsException gone = assertThrows(AwsException.class, () -> handler.handle(
|
||||
"GetJobRuns", mapper.createObjectNode().put("JobName", "nightly"), REGION));
|
||||
assertEquals("EntityNotFoundException", gone.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listJobsFiltersOnTagsAndBatchGetJobsReportsMissingNames() throws Exception {
|
||||
createJobWithTags("tagged", Map.of("team", "data"));
|
||||
createJobWithTags("plain", Map.of());
|
||||
|
||||
JsonNode all = mapper.valueToTree(handler.handle("ListJobs", mapper.createObjectNode(), REGION).getEntity());
|
||||
assertEquals(List.of("plain", "tagged"), mapper.convertValue(all.get("JobNames"), List.class));
|
||||
assertFalse(all.has("NextToken"));
|
||||
|
||||
ObjectNode filtered = mapper.createObjectNode();
|
||||
filtered.putObject("Tags").put("team", "data");
|
||||
JsonNode byTag = mapper.valueToTree(handler.handle("ListJobs", filtered, REGION).getEntity());
|
||||
assertEquals(List.of("tagged"), mapper.convertValue(byTag.get("JobNames"), List.class));
|
||||
|
||||
ObjectNode batch = mapper.createObjectNode();
|
||||
batch.putArray("JobNames").add("tagged").add("absent");
|
||||
JsonNode got = mapper.valueToTree(handler.handle("BatchGetJobs", batch, REGION).getEntity());
|
||||
assertEquals(1, got.get("Jobs").size());
|
||||
assertEquals("tagged", got.get("Jobs").get(0).get("Name").asText());
|
||||
assertEquals("absent", got.get("JobsNotFound").get(0).asText());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user