Open Java modules for Snowflake setup (#9664)

# Important Notes
Some workarounds are being considered but we need this change sooner than later.
This commit is contained in:
Hubert Plociniczak 2024-04-16 23:01:32 +02:00 committed by GitHub
parent fda41cbfd1
commit d6f7afc624
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 66 additions and 25 deletions

View File

@ -7,6 +7,6 @@ for opt in "$@"; do
fi fi
done done
JAVA_OPTS="--add-opens=java.base/java.nio=ALL-UNNAMED $JAVA_OPTS"
exec java --module-path $COMP_PATH -Dorg.graalvm.language.enso.home=$COMP_PATH $EXTRA_OPTS $JAVA_OPTS -m org.enso.runtime/org.enso.EngineRunnerBootLoader "$@" exec java --module-path $COMP_PATH -Dorg.graalvm.language.enso.home=$COMP_PATH $EXTRA_OPTS $JAVA_OPTS -m org.enso.runtime/org.enso.EngineRunnerBootLoader "$@"
exit exit

View File

@ -6,5 +6,6 @@ if /I %%A==--dump-graphs (
set EXTRA_OPTS=%EXTRA_OPTS% -Dgraal.Dump=Truffle:1 set EXTRA_OPTS=%EXTRA_OPTS% -Dgraal.Dump=Truffle:1
) )
) )
set JAVA_OPTS=%JAVA_OPTS% --add-opens=java.base/java.nio=ALL-UNNAMED
java --module-path %comp-dir% -Dorg.graalvm.language.enso.home=%comp-dir% -Dpolyglot.compiler.IterativePartialEscape=true %EXTRA_OPTS% %JAVA_OPTS% -m org.enso.runtime/org.enso.EngineRunnerBootLoader %* java --module-path %comp-dir% -Dorg.graalvm.language.enso.home=%comp-dir% -Dpolyglot.compiler.IterativePartialEscape=true %EXTRA_OPTS% %JAVA_OPTS% -m org.enso.runtime/org.enso.EngineRunnerBootLoader %*
exit /B %errorlevel% exit /B %errorlevel%

View File

@ -45,8 +45,10 @@ type Snowflake_Details
Provides the properties for the connection. Provides the properties for the connection.
jdbc_properties : Vector (Pair Text Text) jdbc_properties : Vector (Pair Text Text)
jdbc_properties self = jdbc_properties self =
## Avoid the Arrow dependency (https://community.snowflake.com/s/article/SAP-BW-Java-lang-NoClassDefFoundError-for-Apache-arrow) ## If Arrow dependency is to be avoided (https://community.snowflake.com/s/article/SAP-BW-Java-lang-NoClassDefFoundError-for-Apache-arrow)
no_arrow = [Pair.new 'jdbc_query_result_format' 'json'] ## [Pair.new 'jdbc_query_result_format' 'json']
## should be prepended to properties. That would make it fallback to plain `json`.
account = [Pair.new 'account' self.account] account = [Pair.new 'account' self.account]
credentials = [Pair.new 'user' self.credentials.username, Pair.new 'password' self.credentials.password] credentials = [Pair.new 'user' self.credentials.username, Pair.new 'password' self.credentials.password]
database = [Pair.new 'db' self.database] database = [Pair.new 'db' self.database]
@ -55,4 +57,4 @@ type Snowflake_Details
## Control the format of TIMESTAMP and TIME fields ## Control the format of TIMESTAMP and TIME fields
formats = [Pair.new "TIME_OUTPUT_FORMAT" "HH24:MI:SS.FF9", Pair.new "TIMESTAMP_OUTPUT_FORMAT" "YYYY-MM-DD HH24:MI:SS.FF9 TZHTZM", Pair.new "TIMESTAMP_NTZ_OUTPUT_FORMAT" "YYYY-MM-DD HH24:MI:SS.FF9", Pair.new "TIMESTAMP_LTZ_OUTPUT_FORMAT" "YYYY-MM-DD HH24:MI:SS.FF9"] formats = [Pair.new "TIME_OUTPUT_FORMAT" "HH24:MI:SS.FF9", Pair.new "TIMESTAMP_OUTPUT_FORMAT" "YYYY-MM-DD HH24:MI:SS.FF9 TZHTZM", Pair.new "TIMESTAMP_NTZ_OUTPUT_FORMAT" "YYYY-MM-DD HH24:MI:SS.FF9", Pair.new "TIMESTAMP_LTZ_OUTPUT_FORMAT" "YYYY-MM-DD HH24:MI:SS.FF9"]
no_arrow + account + credentials + database + schema + warehouse + formats account + credentials + database + schema + warehouse + formats

View File

@ -96,7 +96,7 @@ case class Launcher(cliOptions: GlobalCLIOptions) {
additionalArguments = additionalArguments additionalArguments = additionalArguments
) )
.get, .get,
JVMSettings(useSystemJVM, jvmOpts) JVMSettings(useSystemJVM, jvmOpts, extraOptions = Seq.empty)
) { command => ) { command =>
command.run().get command.run().get
} }
@ -223,7 +223,7 @@ case class Launcher(cliOptions: GlobalCLIOptions) {
additionalArguments additionalArguments
) )
.get, .get,
JVMSettings(useSystemJVM, jvmOpts) JVMSettings(useSystemJVM, jvmOpts, extraOptions = Seq())
) { command => ) { command =>
command.run().get command.run().get
} }
@ -267,7 +267,7 @@ case class Launcher(cliOptions: GlobalCLIOptions) {
additionalArguments additionalArguments
) )
.get, .get,
JVMSettings(useSystemJVM, jvmOpts) JVMSettings(useSystemJVM, jvmOpts, extraOptions = Seq())
) { command => ) { command =>
command.run().get command.run().get
} }
@ -310,7 +310,7 @@ case class Launcher(cliOptions: GlobalCLIOptions) {
additionalArguments additionalArguments
) )
.get, .get,
JVMSettings(useSystemJVM, jvmOpts) JVMSettings(useSystemJVM, jvmOpts, Seq())
) { command => ) { command =>
command.run().get command.run().get
} }
@ -346,7 +346,7 @@ case class Launcher(cliOptions: GlobalCLIOptions) {
additionalArguments = additionalArguments additionalArguments = additionalArguments
) )
.get, .get,
JVMSettings(useSystemJVM, jvmOpts) JVMSettings(useSystemJVM, jvmOpts, extraOptions = Seq())
) { command => ) { command =>
command.run().get command.run().get
} }
@ -413,8 +413,11 @@ case class Launcher(cliOptions: GlobalCLIOptions) {
) )
.get .get
runner.withCommand(settings, JVMSettings(useSystemJVM, jvmOpts)) { runner.withCommand(
command => command.run().get settings,
JVMSettings(useSystemJVM, jvmOpts, extraOptions = Seq())
) { command =>
command.run().get
} }
} }
@ -530,7 +533,11 @@ case class Launcher(cliOptions: GlobalCLIOptions) {
val runtimeVersionString = if (isEngineInstalled) { val runtimeVersionString = if (isEngineInstalled) {
val output = runner.withCommand( val output = runner.withCommand(
runtimeVersionRunSettings, runtimeVersionRunSettings,
JVMSettings(useSystemJVM = false, jvmOptions = Seq.empty) JVMSettings(
useSystemJVM = false,
jvmOptions = Seq(),
extraOptions = Seq()
)
) { runtimeVersionCommand => ) { runtimeVersionCommand =>
runtimeVersionCommand.captureOutput().get runtimeVersionCommand.captureOutput().get
} }

View File

@ -92,7 +92,11 @@ class LauncherRunnerSpec extends RuntimeVersionManagerTest with FlakySpec {
runner.withCommand( runner.withCommand(
runSettings, runSettings,
JVMSettings(useSystemJVM = true, jvmOptions = jvmOptions) JVMSettings(
useSystemJVM = true,
jvmOptions = jvmOptions,
extraOptions = Seq()
)
) { systemCommand => ) { systemCommand =>
systemCommand.command.head shouldEqual "java" systemCommand.command.head shouldEqual "java"
checkCommandLine(systemCommand) checkCommandLine(systemCommand)
@ -100,7 +104,11 @@ class LauncherRunnerSpec extends RuntimeVersionManagerTest with FlakySpec {
runner.withCommand( runner.withCommand(
runSettings, runSettings,
JVMSettings(useSystemJVM = false, jvmOptions = jvmOptions) JVMSettings(
useSystemJVM = false,
jvmOptions = jvmOptions,
extraOptions = Seq()
)
) { managedCommand => ) { managedCommand =>
managedCommand.command.head should include("java") managedCommand.command.head should include("java")
val javaHome = val javaHome =

View File

@ -100,7 +100,8 @@ class TestDistributionConfiguration(
val javaCommand = JavaCommand(currentProcess, None) val javaCommand = JavaCommand(currentProcess, None)
new JVMSettings( new JVMSettings(
javaCommandOverride = Some(javaCommand), javaCommandOverride = Some(javaCommand),
jvmOptions = Seq() jvmOptions = Seq(),
extraOptions = Seq()
) )
} }

View File

@ -17,7 +17,8 @@ class ProjectCreateHandleMissingRuntimeSpec
) { ) {
override def defaultJVMSettings: JVMSettings = JVMSettings( override def defaultJVMSettings: JVMSettings = JVMSettings(
javaCommandOverride = None, javaCommandOverride = None,
jvmOptions = Seq() jvmOptions = Seq(),
extraOptions = Seq()
) )
} }

View File

@ -6,11 +6,13 @@ package org.enso.runtimeversionmanager.runner
* instead of the default JVM provided with the * instead of the default JVM provided with the
* release; it can be an absolute path to a java * release; it can be an absolute path to a java
* executable * executable
* @param jvmOptions options that should be added to the launched JVM * @param jvmOptions options that should be added to the launched JVM, will be prefixed with `-D`
* @param extraOptions extra options that should be added to the launched JVM
*/ */
case class JVMSettings( case class JVMSettings(
javaCommandOverride: Option[JavaCommand], javaCommandOverride: Option[JavaCommand],
jvmOptions: Seq[(String, String)] jvmOptions: Seq[(String, String)],
extraOptions: Seq[(String, String)]
) )
object JVMSettings { object JVMSettings {
@ -19,20 +21,31 @@ object JVMSettings {
* *
* @param useSystemJVM if set, the system configured JVM is used instead of * @param useSystemJVM if set, the system configured JVM is used instead of
* the one managed by the launcher * the one managed by the launcher
* @param jvmOptions options that should be added to the launched JVM * @param jvmOptions options that should be added to the launched JVM, will be prefixed with `-D`
* @param extraOptions extra options that should be added to the launched JVM
*/ */
def apply( def apply(
useSystemJVM: Boolean, useSystemJVM: Boolean,
jvmOptions: Seq[(String, String)] jvmOptions: Seq[(String, String)],
extraOptions: Seq[(String, String)]
): JVMSettings = ): JVMSettings =
new JVMSettings( new JVMSettings(
if (useSystemJVM) Some(JavaCommand.systemJavaCommand) else None, if (useSystemJVM) Some(JavaCommand.systemJavaCommand) else None,
jvmOptions jvmOptions,
extraOptions
) )
// See propositions in #9475 for alternatives
private val nioOpen: (String, String) =
("add-opens", "java.base/java.nio=ALL-UNNAMED")
/** Creates a default instance of [[JVMSettings]] that just use the default /** Creates a default instance of [[JVMSettings]] that just use the default
* JVM with no options overrides. * JVM with no options overrides.
*/ */
def default: JVMSettings = def default: JVMSettings =
JVMSettings(useSystemJVM = false, jvmOptions = Seq()) JVMSettings(
useSystemJVM = false,
jvmOptions = Seq(),
extraOptions = Seq(nioOpen)
)
} }

View File

@ -168,10 +168,13 @@ class Runner(
) )
} }
def translateJVMOption(option: (String, String)): String = { def translateJVMOption(
option: (String, String),
standardOption: Boolean
): String = {
val name = option._1 val name = option._1
val value = option._2 val value = option._2
s"-D$name=$value" if (standardOption) s"-D$name=$value" else s"--$name=$value"
} }
val context = JVMOptionsContext(enginePackagePath = engine.path) val context = JVMOptionsContext(enginePackagePath = engine.path)
@ -180,7 +183,12 @@ class Runner(
engine.defaultJVMOptions.filter(_.isRelevant).map(_.substitute(context)) engine.defaultJVMOptions.filter(_.isRelevant).map(_.substitute(context))
val environmentOptions = val environmentOptions =
jvmOptsFromEnvironment.map(_.split(' ').toIndexedSeq).getOrElse(Seq()) jvmOptsFromEnvironment.map(_.split(' ').toIndexedSeq).getOrElse(Seq())
val commandLineOptions = jvmSettings.jvmOptions.map(translateJVMOption) val commandLineOptions = jvmSettings.jvmOptions.map(
translateJVMOption(_, standardOption = true)
) ++
jvmSettings.extraOptions.map(
translateJVMOption(_, standardOption = false)
)
val shouldInvokeViaModulePath = engine.graalRuntimeVersion.isUnchained val shouldInvokeViaModulePath = engine.graalRuntimeVersion.isUnchained
var jvmArguments = var jvmArguments =