You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@kyuubi.apache.org by GitBox <gi...@apache.org> on 2022/06/09 10:12:38 UTC

[GitHub] [incubator-kyuubi] pan3793 commented on a diff in pull request #2827: [BUILD][TEST] Decouple integration tests from kyuubi-server

pan3793 commented on code in PR #2827:
URL: https://github.com/apache/incubator-kyuubi/pull/2827#discussion_r893324859


##########
kyuubi-server/src/main/scala/org/apache/kyuubi/engine/ProcBuilder.scala:
##########
@@ -297,28 +297,36 @@ trait ProcBuilder {
    * @return SPARK_HOME, HIVE_HOME, etc.
    */
   protected def getEngineHome(shortName: String): String = {
+    val homeDirFilter: FilenameFilter = (dir: File, name: String) =>
+      dir.isDirectory && name.contains(s"$shortName-") && !name.contains("-engine")
+
     val homeKey = s"${shortName.toUpperCase}_HOME"
-    val homeVal = env.get(homeKey).orElse {
-      val cwd = Utils.getCodeSourceLocation(getClass).split("kyuubi-server")
-      assert(cwd.length > 1)
-      Option(
-        Paths.get(cwd.head)
-          .resolve("externals")
-          .resolve("kyuubi-download")
-          .resolve("target")
-          .toFile
-          .listFiles(new FilenameFilter {
-            override def accept(dir: File, name: String): Boolean = {
-              dir.isDirectory && name.contains(s"$shortName-")
-            }
-          }))
-        .flatMap(_.headOption)
-        .map(_.getAbsolutePath)
-    }
-    if (homeVal.isEmpty) {
-      throw validateEnv(homeKey)
-    } else {
-      homeVal.get
+    // 1. get from env, e.g. SPARK_HOME, FLINK_HOME
+    env.get(homeKey)
+      .orElse {
+        // 2. get from $KYUUBI_HOME/externals
+        env.get(KYUUBI_HOME).toSeq.flatMap { p =>
+          val candidates = Paths.get(p, "externals")
+            .toFile.listFiles(homeDirFilter)
+          Option(candidates).getOrElse(Array.empty).map(_.toPath).toSeq
+        }.find(Files.exists(_)).map(_.toAbsolutePath.toFile.getCanonicalPath)
+      }.orElse {
+        // 3. get from $KYUUBI_HOME/externals/kyuubi-download/target
+        env.get(KYUUBI_HOME).toSeq.flatMap { p =>
+          val candidates = Paths.get(p, "externals", "kyuubi-download", "target")
+            .toFile.listFiles(homeDirFilter)
+          Option(candidates).getOrElse(Array.empty).map(_.toPath).toSeq
+        }.find(Files.exists(_)).map(_.toAbsolutePath.toFile.getCanonicalPath)
+      }.orElse {
+        // 4. get from kyuubi-server/../externals/kyuubi-download/target
+        Utils.getCodeSourceLocation(getClass).split("kyuubi-server").toSeq.flatMap { cwd =>

Review Comment:
   We need to handle case 3 because if we run 
   ```
   mvn install -Dskiptests
   mvn test -pl integration-tests/kyuubi-hive-it
   ```
   the kyuubi-server:test-jar under `~/.m2/repositories/` will be picked rather than the one under `/target`



-- 
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: notifications-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org