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


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



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



##########
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:
   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