mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(elasticbeanstalk): persist applications, versions, and environments across restart (#1729)
Elastic Beanstalk was the only stateful service wholesale bypassing the storage layer: applications, versions, and environments lived in raw ConcurrentHashMaps, silently lost on restart in persistent/hybrid/wal modes and invisible to the reset endpoint. Wrap all three maps through StorageFactory (storage key 'elasticbeanstalk'), re-put after every in-place mutation so changes reach persistent backends, implement Resettable, register the persisted models for native-image reflection, and wire the storage mode and flush interval through EmulatorConfig, the service catalog, and both YAMLs.
This commit is contained in:
1 parent
89fadbad81
commit
068b76a195
10 files changed
+205
-14
No files matched your search
@@ -210,6 +210,7 @@ public interface EmulatorConfig {
|
||||
CodeDeployStorageConfig codedeploy();
|
||||
TranscribeStorageConfig transcribe();
|
||||
TaggingStorageConfig tagging();
|
||||
ElasticBeanstalkStorageConfig elasticbeanstalk();
|
||||
}
|
||||
|
||||
interface SsmStorageConfig {
|
||||
@@ -397,6 +398,13 @@ public interface EmulatorConfig {
|
||||
long flushIntervalMs();
|
||||
}
|
||||
|
||||
interface ElasticBeanstalkStorageConfig {
|
||||
Optional<String> mode();
|
||||
|
||||
@WithDefault("5000")
|
||||
long flushIntervalMs();
|
||||
}
|
||||
|
||||
interface CodeDeployStorageConfig {
|
||||
Optional<String> mode();
|
||||
|
||||
|
||||
@@ -299,7 +299,9 @@ public class ResolvedServiceCatalog {
|
||||
Set.of(), Set.of("autoscaling"), Set.of(), Set.of()),
|
||||
descriptor("elasticbeanstalk", "elasticbeanstalk",
|
||||
config.services().elasticbeanstalk().enabled(), true,
|
||||
"elasticbeanstalk", config.storage().mode(), 5000L,
|
||||
"elasticbeanstalk",
|
||||
storageMode(config.storage().services().elasticbeanstalk().mode(), config.storage().mode()),
|
||||
config.storage().services().elasticbeanstalk().flushIntervalMs(),
|
||||
AwsNamespaces.ELASTIC_BEANSTALK, ServiceProtocol.QUERY,
|
||||
protocols(ServiceProtocol.QUERY),
|
||||
Set.of(), Set.of("elasticbeanstalk"), Set.of(), Set.of()),
|
||||
|
||||
+51
-13
@@ -1,11 +1,16 @@
|
||||
package io.github.hectorvent.floci.services.elasticbeanstalk;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
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.StorageBackedMap;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.elasticbeanstalk.model.BeanstalkApplication;
|
||||
import io.github.hectorvent.floci.services.elasticbeanstalk.model.BeanstalkApplicationVersion;
|
||||
import io.github.hectorvent.floci.services.elasticbeanstalk.model.BeanstalkEnvironment;
|
||||
import io.github.hectorvent.floci.services.elasticbeanstalk.model.ConfigurationOptionSetting;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
@@ -22,7 +27,7 @@ import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@ApplicationScoped
|
||||
public class ElasticBeanstalkService {
|
||||
public class ElasticBeanstalkService implements Resettable {
|
||||
|
||||
private static final SecureRandom RANDOM = new SecureRandom();
|
||||
private static final String LOWER_ALNUM = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
@@ -30,16 +35,44 @@ public class ElasticBeanstalkService {
|
||||
"64bit Amazon Linux 2023 v4.3.0 running Docker";
|
||||
|
||||
private final RegionResolver regionResolver;
|
||||
private final Map<String, BeanstalkApplication> applications = new ConcurrentHashMap<>();
|
||||
private final Map<String, BeanstalkApplicationVersion> versions = new ConcurrentHashMap<>();
|
||||
private final Map<String, BeanstalkEnvironment> environments = new ConcurrentHashMap<>();
|
||||
private final StorageFactory storageFactory;
|
||||
private Map<String, BeanstalkApplication> applications = new ConcurrentHashMap<>();
|
||||
private Map<String, BeanstalkApplicationVersion> versions = new ConcurrentHashMap<>();
|
||||
private Map<String, BeanstalkEnvironment> environments = new ConcurrentHashMap<>();
|
||||
|
||||
@Inject
|
||||
ElasticBeanstalkService(RegionResolver regionResolver) {
|
||||
ElasticBeanstalkService(RegionResolver regionResolver, StorageFactory storageFactory) {
|
||||
this.regionResolver = regionResolver;
|
||||
this.storageFactory = storageFactory;
|
||||
}
|
||||
|
||||
public BeanstalkApplication createApplication(String region, String name, String description,
|
||||
@PostConstruct
|
||||
void initializeStorage() {
|
||||
if (storageFactory == null) {
|
||||
return; // keeps non-CDI unit tests working
|
||||
}
|
||||
this.applications = new StorageBackedMap<>(storageFactory.create("elasticbeanstalk",
|
||||
"elasticbeanstalk-applications.json",
|
||||
new TypeReference<Map<String, BeanstalkApplication>>() {}));
|
||||
this.versions = new StorageBackedMap<>(storageFactory.create("elasticbeanstalk",
|
||||
"elasticbeanstalk-versions.json",
|
||||
new TypeReference<Map<String, BeanstalkApplicationVersion>>() {}));
|
||||
this.environments = new StorageBackedMap<>(storageFactory.create("elasticbeanstalk",
|
||||
"elasticbeanstalk-environments.json",
|
||||
new TypeReference<Map<String, BeanstalkEnvironment>>() {}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
applications.clear();
|
||||
versions.clear();
|
||||
environments.clear();
|
||||
}
|
||||
|
||||
// Mutators are synchronized: StorageBackedMap has no atomic check-then-put, and
|
||||
// persistent backends return fresh copies on get, so every in-place mutation must be
|
||||
// re-put and the get-mutate-put sequences must not interleave.
|
||||
public synchronized BeanstalkApplication createApplication(String region, String name, String description,
|
||||
Map<String, String> tags) {
|
||||
requireName(name, "ApplicationName");
|
||||
String key = appKey(region, name);
|
||||
@@ -78,16 +111,17 @@ public class ElasticBeanstalkService {
|
||||
.toList();
|
||||
}
|
||||
|
||||
public BeanstalkApplication updateApplication(String region, String name, String description) {
|
||||
public synchronized BeanstalkApplication updateApplication(String region, String name, String description) {
|
||||
BeanstalkApplication app = requireApplication(region, name);
|
||||
if (description != null) {
|
||||
app.setDescription(description);
|
||||
}
|
||||
app.setDateUpdated(Instant.now());
|
||||
applications.put(appKey(region, name), app);
|
||||
return app;
|
||||
}
|
||||
|
||||
public void deleteApplication(String region, String name, boolean terminateEnvByForce) {
|
||||
public synchronized void deleteApplication(String region, String name, boolean terminateEnvByForce) {
|
||||
requireApplication(region, name);
|
||||
List<BeanstalkEnvironment> activeEnvironments = environments.entrySet().stream()
|
||||
.filter(e -> e.getKey().startsWith(region + "::"))
|
||||
@@ -106,7 +140,7 @@ public class ElasticBeanstalkService {
|
||||
versions.entrySet().removeIf(e -> e.getKey().startsWith(versionPrefix(region, name)));
|
||||
}
|
||||
|
||||
public BeanstalkApplicationVersion createApplicationVersion(String region, String applicationName,
|
||||
public synchronized BeanstalkApplicationVersion createApplicationVersion(String region, String applicationName,
|
||||
String versionLabel, String description,
|
||||
boolean autoCreateApplication,
|
||||
String sourceBundleBucket,
|
||||
@@ -141,6 +175,7 @@ public class ElasticBeanstalkService {
|
||||
versions.put(key, version);
|
||||
app.getVersions().add(versionLabel);
|
||||
app.setDateUpdated(now);
|
||||
applications.put(appKey(region, applicationName), app);
|
||||
return version;
|
||||
}
|
||||
|
||||
@@ -157,7 +192,7 @@ public class ElasticBeanstalkService {
|
||||
.toList();
|
||||
}
|
||||
|
||||
public void deleteApplicationVersion(String region, String applicationName, String versionLabel) {
|
||||
public synchronized void deleteApplicationVersion(String region, String applicationName, String versionLabel) {
|
||||
requireName(applicationName, "ApplicationName");
|
||||
requireName(versionLabel, "VersionLabel");
|
||||
BeanstalkApplicationVersion removed = versions.remove(versionKey(region, applicationName, versionLabel));
|
||||
@@ -169,10 +204,11 @@ public class ElasticBeanstalkService {
|
||||
if (app != null) {
|
||||
app.getVersions().remove(versionLabel);
|
||||
app.setDateUpdated(Instant.now());
|
||||
applications.put(appKey(region, applicationName), app);
|
||||
}
|
||||
}
|
||||
|
||||
public BeanstalkEnvironment createEnvironment(String region, String applicationName, String environmentName,
|
||||
public synchronized BeanstalkEnvironment createEnvironment(String region, String applicationName, String environmentName,
|
||||
String description, String cnamePrefix, String solutionStackName,
|
||||
String platformArn, String templateName, String versionLabel,
|
||||
List<ConfigurationOptionSetting> optionSettings,
|
||||
@@ -236,7 +272,7 @@ public class ElasticBeanstalkService {
|
||||
.toList();
|
||||
}
|
||||
|
||||
public BeanstalkEnvironment updateEnvironment(String region, String environmentName, String environmentId,
|
||||
public synchronized BeanstalkEnvironment updateEnvironment(String region, String environmentName, String environmentId,
|
||||
String description, String versionLabel,
|
||||
String solutionStackName, String platformArn,
|
||||
List<ConfigurationOptionSetting> optionSettings) {
|
||||
@@ -268,15 +304,17 @@ public class ElasticBeanstalkService {
|
||||
env.setHealth("Green");
|
||||
env.setHealthStatus("Ok");
|
||||
env.setDateUpdated(Instant.now());
|
||||
environments.put(envKey(region, env.getEnvironmentName()), env);
|
||||
return env;
|
||||
}
|
||||
|
||||
public BeanstalkEnvironment terminateEnvironment(String region, String environmentName, String environmentId) {
|
||||
public synchronized BeanstalkEnvironment terminateEnvironment(String region, String environmentName, String environmentId) {
|
||||
BeanstalkEnvironment env = requireEnvironment(region, environmentName, environmentId);
|
||||
env.setStatus("Terminated");
|
||||
env.setHealth("Grey");
|
||||
env.setHealthStatus("NoData");
|
||||
env.setDateUpdated(Instant.now());
|
||||
environments.put(envKey(region, env.getEnvironmentName()), env);
|
||||
return env;
|
||||
}
|
||||
|
||||
|
||||
+3
@@ -1,11 +1,14 @@
|
||||
package io.github.hectorvent.floci.services.elasticbeanstalk.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
public class BeanstalkApplication {
|
||||
|
||||
private String applicationName;
|
||||
|
||||
+3
@@ -1,9 +1,12 @@
|
||||
package io.github.hectorvent.floci.services.elasticbeanstalk.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
public class BeanstalkApplicationVersion {
|
||||
|
||||
private String applicationName;
|
||||
|
||||
+3
@@ -1,11 +1,14 @@
|
||||
package io.github.hectorvent.floci.services.elasticbeanstalk.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
public class BeanstalkEnvironment {
|
||||
|
||||
private String applicationName;
|
||||
|
||||
+3
@@ -1,5 +1,8 @@
|
||||
package io.github.hectorvent.floci.services.elasticbeanstalk.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
public class ConfigurationOptionSetting {
|
||||
|
||||
private String namespace;
|
||||
|
||||
Reference in new issue
Block a user