Skip to content

Commit 24c53e0

Browse files
committed
YARN-9546. Add configuration option for YARN Native services AM classpath. Contributed by Gergely Pollak.
1 parent 0d1d7c8 commit 24c53e0

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/client/ServiceClient.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,11 +1234,15 @@ private String buildCommandLine(Service app, Configuration conf,
12341234
return cmdStr;
12351235
}
12361236

1237-
private Map<String, String> addAMEnv() throws IOException {
1237+
@VisibleForTesting
1238+
protected Map<String, String> addAMEnv() throws IOException {
12381239
Map<String, String> env = new HashMap<>();
1239-
ClasspathConstructor classpath =
1240-
buildClasspath(YarnServiceConstants.SUBMITTED_CONF_DIR, "lib", fs, getConfig()
1241-
.getBoolean(YarnConfiguration.IS_MINI_YARN_CLUSTER, false));
1240+
ClasspathConstructor classpath = buildClasspath(
1241+
YarnServiceConstants.SUBMITTED_CONF_DIR,
1242+
"lib",
1243+
fs,
1244+
getConfig().get(YarnServiceConf.YARN_SERVICE_CLASSPATH, ""),
1245+
getConfig().getBoolean(YarnConfiguration.IS_MINI_YARN_CLUSTER, false));
12421246
env.put("CLASSPATH", classpath.buildClasspath());
12431247
env.put("LANG", "en_US.UTF-8");
12441248
env.put("LC_ALL", "en_US.UTF-8");

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/conf/YarnServiceConf.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public class YarnServiceConf {
6060
public static final String ROLLING_LOG_INCLUSION_PATTERN = "yarn.service.rolling-log.include-pattern";
6161
public static final String ROLLING_LOG_EXCLUSION_PATTERN = "yarn.service.rolling-log.exclude-pattern";
6262

63+
public static final String YARN_SERVICE_CLASSPATH = "yarn.service.classpath";
64+
6365
public static final String YARN_SERVICES_SYSTEM_SERVICE_DIRECTORY =
6466
YARN_SERVICE_PREFIX + "system-service.dir";
6567

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/utils/ServiceUtils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,15 @@ public static Path createLocalPath(File file) {
451451
* @param sliderConfDir relative path to the dir containing slider config
452452
* options to put on the classpath -or null
453453
* @param libdir directory containing the JAR files
454+
* @param configClassPath extra class path configured in yarn-site.xml
454455
* @param usingMiniMRCluster flag to indicate the MiniMR cluster is in use
455456
* (and hence the current classpath should be used, not anything built up)
456457
* @return a classpath
457458
*/
458459
public static ClasspathConstructor buildClasspath(String sliderConfDir,
459460
String libdir,
460461
SliderFileSystem sliderFileSystem,
462+
String configClassPath,
461463
boolean usingMiniMRCluster) {
462464

463465
ClasspathConstructor classpath = new ClasspathConstructor();
@@ -479,6 +481,11 @@ public static ClasspathConstructor buildClasspath(String sliderConfDir,
479481
classpath.addRemoteClasspathEnvVar();
480482
classpath.append(ApplicationConstants.Environment.HADOOP_CONF_DIR.$$());
481483
}
484+
485+
if (!configClassPath.isEmpty()) {
486+
classpath.appendAll(Arrays.asList(configClassPath.split(",")));
487+
}
488+
482489
return classpath;
483490
}
484491

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceClient.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,29 @@ public class TestServiceClient {
7676
public ServiceTestUtils.ServiceFSWatcher rule =
7777
new ServiceTestUtils.ServiceFSWatcher();
7878

79+
@Test
80+
public void testAMEnvCustomClasspath() throws Exception {
81+
Service service = createService();
82+
service.getComponents().forEach(comp ->
83+
comp.setRestartPolicy(Component.RestartPolicyEnum.NEVER));
84+
ServiceClient client = MockServiceClient.create(rule, service, true);
85+
//saving the original value of the param, for restoration purposes
86+
String oldParam = client.getConfig().get("yarn.service.classpath", "");
87+
String originalPath = client.addAMEnv().get("CLASSPATH");
88+
89+
client.getConfig().set("yarn.service.classpath", "{{VAR_1}},{{VAR_2}}");
90+
String newPath = client.addAMEnv().get("CLASSPATH");
91+
92+
Assert.assertEquals(originalPath + "<CPS>{{VAR_1}}<CPS>{{VAR_2}}", newPath);
93+
//restoring the original value for service classpath
94+
client.getConfig().set("yarn.service.classpath", oldParam);
95+
96+
newPath = client.addAMEnv().get("CLASSPATH");
97+
Assert.assertEquals(originalPath, newPath);
98+
99+
client.stop();
100+
}
101+
79102
@Test
80103
public void testUpgradeDisabledByDefault() throws Exception {
81104
Service service = createService();

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4211,4 +4211,14 @@
42114211
<name>yarn.resourcemanager.activities-manager.app-activities.max-queue-length</name>
42124212
<value>1000</value>
42134213
</property>
4214+
4215+
<property>
4216+
<description>
4217+
Comma separated extra class path parameters for yarn services AM.
4218+
These path elements will be appended to the end of the YARN service AM
4219+
classpath.
4220+
</description>
4221+
<name>yarn.service.classpath</name>
4222+
<value></value>
4223+
</property>
42144224
</configuration>

0 commit comments

Comments
 (0)