mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
feat(emr): run s3-dist-cp steps (#7192)
In the docker runner mode an s3-dist-cp step, the Release Guide's way of
moving data "from Amazon S3 into HDFS where it can be processed by
subsequent steps", between buckets or back to S3, was FAILED without
running, and on the default TERMINATE_CLUSTER it ended its cluster with
errors. The EMR Serverless image steps run in has neither s3-dist-cp nor
the MapReduce it runs on.
Now a command-runner.jar step whose first argument is s3-dist-cp runs
Floci's own S3DistCp: a Python program, emr/s3-dist-cp.py, which the step's
command writes into the container and runs through spark-submit, copying
through Hadoop's file systems in Spark's JVM. The command wrapper gives it
what a Spark step gets: S3 paths in Floci's S3 and hdfs:// paths, and
those without a scheme, in the cluster's HDFS. It takes the options of
the Release Guide's table, --name=value or --name value, and -D
property=value:
- --src and --dest, a source folder's files keeping their folders;
- --srcPattern and --groupBy matched against the whole path; --groupBy
concatenates the files whose groups give the same name into one file
named by them, and refuses an expression with no group, as the guide
says S3DistCp does; --targetSize breaks a larger group into parts
numbered before the extension ("myfile0.gz, myfile1.gz"); without
--outputCodec a group keeps the compression its files share, named
with that codec's extension, or has none when they differ, each file
decompressed so the group is one stream;
- --outputCodec (gzip, gz, lzo, lzop, snappy, none) through Hadoop's
codecs, each source decompressed by its own extension;
- --deleteOnSuccess, deleting the files but not their folders, as AWS's
"Seven tips for using S3DistCp" says;
- --outputManifest, --previousManifest, --requirePreviousManifest and
--copyFromManifest, the manifest gzipped JSON lines of path, baseName,
srcDir and size, as that post shows them;
- --s3ServerSideEncryption, --storageClass, --disableMultipartUpload and
--multipartUploadChunkSize as S3A's settings; --numberFiles,
--startingIndex, --srcPrefixesFile and --appendToLastFile, the last
through a copy renamed over the file, as neither S3 nor the cluster's
HDFS appends in place. The copy has a name of its own and goes if the
writing fails, and the file steps aside, under a name of its own too,
until the copy has taken its place, coming back if it cannot, so a
failed append leaves it as it was. --s3Endpoint is ignored, S3 being
Floci's.
--requirePreviousManifest takes true or false, after = or as the next
argument, and alone is true, its default. A --srcPrefixesFile line ending
in / names that folder alone, its slash kept though Hadoop's Path drops
it; any other is a prefix as S3 lists one, logs/day taking in
logs/day-old/.
A bucket name with an underscore fails the step, as S3DistCp "does not
support" one, and so does a copy Hadoop fails, leaving what was copied.
A copy that would write two files to the same path, the manifest
included (a.log and a.log.gz with --outputCodec=gzip), a file over one
of its own sources, as with the same --src and --dest, or a file outside
--dest, through a .. in a manifest's baseName or in --outputManifest
(Hadoop's paths resolve it), or a file with no name, from a --groupBy
whose groups matched nothing say, fails before it writes anything. emr.md
says what is Floci's own reading: the grouped file's folder,
--numberFiles' naming, a group's compression without --outputCodec and
that refusal.
This commit is contained in:
1 parent
beef71e8eb
commit
a74a9b0ffc
7 files changed
+973
-14
No files matched your search
@@ -7,6 +7,10 @@ import io.github.hectorvent.floci.services.emr.model.EmrCluster;
|
||||
import io.github.hectorvent.floci.services.emr.model.EmrStep;
|
||||
import io.github.hectorvent.floci.services.emrserverless.EmrServerlessSparkRunner;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -19,13 +23,13 @@ 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.
|
||||
* and scripts on an Amazon EMR cluster" describes them; 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,"
|
||||
+ " hadoop-lzo and s3-dist-cp are not in the image steps run in.";
|
||||
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 INTERRUPTED = "Floci stopped while the step was running.";
|
||||
|
||||
private static final String COMMAND_RUNNER = "command-runner.jar";
|
||||
@@ -46,9 +50,13 @@ final class EmrSparkSteps {
|
||||
// Spark puts a spark.hadoop. setting in the Hadoop configuration its Hive client reads, ahead of hive-site.xml.
|
||||
private static final String SPARK_HADOOP_PREFIX = "spark.hadoop.";
|
||||
// The Release Guide's command-runner.jar tools that the EMR Serverless image does not have; its hadoop
|
||||
// has no HDFS to run streaming or the LZO indexer against.
|
||||
// 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", "s3-dist-cp");
|
||||
"hadoop-lzo");
|
||||
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.
|
||||
static final String S3_DIST_CP_END = "FLOCI_S3_DIST_CP";
|
||||
// script-runner.jar fetches its script from S3 with the step's credentials, the image's AWS CLI reaching
|
||||
// Floci's S3, and runs it with its arguments; a path that is not in S3 is run as it is, a bare name from
|
||||
// the working directory when a file there has it, as exec would otherwise look for it on the PATH only.
|
||||
@@ -105,7 +113,8 @@ final class EmrSparkSteps {
|
||||
/**
|
||||
* The command a step that is not a Spark step runs, or null for one Floci does not run: a
|
||||
* {@code command-runner.jar} step's arguments, its command first, unless it names a tool the image does
|
||||
* not have; a {@code script-runner.jar} step's script, the first of its arguments, with the rest.
|
||||
* not have; Floci's S3DistCp with the arguments of an {@code s3-dist-cp} one; a {@code script-runner.jar}
|
||||
* step's script, the first of its arguments, with the rest.
|
||||
*/
|
||||
static List<String> command(EmrStep step) {
|
||||
String jar = step.getJar();
|
||||
@@ -114,6 +123,11 @@ final class EmrSparkSteps {
|
||||
return null;
|
||||
}
|
||||
if (named(jar, COMMAND_RUNNER)) {
|
||||
if (S3_DIST_CP.equals(args.getFirst())) {
|
||||
List<String> command = new ArrayList<>(List.of("bash", "-c", S3DistCp.COMMAND, S3_DIST_CP));
|
||||
command.addAll(args.subList(1, args.size()));
|
||||
return command;
|
||||
}
|
||||
return named(args.getFirst(), SPARK_SUBMIT) || UNAVAILABLE_TOOLS.contains(args.getFirst())
|
||||
? null : List.copyOf(args);
|
||||
}
|
||||
@@ -211,6 +225,32 @@ final class EmrSparkSteps {
|
||||
return kept;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
private static final class S3DistCp {
|
||||
static final String COMMAND = String.join("\n",
|
||||
"program=\"${TMPDIR:-/tmp}/floci-s3-dist-cp.py\"",
|
||||
"cat > \"$program\" <<'" + S3_DIST_CP_END + "'",
|
||||
program(),
|
||||
S3_DIST_CP_END,
|
||||
"exec spark-submit --conf spark.ui.enabled=false \"$program\" \"$@\"");
|
||||
|
||||
private static String program() {
|
||||
try (InputStream in = Thread.currentThread().getContextClassLoader()
|
||||
.getResourceAsStream(S3_DIST_CP_RESOURCE)) {
|
||||
if (in == null) {
|
||||
throw new IllegalStateException(S3_DIST_CP_RESOURCE + " is missing from the classpath");
|
||||
}
|
||||
return new String(in.readAllBytes(), StandardCharsets.UTF_8).stripTrailing();
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Could not read " + S3_DIST_CP_RESOURCE, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// command-runner.jar is named alone; a path such as /usr/bin/spark-submit names spark-submit too.
|
||||
private static boolean named(String path, String name) {
|
||||
return path.equals(name) || path.endsWith("/" + name);
|
||||
|
||||
Reference in new issue
Block a user