[07/40] hadoop git commit: YARN-6314. Potential infinite redirection on YARN log redirection web service. Contributed by Xuan Gong.

2017-03-20 Thread liuml07
YARN-6314. Potential infinite redirection on YARN log redirection web service. 
Contributed by Xuan Gong.

(cherry picked from commit 5a9dda796f0e73060ada794ad5752cc6a237ab2e)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/34424e98
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/34424e98
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/34424e98

Branch: refs/heads/HADOOP-13345
Commit: 34424e98a618a9fefce800746168be2b72e17de9
Parents: 023b941
Author: Junping Du 
Authored: Tue Mar 14 02:56:18 2017 -0700
Committer: Junping Du 
Committed: Tue Mar 14 02:58:07 2017 -0700

--
 .../webapp/AHSWebServices.java  | 32 +++-
 .../webapp/TestAHSWebServices.java  | 17 +++
 .../server/webapp/YarnWebServiceParams.java |  1 +
 .../nodemanager/webapp/NMWebServices.java   |  6 +++-
 .../nodemanager/webapp/TestNMWebServices.java   |  6 
 5 files changed, 54 insertions(+), 8 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/34424e98/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java
--
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/AHSWebServices.java
 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java
index c296aaa..6195199 100644
--- 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java
+++ 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java
@@ -28,6 +28,7 @@ import java.util.Set;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.DefaultValue;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
@@ -235,6 +236,8 @@ public class AHSWebServices extends WebServices {
*The container ID
* @param nmId
*The Node Manager NodeId
+   * @param redirected_from_node
+   *Whether this is a redirected request from NM
* @return
*The log file's name and current file size
*/
@@ -245,7 +248,9 @@ public class AHSWebServices extends WebServices {
   @Context HttpServletRequest req,
   @Context HttpServletResponse res,
   @PathParam(YarnWebServiceParams.CONTAINER_ID) String containerIdStr,
-  @QueryParam(YarnWebServiceParams.NM_ID) String nmId) {
+  @QueryParam(YarnWebServiceParams.NM_ID) String nmId,
+  @QueryParam(YarnWebServiceParams.REDIRECTED_FROM_NODE)
+  @DefaultValue("false") boolean redirected_from_node) {
 ContainerId containerId = null;
 init(res);
 try {
@@ -253,6 +258,7 @@ public class AHSWebServices extends WebServices {
 } catch (IllegalArgumentException e) {
   throw new BadRequestException("invalid container id, " + containerIdStr);
 }
+
 ApplicationId appId = containerId.getApplicationAttemptId()
 .getApplicationId();
 AppInfo appInfo;
@@ -297,9 +303,12 @@ public class AHSWebServices extends WebServices {
 // make sure nodeHttpAddress is not null and not empty. Otherwise,
 // we would only get log meta for aggregated logs instead of
 // re-directing the request
-if (nodeHttpAddress == null || nodeHttpAddress.isEmpty()) {
+if (nodeHttpAddress == null || nodeHttpAddress.isEmpty()
+|| redirected_from_node) {
   // return log meta for the aggregated logs if exists.
   // It will also return empty log meta for the local logs.
+  // If this is the redirect request from NM, we should not
+  // re-direct the request back. Simply output the aggregated log meta.
   return getContainerLogMeta(appId, appOwner, null,
   containerIdStr, true);
 }
@@ -338,6 +347,8 @@ public class AHSWebServices extends WebServices {
*the size of the log file
* @param nmId
*The Node Manager NodeId
+   * @param redirected_from_node
+   *Whether this is the redirect request from NM
* @return
*The contents of the container's log file
*/
@@ -352,9 +363,11 @@ public class AHSWebServices extends 

[28/50] [abbrv] hadoop git commit: YARN-6314. Potential infinite redirection on YARN log redirection web service. Contributed by Xuan Gong.

2017-03-16 Thread inigoiri
YARN-6314. Potential infinite redirection on YARN log redirection web service. 
Contributed by Xuan Gong.

(cherry picked from commit 5a9dda796f0e73060ada794ad5752cc6a237ab2e)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/34424e98
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/34424e98
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/34424e98

Branch: refs/heads/HDFS-10467
Commit: 34424e98a618a9fefce800746168be2b72e17de9
Parents: 023b941
Author: Junping Du 
Authored: Tue Mar 14 02:56:18 2017 -0700
Committer: Junping Du 
Committed: Tue Mar 14 02:58:07 2017 -0700

--
 .../webapp/AHSWebServices.java  | 32 +++-
 .../webapp/TestAHSWebServices.java  | 17 +++
 .../server/webapp/YarnWebServiceParams.java |  1 +
 .../nodemanager/webapp/NMWebServices.java   |  6 +++-
 .../nodemanager/webapp/TestNMWebServices.java   |  6 
 5 files changed, 54 insertions(+), 8 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/34424e98/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java
--
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/AHSWebServices.java
 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java
index c296aaa..6195199 100644
--- 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java
+++ 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java
@@ -28,6 +28,7 @@ import java.util.Set;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.DefaultValue;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
@@ -235,6 +236,8 @@ public class AHSWebServices extends WebServices {
*The container ID
* @param nmId
*The Node Manager NodeId
+   * @param redirected_from_node
+   *Whether this is a redirected request from NM
* @return
*The log file's name and current file size
*/
@@ -245,7 +248,9 @@ public class AHSWebServices extends WebServices {
   @Context HttpServletRequest req,
   @Context HttpServletResponse res,
   @PathParam(YarnWebServiceParams.CONTAINER_ID) String containerIdStr,
-  @QueryParam(YarnWebServiceParams.NM_ID) String nmId) {
+  @QueryParam(YarnWebServiceParams.NM_ID) String nmId,
+  @QueryParam(YarnWebServiceParams.REDIRECTED_FROM_NODE)
+  @DefaultValue("false") boolean redirected_from_node) {
 ContainerId containerId = null;
 init(res);
 try {
@@ -253,6 +258,7 @@ public class AHSWebServices extends WebServices {
 } catch (IllegalArgumentException e) {
   throw new BadRequestException("invalid container id, " + containerIdStr);
 }
+
 ApplicationId appId = containerId.getApplicationAttemptId()
 .getApplicationId();
 AppInfo appInfo;
@@ -297,9 +303,12 @@ public class AHSWebServices extends WebServices {
 // make sure nodeHttpAddress is not null and not empty. Otherwise,
 // we would only get log meta for aggregated logs instead of
 // re-directing the request
-if (nodeHttpAddress == null || nodeHttpAddress.isEmpty()) {
+if (nodeHttpAddress == null || nodeHttpAddress.isEmpty()
+|| redirected_from_node) {
   // return log meta for the aggregated logs if exists.
   // It will also return empty log meta for the local logs.
+  // If this is the redirect request from NM, we should not
+  // re-direct the request back. Simply output the aggregated log meta.
   return getContainerLogMeta(appId, appOwner, null,
   containerIdStr, true);
 }
@@ -338,6 +347,8 @@ public class AHSWebServices extends WebServices {
*the size of the log file
* @param nmId
*The Node Manager NodeId
+   * @param redirected_from_node
+   *Whether this is the redirect request from NM
* @return
*The contents of the container's log file
*/
@@ -352,9 +363,11 @@ public class AHSWebServices extends 

[24/33] hadoop git commit: YARN-6314. Potential infinite redirection on YARN log redirection web service. Contributed by Xuan Gong.

2017-03-14 Thread jhung
YARN-6314. Potential infinite redirection on YARN log redirection web service. 
Contributed by Xuan Gong.

(cherry picked from commit 5a9dda796f0e73060ada794ad5752cc6a237ab2e)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/34424e98
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/34424e98
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/34424e98

Branch: refs/heads/YARN-5734
Commit: 34424e98a618a9fefce800746168be2b72e17de9
Parents: 023b941
Author: Junping Du 
Authored: Tue Mar 14 02:56:18 2017 -0700
Committer: Junping Du 
Committed: Tue Mar 14 02:58:07 2017 -0700

--
 .../webapp/AHSWebServices.java  | 32 +++-
 .../webapp/TestAHSWebServices.java  | 17 +++
 .../server/webapp/YarnWebServiceParams.java |  1 +
 .../nodemanager/webapp/NMWebServices.java   |  6 +++-
 .../nodemanager/webapp/TestNMWebServices.java   |  6 
 5 files changed, 54 insertions(+), 8 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/34424e98/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java
--
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/AHSWebServices.java
 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java
index c296aaa..6195199 100644
--- 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java
+++ 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java
@@ -28,6 +28,7 @@ import java.util.Set;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.DefaultValue;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
@@ -235,6 +236,8 @@ public class AHSWebServices extends WebServices {
*The container ID
* @param nmId
*The Node Manager NodeId
+   * @param redirected_from_node
+   *Whether this is a redirected request from NM
* @return
*The log file's name and current file size
*/
@@ -245,7 +248,9 @@ public class AHSWebServices extends WebServices {
   @Context HttpServletRequest req,
   @Context HttpServletResponse res,
   @PathParam(YarnWebServiceParams.CONTAINER_ID) String containerIdStr,
-  @QueryParam(YarnWebServiceParams.NM_ID) String nmId) {
+  @QueryParam(YarnWebServiceParams.NM_ID) String nmId,
+  @QueryParam(YarnWebServiceParams.REDIRECTED_FROM_NODE)
+  @DefaultValue("false") boolean redirected_from_node) {
 ContainerId containerId = null;
 init(res);
 try {
@@ -253,6 +258,7 @@ public class AHSWebServices extends WebServices {
 } catch (IllegalArgumentException e) {
   throw new BadRequestException("invalid container id, " + containerIdStr);
 }
+
 ApplicationId appId = containerId.getApplicationAttemptId()
 .getApplicationId();
 AppInfo appInfo;
@@ -297,9 +303,12 @@ public class AHSWebServices extends WebServices {
 // make sure nodeHttpAddress is not null and not empty. Otherwise,
 // we would only get log meta for aggregated logs instead of
 // re-directing the request
-if (nodeHttpAddress == null || nodeHttpAddress.isEmpty()) {
+if (nodeHttpAddress == null || nodeHttpAddress.isEmpty()
+|| redirected_from_node) {
   // return log meta for the aggregated logs if exists.
   // It will also return empty log meta for the local logs.
+  // If this is the redirect request from NM, we should not
+  // re-direct the request back. Simply output the aggregated log meta.
   return getContainerLogMeta(appId, appOwner, null,
   containerIdStr, true);
 }
@@ -338,6 +347,8 @@ public class AHSWebServices extends WebServices {
*the size of the log file
* @param nmId
*The Node Manager NodeId
+   * @param redirected_from_node
+   *Whether this is the redirect request from NM
* @return
*The contents of the container's log file
*/
@@ -352,9 +363,11 @@ public class AHSWebServices extends 

hadoop git commit: YARN-6314. Potential infinite redirection on YARN log redirection web service. Contributed by Xuan Gong.

2017-03-14 Thread junping_du
Repository: hadoop
Updated Branches:
  refs/heads/branch-2 f731013c8 -> f254002f1


YARN-6314. Potential infinite redirection on YARN log redirection web service. 
Contributed by Xuan Gong.

(cherry picked from commit 5a9dda796f0e73060ada794ad5752cc6a237ab2e)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/f254002f
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/f254002f
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/f254002f

Branch: refs/heads/branch-2
Commit: f254002f1d6145642e3ecc32c789e9e2533524d3
Parents: f731013
Author: Junping Du 
Authored: Tue Mar 14 02:56:18 2017 -0700
Committer: Junping Du 
Committed: Tue Mar 14 02:58:44 2017 -0700

--
 .../webapp/AHSWebServices.java  | 32 +++-
 .../webapp/TestAHSWebServices.java  | 17 +++
 .../server/webapp/YarnWebServiceParams.java |  1 +
 .../nodemanager/webapp/NMWebServices.java   |  6 +++-
 .../nodemanager/webapp/TestNMWebServices.java   |  6 
 5 files changed, 54 insertions(+), 8 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/f254002f/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java
--
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/AHSWebServices.java
 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java
index 13c1d5e..5c486ed 100644
--- 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java
+++ 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java
@@ -28,6 +28,7 @@ import java.util.Set;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.DefaultValue;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
@@ -226,6 +227,8 @@ public class AHSWebServices extends WebServices {
*The container ID
* @param nmId
*The Node Manager NodeId
+   * @param redirected_from_node
+   *Whether this is a redirected request from NM
* @return
*The log file's name and current file size
*/
@@ -236,7 +239,9 @@ public class AHSWebServices extends WebServices {
   @Context HttpServletRequest req,
   @Context HttpServletResponse res,
   @PathParam(YarnWebServiceParams.CONTAINER_ID) String containerIdStr,
-  @QueryParam(YarnWebServiceParams.NM_ID) String nmId) {
+  @QueryParam(YarnWebServiceParams.NM_ID) String nmId,
+  @QueryParam(YarnWebServiceParams.REDIRECTED_FROM_NODE)
+  @DefaultValue("false") boolean redirected_from_node) {
 ContainerId containerId = null;
 init(res);
 try {
@@ -244,6 +249,7 @@ public class AHSWebServices extends WebServices {
 } catch (IllegalArgumentException e) {
   throw new BadRequestException("invalid container id, " + containerIdStr);
 }
+
 ApplicationId appId = containerId.getApplicationAttemptId()
 .getApplicationId();
 AppInfo appInfo;
@@ -288,9 +294,12 @@ public class AHSWebServices extends WebServices {
 // make sure nodeHttpAddress is not null and not empty. Otherwise,
 // we would only get log meta for aggregated logs instead of
 // re-directing the request
-if (nodeHttpAddress == null || nodeHttpAddress.isEmpty()) {
+if (nodeHttpAddress == null || nodeHttpAddress.isEmpty()
+|| redirected_from_node) {
   // return log meta for the aggregated logs if exists.
   // It will also return empty log meta for the local logs.
+  // If this is the redirect request from NM, we should not
+  // re-direct the request back. Simply output the aggregated log meta.
   return getContainerLogMeta(appId, appOwner, null,
   containerIdStr, true);
 }
@@ -329,6 +338,8 @@ public class AHSWebServices extends WebServices {
*the size of the log file
* @param nmId
*The Node Manager NodeId
+   * @param redirected_from_node
+   *Whether this is the redirect request from NM
* @return
*The contents of the container's 

hadoop git commit: YARN-6314. Potential infinite redirection on YARN log redirection web service. Contributed by Xuan Gong.

2017-03-14 Thread junping_du
Repository: hadoop
Updated Branches:
  refs/heads/trunk 023b941e3 -> 34424e98a


YARN-6314. Potential infinite redirection on YARN log redirection web service. 
Contributed by Xuan Gong.

(cherry picked from commit 5a9dda796f0e73060ada794ad5752cc6a237ab2e)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/34424e98
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/34424e98
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/34424e98

Branch: refs/heads/trunk
Commit: 34424e98a618a9fefce800746168be2b72e17de9
Parents: 023b941
Author: Junping Du 
Authored: Tue Mar 14 02:56:18 2017 -0700
Committer: Junping Du 
Committed: Tue Mar 14 02:58:07 2017 -0700

--
 .../webapp/AHSWebServices.java  | 32 +++-
 .../webapp/TestAHSWebServices.java  | 17 +++
 .../server/webapp/YarnWebServiceParams.java |  1 +
 .../nodemanager/webapp/NMWebServices.java   |  6 +++-
 .../nodemanager/webapp/TestNMWebServices.java   |  6 
 5 files changed, 54 insertions(+), 8 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/34424e98/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java
--
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/AHSWebServices.java
 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java
index c296aaa..6195199 100644
--- 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java
+++ 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java
@@ -28,6 +28,7 @@ import java.util.Set;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.DefaultValue;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
@@ -235,6 +236,8 @@ public class AHSWebServices extends WebServices {
*The container ID
* @param nmId
*The Node Manager NodeId
+   * @param redirected_from_node
+   *Whether this is a redirected request from NM
* @return
*The log file's name and current file size
*/
@@ -245,7 +248,9 @@ public class AHSWebServices extends WebServices {
   @Context HttpServletRequest req,
   @Context HttpServletResponse res,
   @PathParam(YarnWebServiceParams.CONTAINER_ID) String containerIdStr,
-  @QueryParam(YarnWebServiceParams.NM_ID) String nmId) {
+  @QueryParam(YarnWebServiceParams.NM_ID) String nmId,
+  @QueryParam(YarnWebServiceParams.REDIRECTED_FROM_NODE)
+  @DefaultValue("false") boolean redirected_from_node) {
 ContainerId containerId = null;
 init(res);
 try {
@@ -253,6 +258,7 @@ public class AHSWebServices extends WebServices {
 } catch (IllegalArgumentException e) {
   throw new BadRequestException("invalid container id, " + containerIdStr);
 }
+
 ApplicationId appId = containerId.getApplicationAttemptId()
 .getApplicationId();
 AppInfo appInfo;
@@ -297,9 +303,12 @@ public class AHSWebServices extends WebServices {
 // make sure nodeHttpAddress is not null and not empty. Otherwise,
 // we would only get log meta for aggregated logs instead of
 // re-directing the request
-if (nodeHttpAddress == null || nodeHttpAddress.isEmpty()) {
+if (nodeHttpAddress == null || nodeHttpAddress.isEmpty()
+|| redirected_from_node) {
   // return log meta for the aggregated logs if exists.
   // It will also return empty log meta for the local logs.
+  // If this is the redirect request from NM, we should not
+  // re-direct the request back. Simply output the aggregated log meta.
   return getContainerLogMeta(appId, appOwner, null,
   containerIdStr, true);
 }
@@ -338,6 +347,8 @@ public class AHSWebServices extends WebServices {
*the size of the log file
* @param nmId
*The Node Manager NodeId
+   * @param redirected_from_node
+   *Whether this is the redirect request from NM
* @return
*The contents of the container's log