mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(emr-containers): give a managed endpoint's Scala kernel Toree's magics (#9313)
Toree finds its built-in magics (%AddJar, %AddDeps, %LsMagic, %%sql,
%%dataframe and the rest) by scanning its own jar for plugin classes,
and its class finder reads each entry's name through a reflective call
to JarFile$JarFileEntry.getName(). The notebook image's Java 17 refuses
that call unless java.util.jar is open to the caller, so the scan
failed ("PluginSearcher: Failed to load class info from classpath",
an InaccessibleObjectException) and the kernel started with no magics.
- The Scala kernel spec exports JDK_JAVA_OPTIONS with
--add-opens=java.base/java.util.jar=ALL-UNNAMED, after any value
already set, before it runs spark-submit. Java reads the variable
itself, so the image's spark.driver.extraJavaOptions stay as they
are, where --driver-java-options would replace them. The option
comes from EmrServerlessSparkRunner.javaBaseOpens, which now builds
YARN's options from their package list too.
- The nightly check's Scala kernel adds a jar with %AddJar, then
compiles a cell against a class in it. Its method's timeout grows by
the two cells' four minutes, and the docker-runner group's with it.
This commit is contained in:
1 parent
4198612422
commit
a1b96f5c3f
6 files changed
+44
-12
No files matched your search
@@ -34,8 +34,8 @@ jobs:
|
||||
# EmrDockerRunnerNightlyIntegrationTest's eleven two-minute tests and two-minute setup,
|
||||
# EmrClusterShrinkNightlyIntegrationTest's sixteen-minute method and two-minute setup, and
|
||||
# EmrContainersSparkNightlyIntegrationTest's three six-minute methods, eleven-minute method, two-minute setup before
|
||||
# each and 21-minute image pull, and EmrContainersGatewayNightlyIntegrationTest's twenty-minute, seven-minute and
|
||||
# eighteen-minute methods and 21-minute image pull, 166 minutes. A check added, or a bound raised, raises its
|
||||
# each and 21-minute image pull, and EmrContainersGatewayNightlyIntegrationTest's twenty-four-minute, seven-minute
|
||||
# and eighteen-minute methods and 21-minute image pull, 170 minutes. A check added, or a bound raised, raises its
|
||||
# group's timeout with it, so a slow check fails with its own message.
|
||||
strategy:
|
||||
fail-fast: false
|
||||
@@ -44,7 +44,7 @@ jobs:
|
||||
- group: standard
|
||||
timeout: 359
|
||||
- group: docker-runner
|
||||
timeout: 186
|
||||
timeout: 190
|
||||
timeout-minutes: ${{ matrix.timeout }}
|
||||
# A fork's schedule would spend its owner's minutes on checks it never asked for; a draft waits until it is
|
||||
# ready for review, as the CI shards do.
|
||||
|
||||
@@ -236,8 +236,10 @@ remote kernel lifecycle management capability that interactive clients need" (EM
|
||||
* **Kernels**: the image's `python3` ("Python 3"); `spark-python-kubernetes` ("PySpark on Kubernetes", the name the
|
||||
guide's `jupyter-kernel-overrides` example gives it); and `spark-scala-kubernetes` ("Apache Spark with Scala", a
|
||||
name of Floci's beside it, as the guide gives the Scala kernel none), which runs the image's Apache Toree under
|
||||
`spark-submit`, as Toree's own kernel spec does. The Spark kernels' `spark` and `sc` are a Spark session in Spark's
|
||||
local mode, where EMR on EKS runs each kernel and its executors in pods of their own. The PySpark kernel runs on
|
||||
`spark-submit`, as Toree's own kernel spec does, with `java.util.jar` open to it: Toree finds its magics,
|
||||
`%AddJar` and the rest, by reading its jar in a way Java 17 refuses otherwise, and a cell would have none. The
|
||||
Spark kernels' `spark` and `sc` are a Spark session in Spark's local mode, where EMR on EKS runs each kernel and
|
||||
its executors in pods of their own. The PySpark kernel runs on
|
||||
the image's Python, with `spark.pyspark.virtualenv.enabled` set to `false`: the image's `spark-defaults.conf` turns
|
||||
the virtualenv on, and `spark-submit` makes one on YARN and Kubernetes alone. Every kernel runs with the endpoint's
|
||||
execution role, as "All kernels and users that connect to the interactive endpoint utilize the role that you
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.floci.aws.core.common.AwsArnUtils;
|
||||
import io.floci.aws.services.emrserverless.EmrServerlessJobRunService;
|
||||
import io.floci.aws.services.emrserverless.EmrServerlessSparkRunner;
|
||||
import io.floci.aws.services.emrserverless.SessionServers;
|
||||
import io.floci.aws.services.emrserverless.SparkJobRunner;
|
||||
|
||||
@@ -108,6 +109,10 @@ final class EmrContainersGateways {
|
||||
// What the launcher's additional-info says to load the %%configure magic.
|
||||
private static final String CONFIGURE_MAGIC_ENABLED = Base64.getEncoder()
|
||||
.encodeToString("{\"configure_magic_enabled\": \"true\"}".getBytes(StandardCharsets.UTF_8));
|
||||
// Toree finds its magics, %AddJar and the rest, through a reflective read of its jar's entries that Java 17
|
||||
// refuses unless java.util.jar is open to it, and without them a cell can use none. The Scala kernel gets the
|
||||
// option through JDK_JAVA_OPTIONS, which Java reads itself, so the image's spark.driver.extraJavaOptions stay.
|
||||
private static final String TOREE_JAVA_OPTIONS = EmrServerlessSparkRunner.javaBaseOpens(List.of("java.util.jar"));
|
||||
|
||||
/** The servers' kind, in the answers to the calls they cannot take. */
|
||||
static final SessionServers.Kind KIND = new SessionServers.Kind("Jupyter Enterprise Gateway", "Endpoint",
|
||||
@@ -160,6 +165,8 @@ final class EmrContainersGateways {
|
||||
MAGICS = "/usr/local/bin/kernel-launchers/python/scripts"
|
||||
# The image's Apache Toree, which Jupyter Enterprise Gateway's Scala launcher runs.
|
||||
TOREE = "/usr/local/bin/kernel-launchers/scala/lib/toree-assembly-*.jar"
|
||||
# What Toree's JVM needs to find its magics.
|
||||
TOREE_JAVA_OPTIONS = "@TOREE_JAVA_OPTIONS@"
|
||||
# Where the magic posts its cell's settings when no ENDPOINT_IP names its gateway: its own host's port.
|
||||
CONFIGURE_PORT = 18888
|
||||
# The magic's signature of a post: the SHA-256 of its body, encrypted with its kernel's AES key.
|
||||
@@ -218,7 +225,8 @@ final class EmrContainersGateways {
|
||||
"display_name": "Apache Spark with Scala",
|
||||
"language": "scala",
|
||||
"argv": ["/bin/bash", "-c",
|
||||
'exec "$SPARK_HOME/bin/spark-submit" $KERNEL_EXTRA_SPARK_OPTS --class org.apache.toree.Main '
|
||||
'export JDK_JAVA_OPTIONS="${JDK_JAVA_OPTIONS:+$JDK_JAVA_OPTIONS }' + TOREE_JAVA_OPTIONS + '"; '
|
||||
+ 'exec "$SPARK_HOME/bin/spark-submit" $KERNEL_EXTRA_SPARK_OPTS --class org.apache.toree.Main '
|
||||
+ TOREE + ' --profile "$0"',
|
||||
"{connection_file}"],
|
||||
}))
|
||||
@@ -589,7 +597,8 @@ final class EmrContainersGateways {
|
||||
.replace("@PROGRAM_VARIABLE@", PROGRAM_VARIABLE).replace("@SESSION_HEADER@", SESSION_HEADER)
|
||||
.replace("@OVERRIDES_VARIABLE@", OVERRIDES_VARIABLE)
|
||||
.replace("@KERNEL_CONTAINERS_VARIABLE@", KERNEL_CONTAINERS_VARIABLE)
|
||||
.replace("@SECRET_VARIABLE@", SECRET_VARIABLE).replace("@SECRET_HEADER@", SECRET_HEADER);
|
||||
.replace("@SECRET_VARIABLE@", SECRET_VARIABLE).replace("@SECRET_HEADER@", SECRET_HEADER)
|
||||
.replace("@TOREE_JAVA_OPTIONS@", TOREE_JAVA_OPTIONS);
|
||||
|
||||
private EmrContainersGateways() {
|
||||
}
|
||||
|
||||
@@ -1537,7 +1537,12 @@ public class EmrServerlessSparkRunner implements SparkJobRunner, ContainerTeardo
|
||||
|
||||
/** 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")
|
||||
return javaBaseOpens(YARN_OPENED_PACKAGES);
|
||||
}
|
||||
|
||||
/** The JVM options that open these {@code java.base} packages to the classes on the class path. */
|
||||
public static String javaBaseOpens(List<String> packages) {
|
||||
return packages.stream().map(name -> "--add-opens=java.base/" + name + "=ALL-UNNAMED")
|
||||
.collect(Collectors.joining(" "));
|
||||
}
|
||||
|
||||
|
||||
+14
-4
@@ -58,8 +58,9 @@ import static org.junit.jupiter.api.Assertions.fail;
|
||||
* token alone, and runs code on Floci's S3 over the PySpark kernel's WebSocket, as the guide's "Example: Deploy a
|
||||
* JupyterLab notebook" does through {@code JUPYTER_GATEWAY_URL}, then changes its Spark session's settings with
|
||||
* {@code %%configure}, as "Modifying PySpark session parameters" does, and runs code on Floci's S3 in the "Apache
|
||||
* Spark with Scala" kernel too. An endpoint whose {@code jeg-config} sets a short idle timeout culls a kernel left
|
||||
* idle, and one whose {@code jupyter-kernel-overrides} gives its kernels an image runs each in a container of its own.
|
||||
* Spark with Scala" kernel too, where Toree's {@code %AddJar} adds a jar. An endpoint whose {@code jeg-config} sets a
|
||||
* short idle timeout culls a kernel left idle, and one whose {@code jupyter-kernel-overrides} gives its kernels an
|
||||
* image runs each in a container of its own.
|
||||
*
|
||||
* <p>A nightly check: the release's notebook image is about 6 GB.
|
||||
*/
|
||||
@@ -76,6 +77,9 @@ class EmrContainersGatewayNightlyIntegrationTest {
|
||||
private static final String RELEASE = "emr-7.5.0-latest";
|
||||
// The release's notebook image, which the gateway's default template names.
|
||||
private static final String NOTEBOOK_IMAGE = "public.ecr.aws/emr-on-eks/notebook-spark/emr-7.5.0:latest";
|
||||
// Jupyter Enterprise Gateway's Scala launcher in that image, which holds launcher.KernelProfile.
|
||||
private static final String TOREE_LAUNCHER =
|
||||
"/usr/local/bin/kernel-launchers/scala/lib/toree-launcher_2.12-1.0.jar";
|
||||
private static final Duration ACTIVE_TIMEOUT = Duration.ofMinutes(5);
|
||||
// jupyter_server holds a kernel's handshake until the kernel answers, up to its own minute, and the PySpark kernel
|
||||
// answers once its Spark session is up.
|
||||
@@ -104,10 +108,10 @@ class EmrContainersGatewayNightlyIntegrationTest {
|
||||
}
|
||||
|
||||
// The endpoint's gateway answers within its five minutes, each kernel's WebSocket opens within its two, once the
|
||||
// kernel is up, and each of the five cells answers within its two: nineteen minutes, and one for the requests
|
||||
// kernel is up, and each of the seven cells answers within its two: twenty-three minutes, and one for the requests
|
||||
// between. The Nightly checks' docker-runner group counts it.
|
||||
@Test
|
||||
@Timeout(value = 20, unit = TimeUnit.MINUTES)
|
||||
@Timeout(value = 24, unit = TimeUnit.MINUTES)
|
||||
void pysparkKernelOnTheEndpointsGatewayRunsCodeOnFlocisS3() throws Exception {
|
||||
S3Client s3 = AwsTestClients.create(S3Client.builder().forcePathStyle(true), ACCOUNT, Region.US_EAST_1);
|
||||
cleanup.register(s3::close);
|
||||
@@ -185,6 +189,12 @@ class EmrContainersGatewayNightlyIntegrationTest {
|
||||
String count = execute(scala, scalaMessages, session,
|
||||
"spark.read.textFile(\"s3://" + bucket + "/lines.txt\").count()");
|
||||
assertTrue(count.matches("(res\\d+: Long = )?3"), count);
|
||||
// Its magics load: %AddJar puts the image's Toree launcher, which the kernel does not run, on the cell's
|
||||
// class path.
|
||||
assertEquals("ok", run(scala, scalaMessages, session, "%AddJar file:" + TOREE_LAUNCHER, "execute_reply",
|
||||
"/content/status"));
|
||||
String added = execute(scala, scalaMessages, session, "classOf[launcher.KernelProfile].getName");
|
||||
assertTrue(added.matches("(res\\d+: String = )?launcher\\.KernelProfile"), added);
|
||||
scala.sendClose(WebSocket.NORMAL_CLOSURE, "done").get(10, TimeUnit.SECONDS);
|
||||
delete(http, gateway + "/api/kernels/" + scalaId, token);
|
||||
}
|
||||
|
||||
@@ -1460,6 +1460,12 @@ class EmrServerlessSparkRunnerTest {
|
||||
assertTrue(EmrServerlessSparkRunner.yarnJavaOptions().endsWith("--add-opens=java.base/sun.util.calendar=ALL-UNNAMED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void javaBaseOpensOpensEachPackageToTheClassPath() {
|
||||
assertEquals("--add-opens=java.base/java.util.jar=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED",
|
||||
EmrServerlessSparkRunner.javaBaseOpens(List.of("java.util.jar", "java.io")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aHadoopCommandOnAClusterWhoseCoreNodesHoldItsHdfsWritesTheirCopies() {
|
||||
ContainerBuilder builder = mock(ContainerBuilder.class);
|
||||
|
||||
Reference in new issue
Block a user