diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/GlueCrawlerRunTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/GlueCrawlerRunTest.java
new file mode 100644
index 0000000000..6932e3dbbf
--- /dev/null
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/GlueCrawlerRunTest.java
@@ -0,0 +1,97 @@
+package com.floci.test;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.glue.GlueClient;
+import software.amazon.awssdk.services.glue.model.BatchGetCrawlersResponse;
+import software.amazon.awssdk.services.glue.model.Crawler;
+import software.amazon.awssdk.services.glue.model.CrawlerMetrics;
+import software.amazon.awssdk.services.glue.model.CrawlerNotRunningException;
+import software.amazon.awssdk.services.glue.model.CrawlerState;
+import software.amazon.awssdk.services.glue.model.LastCrawlStatus;
+import software.amazon.awssdk.services.glue.model.ScheduleState;
+
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+@DisplayName("Glue crawler runs")
+class GlueCrawlerRunTest {
+
+ private static final String CRAWLER_NAME = TestFixtures.uniqueName("run_crawler");
+ private static final String ROLE = "arn:aws:iam::000000000000:role/glue";
+
+ private static GlueClient glue;
+
+ @BeforeAll
+ static void setup() {
+ glue = TestFixtures.glueClient();
+ glue.createCrawler(r -> r
+ .name(CRAWLER_NAME)
+ .role(ROLE)
+ .targets(t -> t.s3Targets(s -> s.path("s3://raw/events")))
+ .schedule("cron(0 2 * * ? *)")
+ .tags(Map.of("team", "data")));
+ }
+
+ @AfterAll
+ static void cleanup() {
+ if (glue == null) {
+ return;
+ }
+ try {
+ glue.deleteCrawler(r -> r.name(CRAWLER_NAME));
+ }
+ catch (Exception ignored) {
+ // Cleanup is best effort: the crawler name is unique to this run and the emulator is disposable.
+ }
+ glue.close();
+ }
+
+ @Test
+ @DisplayName("StartCrawler completes a crawl that GetCrawler and GetCrawlerMetrics parse")
+ void startAndReadACrawl() {
+ glue.startCrawler(r -> r.name(CRAWLER_NAME));
+
+ Crawler crawler = glue.getCrawler(r -> r.name(CRAWLER_NAME)).crawler();
+ assertThat(crawler.state()).isEqualTo(CrawlerState.READY);
+ assertThat(crawler.lastCrawl().status()).isEqualTo(LastCrawlStatus.SUCCEEDED);
+ assertThat(crawler.lastCrawl().startTime()).isNotNull();
+
+ CrawlerMetrics metrics = glue.getCrawlerMetrics(r -> r.crawlerNameList(CRAWLER_NAME))
+ .crawlerMetricsList().get(0);
+ assertThat(metrics.crawlerName()).isEqualTo(CRAWLER_NAME);
+ assertThat(metrics.timeLeftSeconds()).isZero();
+ assertThat(metrics.stillEstimating()).isFalse();
+
+ assertThatThrownBy(() -> glue.stopCrawler(r -> r.name(CRAWLER_NAME)))
+ .isInstanceOf(CrawlerNotRunningException.class);
+ }
+
+ @Test
+ @DisplayName("ListCrawlers filters on tags and BatchGetCrawlers reports missing names")
+ void listAndBatchGetCrawlers() {
+ assertThat(glue.listCrawlers(r -> r.tags(Map.of("team", "data"))).crawlerNames()).contains(CRAWLER_NAME);
+
+ BatchGetCrawlersResponse response = glue.batchGetCrawlers(r -> r.crawlerNames(CRAWLER_NAME, "absent_crawler"));
+ assertThat(response.crawlers()).extracting(Crawler::name).containsExactly(CRAWLER_NAME);
+ assertThat(response.crawlersNotFound()).containsExactly("absent_crawler");
+ }
+
+ @Test
+ @DisplayName("The crawler schedule can be stopped, started and replaced")
+ void schedule() {
+ glue.stopCrawlerSchedule(r -> r.crawlerName(CRAWLER_NAME));
+ assertThat(glue.getCrawler(r -> r.name(CRAWLER_NAME)).crawler().schedule().state())
+ .isEqualTo(ScheduleState.NOT_SCHEDULED);
+
+ glue.startCrawlerSchedule(r -> r.crawlerName(CRAWLER_NAME));
+ glue.updateCrawlerSchedule(r -> r.crawlerName(CRAWLER_NAME).schedule("cron(30 3 * * ? *)"));
+ Crawler crawler = glue.getCrawler(r -> r.name(CRAWLER_NAME)).crawler();
+ assertThat(crawler.schedule().state()).isEqualTo(ScheduleState.SCHEDULED);
+ assertThat(crawler.schedule().scheduleExpression()).isEqualTo("cron(30 3 * * ? *)");
+ }
+}
diff --git a/docs/services/glue.md b/docs/services/glue.md
index 9c49f183e9..9716181c07 100644
--- a/docs/services/glue.md
+++ b/docs/services/glue.md
@@ -165,8 +165,23 @@ waiting in `WAITING`.
| CreateCrawler | Creates a new crawler with specified targets, role, configuration, and optional schedule. |
| GetCrawler | Retrieves metadata for a specified crawler. |
| GetCrawlers | Retrieves metadata for all crawlers defined in the customer account. |
-| UpdateCrawler | Updates a crawler. |
-| DeleteCrawler | Removes a specified crawler from the AWS Glue Data Catalog. |
+| ListCrawlers | Lists crawler names, optionally only those carrying every given tag. |
+| BatchGetCrawlers | Retrieves several crawlers by name and reports the names not found. |
+| UpdateCrawler | Updates a crawler; refused with `CrawlerRunningException` while a crawl runs. |
+| DeleteCrawler | Removes a crawler and its crawl history; refused with `CrawlerRunningException` while a crawl runs. |
+| StartCrawler | Starts a crawl. |
+| StopCrawler | Stops the running crawl, which is then recorded as `CANCELLED`. |
+| GetCrawlerMetrics | Reports time left, last and median runtime for the named crawlers, or for all of them. |
+| UpdateCrawlerSchedule | Replaces a crawler's cron schedule. |
+| StartCrawlerSchedule | Sets a crawler's schedule to `SCHEDULED`. |
+| StopCrawlerSchedule | Sets a crawler's schedule to `NOT_SCHEDULED`. |
+
+Crawls do not read the data store or write tables. A crawl follows the crawler's state machine:
+`GetCrawler` reports `RUNNING` with `CrawlElapsedTime` while it runs, then `READY` with a `LastCrawl`
+of `SUCCEEDED` (or `CANCELLED` after `StopCrawler`). With the default `crawler-run-duration-seconds` of
+0 a crawl finishes as soon as it starts; a positive value keeps the crawler `RUNNING` that long.
+`GetCrawlerMetrics` reports zero tables created, updated and deleted. Schedules are stored and their
+state can be switched, but a schedule never starts a crawl on its own.
#### Classifiers
@@ -231,6 +246,7 @@ Supported schema formats are `AVRO`, `JSON`, and `PROTOBUF`. Compatibility modes
|---|---|---|
| `FLOCI_SERVICES_GLUE_ENABLED` | `true` | Enable or disable the service |
| `FLOCI_SERVICES_GLUE_JOB_RUN_DURATION_SECONDS` | `0` | Seconds a job run stays `RUNNING` before it succeeds; `0` finishes it as soon as it starts |
+| `FLOCI_SERVICES_GLUE_CRAWLER_RUN_DURATION_SECONDS` | `0` | Seconds a crawl keeps the crawler `RUNNING` before it succeeds; `0` finishes it as soon as it starts |
## Integration with Athena
diff --git a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
index d2842ea2d7..3d3cfe5a58 100644
--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
@@ -1961,6 +1961,10 @@ public interface EmulatorConfig {
/** How long a job run stays RUNNING before it succeeds; 0 = a run succeeds as soon as it starts. */
@WithDefault("0")
int jobRunDurationSeconds();
+
+ /** How long a crawl keeps the crawler RUNNING before it succeeds; 0 = a crawl finishes as soon as it starts. */
+ @WithDefault("0")
+ int crawlerRunDurationSeconds();
}
interface SesServiceConfig {
diff --git a/src/main/java/io/github/hectorvent/floci/services/glue/GlueCrawlerRunService.java b/src/main/java/io/github/hectorvent/floci/services/glue/GlueCrawlerRunService.java
new file mode 100644
index 0000000000..47743793fe
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/glue/GlueCrawlerRunService.java
@@ -0,0 +1,245 @@
+package io.github.hectorvent.floci.services.glue;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import io.github.hectorvent.floci.config.EmulatorConfig;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.storage.StorageBackend;
+import io.github.hectorvent.floci.core.storage.StorageFactory;
+import io.github.hectorvent.floci.services.glue.model.Crawler;
+import io.github.hectorvent.floci.services.glue.model.CrawlerRunRecord;
+import io.github.hectorvent.floci.services.glue.model.LastCrawlInfo;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import org.jboss.logging.Logger;
+
+import java.time.Clock;
+import java.time.Duration;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Glue crawler runs. No data store is crawled and no table is written: a crawl follows the crawler
+ * state machine (READY, RUNNING, back to READY with a LastCrawl status) and settles lazily when
+ * read. With the default {@code crawler-run-duration-seconds} of 0 a crawl finishes as soon as it
+ * starts; a positive duration keeps the crawler RUNNING for that long.
+ *
+ *
Every public method is synchronized. Starting and stopping a crawl, and the crawler mutations
+ * AWS refuses while a crawl runs (UpdateCrawler, DeleteCrawler), check the crawl state and act on
+ * it; the store has no atomic compare and set, so those steps must not interleave.
+ */
+@ApplicationScoped
+public class GlueCrawlerRunService {
+
+ private static final Logger LOG = Logger.getLogger(GlueCrawlerRunService.class);
+
+ static final String STATE_READY = "READY";
+ static final String STATE_RUNNING = "RUNNING";
+ static final String STATUS_SUCCEEDED = "SUCCEEDED";
+ static final String STATUS_CANCELLED = "CANCELLED";
+
+ private static final String LOG_GROUP = "/aws-glue/crawlers";
+ // Enough history for a stable median without letting a long-lived crawler grow without bound.
+ private static final int MAX_RUNTIME_HISTORY = 100;
+
+ private final StorageBackend recordStore;
+ private final GlueService glueService;
+ private final int runDurationSeconds;
+ private final Clock clock;
+
+ @Inject
+ public GlueCrawlerRunService(StorageFactory storageFactory, GlueService glueService, EmulatorConfig config) {
+ this(storageFactory.create("glue", "crawler_runs.json", new TypeReference<>() {}),
+ glueService, config.services().glue().crawlerRunDurationSeconds(), Clock.systemUTC());
+ }
+
+ GlueCrawlerRunService(StorageBackend recordStore, GlueService glueService,
+ int runDurationSeconds, Clock clock) {
+ if (runDurationSeconds < 0) {
+ throw new IllegalArgumentException(
+ "floci.services.glue.crawler-run-duration-seconds must not be negative: " + runDurationSeconds);
+ }
+ this.recordStore = recordStore;
+ this.glueService = glueService;
+ this.runDurationSeconds = runDurationSeconds;
+ this.clock = clock;
+ }
+
+ public synchronized void startCrawler(String name) {
+ glueService.getCrawler(name);
+ CrawlerRunRecord record = settledRecord(name);
+ if (record.getCurrentStart() != null) {
+ throw new AwsException("CrawlerRunningException", "Crawler with name " + name + " has already started", 400);
+ }
+ record.setCurrentStart(clock.instant());
+ record.setCurrentMessagePrefix(UUID.randomUUID().toString());
+ recordStore.put(name, record);
+ LOG.infov("Started Glue crawler {0}", name);
+ settle(record);
+ }
+
+ public synchronized void stopCrawler(String name) {
+ glueService.getCrawler(name);
+ CrawlerRunRecord record = settledRecord(name);
+ if (record.getCurrentStart() == null) {
+ throw new AwsException("CrawlerNotRunningException", "Crawler with name " + name + " isn't running", 400);
+ }
+ finish(record, clock.instant(), STATUS_CANCELLED);
+ LOG.infov("Stopped Glue crawler {0}", name);
+ }
+
+ /** Fills in the crawl state of a crawler read from the store: State, CrawlElapsedTime, LastCrawl. */
+ public synchronized Crawler withRunState(Crawler crawler) {
+ CrawlerRunRecord record = settledRecord(crawler.getName());
+ Instant now = clock.instant();
+ if (record.getCurrentStart() != null) {
+ crawler.setState(STATE_RUNNING);
+ crawler.setCrawlElapsedTime(Duration.between(record.getCurrentStart(), now).toMillis());
+ } else {
+ crawler.setState(STATE_READY);
+ crawler.setCrawlElapsedTime(null);
+ }
+ if (record.getLastStatus() != null) {
+ LastCrawlInfo lastCrawl = new LastCrawlInfo();
+ lastCrawl.setStatus(record.getLastStatus());
+ lastCrawl.setStartTime(record.getLastStart());
+ lastCrawl.setLogGroup(LOG_GROUP);
+ lastCrawl.setLogStream(crawler.getName());
+ lastCrawl.setMessagePrefix(record.getLastMessagePrefix());
+ crawler.setLastCrawl(lastCrawl);
+ } else {
+ crawler.setLastCrawl(null);
+ }
+ return crawler;
+ }
+
+ public synchronized List withRunState(List crawlers) {
+ for (Crawler crawler : crawlers) {
+ withRunState(crawler);
+ }
+ return crawlers;
+ }
+
+ /**
+ * Metrics for the named crawlers, or for every crawler when no names are given. A name that
+ * matches no crawler is skipped: the operation declares no EntityNotFoundException.
+ */
+ public synchronized GlueService.Page