mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
refactor: read schedules' and pipe sources' Regions with regionOf (#8893)
* refactor: read schedules' and pipe sources' Regions with regionOf
This commit is contained in:
1 parent
466912f939
commit
c0325c5488
9 files changed
+71
-36
No files matched your search
@@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.core.common.AwsArnUtils;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.common.Resettable;
|
||||
import io.floci.aws.services.dynamodb.DynamoDbTtlIdentity;
|
||||
import io.floci.aws.services.dynamodb.backend.DynamoDbStreamReader;
|
||||
@@ -58,7 +59,7 @@ public class PipesPoller implements Resettable {
|
||||
private final PipesFilterMatcher filterMatcher;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final String baseUrl;
|
||||
private final String defaultRegion;
|
||||
private final RegionResolver regionResolver;
|
||||
private volatile LongSupplier clockMs = System::currentTimeMillis;
|
||||
private final ConcurrentHashMap<String, Long> timerIds = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<String, Boolean> activePolls = new ConcurrentHashMap<>();
|
||||
@@ -80,7 +81,8 @@ public class PipesPoller implements Resettable {
|
||||
PipesTargetInvoker targetInvoker,
|
||||
PipesFilterMatcher filterMatcher,
|
||||
ObjectMapper objectMapper,
|
||||
EmulatorConfig config) {
|
||||
EmulatorConfig config,
|
||||
RegionResolver regionResolver) {
|
||||
this.vertx = vertx;
|
||||
this.sqsService = sqsService;
|
||||
this.kinesisService = kinesisService;
|
||||
@@ -90,7 +92,7 @@ public class PipesPoller implements Resettable {
|
||||
this.filterMatcher = filterMatcher;
|
||||
this.objectMapper = objectMapper;
|
||||
this.baseUrl = config.effectiveBaseUrl();
|
||||
this.defaultRegion = config.defaultRegion();
|
||||
this.regionResolver = regionResolver;
|
||||
}
|
||||
|
||||
void setClockForTest(LongSupplier clockMs) {
|
||||
@@ -154,7 +156,8 @@ public class PipesPoller implements Resettable {
|
||||
return;
|
||||
}
|
||||
String sourceArn = pipe.getSource();
|
||||
String region = extractRegionFromArn(sourceArn);
|
||||
// A source that names no Region, such as a self-managed Kafka URI, polls in the default Region.
|
||||
String region = regionResolver.regionOf(sourceArn);
|
||||
if (sourceArn.contains(":sqs:")) {
|
||||
pollSqs(pipe, region);
|
||||
} else if (sourceArn.contains(":kinesis:")) {
|
||||
@@ -757,7 +760,7 @@ public class PipesPoller implements Resettable {
|
||||
List<ObjectNode> nodes = new ArrayList<>();
|
||||
for (Message msg : messages) {
|
||||
nodes.add(SqsEventRecordBuilder.build(objectMapper, msg, pipe.getSource(),
|
||||
extractRegionFromArn(pipe.getSource()), clockMs));
|
||||
regionResolver.regionOf(pipe.getSource()), clockMs));
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
@@ -939,11 +942,6 @@ public class PipesPoller implements Resettable {
|
||||
return pipe.getArn() + "@" + pipe.getCreationTime();
|
||||
}
|
||||
|
||||
/** The region a source ARN names; a source with none, such as a self-managed Kafka URI, polls in the default. */
|
||||
String extractRegionFromArn(String arn) {
|
||||
return AwsArnUtils.regionOrDefault(arn, defaultRegion);
|
||||
}
|
||||
|
||||
/**
|
||||
* The stream a Kinesis source names: the segment after {@code stream/}, so a stream-consumer ARN
|
||||
* ({@code stream/S/consumer/C:123}) still names stream {@code S}.
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.floci.aws.services.scheduler;
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.core.common.AwsArnUtils;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.common.Resettable;
|
||||
import io.floci.aws.services.scheduler.SchedulerExpressionParser.Kind;
|
||||
import io.floci.aws.services.scheduler.model.DeadLetterConfig;
|
||||
@@ -71,7 +72,7 @@ public class ScheduleDispatcher implements Resettable {
|
||||
private final ScheduleInvoker invoker;
|
||||
private final SqsService sqsService;
|
||||
private final String baseUrl;
|
||||
private final String defaultRegion;
|
||||
private final RegionResolver regionResolver;
|
||||
private final long tickIntervalSeconds;
|
||||
private final boolean enabled;
|
||||
private final ScheduledExecutorService executor;
|
||||
@@ -83,12 +84,13 @@ public class ScheduleDispatcher implements Resettable {
|
||||
public ScheduleDispatcher(SchedulerService schedulerService,
|
||||
ScheduleInvoker invoker,
|
||||
SqsService sqsService,
|
||||
EmulatorConfig config) {
|
||||
EmulatorConfig config,
|
||||
RegionResolver regionResolver) {
|
||||
this.schedulerService = schedulerService;
|
||||
this.invoker = invoker;
|
||||
this.sqsService = sqsService;
|
||||
this.baseUrl = config.baseUrl();
|
||||
this.defaultRegion = config.defaultRegion();
|
||||
this.regionResolver = regionResolver;
|
||||
this.tickIntervalSeconds = config.services().scheduler().tickIntervalSeconds();
|
||||
this.enabled = config.services().scheduler().enabled()
|
||||
&& config.services().scheduler().invocationEnabled();
|
||||
@@ -370,7 +372,7 @@ public class ScheduleDispatcher implements Resettable {
|
||||
}
|
||||
|
||||
private String regionOf(Schedule schedule) {
|
||||
return ScheduleInvoker.regionOf(schedule, defaultRegion);
|
||||
return regionResolver.regionOf(schedule.getArn());
|
||||
}
|
||||
|
||||
private record Occurrence(String scheduleArn, Instant scheduledAt) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.core.common.AwsArnUtils;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.common.RequestScopes;
|
||||
import io.floci.aws.core.common.ServiceRegistry;
|
||||
import io.floci.aws.services.ecs.EcsService;
|
||||
@@ -66,7 +67,7 @@ public class ScheduleInvoker {
|
||||
private final RedshiftDataService redshiftDataService;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final String baseUrl;
|
||||
private final String defaultRegion;
|
||||
private final RegionResolver regionResolver;
|
||||
private final ServiceRegistry serviceRegistry;
|
||||
|
||||
@Inject
|
||||
@@ -79,6 +80,7 @@ public class ScheduleInvoker {
|
||||
RedshiftDataService redshiftDataService,
|
||||
ObjectMapper objectMapper,
|
||||
EmulatorConfig config,
|
||||
RegionResolver regionResolver,
|
||||
ServiceRegistry serviceRegistry) {
|
||||
this.sqsService = sqsService;
|
||||
this.lambdaService = lambdaService;
|
||||
@@ -89,7 +91,7 @@ public class ScheduleInvoker {
|
||||
this.redshiftDataService = redshiftDataService;
|
||||
this.objectMapper = objectMapper;
|
||||
this.baseUrl = config.baseUrl();
|
||||
this.defaultRegion = config.defaultRegion();
|
||||
this.regionResolver = regionResolver;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
}
|
||||
|
||||
@@ -113,7 +115,7 @@ public class ScheduleInvoker {
|
||||
return "{}";
|
||||
}
|
||||
String arn = target.getArn();
|
||||
String region = regionOf(schedule, defaultRegion);
|
||||
String region = regionResolver.regionOf(schedule.getArn());
|
||||
String input = contextualInput(schedule, scheduledAt, executionId, attemptNumber);
|
||||
if (isUniversalTarget(arn)) {
|
||||
invokeUniversalTarget(arn.substring(arn.indexOf(":aws-sdk:") + ":aws-sdk:".length()),
|
||||
@@ -570,9 +572,4 @@ public class ScheduleInvoker {
|
||||
private static String extractRegion(String arn, String defaultRegion) {
|
||||
return AwsArnUtils.regionOrDefault(arn, defaultRegion);
|
||||
}
|
||||
|
||||
/** The region a schedule lives in, taken from its ARN; {@code defaultRegion} answers for one without. */
|
||||
static String regionOf(Schedule schedule, String defaultRegion) {
|
||||
return AwsArnUtils.regionOrDefault(schedule.getArn(), defaultRegion);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user