Skip to content

Commit

Permalink
MAPREDUCE-7456. Extend add-opens flag to container launch commands on…
Browse files Browse the repository at this point in the history
… JDK17 nodes. Contributed by Peter Szucs
  • Loading branch information
szilard-nemeth committed Sep 28, 2023
1 parent 0c153fe commit 2d871fa
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2232,6 +2232,14 @@ public static boolean isAclEnabled(Configuration conf) {
public static final String NM_CONTAINER_LOCALIZER_JAVA_OPTS_DEFAULT =
"-Xmx256m";

/*
* Flag to indicate whether JDK17's required add-exports flags should be added to
* container localizers regardless of the user specified JAVA_OPTS.
*/
public static final String NM_CONTAINER_LOCALIZER_JAVA_OPTS_ADD_EXPORTS_KEY =
NM_PREFIX + "container-localizer.java.opts.add-exports-as-default";
public static final boolean NM_CONTAINER_LOCALIZER_JAVA_OPTS_ADD_EXPORTS_DEFAULT = true;

/** The log level of container localizer process. */
public static final String NM_CONTAINER_LOCALIZER_LOG_LEVEL=
NM_PREFIX + "container-localizer.log.level";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,17 @@
<value>-Xmx256m</value>
</property>

<property>
<name>yarn.nodemanager.container-localizer.java.opts.add-exports-as-default</name>
<value>true</value>
<description>Since on JDK17 it is no longer possible to use the reflection API to
access public fields and methods, add-exports flags should be added to container
localizers regardless of the user specified JAVA_OPTS. Setting this to true will
add the flags to the container localizer on nodes with JDK17 or higher.
Defaults to true, but the setting has no effect on nodes using JDK16 and before.
</description>
</property>

<property>
<description>
The log level for container localizer while it is an independent process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ public class ContainerLaunch implements Callable<Integer> {
private static final String PID_FILE_NAME_FMT = "%s.pid";
static final String EXIT_CODE_FILE_SUFFIX = ".exitcode";

private static final String ADDITIONAL_JDK17_PLUS_OPTIONS =
"--add-opens=java.base/java.lang=ALL-UNNAMED " +
"--add-exports=java.base/sun.net.dns=ALL-UNNAMED " +
"--add-exports=java.base/sun.net.util=ALL-UNNAMED";

protected final Dispatcher dispatcher;
protected final ContainerExecutor exec;
protected final Application app;
Expand Down Expand Up @@ -171,8 +176,7 @@ public static String expandEnvironment(String var,
File.pathSeparator);

if (Shell.isJavaVersionAtLeast(17)) {
var = var.replace(ApplicationConstants.JVM_ADD_OPENS_VAR,
"--add-opens=java.base/java.lang=ALL-UNNAMED");
var = var.replace(ApplicationConstants.JVM_ADD_OPENS_VAR, ADDITIONAL_JDK17_PLUS_OPTIONS);
} else {
var = var.replace(ApplicationConstants.JVM_ADD_OPENS_VAR, "");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ public class ContainerLocalizer {
new FsPermission((short) 0755);
public static final String CSI_VOLIUME_MOUNTS_ROOT = "csivolumes";

/*
* Testing discovered that these Java options are needed for Spark service
* running on JDK17 and Isilon clusters.
*/
private static final String ADDITIONAL_JDK17_PLUS_OPTIONS =
"--add-exports=java.base/sun.net.dns=ALL-UNNAMED " +
"--add-exports=java.base/sun.net.util=ALL-UNNAMED";

private final String user;
private final String appId;
private final List<Path> localDirs;
Expand Down Expand Up @@ -400,6 +408,13 @@ private LocalizerStatus createStatus() throws InterruptedException {
public static List<String> getJavaOpts(Configuration conf) {
String opts = conf.get(YarnConfiguration.NM_CONTAINER_LOCALIZER_JAVA_OPTS_KEY,
YarnConfiguration.NM_CONTAINER_LOCALIZER_JAVA_OPTS_DEFAULT);
boolean isExtraJDK17OptionsConfigured =
conf.getBoolean(YarnConfiguration.NM_CONTAINER_LOCALIZER_JAVA_OPTS_ADD_EXPORTS_KEY,
YarnConfiguration.NM_CONTAINER_LOCALIZER_JAVA_OPTS_ADD_EXPORTS_DEFAULT);

if (Shell.isJavaVersionAtLeast(17) && isExtraJDK17OptionsConfigured) {
opts = opts.trim().concat(" " + ADDITIONAL_JDK17_PLUS_OPTIONS);
}
return Arrays.asList(opts.split(" "));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,12 @@ public void testEnvExpansion() throws IOException {

String res = ContainerLaunch.expandEnvironment(input, logPath);

String expectedAddOpens = Shell.isJavaVersionAtLeast(17) ?
"--add-opens=java.base/java.lang=ALL-UNNAMED" : "";
String additionalJdk17PlusOptions =
"--add-opens=java.base/java.lang=ALL-UNNAMED " +
"--add-exports=java.base/sun.net.dns=ALL-UNNAMED " +
"--add-exports=java.base/sun.net.util=ALL-UNNAMED";
String expectedAddOpens = Shell.isJavaVersionAtLeast(17) ? additionalJdk17PlusOptions : "";

if (Shell.WINDOWS) {
Assert.assertEquals("%HADOOP_HOME%/share/hadoop/common/*;"
+ "%HADOOP_HOME%/share/hadoop/common/lib/*;"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,4 +702,39 @@ public void testUserCacheDirPermission() throws Exception {
lfs.getFileStatus(destDirPath.getParent().getParent()).getPermission());
}

@Test
public void testDefaultJavaOptionsWhenExtraJDK17OptionsAreConfigured() throws Exception {
ContainerLocalizerWrapper wrapper = new ContainerLocalizerWrapper();
ContainerLocalizer localizer = wrapper.setupContainerLocalizerForTest();

Configuration conf = new Configuration();
conf.setBoolean(YarnConfiguration.NM_CONTAINER_LOCALIZER_JAVA_OPTS_ADD_EXPORTS_KEY,
true);

List<String> javaOpts = localizer.getJavaOpts(conf);

if (Shell.isJavaVersionAtLeast(17)) {
Assert.assertTrue(javaOpts.contains("--add-exports=java.base/sun.net.dns=ALL-UNNAMED"));
Assert.assertTrue(javaOpts.contains("--add-exports=java.base/sun.net.util=ALL-UNNAMED"));
}
Assert.assertTrue(javaOpts.contains("-Xmx256m"));
}

@Test
public void testDefaultJavaOptionsWhenExtraJDK17OptionsAreNotConfigured() throws Exception {
ContainerLocalizerWrapper wrapper = new ContainerLocalizerWrapper();
ContainerLocalizer localizer = wrapper.setupContainerLocalizerForTest();

Configuration conf = new Configuration();
conf.setBoolean(YarnConfiguration.NM_CONTAINER_LOCALIZER_JAVA_OPTS_ADD_EXPORTS_KEY,
false);

List<String> javaOpts = localizer.getJavaOpts(conf);

if (Shell.isJavaVersionAtLeast(17)) {
Assert.assertFalse(javaOpts.contains("--add-exports=java.base/sun.net.dns=ALL-UNNAMED"));
Assert.assertFalse(javaOpts.contains("--add-exports=java.base/sun.net.util=ALL-UNNAMED"));
}
Assert.assertTrue(javaOpts.contains("-Xmx256m"));
}
}

0 comments on commit 2d871fa

Please sign in to comment.