jerryshao commented on code in PR #13892:
URL: https://github.com/apache/gravitino/pull/13892#discussion_r4294563951


##########
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:
   Addressed in bcf2057fd: `SparkApplicationUtils` now logs at INFO, once per 
submission, the job id, the built-in template name, the jar that runs 
(`spark.builtinJobsJar`) and the executable it replaces. The recorded runtime 
template stays the template as submitted to the executor, as you noted.



##########
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:
   Addressed in bcf2057fd: the executor logs the configured 
`spark.builtinJobsJar` at startup, and each built-in submission logs that URI 
next to the server-side jar path it replaces, so a skew can be traced from the 
server log. A check isn't possible for a `local://` URI; the requirement that 
the jar matches the server version will be documented with the key in #13618.



##########
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:
   Addressed in bcf2057fd: `JobExecutorFactory` now warns when 
`gravitino.jobExecutor.<name>.class` is set to another class for a built-in 
name, and a test checks the built-in class is used. The 
`gravitino.job.executor` doc string, `docs/gravitino-server-config.md` and 
`docs/development/custom-job-executor.md` now say that `local` and `k8s` are 
reserved.



##########
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:
   Addressed in bcf2057fd with a comment naming the scope: the check covers the 
runtime classpath of `:server`, not the jars of the other plugins (idp-basic, 
tms and its dependencies) that also land in `libs`. I kept the test off the 
other plugin modules so it doesn't depend on them.



##########
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:
   Duplicate of the thread above, addressed in bcf2057fd.



-- 
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]

Reply via email to