From ea5d1c65d33189c4d516ac7434b03b85de0c0f8c Mon Sep 17 00:00:00 2001 From: Prabhu Joseph Date: Thu, 21 Feb 2019 18:35:40 +0530 Subject: [PATCH] YARN-7266 --- .../hadoop-yarn/hadoop-yarn-api/pom.xml | 6 +++ .../yarn/api/records/timeline/jaxb.properties | 1 + .../webapp/ContextFactory.java | 55 ++++++++++++++++++++++ .../webapp/TestAHSWebServices.java | 18 +++++++ 4 files changed, 80 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/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/pom.xml index 832e98c..3f5dba8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/pom.xml @@ -91,6 +91,12 @@ false + + src/main/java + + **/jaxb.properties + + 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..4a7b88f --- /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,55 @@ +/** + * 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 com.google.common.annotations.VisibleForTesting; +import org.apache.hadoop.yarn.api.records.timeline.TimelineAbout; + +/** + * ContextFactory to reuse JAXBContextImpl for DAO Classes. + */ +public class ContextFactory { + + private static JAXBContext jaxbContext; + + private ContextFactory() { + } + + 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; + } +} diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/TestAHSWebServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/TestAHSWebServices.java index b4792a8..3ce335d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/TestAHSWebServices.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/TestAHSWebServices.java @@ -34,7 +34,9 @@ import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServletResponse; +import javax.xml.bind.JAXBContext; import javax.ws.rs.core.MediaType; + import org.apache.commons.lang3.StringUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; @@ -64,6 +66,7 @@ import org.apache.hadoop.yarn.server.timeline.security.TimelineACLsManager; import org.apache.hadoop.yarn.server.webapp.LogWebServiceUtils; import org.apache.hadoop.yarn.server.webapp.YarnWebServiceParams; +import org.apache.hadoop.yarn.server.webapp.dao.AppInfo; import org.apache.hadoop.yarn.server.webapp.dao.ContainerLogsInfo; import org.apache.hadoop.yarn.api.records.timeline.TimelineAbout; import org.apache.hadoop.yarn.util.timeline.TimelineUtils; @@ -949,6 +952,21 @@ public void testContainerLogsMetaForFinishedApps() throws Exception { String.valueOf(content.length())); } + @Test + public void testContextFactory() throws Exception { + WebResource r = resource(); + ClientResponse response = r + .path("ws").path("v1").path("applicationhistory").path("about") + .queryParam("user.name", USERS[round]) + .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); + JAXBContext jaxbContext1 = ContextFactory.createContext( + new Class[]{TimelineAbout.class}, Collections.EMPTY_MAP); + JAXBContext jaxbContext2 = ContextFactory.createContext( + new Class[]{AppInfo.class, TimelineAbout.class}, + Collections.EMPTY_MAP); + assertEquals(jaxbContext1, jaxbContext2); + } + private static String getRedirectURL(String url) { String redirectUrl = null; try { -- 2.7.4 (Apple Git-66)