marblejenka commented on a change in pull request #28200:
URL: https://github.com/apache/spark/pull/28200#discussion_r413724703
##########
File path:
launcher/src/main/java/org/apache/spark/launcher/CommandBuilderUtils.java
##########
@@ -314,18 +319,31 @@ static int javaMajorVersion(String javaVersion) {
* or a distribution directory.
*/
static String findJarsDir(String sparkHome, String scalaVersion, boolean
failIfNotFound) {
+ String envSparkJarsDir = System.getenv(ENV_SPARK_JARS_DIR);
+ if (envSparkJarsDir != null && !envSparkJarsDir.isEmpty()) {
+ File envJarsDir = new File(envSparkJarsDir);
+ return handleJarsDir(envJarsDir, failIfNotFound,
Review comment:
I will fix it. Thank you.
##########
File path:
launcher/src/test/java/org/apache/spark/launcher/CommandBuilderUtilsSuite.java
##########
@@ -99,6 +111,56 @@ public void testJavaMajorVersion() {
assertEquals(10, javaMajorVersion("10"));
}
+ @Test
+ public void testFindJarsDir() throws IOException {
+ String tmpRoot = tempFolder.getRoot().toString();
+ String sparkHome = tempFolder.newFolder("spark", "home").getAbsolutePath();
+
+ // if SPARK_HOME/jars is missing and there is no dir to fallback, throws
IllegalStateException
+ try {
+ findJarsDir(sparkHome, "2.13", true);
+ } catch (IllegalStateException e) {
+ assertEquals(
+ "Library directory '" + sparkHome +
+ "/assembly/target/scala-2.13/jars' does not exist; make sure Spark is
built.",
+ e.getMessage());
+ }
+
+ // but if failIfNotFound is false, return null without exception
+ assertEquals(null, findJarsDir(sparkHome, "2.13", false));
+
+ // if we have built jars dir, use it as jars dir
+ tempFolder.newFolder("spark", "home", "assembly", "target", "scala-2.13",
"jars");
+ assertEquals(join(File.separator, tmpRoot, "spark", "home", "assembly",
"target",
+ "scala-2.13", "jars"), findJarsDir(sparkHome, "2.13", true));
+
+ // if we have SPARK_HOME/jars, use it as jars dir
+ tempFolder.newFolder("spark", "home", "jars");
+ assertEquals(
+ join(File.separator, tmpRoot, "spark", "home", "jars"),
+ findJarsDir(sparkHome, "2.13", true));
+
+ // if we have SPARK_JARS_DIR, use it as jars dir
+ File spefifiedJarsDir = tempFolder.newFolder("jars-dir");
+ environmentVariables.set("SPARK_JARS_DIR",
spefifiedJarsDir.getAbsolutePath());
Review comment:
I will fix it. Thank you.
##########
File path:
launcher/src/test/java/org/apache/spark/launcher/CommandBuilderUtilsSuite.java
##########
@@ -99,6 +111,56 @@ public void testJavaMajorVersion() {
assertEquals(10, javaMajorVersion("10"));
}
+ @Test
+ public void testFindJarsDir() throws IOException {
+ String tmpRoot = tempFolder.getRoot().toString();
+ String sparkHome = tempFolder.newFolder("spark", "home").getAbsolutePath();
+
+ // if SPARK_HOME/jars is missing and there is no dir to fallback, throws
IllegalStateException
+ try {
+ findJarsDir(sparkHome, "2.13", true);
+ } catch (IllegalStateException e) {
+ assertEquals(
+ "Library directory '" + sparkHome +
+ "/assembly/target/scala-2.13/jars' does not exist; make sure Spark is
built.",
+ e.getMessage());
+ }
+
+ // but if failIfNotFound is false, return null without exception
+ assertEquals(null, findJarsDir(sparkHome, "2.13", false));
+
+ // if we have built jars dir, use it as jars dir
+ tempFolder.newFolder("spark", "home", "assembly", "target", "scala-2.13",
"jars");
+ assertEquals(join(File.separator, tmpRoot, "spark", "home", "assembly",
"target",
+ "scala-2.13", "jars"), findJarsDir(sparkHome, "2.13", true));
+
+ // if we have SPARK_HOME/jars, use it as jars dir
+ tempFolder.newFolder("spark", "home", "jars");
+ assertEquals(
+ join(File.separator, tmpRoot, "spark", "home", "jars"),
+ findJarsDir(sparkHome, "2.13", true));
+
+ // if we have SPARK_JARS_DIR, use it as jars dir
+ File spefifiedJarsDir = tempFolder.newFolder("jars-dir");
+ environmentVariables.set("SPARK_JARS_DIR",
spefifiedJarsDir.getAbsolutePath());
+ assertEquals(join(File.separator, tmpRoot, "jars-dir"),
+ findJarsDir(sparkHome, "2.13", true));
+
+ // if SPARK_JARS_DIR is specified but not exists, throws
IllegalStateException
+ environmentVariables.set("SPARK_JARS_DIR", join(File.separator, tmpRoot,
"jars-dir-not-exists"));
Review comment:
I will fix it. Thank you.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]