mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(docker): own the floci-aws- container and volume prefix (#4273)
Every container and volume Floci creates was named floci-<service>-<id>. Every Floci emulator shared that prefix, so two of them on one Docker daemon collided on names, and docker volume prune --filter label=floci=true reached all of them at once. Each emulator now owns a prefix of its own; this one uses floci-aws-, and labels its resources floci_emulator=floci-aws. Existing data is neither moved nor lost. Resources with a record (RDS, MSK, OpenSearch, Amazon MQ, Kinesis Analytics savepoints, Timestream InfluxDB) persist the volume name they were created with; records from before the field existed are backfilled with the frozen legacy name so their data keeps resolving. Volumes with no record (the ECR registry, EFS-backed task and Lambda volumes) are found by probing the legacy name first. Containers are disposable and always take the current name; the UI console and the ECR registry, which survive shutdown and are adopted by name, are looked up under both prefixes so an upgrade does not orphan one that still holds its host port. Stale-container cleanup clears both names. Scripts that name containers (docker exec floci-rds-<id>) must be updated, and downgrading does not migrate back: a record written after the upgrade carries a floci-aws- name an older build will not look for. Documented in storage.md.
This commit is contained in:
1 parent
bfedf6c679
commit
836161e1ff
59 files changed
+874
-255
No files matched your search
+42
-13
@@ -14,21 +14,49 @@ import static org.mockito.Mockito.when;
|
||||
class ContainerStorageHelperTest {
|
||||
|
||||
@Test
|
||||
void resourceNamesStayUnchangedWithoutNamespace() {
|
||||
assertEquals("floci-rds-db1", ContainerStorageHelper.resourceName("rds", null, "db1"));
|
||||
assertEquals("floci-rds-vol1", ContainerStorageHelper.resourceName(config(""), "rds", "vol1", "db1"));
|
||||
assertEquals("floci-opensearch-domain1", ContainerStorageHelper.resourceName(config(""), "opensearch", null, "domain1"));
|
||||
assertEquals("floci-ec2-i-123", ContainerStorageHelper.dockerName(config(""), "floci-ec2-i-123"));
|
||||
void resourceNamesCarryThisEmulatorsPrefix() {
|
||||
assertEquals("floci-aws-rds-db1", ContainerStorageHelper.resourceName("rds", null, "db1"));
|
||||
assertEquals("floci-aws-rds-vol1", ContainerStorageHelper.resourceName(config(""), "rds", "vol1", "db1"));
|
||||
assertEquals("floci-aws-opensearch-domain1",
|
||||
ContainerStorageHelper.resourceName(config(""), "opensearch", null, "domain1"));
|
||||
assertEquals("floci-aws-ec2-i-123", ContainerStorageHelper.dockerName(config(""), "ec2-i-123"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void alreadyPrefixedNamesAreNormalisedNotPrefixedTwice() {
|
||||
// A persisted name is fed straight back in when a container is named after the volume it
|
||||
// mounts, so prefixing has to be idempotent in both directions.
|
||||
assertEquals("floci-aws-ec2-i-123", ContainerStorageHelper.dockerName(config(""), "floci-ec2-i-123"));
|
||||
assertEquals("floci-aws-ec2-i-123", ContainerStorageHelper.dockerName(config(""), "floci-aws-ec2-i-123"));
|
||||
assertEquals("floci-aws-ui", ContainerStorageHelper.dockerName(config(""), "floci-ui"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacyNamesKeepTheFrozenPreMigrationShape() {
|
||||
// Frozen forever: this is the name a pre-migration volume's data actually lives under.
|
||||
assertEquals("floci-rds-vol1",
|
||||
ContainerStorageHelper.legacyResourceName(config(""), "rds", "vol1", "db1"));
|
||||
assertEquals("floci-rds-db1",
|
||||
ContainerStorageHelper.legacyResourceName(config(""), "rds", null, "db1"));
|
||||
assertEquals("floci-run-one-rds-vol1",
|
||||
ContainerStorageHelper.legacyResourceName(config(" run/one "), "rds", "vol1", "db1"));
|
||||
// Round-trips back from a current name, which is how a container derives its legacy twin.
|
||||
assertEquals("floci-rds-vol1",
|
||||
ContainerStorageHelper.legacyDockerName(config(""), "floci-aws-rds-vol1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resourceNamesIncludeSanitizedNamespaceWhenConfigured() {
|
||||
EmulatorConfig config = config(" run/one ");
|
||||
|
||||
assertEquals("floci-run-one-rds-db1", ContainerStorageHelper.resourceName(config, "rds", null, "db1"));
|
||||
assertEquals("floci-run-one-rds-vol1", ContainerStorageHelper.resourceName(config, "rds", "vol1", "db1"));
|
||||
assertEquals("floci-run-one-ec2-i-123", ContainerStorageHelper.dockerName(config, "floci-ec2-i-123"));
|
||||
assertEquals("floci-run-one-ui", ContainerStorageHelper.dockerName(config, "floci-ui"));
|
||||
// The namespace lands after the cloud token, never before it.
|
||||
assertEquals("floci-aws-run-one-rds-db1", ContainerStorageHelper.resourceName(config, "rds", null, "db1"));
|
||||
assertEquals("floci-aws-run-one-rds-vol1", ContainerStorageHelper.resourceName(config, "rds", "vol1", "db1"));
|
||||
assertEquals("floci-aws-run-one-ec2-i-123", ContainerStorageHelper.dockerName(config, "floci-ec2-i-123"));
|
||||
assertEquals("floci-aws-run-one-ui", ContainerStorageHelper.dockerName(config, "floci-ui"));
|
||||
// Re-normalising either shape is a no-op.
|
||||
assertEquals("floci-aws-run-one-ec2-i-123",
|
||||
ContainerStorageHelper.dockerName(config, "floci-aws-run-one-ec2-i-123"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -43,7 +71,7 @@ class ContainerStorageHelperTest {
|
||||
EmulatorConfig config = config("..");
|
||||
|
||||
assertEquals(Path.of("/tmp/floci/rds/db1"), ContainerStorageHelper.hostResourcePath(config, "rds", "db1"));
|
||||
assertEquals("floci-rds-db1", ContainerStorageHelper.resourceName(config, "rds", null, "db1"));
|
||||
assertEquals("floci-aws-rds-db1", ContainerStorageHelper.resourceName(config, "rds", null, "db1"));
|
||||
assertEquals(
|
||||
Map.of("floci", "true", "floci_emulator", "floci-aws"),
|
||||
ContainerStorageHelper.defaultLabels(config));
|
||||
@@ -68,9 +96,10 @@ class ContainerStorageHelperTest {
|
||||
ContainerStorageHelper.prefixedDockerName(config(""), "acme", "my-fn-abc123"));
|
||||
assertEquals("acme-run-one-my-fn-abc123",
|
||||
ContainerStorageHelper.prefixedDockerName(config(" run/one "), "acme", "my-fn-abc123"));
|
||||
// The default prefix through this path matches what dockerName produces.
|
||||
assertEquals(ContainerStorageHelper.dockerName(config("run-one"), "floci-my-fn-abc123"),
|
||||
ContainerStorageHelper.prefixedDockerName(config("run-one"), "floci", "my-fn-abc123"));
|
||||
// This emulator's own prefix through this path matches what dockerName produces.
|
||||
assertEquals(ContainerStorageHelper.dockerName(config("run-one"), "my-fn-abc123"),
|
||||
ContainerStorageHelper.prefixedDockerName(
|
||||
config("run-one"), ContainerStorageHelper.NAME_PREFIX, "my-fn-abc123"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+5
-2
@@ -217,8 +217,10 @@ class RabbitMqManagerTest {
|
||||
|
||||
assertThrows(RuntimeException.class, () -> manager.startContainer(broker("b-1")));
|
||||
|
||||
// Once for the stale-container sweep before create, once for the rollback.
|
||||
verify(lifecycleManager, Mockito.times(2)).removeIfExists("floci-amazonmq-b-1");
|
||||
// Once for the stale-container sweep before create, once for the rollback; the sweep also
|
||||
// clears the pre-migration name so a survivor cannot keep the broker's ports.
|
||||
verify(lifecycleManager, Mockito.times(2)).removeIfExists("floci-aws-amazonmq-b-1");
|
||||
verify(lifecycleManager).removeIfExists("floci-amazonmq-b-1");
|
||||
verify(portAllocator).release(5672);
|
||||
verify(portAllocator).release(15672);
|
||||
}
|
||||
@@ -242,6 +244,7 @@ class RabbitMqManagerTest {
|
||||
|
||||
manager.stopContainer(broker);
|
||||
|
||||
verify(lifecycleManager).removeIfExists("floci-aws-amazonmq-b-2");
|
||||
verify(lifecycleManager).removeIfExists("floci-amazonmq-b-2");
|
||||
verifyNoMoreInteractions(lifecycleManager);
|
||||
}
|
||||
|
||||
+8
-1
@@ -139,8 +139,15 @@ class Ec2PortForwardManagerTest {
|
||||
|
||||
@Test
|
||||
void forwardContainerNameIsDeterministic() {
|
||||
assertEquals("floci-aws-ec2-fwd-i-123-80",
|
||||
Ec2PortForwardManager.forwardContainerName(null, "i-123", 80));
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacyForwardContainerNameKeepsThePreMigrationShape() {
|
||||
// Frozen: it is how a sidecar created before the rename is found and cleared.
|
||||
assertEquals("floci-ec2-fwd-i-123-80",
|
||||
Ec2PortForwardManager.forwardContainerName("i-123", 80));
|
||||
Ec2PortForwardManager.legacyForwardContainerName(null, "i-123", 80));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+4
-4
@@ -57,7 +57,7 @@ class EcrRegistryManagerTest {
|
||||
|
||||
private static final int BASE_PORT = 6100;
|
||||
private static final int MAX_PORT = 6101; // pool of exactly two ports
|
||||
private static final String REGISTRY_NAME = "floci-test-ecr-registry";
|
||||
private static final String REGISTRY_NAME = "floci-aws-test-ecr-registry";
|
||||
private static final String AWS_ECR_IMAGE = "123456789012.dkr.ecr.us-east-1.amazonaws.com/backend-user:1";
|
||||
|
||||
private PortAllocator portAllocator;
|
||||
@@ -343,7 +343,7 @@ class EcrRegistryManagerTest {
|
||||
when(containerDetector.isRunningInContainer()).thenReturn(true);
|
||||
when(docker.resourceNamespace()).thenReturn(Optional.of("run/one"));
|
||||
|
||||
assertEquals("http://floci-run-one-test-ecr-registry:5000", manager.httpClient().baseUrl());
|
||||
assertEquals("http://floci-aws-run-one-test-ecr-registry:5000", manager.httpClient().baseUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -532,7 +532,7 @@ class EcrRegistryManagerTest {
|
||||
manager.pruneStorage();
|
||||
|
||||
verify(lifecycleManager).stopAndRemove(Mockito.eq("container-id"), Mockito.isNull());
|
||||
verify(lifecycleManager).removeVolume("floci-ecr-registry-data");
|
||||
verify(lifecycleManager).removeVolume("floci-aws-ecr-registry-data");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -557,7 +557,7 @@ class EcrRegistryManagerTest {
|
||||
manager.shutdown();
|
||||
|
||||
verify(lifecycleManager).stopAndRemove(Mockito.eq("container-id"), Mockito.isNull());
|
||||
verify(lifecycleManager).removeVolume("floci-ecr-registry-data");
|
||||
verify(lifecycleManager).removeVolume("floci-aws-ecr-registry-data");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-1
@@ -145,7 +145,7 @@ class EcsContainerManagerEfsIsolationDockerIntegrationTest {
|
||||
EcsTask task = new EcsTask();
|
||||
task.setTaskArn("arn:aws:ecs:us-east-1:000000000000:task/efs-isolation/" + suffix);
|
||||
|
||||
volumesToCleanUp.add(EcsContainerManager.efsVolumeName(fileSystemId, accessPointId, rootDirectory));
|
||||
volumesToCleanUp.add("floci-aws-" + EcsContainerManager.efsVolumeToken(fileSystemId, accessPointId, rootDirectory));
|
||||
|
||||
EcsTaskHandle handle = containerManager.startTask(task, taskDef, List.of(), "us-east-1");
|
||||
String dockerId = handle.getContainerIds().get("app");
|
||||
|
||||
+20
-20
@@ -9,8 +9,8 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link EcsContainerManager#efsVolumeName}, the naming logic that scopes an
|
||||
* EFS-backed task volume's shared Docker named volume to both {@code fileSystemId} and its
|
||||
* Unit tests for {@link EcsContainerManager#efsVolumeToken}, the naming logic that scopes an
|
||||
* EFS-backed task volume's shared Docker named volume (before the emulator prefix) to both {@code fileSystemId} and its
|
||||
* effective root (#2563). The name must be stable for a given (fileSystemId, rootDirectory,
|
||||
* accessPointId) combination (so identical mounts keep sharing one volume), distinct across
|
||||
* different roots on the same file system (so mounts do not collide on the same tree), and
|
||||
@@ -22,16 +22,16 @@ class EcsContainerManagerEfsVolumeNamingTest {
|
||||
|
||||
@Test
|
||||
void defaultsToPlainFileSystemNameWhenNoRootOrAccessPointIsSet() {
|
||||
assertEquals("floci-efs-fs-abc", EcsContainerManager.efsVolumeName("fs-abc", null, null));
|
||||
assertEquals("floci-efs-fs-abc", EcsContainerManager.efsVolumeName("fs-abc", null, ""));
|
||||
assertEquals("floci-efs-fs-abc", EcsContainerManager.efsVolumeName("fs-abc", null, "/"));
|
||||
assertEquals("efs-fs-abc", EcsContainerManager.efsVolumeToken("fs-abc", null, null));
|
||||
assertEquals("efs-fs-abc", EcsContainerManager.efsVolumeToken("fs-abc", null, ""));
|
||||
assertEquals("efs-fs-abc", EcsContainerManager.efsVolumeToken("fs-abc", null, "/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void differentRootDirectoriesOnSameFileSystemYieldDifferentVolumes() {
|
||||
String rootA = EcsContainerManager.efsVolumeName("fs-shared", null, "/team-a");
|
||||
String rootB = EcsContainerManager.efsVolumeName("fs-shared", null, "/team-b");
|
||||
String rootNone = EcsContainerManager.efsVolumeName("fs-shared", null, null);
|
||||
String rootA = EcsContainerManager.efsVolumeToken("fs-shared", null, "/team-a");
|
||||
String rootB = EcsContainerManager.efsVolumeToken("fs-shared", null, "/team-b");
|
||||
String rootNone = EcsContainerManager.efsVolumeToken("fs-shared", null, null);
|
||||
|
||||
assertNotEquals(rootA, rootB, "different rootDirectory values must isolate the volume");
|
||||
assertNotEquals(rootA, rootNone, "a non-root rootDirectory must not collapse to the plain name");
|
||||
@@ -41,16 +41,16 @@ class EcsContainerManagerEfsVolumeNamingTest {
|
||||
|
||||
@Test
|
||||
void sameRootDirectoryOnSameFileSystemStillShares() {
|
||||
String first = EcsContainerManager.efsVolumeName("fs-shared", null, "/team-a");
|
||||
String second = EcsContainerManager.efsVolumeName("fs-shared", null, "/team-a");
|
||||
String first = EcsContainerManager.efsVolumeToken("fs-shared", null, "/team-a");
|
||||
String second = EcsContainerManager.efsVolumeToken("fs-shared", null, "/team-a");
|
||||
|
||||
assertEquals(first, second, "identical (fileSystemId, rootDirectory) must keep sharing one volume");
|
||||
}
|
||||
|
||||
@Test
|
||||
void accessPointIdTakesPrecedenceOverRootDirectory() {
|
||||
String viaAccessPoint = EcsContainerManager.efsVolumeName("fs-shared", "fsap-111", "/ignored");
|
||||
String viaRootOnly = EcsContainerManager.efsVolumeName("fs-shared", null, "/ignored");
|
||||
String viaAccessPoint = EcsContainerManager.efsVolumeToken("fs-shared", "fsap-111", "/ignored");
|
||||
String viaRootOnly = EcsContainerManager.efsVolumeToken("fs-shared", null, "/ignored");
|
||||
|
||||
assertNotEquals(viaAccessPoint, viaRootOnly,
|
||||
"an access point's own root must take precedence over rootDirectory, not merge with it");
|
||||
@@ -58,16 +58,16 @@ class EcsContainerManagerEfsVolumeNamingTest {
|
||||
|
||||
@Test
|
||||
void differentAccessPointsOnSameFileSystemYieldDifferentVolumes() {
|
||||
String apOne = EcsContainerManager.efsVolumeName("fs-shared", "fsap-111", null);
|
||||
String apTwo = EcsContainerManager.efsVolumeName("fs-shared", "fsap-222", null);
|
||||
String apOne = EcsContainerManager.efsVolumeToken("fs-shared", "fsap-111", null);
|
||||
String apTwo = EcsContainerManager.efsVolumeToken("fs-shared", "fsap-222", null);
|
||||
|
||||
assertNotEquals(apOne, apTwo, "different accessPointId values must isolate the volume");
|
||||
}
|
||||
|
||||
@Test
|
||||
void sameAccessPointStillShares() {
|
||||
String first = EcsContainerManager.efsVolumeName("fs-shared", "fsap-111", null);
|
||||
String second = EcsContainerManager.efsVolumeName("fs-shared", "fsap-111", "/whatever-is-ignored");
|
||||
String first = EcsContainerManager.efsVolumeToken("fs-shared", "fsap-111", null);
|
||||
String second = EcsContainerManager.efsVolumeToken("fs-shared", "fsap-111", "/whatever-is-ignored");
|
||||
|
||||
assertEquals(first, second,
|
||||
"the same accessPointId must keep sharing one volume regardless of rootDirectory");
|
||||
@@ -75,13 +75,13 @@ class EcsContainerManagerEfsVolumeNamingTest {
|
||||
|
||||
@Test
|
||||
void equivalentRootDirectorySpellingsShareTheSameVolume() {
|
||||
String canonical = EcsContainerManager.efsVolumeName("fs-shared", null, "/team-a");
|
||||
String canonical = EcsContainerManager.efsVolumeToken("fs-shared", null, "/team-a");
|
||||
|
||||
assertEquals(canonical, EcsContainerManager.efsVolumeName("fs-shared", null, "/team-a/"),
|
||||
assertEquals(canonical, EcsContainerManager.efsVolumeToken("fs-shared", null, "/team-a/"),
|
||||
"a trailing slash must not create a distinct volume for the same directory");
|
||||
assertEquals(canonical, EcsContainerManager.efsVolumeName("fs-shared", null, "//team-a"),
|
||||
assertEquals(canonical, EcsContainerManager.efsVolumeToken("fs-shared", null, "//team-a"),
|
||||
"a repeated leading slash must not create a distinct volume for the same directory");
|
||||
assertEquals(canonical, EcsContainerManager.efsVolumeName("fs-shared", null, "team-a"),
|
||||
assertEquals(canonical, EcsContainerManager.efsVolumeToken("fs-shared", null, "team-a"),
|
||||
"a missing leading slash must not create a distinct volume for the same directory");
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -130,7 +130,7 @@ class EcsContainerManagerVolumesFromTest {
|
||||
when(lifecycleManager.getDockerClient()).thenReturn(dockerClient);
|
||||
InspectVolumeCmd inspectVolumeCmd = mock(InspectVolumeCmd.class);
|
||||
InspectVolumeResponse volume = mock(InspectVolumeResponse.class);
|
||||
when(dockerClient.inspectVolumeCmd("floci-ecs-firelens-volumesfrom1")).thenReturn(inspectVolumeCmd);
|
||||
when(dockerClient.inspectVolumeCmd("floci-aws-ecs-firelens-volumesfrom1")).thenReturn(inspectVolumeCmd);
|
||||
when(inspectVolumeCmd.exec()).thenReturn(volume);
|
||||
when(volume.getMountpoint()).thenReturn("/var/lib/docker/volumes/floci-ecs-firelens-volumesfrom1/_data");
|
||||
CopyArchiveToContainerCmd copyCmd = mock(CopyArchiveToContainerCmd.class, RETURNS_SELF);
|
||||
@@ -160,8 +160,8 @@ class EcsContainerManagerVolumesFromTest {
|
||||
lifecycleOrder.verify(lifecycleManager).createAndStart(any(ContainerSpec.class));
|
||||
verify(routerBuilder).withVolumesFrom("source-id", false);
|
||||
verify(appBuilder).withVolumesFrom("source-id", true);
|
||||
verify(lifecycleManager).ensureVolume("floci-ecs-firelens-volumesfrom1");
|
||||
verify(routerBuilder).withNamedVolume("floci-ecs-firelens-volumesfrom1", "/var/run");
|
||||
verify(lifecycleManager).ensureVolume("floci-aws-ecs-firelens-volumesfrom1");
|
||||
verify(routerBuilder).withNamedVolume("floci-aws-ecs-firelens-volumesfrom1", "/var/run");
|
||||
verify(copyCmd).withRemotePath("/fluent-bit/etc");
|
||||
verify(routerBuilder, never()).withLoopbackPortBinding(anyInt(), anyInt());
|
||||
verify(appBuilder, never()).withNetworkMode(anyString());
|
||||
@@ -178,7 +178,7 @@ class EcsContainerManagerVolumesFromTest {
|
||||
verify(logStreamer, never()).attach(eq("app-id"), any(), any(), any(), any());
|
||||
verify(logStreamer).attach(eq("source-id"), any(), any(), eq("us-east-1"), any());
|
||||
verify(logStreamer).attach(eq("router-id"), any(), any(), eq("us-east-1"), any());
|
||||
assertEquals("floci-ecs-firelens-volumesfrom1", handle.getFirelensVolumeName());
|
||||
assertEquals("floci-aws-ecs-firelens-volumesfrom1", handle.getFirelensVolumeName());
|
||||
assertEquals(List.of("source", "router", "app"), handle.getContainerIds().keySet().stream().toList());
|
||||
assertEquals(List.of("app", "router", "source"),
|
||||
ecsTask.getContainers().stream().map(Container::getName).toList());
|
||||
|
||||
+5
-3
@@ -159,10 +159,12 @@ class EcsContainerManagerVolumesTest {
|
||||
|
||||
manager.startTask(task, taskDef, List.of(), "us-east-1");
|
||||
|
||||
// Each EFS volume -> a shared local Docker named volume under the current prefix (no
|
||||
// legacy-named volume exists here), read-write or read-only per the mountPoint.
|
||||
verify(builder, times(1)).withNamedVolume(
|
||||
EcsContainerManager.efsVolumeName("fs-0123456789abcdef0", null, "/dps"), "/mnt/efs", false);
|
||||
"floci-aws-" + EcsContainerManager.efsVolumeToken("fs-0123456789abcdef0", null, "/dps"), "/mnt/efs", false);
|
||||
verify(builder, times(1)).withNamedVolume(
|
||||
EcsContainerManager.efsVolumeName("fs-00000000000000001", null, null), "/mnt/shared", true);
|
||||
"floci-aws-" + EcsContainerManager.efsVolumeToken("fs-00000000000000001", null, null), "/mnt/shared", true);
|
||||
|
||||
// EFS volumes are never bind-mounted as host paths.
|
||||
verify(builder, never()).withBind(any(), any());
|
||||
@@ -202,7 +204,7 @@ class EcsContainerManagerVolumesTest {
|
||||
configured.startTask(task, taskDef, List.of(), "us-east-1");
|
||||
|
||||
verify(lifecycleManager, times(1)).ensureSharedVolume(
|
||||
EcsContainerManager.efsVolumeName("fs-abc", null, "/dps"),
|
||||
"floci-aws-" + EcsContainerManager.efsVolumeToken("fs-abc", null, "/dps"),
|
||||
OptionalInt.of(1001), OptionalInt.of(1001), Optional.of("2775"), "busybox:stable");
|
||||
}
|
||||
|
||||
|
||||
@@ -472,7 +472,7 @@ class EksClusterManagerTest {
|
||||
manager.stopCluster(cluster);
|
||||
|
||||
verify(lifecycleManager).stopAndRemove("cid-1", null);
|
||||
verify(lifecycleManager).removeVolume("floci-eks-demo");
|
||||
verify(lifecycleManager).removeVolume("floci-aws-eks-demo");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -501,7 +501,7 @@ class EksClusterManagerTest {
|
||||
Cluster cluster = cluster();
|
||||
cluster.setAccountId("000000000000");
|
||||
|
||||
assertEquals("floci-eks-demo", manager.clusterResourceName(cluster));
|
||||
assertEquals("floci-aws-eks-demo", manager.clusterResourceName(cluster));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -539,7 +539,7 @@ class EksClusterManagerTest {
|
||||
cluster.setAccountId("999999999999");
|
||||
manager.restoreCluster(cluster);
|
||||
|
||||
assertEquals("floci-eks-999999999999.demo", cluster.getDockerName());
|
||||
assertEquals("floci-aws-eks-999999999999.demo", cluster.getDockerName());
|
||||
assertEquals("cid-new", cluster.getContainerId());
|
||||
verify(lifecycleManager, never()).adopt(anyString(), any());
|
||||
verify(lifecycleManager, never()).removeIfExists("floci-eks-demo");
|
||||
@@ -560,7 +560,7 @@ class EksClusterManagerTest {
|
||||
cluster.setAccountId("999999999999");
|
||||
manager.restoreCluster(cluster);
|
||||
|
||||
assertEquals("floci-eks-999999999999.demo", cluster.getDockerName());
|
||||
assertEquals("floci-aws-eks-999999999999.demo", cluster.getDockerName());
|
||||
verify(lifecycleManager, never()).adopt(anyString(), any());
|
||||
verify(lifecycleManager, never()).removeIfExists("floci-eks-demo");
|
||||
}
|
||||
@@ -581,7 +581,7 @@ class EksClusterManagerTest {
|
||||
cluster.setAccountId("999999999999");
|
||||
manager.restoreCluster(cluster);
|
||||
|
||||
assertEquals("floci-eks-999999999999.demo", cluster.getDockerName());
|
||||
assertEquals("floci-aws-eks-999999999999.demo", cluster.getDockerName());
|
||||
assertEquals("cid-new", cluster.getContainerId());
|
||||
verify(inspectVolumeCmd).exec();
|
||||
}
|
||||
@@ -595,8 +595,8 @@ class EksClusterManagerTest {
|
||||
cluster.setAccountId("999999999999");
|
||||
manager.startCluster(cluster);
|
||||
|
||||
assertEquals("floci-eks-999999999999.demo", cluster.getDockerName());
|
||||
verify(lifecycleManager).removeIfExists("floci-eks-999999999999.demo");
|
||||
assertEquals("floci-aws-eks-999999999999.demo", cluster.getDockerName());
|
||||
verify(lifecycleManager).removeIfExists("floci-aws-eks-999999999999.demo");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1644,7 +1644,7 @@ class EksClusterManagerTest {
|
||||
cluster.setVersion("1.30");
|
||||
|
||||
assertThrows(RuntimeException.class, () -> manager.startCluster(cluster));
|
||||
verify(lifecycleManager, Mockito.times(2)).removeIfExists("floci-eks-fail-cluster");
|
||||
verify(lifecycleManager, Mockito.times(2)).removeIfExists("floci-aws-eks-fail-cluster");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ class ElastiCacheContainerManagerTest {
|
||||
// Rollback must still fall back to the deterministic name so nothing is orphaned.
|
||||
manager.stopByGroupId("my-group");
|
||||
|
||||
verify(lifecycleManager).removeIfExists("floci-valkey-my-group");
|
||||
verify(lifecycleManager).removeIfExists("floci-aws-valkey-my-group");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+5
-5
@@ -316,8 +316,8 @@ class FlinkContainerManagerTest {
|
||||
|
||||
assertThrows(RuntimeException.class, () -> manager.startCluster(app));
|
||||
|
||||
verify(lifecycleManager, times(2)).removeIfExists("floci-kinesisanalytics-arn-aws-kinesisanalytics-us-west-2-000000000000-application-jm-failure");
|
||||
verify(lifecycleManager, atLeastOnce()).removeIfExists("floci-kinesisanalytics-arn-aws-kinesisanalytics-us-west-2-000000000000-application-jm-failure-tm");
|
||||
verify(lifecycleManager, times(2)).removeIfExists("floci-aws-kinesisanalytics-arn-aws-kinesisanalytics-us-west-2-000000000000-application-jm-failure");
|
||||
verify(lifecycleManager, atLeastOnce()).removeIfExists("floci-aws-kinesisanalytics-arn-aws-kinesisanalytics-us-west-2-000000000000-application-jm-failure-tm");
|
||||
assertNull(app.getContainerId());
|
||||
assertNull(app.getTaskManagerContainerId());
|
||||
}
|
||||
@@ -337,7 +337,7 @@ class FlinkContainerManagerTest {
|
||||
assertThrows(RuntimeException.class, () -> manager.startCluster(app));
|
||||
|
||||
verify(lifecycleManager).stopAndRemove("jm-id", null);
|
||||
verify(lifecycleManager, atLeastOnce()).removeIfExists("floci-kinesisanalytics-arn-aws-kinesisanalytics-us-west-2-000000000000-application-tm-failure-tm");
|
||||
verify(lifecycleManager, atLeastOnce()).removeIfExists("floci-aws-kinesisanalytics-arn-aws-kinesisanalytics-us-west-2-000000000000-application-tm-failure-tm");
|
||||
assertNull(app.getContainerId());
|
||||
assertNull(app.getRestEndpoint());
|
||||
assertNull(app.getTaskManagerContainerId());
|
||||
@@ -356,8 +356,8 @@ class FlinkContainerManagerTest {
|
||||
|
||||
assertThrows(RuntimeException.class, () -> manager.startCluster(app));
|
||||
|
||||
verify(lifecycleManager, times(2)).removeIfExists("floci-kinesisanalytics-arn-aws-kinesisanalytics-us-west-2-000000000000-application-log4j-copy-failure");
|
||||
verify(lifecycleManager, atLeastOnce()).removeIfExists("floci-kinesisanalytics-arn-aws-kinesisanalytics-us-west-2-000000000000-application-log4j-copy-failure-tm");
|
||||
verify(lifecycleManager, times(2)).removeIfExists("floci-aws-kinesisanalytics-arn-aws-kinesisanalytics-us-west-2-000000000000-application-log4j-copy-failure");
|
||||
verify(lifecycleManager, atLeastOnce()).removeIfExists("floci-aws-kinesisanalytics-arn-aws-kinesisanalytics-us-west-2-000000000000-application-log4j-copy-failure-tm");
|
||||
verify(lifecycleManager, Mockito.never()).startCreated(any(), any());
|
||||
assertNull(app.getContainerId());
|
||||
}
|
||||
|
||||
+3
-3
@@ -81,7 +81,7 @@ class ContainerLauncherCodeVolumeReuseTest {
|
||||
EmulatorConfig.LambdaServiceConfig lambda = mock(EmulatorConfig.LambdaServiceConfig.class);
|
||||
when(config.storage()).thenReturn(storage);
|
||||
when(storage.persistentPath()).thenReturn(tempDir.toString());
|
||||
// ensureCodeVolume resolves the configured container-name prefix (unset = "floci").
|
||||
// ensureCodeVolume resolves the configured container-name prefix (unset = "floci-aws").
|
||||
when(config.services()).thenReturn(services);
|
||||
when(services.lambda()).thenReturn(lambda);
|
||||
when(lambda.containerNamePrefix()).thenReturn(Optional.empty());
|
||||
@@ -202,8 +202,8 @@ class ContainerLauncherCodeVolumeReuseTest {
|
||||
void successfulPopulationPrunesOnlyOrphanInternalMarkers() throws Exception {
|
||||
LambdaFunction fn = fn("sha-v1-abcdef0123456789");
|
||||
String vol = ContainerLauncher.codeVolumeName(fn);
|
||||
String live = "floci-code-live";
|
||||
String orphan = "floci-code-orphan";
|
||||
String live = "floci-aws-code-live";
|
||||
String orphan = "floci-aws-code-orphan";
|
||||
writeMarker(live);
|
||||
writeMarker(orphan);
|
||||
writeMarker("unrelated-marker");
|
||||
|
||||
+8
-8
@@ -23,9 +23,9 @@ class ContainerLauncherNamePrefixTest {
|
||||
private static final Pattern DOCKER_NAME = Pattern.compile("^[a-zA-Z0-9][a-zA-Z0-9_.-]*$");
|
||||
|
||||
@Test
|
||||
void fallsBackToFlociWhenPrefixUnsetOrBlank() {
|
||||
assertEquals("floci", ContainerLauncher.resolveContainerNamePrefix(config(null)));
|
||||
assertEquals("floci", ContainerLauncher.resolveContainerNamePrefix(config(" ")));
|
||||
void fallsBackToThisEmulatorsPrefixWhenUnsetOrBlank() {
|
||||
assertEquals("floci-aws", ContainerLauncher.resolveContainerNamePrefix(config(null)));
|
||||
assertEquals("floci-aws", ContainerLauncher.resolveContainerNamePrefix(config(" ")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -35,11 +35,11 @@ class ContainerLauncherNamePrefixTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void fallsBackToFlociWhenPrefixIsNotDockerSafe() {
|
||||
void fallsBackToThisEmulatorsPrefixWhenNotDockerSafe() {
|
||||
// Docker names must start alphanumeric and allow only [A-Za-z0-9_.-] after that.
|
||||
assertEquals("floci", ContainerLauncher.resolveContainerNamePrefix(config("-leading-dash")));
|
||||
assertEquals("floci", ContainerLauncher.resolveContainerNamePrefix(config("has space")));
|
||||
assertEquals("floci", ContainerLauncher.resolveContainerNamePrefix(config("has:colon")));
|
||||
assertEquals("floci-aws", ContainerLauncher.resolveContainerNamePrefix(config("-leading-dash")));
|
||||
assertEquals("floci-aws", ContainerLauncher.resolveContainerNamePrefix(config("has space")));
|
||||
assertEquals("floci-aws", ContainerLauncher.resolveContainerNamePrefix(config("has:colon")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,7 +56,7 @@ class ContainerLauncherNamePrefixTest {
|
||||
"must be a docker-volume-safe name, was: " + name);
|
||||
// The one-arg overload stays on the default prefix (used by pre-existing callers/tests).
|
||||
assertEquals(ContainerLauncher.codeVolumeName(fn),
|
||||
ContainerLauncher.codeVolumeName("floci", fn));
|
||||
ContainerLauncher.codeVolumeName(ContainerLauncher.DEFAULT_NAME_PREFIX, fn));
|
||||
}
|
||||
|
||||
private static EmulatorConfig config(String prefix) {
|
||||
|
||||
+1
-1
@@ -484,7 +484,7 @@ class ContainerLauncherTest {
|
||||
|
||||
launcher.launch(fn);
|
||||
|
||||
String expectedVolumeName = "floci-efs-fsap-0123456789abcdef0-"
|
||||
String expectedVolumeName = "floci-aws-efs-fsap-0123456789abcdef0-"
|
||||
+ "9d6eafd2aec94d4518a004f005725b4b3c673c1506436bb7368cfd5450fc0810";
|
||||
verify(lifecycleManager).ensureSharedVolume(expectedVolumeName,
|
||||
OptionalInt.empty(), OptionalInt.empty(), Optional.empty(), "busybox:stable");
|
||||
|
||||
+12
-8
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.services.lambda.launcher;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerStorageHelper;
|
||||
import io.github.hectorvent.floci.services.lambda.model.LambdaFunction;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
@@ -39,8 +40,8 @@ class ContainerLauncherVolumeNamingTest {
|
||||
String name = ContainerLauncher.codeVolumeName(
|
||||
fnWithSha("my-fn", "AbC123+/xyz=deadbeefcafebabe0123456789"));
|
||||
|
||||
assertTrue(name.startsWith("floci-code-my-fn-"),
|
||||
"should be floci-code-<functionName>-<hash> shaped, was: " + name);
|
||||
assertTrue(name.startsWith("floci-aws-code-my-fn-"),
|
||||
"should be floci-aws-code-<functionName>-<hash> shaped, was: " + name);
|
||||
assertTrue(DOCKER_VOLUME_NAME.matcher(name).matches(),
|
||||
"must be a docker-volume-safe name, was: " + name);
|
||||
}
|
||||
@@ -105,12 +106,15 @@ class ContainerLauncherVolumeNamingTest {
|
||||
String arn = "arn:aws:elasticfilesystem:us-east-1:000000000000:"
|
||||
+ "access-point/fsap-0123456789abcdef0";
|
||||
|
||||
String volumeName = ContainerLauncher.efsVolumeName(arn);
|
||||
String token = ContainerLauncher.efsVolumeToken(arn);
|
||||
|
||||
assertEquals("floci-efs-fsap-0123456789abcdef0-"
|
||||
assertEquals("efs-fsap-0123456789abcdef0-"
|
||||
+ "9d6eafd2aec94d4518a004f005725b4b3c673c1506436bb7368cfd5450fc0810",
|
||||
volumeName);
|
||||
assertEquals(volumeName, ContainerLauncher.efsVolumeName(arn));
|
||||
token);
|
||||
assertEquals(token, ContainerLauncher.efsVolumeToken(arn));
|
||||
String volumeName = ContainerStorageHelper.dockerName(null, token);
|
||||
assertTrue(volumeName.startsWith("floci-aws-efs-"),
|
||||
"a new EFS volume takes this emulator's prefix, was: " + volumeName);
|
||||
assertTrue(DOCKER_VOLUME_NAME.matcher(volumeName).matches(),
|
||||
"EFS volume name must be Docker-safe, was: " + volumeName);
|
||||
}
|
||||
@@ -122,8 +126,8 @@ class ContainerLauncherVolumeNamingTest {
|
||||
String westArn = "arn:aws:elasticfilesystem:us-west-2:111111111111:"
|
||||
+ "access-point/fsap-0123456789abcdef0";
|
||||
|
||||
assertNotEquals(ContainerLauncher.efsVolumeName(eastArn),
|
||||
ContainerLauncher.efsVolumeName(westArn),
|
||||
assertNotEquals(ContainerLauncher.efsVolumeToken(eastArn),
|
||||
ContainerLauncher.efsVolumeToken(westArn),
|
||||
"the complete ARN must participate in volume identity");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ class MemoryDbContainerManagerTest {
|
||||
// Rollback must still fall back to the deterministic name so nothing is orphaned.
|
||||
manager.stopByClusterName("my-cluster");
|
||||
|
||||
verify(lifecycleManager).removeIfExists("floci-memorydb-my-cluster");
|
||||
verify(lifecycleManager).removeIfExists("floci-aws-memorydb-my-cluster");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -39,6 +39,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -113,6 +114,51 @@ class RedpandaManagerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void aPersistedVolumeNameIsMountedVerbatim() {
|
||||
when(lifecycleManager.createAndStart(any())).thenReturn(
|
||||
new ContainerInfo("container-1", Map.of(KAFKA_PORT, new EndpointInfo("h", KAFKA_PORT))));
|
||||
when(config.storage().hostPersistentPath()).thenReturn("");
|
||||
MskCluster cluster = newCluster();
|
||||
cluster.setDockerVolumeName("floci-aws-msk-abc123");
|
||||
|
||||
manager.startContainer(cluster);
|
||||
|
||||
verify(lifecycleManager).ensureVolume("floci-aws-msk-abc123");
|
||||
assertEquals("floci-aws-msk-abc123", cluster.getDockerVolumeName(),
|
||||
"a persisted volume name must never be rewritten");
|
||||
}
|
||||
|
||||
@Test
|
||||
void aPreUpgradeClusterMountsItsLegacyVolumeAndKeepsThatName() {
|
||||
// No persisted name means a record written before the field existed, so the cluster's
|
||||
// data lives in the legacy-prefixed volume. Mounting the current name would silently
|
||||
// start an empty broker and strand every topic.
|
||||
when(lifecycleManager.createAndStart(any())).thenReturn(
|
||||
new ContainerInfo("container-2", Map.of(KAFKA_PORT, new EndpointInfo("h", KAFKA_PORT))));
|
||||
when(config.storage().hostPersistentPath()).thenReturn("");
|
||||
MskCluster cluster = newCluster();
|
||||
cluster.setDockerVolumeName(null);
|
||||
|
||||
manager.startContainer(cluster);
|
||||
|
||||
verify(lifecycleManager).ensureVolume("floci-msk-abc123");
|
||||
verify(lifecycleManager, never()).ensureVolume("floci-aws-msk-abc123");
|
||||
assertEquals("floci-msk-abc123", cluster.getDockerVolumeName(),
|
||||
"the legacy name must be backfilled onto the record, not recomputed each start");
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletingAPreUpgradeClusterRemovesItsLegacyVolume() {
|
||||
when(config.storage().mode()).thenReturn("memory");
|
||||
MskCluster cluster = newCluster();
|
||||
cluster.setDockerVolumeName(null);
|
||||
|
||||
manager.removeClusterStorage(cluster);
|
||||
|
||||
verify(lifecycleManager).removeVolume("floci-msk-abc123");
|
||||
}
|
||||
|
||||
private MskCluster newCluster() {
|
||||
MskCluster cluster = new MskCluster("arn:aws:kafka:us-east-1:000000000000:cluster/test-cluster/abc", "test-cluster", "3.6.0");
|
||||
cluster.setVolumeId("abc123");
|
||||
@@ -199,7 +245,7 @@ class RedpandaManagerTest {
|
||||
|
||||
int flagIndex = spec.cmd().indexOf("--advertise-kafka-addr");
|
||||
assertTrue(flagIndex >= 0, "cmd should contain --advertise-kafka-addr");
|
||||
assertEquals("floci-msk-abc123:9092", spec.cmd().get(flagIndex + 1));
|
||||
assertEquals("floci-aws-msk-abc123:9092", spec.cmd().get(flagIndex + 1));
|
||||
|
||||
assertFalse(spec.portBindings().containsKey(KAFKA_PORT), "container mode should not publish ports to host");
|
||||
assertTrue(spec.exposedPorts().contains(KAFKA_PORT));
|
||||
|
||||
+2
-2
@@ -317,9 +317,9 @@ class MwaaEnvironmentManagerTest {
|
||||
environment.setAccountId("000000000000");
|
||||
environment.setArn("arn:aws:airflow:us-east-1:000000000000:environment/my-env");
|
||||
|
||||
assertEquals("floci-ns1-mwaa-000000000000.us-east-1.my-env-db",
|
||||
assertEquals("floci-aws-ns1-mwaa-000000000000.us-east-1.my-env-db",
|
||||
MwaaEnvironmentManager.dbContainerName(namespacedConfig, environment));
|
||||
assertEquals("floci-ns1-mwaa-000000000000.us-east-1.my-env-airflow",
|
||||
assertEquals("floci-aws-ns1-mwaa-000000000000.us-east-1.my-env-airflow",
|
||||
MwaaEnvironmentManager.airflowContainerName(namespacedConfig, environment));
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -46,7 +46,7 @@ class NeptuneContainerManagerTest {
|
||||
// Rollback must still fall back to the deterministic name so nothing is orphaned.
|
||||
manager.stopByClusterId("my-cluster");
|
||||
|
||||
verify(lifecycleManager).removeIfExists("floci-neptune-my-cluster");
|
||||
verify(lifecycleManager).removeIfExists("floci-aws-neptune-my-cluster");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -169,7 +169,7 @@ class NeptuneContainerManagerTest {
|
||||
"io.floci.resource-id", "cluster1",
|
||||
"io.floci.account", "111111111111",
|
||||
"io.floci.region", "eu-west-1"));
|
||||
verify(builder).withName("floci-neptune-111111111111-eu-west-1-cluster1");
|
||||
verify(builder).withName("floci-aws-neptune-111111111111-eu-west-1-cluster1");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+41
-4
@@ -356,7 +356,7 @@ class RdsContainerManagerTest {
|
||||
var spec = org.mockito.ArgumentCaptor.forClass(ContainerSpec.class);
|
||||
verify(lifecycleManager).create(spec.capture());
|
||||
assertEquals(dbPath.toString(), spec.getValue().binds().getFirst().getPath());
|
||||
assertEquals("floci-rds-db1", spec.getValue().name());
|
||||
assertEquals("floci-aws-rds-db1", spec.getValue().name());
|
||||
verify(logStreamer).attachForAccount(
|
||||
"222222222222", "container-id", "/aws/rds/instance/db1/error",
|
||||
"log-stream", "us-west-2", "rds:" + runtimeId);
|
||||
@@ -912,7 +912,7 @@ class RdsContainerManagerTest {
|
||||
runtimeId, "legacy", "legacy", "floci-rds-legacy-volume",
|
||||
DatabaseEngine.MYSQL, "mysql:8.0", "root", "password", "db"));
|
||||
|
||||
assertEquals("floci-rds-legacy-volume",
|
||||
assertEquals("floci-aws-rds-legacy-volume",
|
||||
manager.getActiveHandle(runtimeId).getContainerId());
|
||||
verify(lifecycleManager, never()).create(any());
|
||||
assertThrows(IllegalStateException.class, () -> manager.start(
|
||||
@@ -1095,7 +1095,44 @@ class RdsContainerManagerTest {
|
||||
var spec = org.mockito.ArgumentCaptor.forClass(ContainerSpec.class);
|
||||
verify(lifecycleManager).removeIfExistsStrict("floci-rds-volume-a");
|
||||
verify(lifecycleManager).create(spec.capture());
|
||||
assertEquals("floci-rds-volume-a", spec.getValue().name());
|
||||
assertEquals("floci-aws-rds-volume-a", spec.getValue().name());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aLegacyVolumeIsMountedAsIsWhileItsContainerTakesTheCurrentName() {
|
||||
// The central asymmetry of the prefix migration. The volume holds the data, so it keeps
|
||||
// whatever name it was persisted under; the container is disposable, so it is always
|
||||
// normalised. Mounting the current name here would start an empty database.
|
||||
EmulatorConfig config = config(Path.of("data"));
|
||||
ContainerDetector containerDetector = mock(ContainerDetector.class);
|
||||
ContainerLifecycleManager lifecycleManager = mock(ContainerLifecycleManager.class);
|
||||
stubStarts(lifecycleManager, new ContainerLifecycleManager.ContainerInfo(
|
||||
"container-id", Map.of(3306, new ContainerLifecycleManager.EndpointInfo("db1", 3306))));
|
||||
ContainerLogStreamer logStreamer = mock(ContainerLogStreamer.class);
|
||||
lenient().when(logStreamer.generateLogStreamName(any())).thenReturn("log-stream");
|
||||
|
||||
RdsContainerManager manager = new RdsContainerManager(
|
||||
new ContainerBuilder(config, mock(DockerHostResolver.class), mock(EmbeddedDnsServer.class)),
|
||||
lifecycleManager,
|
||||
logStreamer,
|
||||
containerDetector,
|
||||
config,
|
||||
new RegionResolver("us-east-1", "000000000000"),
|
||||
mock(ServiceConfigAccess.class));
|
||||
|
||||
manager.start(null, "db1", "db1", "floci-rds-db1",
|
||||
DatabaseEngine.MYSQL, "mysql:8.0", "root", "password", "db");
|
||||
|
||||
var spec = org.mockito.ArgumentCaptor.forClass(ContainerSpec.class);
|
||||
verify(lifecycleManager).create(spec.capture());
|
||||
assertEquals("floci-aws-rds-db1", spec.getValue().name(),
|
||||
"the container is renamed to the current prefix");
|
||||
verify(lifecycleManager).ensureVolume("floci-rds-db1");
|
||||
verify(lifecycleManager, org.mockito.Mockito.never()).ensureVolume("floci-aws-rds-db1");
|
||||
// A pre-migration container under the old name holds the volume's engine lock, so it is
|
||||
// cleared too before the new one starts.
|
||||
verify(lifecycleManager).removeIfExistsStrict("floci-rds-db1");
|
||||
verify(lifecycleManager).removeIfExistsStrict("floci-aws-rds-db1");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1124,7 +1161,7 @@ class RdsContainerManagerTest {
|
||||
var spec = org.mockito.ArgumentCaptor.forClass(ContainerSpec.class);
|
||||
verify(lifecycleManager).removeIfExistsStrict("floci-rds-db1");
|
||||
verify(lifecycleManager).create(spec.capture());
|
||||
assertEquals("floci-rds-db1", spec.getValue().name());
|
||||
assertEquals("floci-aws-rds-db1", spec.getValue().name());
|
||||
assertEquals("db1", handle.getRuntimeId());
|
||||
manager.stop(handle);
|
||||
verify(lifecycleManager).stopAndRemoveStrict(
|
||||
|
||||
+4
-4
@@ -309,7 +309,7 @@ class RedshiftContainerManagerTest {
|
||||
|
||||
manager.stop(ACCOUNT_ID, "test-cluster");
|
||||
assertTrue(manager.getContainer(ACCOUNT_ID, "test-cluster").isEmpty());
|
||||
verify(lifecycleManager).removeIfExists("floci-redshift-" + ACCOUNT_ID + "-test-cluster");
|
||||
verify(lifecycleManager).removeIfExists("floci-aws-redshift-" + ACCOUNT_ID + "-test-cluster");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -333,7 +333,7 @@ class RedshiftContainerManagerTest {
|
||||
|
||||
@Test
|
||||
void adoptOrStartAdoptsExistingContainerInsteadOfRecreatingIt() {
|
||||
String containerName = "floci-redshift-" + ACCOUNT_ID + "-test-cluster";
|
||||
String containerName = "floci-aws-redshift-" + ACCOUNT_ID + "-test-cluster";
|
||||
Container existing = mock(Container.class);
|
||||
when(existing.getId()).thenReturn("cont-existing");
|
||||
when(lifecycleManager.findByName(containerName)).thenReturn(Optional.of(existing));
|
||||
@@ -352,7 +352,7 @@ class RedshiftContainerManagerTest {
|
||||
|
||||
@Test
|
||||
void adoptOrStartFallsBackToStartWhenNoExistingContainer() {
|
||||
String containerName = "floci-redshift-" + ACCOUNT_ID + "-test-cluster";
|
||||
String containerName = "floci-aws-redshift-" + ACCOUNT_ID + "-test-cluster";
|
||||
when(lifecycleManager.findByName(containerName)).thenReturn(Optional.empty());
|
||||
ContainerBuilder.Builder specBuilder = mock(ContainerBuilder.Builder.class, org.mockito.Mockito.RETURNS_SELF);
|
||||
when(containerBuilder.newContainer(anyString())).thenReturn(specBuilder);
|
||||
@@ -523,7 +523,7 @@ class RedshiftContainerManagerTest {
|
||||
|
||||
@Test
|
||||
void adoptOrStartAttachesLogStreamerAndToleratesFailure() throws Exception {
|
||||
String containerName = "floci-redshift-" + ACCOUNT_ID + "-test-cluster";
|
||||
String containerName = "floci-aws-redshift-" + ACCOUNT_ID + "-test-cluster";
|
||||
Container existing = mock(Container.class);
|
||||
when(existing.getId()).thenReturn("cont-adopt-stream");
|
||||
when(lifecycleManager.findByName(containerName)).thenReturn(Optional.of(existing));
|
||||
|
||||
+2
-2
@@ -122,7 +122,7 @@ class SageMakerDockerIntegrationTest {
|
||||
""".formatted(job, bucket)).then().statusCode(200);
|
||||
// Wait for the container to actually be running, blocked on an empty pipe, so the stop
|
||||
// races a real running container rather than one still being staged.
|
||||
awaitContainerRunning("floci-sagemaker-training-" + job);
|
||||
awaitContainerRunning("floci-aws-sagemaker-training-" + job);
|
||||
post("SageMaker.StopTrainingJob", "{\"TrainingJobName\":\"%s\"}".formatted(job)).then().statusCode(200);
|
||||
post("SageMaker.DescribeTrainingJob", "{\"TrainingJobName\":\"%s\"}".formatted(job))
|
||||
.then().statusCode(200).body("TrainingJobStatus", equalTo("Stopped"));
|
||||
@@ -154,7 +154,7 @@ class SageMakerDockerIntegrationTest {
|
||||
// rather than polling for the container means a container that is created and discarded
|
||||
// between two polls is still seen: events are queued and replayed from the watch's start.
|
||||
try (ContainerDestroyWatch discarded =
|
||||
new ContainerDestroyWatch(dockerClient, "floci-sagemaker-endpoint-" + endpoint)) {
|
||||
new ContainerDestroyWatch(dockerClient, "floci-aws-sagemaker-endpoint-" + endpoint)) {
|
||||
post("SageMaker.CreateEndpoint", "{\"EndpointName\":\"%s\",\"EndpointConfigName\":\"%s\"}".formatted(endpoint, cfg))
|
||||
.then().statusCode(200);
|
||||
post("SageMaker.DeleteEndpoint", "{\"EndpointName\":\"%s\"}".formatted(endpoint)).then().statusCode(200);
|
||||
|
||||
+35
-10
@@ -41,6 +41,9 @@ class TimestreamInfluxDbServiceTest {
|
||||
|
||||
private static final String ACCOUNT = "000000000000";
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String CURRENT_PREFIX = "floci-aws-timestream-influxdb-";
|
||||
private static final String LEGACY_PREFIX = "floci-timestream-influxdb-";
|
||||
private final AccountAwareStorageBackend<DbInstance> instances = AccountAwareStorageBackend.inMemory(ACCOUNT);
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
private TimestreamInfluxDbContainerManager containerManager;
|
||||
@@ -50,7 +53,9 @@ class TimestreamInfluxDbServiceTest {
|
||||
void setUp() {
|
||||
containerManager = mock(TimestreamInfluxDbContainerManager.class);
|
||||
when(containerManager.isDockerReachable()).thenReturn(true);
|
||||
when(containerManager.start(anyString(), anyString(), anyString(), any(), anyMap()))
|
||||
when(containerManager.volumeName(anyString())).thenAnswer(inv -> CURRENT_PREFIX + inv.getArgument(0));
|
||||
when(containerManager.legacyVolumeName(anyString())).thenAnswer(inv -> LEGACY_PREFIX + inv.getArgument(0));
|
||||
when(containerManager.start(anyString(), anyString(), anyString(), anyString(), any(), anyMap()))
|
||||
.thenReturn(new InfluxDbEndpoint("container-1", "localhost", 18086));
|
||||
SecretsManagerService secrets = mock(SecretsManagerService.class);
|
||||
Secret secret = mock(Secret.class);
|
||||
@@ -58,7 +63,7 @@ class TimestreamInfluxDbServiceTest {
|
||||
when(secrets.createSecret(anyString(), anyString(), isNull(), anyString(), isNull(), isNull(), eq(REGION)))
|
||||
.thenReturn(secret);
|
||||
service = new TimestreamInfluxDbService(
|
||||
AccountAwareStorageBackend.<DbInstance>inMemory(ACCOUNT),
|
||||
instances,
|
||||
AccountAwareStorageBackend.<DbCluster>inMemory(ACCOUNT),
|
||||
AccountAwareStorageBackend.<DbParameterGroup>inMemory(ACCOUNT),
|
||||
AccountAwareStorageBackend.<DbBackup>inMemory(ACCOUNT),
|
||||
@@ -74,7 +79,8 @@ class TimestreamInfluxDbServiceTest {
|
||||
"""), REGION).resource();
|
||||
|
||||
ArgumentCaptor<InfluxDbSetup> setup = ArgumentCaptor.forClass(InfluxDbSetup.class);
|
||||
verify(containerManager).start(eq(created.getId()), eq(ACCOUNT), eq(REGION), setup.capture(), eq(Map.of()));
|
||||
verify(containerManager).start(eq(created.getId()), eq(CURRENT_PREFIX + created.getId()), eq(ACCOUNT), eq(REGION),
|
||||
setup.capture(), eq(Map.of()));
|
||||
assertEquals(new InfluxDbSetup("operator", "password123", "acme", "metrics"), setup.getValue());
|
||||
|
||||
DbInstance stored = service.getDbInstance(json("{\"identifier\":\"" + created.getId() + "\"}"), REGION);
|
||||
@@ -102,7 +108,7 @@ class TimestreamInfluxDbServiceTest {
|
||||
DbInstance stored = service.getDbInstance(json("{\"identifier\":\"" + id + "\"}"), REGION);
|
||||
assertEquals("AVAILABLE", stored.getStatus());
|
||||
assertNull(stored.getContainerId());
|
||||
verify(containerManager, never()).start(anyString(), anyString(), anyString(), any(), anyMap());
|
||||
verify(containerManager, never()).start(anyString(), anyString(), anyString(), anyString(), any(), anyMap());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,7 +120,7 @@ class TimestreamInfluxDbServiceTest {
|
||||
|
||||
createInstance("tuned-db", groupId);
|
||||
|
||||
verify(containerManager).start(anyString(), eq(ACCOUNT), eq(REGION), any(),
|
||||
verify(containerManager).start(anyString(), anyString(), eq(ACCOUNT), eq(REGION), any(),
|
||||
eq(Map.of("INFLUXD_LOG_LEVEL", "debug", "INFLUXD_HTTP_IDLE_TIMEOUT", "5m")));
|
||||
}
|
||||
|
||||
@@ -128,7 +134,8 @@ class TimestreamInfluxDbServiceTest {
|
||||
service.updateDbInstance(json("{\"identifier\":\"" + id + "\",\"dbParameterGroupIdentifier\":\"" + groupId + "\"}"),
|
||||
REGION);
|
||||
|
||||
verify(containerManager).start(eq(id), eq(ACCOUNT), eq(REGION), isNull(), eq(Map.of("INFLUXD_UI_DISABLED", "true")));
|
||||
verify(containerManager).start(eq(id), eq(CURRENT_PREFIX + id), eq(ACCOUNT), eq(REGION), isNull(),
|
||||
eq(Map.of("INFLUXD_UI_DISABLED", "true")));
|
||||
assertEquals("AVAILABLE", service.getDbInstance(json("{\"identifier\":\"" + id + "\"}"), REGION).getStatus());
|
||||
}
|
||||
|
||||
@@ -142,7 +149,7 @@ class TimestreamInfluxDbServiceTest {
|
||||
|
||||
service.deleteDbInstance(json("{\"identifier\":\"" + id + "\"}"), REGION);
|
||||
verify(containerManager).stop(id, "container-1");
|
||||
verify(containerManager).removeStorage(id);
|
||||
verify(containerManager).removeStorage(CURRENT_PREFIX + id);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -166,7 +173,7 @@ class TimestreamInfluxDbServiceTest {
|
||||
assertEquals("COMPLETED", stored.getStatus());
|
||||
assertTrue(stored.isDataCaptured());
|
||||
|
||||
when(containerManager.start(anyString(), anyString(), anyString(), any(), anyMap()))
|
||||
when(containerManager.start(anyString(), anyString(), anyString(), anyString(), any(), anyMap()))
|
||||
.thenReturn(new InfluxDbEndpoint("container-2", "localhost", 18087));
|
||||
RestoreResult result = service.restoreFromDbBackup(
|
||||
json("{\"name\":\"restored\",\"dbBackupId\":\"" + backup.getId() + "\"}"), REGION);
|
||||
@@ -202,7 +209,7 @@ class TimestreamInfluxDbServiceTest {
|
||||
"vpcSubnetIds":["subnet-abc"],"vpcSecurityGroupIds":["sg-abc"]}
|
||||
"""), REGION).resource().getId();
|
||||
|
||||
verify(containerManager).start(eq(clusterId), eq(ACCOUNT), eq(REGION), any(), anyMap());
|
||||
verify(containerManager).start(eq(clusterId), eq(CURRENT_PREFIX + clusterId), eq(ACCOUNT), eq(REGION), any(), anyMap());
|
||||
DbCluster cluster = service.getDbCluster(json("{\"dbClusterId\":\"" + clusterId + "\"}"), REGION);
|
||||
assertEquals("AVAILABLE", cluster.getStatus());
|
||||
List<DbInstance> members = service.listDbInstancesForCluster(
|
||||
@@ -224,7 +231,7 @@ class TimestreamInfluxDbServiceTest {
|
||||
"vpcSubnetIds":["subnet-abc"],"vpcSecurityGroupIds":["sg-abc"]}
|
||||
""".formatted(groupId)), REGION).resource().getId();
|
||||
|
||||
verify(containerManager, never()).start(anyString(), anyString(), anyString(), any(), anyMap());
|
||||
verify(containerManager, never()).start(anyString(), anyString(), anyString(), anyString(), any(), anyMap());
|
||||
DbCluster cluster = service.getDbCluster(json("{\"dbClusterId\":\"" + clusterId + "\"}"), REGION);
|
||||
assertEquals("AVAILABLE", cluster.getStatus());
|
||||
assertEquals(8181, cluster.getPort());
|
||||
@@ -290,6 +297,24 @@ class TimestreamInfluxDbServiceTest {
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* The upgrade path: a record persisted before the volume name was stamped is backfilled with
|
||||
* the legacy name, so deleting it removes the volumes its data lives in, not freshly named
|
||||
* empty ones.
|
||||
*/
|
||||
@Test
|
||||
void recordsWithoutAPersistedVolumeNameKeepTheirLegacyVolumes() throws Exception {
|
||||
String id = createInstance("legacy-db", null).getId();
|
||||
DbInstance stored = instances.getForAccount(ACCOUNT, REGION + ":" + id).orElseThrow();
|
||||
stored.setDockerVolumeName(null);
|
||||
instances.putForAccount(ACCOUNT, REGION + ":" + id, stored);
|
||||
|
||||
service.deleteDbInstance(json("{\"identifier\":\"" + id + "\"}"), REGION);
|
||||
|
||||
verify(containerManager).removeStorage(LEGACY_PREFIX + id);
|
||||
assertEquals(LEGACY_PREFIX + id, stored.getDockerVolumeName());
|
||||
}
|
||||
|
||||
private DbInstance createInstance(String name, String parameterGroupId) throws Exception {
|
||||
String groupField = parameterGroupId == null ? "" : ",\"dbParameterGroupIdentifier\":\"" + parameterGroupId + "\"";
|
||||
return service.createDbInstance(json("""
|
||||
|
||||
+38
-8
@@ -33,6 +33,7 @@ class TimestreamInfluxDbContainerManagerTest {
|
||||
private ContainerBuilder.Builder builder;
|
||||
private PortAllocator portAllocator;
|
||||
private TimestreamInfluxDbContainerManager manager;
|
||||
private EmulatorConfig.StorageConfig storage;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
@@ -47,7 +48,7 @@ class TimestreamInfluxDbContainerManagerTest {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
EmulatorConfig.ServicesConfig services = mock(EmulatorConfig.ServicesConfig.class);
|
||||
EmulatorConfig.TimestreamInfluxDbServiceConfig influx = mock(EmulatorConfig.TimestreamInfluxDbServiceConfig.class);
|
||||
EmulatorConfig.StorageConfig storage = mock(EmulatorConfig.StorageConfig.class);
|
||||
storage = mock(EmulatorConfig.StorageConfig.class);
|
||||
when(config.services()).thenReturn(services);
|
||||
when(config.storage()).thenReturn(storage);
|
||||
when(services.timestreamInfluxdb()).thenReturn(influx);
|
||||
@@ -65,7 +66,7 @@ class TimestreamInfluxDbContainerManagerTest {
|
||||
when(lifecycleManager.createAndStart(any())).thenReturn(new ContainerInfo("container-id",
|
||||
Map.of(8086, new EndpointInfo("localhost", 8090))));
|
||||
|
||||
InfluxDbEndpoint endpoint = manager.start("abc1234567", "000000000000", "us-east-1",
|
||||
InfluxDbEndpoint endpoint = manager.start("abc1234567", "floci-aws-timestream-influxdb-abc1234567", "000000000000", "us-east-1",
|
||||
new InfluxDbSetup("admin", "password123", "acme", "metrics"), Map.of("INFLUXD_LOG_LEVEL", "debug"));
|
||||
|
||||
assertEquals(new InfluxDbEndpoint("container-id", "localhost", 8090), endpoint);
|
||||
@@ -76,8 +77,8 @@ class TimestreamInfluxDbContainerManagerTest {
|
||||
verify(builder).withEnv("DOCKER_INFLUXDB_INIT_BUCKET", "metrics");
|
||||
verify(builder).withEnv("INFLUXD_LOG_LEVEL", "debug");
|
||||
verify(builder).withPortBinding(8086, 8090);
|
||||
verify(builder).withNamedVolume("floci-timestream-influxdb-abc1234567", "/var/lib/influxdb2");
|
||||
verify(builder).withNamedVolume("floci-timestream-influxdb-abc1234567-config", "/etc/influxdb2");
|
||||
verify(builder).withNamedVolume("floci-aws-timestream-influxdb-abc1234567", "/var/lib/influxdb2");
|
||||
verify(builder).withNamedVolume("floci-aws-timestream-influxdb-abc1234567-config", "/etc/influxdb2");
|
||||
verify(builder).withLabels(Map.of(
|
||||
"io.floci", "aws",
|
||||
"io.floci.service", "timestream-influxdb",
|
||||
@@ -91,7 +92,7 @@ class TimestreamInfluxDbContainerManagerTest {
|
||||
when(lifecycleManager.createAndStart(any())).thenReturn(new ContainerInfo("container-id",
|
||||
Map.of(8086, new EndpointInfo("localhost", 8090))));
|
||||
|
||||
manager.start("abc1234567", "000000000000", "us-east-1", null, Map.of());
|
||||
manager.start("abc1234567", "floci-aws-timestream-influxdb-abc1234567", "000000000000", "us-east-1", null, Map.of());
|
||||
|
||||
verify(builder, never()).withEnv("DOCKER_INFLUXDB_INIT_MODE", "setup");
|
||||
}
|
||||
@@ -100,18 +101,47 @@ class TimestreamInfluxDbContainerManagerTest {
|
||||
void failedStartRemovesTheContainerAndReleasesThePort() {
|
||||
when(lifecycleManager.createAndStart(any())).thenThrow(new RuntimeException("port already allocated"));
|
||||
|
||||
assertThrows(RuntimeException.class, () -> manager.start("abc1234567", "000000000000", "us-east-1",
|
||||
assertThrows(RuntimeException.class, () -> manager.start("abc1234567", "floci-aws-timestream-influxdb-abc1234567", "000000000000", "us-east-1",
|
||||
new InfluxDbSetup("admin", "password123", "acme", "metrics"), Map.of()));
|
||||
|
||||
verify(portAllocator).release(8090);
|
||||
verify(lifecycleManager, Mockito.times(2)).removeIfExists("floci-timestream-influxdb-abc1234567");
|
||||
verify(lifecycleManager, Mockito.times(2)).removeIfExists("floci-aws-timestream-influxdb-abc1234567");
|
||||
}
|
||||
|
||||
@Test
|
||||
void volumeNamesCarryTheCurrentAndTheLegacyPrefix() {
|
||||
assertEquals("floci-aws-timestream-influxdb-abc1234567", manager.volumeName("abc1234567"));
|
||||
assertEquals("floci-timestream-influxdb-abc1234567", manager.legacyVolumeName("abc1234567"));
|
||||
}
|
||||
|
||||
/** A record from before the migration keeps mounting the legacy-named volumes it was created with. */
|
||||
@Test
|
||||
void startMountsThePersistedVolumeNameRatherThanRecomputingIt() {
|
||||
when(lifecycleManager.createAndStart(any())).thenReturn(new ContainerInfo("container-id",
|
||||
Map.of(8086, new EndpointInfo("localhost", 8090))));
|
||||
|
||||
manager.start("abc1234567", "floci-timestream-influxdb-abc1234567", "000000000000", "us-east-1", null, Map.of());
|
||||
|
||||
verify(builder).withNamedVolume("floci-timestream-influxdb-abc1234567", "/var/lib/influxdb2");
|
||||
verify(builder).withNamedVolume("floci-timestream-influxdb-abc1234567-config", "/etc/influxdb2");
|
||||
verify(builder).withName("floci-aws-timestream-influxdb-abc1234567");
|
||||
}
|
||||
|
||||
@Test
|
||||
void removeStorageRemovesTheDataAndConfigVolumesByTheirPersistedName() {
|
||||
when(storage.mode()).thenReturn("memory");
|
||||
|
||||
manager.removeStorage("floci-timestream-influxdb-abc1234567");
|
||||
|
||||
verify(lifecycleManager).removeVolume("floci-timestream-influxdb-abc1234567");
|
||||
verify(lifecycleManager).removeVolume("floci-timestream-influxdb-abc1234567-config");
|
||||
}
|
||||
|
||||
@Test
|
||||
void stopReleasesThePublishedPort() {
|
||||
when(lifecycleManager.createAndStart(any())).thenReturn(new ContainerInfo("container-id",
|
||||
Map.of(8086, new EndpointInfo("localhost", 8090))));
|
||||
manager.start("abc1234567", "000000000000", "us-east-1", null, Map.of());
|
||||
manager.start("abc1234567", "floci-aws-timestream-influxdb-abc1234567", "000000000000", "us-east-1", null, Map.of());
|
||||
|
||||
manager.stop("abc1234567", "container-id");
|
||||
|
||||
|
||||
Reference in new issue
Block a user