Repository: ambari
Updated Branches:
  refs/heads/trunk 37434acae -> e3c7dd2c8


AMBARI-5109. BootStrapTest hangs sometimes (dlysnichenko)


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

Branch: refs/heads/trunk
Commit: e3c7dd2c8b507b287ae91910ce65c8aead1bd80f
Parents: 37434ac
Author: Lisnichenko Dmitro <[email protected]>
Authored: Mon Mar 17 18:07:57 2014 +0200
Committer: Lisnichenko Dmitro <[email protected]>
Committed: Mon Mar 17 22:35:27 2014 +0200

----------------------------------------------------------------------
 .../ambari/server/bootstrap/BSRunner.java       | 25 ++++++++++++++------
 .../ambari/server/bootstrap/BootStrapTest.java  | 17 +++++++++----
 2 files changed, 31 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/e3c7dd2c/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BSRunner.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BSRunner.java 
b/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BSRunner.java
index f4ccbca..7795c99 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BSRunner.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BSRunner.java
@@ -258,10 +258,16 @@ class BSRunner extends Thread {
           }
           boolean pendingHosts = false;
           BootStrapStatus tmpStatus = bsImpl.getStatus(requestId);
-          for (BSHostStatus status : tmpStatus.getHostsStatus()) {
-            if (status.getStatus().equals("RUNNING")) {
-              pendingHosts = true;
+          List <BSHostStatus> hostStatusList = tmpStatus.getHostsStatus();
+          if (hostStatusList != null) {
+            for (BSHostStatus status : hostStatusList) {
+              if (status.getStatus().equals("RUNNING")) {
+                pendingHosts = true;
+              }
             }
+          } else {
+            //Failed to get host status, waiting for hosts status to be updated
+            pendingHosts = true;
           }
           if (LOG.isDebugEnabled()) {
             LOG.debug("Whether hosts status yet to be updated, pending="
@@ -302,11 +308,16 @@ class BSRunner extends Thread {
     finally {
       /* get the bstatus */
       BootStrapStatus tmpStatus = bsImpl.getStatus(requestId);
-      for (BSHostStatus hostStatus : tmpStatus.getHostsStatus()) {
-        if ("FAILED".equals(hostStatus.getStatus())) {
-          stat = BSStat.ERROR;
-          break;
+      List <BSHostStatus> hostStatusList = tmpStatus.getHostsStatus();
+      if (hostStatusList != null) {
+        for (BSHostStatus hostStatus : hostStatusList) {
+          if ("FAILED".equals(hostStatus.getStatus())) {
+            stat = BSStat.ERROR;
+            break;
+          }
         }
+      } else {
+        stat = BSStat.ERROR;
       }
       tmpStatus.setLog(scriptlog);
       tmpStatus.setStatus(stat);

http://git-wip-us.apache.org/repos/asf/ambari/blob/e3c7dd2c/ambari-server/src/test/java/org/apache/ambari/server/bootstrap/BootStrapTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/bootstrap/BootStrapTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/bootstrap/BootStrapTest.java
index 9116b9d..34ccf6e 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/bootstrap/BootStrapTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/bootstrap/BootStrapTest.java
@@ -89,7 +89,7 @@ public class BootStrapTest extends TestCase {
     BootStrapStatus status = impl.getStatus(response.getRequestId());
     LOG.info("Status " + status.getStatus());
     int num = 0;
-    while ((status.getStatus() != BSStat.SUCCESS) && (num < 10000)) {
+    while ((status.getStatus() == BSStat.RUNNING) && (num < 500)) {
         status = impl.getStatus(response.getRequestId());
         Thread.sleep(100);
         num++;
@@ -133,15 +133,24 @@ public class BootStrapTest extends TestCase {
         BSResponse response = impl.runBootStrap(info);
         long requestId = response.getRequestId();
         LOG.info("Response id from bootstrap " + requestId);
-    /* create failed done file for host1 */
+    /* create failed done file for host2 */
         File requestDir = new File(bootdir, Long.toString(requestId));
+    /* wait while directory is created */
+        int num = 0;
+        while (!requestDir.exists() && num<500) {
+            Thread.sleep(100);
+            num++;
+        }
+        if (!requestDir.exists()) {
+            LOG.warn("RequestDir does not exists");
+        }
         FileUtils.writeStringToFile(new File(requestDir, "host1.done"), "0");
         FileUtils.writeStringToFile(new File(requestDir, "host2.done"), "1");
     /* do a query */
         BootStrapStatus status = impl.getStatus(response.getRequestId());
         LOG.info("Status " + status.getStatus());
-        int num = 0;
-        while ((status.getStatus() != BSStat.ERROR) && (num < 10000)) {
+        num = 0;
+        while ((status.getStatus() == BSStat.RUNNING) && (num < 500)) {
             status = impl.getStatus(response.getRequestId());
             Thread.sleep(100);
             num++;

Reply via email to