mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(emr): keep a cluster's application history and open its persistent UIs for real in the docker runner mode (#8817)
With runner-mode docker, GetPersistentAppUIPresignedURL now opens the persistent application UI's interface for real, SHS the Spark History Server, YTS the YARN timeline server and TEZ the Tez UI, on a host of its own as an on-cluster UI does: while the cluster runs, its primary node's; once it has ended, as "You can access application history and relevant log files for active and terminated clusters", its kept history's, for the 30 days for which "The logs are available ... after the application ends". The primary node of a cluster that runs either history interface mounts a volume of its own, which holds the timeline server's store (its entities kept 30 days rather than Hadoop's 7), and into which, as the cluster's storage goes, or as a reset or a shutdown removes a node still running, its Spark applications' event logs are copied out of its HDFS; the cluster's other storage goes as before, though a copy that fails keeps it, the event logs in it, for a later try or a restart to remove. The URL is not PresignedURLReady while the cluster is ending or its storage is going. Then a container of the image the cluster ran serves it, on a network of its own that no step's container is on, started by the first link, the URL not PresignedURLReady until it answers, and stopped once no link to it is valid, a later link starting it again; with no ResourceManager there, the Tez UI's asks for one go to the timeline server. A kept history goes once its 30 days have passed, whether or not a link asked for it. A restart keeps the histories of the clusters that ended within 30 days, a reset or a shutdown removes the containers, and a reset every history. Elsewhere, the link still opens Floci's own page. EmrAppUiNightlyIntegrationTest runs it for real: a persistent UI opens the cluster's Spark History Server while it runs, and, once it has ended and its storage has gone, its kept history: the Spark application, the Hive query's Tez DAG and the Tez UI's page.
This commit is contained in:
1 parent
8418c7e674
commit
5fa518cf10
11 files changed
+1128
-43
No files matched your search
@@ -20,6 +20,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
import java.util.function.BooleanSupplier;
|
||||
@@ -40,7 +41,9 @@ import static org.junit.jupiter.api.Assertions.fail;
|
||||
* opens it, as the JobHistory server's link does; after a Spark step, whose event logs are in the cluster's HDFS, the
|
||||
* ResourceManager's answer links to the application on the Spark History Server's own host, which lists and opens it,
|
||||
* as the Spark History Server's link does; after a Hive step, its Tez DAG is in the YARN timeline server, and the Tez
|
||||
* UI's page names the timeline server and the ResourceManager on their own hosts, which answer its page's requests.
|
||||
* UI's page names the timeline server and the ResourceManager on their own hosts, which answer its page's requests. A
|
||||
* persistent application UI opens the Spark History Server while the cluster runs, and, once it has ended and its
|
||||
* storage has gone, its kept history: the Spark application, the DAG and the Tez UI's page.
|
||||
*
|
||||
* <p>A nightly check: the cluster's image, its HDFS and YARN, and a MapReduce job and a Spark one take minutes and
|
||||
* gigabytes.
|
||||
@@ -75,6 +78,9 @@ class EmrAppUiNightlyIntegrationTest {
|
||||
@Inject
|
||||
EmrService emrService;
|
||||
|
||||
@Inject
|
||||
EmrClusterStorage clusterStorage;
|
||||
|
||||
@BeforeAll
|
||||
static void configure() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
@@ -206,6 +212,51 @@ class EmrAppUiNightlyIntegrationTest {
|
||||
assertEquals(200, crossOrigin.statusCode(), crossOrigin.asString());
|
||||
String allowed = crossOrigin.getHeader("Access-Control-Allow-Origin");
|
||||
assertTrue(tezOrigin.equals(allowed) || "*".equals(allowed), String.valueOf(allowed));
|
||||
|
||||
// A persistent application UI: the cluster's own while it runs.
|
||||
String appUi = emr("CreatePersistentAppUI", "{\"TargetResourceArn\":\"arn:aws:elasticmapreduce:us-east-1:"
|
||||
+ "000000000000:cluster/" + clusterId + "\"}").then().statusCode(200).extract().jsonPath()
|
||||
.getString("PersistentAppUIId");
|
||||
JsonPath live = persistentLink(appUi, "SHS");
|
||||
assertTrue(live.getBoolean("PresignedURLReady"), live.prettify());
|
||||
assertEquals(200, open(live.getString("PresignedURL")).statusCode());
|
||||
// Once the cluster has ended and its storage has gone, its kept history, served by a container of its own.
|
||||
cleanup.register(() -> clusterStorage.removeHistoriesBut(Set.of()));
|
||||
terminateClusterAndAwaitCleanup(clusterId, emrService);
|
||||
String keptHistory = readyPersistentLink(appUi, "SHS");
|
||||
await(() -> open(keptHistory.replaceFirst("/$", "") + "/api/v1/applications").asString().contains(sparkId),
|
||||
Duration.ofMinutes(2));
|
||||
URI keptTimeline = URI.create(readyPersistentLink(appUi, "YTS"));
|
||||
Response keptDags = open(keptTimeline.getScheme() + "://" + keptTimeline.getRawAuthority()
|
||||
+ "/ws/v1/timeline/TEZ_DAG_ID");
|
||||
assertFalse(keptDags.jsonPath().getList("entities").isEmpty(), keptDags.asString());
|
||||
URI keptTez = URI.create(readyPersistentLink(appUi, "TEZ"));
|
||||
assertTrue(open(keptTez.toString()).asString().contains("<title>Tez UI</title>"));
|
||||
String keptConfig = open(keptTez.getScheme() + "://" + keptTez.getRawAuthority()
|
||||
+ "/tez-ui/config/configs.js").asString();
|
||||
String keptTimelineHost = "http://" + keptTez.getHost().substring(0, 26) + "-8188.emrappui.localhost:" + PORT;
|
||||
assertTrue(keptConfig.contains(keptTimelineHost), keptConfig);
|
||||
// With no ResourceManager there, the Tez UI asks the timeline server in its place, which answers, rather than
|
||||
// the primary node that has gone.
|
||||
assertFalse(keptConfig.contains("8088"), keptConfig);
|
||||
Response keptRm = open(keptTimelineHost + "/ws/v1/cluster/apps");
|
||||
assertTrue(keptRm.statusCode() < 500, keptRm.statusCode() + " " + keptRm.asString());
|
||||
}
|
||||
|
||||
private static JsonPath persistentLink(String appUi, String type) {
|
||||
return emr("GetPersistentAppUIPresignedURL", "{\"PersistentAppUIId\":\"" + appUi
|
||||
+ "\",\"PersistentAppUIType\":\"" + type + "\"}").then().statusCode(200).extract().jsonPath();
|
||||
}
|
||||
|
||||
// The link once it is ready: the history's container starts first.
|
||||
private static String readyPersistentLink(String appUi, String type) {
|
||||
String[] url = new String[1];
|
||||
await(() -> {
|
||||
JsonPath answer = persistentLink(appUi, type);
|
||||
url[0] = answer.getString("PresignedURL");
|
||||
return answer.getBoolean("PresignedURLReady");
|
||||
}, Duration.ofMinutes(10));
|
||||
return url[0];
|
||||
}
|
||||
|
||||
// A browser's request to the link, following the redirects it is sent, each to a link's host.
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.github.dockerjava.api.command.ExecCreateCmd;
|
||||
import com.github.dockerjava.api.command.InspectContainerCmd;
|
||||
import com.github.dockerjava.api.command.InspectContainerResponse;
|
||||
import com.github.dockerjava.api.command.InspectNetworkCmd;
|
||||
import com.github.dockerjava.api.command.InspectVolumeCmd;
|
||||
import com.github.dockerjava.api.command.InspectVolumeResponse;
|
||||
import com.github.dockerjava.api.command.ListContainersCmd;
|
||||
import com.github.dockerjava.api.command.ListNetworksCmd;
|
||||
@@ -131,6 +132,7 @@ class EmrClusterStorageTest {
|
||||
private final EmrClusterStorage storage = new EmrClusterStorage(lifecycle, containerBuilder, awsEnv,
|
||||
roleCredentials, currentContainer, config, s3, Duration.ofSeconds(120), System::nanoTime);
|
||||
private final String hdfsName = ContainerStorageHelper.dockerName(config, "emr-j-1-hdfs");
|
||||
private final String historyName = ContainerStorageHelper.dockerName(config, "emr-j-1-history");
|
||||
private final String coreName = ContainerStorageHelper.dockerName(config, "emr-j-1-node-1-1");
|
||||
private final String taskName = ContainerStorageHelper.dockerName(config, "emr-j-1-node-2-1");
|
||||
|
||||
@@ -1400,8 +1402,9 @@ class EmrClusterStorageTest {
|
||||
// interface and the ResourceManager's open to the Tez UI's page on its own host.
|
||||
return script.contains("timeline=; [ -z \"$FLOCI_YARN_TIMELINE\" ] || timeline=\"<property><name>"
|
||||
+ "yarn.timeline-service.enabled</name><value>true</value></property>")
|
||||
&& script.contains("timeline_store=/mnt/yarn/timeline\n")
|
||||
&& script.contains("<property><name>yarn.timeline-service.leveldb-timeline-store.path</name>"
|
||||
+ "<value>/mnt/yarn/timeline</value></property>")
|
||||
+ "<value>$timeline_store</value></property>")
|
||||
&& script.contains("<property><name>yarn.timeline-service.http-cross-origin.enabled</name>"
|
||||
+ "<value>true</value></property>")
|
||||
&& script.contains(" \"$timeline\" '</configuration>' > /tmp/floci-hdfs-conf/yarn-site.xml")
|
||||
@@ -1426,6 +1429,198 @@ class EmrClusterStorageTest {
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aPrimaryNodeThatRunsAHistoryInterfaceKeepsItsTimelineStoreInAVolumeThatOutlivesTheCluster() {
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.NOT_RUNNING);
|
||||
when(lifecycle.createAndStart(any())).thenReturn(new ContainerLifecycleManager.ContainerInfo("c-7", Map.of()));
|
||||
when(lifecycle.probeContainer("c-7")).thenReturn(ContainerLiveness.RUNNING);
|
||||
when(lifecycle.resolveContainerNetworkIp("c-7", hdfsName)).thenReturn("172.18.0.8");
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-7", 0L, "", "");
|
||||
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", null,
|
||||
() -> new ClusterStorage.Yarn(4096, 4).withSparkHistory(true).withHistories(true, false),
|
||||
NOT_STOPPED);
|
||||
|
||||
verify(lifecycle).ensureVolume(eq(historyName), argThat(labels -> "emr-history".equals(
|
||||
labels.get(ContainerStorageHelper.COMPONENT_LABEL))
|
||||
&& "j-1".equals(labels.get(ContainerStorageHelper.RESOURCE_ID_LABEL))));
|
||||
verify(spec).withNamedVolume(historyName, EmrClusterStorage.HISTORY_PATH);
|
||||
verify(spec).withEnv("FLOCI_HISTORY", "1");
|
||||
// Made the image's user's as root, the timeline server's store in it, kept as long as the history is.
|
||||
verify(spec).withEntrypoint(argThat(entrypoint -> entrypoint.get(2).contains(
|
||||
"if [ -n \"$FLOCI_HISTORY\" ]; then\n"
|
||||
+ " mkdir -p /var/lib/floci-history/spark-events /var/lib/floci-history/timeline"
|
||||
+ " && chown -R hadoop:hadoop /var/lib/floci-history || exit\n"
|
||||
+ " timeline_store=/var/lib/floci-history/timeline\nfi")
|
||||
&& entrypoint.get(2).contains("<property><name>yarn.timeline-service.ttl-ms</name>"
|
||||
+ "<value>2592000000</value></property>")));
|
||||
// Removing the cluster's storage leaves it.
|
||||
storage.remove("j-1");
|
||||
verify(lifecycle, never()).removeVolume(historyName);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aClustersSparkEventLogsAreCopiedIntoItsKeptHistoryWhileItsPrimaryNodeStillRuns() {
|
||||
InspectVolumeCmd inspect = mock(InspectVolumeCmd.class);
|
||||
when(docker.inspectVolumeCmd(historyName)).thenReturn(inspect);
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.RUNNING);
|
||||
List<List<String>> commands = ContainerExecStubs.completeEveryExec(docker, hdfsName, 0L, "", "");
|
||||
|
||||
assertTrue(storage.keepHistory("j-1"));
|
||||
|
||||
assertEquals(1, commands.size(), commands.toString());
|
||||
assertEquals(List.of("setpriv", "--reuid=hadoop", "--regid=hadoop", "--clear-groups", "bash", "-c"),
|
||||
commands.get(0).subList(0, 6));
|
||||
assertTrue(commands.get(0).get(6).endsWith("exec hdfs dfs -get -f '/var/log/spark/apps/*'"
|
||||
+ " /var/lib/floci-history/spark-events/"), commands.get(0).get(6));
|
||||
// A cluster that keeps no history has nothing copied.
|
||||
when(inspect.exec()).thenThrow(new NotFoundException("no such volume"));
|
||||
assertTrue(storage.keepHistory("j-1"));
|
||||
assertEquals(1, commands.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aFailedCopyOfTheSparkEventLogsIsReportedSoTheStorageStays() {
|
||||
when(docker.inspectVolumeCmd(historyName)).thenReturn(mock(InspectVolumeCmd.class));
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.RUNNING);
|
||||
ContainerExecStubs.completeEveryExec(docker, hdfsName, 1L, "", "get: Connection refused");
|
||||
|
||||
assertFalse(storage.keepHistory("j-1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aKeptHistoryIsServedByAContainerOfItsOwnStartedOnItsFirstLink() {
|
||||
String historyUi = ContainerStorageHelper.dockerName(config, "emr-j-1-history-ui");
|
||||
when(lifecycle.probeContainer(historyUi)).thenReturn(ContainerLiveness.NOT_RUNNING);
|
||||
when(docker.inspectVolumeCmd(historyName)).thenReturn(mock(InspectVolumeCmd.class));
|
||||
List<String> released = new ArrayList<>();
|
||||
ClusterStorage.Yarn yarn = new ClusterStorage.Yarn(4096, 4).withSparkHistory(true).withHistories(true, true);
|
||||
|
||||
Optional<ContainerLifecycleManager.EndpointInfo> starting = storage.historyInterface("j-1", "123456789012",
|
||||
"us-east-1", () -> IMAGE, released::add, HOST, yarn, EmrServerlessSparkRunner.SPARK_HISTORY_WEB_PORT);
|
||||
|
||||
assertTrue(starting.isEmpty());
|
||||
verify(spec).withName(historyUi);
|
||||
verify(spec).withNamedVolume(historyName, EmrClusterStorage.HISTORY_PATH);
|
||||
// On a network of its own, so no step's container reaches it.
|
||||
verify(lifecycle).ensureNetwork(eq(historyName), argThat(labels -> "emr-history".equals(
|
||||
labels.get(ContainerStorageHelper.COMPONENT_LABEL))));
|
||||
verify(spec).withDockerNetwork(Optional.of(historyName));
|
||||
verify(spec).withEnv("FLOCI_HDFS_HOST", HOST);
|
||||
verify(spec).withEnv("FLOCI_SPARK_HISTORY", "1");
|
||||
verify(spec).withEnv("FLOCI_YARN_TIMELINE", "1");
|
||||
verify(spec).withEnv("FLOCI_TEZ_UI", "1");
|
||||
verify(spec).withLoopbackPortBinding(EmrServerlessSparkRunner.SPARK_HISTORY_WEB_PORT, 0);
|
||||
verify(spec).withLoopbackPortBinding(EmrClusterStorage.TIMELINE_WEB_PORT, 0);
|
||||
verify(spec).withLoopbackPortBinding(EmrClusterStorage.TEZ_UI_PORT, 0);
|
||||
verify(spec).withLabels(argThat(labels -> "emr-history".equals(
|
||||
labels.get(ContainerStorageHelper.COMPONENT_LABEL))));
|
||||
// The event logs from the history, the timeline server on its store, as the cluster's ran them.
|
||||
verify(spec).withEntrypoint(argThat(entrypoint -> entrypoint.get(2).contains(
|
||||
"-Dspark.history.fs.logDirectory=file:///var/lib/floci-history/spark-events")
|
||||
&& entrypoint.get(2).contains("<property><name>yarn.timeline-service.leveldb-timeline-store.path"
|
||||
+ "</name><value>/var/lib/floci-history/timeline</value></property>")
|
||||
// With no ResourceManager there, the Tez UI asks the timeline server in its place.
|
||||
&& entrypoint.get(2).contains("\" rm: 'http://$FLOCI_HDFS_HOST:8188',\"")));
|
||||
verify(lifecycle).createAndStart(any());
|
||||
assertEquals(List.of(IMAGE), released);
|
||||
|
||||
ContainerLifecycleManager.EndpointInfo published = new ContainerLifecycleManager.EndpointInfo("localhost",
|
||||
32804);
|
||||
when(lifecycle.probeContainer(historyUi)).thenReturn(ContainerLiveness.RUNNING);
|
||||
when(lifecycle.resolveEndpoint(historyUi, EmrServerlessSparkRunner.SPARK_HISTORY_WEB_PORT, historyName))
|
||||
.thenReturn(published);
|
||||
ContainerExecStubs.completeEveryExec(docker, historyUi, 0L, "", "");
|
||||
assertEquals(Optional.of(published), storage.historyInterface("j-1", "123456789012", "us-east-1",
|
||||
() -> IMAGE, released::add, HOST, yarn, EmrServerlessSparkRunner.SPARK_HISTORY_WEB_PORT));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aHistoryContainerStartedThroughATeardownIsRemovedAndNoneStartsOnceTheHistoryHasGone() {
|
||||
String historyUi = ContainerStorageHelper.dockerName(config, "emr-j-1-history-ui");
|
||||
when(lifecycle.probeContainer(historyUi)).thenReturn(ContainerLiveness.NOT_RUNNING);
|
||||
InspectVolumeCmd inspect = mock(InspectVolumeCmd.class);
|
||||
when(docker.inspectVolumeCmd(historyName)).thenReturn(inspect);
|
||||
ClusterStorage.Yarn yarn = new ClusterStorage.Yarn(4096, 4).withSparkHistory(true);
|
||||
when(lifecycle.createAndStart(any())).thenReturn(new ContainerLifecycleManager.ContainerInfo("h-1", Map.of()));
|
||||
// A teardown runs as it starts, before its name is known, so the teardown misses it.
|
||||
doAnswer(network -> {
|
||||
storage.stopManagedContainers();
|
||||
return null;
|
||||
}).when(lifecycle).ensureNetwork(eq(historyName), any());
|
||||
|
||||
storage.historyInterface("j-1", "123456789012", "us-east-1", () -> IMAGE, image -> { }, HOST, yarn,
|
||||
EmrServerlessSparkRunner.SPARK_HISTORY_WEB_PORT);
|
||||
|
||||
// Once in place of any left before it, and once as it started through the teardown.
|
||||
verify(lifecycle, times(2)).removeIfExistsStrict(historyUi);
|
||||
// Its history gone, as its 30 days passed: no container makes its volume again, empty.
|
||||
when(inspect.exec()).thenThrow(new NotFoundException("no such volume"));
|
||||
storage.historyInterface("j-1", "123456789012", "us-east-1", () -> IMAGE, image -> { }, HOST, yarn,
|
||||
EmrServerlessSparkRunner.SPARK_HISTORY_WEB_PORT);
|
||||
verify(lifecycle, times(1)).createAndStart(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aFailureToTellWhetherAHistoryIsKeptIsNotTakenForNone() {
|
||||
InspectVolumeCmd inspect = mock(InspectVolumeCmd.class);
|
||||
when(docker.inspectVolumeCmd(historyName)).thenReturn(inspect);
|
||||
when(inspect.exec()).thenThrow(new IllegalStateException("Docker went away"));
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> storage.historyKept("j-1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aRunningPrimaryNodesEventLogsAreKeptBeforeATeardownRemovesIt() {
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.NOT_RUNNING, ContainerLiveness.RUNNING);
|
||||
when(lifecycle.createAndStart(any())).thenReturn(new ContainerLifecycleManager.ContainerInfo("c-7", Map.of()));
|
||||
when(lifecycle.probeContainer("c-7")).thenReturn(ContainerLiveness.RUNNING);
|
||||
when(lifecycle.resolveContainerNetworkIp("c-7", hdfsName)).thenReturn("172.18.0.8");
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-7", 0L, "", "");
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", null,
|
||||
() -> new ClusterStorage.Yarn(4096, 4).withSparkHistory(true), NOT_STOPPED);
|
||||
List<List<String>> commands = ContainerExecStubs.completeEveryExec(docker, hdfsName, 0L, "", "");
|
||||
|
||||
storage.stopManagedContainers();
|
||||
|
||||
assertTrue(commands.stream().anyMatch(command -> command.get(command.size() - 1)
|
||||
.contains("hdfs dfs -get -f '/var/log/spark/apps/*'")), commands.toString());
|
||||
// Once as it was created, in place of any left before it, and once by the teardown.
|
||||
verify(lifecycle, times(2)).removeIfExistsStrict(hdfsName);
|
||||
}
|
||||
|
||||
@Test
|
||||
void theKeptHistoriesOfClustersNotKeptGoTheirContainersFirst() {
|
||||
Container gone = historyContainer("c-gone", "j-1");
|
||||
Container kept = historyContainer("c-kept", "j-2");
|
||||
ListContainersCmd containers = mock(ListContainersCmd.class, RETURNS_SELF);
|
||||
when(docker.listContainersCmd()).thenReturn(containers);
|
||||
when(containers.exec()).thenReturn(List.of(gone, kept));
|
||||
InspectVolumeResponse goneVolume = mock(InspectVolumeResponse.class);
|
||||
when(goneVolume.getName()).thenReturn(historyName);
|
||||
when(goneVolume.getLabels()).thenReturn(Map.of(ContainerStorageHelper.RESOURCE_ID_LABEL, "j-1"));
|
||||
InspectVolumeResponse keptVolume = mock(InspectVolumeResponse.class);
|
||||
when(keptVolume.getName()).thenReturn("floci-aws-emr-j-2-history");
|
||||
when(keptVolume.getLabels()).thenReturn(Map.of(ContainerStorageHelper.RESOURCE_ID_LABEL, "j-2"));
|
||||
nodeVolumes(goneVolume, keptVolume);
|
||||
|
||||
storage.removeHistoriesBut(Set.of("j-2"));
|
||||
|
||||
verify(lifecycle).removeIfExistsStrict("c-gone");
|
||||
verify(lifecycle, never()).removeIfExistsStrict("c-kept");
|
||||
verify(lifecycle).removeVolume(historyName);
|
||||
verify(lifecycle).removeNetwork(historyName);
|
||||
verify(lifecycle, never()).removeVolume("floci-aws-emr-j-2-history");
|
||||
}
|
||||
|
||||
private static Container historyContainer(String id, String clusterId) {
|
||||
Container container = mock(Container.class);
|
||||
when(container.getId()).thenReturn(id);
|
||||
when(container.getLabels()).thenReturn(Map.of(ContainerStorageHelper.RESOURCE_ID_LABEL, clusterId,
|
||||
ContainerStorageHelper.COMPONENT_LABEL, "emr-history"));
|
||||
return container;
|
||||
}
|
||||
|
||||
@Test
|
||||
void aClusterWithSparkHasItsPrimaryNodeRunASparkHistoryServerOnItsApplicationsEventLogs() {
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.NOT_RUNNING);
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
package io.floci.aws.services.emr;
|
||||
|
||||
import io.floci.aws.core.common.LinkSigner;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.common.docker.ContainerLifecycleManager;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.services.emr.model.EmrCluster;
|
||||
import io.floci.aws.services.emr.model.EmrPersistentAppUi;
|
||||
import io.floci.aws.services.emrserverless.EmrServerlessSparkRunner;
|
||||
import io.floci.aws.services.emrserverless.SparkJobRunner;
|
||||
import io.floci.aws.services.iam.IamService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
import static io.floci.aws.services.emr.EmrServiceFixture.ACCOUNT;
|
||||
import static io.floci.aws.services.emr.EmrServiceFixture.REGION;
|
||||
import static io.floci.aws.services.emr.EmrServiceFixture.cluster;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Persistent application UI links in the docker runner mode ({@link EmrAppUiService}): while the cluster runs, its
|
||||
* primary node's interface; once it has ended, for 30 days, its kept history's, served by a container of its own
|
||||
* that starts on the link and stops once no link to it is valid.
|
||||
*/
|
||||
class EmrPersistentAppUiTest {
|
||||
|
||||
private static final int SPARK_HISTORY = EmrServerlessSparkRunner.SPARK_HISTORY_WEB_PORT;
|
||||
private static final ContainerLifecycleManager.EndpointInfo ON_HOST =
|
||||
new ContainerLifecycleManager.EndpointInfo("localhost", 32803);
|
||||
|
||||
private final EmrServiceFixture fixture = EmrServiceFixture.docker(new FinishingRunner(),
|
||||
mock(IamService.class));
|
||||
private final EmrAppUiService appUis = new EmrAppUiService(
|
||||
AccountAwareStorageBackend.<EmrPersistentAppUi>inMemory(ACCOUNT), fixture.service,
|
||||
new RegionResolver(REGION, ACCOUNT), fixture.clock, "http://localhost:4566", LinkSigner.withNewKey());
|
||||
|
||||
@Test
|
||||
void aPersistentUiOpensItsClustersLiveInterfaceWhileTheClusterRuns() {
|
||||
fixture.clusterStorage.webInterfaces.put(SPARK_HISTORY, ON_HOST);
|
||||
EmrCluster cluster = sparkCluster();
|
||||
String appUi = appUis.create(arn(cluster), null, null).appUi().getId();
|
||||
|
||||
EmrAppUiService.Presigned link = appUis.persistentUrl(appUi, "SHS", "application_1_0001");
|
||||
|
||||
assertTrue(link.ready());
|
||||
URI url = URI.create(link.url());
|
||||
assertTrue(url.getAuthority().contains("-18080.emrappui."), link.url());
|
||||
assertEquals("/history/application_1_0001/", url.getPath());
|
||||
assertEquals(32803, appUis.route(url.getAuthority(), "http").port());
|
||||
}
|
||||
|
||||
@Test
|
||||
void onceItsClusterHasEndedItOpensTheKeptHistoryUntilItsThirtyDaysHavePassed() {
|
||||
EmrCluster cluster = sparkCluster();
|
||||
String appUi = appUis.create(arn(cluster), null, null).appUi().getId();
|
||||
startAndEnd(cluster);
|
||||
|
||||
// What its interfaces show was kept before its storage went.
|
||||
assertEquals(List.of("kept " + cluster.getId()), fixture.clusterStorage.historyEvents);
|
||||
EmrAppUiService.Presigned starting = appUis.persistentUrl(appUi, "SHS", null);
|
||||
|
||||
assertFalse(starting.ready());
|
||||
String primary = EmrService.masterPrivateDnsName(cluster);
|
||||
assertEquals("starting " + cluster.getId() + " as " + primary,
|
||||
fixture.clusterStorage.historyEvents.get(1));
|
||||
URI url = URI.create(starting.url());
|
||||
assertEquals(EmrAppUiService.HISTORY_NOT_READY, appUis.route(url.getAuthority(), "http").refusal());
|
||||
fixture.clusterStorage.historyInterfaces.put(SPARK_HISTORY, ON_HOST);
|
||||
EmrAppUiService.UiRoute route = appUis.route(url.getAuthority(), "http");
|
||||
assertNull(route.refusal());
|
||||
assertEquals(32803, route.port());
|
||||
assertTrue(appUis.persistentUrl(appUi, "SHS", null).ready());
|
||||
|
||||
fixture.clock.advance(EmrService.HISTORY_KEPT);
|
||||
assertTrue(appUis.persistentUrl(appUi, "SHS", null).url()
|
||||
.startsWith("http://localhost:4566" + EmrAppUiService.PATH + "?"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theContainerServingAKeptHistoryStopsOnceNoLinkToItIsValid() {
|
||||
EmrCluster cluster = sparkCluster();
|
||||
String appUi = appUis.create(arn(cluster), null, null).appUi().getId();
|
||||
startAndEnd(cluster);
|
||||
fixture.clusterStorage.historyInterfaces.put(SPARK_HISTORY, ON_HOST);
|
||||
appUis.persistentUrl(appUi, "SHS", null);
|
||||
|
||||
appUis.reapHistory(ACCOUNT, REGION, cluster.getId());
|
||||
assertFalse(fixture.clusterStorage.historyEvents.contains("stopped " + cluster.getId()));
|
||||
fixture.clock.advance(EmrAppUiService.VALIDITY);
|
||||
appUis.reapHistory(ACCOUNT, REGION, cluster.getId());
|
||||
|
||||
assertTrue(fixture.clusterStorage.historyEvents.contains("stopped " + cluster.getId()));
|
||||
// The histories within their 30 days stay, the cluster's among them.
|
||||
assertTrue(fixture.clusterStorage.historySweeps.getLast().contains(cluster.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aLinkAskedWhileItsClustersStorageIsStillGoingIsNotReadyAndStartsNothing() {
|
||||
EmrCluster cluster = sparkCluster();
|
||||
String appUi = appUis.create(arn(cluster), null, null).appUi().getId();
|
||||
appUis.onClusterUrl(cluster.getId(), null, null, false);
|
||||
fixture.runStepThread();
|
||||
// Its history's volume, which the node made as it started.
|
||||
fixture.clusterStorage.historiesKept.add(cluster.getId());
|
||||
fixture.service.terminateJobFlows(List.of(cluster.getId()));
|
||||
|
||||
// Its primary node may still hold the timeline server's store, and its event logs are not yet copied.
|
||||
EmrAppUiService.Presigned link = appUis.persistentUrl(appUi, "SHS", null);
|
||||
|
||||
assertFalse(link.ready());
|
||||
assertTrue(fixture.clusterStorage.historyEvents.stream().noneMatch(event -> event.startsWith("starting")),
|
||||
fixture.clusterStorage.historyEvents.toString());
|
||||
endStorage(cluster);
|
||||
assertFalse(appUis.persistentUrl(appUi, "SHS", null).ready());
|
||||
assertEquals("starting " + cluster.getId() + " as " + EmrService.masterPrivateDnsName(cluster),
|
||||
fixture.clusterStorage.historyEvents.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aFailedCopyOfItsEventLogsKeepsTheClustersStorageForALaterTry() {
|
||||
EmrCluster cluster = sparkCluster();
|
||||
String appUi = appUis.create(arn(cluster), null, null).appUi().getId();
|
||||
appUis.onClusterUrl(cluster.getId(), null, null, false);
|
||||
fixture.runStepThread();
|
||||
fixture.clusterStorage.historiesKept.add(cluster.getId());
|
||||
fixture.clusterStorage.keepFails = true;
|
||||
fixture.service.terminateJobFlows(List.of(cluster.getId()));
|
||||
while (fixture.stepThreadsWaiting() > 0) {
|
||||
fixture.runStepThread();
|
||||
}
|
||||
|
||||
// Its HDFS, which holds the event logs, stays, and its history is not yet there to open.
|
||||
assertEquals(List.of("could not keep " + cluster.getId()), fixture.clusterStorage.historyEvents);
|
||||
assertFalse(fixture.clusterStorage.removed.contains(cluster.getId()));
|
||||
assertTrue(fixture.service.describeCluster(cluster.getId()).isStorageCreated());
|
||||
assertFalse(appUis.persistentUrl(appUi, "SHS", null).ready());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aKeptHistoryNoLinkAskedForGoesOnceItsThirtyDaysHavePassed() {
|
||||
EmrCluster cluster = sparkCluster();
|
||||
startAndEnd(cluster);
|
||||
assertTrue(fixture.clusterStorage.historySweeps.isEmpty());
|
||||
|
||||
// The sweep its end set, a minute past its 30 days.
|
||||
fixture.pass(EmrService.HISTORY_KEPT);
|
||||
|
||||
assertFalse(fixture.clusterStorage.historySweeps.isEmpty());
|
||||
assertFalse(fixture.clusterStorage.historySweeps.getLast().contains(cluster.getId()));
|
||||
}
|
||||
|
||||
// Its primary node started, as a link to it before any step starts it, then the cluster ended, its storage gone.
|
||||
private void startAndEnd(EmrCluster cluster) {
|
||||
appUis.onClusterUrl(cluster.getId(), null, null, false);
|
||||
fixture.runStepThread();
|
||||
fixture.service.terminateJobFlows(List.of(cluster.getId()));
|
||||
endStorage(cluster);
|
||||
}
|
||||
|
||||
private void endStorage(EmrCluster cluster) {
|
||||
while (fixture.stepThreadsWaiting() > 0) {
|
||||
fixture.runStepThread();
|
||||
}
|
||||
assertTrue(fixture.clusterStorage.removed.contains(cluster.getId()));
|
||||
fixture.clock.advance(Duration.ofMinutes(1));
|
||||
}
|
||||
|
||||
private EmrCluster sparkCluster() {
|
||||
fixture.clusterStorage.ownNetwork = true;
|
||||
EmrCluster cluster = cluster("history", true);
|
||||
cluster.setReleaseLabel("emr-7.5.0");
|
||||
cluster.setApplications("[{\"Name\":\"Hadoop\"},{\"Name\":\"Spark\"}]");
|
||||
return fixture.service.runJobFlow(cluster, REGION);
|
||||
}
|
||||
|
||||
private static String arn(EmrCluster cluster) {
|
||||
return "arn:aws:elasticmapreduce:us-east-1:000000000000:cluster/" + cluster.getId();
|
||||
}
|
||||
|
||||
/** Ends each command at once, as the Docker runner would one that runs nothing. */
|
||||
private static final class FinishingRunner implements SparkJobRunner {
|
||||
|
||||
@Override
|
||||
public Outcome run(Job job, Progress progress) {
|
||||
progress.started();
|
||||
return Outcome.exitedWith(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(String runId) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLeftoverDrivers(String service) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@@ -101,6 +102,14 @@ final class EmrServiceFixture {
|
||||
final List<String> released = new ArrayList<>();
|
||||
// Where each port of a primary node's web interfaces is reached, once the node is ready.
|
||||
final Map<Integer, ContainerLifecycleManager.EndpointInfo> webInterfaces = new HashMap<>();
|
||||
// The clusters whose history is kept; where each port of a kept history's container is reached, once it
|
||||
// answers; what was asked of the histories, in order; and the clusters each sweep kept.
|
||||
final Set<String> historiesKept = new HashSet<>();
|
||||
final Map<Integer, ContainerLifecycleManager.EndpointInfo> historyInterfaces = new HashMap<>();
|
||||
final List<String> historyEvents = new ArrayList<>();
|
||||
final List<Set<String>> historySweeps = new ArrayList<>();
|
||||
// Whether copying a cluster's event logs into its kept history fails.
|
||||
boolean keepFails;
|
||||
// How each cluster's nodes are known as EC2 instances.
|
||||
final Map<String, Function<String, Instance>> identities = new HashMap<>();
|
||||
|
||||
@@ -159,6 +168,43 @@ final class EmrServiceFixture {
|
||||
return Optional.ofNullable(webInterfaces.get(port));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keepHistory(String clusterId) {
|
||||
if (keepFails) {
|
||||
historyEvents.add("could not keep " + clusterId);
|
||||
return false;
|
||||
}
|
||||
historyEvents.add("kept " + clusterId + (removed.contains(clusterId) ? " after its removal" : ""));
|
||||
historiesKept.add(clusterId);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean historyKept(String clusterId) {
|
||||
return historiesKept.contains(clusterId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ContainerLifecycleManager.EndpointInfo> historyInterface(String clusterId, String accountId,
|
||||
String region, Supplier<String> image, Consumer<String> released, String primaryHost, Yarn yarn,
|
||||
int port) {
|
||||
ContainerLifecycleManager.EndpointInfo endpoint = historyInterfaces.get(port);
|
||||
if (endpoint == null) {
|
||||
historyEvents.add("starting " + clusterId + " as " + primaryHost);
|
||||
}
|
||||
return Optional.ofNullable(endpoint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopHistory(String clusterId) {
|
||||
historyEvents.add("stopped " + clusterId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHistoriesBut(Set<String> kept) {
|
||||
historySweeps.add(Set.copyOf(kept));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(String clusterId, Supplier<Yarn> yarn) {
|
||||
resizes.add(yarn.get());
|
||||
|
||||
Reference in new issue
Block a user