You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2016/04/12 05:34:16 UTC

[2/3] ambari git commit: Revert "AMBARI-15691. Express Upgrade hangs if ambari agent is restarted in the middle of EU. (mpapirkovskyy)"

Revert "AMBARI-15691. Express Upgrade hangs if ambari agent is restarted in the middle of EU. (mpapirkovskyy)"

This reverts commit 650021ae78c4db2df5a4c70ba84f1a179efb8006.


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

Branch: refs/heads/branch-2.2
Commit: a8b8ef9dd6d7bd14d4d58caf5fa41cf6d20e091f
Parents: 9d630dc
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Mon Apr 11 23:32:46 2016 -0400
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Mon Apr 11 23:32:46 2016 -0400

----------------------------------------------------------------------
 .../server/actionmanager/ActionScheduler.java   | 13 ++--
 .../actionmanager/TestActionScheduler.java      | 75 ++++++++++----------
 2 files changed, 41 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a8b8ef9d/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java
index 67882e8..c05e50b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java
@@ -881,15 +881,10 @@ class ActionScheduler implements Runnable {
     return false;
   }
 
-  boolean wasAgentRestartedDuringOperation(Host host, Stage stage, String role) {
-    if (host == null) {
-      // null host is valid in case of server action, skip restart detection
-      return false;
-    } else {
-      String hostName = host.getHostName();
-      long lastStageAttemptTime = stage.getLastAttemptTime(hostName, role);
-      return lastStageAttemptTime > 0 && lastStageAttemptTime <= host.getLastRegistrationTime();
-    }
+  protected boolean wasAgentRestartedDuringOperation(Host host, Stage stage, String role) {
+    String hostName = (null == host) ? null : host.getHostName();
+    long lastStageAttemptTime = stage.getLastAttemptTime(hostName, role);
+    return lastStageAttemptTime > 0 && lastStageAttemptTime <= host.getLastRegistrationTime();
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/a8b8ef9d/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java
index 9cecd98..0ee0c27 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java
@@ -113,11 +113,6 @@ public class TestActionScheduler {
       + " c6402.ambari.apache.org], slave_hosts=[c6401.ambari.apache.org,"
       + " c6402.ambari.apache.org]}";
 
-  // HOST_LAST_REGISTRATION_TIME should be less than STAGE_LAST_ATTEMPT_TIME
-  // This means that there was not ambari-agent restart during stage execution
-  public static final long HOST_LAST_REGISTRATION_TIME = 99L;
-  public static final long STAGE_LAST_ATTEMPT_TIME = 100L;
-
   private static Injector injector;
 
   private final String hostname = "ahost.ambari.apache.org";
@@ -964,8 +959,10 @@ public class TestActionScheduler {
 
     Properties properties = new Properties();
     Configuration conf = new Configuration(properties);
-    ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3,
-            new HostsMap((String) null), unitOfWork, null, conf);
+    ActionScheduler scheduler = spy(new ActionScheduler(100, 50, db, aq, fsm, 3,
+            new HostsMap((String) null), unitOfWork, null, conf));
+
+    doReturn(false).when(scheduler).wasAgentRestartedDuringOperation(any(Host.class), any(Stage.class), anyString());
 
     scheduler.doWork();
 
@@ -1052,9 +1049,12 @@ public class TestActionScheduler {
     Properties properties = new Properties();
     properties.put(Configuration.PARALLEL_STAGE_EXECUTION_KEY, "false");
     Configuration conf = new Configuration(properties);
-    ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3,
+    ActionScheduler scheduler = spy(new ActionScheduler(100, 50, db, aq, fsm, 3,
             new HostsMap((String) null),
-            unitOfWork, null, conf);
+            unitOfWork, null, conf));
+
+
+    doReturn(false).when(scheduler).wasAgentRestartedDuringOperation(any(Host.class), any(Stage.class), anyString());
 
     scheduler.doWork();
 
@@ -1123,9 +1123,11 @@ public class TestActionScheduler {
     Properties properties = new Properties();
     properties.put(Configuration.PARALLEL_STAGE_EXECUTION_KEY, "true");
     Configuration conf = new Configuration(properties);
-    ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3,
+    ActionScheduler scheduler = spy(new ActionScheduler(100, 50, db, aq, fsm, 3,
         new HostsMap((String) null),
-        unitOfWork, null, conf);
+        unitOfWork, null, conf));
+
+    doReturn(false).when(scheduler).wasAgentRestartedDuringOperation(any(Host.class), any(Stage.class), anyString());
 
     scheduler.doWork();
 
@@ -2305,41 +2307,39 @@ public class TestActionScheduler {
 
     final List<Stage> stagesInProgress = new ArrayList<Stage>();
     int namenodeCmdTaskId = 1;
-    Stage stageInProgress1 = spy(getStageWithSingleTask(
-      hostname1, "cluster1", Role.NAMENODE, RoleCommand.START,
-      Service.Type.HDFS, namenodeCmdTaskId, 1, (int) requestId1));
-    Stage stageInProgress2 = spy(getStageWithSingleTask(
-      hostname1, "cluster1", Role.DATANODE, RoleCommand.START,
-      Service.Type.HDFS, 2, 2, (int) requestId1));
-    Stage stageInProgress3 = spy(getStageWithSingleTask(
-      hostname2, "cluster1", Role.DATANODE, RoleCommand.STOP, //Exclusive
-      Service.Type.HDFS, 3, 3, (int) requestId2));
-    Stage stageInProgress4 = spy(getStageWithSingleTask(
-      hostname3, "cluster1", Role.DATANODE, RoleCommand.START,
-      Service.Type.HDFS, 4, 4, (int) requestId3));
-    stagesInProgress.add(stageInProgress1);
-    stagesInProgress.add(stageInProgress2);
-    stagesInProgress.add(stageInProgress3);
-    stagesInProgress.add(stageInProgress4);
+    stagesInProgress.add(
+            getStageWithSingleTask(
+                    hostname1, "cluster1", Role.NAMENODE, RoleCommand.START,
+                    Service.Type.HDFS, namenodeCmdTaskId, 1, (int) requestId1));
+    stagesInProgress.add(
+            getStageWithSingleTask(
+                    hostname1, "cluster1", Role.DATANODE, RoleCommand.START,
+                    Service.Type.HDFS, 2, 2, (int) requestId1));
+    stagesInProgress.add(
+            getStageWithSingleTask(
+                    hostname2, "cluster1", Role.DATANODE, RoleCommand.STOP, //Exclusive
+                    Service.Type.HDFS, 3, 3, (int) requestId2));
+
+    stagesInProgress.add(
+            getStageWithSingleTask(
+                    hostname3, "cluster1", Role.DATANODE, RoleCommand.START,
+                    Service.Type.HDFS, 4, 4, (int) requestId3));
 
 
     Host host1 = mock(Host.class);
     when(fsm.getHost(anyString())).thenReturn(host1);
     when(host1.getState()).thenReturn(HostState.HEALTHY);
     when(host1.getHostName()).thenReturn(hostname);
-    when(host1.getLastRegistrationTime()).thenReturn(HOST_LAST_REGISTRATION_TIME);
 
     Host host2 = mock(Host.class);
     when(fsm.getHost(anyString())).thenReturn(host2);
     when(host2.getState()).thenReturn(HostState.HEALTHY);
     when(host2.getHostName()).thenReturn(hostname);
-    when(host2.getLastRegistrationTime()).thenReturn(HOST_LAST_REGISTRATION_TIME);
 
     Host host3 = mock(Host.class);
     when(fsm.getHost(anyString())).thenReturn(host3);
     when(host3.getState()).thenReturn(HostState.HEALTHY);
     when(host3.getHostName()).thenReturn(hostname);
-    when(host3.getLastRegistrationTime()).thenReturn(HOST_LAST_REGISTRATION_TIME);
 
     ActionDBAccessor db = mock(ActionDBAccessor.class);
     when(db.getCommandsInProgressCount()).thenReturn(stagesInProgress.size());
@@ -2415,13 +2415,10 @@ public class TestActionScheduler {
     Properties properties = new Properties();
     Configuration conf = new Configuration(properties);
 
-    ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3,
-        new HostsMap((String) null), unitOfWork, null, conf);
+    ActionScheduler scheduler = spy(new ActionScheduler(100, 50, db, aq, fsm, 3,
+        new HostsMap((String) null), unitOfWork, null, conf));
 
-    doReturn(STAGE_LAST_ATTEMPT_TIME).when(stageInProgress1).getLastAttemptTime(anyString(), anyString());
-    doReturn(STAGE_LAST_ATTEMPT_TIME).when(stageInProgress2).getLastAttemptTime(anyString(), anyString());
-    doReturn(STAGE_LAST_ATTEMPT_TIME).when(stageInProgress3).getLastAttemptTime(anyString(), anyString());
-    doReturn(STAGE_LAST_ATTEMPT_TIME).when(stageInProgress4).getLastAttemptTime(anyString(), anyString());
+    doReturn(false).when(scheduler).wasAgentRestartedDuringOperation(any(Host.class), any(Stage.class), anyString());
 
     // Execution of request 1
 
@@ -2618,8 +2615,10 @@ public class TestActionScheduler {
       }
     }).when(db).abortOperation(anyLong());
 
-    ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3,
-        new HostsMap((String) null), unitOfWork, null, conf);
+    ActionScheduler scheduler = spy(new ActionScheduler(100, 50, db, aq, fsm, 3,
+        new HostsMap((String) null), unitOfWork, null, conf));
+
+    doReturn(false).when(scheduler).wasAgentRestartedDuringOperation(any(Host.class), any(Stage.class), anyString());
 
     scheduler.doWork();