mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
feat(emr): run hadoop-streaming and hadoop-lzo steps (#7264)
In the docker runner mode a command-runner.jar step running hadoop-streaming, which "Submits an Hadoop streaming program. In the console and some SDKs, this is a streaming step", or hadoop-lzo, the LZO indexer, failed without running, as the image's hadoop had no MapReduce; and a command's hadoop fs could not reach S3, its classpath having no AWS SDK v2 and the image's EMRFS not being pointed at Floci. Now a step's hadoop command, on its cluster: - runs MapReduce in local mode: links to Spark's shaded Hadoop client, the image's only copy of MapReduce, and to the jar Spark's own S3A finds the AWS SDK in make up its MapReduce home, so they are on its class path whatever HADOOP_CLASSPATH a command sets, and a copy of its mapred-site.xml sets mapreduce.framework.name to local. The local job runner names a job's -files and -archives by their path alone, which the default file system, the cluster's HDFS, resolves, so its staging folder is a link to the same path in the HDFS folder. - reaches Floci's S3 through S3A, with the settings its spark-submit gets, now one list for both, ahead of the cluster's HDFS and core-site. - logs to standard error when its log4j.properties is empty, as the image's is, in the layout of the Management Guide's step log lines, so a failed job's reason is in the step's stderr. - runs hadoop-streaming from the jar the image has, where the image's own hadoop-streaming names /usr/lib/hadoop-mapreduce, which it lacks. hive-script and pig-script steps still fail without running.
This commit is contained in:
1 parent
9bd90d6580
commit
048070e699
6 files changed
+241
-62
No files matched your search
+25
-7
@@ -121,14 +121,15 @@ but for its bootstrap actions and its storage.
|
||||
command, its first argument, with the rest, and a `script-runner.jar` step (by name, or by its
|
||||
`s3://<region>.elasticmapreduce/libs/script-runner/script-runner.jar` URI) its script, as the Release
|
||||
Guide's "Run commands and scripts on an Amazon EMR cluster" describes them. An `s3-dist-cp` step runs
|
||||
Floci's own S3DistCp (see **S3DistCp**). `hive-script`, `pig-script`, `hadoop-streaming` and
|
||||
`hadoop-lzo`, which the image does not have, are `FAILED` without running.
|
||||
Floci's own S3DistCp (see **S3DistCp**), and `hadoop-streaming` and `hadoop-lzo` steps the image's
|
||||
Hadoop (see **Hadoop streaming and MapReduce**). `hive-script` and `pig-script`, which the image does not
|
||||
have, are `FAILED` without running.
|
||||
* **Commands and scripts**: they run as the image's `hadoop` user in `/home/hadoop`, with `bash`, Python
|
||||
3, Java, `curl` and the AWS CLI v2, which reaches Floci through `AWS_ENDPOINT_URL`. A
|
||||
`script-runner.jar` step's script is fetched from S3 with the AWS CLI and the step's credentials, then
|
||||
run with the step's other arguments; a path not in S3 is run as it is, a bare name from `/home/hadoop`
|
||||
when a file there has it, one a former step left there included. `hadoop fs` and `hdfs dfs` reach the
|
||||
cluster's HDFS (see **Storage**). A `spark-submit` they start runs in local mode on Floci's S3 with the
|
||||
cluster's HDFS (see **Storage**) and Floci's S3. A `spark-submit` they start runs in local mode on Floci's S3 with the
|
||||
cluster's `spark-defaults`, `core-site`, `spark-hive-site` and `spark-log4j2`, which Floci puts in a Spark
|
||||
configuration of its own, a copy of the folder a `spark-env` export of `SPARK_CONF_DIR` names, else of the
|
||||
image's, ahead of the image's EMR Serverless master; its own `--master yarn` or `--deploy-mode cluster`
|
||||
@@ -150,10 +151,27 @@ but for its bootstrap actions and its storage.
|
||||
("HDFS is ephemeral storage that is reclaimed when you terminate a cluster"), on a state reset, and, for
|
||||
clusters that are gone or have ended, when the EMR service starts, unless
|
||||
`reconcile-containers-on-startup` is off. HDFS is a folder, without a NameNode or replication: an
|
||||
`hdfs://` path naming a host is not served, `hadoop fs -ls /` fails ("URI scheme is not "file""), where
|
||||
`-ls -d /` and a folder below it do not, and `hadoop fs` does not reach S3, as its classpath has no AWS
|
||||
SDK v2 and the image's EMRFS is not pointed at Floci (`aws s3 cp` does). `/tmp` is each container's own.
|
||||
* **S3DistCp**: the image has neither `s3-dist-cp` nor MapReduce, so a `command-runner.jar` step whose
|
||||
`hdfs://` path naming a host is not served, and `hadoop fs -ls /` fails ("URI scheme is not "file""),
|
||||
where `-ls -d /` and a folder below it do not. `/tmp` is each container's own.
|
||||
* **Hadoop streaming and MapReduce**: a step's `hadoop` command runs MapReduce in local mode, in its own JVM,
|
||||
as there is no YARN: 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
|
||||
`mapreduce.framework.name` to `local`. So a `command-runner.jar` step whose first argument is
|
||||
`hadoop-streaming`, which "Submits an Hadoop streaming program. In the console and some SDKs, this is a
|
||||
streaming step", as the Release Guide's tools table puts it (the AWS CLI's `Type=STREAMING` becomes one),
|
||||
runs the image's `hadoop-streaming.jar` with the step's other arguments: its mapper and reducer can come
|
||||
from Floci's S3 through `-files`, `-cacheFile` or `-cacheArchive`, and its `-input` and `-output` can be in
|
||||
Floci's S3 or the cluster's HDFS, where a job's staging folder, `/tmp/hadoop/mapred/staging`, is too. A
|
||||
`hadoop-lzo` step runs the image's LZO indexer the same way, as does a `hadoop jar` a command or script
|
||||
runs. `s3://` and `s3a://` paths reach Floci's S3 through S3A, with the AWS SDK Spark's own S3A finds, in
|
||||
place of the image's EMRFS, which is not pointed at Floci. The image's `log4j.properties` for Hadoop is
|
||||
empty, so Hadoop logs to the step's standard error, from `INFO` up, in the layout of the Management Guide's
|
||||
step log lines, and `stderr.gz` holds a failed job's reason ("ERROR org.apache.hadoop.streaming.StreamJob
|
||||
(main): Error Launching job : Output directory ... already exists"), which EMR writes to the step's
|
||||
`syslog`. The cluster's `mapred-site`, `hadoop-log4j` and `hadoop-env` classifications are not applied, and
|
||||
a job's own `-D mapreduce.framework.name=yarn` fails.
|
||||
* **S3DistCp**: the image has no `s3-dist-cp`, so a `command-runner.jar` step whose
|
||||
first argument is `s3-dist-cp`, the Release Guide's form, runs Floci's own program instead, through
|
||||
`spark-submit` in the step's container, copying through Hadoop's file systems: `--src` and `--dest` take
|
||||
S3 paths in Floci's S3, the cluster's HDFS (`hdfs:///output`, or a path without a scheme) or a file of
|
||||
|
||||
@@ -23,13 +23,15 @@ import java.util.Set;
|
||||
* {@code spark-submit}, as the Management Guide's Spark steps are written, and a custom JAR step, whose main
|
||||
* class {@code spark-submit} runs with the JAR on its class path. Any other {@code command-runner.jar} step
|
||||
* runs its command, and a {@code script-runner.jar} step its script, as the Release Guide's "Run commands
|
||||
* and scripts on an Amazon EMR cluster" describes them; an {@code s3-dist-cp} one runs Floci's own S3DistCp.
|
||||
* and scripts on an Amazon EMR cluster" describes them, a {@code hadoop-streaming} or {@code hadoop-lzo} one
|
||||
* through the image's {@code hadoop}, with MapReduce in local mode; an {@code s3-dist-cp} one runs Floci's own
|
||||
* S3DistCp.
|
||||
*/
|
||||
final class EmrSparkSteps {
|
||||
|
||||
// No source gives AWS's wording for these; they are Floci's.
|
||||
static final String NOT_RUN = "Floci does not run this step: hive-script, pig-script, hadoop-streaming and"
|
||||
+ " hadoop-lzo are not in the image steps run in.";
|
||||
static final String NOT_RUN = "Floci does not run this step: hive-script and pig-script are not in the image"
|
||||
+ " steps run in.";
|
||||
static final String INTERRUPTED = "Floci stopped while the step was running.";
|
||||
|
||||
private static final String COMMAND_RUNNER = "command-runner.jar";
|
||||
@@ -55,10 +57,8 @@ final class EmrSparkSteps {
|
||||
private static final String SPARK_HADOOP_PREFIX = "spark.hadoop.";
|
||||
// spark-submit gives the JVM it runs an application's main class in the Java options of this variable.
|
||||
private static final String SPARK_SUBMIT_OPTS = "SPARK_SUBMIT_OPTS";
|
||||
// The Release Guide's command-runner.jar tools that the EMR Serverless image does not have; its hadoop
|
||||
// has no MapReduce to run streaming or the LZO indexer.
|
||||
private static final Set<String> UNAVAILABLE_TOOLS = Set.of("hive-script", "pig-script", "hadoop-streaming",
|
||||
"hadoop-lzo");
|
||||
// The Release Guide's command-runner.jar tools that the EMR Serverless image does not have.
|
||||
private static final Set<String> UNAVAILABLE_TOOLS = Set.of("hive-script", "pig-script");
|
||||
private static final String S3_DIST_CP = "s3-dist-cp";
|
||||
static final String S3_DIST_CP_RESOURCE = "emr/s3-dist-cp.py";
|
||||
// The line that ends the program where the command writes it out.
|
||||
@@ -278,9 +278,9 @@ final class EmrSparkSteps {
|
||||
}
|
||||
|
||||
/**
|
||||
* Floci's S3DistCp: the image has neither {@code s3-dist-cp} nor MapReduce, so the command writes Floci's
|
||||
* program into the container and runs it through {@code spark-submit}, which the command wrapper gives
|
||||
* Floci's S3 and the cluster's HDFS. Read once, when the first {@code s3-dist-cp} step comes.
|
||||
* Floci's S3DistCp: the image has no {@code s3-dist-cp}, so the command writes Floci's program into the
|
||||
* container and runs it through {@code spark-submit}, which the command wrapper gives Floci's S3 and the
|
||||
* cluster's HDFS. Read once, when the first {@code s3-dist-cp} step comes.
|
||||
*/
|
||||
private static final class S3DistCp {
|
||||
static final String COMMAND = String.join("\n",
|
||||
|
||||
+89
-33
@@ -59,7 +59,8 @@ import java.util.zip.GZIPOutputStream;
|
||||
* are unpacked into its working directory before the driver starts. The driver's output goes to
|
||||
* Floci's log and, while it runs, to the run's CloudWatch log streams, when it has some; once it ends, its
|
||||
* standard output and error go, gzipped, to the run's log folder in Floci's S3, when it has one. An EMR step's
|
||||
* container mounts its cluster's storage, where {@code hdfs://} paths, and paths without a scheme, lead.
|
||||
* container mounts its cluster's storage, where {@code hdfs://} paths, and paths without a scheme, lead, and a
|
||||
* step's {@code hadoop} command reaches Floci's S3 and runs MapReduce in local mode.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class EmrServerlessSparkRunner implements SparkJobRunner, ContainerTeardown {
|
||||
@@ -72,15 +73,41 @@ public class EmrServerlessSparkRunner implements SparkJobRunner, ContainerTeardo
|
||||
// A cluster's HDFS, as Hadoop settings: hdfs:// paths, and those without a scheme ("hdfs:// (or no prefix)"),
|
||||
// lead to the HDFS folder of the cluster's /mnt volume, through a view of it under the hdfs scheme, as the
|
||||
// image has no HDFS of its own.
|
||||
private static final String HDFS_FOLDER = "/mnt/hdfs";
|
||||
private static final List<SparkSetting> HDFS_SETTINGS = List.of(
|
||||
new SparkSetting("fs.defaultFS", "hdfs:///"),
|
||||
new SparkSetting("fs.hdfs.impl", "org.apache.hadoop.fs.viewfs.ViewFileSystemOverloadScheme"),
|
||||
new SparkSetting("fs.viewfs.mounttable.default.linkFallback", "file:///mnt/hdfs"));
|
||||
new SparkSetting("fs.viewfs.mounttable.default.linkFallback", "file://" + HDFS_FOLDER));
|
||||
// Spark's default checkpoint manager goes through Hadoop's FileContext, which refuses an hdfs:// path
|
||||
// without a host, so a streaming query keeps its checkpoints through the file system instead.
|
||||
private static final SparkSetting FILE_SYSTEM_CHECKPOINTS = new SparkSetting(
|
||||
"spark.sql.streaming.checkpointFileManagerClass",
|
||||
"org.apache.spark.sql.execution.streaming.FileSystemBasedCheckpointFileManager");
|
||||
// Where Hadoop's local job runner puts a job's files, -files and -archives among them: a folder of the local
|
||||
// file system, whose files it then names by their path alone, which leads to the cluster's HDFS.
|
||||
private static final String MAPRED_STAGING = "/tmp/hadoop/mapred/staging";
|
||||
// A command's MapReduce runs in the hadoop command's own JVM, as there is no YARN to run it on.
|
||||
private static final String MAPRED_SITE = "<property><name>mapreduce.framework.name</name><value>local</value>"
|
||||
+ "</property><property><name>mapreduce.jobtracker.staging.root.dir</name><value>" + MAPRED_STAGING
|
||||
+ "</value></property>";
|
||||
// The image's Hadoop log4j.properties is empty, so a hadoop command logs nothing, a streaming job's reason for
|
||||
// failing included; one that is empty logs to standard error instead, in the layout of the step log lines the
|
||||
// Management Guide shows ("ERROR org.apache.hadoop.streaming.StreamJob (main): Error Launching job : ...").
|
||||
private static final List<String> HADOOP_CONSOLE_LOG = List.of(
|
||||
"hadoop.root.logger=INFO,console",
|
||||
"log4j.rootLogger=${hadoop.root.logger}",
|
||||
"log4j.appender.console=org.apache.log4j.ConsoleAppender",
|
||||
"log4j.appender.console.target=System.err",
|
||||
"log4j.appender.console.layout=org.apache.log4j.PatternLayout",
|
||||
"log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %p %c (%t): %m%n");
|
||||
// MapReduce, which a streaming job, the LZO indexer and any other hadoop jar run in, is only in Spark's shaded
|
||||
// Hadoop client, and S3A's AWS SDK only in the jar Spark's own S3A finds it in; links to them make up the hadoop
|
||||
// command's MapReduce home, whose jars it puts after its own, whatever HADOOP_CLASSPATH a command sets.
|
||||
private static final String MAPRED_HOME = "/tmp/floci-mapreduce";
|
||||
private static final List<String> MAPRED_JARS = List.of(
|
||||
"/usr/lib/spark/jars/hadoop-client-api-*.jar",
|
||||
"/usr/lib/spark/jars/hadoop-client-runtime-*.jar",
|
||||
"/usr/lib/spark/jars/emr-serverless-spark-goodies.jar");
|
||||
// A Spark configuration of the container's own: a copy of the folder a spark-env export of SPARK_CONF_DIR names,
|
||||
// else of the image's, links followed, whose log4j2.properties ends with the job's lines, passed in
|
||||
// SPARK_LOG4J2_VARIABLE, a later line winning. What is added to a file starts on a line of its own, as the
|
||||
@@ -104,29 +131,47 @@ public class EmrServerlessSparkRunner implements SparkJobRunner, ContainerTeardo
|
||||
"sed -i -e '/^spark\\.master[[:space:]]/d' -e '/^spark\\.submit\\.deployMode[[:space:]]/d'"
|
||||
+ " -e '/^spark\\.submit\\.customResourceManager/d' \"$conf/spark-defaults.conf\"",
|
||||
"printf '\\n%s\\n' \"$" + SPARK_DEFAULTS_VARIABLE + "\" >> \"$conf/spark-defaults.conf\"",
|
||||
// On a cluster, the hadoop command gets its HDFS too, through a copy of its Hadoop configuration (the
|
||||
// image's, or the folder a spark-env export names), links followed, whose core-site.xml takes in the
|
||||
// original's through Hadoop's XInclude, whatever its XML, then HADOOP_SITE_VARIABLE's properties, which
|
||||
// win (see hadoopSite). Its script runs only once its HDFS, MapReduce and YARN homes name folders that
|
||||
// are there, and the image has /usr/lib/hadoop alone. The image's hdfs command cannot run, so hdfs dfs
|
||||
// runs as hadoop fs.
|
||||
// On a cluster, the hadoop command gets its HDFS and Floci's S3 too, through a copy of its Hadoop
|
||||
// configuration (the image's, or the folder a spark-env export names), links followed, whose
|
||||
// core-site.xml takes in the original's through Hadoop's XInclude, whatever its XML, then
|
||||
// HADOOP_SITE_VARIABLE's properties, which win (see hadoopSite), and whose mapred-site.xml runs
|
||||
// MapReduce in local mode the same way. Its script runs only once its HDFS, MapReduce and YARN homes
|
||||
// name folders that are there, and the image has /usr/lib/hadoop alone, without MapReduce, so the
|
||||
// MapReduce home is Floci's (see MAPRED_HOME). The image's hdfs command cannot run, so hdfs dfs runs
|
||||
// as hadoop fs, and its hadoop-streaming names a jar it does not have, so the one it has runs.
|
||||
"if [ -n \"${" + HADOOP_SITE_VARIABLE + ":-}\" ]; then",
|
||||
" hadoop_conf=/tmp/floci-hadoop-conf source_conf=\"${HADOOP_CONF_DIR:-/etc/hadoop/conf}\"",
|
||||
" mkdir -p \"$hadoop_conf\" /tmp/floci-bin",
|
||||
" mkdir -p \"$hadoop_conf\" /tmp/floci-bin " + MAPRED_HOME,
|
||||
" cp -rL \"$source_conf/.\" \"$hadoop_conf\" 2>/dev/null",
|
||||
" include=",
|
||||
" if [ -f \"$hadoop_conf/core-site.xml\" ]; then",
|
||||
" mv \"$hadoop_conf/core-site.xml\" \"$hadoop_conf/floci-original-core-site.xml\"",
|
||||
" include='<xi:include href=\"/tmp/floci-hadoop-conf/floci-original-core-site.xml\"/>'",
|
||||
" site() {",
|
||||
" include=",
|
||||
" if [ -f \"$hadoop_conf/$1\" ]; then",
|
||||
" mv \"$hadoop_conf/$1\" \"$hadoop_conf/floci-original-$1\"",
|
||||
" include=\"<xi:include href=\\\"$hadoop_conf/floci-original-$1\\\"/>\"",
|
||||
" fi",
|
||||
" printf '%s\\n' '<configuration xmlns:xi=\"http://www.w3.org/2001/XInclude\">' \"$include\" \"$2\""
|
||||
+ " '</configuration>' > \"$hadoop_conf/$1\"",
|
||||
" }",
|
||||
" site core-site.xml \"$" + HADOOP_SITE_VARIABLE + "\"",
|
||||
" site mapred-site.xml '" + MAPRED_SITE + "'",
|
||||
// The local staging folder is a link to the same path in the HDFS folder, so a job's files are where
|
||||
// their path leads.
|
||||
" mkdir -p \"" + HDFS_FOLDER + MAPRED_STAGING + "\" \"$(dirname " + MAPRED_STAGING + ")\"",
|
||||
" ln -sfn \"" + HDFS_FOLDER + MAPRED_STAGING + "\" " + MAPRED_STAGING,
|
||||
" if [ ! -s \"$hadoop_conf/log4j.properties\" ]; then",
|
||||
" printf '%s\\n' '" + String.join("' '", HADOOP_CONSOLE_LOG) + "' > \"$hadoop_conf/log4j.properties\"",
|
||||
" fi",
|
||||
" printf '%s\\n' '<configuration xmlns:xi=\"http://www.w3.org/2001/XInclude\">' \"$include\" \"$"
|
||||
+ HADOOP_SITE_VARIABLE + "\" '</configuration>' > \"$hadoop_conf/core-site.xml\"",
|
||||
" printf '%s\\n' '#!/bin/bash' 'if [ \"$1\" = dfs ]; then shift; exec hadoop fs \"$@\"; fi'"
|
||||
+ " 'echo \"hdfs $1: only hdfs dfs runs here, as hadoop fs\" >&2' 'exit 1' > /tmp/floci-bin/hdfs",
|
||||
" chmod +x /tmp/floci-bin/hdfs",
|
||||
" printf '%s\\n' '#!/bin/bash' 'exec hadoop jar /usr/lib/hadoop/hadoop-streaming.jar \"$@\"'"
|
||||
+ " > /tmp/floci-bin/hadoop-streaming",
|
||||
" chmod +x /tmp/floci-bin/hdfs /tmp/floci-bin/hadoop-streaming",
|
||||
" for jar in " + String.join(" ", MAPRED_JARS) + "; do",
|
||||
" if [ -f \"$jar\" ]; then ln -sf \"$jar\" " + MAPRED_HOME + "/; fi",
|
||||
" done",
|
||||
" export HADOOP_CONF_DIR=\"$hadoop_conf\" PATH=\"/tmp/floci-bin:$PATH\"",
|
||||
" export HADOOP_HDFS_HOME=\"${HADOOP_HDFS_HOME:-/usr/lib/hadoop}\"",
|
||||
" export HADOOP_MAPRED_HOME=\"${HADOOP_MAPRED_HOME:-/usr/lib/hadoop}\"",
|
||||
" export HADOOP_MAPRED_HOME=\"${HADOOP_MAPRED_HOME:-" + MAPRED_HOME + "}\"",
|
||||
" export HADOOP_YARN_HOME=\"${HADOOP_YARN_HOME:-/usr/lib/hadoop}\"",
|
||||
"fi",
|
||||
"exec \"$@\""));
|
||||
@@ -240,7 +285,7 @@ public class EmrServerlessSparkRunner implements SparkJobRunner, ContainerTeardo
|
||||
.withCmd(job.command())
|
||||
.withEnv(SPARK_DEFAULTS_VARIABLE, sparkDefaultsFile(job, endpoint));
|
||||
if (job.storage() != null) {
|
||||
container.withEnv(HADOOP_SITE_VARIABLE, hadoopSite(job));
|
||||
container.withEnv(HADOOP_SITE_VARIABLE, hadoopSite(job, endpoint));
|
||||
}
|
||||
}
|
||||
if (!job.sparkLog4j2().isEmpty()) {
|
||||
@@ -568,12 +613,15 @@ public class EmrServerlessSparkRunner implements SparkJobRunner, ContainerTeardo
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@code core-site.xml} properties a step's {@code hadoop} command gets: its cluster's HDFS, then the
|
||||
* job's {@code core-site}, which wins, as a later property does in one file.
|
||||
* The {@code core-site.xml} properties a step's {@code hadoop} command gets: Floci's S3 and Glue, as its
|
||||
* {@code spark-submit} gets them, its cluster's HDFS, then the job's {@code core-site}, which wins, as a
|
||||
* later property does in one file.
|
||||
*/
|
||||
static String hadoopSite(Job job) {
|
||||
static String hadoopSite(Job job, String flociEndpoint) {
|
||||
List<SparkSetting> settings = new ArrayList<>(hadoopSettings(job, flociEndpoint));
|
||||
settings.addAll(HDFS_SETTINGS);
|
||||
List<String> properties = new ArrayList<>();
|
||||
for (SparkSetting setting : HDFS_SETTINGS) {
|
||||
for (SparkSetting setting : settings) {
|
||||
properties.add(siteProperty(setting.key(), setting.value()));
|
||||
}
|
||||
job.coreSite().forEach((name, value) -> properties.add(siteProperty(name, value)));
|
||||
@@ -623,20 +671,28 @@ public class EmrServerlessSparkRunner implements SparkJobRunner, ContainerTeardo
|
||||
return escaped.toString();
|
||||
}
|
||||
|
||||
// Floci's Hadoop settings: S3A on Floci's S3, and the Glue Data Catalog client on Floci's Glue.
|
||||
private static List<SparkSetting> hadoopSettings(Job job, String flociEndpoint) {
|
||||
return List.of(
|
||||
new SparkSetting("fs.s3a.endpoint", flociEndpoint),
|
||||
new SparkSetting("fs.s3a.endpoint.region", job.region()),
|
||||
new SparkSetting("fs.s3a.path.style.access", "true"),
|
||||
new SparkSetting("fs.s3a.committer.magic.track.commits.in.memory.enabled", "true"),
|
||||
new SparkSetting("fs.s3.impl", "org.apache.hadoop.fs.s3a.S3AFileSystem"),
|
||||
new SparkSetting("fs.AbstractFileSystem.s3.impl", "org.apache.hadoop.fs.s3a.S3A"),
|
||||
new SparkSetting("aws.glue.endpoint", flociEndpoint),
|
||||
new SparkSetting("aws.region", job.region()));
|
||||
}
|
||||
|
||||
// Floci's settings, then the job's spark-defaults, in the order a later one wins.
|
||||
private static List<SparkSetting> sparkSettings(Job job, String flociEndpoint) {
|
||||
List<SparkSetting> settings = new ArrayList<>(List.of(
|
||||
new SparkSetting("spark.hadoop.fs.s3a.endpoint", flociEndpoint),
|
||||
new SparkSetting("spark.hadoop.fs.s3a.endpoint.region", job.region()),
|
||||
new SparkSetting("spark.hadoop.fs.s3a.path.style.access", "true"),
|
||||
new SparkSetting("spark.hadoop.fs.s3a.committer.magic.track.commits.in.memory.enabled", "true"),
|
||||
new SparkSetting("spark.hadoop.fs.s3.impl", "org.apache.hadoop.fs.s3a.S3AFileSystem"),
|
||||
new SparkSetting("spark.hadoop.fs.AbstractFileSystem.s3.impl", "org.apache.hadoop.fs.s3a.S3A"),
|
||||
new SparkSetting("spark.hadoop.aws.glue.endpoint", flociEndpoint),
|
||||
new SparkSetting("spark.hadoop.aws.region", job.region())));
|
||||
List<SparkSetting> hadoop = new ArrayList<>(hadoopSettings(job, flociEndpoint));
|
||||
if (job.storage() != null) {
|
||||
hadoop.addAll(HDFS_SETTINGS);
|
||||
}
|
||||
List<SparkSetting> settings = new ArrayList<>();
|
||||
hadoop.forEach(setting -> settings.add(new SparkSetting("spark.hadoop." + setting.key(), setting.value())));
|
||||
if (job.storage() != null) {
|
||||
HDFS_SETTINGS.forEach(setting -> settings.add(new SparkSetting("spark.hadoop." + setting.key(),
|
||||
setting.value())));
|
||||
settings.add(FILE_SYSTEM_CHECKPOINTS);
|
||||
}
|
||||
job.sparkDefaults().forEach((key, value) -> settings.add(new SparkSetting(key, value)));
|
||||
|
||||
+16
@@ -304,6 +304,22 @@ class EmrServiceContainerStepsTest {
|
||||
assertEquals(List.of(), runner.jobs);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aStreamingStepRunsItsCommandOnTheClustersStorage() {
|
||||
EmrStep streaming = sparkStep("Streaming program", "CONTINUE");
|
||||
List<String> args = List.of("hadoop-streaming", "-files", "s3://bucket/mapper.py", "-mapper", "mapper.py",
|
||||
"-reducer", "aggregate", "-input", "s3://bucket/input/", "-output", "s3://bucket/output/");
|
||||
streaming.setArgs(new ArrayList<>(args));
|
||||
EmrCluster cluster = service.runJobFlow(cluster("streaming", true, streaming), REGION);
|
||||
|
||||
fixture.runStepThread();
|
||||
|
||||
assertEquals("COMPLETED", service.describeStep(cluster.getId(), cluster.getSteps().get(0).getId()).getState());
|
||||
SparkJobRunner.Job job = runner.jobs.get(0);
|
||||
assertEquals(args, job.command());
|
||||
assertEquals(new SparkJobRunner.Storage(cluster.getId() + "-home", cluster.getId() + "-mnt"), job.storage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anS3DistCpStepRunsFlocisS3DistCpOnTheClustersStorage() {
|
||||
EmrStep copy = sparkStep("copy", "CONTINUE");
|
||||
|
||||
@@ -125,9 +125,22 @@ class EmrSparkStepsTest {
|
||||
assertFalse(program.lines().anyMatch(EmrSparkSteps.S3_DIST_CP_END::equals));
|
||||
}
|
||||
|
||||
@Test
|
||||
void streamingAndTheLzoIndexerRunAsTheCommandsTheyAre() {
|
||||
// The Management Guide's streaming step, as the AWS CLI turns Type=STREAMING into one.
|
||||
String[] streaming = {"hadoop-streaming", "-files", "s3://bucket/my_mapper.py,s3://bucket/my_reducer.py",
|
||||
"-mapper", "my_mapper.py", "-reducer", "my_reducer.py", "-input", "s3://bucket/my_input",
|
||||
"-output", "s3://bucket/my_output",
|
||||
"-cacheFile", "s3://bucket/sample_dataset.dat#sample_dataset_cached.dat"};
|
||||
String[] indexer = {"hadoop-lzo", "com.hadoop.compression.lzo.DistributedLzoIndexer", "s3://bucket/logs/"};
|
||||
|
||||
assertEquals(List.of(streaming), EmrSparkSteps.command(step("command-runner.jar", null, streaming)));
|
||||
assertEquals(List.of(indexer), EmrSparkSteps.command(step("command-runner.jar", null, indexer)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void toolsTheImageDoesNotHaveAreNotRun() {
|
||||
for (String tool : List.of("hive-script", "pig-script", "hadoop-streaming", "hadoop-lzo")) {
|
||||
for (String tool : List.of("hive-script", "pig-script")) {
|
||||
assertNull(EmrSparkSteps.command(step("command-runner.jar", null, tool, "--src", "s3://bucket/in/")));
|
||||
}
|
||||
assertNull(EmrSparkSteps.command(step("command-runner.jar", null)));
|
||||
|
||||
+87
-11
@@ -437,12 +437,12 @@ class EmrServerlessSparkRunnerTest {
|
||||
|
||||
verify(spec).withNamedVolume(STORAGE.home(), "/home/hadoop");
|
||||
verify(spec).withNamedVolume(STORAGE.mnt(), "/mnt");
|
||||
verify(spec).withEnv("FLOCI_HADOOP_SITE", String.join("\n",
|
||||
verify(spec).withEnv(eq("FLOCI_HADOOP_SITE"), argThat(site -> site.endsWith(String.join("\n",
|
||||
"<property><name>fs.defaultFS</name><value>hdfs:///</value></property>",
|
||||
"<property><name>fs.hdfs.impl</name><value>org.apache.hadoop.fs.viewfs.ViewFileSystemOverloadScheme"
|
||||
+ "</value></property>",
|
||||
"<property><name>fs.viewfs.mounttable.default.linkFallback</name><value>file:///mnt/hdfs</value>"
|
||||
+ "</property>"));
|
||||
+ "</property>"))));
|
||||
verify(spec).withEnv(eq("FLOCI_SPARK_DEFAULTS"), argThat(file -> file.contains(
|
||||
"\nspark.hadoop.fs.defaultFS hdfs:///\n")));
|
||||
// A copy of the Hadoop configuration a spark-env export of HADOOP_CONF_DIR names, else of the image's, links
|
||||
@@ -450,22 +450,97 @@ class EmrServerlessSparkRunnerTest {
|
||||
verify(spec).withEntrypoint(argThat(entrypoint -> entrypoint.get(2).contains(
|
||||
"source_conf=\"${HADOOP_CONF_DIR:-/etc/hadoop/conf}\"\n")
|
||||
&& entrypoint.get(2).contains("cp -rL \"$source_conf/.\" \"$hadoop_conf\"")
|
||||
&& entrypoint.get(2).contains(
|
||||
"include='<xi:include href=\"/tmp/floci-hadoop-conf/floci-original-core-site.xml\"/>'")
|
||||
&& entrypoint.get(2).contains("'<configuration xmlns:xi=\"http://www.w3.org/2001/XInclude\">'"
|
||||
+ " \"$include\" \"$FLOCI_HADOOP_SITE\" '</configuration>' > \"$hadoop_conf/core-site.xml\"")
|
||||
&& entrypoint.get(2).contains(String.join("\n",
|
||||
" if [ -f \"$hadoop_conf/$1\" ]; then",
|
||||
" mv \"$hadoop_conf/$1\" \"$hadoop_conf/floci-original-$1\"",
|
||||
" include=\"<xi:include href=\\\"$hadoop_conf/floci-original-$1\\\"/>\"",
|
||||
" fi",
|
||||
" printf '%s\\n' '<configuration xmlns:xi=\"http://www.w3.org/2001/XInclude\">' \"$include\""
|
||||
+ " \"$2\" '</configuration>' > \"$hadoop_conf/$1\""))
|
||||
&& entrypoint.get(2).contains("\n site core-site.xml \"$FLOCI_HADOOP_SITE\"\n")
|
||||
&& entrypoint.get(2).contains(
|
||||
"export HADOOP_CONF_DIR=\"$hadoop_conf\" PATH=\"/tmp/floci-bin:$PATH\"")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aStepsHadoopCommandGetsItsClustersCoreSiteAfterItsHdfsEscapedForXml() {
|
||||
void aStepsHadoopCommandReachesFlocisS3AndRunsMapReduceLocally() {
|
||||
ContainerBuilder builder = mock(ContainerBuilder.class);
|
||||
ContainerBuilder.Builder spec = mock(ContainerBuilder.Builder.class, RETURNS_SELF);
|
||||
when(builder.newContainer(anyString())).thenReturn(spec);
|
||||
List<String> command = List.of("hadoop-streaming", "-mapper", "cat", "-input", "s3://bucket/input/",
|
||||
"-output", "s3://bucket/output/");
|
||||
SparkJobRunner.Job job = commandJob(command, Map.of(), STORAGE);
|
||||
|
||||
runner(builder).run(job, progress);
|
||||
|
||||
// S3A on Floci's S3, as the step's spark-submit gets it.
|
||||
verify(spec).withEnv("FLOCI_HADOOP_SITE", EmrServerlessSparkRunner.hadoopSite(job, ENDPOINT));
|
||||
verify(spec).withEnv(eq("FLOCI_HADOOP_SITE"), argThat(site -> site.startsWith(
|
||||
"<property><name>fs.s3a.endpoint</name><value>http://floci:4566</value></property>\n")));
|
||||
verify(spec).withCmd(command);
|
||||
verify(spec).withEntrypoint(argThat(entrypoint -> entrypoint.get(2).contains(String.join("\n",
|
||||
" site mapred-site.xml '<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>'",
|
||||
// The local job runner names a job's files by their path alone, which leads to the cluster's HDFS.
|
||||
" mkdir -p \"/mnt/hdfs/tmp/hadoop/mapred/staging\" \"$(dirname /tmp/hadoop/mapred/staging)\"",
|
||||
" ln -sfn \"/mnt/hdfs/tmp/hadoop/mapred/staging\" /tmp/hadoop/mapred/staging\n"))
|
||||
// MapReduce from Spark's shaded Hadoop client, and S3A's AWS SDK, in a MapReduce home of Floci's,
|
||||
// which a command's own HADOOP_CLASSPATH does not take off the hadoop command's class path.
|
||||
&& entrypoint.get(2).contains("\n mkdir -p \"$hadoop_conf\" /tmp/floci-bin /tmp/floci-mapreduce\n")
|
||||
&& entrypoint.get(2).contains(String.join("\n",
|
||||
" for jar in /usr/lib/spark/jars/hadoop-client-api-*.jar"
|
||||
+ " /usr/lib/spark/jars/hadoop-client-runtime-*.jar"
|
||||
+ " /usr/lib/spark/jars/emr-serverless-spark-goodies.jar; do",
|
||||
" if [ -f \"$jar\" ]; then ln -sf \"$jar\" /tmp/floci-mapreduce/; fi",
|
||||
" done"))
|
||||
&& entrypoint.get(2).contains(
|
||||
"\n export HADOOP_MAPRED_HOME=\"${HADOOP_MAPRED_HOME:-/tmp/floci-mapreduce}\"\n")
|
||||
// The image's hadoop-streaming names /usr/lib/hadoop-mapreduce/hadoop-streaming.jar, which it lacks.
|
||||
&& entrypoint.get(2).contains("printf '%s\\n' '#!/bin/bash'"
|
||||
+ " 'exec hadoop jar /usr/lib/hadoop/hadoop-streaming.jar \"$@\"'"
|
||||
+ " > /tmp/floci-bin/hadoop-streaming")
|
||||
&& entrypoint.get(2).contains("chmod +x /tmp/floci-bin/hdfs /tmp/floci-bin/hadoop-streaming")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aStepsHadoopCommandLogsToStandardErrorWhenItsLog4jPropertiesIsEmpty() {
|
||||
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("hadoop", "fs", "-ls", "s3://bucket/"), Map.of(), STORAGE), progress);
|
||||
|
||||
// The image's is empty; one a spark-env export's folder has is kept.
|
||||
verify(spec).withEntrypoint(argThat(entrypoint -> entrypoint.get(2).contains(String.join("\n",
|
||||
" if [ ! -s \"$hadoop_conf/log4j.properties\" ]; then",
|
||||
" printf '%s\\n' 'hadoop.root.logger=INFO,console' 'log4j.rootLogger=${hadoop.root.logger}'"
|
||||
+ " 'log4j.appender.console=org.apache.log4j.ConsoleAppender'"
|
||||
+ " 'log4j.appender.console.target=System.err'"
|
||||
+ " 'log4j.appender.console.layout=org.apache.log4j.PatternLayout'"
|
||||
+ " 'log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %p %c (%t): %m%n'"
|
||||
+ " > \"$hadoop_conf/log4j.properties\"",
|
||||
" fi"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aStepsHadoopCommandGetsItsClustersCoreSiteAfterFlocisS3AndItsHdfsEscapedForXml() {
|
||||
Map<String, String> coreSite = new LinkedHashMap<>();
|
||||
coreSite.put("fs.permissions.umask-mode", "077");
|
||||
coreSite.put("floci.note", "a<b & \"c\" 'd'");
|
||||
|
||||
// A later property wins over an earlier one in the same file.
|
||||
assertEquals(String.join("\n",
|
||||
"<property><name>fs.s3a.endpoint</name><value>http://floci:4566</value></property>",
|
||||
"<property><name>fs.s3a.endpoint.region</name><value>eu-west-1</value></property>",
|
||||
"<property><name>fs.s3a.path.style.access</name><value>true</value></property>",
|
||||
"<property><name>fs.s3a.committer.magic.track.commits.in.memory.enabled</name><value>true</value>"
|
||||
+ "</property>",
|
||||
"<property><name>fs.s3.impl</name><value>org.apache.hadoop.fs.s3a.S3AFileSystem</value></property>",
|
||||
"<property><name>fs.AbstractFileSystem.s3.impl</name><value>org.apache.hadoop.fs.s3a.S3A</value>"
|
||||
+ "</property>",
|
||||
"<property><name>aws.glue.endpoint</name><value>http://floci:4566</value></property>",
|
||||
"<property><name>aws.region</name><value>eu-west-1</value></property>",
|
||||
"<property><name>fs.defaultFS</name><value>hdfs:///</value></property>",
|
||||
"<property><name>fs.hdfs.impl</name><value>org.apache.hadoop.fs.viewfs.ViewFileSystemOverloadScheme"
|
||||
+ "</value></property>",
|
||||
@@ -474,7 +549,7 @@ class EmrServerlessSparkRunnerTest {
|
||||
"<property><name>fs.permissions.umask-mode</name><value>077</value></property>",
|
||||
"<property><name>floci.note</name><value>a<b & "c" 'd'</value></property>"),
|
||||
EmrServerlessSparkRunner.hadoopSite(
|
||||
clusterJob(List.of("hadoop", "fs", "-ls", "/"), coreSite, Map.of())));
|
||||
clusterJob(List.of("hadoop", "fs", "-ls", "/"), coreSite, Map.of()), ENDPOINT));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -910,9 +985,10 @@ class EmrServerlessSparkRunnerTest {
|
||||
when(lifecycle.create(any())).thenReturn("driver");
|
||||
when(docker.inspectContainerCmd("driver").exec().getState().getRunning()).thenReturn(false);
|
||||
when(docker.inspectContainerCmd("driver").exec().getState().getExitCodeLong()).thenReturn(0L);
|
||||
return new EmrServerlessSparkRunner(builder, lifecycle, logStreamer,
|
||||
mock(LaunchedContainerAwsEnv.class), mock(LambdaExecutionRoleCredentials.class), s3, ecr, config,
|
||||
new MutableClock(), Duration.ZERO);
|
||||
LaunchedContainerAwsEnv awsEnv = mock(LaunchedContainerAwsEnv.class);
|
||||
when(awsEnv.flociEndpoint()).thenReturn(ENDPOINT);
|
||||
return new EmrServerlessSparkRunner(builder, lifecycle, logStreamer, awsEnv,
|
||||
mock(LambdaExecutionRoleCredentials.class), s3, ecr, config, new MutableClock(), Duration.ZERO);
|
||||
}
|
||||
|
||||
// What the driver wrote, as Docker gives it once asked for an ended container's output.
|
||||
|
||||
Reference in new issue
Block a user