jerryshao commented on code in PR #13892:
URL: https://github.com/apache/gravitino/pull/13892#discussion_r4293089628
##########
plugins/k8s-job-executor/src/main/java/org/apache/gravitino/job/k8s/K8sJobExecutorConfigs.java:
##########
@@ -290,6 +306,14 @@ public K8sJobExecutorConfigs(Map<String, String> configs) {
positiveLongValue(configs, SPARK_DRIVER_START_TIMEOUT_MS,
DEFAULT_SPARK_START_TIMEOUT_MS);
this.sparkDriverReadyTimeoutMs =
positiveLongValue(configs, SPARK_DRIVER_READY_TIMEOUT_MS,
DEFAULT_SPARK_START_TIMEOUT_MS);
+ this.sparkBuiltinJobsJar =
+ stringValue(configs, SPARK_BUILTIN_JOBS_JAR,
DEFAULT_SPARK_BUILTIN_JOBS_JAR);
Review Comment:
[Question] Nothing ties the jar at `spark.builtinJobsJar` to the server's
own jobs jar, so a version skew is silent.
The built-in templates pin a `VERSION` custom field (for example
`maintenance/jobs/src/main/java/org/apache/gravitino/maintenance/jobs/spark/SparkPiJob.java:42-43`
and `iceberg/IcebergExpireSnapshotsJob.java:42`) and the arguments and
`className` of the template come from the server's jobs jar, while the jar the
driver actually loads is whatever sits at this URI inside the image. If the
image is older or newer than the server, the mismatch shows up only as a
`ClassNotFoundException` or an argument-parsing failure in the driver, with
nothing pointing at the real cause.
Is it worth logging the configured URI next to the server's resolved
jobs-jar path at executor startup, or documenting the version requirement where
#13618 documents the key? A validation is probably out of reach for a
`local://` URI, but a log line would make the failure diagnosable.
Verified by: reading the built-in template definitions under
maintenance/jobs/src/main and `BuiltInJob.resolveExecutable`
(maintenance/jobs/src/main/java/org/apache/gravitino/maintenance/jobs/BuiltInJob.java:34-47);
no code in this checkout compares the two.
##########
core/src/main/java/org/apache/gravitino/job/JobExecutorFactory.java:
##########
@@ -35,14 +35,29 @@
public class JobExecutorFactory {
+ /** The name of the built-in k8s job executor. */
+ public static final String K8S_JOB_EXECUTOR_NAME = "k8s";
+
+ /**
+ * The class name of the built-in k8s job executor. The job executor is a
plugin that depends on
+ * core, so core can only refer to its class by name. The plugin uses these
constants and checks
+ * that the name is the one of its class.
+ */
+ public static final String K8S_JOB_EXECUTOR_CLASS_NAME =
+ "org.apache.gravitino.job.k8s.K8sJobExecutor";
+
private static final String JOB_EXECUTOR_CONF_PREFIX =
"gravitino.jobExecutor.";
private static final String JOB_EXECUTOR_CLASS_SUFFIX = ".class";
+ private static final String K8S_JOB_EXECUTOR_JAR =
"gravitino-k8s-job-executor-<version>.jar";
+
private static final Map<String, String> BUILTIN_EXECUTORS =
ImmutableMap.of(
LocalJobExecutorConfigs.LOCAL_JOB_EXECUTOR_NAME,
- LocalJobExecutor.class.getCanonicalName());
+ LocalJobExecutor.class.getCanonicalName(),
+ K8S_JOB_EXECUTOR_NAME,
+ K8S_JOB_EXECUTOR_CLASS_NAME);
Review Comment:
[Nit] `k8s` becomes a reserved executor name, and a
`gravitino.jobExecutor.k8s.class` set by an operator is now ignored without a
word.
`create` checks `BUILTIN_EXECUTORS.containsKey(jobExecutorName)` first
(lines 68-77), so once `k8s` is in the map the `.class` key for that name is
never read. For anyone who configured the executor from #13613 by class name
this is harmless (same class), but someone running a subclass under the name
`k8s` would silently get the stock one.
Two docs now describe only `local` as built-in and still invite
`gravitino.jobExecutor.<name>.class` for anything else: the `JOB_EXECUTOR` doc
string at core/src/main/java/org/apache/gravitino/Configs.java:596-598 ("by
default it is 'local', user can implement their own executor and set it here")
and docs/development/custom-job-executor.md:59-68. Worth a sentence in both
that `local` and `k8s` are reserved, if #13618 does not already cover it.
Verified by: reading `JobExecutorFactory.create` lines 66-90 in this
checkout and the two doc locations above.
##########
plugins/k8s-job-executor/src/main/java/org/apache/gravitino/job/k8s/spark/SparkApplicationUtils.java:
##########
@@ -197,6 +198,17 @@ public static GenericKubernetesResource
buildSparkApplication(
return app;
}
+ private static String getExecutableUri(SparkJobTemplate template,
K8sJobExecutorConfigs configs) {
+ // The executable of a built-in job template is the path of the jobs jar
on the Gravitino
+ // server, which is what the local job executor runs. An executable that
is already reachable
+ // from the cluster is kept as it is.
+ if (template.name().startsWith(JobTemplateProvider.BUILTIN_NAME_PREFIX)
+ && !K8sJobResourceUtils.isClusterReachable(template.executable())) {
+ return configs.sparkBuiltinJobsJar();
Review Comment:
[Question] The substitution happens after the runtime job template has been
serialised, so what Gravitino records as the submitted template no longer
matches what ran.
`JobManager.runJob` builds `runtimeJobTemplateDTO` at
core/src/main/java/org/apache/gravitino/job/JobManager.java:534-538 and stores
it on the entity at line 584, with the comment at lines 530-532 saying it
exists so "callers can later see exactly what was submitted for execution, not
just the original template". That snapshot is taken before
`jobExecutor.submitJob(...)` at line 553, so for a built-in job on the k8s
executor it keeps the server-side path (for example
`/gravitino/auxlib/gravitino-jobs-<ver>.jar`) while the SparkApplication
actually carries `configs.sparkBuiltinJobsJar()`.
Anyone debugging a built-in run from the job API therefore sees a jar path
that the cluster never used. Not blocking, and the k8s-side substitution has to
stay here, but it would help to log the replacement once per submission
(`LOG.debug`/`LOG.info` with the template name, the original executable and the
substituted URI) so the mapping is recoverable from the server log.
Verified by: reading JobManager.java:520-590 and
SparkApplicationUtils.getExecutableUri in this checkout; confirmed the entity
field is written from the pre-submission JSON (`grep -n runtimeJobTemplateJson
JobManager.java` gives 536, 538, 584).
##########
plugins/k8s-job-executor/src/shadedJarTest/java/org/apache/gravitino/job/k8s/TestK8sJobExecutorShadedJar.java:
##########
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.job.k8s;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.io.ByteStreams;
+import com.sun.net.httpserver.HttpServer;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.Configs;
+import org.apache.gravitino.connector.job.JobContext;
+import org.apache.gravitino.connector.job.JobExecutor;
+import org.apache.gravitino.job.JobExecutorFactory;
+import org.apache.gravitino.job.SparkJobTemplate;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * Tests the shaded jar of the k8s job executor the way the Gravitino server
loads it: the jar is on
+ * the classpath of the server, next to the server's own Jackson, and neither
the classes nor the
+ * dependencies of the module are. The tests refer to the job executor by name
only.
+ */
+public class TestK8sJobExecutorShadedJar {
+
+ private static final String SHADED_PACKAGE =
"org.apache.gravitino.k8s.shaded.";
+
+ private static final String SPARK_APPLICATIONS_PATH =
+ "/apis/spark.apache.org/v1/namespaces/default/sparkapplications";
+
+ private static File shadedJar;
+
+ @BeforeAll
+ public static void setUp() throws IOException {
+ String path = System.getProperty("gravitino.k8s.shadedJar");
+ Assertions.assertNotNull(path, "Run the tests with the shadedJarTest
Gradle task");
+ shadedJar = new File(path).getCanonicalFile();
+ Assertions.assertTrue(shadedJar.isFile(), shadedJar + " doesn't exist");
+ }
+
+ @Test
+ public void testJacksonIsRelocated() throws Exception {
+ Assertions.assertEquals(
+ shadedJar,
getJarOf(Class.forName(JobExecutorFactory.K8S_JOB_EXECUTOR_CLASS_NAME)));
+ // fabric8 uses the Jackson of the shaded jar, the server keeps its own.
+ Assertions.assertEquals(
+ shadedJar, getJarOf(Class.forName(SHADED_PACKAGE +
ObjectMapper.class.getName())));
+ Assertions.assertNotEquals(shadedJar, getJarOf(ObjectMapper.class));
+
+ try (JarFile jar = new JarFile(shadedJar)) {
+ Set<String> notRelocated = new TreeSet<>();
+ for (JarEntry entry : Collections.list(jar.entries())) {
+ String name = entry.getName();
+ if (name.startsWith("com/fasterxml/")
+ || name.startsWith("org/yaml/")
+ || name.startsWith("org/snakeyaml/")) {
+ notRelocated.add(name);
+ }
+ }
+ Assertions.assertTrue(notRelocated.isEmpty(), "Not relocated: " +
notRelocated);
+ }
+ }
+
+ @Test
+ public void testNoClassOfServerClasspathIsBundled() throws IOException {
Review Comment:
[Nit] The overlap check uses the `:server` runtime classpath, which is
narrower than the `libs` directory the jar actually lands in.
`distribution/package/libs` also receives the tms plugin jar together with
its full runtime classpath (plugins/tms/build.gradle.kts:60-76 copies
`configurations.runtimeClasspath` into `build/libs` and then into the
distribution, bringing jersey, db-scheduler, mybatis and their transitives) and
the idp-basic jar (plugins/idp-basic/build.gradle.kts:70-78). None of those is
on `:server`'s runtime classpath, so a future clash with one of them would pass
this test and only show up in a real distribution.
Nothing today bundles fabric8 besides this module, so there is no live
conflict; this is only about where the test's safety net ends. A comment naming
the scope, or extending the classpath to the other `libs` contributors, would
keep the next reader from over-trusting it.
Verified by: `grep -rn "distribution/package/libs" --include=*.kts .`
(build.gradle.kts:1512, 1567; plugins/tms:74; plugins/k8s-job-executor:128;
plugins/idp-basic:78) and reading the three plugin build files.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]