feat(emr): run a step's MapReduce and Hive's Tez on the cluster's YARN (#8151)

Where a docker cluster runs YARN its Spark ran on it, while MapReduce and
Hive's Tez stayed in local mode, in the step's container, and a job's own
-D mapreduce.framework.name=yarn failed.

- A step's mapred-site names YARN and the layout of the cluster's nodes,
  which yarn.application.classpath's default does not, S3A's AWS SDK, and
  the step's AWS environment for the application master and tasks, sized
  for a NodeManager; the cluster's mapred-site replaces them.
- A step's hadoop, hadoop-streaming and hdfs dfs run from the nodes'
  Hadoop, /usr/lib or an emr-spark-* release's /opt, set for that command
  alone, so a spark-submit in the same step keeps the release's own.
- The images hold EMR Serverless's build of Tez, whose tez-site.xml names
  its own plugins. On YARN a Hive step names the stock classes from the
  same jars, real ports and bind addresses, ${env.NM_HOST} left for the
  application master's node to fill in, Tez's jars from the node's own
  disk, and one virtual core a task, as YARN's default scheduler grants
  one and Tez gives back a container that does not match what it asked.
  Intermediate compression is off, as the image's codec needs a native
  library it lacks.

Where a cluster runs no YARN, MapReduce and Tez stay in local mode.

Two Docker cases check that a streaming job's tasks and a Hive query's
Tez tasks run in YARN's containers on the cluster's nodes. With them the
two EMR Docker classes take 651s and 402s on CI's runners, so the shard
partitioner weighs them at that, as at 280s and 260s their shard ran into
Surefire's 25 minutes.

With that split, PipesStreamEnrichmentDockerIntegrationTest ran in a JVM
where no class before it had told RestAssured how to send and read
DynamoDB's application/x-amz-json-1.0, which it relied on; it now does so
itself, as other tests do.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-12 19:20:56 -04:00
1 parent f41c4ee5c0
commit 54ea160aa6
8 files changed
+463 -40

No files matched your search

+4 -2
View File
@@ -25,9 +25,11 @@ AUGMENTATION_WEIGHT = 10 # one augmentation ~ 5.4s ~ 10 average test classes
# 220 average classes, and the shard that held them both ran over 200s longer than any other
# (1246s of Surefire's 1500s, against 641s to 869s for the rest). A shard's other classes are
# packed around them; a class that stops being this slow only leaves the shards a little uneven.
# They took 651s and 402s on 2026-11-12, once their cases had grown, and weighed at 280s and 260s
# their shard ran into Surefire's 1500s while the others finished in 16 to 20 minutes.
SLOW_CLASSES = {
'EmrDockerRunnerDockerIntegrationTest': 280,
'EmrHiveStepsDockerIntegrationTest': 260,
'EmrDockerRunnerDockerIntegrationTest': 650,
'EmrHiveStepsDockerIntegrationTest': 400,
}
SECONDS_PER_CLASS = 1.2 # the suite's mean: 4212s over 3451 classes on 2026-11-09
+22 -11
View File
@@ -139,7 +139,8 @@ holding the driver and its executors, or a command or a script. The cluster itse
Management Guide writes Spark steps, runs the arguments after it, with its `--master` and `--deploy-mode` as
given where the cluster runs YARN (see **YARN**) and without them where it does not. A custom JAR step runs its `MainClass`, or else the one its manifest names, through
`spark-submit`, with the JAR and the step's `Args`; a MapReduce job it starts, such as the Management
Guide's `wordcount` of Hadoop's examples JAR, runs in local mode (see **Hadoop streaming and MapReduce**).
Guide's `wordcount` of Hadoop's examples JAR, runs on the cluster's YARN, or in local mode where it runs none (see
**Hadoop streaming and MapReduce**).
A `Jar` of `/usr/lib/hadoop-mapreduce/hadoop-streaming.jar`, where EMR has it, runs the image's
`/usr/lib/hadoop/hadoop-streaming.jar`. Any other `command-runner.jar` step runs its
command, its first argument, with the rest, and a `script-runner.jar` step (by name, or by its
@@ -207,8 +208,8 @@ holding the driver and its executors, or a command or a script. The cluster itse
folder a `spark-env` export of `HADOOP_CONF_DIR` names, with the cluster's `core-site` after it, which wins; the
image's `hdfs` command cannot run, so `hdfs dfs` runs as `hadoop fs`, and its other commands fail. A structured
streaming query keeps its checkpoints through Spark's file system checkpoint manager, as its default one refuses
an `hdfs://` path without a host. In a command's Hadoop configuration, which a custom JAR's MapReduce in the
driver reads too, the `hdfs` scheme is a view of that HDFS in which one folder, `/tmp/hadoop/mapred/staging`, is
an `hdfs://` path without a host. Where the cluster runs no YARN, in a command's Hadoop configuration, which a custom
JAR's MapReduce in the driver reads too, the `hdfs` scheme is a view of that HDFS in which one folder, `/tmp/hadoop/mapred/staging`, is
the container's own, for MapReduce in local mode (see **Hadoop streaming and MapReduce**); Spark and Hive keep
HDFS's own client, so a Spark step can write a Hive table there. The HDFS container, its network and the volumes
go once the cluster has ended and its last step is done ("HDFS is ephemeral storage that is reclaimed when you terminate a
@@ -218,7 +219,8 @@ holding the driver and its executors, or a command or a script. The cluster itse
* **YARN**: on a Docker network of the cluster's own, the default, "the primary node runs the YARN ResourceManager
service", as the Management Guide puts it, in the primary node's container, with a NodeManager beside it on a cluster
created with no core node, which keeps it, and its DataNode, as core nodes are added, the blocks it holds staying in
reach, and the cluster's Spark runs on them. A
reach, and the cluster's Spark, MapReduce (see **Hadoop streaming and MapReduce**) and Hive's Tez (see **Hive steps**)
run on them. A
Spark step or custom JAR step submits to it, with `--master yarn` unless it names another master, and in the deploy
mode it asks for, `client` when it names none, and so does a `spark-submit` a command or script starts. In client
mode the driver stays in the step's container and its output in the step's logs, and the executors run in YARN's
@@ -258,8 +260,13 @@ holding the driver and its executors, or a command or a script. The cluster itse
again. A core node a resize brings back under its name in that minute takes no new blocks until it is over. A core
node that stops before HDFS has moved its blocks starts again on its data, and one a shutdown of Floci cut off while
it was being decommissioned starts again on its data with the cluster's next step, to be decommissioned then.
* **Hadoop streaming and MapReduce**: a step's `hadoop` command runs MapReduce in local mode, in its own JVM, on the
YARN clusters too (see **Known limitations**): the image has MapReduce only in Spark's shaded Hadoop client, which
* **Hadoop streaming and MapReduce**: on a cluster that runs YARN (see **YARN**), a step's MapReduce runs there, its
application master and tasks in YARN's containers on the cluster's nodes. A step's `hadoop` command, and so
`hadoop-streaming`, a `hadoop jar` and `hdfs dfs`, run from the nodes' Hadoop (`/usr/lib`, or the one an `emr-spark-*`
release keeps in `/opt`), with a `mapred-site.xml` that names YARN, the nodes' folders and the step's AWS environment,
and an application master of 1 GB and tasks of 768 MB, which the cluster's `mapred-site` replaces. A custom JAR step's
MapReduce gets the same. Where the cluster runs no YARN, a step's `hadoop` command runs MapReduce in local mode, in
its own JVM: the image has MapReduce only in Spark's shaded Hadoop client, which
Floci makes the
command's MapReduce home (`HADOOP_MAPRED_HOME`, unless a `spark-env` export names one), so it is on the
command's class path whatever `HADOOP_CLASSPATH` a command sets, and a copy of its `mapred-site.xml` sets
@@ -310,12 +317,14 @@ holding the driver and its executors, or a command or a script. The cluster itse
on its class path, while the cluster's other steps keep the release image's. Then a `command-runner.jar` step
running `hive-script`, as the AWS CLI writes a `Type=Hive` step (`hive-script --run-hive-script --args` and the
step's `Args`), or `hive` itself, runs Hive: `hive-script` runs `hive` with the arguments after `--args`, as the
image's `hadoop` user in `/home/hadoop`, with Tez in local mode in its JVM, as an [EMR Serverless Hive job
run](emr-serverless.md#running-hive-job-runs)'s does, on the cluster's storage. It gets the cluster's `core-site`,
image's `hadoop` user in `/home/hadoop`, on the cluster's storage, its Tez on the cluster's YARN, or, where it runs
none, in local mode in its JVM, as an [EMR Serverless Hive job run](emr-serverless.md#running-hive-job-runs)'s does.
The images hold EMR Serverless's build of Tez, whose `tez-site.xml` names its own plugins, so on YARN Hive runs the
stock classes from the same jars, with an application master of 1 GB and tasks of 768 MB and one virtual core. It gets the cluster's `core-site`,
`tez-site` and `hive-site` properties, each a `--hiveconf`, then the step's own arguments, so a `--hiveconf` of
the step's wins over a classification's, as it does over `hive-site.xml`; the cluster's `hive-env` exports are its
environment. Floci's settings come before them all, and any of them replaces one: S3A on Floci's S3 for `s3://`,
Tez in local mode, the cluster's HDFS, and its metastore. "By default, Hive records metastore information in a
where Tez runs, the cluster's HDFS, and its metastore. "By default, Hive records metastore information in a
MySQL database on the primary node's file system", which Floci keeps in a Derby database of the metastore service
its primary node runs (see **Storage**), so a table one Hive step makes is there for the next, until the cluster
ends, and any number of Hive steps use it at once. The `hive-site` setting of
@@ -493,8 +502,10 @@ holding the driver and its executors, or a command or a script. The cluster itse
- **No YARN in a network namespace the steps share, or with no network.** With `docker-network` set to `host` or
`container:<id>`, YARN's daemons would listen on every interface of the namespace, and with `none` the steps could not
reach them, so the cluster's Spark runs in local mode.
- **MapReduce and Tez in local mode.** On a cluster that runs YARN too, `hadoop-streaming`, a custom JAR's MapReduce and
Hive's Tez run in the step's container.
- **MapReduce and Tez in local mode where there is no YARN.** Only a cluster that runs YARN (see **YARN**) runs them on
it; on any other, `hadoop-streaming`, a custom JAR's MapReduce and Hive's Tez run in the step's container.
- **Tez's intermediate data is not compressed on YARN.** The images name the LZO codec for it, whose native library they
lack, so Floci turns that compression off, which a `tez-site` classification can turn back on with a codec they have.
- **No Hive metastore service in a network namespace the steps share.** With `docker-network` set to `host` or
`container:<id>`, the primary node runs HDFS but not Hive's metastore service: Hive 3's has no setting for the
address it listens on, so it would serve its tables, and the files under them, on every interface of the
@@ -118,12 +118,6 @@ public class EmrClusterStorage implements ClusterStorage, ContainerTeardown {
// The ResourceManager's cluster metrics on its web port, which say when the NodeManager has registered.
private static final String RESOURCE_MANAGER_METRICS = "http://127.0.0.1:8088/ws/v1/cluster/metrics";
private static final String RESOURCE_MANAGER_NODES = "http://127.0.0.1:8088/ws/v1/cluster/nodes?states=";
// The java.base packages Hadoop 3.4's YARN daemons reach into, which Java 17 opens only when told, through
// JDK_JAVA_OPTIONS, which Java 9 on reads and Java 8, on which a release may run and which refuses the options
// themselves, ignores.
private static final List<String> YARN_OPENED_PACKAGES = List.of("java.lang", "java.lang.reflect",
"java.lang.invoke", "java.util", "java.util.concurrent", "java.util.regex", "java.net", "java.io",
"java.nio", "sun.nio.ch", "sun.nio.cs", "sun.security.action", "sun.util.calendar");
// Where a NodeManager keeps its containers' logs, on the node's volume, as <application>/<container>/<file>.
private static final String YARN_LOGS = "/mnt/yarn/logs";
private static final int LOG_LISTING_SECONDS = 30;
@@ -1045,10 +1039,9 @@ public class EmrClusterStorage implements ClusterStorage, ContainerTeardown {
return properties.toString();
}
// The JVM options that open YARN_OPENED_PACKAGES to Hadoop's classes.
// The JVM options that open to Hadoop's classes the packages its daemons reach into.
private static String yarnOpens() {
return YARN_OPENED_PACKAGES.stream().map(name -> "--add-opens=java.base/" + name + "=ALL-UNNAMED")
.collect(Collectors.joining(" "));
return EmrServerlessSparkRunner.yarnJavaOptions();
}
// A cluster's HDFS container, started anew on the HDFS data its volume holds, which goes with the cluster's other
@@ -50,6 +50,7 @@ import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.function.BooleanSupplier;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.zip.GZIPOutputStream;
/**
@@ -87,6 +88,22 @@ public class EmrServerlessSparkRunner implements SparkJobRunner, ContainerTeardo
// The copies of a block a cluster's core nodes keep, as an hdfs-site.xml property: there, as the image's own says two
// and a Hadoop client reads hdfs-site.xml after core-site.xml.
private static final String HDFS_SITE_VARIABLE = "FLOCI_HDFS_SITE";
// Where a step on its cluster's YARN finds the ResourceManager, as a yarn-site.xml property, a Hadoop client reading
// yarn-site.xml after core-site.xml.
private static final String YARN_SITE_VARIABLE = "FLOCI_YARN_SITE";
// The folder of a step's image holding the Hadoop its cluster's nodes run from, which its hadoop command runs from
// on YARN, as the MapReduce home the local job runner uses has no YARN client to speak of.
private static final String HADOOP_ROOT_VARIABLE = "FLOCI_HADOOP_ROOT";
// S3A's AWS SDK, in the folder a release keeps it in or in the jar the others keep it in, each harmless where it is
// not.
private static final List<String> AWS_SDK_JARS = List.of("/usr/share/aws/aws-java-sdk-v2/*",
"/usr/share/aws/emr/serverless-goodies/lib/emr-serverless-spark-goodies.jar");
// The java.base packages Hadoop 3.4's JVMs reach into, which Java 17 opens only when told, through
// JDK_JAVA_OPTIONS, which Java 9 on reads and Java 8, on which a release may run and which refuses the options
// themselves, ignores.
private static final List<String> YARN_OPENED_PACKAGES = List.of("java.lang", "java.lang.reflect",
"java.lang.invoke", "java.util", "java.util.concurrent", "java.util.regex", "java.net", "java.io",
"java.nio", "sun.nio.ch", "sun.nio.cs", "sun.security.action", "sun.util.calendar");
private static final String HADOOP_LOG4J_VARIABLE = "FLOCI_HADOOP_LOG4J";
private static final String HADOOP_ENV_VARIABLE = "FLOCI_HADOOP_ENV";
private static final Pattern SHELL_NAME = Pattern.compile("[A-Za-z_][A-Za-z0-9_]*");
@@ -173,6 +190,9 @@ public class EmrServerlessSparkRunner implements SparkJobRunner, ContainerTeardo
" if [ -n \"${" + HDFS_SITE_VARIABLE + ":-}\" ]; then",
" site hdfs-site.xml \"$" + HDFS_SITE_VARIABLE + "\"",
" fi",
" if [ -n \"${" + YARN_SITE_VARIABLE + ":-}\" ]; then",
" site yarn-site.xml \"$" + YARN_SITE_VARIABLE + "\"",
" fi",
" if [ ! -s \"$hadoop_conf/log4j.properties\" ]; then",
" printf '%s\\n' '" + String.join("' '", HADOOP_CONSOLE_LOG) + "' > \"$hadoop_conf/log4j.properties\"",
" fi",
@@ -197,6 +217,21 @@ public class EmrServerlessSparkRunner implements SparkJobRunner, ContainerTeardo
" export HADOOP_HDFS_HOME=\"${HADOOP_HDFS_HOME:-/usr/lib/hadoop}\"",
" export HADOOP_MAPRED_HOME=\"${HADOOP_MAPRED_HOME:-" + MAPRED_HOME + "}\"",
" export HADOOP_YARN_HOME=\"${HADOOP_YARN_HOME:-/usr/lib/hadoop}\"",
// On YARN the hadoop command, and so hadoop-streaming and hdfs dfs, runs from the nodes' Hadoop, its homes
// set for it alone, so a spark-submit in the same step keeps the Hadoop the release gives Spark.
" if [ -n \"${" + HADOOP_ROOT_VARIABLE + ":-}\" ]; then",
" r=$" + HADOOP_ROOT_VARIABLE,
" printf '%s\\n' '#!/bin/bash'"
+ " \"export HADOOP_HOME=$r/hadoop HADOOP_COMMON_HOME=$r/hadoop"
+ " HADOOP_LIBEXEC_DIR=$r/hadoop/libexec HADOOP_HDFS_HOME=$r/hadoop-hdfs"
+ " HADOOP_MAPRED_HOME=$r/hadoop-mapreduce HADOOP_YARN_HOME=$r/hadoop-yarn\""
+ " 'export HADOOP_CLASSPATH=\"${HADOOP_CLASSPATH:-}:" + String.join(":", AWS_SDK_JARS) + "\"'"
+ " \"exec $r/hadoop/bin/hadoop \\\"\\$@\\\"\" > /tmp/floci-bin/hadoop",
" printf '%s\\n' '#!/bin/bash'"
+ " \"exec /tmp/floci-bin/hadoop jar $r/hadoop-mapreduce/hadoop-streaming.jar \\\"\\$@\\\"\""
+ " > /tmp/floci-bin/hadoop-streaming",
" chmod +x /tmp/floci-bin/hadoop /tmp/floci-bin/hadoop-streaming",
" fi",
"fi");
// A step on a cluster, or one whose job has log4j2.properties lines, runs spark-submit after this.
private static final String SPARK_CONF_WRAPPER = wrapper(SPARK_CONF_COPY, HADOOP_CONF_SETUP);
@@ -240,8 +275,9 @@ public class EmrServerlessSparkRunner implements SparkJobRunner, ContainerTeardo
private static final String HIVE_DEFAULT_IMAGE =
"public.ecr.aws/emr-serverless/hive/%s:latest"; // partition-literal: ECR Public's registry host, where AWS publishes the base images; hive-image-template overrides it
// Hive's settings beside Floci's Hadoop ones. The image's Tez runs its DAGs through EMR Serverless's own container
// plugins, which the public image cannot reach, so Tez runs them in local mode, in Hive's JVM. The port range its
// client talks to it on is a placeholder EMR Serverless fills.
// plugins, which the public image cannot reach, so where there is no YARN Tez runs them in local mode, in Hive's
// JVM (see hiveOnYarnSettings for where there is). The port range its client talks to it on is a placeholder EMR
// Serverless fills.
private static final List<SparkSetting> HIVE_SETTINGS = List.of(
new SparkSetting("tez.local.mode", "true"),
new SparkSetting("tez.am.client.am.port-range", "40000-40100"));
@@ -385,7 +421,7 @@ public class EmrServerlessSparkRunner implements SparkJobRunner, ContainerTeardo
job.environment()));
// bash -c's script gets "floci" as its $0, and what runs after it as its arguments, "$@".
if (job.engine() == Engine.HIVE) {
List<String> hive = hiveArguments(job, endpoint);
List<String> hive = hiveArguments(job, endpoint, executorEnvironment);
List<String> entrypoint = new ArrayList<>(List.of("/bin/bash", "-c", HIVE_WRAPPER, "floci"));
entrypoint.addAll(job.command() != null ? job.command() : List.of(HIVE));
container.withUser("root")
@@ -420,7 +456,12 @@ public class EmrServerlessSparkRunner implements SparkJobRunner, ContainerTeardo
// Hive's settings reach it as --hiveconf settings, so only a Spark job's container sets up Hadoop.
if (job.storage() != null && job.engine() == Engine.SPARK) {
container.withEnv(HADOOP_SITE_VARIABLE, hadoopSite(job, endpoint))
.withEnv(MAPRED_SITE_VARIABLE, mapredSite(job));
.withEnv(MAPRED_SITE_VARIABLE, mapredSite(job, executorEnvironment));
if (onYarn) {
container.withEnv(HADOOP_ROOT_VARIABLE, hadoopRoot(job))
.withEnv(YARN_SITE_VARIABLE, siteProperty("yarn.resourcemanager.hostname",
job.storage().resourceManager()));
}
if (job.storage() != null && job.storage().replication() > 0) {
container.withEnv(HDFS_SITE_VARIABLE, siteProperty("dfs.replication",
String.valueOf(job.storage().replication())));
@@ -791,12 +832,13 @@ public class EmrServerlessSparkRunner implements SparkJobRunner, ContainerTeardo
}
/**
* {@code hive}'s arguments: Floci's S3 and Glue, as a Spark run gets them, Tez in local mode, and on a cluster its
* {@code hive}'s arguments: Floci's S3 and Glue, as a Spark run gets them, Tez on its cluster's YARN, whose
* containers get {@code executorEnvironment} as Spark's executors do, or else in local mode, and on a cluster its
* HDFS and metastore, each a {@code --hiveconf}, which a later one replaces, then the run's own arguments.
*/
static List<String> hiveArguments(Job job, String flociEndpoint) {
static List<String> hiveArguments(Job job, String flociEndpoint, List<String> executorEnvironment) {
List<SparkSetting> settings = new ArrayList<>(hadoopSettings(job, flociEndpoint));
settings.addAll(HIVE_SETTINGS);
settings.addAll(onYarn(job) ? hiveOnYarnSettings(job, executorEnvironment) : HIVE_SETTINGS);
if (job.storage() != null) {
settings.addAll(hdfsSettings(job.storage()));
settings.addAll(hiveClusterSettings(job.storage()));
@@ -870,7 +912,7 @@ public class EmrServerlessSparkRunner implements SparkJobRunner, ContainerTeardo
*/
static String hadoopSite(Job job, String flociEndpoint) {
List<SparkSetting> settings = new ArrayList<>(hadoopSettings(job, flociEndpoint));
settings.addAll(localJobHdfsSettings(job.storage()));
settings.addAll(onYarn(job) ? yarnJobHdfsSettings(job.storage()) : localJobHdfsSettings(job.storage()));
List<String> properties = new ArrayList<>();
for (SparkSetting setting : settings) {
properties.add(siteProperty(setting.key(), setting.value()));
@@ -888,16 +930,116 @@ public class EmrServerlessSparkRunner implements SparkJobRunner, ContainerTeardo
}
/**
* The {@code mapred-site.xml} properties a step's MapReduce gets: its cluster's {@code mapred-site}, then
* Floci's local mode and staging folder, which win, as there is no YARN to run a job on.
* The {@code mapred-site.xml} properties a step's MapReduce gets. On its cluster's YARN, Floci's settings for that,
* whose containers get {@code executorEnvironment} as Spark's executors do, then its cluster's {@code mapred-site},
* which replaces them; where there is no YARN to run a job on, its cluster's {@code mapred-site}, then Floci's local
* mode and staging folder, which win.
*/
static String mapredSite(Job job) {
static String mapredSite(Job job, List<String> executorEnvironment) {
List<String> properties = new ArrayList<>();
if (onYarn(job)) {
yarnMapReduceSettings(job, executorEnvironment)
.forEach(setting -> properties.add(siteProperty(setting.key(), setting.value())));
job.mapredSite().forEach((name, value) -> properties.add(siteProperty(name, value)));
return String.join("\n", properties);
}
job.mapredSite().forEach((name, value) -> properties.add(siteProperty(name, value)));
properties.add(MAPRED_SITE);
return String.join("\n", properties);
}
// A MapReduce job on the cluster's YARN: its application master and tasks find Hadoop in the nodes' layout, which
// yarn.application.classpath's default does not name, and S3A's AWS SDK, reach Floci with the step's AWS environment,
// and are sized for a NodeManager as Spark's executors are. The image's core-site.xml names the LZO codec, so its
// jars come too.
private static List<SparkSetting> yarnMapReduceSettings(Job job, List<String> executorEnvironment) {
String root = hadoopRoot(job);
List<String> classPath = new ArrayList<>(hadoopLayout(root));
classPath.addAll(AWS_SDK_JARS);
String environment = containerEnvironment(executorEnvironment,
"HADOOP_MAPRED_HOME=" + root + "/hadoop-mapreduce");
return List.of(
new SparkSetting("mapreduce.framework.name", "yarn"),
new SparkSetting("mapreduce.application.classpath", String.join(",", classPath)),
new SparkSetting("yarn.app.mapreduce.am.env", environment),
new SparkSetting("mapreduce.map.env", environment),
new SparkSetting("mapreduce.reduce.env", environment),
new SparkSetting("yarn.app.mapreduce.am.resource.mb", "1024"),
new SparkSetting("mapreduce.map.memory.mb", "768"),
new SparkSetting("mapreduce.reduce.memory.mb", "768"));
}
// Hive's Tez on the cluster's YARN. The image's tez-site.xml names EMR Serverless's own plugins, whose stock
// counterparts are in the same jars, named here as Tez's own defaults are; its port ranges and addresses are
// placeholders EMR Serverless fills, its compression needs a native library the image lacks, and a task's two
// virtual cores never match the one YARN's default scheduler grants, so Tez would give each container back. An
// application master says where it is by ${env.NM_HOST}, which is left for its own node to fill in: the settings
// are read on the step's side first, and $NM_HOST or an env of the step's would be filled in there.
private static List<SparkSetting> hiveOnYarnSettings(Job job, List<String> executorEnvironment) {
String root = hadoopRoot(job);
List<String> classPath = new ArrayList<>(List.of("$PWD/*", root + "/hive/lib/hive-exec.jar", root + "/tez/*",
root + "/tez/lib/*"));
classPath.addAll(hadoopLayout(root));
String environment = containerEnvironment(executorEnvironment, "HIVE_HOME=" + root + "/hive",
"TEZ_HOME=" + root + "/tez");
return List.of(
new SparkSetting("yarn.resourcemanager.hostname", job.storage().resourceManager()),
new SparkSetting("tez.local.mode", "false"),
new SparkSetting("tez.framework.client", "org.apache.tez.client.TezYarnClient"),
new SparkSetting("tez.am.class", "org.apache.tez.dag.app.DAGAppMaster"),
new SparkSetting("tez.task.class", "org.apache.tez.runtime.task.TezChild"),
new SparkSetting("tez.am.yarn.scheduler.class", "org.apache.tez.dag.app.rm.YarnTaskSchedulerService"),
new SparkSetting("tez.am.yarn.communicator.class", "org.apache.tez.dag.app.TezTaskCommunicatorImpl"),
new SparkSetting("tez.am.yarn.container-launcher.class",
"org.apache.tez.dag.app.launcher.TezContainerLauncherImpl"),
new SparkSetting("tez.am.shuffle.auxiliary-service.id", "mapreduce_shuffle"),
new SparkSetting("tez.am.client.am.port-range", "40000-40100"),
new SparkSetting("tez.am.task.am.port-range", "40101-40200"),
new SparkSetting("tez.am.client.am.hostname", "${env.NM_HOST}"),
new SparkSetting("tez.am.task.am.hostname", "${env.NM_HOST}"),
new SparkSetting("tez.am.client.am.bind-host", "0.0.0.0"),
new SparkSetting("tez.am.task.am.bind-host", "0.0.0.0"),
new SparkSetting("tez.shuffle.bind-host", "0.0.0.0"),
new SparkSetting("tez.lib.uris", "file://" + root + "/tez/,file://" + root + "/tez/lib/"),
new SparkSetting("tez.use.cluster.hadoop-libs", "false"),
new SparkSetting("tez.cluster.additional.classpath.prefix", String.join(":", classPath)),
new SparkSetting("tez.am.launch.env", environment),
new SparkSetting("tez.task.launch.env", environment),
new SparkSetting("tez.am.resource.memory.mb", "1024"),
new SparkSetting("hive.tez.container.size", "768"),
new SparkSetting("hive.tez.cpu.vcores", "1"),
new SparkSetting("tez.runtime.intermediate-output.should-compress", "false"),
new SparkSetting("tez.runtime.intermediate-input.is-compressed", "false"));
}
// The folders holding Hadoop on a cluster's nodes, as a class path's entries; the LZO codec's beside them.
private static List<String> hadoopLayout(String root) {
return List.of(root + "/hadoop-mapreduce/*", root + "/hadoop-mapreduce/lib/*", root + "/hadoop/*",
root + "/hadoop/lib/*", root + "/hadoop-hdfs/*", root + "/hadoop-hdfs/lib/*", root + "/hadoop-yarn/*",
root + "/hadoop-yarn/lib/*", "/usr/lib/hadoop-lzo/lib/*");
}
// A YARN container's environment as Hadoop's settings take it, comma-separated: the options Java 17 needs, the
// variables given, then the step's AWS environment.
private static String containerEnvironment(List<String> executorEnvironment, String... variables) {
List<String> environment = new ArrayList<>(List.of("JDK_JAVA_OPTIONS=" + yarnJavaOptions()));
environment.addAll(List.of(variables));
environment.addAll(executorEnvironment);
return String.join(",", environment);
}
// Where the Hadoop of a job's cluster's nodes is in its image: an emr-spark-* release's in the folder EmrReleaseImages
// keeps it apart in.
private static String hadoopRoot(Job job) {
return sparkRuntime(job.releaseLabel()) ? "/opt" : "/usr/lib";
}
/** The JVM options that open to Hadoop's classes the packages it reaches into, which Java 8 ignores. */
public static String yarnJavaOptions() {
return YARN_OPENED_PACKAGES.stream().map(name -> "--add-opens=java.base/" + name + "=ALL-UNNAMED")
.collect(Collectors.joining(" "));
}
/** The lines a step's {@code hadoop} command gets after those of its {@code log4j.properties}. */
static String hadoopLog4jFile(Job job) {
return propertiesLines(job.hadoopLog4j());
@@ -1009,6 +1151,13 @@ public class EmrServerlessSparkRunner implements SparkJobRunner, ContainerTeardo
return settings;
}
// The cluster's HDFS for a MapReduce job on its YARN, its staging folder there with the rest, by HDFS's own client.
private static List<SparkSetting> yarnJobHdfsSettings(Storage storage) {
List<SparkSetting> settings = new ArrayList<>(hdfsSettings(storage));
settings.add(new SparkSetting("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem"));
return settings;
}
// The cluster's HDFS for a MapReduce job in local mode, which reads the core-site.xml of the hadoop command's
// configuration, a custom JAR's in the driver included: Hadoop's JobResourceUploader copies a job's files to
// MAPRED_STAGING, on the local file system, then drops that folder's scheme, so the job looks for them at the
@@ -128,6 +128,39 @@ class EmrDockerRunnerDockerIntegrationTest {
assertEquals(WORD_COUNTS, counts("out/"));
}
@Test
void aStreamingJobsMapperAndReducerRunInYarnContainersOnItsClustersCoreAndTaskNodes() {
// Each says the host it ran on, after the words it counted.
String where = """
import socket
print(sys.argv[1] + " " + socket.gethostname() + "\\t1")
""";
put("side/where-mapper.py", MAPPER + where);
put("side/where-reducer.py", REDUCER + where);
startCluster("[]", null, ",{\"Name\":\"core\",\"InstanceRole\":\"CORE\",\"InstanceType\":\"m5.xlarge\","
+ "\"InstanceCount\":1},{\"Name\":\"task\",\"InstanceRole\":\"TASK\",\"InstanceType\":\"m5.xlarge\","
+ "\"InstanceCount\":1}");
List<String> instances = emr("ListInstances", "{\"ClusterId\":\"" + clusterId + "\"}").jsonPath()
.getList("Instances.PrivateDnsName");
List<String> nodes = instances.subList(1, instances.size());
// The mapper and the reducer, from the files -files sends, with a shuffle between them, run on the core and
// task nodes, not in the step's container.
assertEquals("COMPLETED", runStep("command-runner.jar", "hadoop-streaming",
"-D", "mapreduce.job.maps=1", "-D", "mapreduce.job.reduces=1",
"-files", side("where-mapper.py", "where-reducer.py"), "-mapper", "python3 where-mapper.py mapper",
"-reducer", "python3 where-reducer.py reducer", "-input", s3Uri("in/"), "-output", s3Uri("where/")));
Map<String, Integer> counts = counts("where/");
assertEquals(WORD_COUNTS, counts.entrySet().stream().filter(entry -> !entry.getKey().contains(" "))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)), counts::toString);
List<String> ranOn = counts.keySet().stream().filter(key -> key.contains(" ")).toList();
assertEquals(List.of("mapper", "reducer"), ranOn.stream().map(task -> task.split(" ")[0]).distinct().toList(),
ranOn::toString);
for (String task : ranOn) {
assertTrue(nodes.contains(task.split(" ")[1]), task + " among " + nodes);
}
}
@Test
void aCustomJarAtEmrsStreamingJarPathRunsItsWordCountInTheDriver() {
startCluster("[]");
@@ -142,6 +142,26 @@ class EmrHiveStepsDockerIntegrationTest {
assertTrue(stepLog(both, "stdout.gz").contains("q\ns\n"));
}
@Test
void aHiveStepsTezTasksRunInYarnContainersOnItsClustersPrimaryNode() {
startCluster(HIVE_AND_SPARK, "[]", null);
List<String> instances = emr("ListInstances", "{\"ClusterId\":\"" + clusterId + "\"}").jsonPath()
.getList("Instances.PrivateDnsName");
// A query that groups its rows through a shuffle, its tasks giving the hosts they ran on: the primary node,
// whose NodeManager runs them on a cluster without core nodes, not the step's container. Core and task nodes
// running a job's containers are EmrDockerRunnerDockerIntegrationTest's, as a cluster with Hive starts slower.
assertEquals("COMPLETED", hiveStep("-e", "create external table kv (k string, v int) row format delimited"
+ " fields terminated by ',' location '" + s3Uri("data/rows/") + "';"
+ " insert overwrite directory '" + s3Uri("out/tez/") + "' row format delimited fields terminated"
+ " by ',' collection items terminated by ' ' select sum(v), count(k),"
+ " collect_set(split(reflect('java.net.InetAddress', 'getLocalHost'), '/')[0]) from kv;"));
String[] fields = objects("out/tez/").trim().split(",");
assertEquals(List.of("6", "3"), List.of(fields[0], fields[1]), () -> String.join(",", fields));
List<String> hosts = List.of(fields[2].split(" "));
assertTrue(instances.containsAll(hosts), hosts + " among " + instances);
}
@Test
void aClustersHiveSiteForTheGlueDataCatalogKeepsItsHiveStepsTablesInFlocisGlue() {
String database = bucket.replace('-', '_');
@@ -86,6 +86,12 @@ class EmrServerlessSparkRunnerTest {
"floci-aws-emr-j-2AXXXXXXGAPLF-home", "floci-aws-emr-j-2AXXXXXXGAPLF-mnt")
.withHdfs("ip-10-0-0-1.ec2.internal", "172.18.0.5", "floci-aws-emr-j-2AXXXXXXGAPLF-hdfs");
// The same, on its cluster's YARN, with a step's AWS environment for its containers.
private static final SparkJobRunner.Storage ON_YARN = STORAGE.withYarn("ip-10-0-0-1.ec2.internal",
"http://floci:4566");
private static final List<String> AWS_ENVIRONMENT = List.of("AWS_ACCESS_KEY_ID=ASIASTEP",
"AWS_ENDPOINT_URL=http://floci:4566");
private final EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
private final ContainerLifecycleManager lifecycle = mock(ContainerLifecycleManager.class);
private final LaunchedContainerAwsEnv awsEnv = mock(LaunchedContainerAwsEnv.class);
@@ -182,7 +188,7 @@ class EmrServerlessSparkRunnerTest {
"-i", "s3://bucket/queries/init.sql", "-f", "s3://bucket/queries/report.sql",
"--hivevar", "day=2026-11-03");
List<String> arguments = EmrServerlessSparkRunner.hiveArguments(hiveJob(application), ENDPOINT);
List<String> arguments = EmrServerlessSparkRunner.hiveArguments(hiveJob(application), ENDPOINT, List.of());
assertEquals(List.of(
"--hiveconf", "fs.s3a.endpoint=http://floci:4566",
@@ -242,7 +248,7 @@ class EmrServerlessSparkRunnerTest {
verify(spec).withEntrypoint(argThat((List<String> entrypoint) -> entrypoint.size() == 7
&& List.of("floci", "hive-script", "--run-hive-script", "--args")
.equals(entrypoint.subList(3, 7))));
verify(spec).withCmd(EmrServerlessSparkRunner.hiveArguments(step, ENDPOINT));
verify(spec).withCmd(EmrServerlessSparkRunner.hiveArguments(step, ENDPOINT, List.of()));
verify(spec).withNamedVolume("j-1-home", "/home/hadoop");
verify(spec).withNamedVolume("j-1-mnt", "/mnt");
// In its cluster's image, which holds Spark too, Hive reads its own Hadoop configuration.
@@ -256,7 +262,7 @@ class EmrServerlessSparkRunnerTest {
void anEmrHiveStepsHiveReachesItsClustersHdfsAndMetastoreServiceOnItsPrimaryNode() {
List<String> arguments = EmrServerlessSparkRunner.hiveArguments(
hiveStep(List.of("--hiveconf", "hive.exec.reducers.max=8", "-f", "s3://bucket/queries/report.q")),
ENDPOINT);
ENDPOINT, List.of());
int tez = arguments.indexOf("tez.am.client.am.port-range=40000-40100");
assertEquals(List.of(
@@ -274,7 +280,7 @@ class EmrServerlessSparkRunnerTest {
SparkJobRunner.Job step = hiveStep(List.of("-f", "s3://bucket/queries/report.q"));
List<String> arguments = EmrServerlessSparkRunner.hiveArguments(step.onStorage(
new SparkJobRunner.Storage("j-1-home", "j-1-mnt").withHdfs("ip-10-0-0-1.ec2.internal", "127.0.0.1",
null)), ENDPOINT);
null)), ENDPOINT, List.of());
int tez = arguments.indexOf("tez.am.client.am.port-range=40000-40100");
assertEquals(List.of(
@@ -623,7 +629,8 @@ class EmrServerlessSparkRunnerTest {
assertTrue(EmrServerlessSparkRunner.sparkSubmitArguments(job, "http://floci:4566", List.of())
.contains("spark.hadoop.dfs.replication=2"));
assertTrue(EmrServerlessSparkRunner.hiveArguments(job, "http://floci:4566").contains("dfs.replication=2"));
assertTrue(EmrServerlessSparkRunner.hiveArguments(job, "http://floci:4566", List.of())
.contains("dfs.replication=2"));
}
@Test
@@ -731,6 +738,197 @@ class EmrServerlessSparkRunnerTest {
assertTrue(arguments.indexOf(glue) > metastore, arguments.toString());
}
@Test
void aMapReduceJobOnItsClustersYarnRunsThereFromItsNodesLayout() {
String site = EmrServerlessSparkRunner.mapredSite(stepJob(Map.of()).onStorage(ON_YARN), AWS_ENVIRONMENT);
assertTrue(site.contains("<name>mapreduce.framework.name</name><value>yarn</value>"), site);
assertFalse(site.contains("<value>local</value>"), site);
assertFalse(site.contains("mapreduce.jobtracker.staging.root.dir"), site);
// The image's real layout, which yarn.application.classpath's default does not name, and S3A's AWS SDK.
assertTrue(site.contains("<name>mapreduce.application.classpath</name><value>"
+ "/usr/lib/hadoop-mapreduce/*,/usr/lib/hadoop-mapreduce/lib/*,/usr/lib/hadoop/*,/usr/lib/hadoop/lib/*,"
+ "/usr/lib/hadoop-hdfs/*,/usr/lib/hadoop-hdfs/lib/*,/usr/lib/hadoop-yarn/*,/usr/lib/hadoop-yarn/lib/*,"
+ "/usr/lib/hadoop-lzo/lib/*,/usr/share/aws/aws-java-sdk-v2/*,"
+ "/usr/share/aws/emr/serverless-goodies/lib/emr-serverless-spark-goodies.jar</value>"), site);
// Java 17's options, the MapReduce home and the step's AWS environment, for all three kinds of container.
for (String name : List.of("yarn.app.mapreduce.am.env", "mapreduce.map.env", "mapreduce.reduce.env")) {
assertTrue(site.contains("<name>" + name + "</name><value>JDK_JAVA_OPTIONS="
+ EmrServerlessSparkRunner.yarnJavaOptions() + ",HADOOP_MAPRED_HOME=/usr/lib/hadoop-mapreduce,"
+ "AWS_ACCESS_KEY_ID=ASIASTEP,AWS_ENDPOINT_URL=http://floci:4566</value>"), site);
}
assertTrue(site.contains("<name>yarn.app.mapreduce.am.resource.mb</name><value>1024</value>"), site);
assertTrue(site.contains("<name>mapreduce.map.memory.mb</name><value>768</value>"), site);
assertTrue(site.contains("<name>mapreduce.reduce.memory.mb</name><value>768</value>"), site);
}
@Test
void anEmrSparkReleasesMapReduceRunsFromTheHadoopItsImageKeepsApart() {
String site = EmrServerlessSparkRunner.mapredSite(
onRelease("emr-spark-8.1.0", stepJob(Map.of()).onStorage(ON_YARN)), List.of());
assertTrue(site.contains("<value>/opt/hadoop-mapreduce/*,/opt/hadoop-mapreduce/lib/*,/opt/hadoop/*"), site);
assertTrue(site.contains(",HADOOP_MAPRED_HOME=/opt/hadoop-mapreduce</value>"), site);
}
@Test
void aClustersMapredSiteReplacesFlocisSettingsOnYarn() {
String site = EmrServerlessSparkRunner.mapredSite(hadoopJob(null,
Map.of("mapreduce.map.memory.mb", "2048"), Map.of(), Map.of()).onStorage(ON_YARN), List.of());
assertTrue(site.indexOf("<value>2048</value>") > site.indexOf("<value>768</value>"), site);
}
@Test
void aJobOnYarnKeepsItsStagingFolderInHdfsWithHdfssOwnClient() {
String site = EmrServerlessSparkRunner.hadoopSite(stepJob(Map.of()).onStorage(ON_YARN), ENDPOINT);
assertTrue(site.contains("<name>fs.hdfs.impl</name>"
+ "<value>org.apache.hadoop.hdfs.DistributedFileSystem</value>"), site);
assertFalse(site.contains("viewfs"), site);
// Where there is no YARN, the local job runner's staging folder needs the view.
assertTrue(EmrServerlessSparkRunner.hadoopSite(stepJob(Map.of()), ENDPOINT).contains("viewfs"));
}
@Test
void aStepOnYarnRunsItsHadoopCommandFromTheNodesHadoopAndKnowsItsResourceManager() {
ContainerBuilder builder = mock(ContainerBuilder.class);
ContainerBuilder.Builder spec = mock(ContainerBuilder.Builder.class, RETURNS_SELF);
when(builder.newContainer(anyString())).thenReturn(spec);
runner(builder).run(commandJob(List.of("bash", "-c", "hadoop version"), Map.of(), ON_YARN), progress);
verify(spec).withEnv("FLOCI_HADOOP_ROOT", "/usr/lib");
verify(spec).withEnv("FLOCI_YARN_SITE",
"<property><name>yarn.resourcemanager.hostname</name><value>ip-10-0-0-1.ec2.internal</value></property>");
verify(spec).withEntrypoint(argThat(entrypoint -> entrypoint.get(2).contains(String.join("\n",
" if [ -n \"${FLOCI_YARN_SITE:-}\" ]; then",
" site yarn-site.xml \"$FLOCI_YARN_SITE\"",
" fi"))
&& entrypoint.get(2).contains(
"\"export HADOOP_HOME=$r/hadoop HADOOP_COMMON_HOME=$r/hadoop HADOOP_LIBEXEC_DIR=$r/hadoop/libexec"
+ " HADOOP_HDFS_HOME=$r/hadoop-hdfs HADOOP_MAPRED_HOME=$r/hadoop-mapreduce"
+ " HADOOP_YARN_HOME=$r/hadoop-yarn\"")
&& entrypoint.get(2).contains("'export HADOOP_CLASSPATH=\"${HADOOP_CLASSPATH:-}:"
+ "/usr/share/aws/aws-java-sdk-v2/*:"
+ "/usr/share/aws/emr/serverless-goodies/lib/emr-serverless-spark-goodies.jar\"'")
&& entrypoint.get(2).contains("\"exec $r/hadoop/bin/hadoop \\\"\\$@\\\"\" > /tmp/floci-bin/hadoop")
&& entrypoint.get(2).contains("\"exec /tmp/floci-bin/hadoop jar $r/hadoop-mapreduce/hadoop-streaming.jar"
+ " \\\"\\$@\\\"\" > /tmp/floci-bin/hadoop-streaming")));
}
@Test
void aStepOnAnEmrSparkReleasesYarnRunsItsHadoopCommandFromTheHadoopItsImageKeepsApart() {
ContainerBuilder builder = mock(ContainerBuilder.class);
ContainerBuilder.Builder spec = mock(ContainerBuilder.Builder.class, RETURNS_SELF);
when(builder.newContainer(anyString())).thenReturn(spec);
runner(builder).run(onRelease("emr-spark-8.1.0",
commandJob(List.of("bash", "-c", "hadoop version"), Map.of(), ON_YARN)), progress);
verify(spec).withEnv("FLOCI_HADOOP_ROOT", "/opt");
}
@Test
void aStepWhereThereIsNoYarnKeepsTheLocalJobRunnersHadoop() {
ContainerBuilder builder = mock(ContainerBuilder.class);
ContainerBuilder.Builder spec = mock(ContainerBuilder.Builder.class, RETURNS_SELF);
when(builder.newContainer(anyString())).thenReturn(spec);
runner(builder).run(commandJob(List.of("bash", "-c", "hadoop version"), Map.of(), STORAGE), progress);
verify(spec, never()).withEnv(eq("FLOCI_HADOOP_ROOT"), anyString());
verify(spec, never()).withEnv(eq("FLOCI_YARN_SITE"), anyString());
}
@Test
void aHiveStepOnItsClustersYarnRunsStockTezThereInPlaceOfEmrServerlesssPlugins() {
List<String> arguments = EmrServerlessSparkRunner.hiveArguments(
hiveJob(List.of("-e", "select 1")).onStorage(ON_YARN), ENDPOINT, AWS_ENVIRONMENT);
assertFalse(arguments.contains("tez.local.mode=true"), arguments.toString());
for (String setting : List.of(
"tez.local.mode=false",
"yarn.resourcemanager.hostname=ip-10-0-0-1.ec2.internal",
"tez.framework.client=org.apache.tez.client.TezYarnClient",
"tez.am.class=org.apache.tez.dag.app.DAGAppMaster",
"tez.task.class=org.apache.tez.runtime.task.TezChild",
"tez.am.yarn.scheduler.class=org.apache.tez.dag.app.rm.YarnTaskSchedulerService",
"tez.am.yarn.communicator.class=org.apache.tez.dag.app.TezTaskCommunicatorImpl",
"tez.am.yarn.container-launcher.class=org.apache.tez.dag.app.launcher.TezContainerLauncherImpl",
"tez.am.shuffle.auxiliary-service.id=mapreduce_shuffle",
"tez.am.client.am.port-range=40000-40100",
"tez.am.task.am.port-range=40101-40200",
// Left for the application master's own node to fill in.
"tez.am.client.am.hostname=${env.NM_HOST}",
"tez.am.task.am.hostname=${env.NM_HOST}",
"tez.am.client.am.bind-host=0.0.0.0",
"tez.am.task.am.bind-host=0.0.0.0",
"tez.shuffle.bind-host=0.0.0.0",
"tez.lib.uris=file:///usr/lib/tez/,file:///usr/lib/tez/lib/",
"tez.use.cluster.hadoop-libs=false",
"tez.am.resource.memory.mb=1024",
"hive.tez.container.size=768",
// A task's two would never match the one YARN's default scheduler grants.
"hive.tez.cpu.vcores=1",
"tez.runtime.intermediate-output.should-compress=false",
"tez.runtime.intermediate-input.is-compressed=false")) {
assertTrue(arguments.contains(setting), setting + " in " + arguments);
}
assertTrue(arguments.contains("tez.cluster.additional.classpath.prefix=$PWD/*:/usr/lib/hive/lib/hive-exec.jar:"
+ "/usr/lib/tez/*:/usr/lib/tez/lib/*:/usr/lib/hadoop-mapreduce/*:/usr/lib/hadoop-mapreduce/lib/*:"
+ "/usr/lib/hadoop/*:/usr/lib/hadoop/lib/*:/usr/lib/hadoop-hdfs/*:/usr/lib/hadoop-hdfs/lib/*:"
+ "/usr/lib/hadoop-yarn/*:/usr/lib/hadoop-yarn/lib/*:/usr/lib/hadoop-lzo/lib/*"), arguments.toString());
String environment = "=JDK_JAVA_OPTIONS=" + EmrServerlessSparkRunner.yarnJavaOptions()
+ ",HIVE_HOME=/usr/lib/hive,TEZ_HOME=/usr/lib/tez,AWS_ACCESS_KEY_ID=ASIASTEP,"
+ "AWS_ENDPOINT_URL=http://floci:4566";
assertTrue(arguments.contains("tez.am.launch.env" + environment), arguments.toString());
assertTrue(arguments.contains("tez.task.launch.env" + environment), arguments.toString());
}
@Test
void aStepsMapReduceContainersGetItsAwsEnvironmentThroughARealRun() {
ContainerBuilder builder = mock(ContainerBuilder.class);
ContainerBuilder.Builder spec = mock(ContainerBuilder.Builder.class, RETURNS_SELF);
when(builder.newContainer(anyString())).thenReturn(spec);
when(awsEnv.sdkBaselineEnv("eu-west-1", Optional.empty(), "http://floci:4566", Optional.empty(),
"123456789012")).thenReturn(List.of("AWS_ACCESS_KEY_ID=ASIASTEP"));
runner(builder).run(commandJob(List.of("bash", "-c", "hadoop version"), Map.of(), ON_YARN), progress);
verify(spec).withEnv(eq("FLOCI_MAPRED_SITE"), argThat(site -> site.contains(
"AWS_ACCESS_KEY_ID=ASIASTEP</value></property>")));
}
@Test
void aHiveStepsTezContainersGetItsAwsEnvironmentThroughARealRun() {
ContainerBuilder builder = mock(ContainerBuilder.class);
ContainerBuilder.Builder spec = mock(ContainerBuilder.Builder.class, RETURNS_SELF);
when(builder.newContainer(anyString())).thenReturn(spec);
when(awsEnv.sdkBaselineEnv("eu-west-1", Optional.empty(), "http://floci:4566", Optional.empty(),
"123456789012")).thenReturn(List.of("AWS_ACCESS_KEY_ID=ASIASTEP"));
runner(builder).run(hiveStep(List.of("-e", "select 1")).onStorage(ON_YARN), progress);
verify(spec).withCmd(argThat((List<String> arguments) -> arguments.stream().anyMatch(argument ->
argument.startsWith("tez.task.launch.env=") && argument.endsWith(",AWS_ACCESS_KEY_ID=ASIASTEP"))));
}
@Test
void aHiveStepWhereThereIsNoYarnKeepsTezInLocalMode() {
List<String> arguments = EmrServerlessSparkRunner.hiveArguments(hiveJob(List.of("-e", "select 1")), ENDPOINT,
List.of());
assertTrue(arguments.contains("tez.local.mode=true"), arguments.toString());
assertFalse(arguments.toString().contains("tez.framework.client"), arguments.toString());
}
@Test
void yarnsJavaOptionsOpenWhatHadoopReachesInto() {
assertTrue(EmrServerlessSparkRunner.yarnJavaOptions().startsWith("--add-opens=java.base/java.lang=ALL-UNNAMED "));
assertTrue(EmrServerlessSparkRunner.yarnJavaOptions().endsWith("--add-opens=java.base/sun.util.calendar=ALL-UNNAMED"));
}
@Test
void aHadoopCommandOnAClusterWhoseCoreNodesHoldItsHdfsWritesTheirCopies() {
ContainerBuilder builder = mock(ContainerBuilder.class);
@@ -1008,7 +1206,7 @@ class EmrServerlessSparkRunnerTest {
// A MapReduce job its main class starts reads mapred-site.xml from HADOOP_CONF_DIR, which spark-submit puts
// on its class path: the image's names YARN, which the job would wait for without end.
verify(spec).withEnv("FLOCI_HADOOP_SITE", EmrServerlessSparkRunner.hadoopSite(job, ENDPOINT));
verify(spec).withEnv("FLOCI_MAPRED_SITE", EmrServerlessSparkRunner.mapredSite(job));
verify(spec).withEnv("FLOCI_MAPRED_SITE", EmrServerlessSparkRunner.mapredSite(job, List.of()));
verify(spec, never()).withEnv(eq("FLOCI_SPARK_LOG4J2"), anyString());
verify(spec, never()).withEnv(eq("FLOCI_HADOOP_LOG4J"), anyString());
verify(spec, never()).withEnv(eq("FLOCI_HADOOP_ENV"), anyString());
@@ -1039,7 +1237,7 @@ class EmrServerlessSparkRunnerTest {
"<property><name>mapreduce.framework.name</name><value>local</value></property>"
+ "<property><name>mapreduce.jobtracker.staging.root.dir</name>"
+ "<value>/tmp/hadoop/mapred/staging</value></property>"),
EmrServerlessSparkRunner.mapredSite(hadoopJob(null, mapredSite, Map.of(), Map.of())));
EmrServerlessSparkRunner.mapredSite(hadoopJob(null, mapredSite, Map.of(), Map.of()), List.of()));
}
@Test
@@ -1720,6 +1918,14 @@ class EmrServerlessSparkRunnerTest {
}
// A Spark step on a cluster, which has storage.
private static SparkJobRunner.Job onRelease(String release, SparkJobRunner.Job job) {
return new SparkJobRunner.Job(job.service(), job.runId(), job.accountId(), job.region(), release, job.engine(),
job.imageTemplate(), job.customImage(), job.dockerNetwork(), job.executionRole(), job.sparkDefaults(),
job.application(), job.command(), job.timeout(), job.logFolder(), job.cloudWatchLogs(),
job.environment(), job.archives(), job.storage(), job.coreSite(), job.sparkLog4j2(), job.mapredSite(),
job.hadoopLog4j(), job.hadoopEnvironment());
}
private static SparkJobRunner.Job stepJob(Map<String, String> sparkDefaults) {
return new SparkJobRunner.Job("emr", "s-1A2B3C4D5E6F7", "123456789012", "eu-west-1", "emr-7.5.0", SPARK, null,
null, "floci-network", "arn:aws:iam::123456789012:role/job", sparkDefaults,
@@ -5,10 +5,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.floci.aws.services.sqs.SqsService;
import io.floci.aws.testing.DockerAvailability;
import io.floci.aws.testing.DynamoDbRequests;
import io.floci.aws.testing.RestAssuredJsonUtils;
import io.floci.aws.testing.SqsTestQueue;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -42,6 +44,13 @@ class PipesStreamEnrichmentDockerIntegrationTest {
@Inject
SqsService sqsService;
// DynamoDB's requests and answers are application/x-amz-json-1.0, which RestAssured encodes and parses only once
// told to, whichever classes ran before this one.
@BeforeAll
static void configure() {
RestAssuredJsonUtils.configureAwsContentTypes();
}
@BeforeEach
void requireDocker() throws Exception {
Assumptions.assumeTrue(DockerAvailability.isAvailable(),