mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(ecs): reconcile persisted services at boot (#4501)
* fix(ecs): reconcile persisted services at boot EcsService is ApplicationScoped, so Quarkus only creates it on the first ECS request, and creating it is what loads the ECS stores and starts the reconciler. After a restart every persisted service stayed without tasks, load balancer targets or Cloud Map instances until something called the ECS API. EmulatorLifecycle now calls EcsService.restorePersistedRuntime() after storage is loaded and the load balancers are restored, the way it already restores RDS, ElastiCache and ELBv2. * test(ecs): assert boot starts the ECS reconciler through CDI
This commit is contained in:
1 parent
2895262064
commit
52225e2053
6 files changed
+127
-1
No files matched your search
@@ -9,6 +9,7 @@ import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.lifecycle.inithook.InitializationHook;
|
||||
import io.github.hectorvent.floci.lifecycle.inithook.InitializationHooksRunner;
|
||||
import io.github.hectorvent.floci.services.ec2.Ec2MetadataServer;
|
||||
import io.github.hectorvent.floci.services.ecs.EcsService;
|
||||
import io.github.hectorvent.floci.services.ecs.container.EcsTaskRoleCredentialsServer;
|
||||
import io.github.hectorvent.floci.services.ecr.registry.EcrRegistryManager;
|
||||
import io.github.hectorvent.floci.services.floci.ui.FlociUiManager;
|
||||
@@ -93,6 +94,7 @@ public class EmulatorLifecycle {
|
||||
private final RdsService rdsService;
|
||||
private final TimestreamInfluxDbService timestreamInfluxDbService;
|
||||
private final ElbV2Service elbV2Service;
|
||||
private final EcsService ecsService;
|
||||
private final ElbClassicService elbClassicService;
|
||||
private final InitializationHooksRunner initializationHooksRunner;
|
||||
private final SqsEventSourcePoller sqsPoller;
|
||||
@@ -133,6 +135,7 @@ public class EmulatorLifecycle {
|
||||
TimestreamInfluxDbService timestreamInfluxDbService,
|
||||
ElbV2Service elbV2Service,
|
||||
ElbClassicService elbClassicService,
|
||||
EcsService ecsService,
|
||||
InitializationHooksRunner initializationHooksRunner,
|
||||
SqsEventSourcePoller sqsPoller,
|
||||
KinesisEventSourcePoller kinesisPoller,
|
||||
@@ -171,6 +174,7 @@ public class EmulatorLifecycle {
|
||||
this.timestreamInfluxDbService = timestreamInfluxDbService;
|
||||
this.elbV2Service = elbV2Service;
|
||||
this.elbClassicService = elbClassicService;
|
||||
this.ecsService = ecsService;
|
||||
this.initializationHooksRunner = initializationHooksRunner;
|
||||
this.sqsPoller = sqsPoller;
|
||||
this.kinesisPoller = kinesisPoller;
|
||||
@@ -259,6 +263,10 @@ public class EmulatorLifecycle {
|
||||
if (config.services().elb().enabled()) {
|
||||
elbClassicService.restorePersistedRuntime();
|
||||
}
|
||||
// After the load balancers: the reconciler registers the tasks it starts as their targets.
|
||||
if (config.services().ecs().enabled()) {
|
||||
ecsService.restorePersistedRuntime();
|
||||
}
|
||||
|
||||
if (isMetadataServerNeeded()) {
|
||||
ec2MetadataServer.start().exceptionally(ex -> {
|
||||
|
||||
@@ -348,6 +348,22 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Brings persisted services back to their desired count after a restart. Invoked from
|
||||
* {@code EmulatorLifecycle} once storage is loaded. The bean is created lazily, so without this
|
||||
* call neither the ECS stores nor the reconciler start until the first ECS request, and every
|
||||
* persisted service stays without tasks until then. Creating the bean loads the stores and
|
||||
* schedules the reconciler; this reports what that reconciler picks up.
|
||||
*/
|
||||
public void restorePersistedRuntime() {
|
||||
int persistedServices = servicesStore == null
|
||||
? services.size()
|
||||
: servicesStore.scanAllAccountEntries(key -> true).size();
|
||||
if (persistedServices > 0) {
|
||||
LOG.infov("Reconciling {0} persisted ECS service(s)", persistedServices);
|
||||
}
|
||||
}
|
||||
|
||||
boolean isReconcilerShutdown() {
|
||||
return reconciler.isShutdown();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user