Selaa lähdekoodia

AMBARI-5109. BootStrapTest hangs sometimes (dlysnichenko)

Lisnichenko Dmitro 11 vuotta sitten
vanhempi
commit
e3c7dd2c8b

+ 18 - 7
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);

+ 13 - 4
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++;