From 88867ae9d7cd5877bc8a677e20a288258e49dfe7 Mon Sep 17 00:00:00 2001 From: Ridwan <49554047+Ridzzz0Alam@users.noreply.github.com> Date: Sun, 15 Nov 2026 18:52:34 +0100 Subject: [PATCH] chore(storage): move EventBridge and Lambda provisioned concurrency onto the shared account helpers (#8476) --- .../eventbridge/EventBridgeService.java | 48 +++++++------------ .../lambda/ProvisionedConcurrencyPool.java | 14 ++---- 2 files changed, 22 insertions(+), 40 deletions(-) diff --git a/src/main/java/io/floci/aws/services/eventbridge/EventBridgeService.java b/src/main/java/io/floci/aws/services/eventbridge/EventBridgeService.java index 89a26f6263..5fee808799 100644 --- a/src/main/java/io/floci/aws/services/eventbridge/EventBridgeService.java +++ b/src/main/java/io/floci/aws/services/eventbridge/EventBridgeService.java @@ -65,6 +65,9 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.regex.Pattern; +import static io.floci.aws.core.storage.AccountAwareStorageBackend.getInAccount; +import static io.floci.aws.core.storage.AccountAwareStorageBackend.putInAccount; + @ApplicationScoped public class EventBridgeService implements ResourceProvider, StoredResourceArns { @@ -1149,7 +1152,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns if ("default".equals(effectiveBus)) { getOrCreateDefaultBus(region); - } else if (accountGet(busStore, accountId, busStoreKey).isEmpty()) { + } else if (getInAccount(busStore, accountId, busStoreKey).isEmpty()) { if (dropForMissingBus) { LOG.infov("PutEvents dropped an event for event bus {0}, which does not exist in {1}", effectiveBus, region); @@ -1178,11 +1181,11 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns } if (matchesPattern(entry, rule.getEventPattern())) { String ruleKey = ruleKey(region, effectiveBus, rule.getName()); - List targets = accountGet(targetStore, accountId, ruleKey).orElse(List.of()); + List targets = getInAccount(targetStore, accountId, ruleKey).orElse(List.of()); String eventJson = buildEventEnvelope(entry, effectiveBus, eventId, region, accountId); for (Target target : targets) { dispatcher.dispatch(rule.getArn(), target, eventJson, region, - () -> accountGet(targetStore, accountId, ruleKey).orElse(List.of())); + () -> getInAccount(targetStore, accountId, ruleKey).orElse(List.of())); } } } @@ -1643,7 +1646,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns public Optional findBusPolicy(String busArn) { AwsArnUtils.Arn arn = AwsArnUtils.parse(busArn); String name = arn.resource().substring("event-bus/".length()); - return accountGet(busStore, arn.accountId(), busKey(arn.region(), name)) + return getInAccount(busStore, arn.accountId(), busKey(arn.region(), name)) .map(EventBus::getPolicy) .filter(policy -> !policy.isBlank()); } @@ -2289,7 +2292,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns private void captureToArchives(Map entry, String busStoreKey, String eventId, String region, String accountId) { - EventBus bus = accountGet(busStore, accountId, busStoreKey).orElse(null); + EventBus bus = getInAccount(busStore, accountId, busStoreKey).orElse(null); if (bus == null) { return; } @@ -2297,7 +2300,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns String archivePrefix = "archive:" + region + ":"; List candidates = accountScan(archiveStore, accountId, k -> k.startsWith(archivePrefix) - && accountGet(archiveStore, accountId, k).map(a -> + && getInAccount(archiveStore, accountId, k).map(a -> a.getState() == ArchiveState.ENABLED && busArn.equals(a.getEventSourceArn())).orElse(false)); @@ -2305,7 +2308,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns if (matchesPattern(entry, archive.getEventPattern())) { String evKey = archivedEventKey(region, archive.getArchiveName()); List stored = new ArrayList<>( - accountGet(archivedEventStore, accountId, evKey).orElse(new ArrayList<>())); + getInAccount(archivedEventStore, accountId, evKey).orElse(new ArrayList<>())); ArchivedEvent ae = new ArchivedEvent( eventId, Instant.now(), @@ -2315,9 +2318,9 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns busArn ); stored.add(ae); - accountPut(archivedEventStore, accountId, evKey, stored); + putInAccount(archivedEventStore, accountId, evKey, stored); archive.setEventCount(archive.getEventCount() + 1); - accountPut(archiveStore, accountId, archiveKey(region, archive.getArchiveName()), archive); + putInAccount(archiveStore, accountId, archiveKey(region, archive.getArchiveName()), archive); } } } @@ -2429,13 +2432,13 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns private void updateReplayStateForAccount(String accountId, String replayName, ReplayState state, String region) { String key = replayKey(region, replayName); - accountGet(replayStore, accountId, key).ifPresent(r -> { + getInAccount(replayStore, accountId, key).ifPresent(r -> { r.setState(state); if (state == ReplayState.COMPLETED || state == ReplayState.CANCELLED || state == ReplayState.FAILED) { r.setReplayEndTime(Instant.now()); } - accountPut(replayStore, accountId, key, r); + putInAccount(replayStore, accountId, key, r); LOG.debugv("Replay {0} transitioned to {1}", replayName, state); }); } @@ -2447,9 +2450,9 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns private void updateReplayLastReplayedForAccount(String accountId, String replayName, Instant eventTime, String region) { String key = replayKey(region, replayName); - accountGet(replayStore, accountId, key).ifPresent(r -> { + getInAccount(replayStore, accountId, key).ifPresent(r -> { r.setEventLastReplayedTime(eventTime); - accountPut(replayStore, accountId, key, r); + putInAccount(replayStore, accountId, key, r); }); } @@ -2493,21 +2496,14 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns rule.getArn(), rule.getScheduleExpression(), () -> { - Rule r = accountGet(ruleStore, accountId, key).orElse(null); - List t = accountGet(targetStore, accountId, key).orElse(List.of()); + Rule r = getInAccount(ruleStore, accountId, key).orElse(null); + List t = getInAccount(targetStore, accountId, key).orElse(List.of()); return new RuleScheduler.ScheduleData(r, t); } ); } } - private Optional accountGet(StorageBackend store, String accountId, String key) { - if (accountId != null && store instanceof AccountAwareStorageBackend aware) { - return aware.getForAccount(accountId, key); - } - return store.get(key); - } - private List accountScan(StorageBackend store, String accountId, Predicate filter) { if (accountId != null && store instanceof AccountAwareStorageBackend aware) { @@ -2516,14 +2512,6 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns return store.scan(filter); } - private void accountPut(StorageBackend store, String accountId, String key, V value) { - if (accountId != null && store instanceof AccountAwareStorageBackend aware) { - aware.putForAccount(accountId, key, value); - } else { - store.put(key, value); - } - } - // ─── Resource Explorer 2 ─────────────────────────────────────────────────── @Override diff --git a/src/main/java/io/floci/aws/services/lambda/ProvisionedConcurrencyPool.java b/src/main/java/io/floci/aws/services/lambda/ProvisionedConcurrencyPool.java index 02df694825..d67194fcf6 100644 --- a/src/main/java/io/floci/aws/services/lambda/ProvisionedConcurrencyPool.java +++ b/src/main/java/io/floci/aws/services/lambda/ProvisionedConcurrencyPool.java @@ -42,6 +42,8 @@ import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import static io.floci.aws.core.storage.AccountAwareStorageBackend.putInAccount; + /** * Owns initialized environments separately from the on-demand idle pool. * Persisted requests never imply readiness: every new process must finish real initialization. @@ -224,7 +226,7 @@ public class ProvisionedConcurrencyPool implements Resettable { && previous.configuration.requested() == count && !"FAILED".equals(previous.status)) { return status(previous); } - write(target); + putInAccount(storage, target.account(), target.key(), target); Allocation next = new Allocation(target); allocations.put(target.key(), next); if (previous != null) { @@ -503,7 +505,7 @@ public class ProvisionedConcurrencyPool implements Resettable { Configuration target = new Configuration(value.account(), value.region(), value.name(), value.functionArn(), value.qualifier(), fn.getVersion(), fn.getRevisionId(), value.requested(), LAST_MODIFIED.format(Instant.ofEpochMilli(clock.millis()))); - write(target); + putInAccount(storage, target.account(), target.key(), target); Allocation next = new Allocation(target); allocations.put(target.key(), next); retired.addAll(retire(previous)); @@ -818,14 +820,6 @@ public class ProvisionedConcurrencyPool implements Resettable { "function:" + fn.getFunctionName()).toString(); } - private void write(Configuration value) { - if (storage instanceof AccountAwareStorageBackend aware) { - aware.putForAccount(value.account(), value.key(), value); - } else { - storage.put(value.key(), value); - } - } - private void erase(Configuration value) { if (storage instanceof AccountAwareStorageBackend aware) { aware.deleteForAccount(value.account(), value.key());