YARN-10361. Make custom DAO classes configurable into RMWebApp#JAXBContextResolver.
Contributed by Bilwa ST.
This commit is contained in:
parent
dc5470ae86
commit
c7e71a6c0b
@ -2398,7 +2398,13 @@ public static boolean isAclEnabled(Configuration conf) {
|
|||||||
"yarn.http.rmwebapp.external.classes";
|
"yarn.http.rmwebapp.external.classes";
|
||||||
|
|
||||||
public static final String YARN_HTTP_WEBAPP_SCHEDULER_PAGE =
|
public static final String YARN_HTTP_WEBAPP_SCHEDULER_PAGE =
|
||||||
"hadoop.http.rmwebapp.scheduler.page.class";
|
"yarn.http.rmwebapp.scheduler.page.class";
|
||||||
|
|
||||||
|
public static final String YARN_HTTP_WEBAPP_CUSTOM_DAO_CLASSES =
|
||||||
|
"yarn.http.rmwebapp.custom.dao.classes";
|
||||||
|
|
||||||
|
public static final String YARN_HTTP_WEBAPP_CUSTOM_UNWRAPPED_DAO_CLASSES =
|
||||||
|
"yarn.http.rmwebapp.custom.unwrapped.dao.classes";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not users are allowed to request that Docker containers honor
|
* Whether or not users are allowed to request that Docker containers honor
|
||||||
|
@ -3355,10 +3355,26 @@
|
|||||||
<description>
|
<description>
|
||||||
Used to specify custom scheduler page
|
Used to specify custom scheduler page
|
||||||
</description>
|
</description>
|
||||||
<name>hadoop.http.rmwebapp.scheduler.page.class</name>
|
<name>yarn.http.rmwebapp.scheduler.page.class</name>
|
||||||
<value></value>
|
<value></value>
|
||||||
</property>
|
</property>
|
||||||
|
|
||||||
|
<property>
|
||||||
|
<description>
|
||||||
|
Used to specify custom DAO classes used by custom web services.
|
||||||
|
</description>
|
||||||
|
<name>yarn.http.rmwebapp.custom.dao.classes</name>
|
||||||
|
<value></value>
|
||||||
|
</property>
|
||||||
|
|
||||||
|
<property>
|
||||||
|
<description>
|
||||||
|
Used to specify custom DAO classes used by custom web services which requires
|
||||||
|
root unwrapping.
|
||||||
|
</description>
|
||||||
|
<name>yarn.http.rmwebapp.custom.unwrapped.dao.classes</name>
|
||||||
|
<value></value>
|
||||||
|
</property>
|
||||||
|
|
||||||
<property>
|
<property>
|
||||||
<description>The Node Label script to run. Script output Line starting with
|
<description>The Node Label script to run. Script output Line starting with
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package org.apache.hadoop.yarn.server.resourcemanager.webapp;
|
package org.apache.hadoop.yarn.server.resourcemanager.webapp;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import com.sun.jersey.api.json.JSONConfiguration;
|
import com.sun.jersey.api.json.JSONConfiguration;
|
||||||
import com.sun.jersey.api.json.JSONJAXBContext;
|
import com.sun.jersey.api.json.JSONJAXBContext;
|
||||||
@ -28,6 +29,10 @@
|
|||||||
import javax.ws.rs.ext.Provider;
|
import javax.ws.rs.ext.Provider;
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
||||||
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.UserInfo;
|
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.UserInfo;
|
||||||
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.*;
|
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.*;
|
||||||
import org.apache.hadoop.yarn.webapp.RemoteExceptionData;
|
import org.apache.hadoop.yarn.webapp.RemoteExceptionData;
|
||||||
@ -36,9 +41,17 @@
|
|||||||
@Provider
|
@Provider
|
||||||
public class JAXBContextResolver implements ContextResolver<JAXBContext> {
|
public class JAXBContextResolver implements ContextResolver<JAXBContext> {
|
||||||
|
|
||||||
|
private static final Log LOG =
|
||||||
|
LogFactory.getLog(JAXBContextResolver.class.getName());
|
||||||
|
|
||||||
private final Map<Class, JAXBContext> typesContextMap;
|
private final Map<Class, JAXBContext> typesContextMap;
|
||||||
|
|
||||||
public JAXBContextResolver() throws Exception {
|
public JAXBContextResolver() throws Exception {
|
||||||
|
this(new Configuration());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public JAXBContextResolver(Configuration conf) throws Exception {
|
||||||
|
|
||||||
JAXBContext context;
|
JAXBContext context;
|
||||||
JAXBContext unWrappedRootContext;
|
JAXBContext unWrappedRootContext;
|
||||||
@ -66,17 +79,54 @@ public JAXBContextResolver() throws Exception {
|
|||||||
DelegationToken.class, AppQueue.class, AppPriority.class,
|
DelegationToken.class, AppQueue.class, AppPriority.class,
|
||||||
ResourceOptionInfo.class };
|
ResourceOptionInfo.class };
|
||||||
|
|
||||||
|
ArrayList<Class> finalcTypesList = new ArrayList<>();
|
||||||
|
ArrayList<Class> finalRootUnwrappedTypesList = new ArrayList<>();
|
||||||
|
|
||||||
|
Collections.addAll(finalcTypesList, cTypes);
|
||||||
|
Collections.addAll(finalRootUnwrappedTypesList, rootUnwrappedTypes);
|
||||||
|
|
||||||
|
// Add Custom DAO Classes
|
||||||
|
Class[] daoClasses = null;
|
||||||
|
Class[] unwrappedDaoClasses = null;
|
||||||
|
boolean loadCustom = true;
|
||||||
|
try {
|
||||||
|
daoClasses = conf
|
||||||
|
.getClasses(YarnConfiguration.YARN_HTTP_WEBAPP_CUSTOM_DAO_CLASSES);
|
||||||
|
unwrappedDaoClasses = conf.getClasses(
|
||||||
|
YarnConfiguration.YARN_HTTP_WEBAPP_CUSTOM_UNWRAPPED_DAO_CLASSES);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.warn("Failed to load custom dao class: " + e);
|
||||||
|
loadCustom = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loadCustom) {
|
||||||
|
if (daoClasses != null) {
|
||||||
|
Collections.addAll(finalcTypesList, daoClasses);
|
||||||
|
LOG.debug("Added custom dao classes: " + Arrays.toString(daoClasses));
|
||||||
|
}
|
||||||
|
if (unwrappedDaoClasses != null) {
|
||||||
|
Collections.addAll(finalRootUnwrappedTypesList, unwrappedDaoClasses);
|
||||||
|
LOG.debug("Added custom Unwrapped dao classes: "
|
||||||
|
+ Arrays.toString(unwrappedDaoClasses));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final Class[] finalcTypes = finalcTypesList
|
||||||
|
.toArray(new Class[finalcTypesList.size()]);
|
||||||
|
final Class[] finalRootUnwrappedTypes = finalRootUnwrappedTypesList
|
||||||
|
.toArray(new Class[finalRootUnwrappedTypesList.size()]);
|
||||||
|
|
||||||
this.typesContextMap = new HashMap<Class, JAXBContext>();
|
this.typesContextMap = new HashMap<Class, JAXBContext>();
|
||||||
context =
|
context =
|
||||||
new JSONJAXBContext(JSONConfiguration.natural().rootUnwrapping(false)
|
new JSONJAXBContext(JSONConfiguration.natural().rootUnwrapping(false)
|
||||||
.build(), cTypes);
|
.build(), finalcTypes);
|
||||||
unWrappedRootContext =
|
unWrappedRootContext =
|
||||||
new JSONJAXBContext(JSONConfiguration.natural().rootUnwrapping(true)
|
new JSONJAXBContext(JSONConfiguration.natural().rootUnwrapping(true)
|
||||||
.build(), rootUnwrappedTypes);
|
.build(), finalRootUnwrappedTypes);
|
||||||
for (Class type : cTypes) {
|
for (Class type : finalcTypes) {
|
||||||
typesContextMap.put(type, context);
|
typesContextMap.put(type, context);
|
||||||
}
|
}
|
||||||
for (Class type : rootUnwrappedTypes) {
|
for (Class type : finalRootUnwrappedTypes) {
|
||||||
typesContextMap.put(type, unWrappedRootContext);
|
typesContextMap.put(type, unWrappedRootContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user