AMBARI-13436. Kerberos Wizard: null in request logs (rlevas)

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

Branch: refs/heads/branch-dev-patch-upgrade
Commit: 86fb7574aa8bdb02791ef31b45322c92c9e5ac02
Parents: fbc65a9
Author: Robert Levas <[email protected]>
Authored: Thu Oct 15 18:01:30 2015 -0400
Committer: Robert Levas <[email protected]>
Committed: Thu Oct 15 18:01:35 2015 -0400

----------------------------------------------------------------------
 .../server/controller/ShortTaskStatus.java      | 23 +++++++++++++++---
 .../AmbariManagementControllerTest.java         | 25 ++++++++++++++++++++
 2 files changed, 45 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/86fb7574/ambari-server/src/main/java/org/apache/ambari/server/controller/ShortTaskStatus.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/ShortTaskStatus.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/ShortTaskStatus.java
index 6fe4db2..975476f 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/ShortTaskStatus.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/ShortTaskStatus.java
@@ -19,6 +19,8 @@
 package org.apache.ambari.server.controller;
 
 import org.apache.ambari.server.actionmanager.HostRoleCommand;
+import org.apache.ambari.server.utils.StageUtils;
+import org.apache.commons.lang.StringUtils;
 
 public class ShortTaskStatus {
   protected long requestId;
@@ -39,7 +41,7 @@ public class ShortTaskStatus {
                          String customCommandName, String outputLog, String 
errorLog) {
     this.taskId = taskId;
     this.stageId = stageId;
-    this.hostName = hostName;
+    this.hostName = translateHostName(hostName);
     this.role = role;
     this.command = command;
     this.status = status;
@@ -52,7 +54,7 @@ public class ShortTaskStatus {
     this.taskId = hostRoleCommand.getTaskId();
     this.stageId = hostRoleCommand.getStageId();
     this.command = hostRoleCommand.getRoleCommand().toString();
-    this.hostName = hostRoleCommand.getHostName();
+    this.hostName = translateHostName(hostRoleCommand.getHostName());
     this.role = hostRoleCommand.getRole().toString();
     this.status = hostRoleCommand.getStatus().toString();
     this.customCommandName = hostRoleCommand.getCustomCommandName();
@@ -97,7 +99,7 @@ public class ShortTaskStatus {
   }
 
   public void setHostName(String hostName) {
-    this.hostName = hostName;
+    this.hostName = translateHostName(hostName);
   }
 
   public String getRole() {
@@ -155,4 +157,19 @@ public class ShortTaskStatus {
     return sb.toString();
   }
 
+  /**
+   * If the hostname is null (or empty), returns the hostname of the Ambari 
Server; else returns the
+   * supplied hostname value.
+   *
+   * @param hostName a hostname
+   * @return the hostname of the Ambari Server if the hostname is null (or 
empty); else supplied hostname value
+   */
+  private String translateHostName(String hostName) {
+    // if the hostname in the command is null, replace it with the hostname of 
the Ambari Server
+    // This is because commands (to be) handled by the Ambari Server have a 
null value for its
+    // host designation.
+    return (StringUtils.isEmpty(hostName))
+        ? StageUtils.getHostName()
+        : hostName;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/86fb7574/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index 528d343..7e2090a 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -100,6 +100,7 @@ import 
org.apache.ambari.server.state.configgroup.ConfigGroup;
 import org.apache.ambari.server.state.configgroup.ConfigGroupFactory;
 import 
org.apache.ambari.server.state.svccomphost.ServiceComponentHostInstallEvent;
 import 
org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpSucceededEvent;
+import 
org.apache.ambari.server.state.svccomphost.ServiceComponentHostServerActionEvent;
 import 
org.apache.ambari.server.state.svccomphost.ServiceComponentHostStartEvent;
 import 
org.apache.ambari.server.state.svccomphost.ServiceComponentHostStartedEvent;
 import 
org.apache.ambari.server.state.svccomphost.ServiceComponentHostStopEvent;
@@ -7998,6 +7999,7 @@ public class AmbariManagementControllerTest {
   public void testGetTasksByRequestId() throws AmbariException {
     final long requestId1 = 1;
     final long requestId2 = 2;
+    final long requestId3 = 3;
     final String clusterName = "c1";
     final String hostName1 = "h1";
     final String context = "Test invocation";
@@ -8066,6 +8068,19 @@ public class AmbariManagementControllerTest {
     request = new Request(stages, clusters);
     actionDB.persistActions(request);
 
+    // Add a stage to execute a task as server-side action on the Ambari server
+    ServiceComponentHostServerActionEvent 
serviceComponentHostServerActionEvent =
+        new 
ServiceComponentHostServerActionEvent(Role.AMBARI_SERVER_ACTION.toString(), 
null, System.currentTimeMillis());
+    stages.clear();
+    stages.add(stageFactory.createNew(requestId3, "/a6", clusterName, 1L, 
context,
+      CLUSTER_HOST_INFO, "", ""));
+    stages.get(0).setStageId(6);
+    stages.get(0).addServerActionCommand("some.action.class.name", null, 
Role.AMBARI_SERVER_ACTION,
+        RoleCommand.EXECUTE, clusterName, 
serviceComponentHostServerActionEvent, null, null, null, null, false, false);
+    assertEquals("_internal_ambari", 
stages.get(0).getOrderedHostRoleCommands().get(0).getHostName());
+    request = new Request(stages, clusters);
+    actionDB.persistActions(request);
+
 
     Set<TaskStatusRequest> taskStatusRequests;
     Set<TaskStatusResponse> taskStatusResponses;
@@ -8107,6 +8122,16 @@ public class AmbariManagementControllerTest {
     taskStatusResponses = controller.getTaskStatus(taskStatusRequests);
     assertEquals(5L, taskStatusResponses.iterator().next().getTaskId());
 
+    //check that a sever-side action is reported back properly (namely the 
hostname value of the repsonse)
+    taskStatusResponses = controller.getTaskStatus(Collections.singleton(new 
TaskStatusRequest(requestId3, null)));
+    assertEquals(1, taskStatusResponses.size());
+    TaskStatusResponse response = taskStatusResponses.iterator().next();
+    assertNotNull(response);
+    assertEquals(6L, response.getTaskId());
+    // The host name for the task should be the same as what 
StageUtils#getHostName returns since
+    // the host was specified as null when
+    assertEquals(StageUtils.getHostName(), response.getHostName());
+
     //verify that task from second request (requestId2) does not present in 
first request (requestId1)
     taskStatusRequests = new HashSet<TaskStatusRequest>(){
       {

Reply via email to