|
18 | 18 |
|
19 | 19 | package org.apache.hadoop.yarn.server.resourcemanager.webapp; |
20 | 20 |
|
| 21 | +import com.google.inject.Inject; |
21 | 22 | import com.google.inject.Singleton; |
22 | 23 | import com.sun.jersey.api.json.JSONConfiguration; |
23 | 24 | import com.sun.jersey.api.json.JSONJAXBContext; |
|
28 | 29 | import javax.ws.rs.ext.Provider; |
29 | 30 | import javax.xml.bind.JAXBContext; |
30 | 31 |
|
| 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; |
31 | 36 | import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.UserInfo; |
32 | 37 | import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.*; |
33 | 38 | import org.apache.hadoop.yarn.webapp.RemoteExceptionData; |
|
36 | 41 | @Provider |
37 | 42 | public class JAXBContextResolver implements ContextResolver<JAXBContext> { |
38 | 43 |
|
| 44 | + private static final Log LOG = |
| 45 | + LogFactory.getLog(JAXBContextResolver.class.getName()); |
| 46 | + |
39 | 47 | private final Map<Class, JAXBContext> typesContextMap; |
40 | 48 |
|
41 | 49 | public JAXBContextResolver() throws Exception { |
| 50 | + this(new Configuration()); |
| 51 | + } |
| 52 | + |
| 53 | + @Inject |
| 54 | + public JAXBContextResolver(Configuration conf) throws Exception { |
42 | 55 |
|
43 | 56 | JAXBContext context; |
44 | 57 | JAXBContext unWrappedRootContext; |
@@ -66,17 +79,54 @@ public JAXBContextResolver() throws Exception { |
66 | 79 | DelegationToken.class, AppQueue.class, AppPriority.class, |
67 | 80 | ResourceOptionInfo.class }; |
68 | 81 |
|
| 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 | + |
69 | 119 | this.typesContextMap = new HashMap<Class, JAXBContext>(); |
70 | 120 | context = |
71 | 121 | new JSONJAXBContext(JSONConfiguration.natural().rootUnwrapping(false) |
72 | | - .build(), cTypes); |
| 122 | + .build(), finalcTypes); |
73 | 123 | unWrappedRootContext = |
74 | 124 | new JSONJAXBContext(JSONConfiguration.natural().rootUnwrapping(true) |
75 | | - .build(), rootUnwrappedTypes); |
76 | | - for (Class type : cTypes) { |
| 125 | + .build(), finalRootUnwrappedTypes); |
| 126 | + for (Class type : finalcTypes) { |
77 | 127 | typesContextMap.put(type, context); |
78 | 128 | } |
79 | | - for (Class type : rootUnwrappedTypes) { |
| 129 | + for (Class type : finalRootUnwrappedTypes) { |
80 | 130 | typesContextMap.put(type, unWrappedRootContext); |
81 | 131 | } |
82 | 132 | } |
|
0 commit comments