mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(floci-core): implement state reset and nuke endpoints (#1482)
* feat(floci-core): implement state reset and nuke endpoints * feat(floci-core): implement core interface to handle service wide state clearing when the emulator's state is reset * feat(floci-core): genericize state reset via Resettable interface
This commit is contained in:
1 parent
398100100a
commit
f4c7a84de6
24 files changed
+295
-23
No files matched your search
@@ -0,0 +1,9 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
/**
|
||||
* Interface for services or components that hold in-memory state
|
||||
* and need to be cleared when the emulator state is reset or nuked.
|
||||
*/
|
||||
public interface Resettable {
|
||||
void clear();
|
||||
}
|
||||
@@ -100,6 +100,14 @@ public class StorageFactory {
|
||||
}
|
||||
}
|
||||
|
||||
/** Clear all storage backends. */
|
||||
public void clearAll() {
|
||||
for (StorageBackend<?, ?> backend : allBackends) {
|
||||
backend.clear();
|
||||
}
|
||||
flushAll();
|
||||
}
|
||||
|
||||
/** Shutdown all managed backends (stop schedulers, close connections). */
|
||||
public void shutdownAll() {
|
||||
for (HybridStorage<?, ?> hybrid : hybridBackends) {
|
||||
|
||||
@@ -9,6 +9,11 @@ import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import jakarta.enterprise.inject.Instance;
|
||||
import jakarta.ws.rs.POST;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -20,10 +25,18 @@ public class EmulatorInfoController {
|
||||
private final InitLifecycleState initLifecycleState;
|
||||
private final String version;
|
||||
|
||||
private final StorageFactory storageFactory;
|
||||
private final Instance<Resettable> resettables;
|
||||
|
||||
@Inject
|
||||
public EmulatorInfoController(ServiceRegistry serviceRegistry, InitLifecycleState initLifecycleState) {
|
||||
public EmulatorInfoController(ServiceRegistry serviceRegistry,
|
||||
InitLifecycleState initLifecycleState,
|
||||
StorageFactory storageFactory,
|
||||
Instance<Resettable> resettables) {
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.initLifecycleState = initLifecycleState;
|
||||
this.storageFactory = storageFactory;
|
||||
this.resettables = resettables;
|
||||
this.version = resolveVersion();
|
||||
}
|
||||
|
||||
@@ -77,6 +90,26 @@ public class EmulatorInfoController {
|
||||
return Response.ok(Map.of()).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/state/reset")
|
||||
public Response reset() {
|
||||
performReset();
|
||||
return Response.ok(Map.of("status", "OK")).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/state/nuke")
|
||||
public Response nuke() {
|
||||
return reset();
|
||||
}
|
||||
|
||||
private void performReset() {
|
||||
for (Resettable r : resettables) {
|
||||
r.clear();
|
||||
}
|
||||
storageFactory.clearAll();
|
||||
}
|
||||
|
||||
static String resolveVersion() {
|
||||
String env = System.getenv("FLOCI_VERSION");
|
||||
if (env != null && !env.isBlank()) {
|
||||
|
||||
+13
-1
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.services.apigatewayv2.websocket;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import io.vertx.core.http.ServerWebSocket;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import org.jboss.logging.Logger;
|
||||
@@ -12,7 +13,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* Tracks connection metadata and live socket references.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class WebSocketConnectionManager {
|
||||
public class WebSocketConnectionManager implements Resettable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(WebSocketConnectionManager.class);
|
||||
|
||||
@@ -46,6 +47,17 @@ public class WebSocketConnectionManager {
|
||||
LOG.debugv("Unregistered WebSocket connection {0}", connectionId);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
sockets.values().forEach(ws -> {
|
||||
try {
|
||||
ws.close();
|
||||
} catch (Exception ignored) {}
|
||||
});
|
||||
connections.clear();
|
||||
sockets.clear();
|
||||
serverInitiatedCloses.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a text message to the specified connection.
|
||||
*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.elbv2;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import io.github.hectorvent.floci.services.ec2.Ec2Service;
|
||||
import io.github.hectorvent.floci.services.elbv2.model.TargetDescription;
|
||||
import io.github.hectorvent.floci.services.elbv2.model.TargetGroup;
|
||||
@@ -18,7 +19,7 @@ import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@ApplicationScoped
|
||||
public class ElbV2HealthChecker {
|
||||
public class ElbV2HealthChecker implements Resettable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(ElbV2HealthChecker.class);
|
||||
|
||||
@@ -71,6 +72,12 @@ public class ElbV2HealthChecker {
|
||||
states.remove(tgArn);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
timers.values().forEach(vertx::cancelTimer);
|
||||
timers.clear();
|
||||
states.clear();
|
||||
}
|
||||
|
||||
public void addTargets(String tgArn, List<TargetDescription> targets, TargetGroup tg) {
|
||||
if (config.services().elbv2().mock()) {
|
||||
return;
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.eventbridge;
|
||||
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.Resettable;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.Rule;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.RuleState;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.Target;
|
||||
@@ -20,7 +21,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@ApplicationScoped
|
||||
public class RuleScheduler {
|
||||
public class RuleScheduler implements Resettable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(RuleScheduler.class);
|
||||
|
||||
@@ -48,6 +49,11 @@ public class RuleScheduler {
|
||||
LOG.info("RuleScheduler shut down, all timers cancelled");
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
scheduleContexts.values().forEach(ctx -> vertx.cancelTimer(ctx.timerId));
|
||||
scheduleContexts.clear();
|
||||
}
|
||||
|
||||
public void startScheduler(String ruleArn, String scheduleExpr,
|
||||
Supplier<ScheduleData> dataSupplier) {
|
||||
if (scheduleContexts.containsKey(ruleArn)) {
|
||||
|
||||
+8
-1
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.lambda;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import io.github.hectorvent.floci.services.dynamodb.DynamoDbStreamService;
|
||||
import io.github.hectorvent.floci.services.dynamodb.model.DynamoDbStreamRecord;
|
||||
import io.github.hectorvent.floci.services.lambda.model.EventSourceMapping;
|
||||
@@ -23,7 +24,7 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@ApplicationScoped
|
||||
public class DynamoDbStreamsEventSourcePoller {
|
||||
public class DynamoDbStreamsEventSourcePoller implements Resettable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(DynamoDbStreamsEventSourcePoller.class);
|
||||
|
||||
@@ -74,6 +75,12 @@ public class DynamoDbStreamsEventSourcePoller {
|
||||
timerIds.clear();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
timerIds.values().forEach(vertx::cancelTimer);
|
||||
timerIds.clear();
|
||||
activePolls.clear();
|
||||
}
|
||||
|
||||
public void startPolling(EventSourceMapping esm) {
|
||||
if (timerIds.containsKey(esm.getUuid())) {
|
||||
return;
|
||||
|
||||
+8
-1
@@ -5,6 +5,7 @@ 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.Resettable;
|
||||
import io.github.hectorvent.floci.services.kinesis.KinesisService;
|
||||
import io.github.hectorvent.floci.services.kinesis.model.KinesisRecord;
|
||||
import io.github.hectorvent.floci.services.kinesis.model.KinesisShard;
|
||||
@@ -27,7 +28,7 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@ApplicationScoped
|
||||
public class KinesisEventSourcePoller {
|
||||
public class KinesisEventSourcePoller implements Resettable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(KinesisEventSourcePoller.class);
|
||||
|
||||
@@ -77,6 +78,12 @@ public class KinesisEventSourcePoller {
|
||||
timerIds.clear();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
timerIds.values().forEach(vertx::cancelTimer);
|
||||
timerIds.clear();
|
||||
activePolls.clear();
|
||||
}
|
||||
|
||||
public void startPolling(EventSourceMapping esm) {
|
||||
if (timerIds.containsKey(esm.getUuid())) return;
|
||||
String uuid = esm.getUuid();
|
||||
|
||||
+11
-1
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.lambda;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import io.github.hectorvent.floci.services.lambda.model.LambdaFunction;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -33,7 +34,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
* </ul>
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class LambdaConcurrencyLimiter {
|
||||
public class LambdaConcurrencyLimiter implements Resettable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(LambdaConcurrencyLimiter.class);
|
||||
/** Tracks malformed ARNs already logged so the warn fires once per unique input. */
|
||||
@@ -238,6 +239,15 @@ public class LambdaConcurrencyLimiter {
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
synchronized (reservedLock) {
|
||||
inflight.clear();
|
||||
reservedByRegion.clear();
|
||||
regionReservedTotal.clear();
|
||||
unreservedByRegion.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public int totalReserved(String region) {
|
||||
return regionTotal(region).get();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.services.lambda;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
@@ -16,7 +17,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* Wraps the storage backend for Lambda functions with region-aware key logic.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class LambdaFunctionStore {
|
||||
public class LambdaFunctionStore implements Resettable {
|
||||
|
||||
private final StorageBackend<String, LambdaFunction> backend;
|
||||
private final ConcurrentHashMap<String, LambdaFunction> urlIdIndex = new ConcurrentHashMap<>();
|
||||
@@ -41,6 +42,10 @@ public class LambdaFunctionStore {
|
||||
all.forEach(this::indexFunction);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
urlIdIndex.clear();
|
||||
}
|
||||
|
||||
private void indexFunction(LambdaFunction fn) {
|
||||
if (fn.getUrlConfig() != null && fn.getUrlConfig().getFunctionUrl() != null) {
|
||||
String urlId = extractUrlId(fn.getUrlConfig().getFunctionUrl());
|
||||
|
||||
@@ -4,6 +4,7 @@ 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.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.lambda.model.EventSourceMapping;
|
||||
import io.github.hectorvent.floci.services.lambda.model.InvocationType;
|
||||
@@ -31,7 +32,7 @@ import java.util.concurrent.Executors;
|
||||
* to avoid a circular CDI dependency.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class SqsEventSourcePoller {
|
||||
public class SqsEventSourcePoller implements Resettable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(SqsEventSourcePoller.class);
|
||||
|
||||
@@ -89,6 +90,12 @@ public class SqsEventSourcePoller {
|
||||
LOG.info("SqsEventSourcePoller shut down, all timers cancelled");
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
timerIds.values().forEach(vertx::cancelTimer);
|
||||
timerIds.clear();
|
||||
activePolls.clear();
|
||||
}
|
||||
|
||||
public void startPolling(EventSourceMapping esm) {
|
||||
if (timerIds.containsKey(esm.getUuid())) {
|
||||
return; // already polling
|
||||
|
||||
@@ -7,6 +7,7 @@ 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.Resettable;
|
||||
import io.github.hectorvent.floci.services.dynamodb.DynamoDbStreamService;
|
||||
import io.github.hectorvent.floci.services.kinesis.KinesisService;
|
||||
import io.github.hectorvent.floci.services.pipes.model.DesiredState;
|
||||
@@ -38,7 +39,7 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@ApplicationScoped
|
||||
public class PipesPoller {
|
||||
public class PipesPoller implements Resettable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(PipesPoller.class);
|
||||
private static final long POLL_INTERVAL_MS = 1000;
|
||||
@@ -92,6 +93,14 @@ public class PipesPoller {
|
||||
LOG.info("PipesPoller shut down");
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
timerIds.values().forEach(vertx::cancelTimer);
|
||||
timerIds.clear();
|
||||
activePolls.clear();
|
||||
kinesisIterators.clear();
|
||||
dynamoDbIterators.clear();
|
||||
}
|
||||
|
||||
public void startPolling(Pipe pipe) {
|
||||
String pipeKey = pipeKey(pipe);
|
||||
if (timerIds.containsKey(pipeKey)) {
|
||||
|
||||
@@ -26,6 +26,7 @@ import io.github.hectorvent.floci.services.rds.model.DbSubnetGroup;
|
||||
import io.github.hectorvent.floci.services.rds.proxy.RdsProxyManager;
|
||||
import io.github.hectorvent.floci.services.secretsmanager.SecretsManagerService;
|
||||
import io.github.hectorvent.floci.services.secretsmanager.model.Secret;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
@@ -48,7 +49,7 @@ import java.util.regex.Pattern;
|
||||
* Starts DB containers and auth proxies on creation.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class RdsService {
|
||||
public class RdsService implements Resettable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(RdsService.class);
|
||||
private static final ObjectMapper JSON = new ObjectMapper();
|
||||
@@ -143,6 +144,10 @@ public class RdsService {
|
||||
restoreInstances();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
usedPorts.clear();
|
||||
}
|
||||
|
||||
// ── DB Instances ──────────────────────────────────────────────────────────
|
||||
|
||||
public DbInstance createDbInstance(String id, String engineParam, String engineVersion,
|
||||
|
||||
@@ -8,6 +8,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.secretsmanager.SecretsManagerService;
|
||||
import io.github.hectorvent.floci.services.secretsmanager.model.SecretVersion;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
@@ -29,7 +30,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ApplicationScoped
|
||||
public class RdsDataService {
|
||||
public class RdsDataService implements Resettable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(RdsDataService.class);
|
||||
|
||||
@@ -88,6 +89,18 @@ public class RdsDataService {
|
||||
});
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
transactions.forEach((id, tx) -> {
|
||||
synchronized (tx) {
|
||||
if (transactions.remove(id, tx)) {
|
||||
rollbackQuietly(tx.connection);
|
||||
closeQuietly(tx.connection);
|
||||
}
|
||||
}
|
||||
});
|
||||
transactions.clear();
|
||||
}
|
||||
|
||||
public ObjectNode executeStatement(JsonNode request, String region) {
|
||||
rejectUnsupportedOptions(request);
|
||||
|
||||
|
||||
+6
-1
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.resourcegroupstagging;
|
||||
|
||||
import io.github.hectorvent.floci.services.resourcegroupstagging.model.ResourceTagMapping;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -9,7 +10,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ApplicationScoped
|
||||
public class ResourceGroupsTaggingService {
|
||||
public class ResourceGroupsTaggingService implements Resettable {
|
||||
|
||||
// region::arn → ResourceTagMapping
|
||||
private final Map<String, ResourceTagMapping> store = new ConcurrentHashMap<>();
|
||||
@@ -44,6 +45,10 @@ public class ResourceGroupsTaggingService {
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
store.clear();
|
||||
}
|
||||
|
||||
// ─── GetResources ──────────────────────────────────────────────────────────
|
||||
|
||||
public record TagFilter(String key, List<String> values) {}
|
||||
|
||||
@@ -7,6 +7,7 @@ import io.github.hectorvent.floci.core.common.AwsNamespaces;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.XmlBuilder;
|
||||
import io.github.hectorvent.floci.core.common.XmlParser;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.lambda.LambdaService;
|
||||
@@ -40,7 +41,7 @@ import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@ApplicationScoped
|
||||
public class S3Service {
|
||||
public class S3Service implements Resettable {
|
||||
private String ownerId() { return regionResolver != null ? regionResolver.getAccountId() : "000000000000"; }
|
||||
private static final String DEFAULT_OWNER_DISPLAY_NAME = "floci";
|
||||
private static final String ALL_USERS_GROUP_URI = "http://acs.amazonaws.com/groups/global/AllUsers";
|
||||
@@ -159,6 +160,12 @@ public class S3Service {
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
memoryDataStore.clear();
|
||||
memoryMultipartStore.clear();
|
||||
multipartUploads.clear();
|
||||
}
|
||||
|
||||
public Bucket createBucket(String bucketName, String region) {
|
||||
var existing = bucketStore.get(bucketName);
|
||||
if (existing.isPresent()) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.scheduler;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import io.github.hectorvent.floci.services.scheduler.SchedulerExpressionParser.Kind;
|
||||
import io.github.hectorvent.floci.services.scheduler.model.Schedule;
|
||||
import io.quarkus.runtime.ShutdownEvent;
|
||||
@@ -40,7 +41,7 @@ import java.util.concurrent.TimeUnit;
|
||||
* </ul>
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class ScheduleDispatcher {
|
||||
public class ScheduleDispatcher implements Resettable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(ScheduleDispatcher.class);
|
||||
|
||||
@@ -81,6 +82,11 @@ public class ScheduleDispatcher {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
lastFireByArn.clear();
|
||||
firedOnceByArn.clear();
|
||||
}
|
||||
|
||||
void tickSafely() {
|
||||
try {
|
||||
tick(Instant.now());
|
||||
|
||||
@@ -4,6 +4,7 @@ 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.common.Resettable;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.lambda.LambdaService;
|
||||
@@ -50,7 +51,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||
|
||||
@ApplicationScoped
|
||||
public class SnsService {
|
||||
public class SnsService implements Resettable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(SnsService.class);
|
||||
private static final Duration FIFO_DEDUP_WINDOW = Duration.ofMinutes(5);
|
||||
@@ -159,6 +160,11 @@ public class SnsService {
|
||||
this.httpClient = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).build();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
pushCapture.clear();
|
||||
fifoDeduplicationCache.clear();
|
||||
}
|
||||
|
||||
public Topic createTopic(String name, Map<String, String> attributes,
|
||||
Map<String, String> tags, String region) {
|
||||
if (name == null || name.isBlank()) {
|
||||
|
||||
@@ -4,6 +4,7 @@ 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.common.Resettable;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
@@ -26,7 +27,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
@ApplicationScoped
|
||||
public class SqsService {
|
||||
public class SqsService implements Resettable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(SqsService.class);
|
||||
private static final int DEDUP_WINDOW_SECONDS = 300; // 5 minutes
|
||||
@@ -128,6 +129,17 @@ public class SqsService {
|
||||
loadPersistedDedup();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
messagesByQueue.values().forEach(GuardedMessageQueue::close);
|
||||
messagesByQueue.clear();
|
||||
queueLocks.clear();
|
||||
redrivePolicyCache.clear();
|
||||
deduplicationCache.clear();
|
||||
moveTaskCancellation.values().forEach(flag -> flag.set(true));
|
||||
moveTaskCancellation.clear();
|
||||
moveTasksByHandle.clear();
|
||||
}
|
||||
|
||||
private void loadPersistedMessages() {
|
||||
if (messageStore == null) {
|
||||
return;
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
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.common.Resettable;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.ssm.model.Command;
|
||||
@@ -37,7 +38,7 @@ import java.util.concurrent.Executors;
|
||||
* - GetMessages / AcknowledgeMessage / SendReply / FailMessage / DeleteMessage (ec2messages, agent side)
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class SsmCommandService {
|
||||
public class SsmCommandService implements Resettable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(SsmCommandService.class);
|
||||
private static final int MIN_TIMEOUT_SECONDS = 30;
|
||||
@@ -76,6 +77,11 @@ public class SsmCommandService {
|
||||
});
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
messageQueues.clear();
|
||||
messageIndex.clear();
|
||||
}
|
||||
|
||||
// ── Agent registration ──────────────────────────────────────────────────
|
||||
|
||||
public void updateInstanceInformation(JsonNode request, String region) {
|
||||
|
||||
+9
-1
@@ -12,6 +12,7 @@ import io.github.hectorvent.floci.services.stepfunctions.model.ActivityTask;
|
||||
import io.github.hectorvent.floci.services.stepfunctions.model.Execution;
|
||||
import io.github.hectorvent.floci.services.stepfunctions.model.HistoryEvent;
|
||||
import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
@@ -29,7 +30,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ApplicationScoped
|
||||
public class StepFunctionsService {
|
||||
public class StepFunctionsService implements Resettable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(StepFunctionsService.class);
|
||||
|
||||
@@ -62,6 +63,13 @@ public class StepFunctionsService {
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
historyCache.clear();
|
||||
activityQueues.clear();
|
||||
pendingTaskTokens.values().forEach(f -> f.completeExceptionally(new RuntimeException("StepFunctionsService cleared")));
|
||||
pendingTaskTokens.clear();
|
||||
}
|
||||
|
||||
// ──────────────────────────── State Machines ────────────────────────────
|
||||
|
||||
public StateMachine createStateMachine(String name, String definition, String roleArn, String type, String region, Map<String, String> tags) {
|
||||
|
||||
@@ -3,6 +3,7 @@ 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.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
@@ -17,7 +18,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* @see <a href="https://docs.aws.amazon.com/textract/latest/dg/API_Operations.html">Textract API Reference</a>
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class TextractService {
|
||||
public class TextractService implements Resettable {
|
||||
static final String MODEL_VERSION = "1.0";
|
||||
private final ObjectMapper objectMapper;
|
||||
/** In-memory async job store: jobId to jobType ("TEXT_DETECTION" or "DOCUMENT_ANALYSIS"). */
|
||||
@@ -26,6 +27,9 @@ public class TextractService {
|
||||
public TextractService(ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
public void clear() {
|
||||
asyncJobs.clear();
|
||||
}
|
||||
/**
|
||||
* DetectDocumentText — returns a stub PAGE + LINE + WORD block hierarchy.
|
||||
* Response shape: https://docs.aws.amazon.com/textract/latest/dg/API_DetectDocumentText.html
|
||||
|
||||
@@ -7,6 +7,7 @@ import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.transcribe.model.TranscriptionJob;
|
||||
import io.github.hectorvent.floci.services.transcribe.model.TranscriptionJobSummary;
|
||||
import io.github.hectorvent.floci.services.transcribe.model.VocabularyInfo;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -24,7 +25,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* @see <a href="https://docs.aws.amazon.com/transcribe/latest/APIReference/Welcome.html">Transcribe API</a>
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class TranscribeService {
|
||||
public class TranscribeService implements Resettable {
|
||||
|
||||
private final StorageFactory storageFactory;
|
||||
|
||||
@@ -46,6 +47,11 @@ public class TranscribeService {
|
||||
"transcribe-vocabularies.json", new TypeReference<Map<String, VocabularyInfo>>() {}));
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
transcriptionJobs.clear();
|
||||
vocabularies.clear();
|
||||
}
|
||||
|
||||
public TranscriptionJob startTranscriptionJob(String jobName, String mediaFileUri,
|
||||
String languageCode, String mediaFormat) {
|
||||
requireNonBlank(jobName, "TranscriptionJobName");
|
||||
|
||||
Reference in new issue
Block a user