mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
feat(glue): start and stop crawls, crawler metrics, listing and schedules (#4427)
A crawler could be defined but never run: StartCrawler answered InvalidAction and a crawler stayed READY with no LastCrawl. Add StartCrawler, StopCrawler, GetCrawlerMetrics, ListCrawlers, BatchGetCrawlers, UpdateCrawlerSchedule, StartCrawlerSchedule and StopCrawlerSchedule. Crawls follow the crawler state machine without reading data and are settled on read, as job runs are; floci.services.glue.crawler-run-duration-seconds (default 0) can keep a crawler RUNNING. UpdateCrawler and DeleteCrawler are refused while a crawl runs, and DeleteCrawler removes the crawl history. Part of #4380
This commit is contained in:
1 parent
6656c8e5df
commit
93c7b1f93f
13 files changed
+1068
-54
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
* <p>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<String, CrawlerRunRecord> 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<String, CrawlerRunRecord> 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<Crawler> withRunState(List<Crawler> 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<Map<String, Object>> getCrawlerMetrics(List<String> names,
|
||||
Integer maxResults,
|
||||
String nextToken) {
|
||||
List<String> selected = new ArrayList<>();
|
||||
if (names == null || names.isEmpty()) {
|
||||
for (Crawler crawler : glueService.getCrawlers()) {
|
||||
selected.add(crawler.getName());
|
||||
}
|
||||
} else {
|
||||
for (Crawler crawler : glueService.batchGetCrawlers(names).crawlers()) {
|
||||
selected.add(crawler.getName());
|
||||
}
|
||||
}
|
||||
selected.sort(Comparator.naturalOrder());
|
||||
List<Map<String, Object>> metrics = new ArrayList<>();
|
||||
for (String name : selected) {
|
||||
metrics.add(metricsFor(settledRecord(name)));
|
||||
}
|
||||
return glueService.paginate(metrics, maxResults, nextToken);
|
||||
}
|
||||
|
||||
public synchronized void updateCrawler(Crawler update) {
|
||||
requireNotRunning(update.getName());
|
||||
glueService.updateCrawler(update);
|
||||
}
|
||||
|
||||
/** Crawl records belong to their crawler: deleting it removes them, and a running crawler cannot be deleted. */
|
||||
public synchronized void deleteCrawler(String name, String region) {
|
||||
requireNotRunning(name);
|
||||
glueService.deleteCrawler(name, region);
|
||||
recordStore.delete(name);
|
||||
}
|
||||
|
||||
public synchronized void updateCrawlerSchedule(String name, String expression) {
|
||||
glueService.updateCrawlerSchedule(name, expression);
|
||||
}
|
||||
|
||||
public synchronized void startCrawlerSchedule(String name) {
|
||||
glueService.startCrawlerSchedule(name);
|
||||
}
|
||||
|
||||
public synchronized void stopCrawlerSchedule(String name) {
|
||||
glueService.stopCrawlerSchedule(name);
|
||||
}
|
||||
|
||||
private void requireNotRunning(String name) {
|
||||
if (name != null && settledRecord(name).getCurrentStart() != null) {
|
||||
throw new AwsException("CrawlerRunningException", "Crawler with name " + name + " is running", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> metricsFor(CrawlerRunRecord record) {
|
||||
Map<String, Object> metrics = new LinkedHashMap<>();
|
||||
metrics.put("CrawlerName", record.getCrawlerName());
|
||||
double timeLeft = 0;
|
||||
if (record.getCurrentStart() != null) {
|
||||
Instant finishesAt = record.getCurrentStart().plusSeconds(runDurationSeconds);
|
||||
timeLeft = Math.max(0, Duration.between(clock.instant(), finishesAt).toMillis() / 1000.0);
|
||||
}
|
||||
metrics.put("TimeLeftSeconds", timeLeft);
|
||||
metrics.put("StillEstimating", false);
|
||||
List<Double> runtimes = record.getRuntimeSeconds();
|
||||
metrics.put("LastRuntimeSeconds", runtimes.isEmpty() ? 0.0 : runtimes.getLast());
|
||||
metrics.put("MedianRuntimeSeconds", median(runtimes));
|
||||
metrics.put("TablesCreated", 0);
|
||||
metrics.put("TablesUpdated", 0);
|
||||
metrics.put("TablesDeleted", 0);
|
||||
return metrics;
|
||||
}
|
||||
|
||||
private static double median(List<Double> values) {
|
||||
if (values.isEmpty()) {
|
||||
return 0.0;
|
||||
}
|
||||
List<Double> sorted = new ArrayList<>(values);
|
||||
sorted.sort(Comparator.naturalOrder());
|
||||
int middle = sorted.size() / 2;
|
||||
return sorted.size() % 2 == 1 ? sorted.get(middle) : (sorted.get(middle - 1) + sorted.get(middle)) / 2.0;
|
||||
}
|
||||
|
||||
private CrawlerRunRecord settledRecord(String name) {
|
||||
CrawlerRunRecord record = recordStore.get(name).orElseGet(() -> {
|
||||
CrawlerRunRecord fresh = new CrawlerRunRecord();
|
||||
fresh.setCrawlerName(name);
|
||||
return fresh;
|
||||
});
|
||||
settle(record);
|
||||
return record;
|
||||
}
|
||||
|
||||
private void settle(CrawlerRunRecord record) {
|
||||
if (record.getCurrentStart() == null) {
|
||||
return;
|
||||
}
|
||||
Instant finishesAt = record.getCurrentStart().plusSeconds(runDurationSeconds);
|
||||
if (!clock.instant().isBefore(finishesAt)) {
|
||||
finish(record, finishesAt, STATUS_SUCCEEDED);
|
||||
}
|
||||
}
|
||||
|
||||
private void finish(CrawlerRunRecord record, Instant finishedAt, String status) {
|
||||
List<Double> runtimes = new ArrayList<>(record.getRuntimeSeconds());
|
||||
runtimes.add(Duration.between(record.getCurrentStart(), finishedAt).toMillis() / 1000.0);
|
||||
if (runtimes.size() > MAX_RUNTIME_HISTORY) {
|
||||
runtimes.removeFirst();
|
||||
}
|
||||
record.setRuntimeSeconds(runtimes);
|
||||
record.setLastStart(record.getCurrentStart());
|
||||
record.setLastStatus(status);
|
||||
record.setLastMessagePrefix(record.getCurrentMessagePrefix());
|
||||
record.setCurrentStart(null);
|
||||
record.setCurrentMessagePrefix(null);
|
||||
recordStore.put(record.getCrawlerName(), record);
|
||||
}
|
||||
}
|
||||
@@ -32,16 +32,19 @@ public class GlueJsonHandler {
|
||||
|
||||
private final GlueService glueService;
|
||||
private final GlueJobRunService jobRunService;
|
||||
private final GlueCrawlerRunService crawlerRunService;
|
||||
private final GlueSchemaRegistryService schemaRegistryService;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
@Inject
|
||||
public GlueJsonHandler(GlueService glueService,
|
||||
GlueJobRunService jobRunService,
|
||||
GlueCrawlerRunService crawlerRunService,
|
||||
GlueSchemaRegistryService schemaRegistryService,
|
||||
ObjectMapper mapper) {
|
||||
this.glueService = glueService;
|
||||
this.jobRunService = jobRunService;
|
||||
this.crawlerRunService = crawlerRunService;
|
||||
this.schemaRegistryService = schemaRegistryService;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
@@ -302,27 +305,75 @@ public class GlueJsonHandler {
|
||||
}
|
||||
case "GetCrawler" -> {
|
||||
GetCrawlerRequest req = mapper.treeToValue(request, GetCrawlerRequest.class);
|
||||
yield Response.ok(new GetCrawlerResponse(glueService.getCrawler(req.getName()))).build();
|
||||
yield Response.ok(new GetCrawlerResponse(
|
||||
crawlerRunService.withRunState(glueService.getCrawler(req.getName())))).build();
|
||||
}
|
||||
case "GetCrawlers" -> {
|
||||
GetCrawlersRequest req = mapper.treeToValue(request, GetCrawlersRequest.class);
|
||||
GlueService.Page<Crawler> page = glueService.getCrawlers(req.getMaxResults(), req.getNextToken());
|
||||
GetCrawlersResponse res = new GetCrawlersResponse();
|
||||
res.setCrawlers(page.items());
|
||||
res.setCrawlers(crawlerRunService.withRunState(page.items()));
|
||||
res.setNextToken(page.nextToken());
|
||||
yield Response.ok(res).build();
|
||||
}
|
||||
case "UpdateCrawler" -> {
|
||||
UpdateCrawlerRequest req = mapper.treeToValue(request, UpdateCrawlerRequest.class);
|
||||
Crawler update = toDomain(req);
|
||||
glueService.updateCrawler(update);
|
||||
crawlerRunService.updateCrawler(update);
|
||||
yield Response.ok().build();
|
||||
}
|
||||
case "DeleteCrawler" -> {
|
||||
DeleteCrawlerRequest req = mapper.treeToValue(request, DeleteCrawlerRequest.class);
|
||||
glueService.deleteCrawler(req.getName(), region);
|
||||
crawlerRunService.deleteCrawler(req.getName(), region);
|
||||
yield Response.ok().build();
|
||||
}
|
||||
case "ListCrawlers" -> {
|
||||
Map<String, String> tags = request.hasNonNull("Tags")
|
||||
? mapper.convertValue(request.get("Tags"), STRING_MAP)
|
||||
: null;
|
||||
GlueService.Page<String> page = glueService.listCrawlers(
|
||||
readMaxResults(request), readNextToken(request), tags, region);
|
||||
yield Response.ok(pageResponse("CrawlerNames", page.items(), page.nextToken())).build();
|
||||
}
|
||||
case "BatchGetCrawlers" -> {
|
||||
List<String> names = request.hasNonNull("CrawlerNames")
|
||||
? mapper.convertValue(request.get("CrawlerNames"), STRING_LIST)
|
||||
: null;
|
||||
GlueService.BatchGetCrawlersResult result = glueService.batchGetCrawlers(names);
|
||||
Map<String, Object> response = new LinkedHashMap<>();
|
||||
response.put("Crawlers", crawlerRunService.withRunState(result.crawlers()));
|
||||
response.put("CrawlersNotFound", result.crawlersNotFound());
|
||||
yield Response.ok(response).build();
|
||||
}
|
||||
case "StartCrawler" -> {
|
||||
crawlerRunService.startCrawler(request.path("Name").asText(null));
|
||||
yield Response.ok(Map.of()).build();
|
||||
}
|
||||
case "StopCrawler" -> {
|
||||
crawlerRunService.stopCrawler(request.path("Name").asText(null));
|
||||
yield Response.ok(Map.of()).build();
|
||||
}
|
||||
case "GetCrawlerMetrics" -> {
|
||||
List<String> names = request.hasNonNull("CrawlerNameList")
|
||||
? mapper.convertValue(request.get("CrawlerNameList"), STRING_LIST)
|
||||
: null;
|
||||
GlueService.Page<Map<String, Object>> page = crawlerRunService.getCrawlerMetrics(
|
||||
names, readMaxResults(request), readNextToken(request));
|
||||
yield Response.ok(pageResponse("CrawlerMetricsList", page.items(), page.nextToken())).build();
|
||||
}
|
||||
case "UpdateCrawlerSchedule" -> {
|
||||
crawlerRunService.updateCrawlerSchedule(request.path("CrawlerName").asText(null),
|
||||
request.path("Schedule").asText(null));
|
||||
yield Response.ok(Map.of()).build();
|
||||
}
|
||||
case "StartCrawlerSchedule" -> {
|
||||
crawlerRunService.startCrawlerSchedule(request.path("CrawlerName").asText(null));
|
||||
yield Response.ok(Map.of()).build();
|
||||
}
|
||||
case "StopCrawlerSchedule" -> {
|
||||
crawlerRunService.stopCrawlerSchedule(request.path("CrawlerName").asText(null));
|
||||
yield Response.ok(Map.of()).build();
|
||||
}
|
||||
case "CreateConnection" -> handleCreateConnection(request, region);
|
||||
case "GetConnection" -> handleGetConnection(request);
|
||||
case "GetConnections" -> handleGetConnections(request);
|
||||
|
||||
@@ -26,6 +26,7 @@ import io.github.hectorvent.floci.services.glue.model.KeySchemaElement;
|
||||
import io.github.hectorvent.floci.services.glue.model.Partition;
|
||||
import io.github.hectorvent.floci.services.glue.model.PartitionIndex;
|
||||
import io.github.hectorvent.floci.services.glue.model.PartitionIndexDescriptor;
|
||||
import io.github.hectorvent.floci.services.glue.model.Schedule;
|
||||
import io.github.hectorvent.floci.services.glue.model.SchemaReference;
|
||||
import io.github.hectorvent.floci.services.glue.model.SecurityConfiguration;
|
||||
import io.github.hectorvent.floci.services.glue.model.StorageDescriptor;
|
||||
@@ -149,6 +150,12 @@ public class GlueService {
|
||||
private static final String INDEX_STATUS_ACTIVE = "ACTIVE";
|
||||
private static final String INDEX_STATUS_DELETING = "DELETING";
|
||||
|
||||
private static final String SCHEDULE_SCHEDULED = "SCHEDULED";
|
||||
private static final String SCHEDULE_NOT_SCHEDULED = "NOT_SCHEDULED";
|
||||
private static final Pattern CRON_FIELD = Pattern.compile("[0-9A-Za-z*?/,#-]+");
|
||||
// BatchGetCrawlers takes a CrawlerNameList, which the API model caps at 100 names.
|
||||
private static final int MAX_BATCH_GET_CRAWLERS = 100;
|
||||
|
||||
private final StorageBackend<String, Database> databaseStore;
|
||||
private final StorageBackend<String, Table> tableStore;
|
||||
private final StorageBackend<String, Table> tableVersionStore;
|
||||
@@ -2037,6 +2044,110 @@ public class GlueService {
|
||||
return paginate(all, maxResults, nextToken);
|
||||
}
|
||||
|
||||
public Page<String> listCrawlers(Integer maxResults, String nextToken, Map<String, String> tags,
|
||||
String region) {
|
||||
List<String> names = new ArrayList<>();
|
||||
for (Crawler crawler : crawlerStore.scan(k -> true)) {
|
||||
if (tags == null || tags.isEmpty() || hasTags(crawlerArn(region, crawler.getName()), tags, region)) {
|
||||
names.add(crawler.getName());
|
||||
}
|
||||
}
|
||||
names.sort(Comparator.naturalOrder());
|
||||
return paginate(names, maxResults, nextToken);
|
||||
}
|
||||
|
||||
public BatchGetCrawlersResult batchGetCrawlers(List<String> names) {
|
||||
if (names == null) {
|
||||
throw new AwsException("InvalidInputException", "CrawlerNames is required.", 400);
|
||||
}
|
||||
if (names.size() > MAX_BATCH_GET_CRAWLERS) {
|
||||
throw new AwsException("InvalidInputException",
|
||||
"CrawlerNames must contain at most " + MAX_BATCH_GET_CRAWLERS + " names.", 400);
|
||||
}
|
||||
List<Crawler> crawlers = new ArrayList<>();
|
||||
List<String> notFound = new ArrayList<>();
|
||||
for (String name : names) {
|
||||
Optional<Crawler> crawler = name == null ? Optional.empty() : crawlerStore.get(name);
|
||||
if (crawler.isPresent()) {
|
||||
crawlers.add(crawler.get());
|
||||
} else {
|
||||
notFound.add(name);
|
||||
}
|
||||
}
|
||||
return new BatchGetCrawlersResult(crawlers, notFound);
|
||||
}
|
||||
|
||||
public record BatchGetCrawlersResult(List<Crawler> crawlers, List<String> crawlersNotFound) {}
|
||||
|
||||
public void updateCrawlerSchedule(String name, String expression) {
|
||||
validateRequired(name, "CrawlerName");
|
||||
Crawler crawler = getCrawler(name);
|
||||
if (expression == null || expression.isBlank()) {
|
||||
crawler.setSchedule(null);
|
||||
} else {
|
||||
validateCronExpression(expression);
|
||||
Schedule schedule = crawler.getSchedule() != null ? crawler.getSchedule() : new Schedule();
|
||||
schedule.setScheduleExpression(expression);
|
||||
if (schedule.getState() == null) {
|
||||
schedule.setState(SCHEDULE_SCHEDULED);
|
||||
}
|
||||
crawler.setSchedule(schedule);
|
||||
}
|
||||
crawler.setLastUpdated(Instant.now());
|
||||
crawlerStore.put(name, crawler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Glue schedules are AWS cron expressions: cron(Minutes Hours Day-of-month Month Day-of-week Year),
|
||||
* with {@code ?} in exactly one of the two day fields.
|
||||
*/
|
||||
static void validateCronExpression(String expression) {
|
||||
String message = "Schedule must be a cron expression, for example cron(15 12 * * ? *).";
|
||||
if (expression == null || !expression.startsWith("cron(") || !expression.endsWith(")")) {
|
||||
throw new AwsException("InvalidInputException", message, 400);
|
||||
}
|
||||
String[] fields = expression.substring(5, expression.length() - 1).trim().split("\\s+");
|
||||
if (fields.length != 6) {
|
||||
throw new AwsException("InvalidInputException", message, 400);
|
||||
}
|
||||
for (String field : fields) {
|
||||
if (!CRON_FIELD.matcher(field).matches()) {
|
||||
throw new AwsException("InvalidInputException", message, 400);
|
||||
}
|
||||
}
|
||||
if ("?".equals(fields[2]) == "?".equals(fields[4])) {
|
||||
throw new AwsException("InvalidInputException",
|
||||
"Exactly one of day-of-month and day-of-week must be '?' in " + expression, 400);
|
||||
}
|
||||
}
|
||||
|
||||
public void startCrawlerSchedule(String name) {
|
||||
validateRequired(name, "CrawlerName");
|
||||
Crawler crawler = getCrawler(name);
|
||||
Schedule schedule = crawler.getSchedule();
|
||||
if (schedule == null || schedule.getScheduleExpression() == null) {
|
||||
throw new AwsException("NoScheduleException", "Crawler " + name + " has no schedule.", 400);
|
||||
}
|
||||
if (SCHEDULE_SCHEDULED.equals(schedule.getState())) {
|
||||
throw new AwsException("SchedulerRunningException",
|
||||
"The schedule of crawler " + name + " is already running.", 400);
|
||||
}
|
||||
schedule.setState(SCHEDULE_SCHEDULED);
|
||||
crawlerStore.put(name, crawler);
|
||||
}
|
||||
|
||||
public void stopCrawlerSchedule(String name) {
|
||||
validateRequired(name, "CrawlerName");
|
||||
Crawler crawler = getCrawler(name);
|
||||
Schedule schedule = crawler.getSchedule();
|
||||
if (schedule == null || !SCHEDULE_SCHEDULED.equals(schedule.getState())) {
|
||||
throw new AwsException("SchedulerNotRunningException",
|
||||
"The schedule of crawler " + name + " is not running.", 400);
|
||||
}
|
||||
schedule.setState(SCHEDULE_NOT_SCHEDULED);
|
||||
crawlerStore.put(name, crawler);
|
||||
}
|
||||
|
||||
public void updateCrawler(Crawler update) {
|
||||
validateRequired(update.getName(), "Name");
|
||||
// Jobs and crawlers skip normalizeName because AWS preserves their case
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package io.github.hectorvent.floci.services.glue.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Floci's own bookkeeping for a crawler's crawls; never sent on the wire. The crawl in progress (if
|
||||
* any), the last finished crawl, and the runtimes GetCrawlerMetrics summarises.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
public class CrawlerRunRecord {
|
||||
private String crawlerName;
|
||||
private Instant currentStart;
|
||||
private String currentMessagePrefix;
|
||||
private Instant lastStart;
|
||||
private String lastStatus;
|
||||
private String lastMessagePrefix;
|
||||
private List<Double> runtimeSeconds = new ArrayList<>();
|
||||
|
||||
public CrawlerRunRecord() {}
|
||||
|
||||
public String getCrawlerName() { return crawlerName; }
|
||||
public void setCrawlerName(String crawlerName) { this.crawlerName = crawlerName; }
|
||||
|
||||
public Instant getCurrentStart() { return currentStart; }
|
||||
public void setCurrentStart(Instant currentStart) { this.currentStart = currentStart; }
|
||||
|
||||
public String getCurrentMessagePrefix() { return currentMessagePrefix; }
|
||||
public void setCurrentMessagePrefix(String currentMessagePrefix) { this.currentMessagePrefix = currentMessagePrefix; }
|
||||
|
||||
public Instant getLastStart() { return lastStart; }
|
||||
public void setLastStart(Instant lastStart) { this.lastStart = lastStart; }
|
||||
|
||||
public String getLastStatus() { return lastStatus; }
|
||||
public void setLastStatus(String lastStatus) { this.lastStatus = lastStatus; }
|
||||
|
||||
public String getLastMessagePrefix() { return lastMessagePrefix; }
|
||||
public void setLastMessagePrefix(String lastMessagePrefix) { this.lastMessagePrefix = lastMessagePrefix; }
|
||||
|
||||
public List<Double> getRuntimeSeconds() { return runtimeSeconds; }
|
||||
public void setRuntimeSeconds(List<Double> runtimeSeconds) { this.runtimeSeconds = runtimeSeconds; }
|
||||
}
|
||||
Reference in new issue
Block a user