Skip to content

Commit c7e71a6

Browse files
Prabhu JosephPrabhu Joseph
authored andcommitted
YARN-10361. Make custom DAO classes configurable into RMWebApp#JAXBContextResolver.
Contributed by Bilwa ST.
1 parent dc5470a commit c7e71a6

File tree

3 files changed

+78
-6
lines changed

3 files changed

+78
-6
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2398,7 +2398,13 @@ public static boolean isAclEnabled(Configuration conf) {
23982398
"yarn.http.rmwebapp.external.classes";
23992399

24002400
public static final String YARN_HTTP_WEBAPP_SCHEDULER_PAGE =
2401-
"hadoop.http.rmwebapp.scheduler.page.class";
2401+
"yarn.http.rmwebapp.scheduler.page.class";
2402+
2403+
public static final String YARN_HTTP_WEBAPP_CUSTOM_DAO_CLASSES =
2404+
"yarn.http.rmwebapp.custom.dao.classes";
2405+
2406+
public static final String YARN_HTTP_WEBAPP_CUSTOM_UNWRAPPED_DAO_CLASSES =
2407+
"yarn.http.rmwebapp.custom.unwrapped.dao.classes";
24022408

24032409
/**
24042410
* Whether or not users are allowed to request that Docker containers honor

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3355,10 +3355,26 @@
33553355
<description>
33563356
Used to specify custom scheduler page
33573357
</description>
3358-
<name>hadoop.http.rmwebapp.scheduler.page.class</name>
3358+
<name>yarn.http.rmwebapp.scheduler.page.class</name>
33593359
<value></value>
33603360
</property>
33613361

3362+
<property>
3363+
<description>
3364+
Used to specify custom DAO classes used by custom web services.
3365+
</description>
3366+
<name>yarn.http.rmwebapp.custom.dao.classes</name>
3367+
<value></value>
3368+
</property>
3369+
3370+
<property>
3371+
<description>
3372+
Used to specify custom DAO classes used by custom web services which requires
3373+
root unwrapping.
3374+
</description>
3375+
<name>yarn.http.rmwebapp.custom.unwrapped.dao.classes</name>
3376+
<value></value>
3377+
</property>
33623378

33633379
<property>
33643380
<description>The Node Label script to run. Script output Line starting with

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/JAXBContextResolver.java

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package org.apache.hadoop.yarn.server.resourcemanager.webapp;
2020

21+
import com.google.inject.Inject;
2122
import com.google.inject.Singleton;
2223
import com.sun.jersey.api.json.JSONConfiguration;
2324
import com.sun.jersey.api.json.JSONJAXBContext;
@@ -28,6 +29,10 @@
2829
import javax.ws.rs.ext.Provider;
2930
import javax.xml.bind.JAXBContext;
3031

32+
import org.apache.commons.logging.Log;
33+
import org.apache.commons.logging.LogFactory;
34+
import org.apache.hadoop.conf.Configuration;
35+
import org.apache.hadoop.yarn.conf.YarnConfiguration;
3136
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.UserInfo;
3237
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.*;
3338
import org.apache.hadoop.yarn.webapp.RemoteExceptionData;
@@ -36,9 +41,17 @@
3641
@Provider
3742
public class JAXBContextResolver implements ContextResolver<JAXBContext> {
3843

44+
private static final Log LOG =
45+
LogFactory.getLog(JAXBContextResolver.class.getName());
46+
3947
private final Map<Class, JAXBContext> typesContextMap;
4048

4149
public JAXBContextResolver() throws Exception {
50+
this(new Configuration());
51+
}
52+
53+
@Inject
54+
public JAXBContextResolver(Configuration conf) throws Exception {
4255

4356
JAXBContext context;
4457
JAXBContext unWrappedRootContext;
@@ -66,17 +79,54 @@ public JAXBContextResolver() throws Exception {
6679
DelegationToken.class, AppQueue.class, AppPriority.class,
6780
ResourceOptionInfo.class };
6881

82+
ArrayList<Class> finalcTypesList = new ArrayList<>();
83+
ArrayList<Class> finalRootUnwrappedTypesList = new ArrayList<>();
84+
85+
Collections.addAll(finalcTypesList, cTypes);
86+
Collections.addAll(finalRootUnwrappedTypesList, rootUnwrappedTypes);
87+
88+
// Add Custom DAO Classes
89+
Class[] daoClasses = null;
90+
Class[] unwrappedDaoClasses = null;
91+
boolean loadCustom = true;
92+
try {
93+
daoClasses = conf
94+
.getClasses(YarnConfiguration.YARN_HTTP_WEBAPP_CUSTOM_DAO_CLASSES);
95+
unwrappedDaoClasses = conf.getClasses(
96+
YarnConfiguration.YARN_HTTP_WEBAPP_CUSTOM_UNWRAPPED_DAO_CLASSES);
97+
} catch (Exception e) {
98+
LOG.warn("Failed to load custom dao class: " + e);
99+
loadCustom = false;
100+
}
101+
102+
if (loadCustom) {
103+
if (daoClasses != null) {
104+
Collections.addAll(finalcTypesList, daoClasses);
105+
LOG.debug("Added custom dao classes: " + Arrays.toString(daoClasses));
106+
}
107+
if (unwrappedDaoClasses != null) {
108+
Collections.addAll(finalRootUnwrappedTypesList, unwrappedDaoClasses);
109+
LOG.debug("Added custom Unwrapped dao classes: "
110+
+ Arrays.toString(unwrappedDaoClasses));
111+
}
112+
}
113+
114+
final Class[] finalcTypes = finalcTypesList
115+
.toArray(new Class[finalcTypesList.size()]);
116+
final Class[] finalRootUnwrappedTypes = finalRootUnwrappedTypesList
117+
.toArray(new Class[finalRootUnwrappedTypesList.size()]);
118+
69119
this.typesContextMap = new HashMap<Class, JAXBContext>();
70120
context =
71121
new JSONJAXBContext(JSONConfiguration.natural().rootUnwrapping(false)
72-
.build(), cTypes);
122+
.build(), finalcTypes);
73123
unWrappedRootContext =
74124
new JSONJAXBContext(JSONConfiguration.natural().rootUnwrapping(true)
75-
.build(), rootUnwrappedTypes);
76-
for (Class type : cTypes) {
125+
.build(), finalRootUnwrappedTypes);
126+
for (Class type : finalcTypes) {
77127
typesContextMap.put(type, context);
78128
}
79-
for (Class type : rootUnwrappedTypes) {
129+
for (Class type : finalRootUnwrappedTypes) {
80130
typesContextMap.put(type, unWrappedRootContext);
81131
}
82132
}

0 commit comments

Comments
 (0)