From 87ef9011a5dc98d236207e71be26ea126dda8d2d Mon Sep 17 00:00:00 2001 From: Prabhu Joseph Date: Wed, 20 Feb 2019 20:34:51 +0530 Subject: [PATCH] YARN-7266 --- .../yarn/api/records/timeline/jaxb.properties | 1 + .../webapp/ContextFactory.java | 50 ++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timeline/jaxb.properties create mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/ContextFactory.java diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timeline/jaxb.properties b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timeline/jaxb.properties new file mode 100644 index 0000000..a0ef2eb --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timeline/jaxb.properties @@ -0,0 +1 @@ +javax.xml.bind.context.factory=org.apache.hadoop.yarn.server.applicationhistoryservice.webapp.ContextFactory diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/ContextFactory.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/ContextFactory.java new file mode 100644 index 0000000..413c242 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/ContextFactory.java @@ -0,0 +1,50 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.yarn.server.applicationhistoryservice.webapp; + +import java.util.Arrays; +import java.util.Map; +import java.lang.reflect.Method; +import javax.xml.bind.JAXBContext; +import org.apache.hadoop.yarn.api.records.timeline.TimelineAbout; + + +public class ContextFactory { + + private static JAXBContext jaxbContext; + + public static JAXBContext createContext(Class[] classes, + Map properties) throws Exception { + + if (Arrays.asList(classes).contains(TimelineAbout.class) + && jaxbContext != null) { + return jaxbContext; + } + Class spFactory = Class.forName + ("com.sun.xml.internal.bind.v2.ContextFactory"); + Method m = spFactory.getMethod("createContext", Class[].class, + Map.class); + Object context = m.invoke((Object) null, classes, properties); + if (Arrays.asList(classes).contains(TimelineAbout.class)) { + jaxbContext = (JAXBContext) context; + } + return (JAXBContext) context; + } +} + -- 2.7.4 (Apple Git-66)