|
@@ -22,62 +22,61 @@ 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;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
|
-import java.util.HashSet;
|
|
|
|
-import java.util.Set;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
import javax.ws.rs.ext.ContextResolver;
|
|
import javax.ws.rs.ext.ContextResolver;
|
|
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.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.AppInfo;
|
|
|
|
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppAttemptInfo;
|
|
|
|
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppAttemptsInfo;
|
|
|
|
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ApplicationStatisticsInfo;
|
|
|
|
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppsInfo;
|
|
|
|
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.CapacitySchedulerInfo;
|
|
|
|
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.CapacitySchedulerQueueInfo;
|
|
|
|
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.CapacitySchedulerQueueInfoList;
|
|
|
|
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ClusterInfo;
|
|
|
|
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ClusterMetricsInfo;
|
|
|
|
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.StatisticsItemInfo;
|
|
|
|
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.FifoSchedulerInfo;
|
|
|
|
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeInfo;
|
|
|
|
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodesInfo;
|
|
|
|
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ResourceInfo;
|
|
|
|
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.SchedulerInfo;
|
|
|
|
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.SchedulerTypeInfo;
|
|
|
|
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.UserMetricsInfo;
|
|
|
|
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.UsersInfo;
|
|
|
|
|
|
+import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.*;
|
|
import org.apache.hadoop.yarn.webapp.RemoteExceptionData;
|
|
import org.apache.hadoop.yarn.webapp.RemoteExceptionData;
|
|
|
|
|
|
@Singleton
|
|
@Singleton
|
|
@Provider
|
|
@Provider
|
|
public class JAXBContextResolver implements ContextResolver<JAXBContext> {
|
|
public class JAXBContextResolver implements ContextResolver<JAXBContext> {
|
|
|
|
|
|
- private JAXBContext context;
|
|
|
|
- private final Set<Class> types;
|
|
|
|
-
|
|
|
|
- // you have to specify all the dao classes here
|
|
|
|
- private final Class[] cTypes = { AppInfo.class, AppAttemptInfo.class,
|
|
|
|
- AppAttemptsInfo.class, ClusterInfo.class,
|
|
|
|
- CapacitySchedulerQueueInfo.class, FifoSchedulerInfo.class,
|
|
|
|
- SchedulerTypeInfo.class, NodeInfo.class, UserMetricsInfo.class,
|
|
|
|
- CapacitySchedulerInfo.class, ClusterMetricsInfo.class,
|
|
|
|
- SchedulerInfo.class, AppsInfo.class, NodesInfo.class,
|
|
|
|
- RemoteExceptionData.class, CapacitySchedulerQueueInfoList.class,
|
|
|
|
- ResourceInfo.class, UsersInfo.class, UserInfo.class,
|
|
|
|
- ApplicationStatisticsInfo.class, StatisticsItemInfo.class};
|
|
|
|
|
|
+ private final Map<Class, JAXBContext> typesContextMap;
|
|
|
|
|
|
public JAXBContextResolver() throws Exception {
|
|
public JAXBContextResolver() throws Exception {
|
|
- this.types = new HashSet<Class>(Arrays.asList(cTypes));
|
|
|
|
- this.context = new JSONJAXBContext(JSONConfiguration.natural()
|
|
|
|
- .rootUnwrapping(false).build(), cTypes);
|
|
|
|
|
|
+
|
|
|
|
+ JAXBContext context;
|
|
|
|
+ JAXBContext unWrappedRootContext;
|
|
|
|
+
|
|
|
|
+ // you have to specify all the dao classes here
|
|
|
|
+ final Class[] cTypes =
|
|
|
|
+ { AppInfo.class, AppAttemptInfo.class, AppAttemptsInfo.class,
|
|
|
|
+ ClusterInfo.class, CapacitySchedulerQueueInfo.class,
|
|
|
|
+ FifoSchedulerInfo.class, SchedulerTypeInfo.class, NodeInfo.class,
|
|
|
|
+ UserMetricsInfo.class, CapacitySchedulerInfo.class,
|
|
|
|
+ ClusterMetricsInfo.class, SchedulerInfo.class, AppsInfo.class,
|
|
|
|
+ NodesInfo.class, RemoteExceptionData.class,
|
|
|
|
+ CapacitySchedulerQueueInfoList.class, ResourceInfo.class,
|
|
|
|
+ UsersInfo.class, UserInfo.class, ApplicationStatisticsInfo.class,
|
|
|
|
+ StatisticsItemInfo.class };
|
|
|
|
+ // these dao classes need root unwrapping
|
|
|
|
+ final Class[] rootUnwrappedTypes =
|
|
|
|
+ { NewApplication.class, ApplicationSubmissionContextInfo.class,
|
|
|
|
+ ContainerLaunchContextInfo.class, LocalResourceInfo.class,
|
|
|
|
+ DelegationToken.class };
|
|
|
|
+
|
|
|
|
+ this.typesContextMap = new HashMap<Class, JAXBContext>();
|
|
|
|
+ context =
|
|
|
|
+ new JSONJAXBContext(JSONConfiguration.natural().rootUnwrapping(false)
|
|
|
|
+ .build(), cTypes);
|
|
|
|
+ unWrappedRootContext =
|
|
|
|
+ new JSONJAXBContext(JSONConfiguration.natural().rootUnwrapping(true)
|
|
|
|
+ .build(), rootUnwrappedTypes);
|
|
|
|
+ for (Class type : cTypes) {
|
|
|
|
+ typesContextMap.put(type, context);
|
|
|
|
+ }
|
|
|
|
+ for (Class type : rootUnwrappedTypes) {
|
|
|
|
+ typesContextMap.put(type, unWrappedRootContext);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public JAXBContext getContext(Class<?> objectType) {
|
|
public JAXBContext getContext(Class<?> objectType) {
|
|
- return (types.contains(objectType)) ? context : null;
|
|
|
|
|
|
+ return typesContextMap.get(objectType);
|
|
}
|
|
}
|
|
}
|
|
}
|