From 1e61f389e9d8ade8b8fb2cf0dbe8731f0cff1642 Mon Sep 17 00:00:00 2001 From: Jason Lowe Date: Thu, 13 Sep 2018 14:41:38 -0500 Subject: [PATCH] MAPREDUCE-7133. History Server task attempts REST API returns invalid data. Contributed by Oleksandr Shevchenko (cherry picked from commit 2886024ac3a8613ecc27f1595b278ce6fc2d03ba) --- .../mapreduce/v2/app/webapp/dao/TaskAttemptsInfo.java | 8 +++++--- .../v2/app/webapp/TestAMWebServicesAttempts.java | 3 +++ .../src/site/markdown/MapredAppMasterRest.md | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/dao/TaskAttemptsInfo.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/dao/TaskAttemptsInfo.java index c92488fe81b..6f188d9d772 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/dao/TaskAttemptsInfo.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/dao/TaskAttemptsInfo.java @@ -19,12 +19,10 @@ import java.util.ArrayList; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElementRef; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name = "taskAttempts") -@XmlAccessorType(XmlAccessType.FIELD) public class TaskAttemptsInfo { protected ArrayList taskAttempt = new ArrayList(); @@ -36,6 +34,10 @@ public void add(TaskAttemptInfo taskattemptInfo) { taskAttempt.add(taskattemptInfo); } + // XmlElementRef annotation should be used to identify the exact type of a list element + // otherwise metadata will be added to XML attributes, + // it can lead to incorrect JSON marshaling + @XmlElementRef public ArrayList getTaskAttempts() { return taskAttempt; } diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/webapp/TestAMWebServicesAttempts.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/webapp/TestAMWebServicesAttempts.java index 21654865cdd..332ec757a54 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/webapp/TestAMWebServicesAttempts.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/webapp/TestAMWebServicesAttempts.java @@ -19,6 +19,7 @@ package org.apache.hadoop.mapreduce.v2.app.webapp; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -475,6 +476,8 @@ public void verifyAMTaskAttemptsXML(NodeList nodes, Task task) { Boolean found = false; for (int i = 0; i < nodes.getLength(); i++) { Element element = (Element) nodes.item(i); + assertFalse("task attempt should not contain any attributes, it can lead to incorrect JSON marshaling", + element.hasAttributes()); if (attid.matches(WebServicesTestUtils.getXmlString(element, "id"))) { found = true; diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/site/markdown/MapredAppMasterRest.md b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/site/markdown/MapredAppMasterRest.md index e2806706925..37773d80583 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/site/markdown/MapredAppMasterRest.md +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/site/markdown/MapredAppMasterRest.md @@ -1875,7 +1875,7 @@ Response Body: - + 1326238777460 0 0