From 1a16431bd0df52d2df32c594f8b9b506c2101ad8 Mon Sep 17 00:00:00 2001 From: Junping Du Date: Fri, 27 Jan 2017 06:31:10 -0800 Subject: [PATCH] YARN-6126. Obtaining app logs for Running application fails with json parse error. Contributed by Xuan Gong. --- .../org/apache/hadoop/yarn/client/cli/LogsCLI.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java index b8119e5ec2..1de4cd1724 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java @@ -426,8 +426,17 @@ private List getContainerLogFiles( if (response.getStatusInfo().getStatusCode() == ClientResponse.Status.OK.getStatusCode()) { try { + JSONArray array = new JSONArray(); JSONObject json = response.getEntity(JSONObject.class); - JSONArray array = json.getJSONArray("containerLogsInfo"); + Object logsInfoObj = json.get("containerLogsInfo"); + if (logsInfoObj instanceof JSONObject) { + array.put((JSONObject)logsInfoObj); + } else if (logsInfoObj instanceof JSONArray) { + JSONArray logsArray = (JSONArray)logsInfoObj; + for (int i=0; i < logsArray.length(); i++) { + array.put(logsArray.getJSONObject(i)); + } + } for (int i = 0; i < array.length(); i++) { JSONObject log = array.getJSONObject(i); Object ob = log.get("containerLogInfo");