Ver código fonte

AMBARI-479. Add nodes after install does not allow re-bootstrap if user closes browser after bootstrap and before starting services (Contributed by Vikram)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/branches/ambari-186@1347299 13f79535-47bb-0310-9956-ffa450edef68
Vikram Dixit K 13 anos atrás
pai
commit
c5b4e81a0e
4 arquivos alterados com 53 adições e 44 exclusões
  1. 2 0
      CHANGES.txt
  2. 9 9
      hmc/js/addNodes.js
  3. 2 1
      hmc/php/db/HMCDBAccessor.php
  4. 40 34
      hmc/php/frontend/addNodes.php

+ 2 - 0
CHANGES.txt

@@ -6,6 +6,8 @@ characters wide.
 
 
 Release 0.1.x - unreleased
 Release 0.1.x - unreleased
 
 
+  AMBARI-479. Add nodes after install does not allow re-bootstrap if user closes browser after bootstrap and before starting services (Vikram)
+
   AMBARI-477. Spec file for using installer with php-5.3 (Hitesh via Vikram)
   AMBARI-477. Spec file for using installer with php-5.3 (Hitesh via Vikram)
 
 
   AMBARI-478. Checkbox in the review and deploy page does not show proper state (Vikram)
   AMBARI-478. Checkbox in the review and deploy page does not show proper state (Vikram)

+ 9 - 9
hmc/js/addNodes.js

@@ -186,11 +186,7 @@ globalYui.one("#fileUploadTargetId").on('load', function (e) {
 
 
       if (responseJson.result != 0) {
       if (responseJson.result != 0) {
         // This means we hit an error
         // This means we hit an error
-        if (responseJson.result == 2) {
-          hideLoadingImg();
-          setFormStatus(responseJson.error, true);
-          return;
-      } else if (responseJson.result == 3) {
+      if (responseJson.result == 3) {
         info =
         info =
           '<p>' +
           '<p>' +
             responseJson.error + '. ' +
             responseJson.error + '. ' +
@@ -201,11 +197,15 @@ globalYui.one("#fileUploadTargetId").on('load', function (e) {
           setFormStatus(info, true);
           setFormStatus(info, true);
           var infoPanel = createInformationalPanel("#informationalPanelContainerDivId", "Duplicate nodes");
           var infoPanel = createInformationalPanel("#informationalPanelContainerDivId", "Duplicate nodes");
           infoPanel.set('centered', true);
           infoPanel.set('centered', true);
-          var infoPanelContent = '<ul>';
-          for (host in responseJson.hosts) {
-            infoPanelContent += '<li>' + responseJson.hosts[host] + '</li>';
+          var infoPanelContent = '';
+          for (cluster in responseJson.hosts) {
+            infoPanelContent += 'Cluster: <b>' + cluster + '</b><ul>';
+            for (host in responseJson.hosts[cluster]) {
+              infoPanelContent += '<li>' + responseJson.hosts[cluster][host] + '</li>';
+            }
+
+            infoPanelContent += '</ul><br/>';
           }
           }
-          infoPanelContent += '</ul>';
           infoPanel.set('bodyContent', infoPanelContent);
           infoPanel.set('bodyContent', infoPanelContent);
           infoPanel.addButton({
           infoPanel.addButton({
             value: 'Close',
             value: 'Close',

+ 2 - 1
hmc/php/db/HMCDBAccessor.php

@@ -1094,6 +1094,7 @@ class HMCDBAccessor {
       $host["discoveryStatus"] = $entry["discovery_status"];
       $host["discoveryStatus"] = $entry["discovery_status"];
       $host["badHealthReason"] = $entry["bad_health_reason"];
       $host["badHealthReason"] = $entry["bad_health_reason"];
       $host["attributes"] = json_decode($entry["attributes"], true);
       $host["attributes"] = json_decode($entry["attributes"], true);
+      $host["clusterName"] = $entry["cluster_name"];
       array_push($response["hosts"], $host);
       array_push($response["hosts"], $host);
     }
     }
     LockRelease(); return $response;
     LockRelease(); return $response;
@@ -3381,7 +3382,7 @@ class HMCDBAccessor {
       $host["discoveryStatus"] = $entry["discovery_status"];
       $host["discoveryStatus"] = $entry["discovery_status"];
       $host["badHealthReason"] = $entry["bad_health_reason"];
       $host["badHealthReason"] = $entry["bad_health_reason"];
       $host["attributes"] = json_decode($entry["attributes"], true);
       $host["attributes"] = json_decode($entry["attributes"], true);
-      array_push($response["hosts"], $host);
+      array_push($response["hosts"][$host["hostName"]], $host);
     }
     }
     LockRelease(); return $response;
     LockRelease(); return $response;
   }
   }

+ 40 - 34
hmc/php/frontend/addNodes.php

@@ -82,42 +82,48 @@ $logger->log_info("Doing a fresh install: $freshInstall");
 if (!$freshInstall) {
 if (!$freshInstall) {
 
 
   // Get the list of current nodes
   // Get the list of current nodes
-    $allHostsInfoResult = $dbAccessor->getAllHostsInfo($clusterName, array());
-    if ($allHostsInfoResult["result"] != 0 ) {
-      $logger->log_error("Got error while getting hostInfo for $host :" .$allHostsInfoResult["error"]);
-      print json_encode($allHostsInfoResult);
-      return;
-    }
-
-    // See if they are duplicates
-    $newHosts = readHostsFile($hostsFileDestination);
-    $duplicateHosts = array();
-    $logger->log_debug("Checking for Duplicate Hosts.");
-    foreach ($allHostsInfoResult["hosts"] as $hostInfo) {
-      if (in_array($hostInfo["hostName"], $newHosts)) {
-        $duplicateHosts[] = $hostInfo["hostName"];
-      }
-    }
-    $numDupHosts = count($duplicateHosts);
-    $numNewHosts = count($newHosts);
-    if ($numDupHosts != 0) {
-      if ($numNewHosts == $numDupHosts) {
-        print (json_encode(array("result" => 2, "error" => "All the hosts in the given file are already being used in cluster '$clusterName'")));
-      } else {
-        print (json_encode(array("result" => 3, "error" => "Some hosts in the given file are already being used in cluster '$clusterName'", "hosts" => $duplicateHosts)));
-
-        // Just re-edit the hosts' file in case users says go ahead
-        $nodeFileOut = fopen($hostsFileDestination, "w");
-        foreach ($newHosts as $newHost) {
-          if (in_array($newHost, $duplicateHosts)) {
-            continue;
-          }
-          fwrite($nodeFileOut, $newHost."\n");
+  $allHostsInfoResult = $dbAccessor->getAllHostsInfo("", array());
+  if ($allHostsInfoResult["result"] != 0 ) {
+    $logger->log_error("Got error while getting hostInfo for $host :" .$allHostsInfoResult["error"]);
+    print json_encode($allHostsInfoResult);
+    return;
+  }
+
+  $unassignedHostResult = $dbAccessor->getAllUnassignedHosts($clusterName);
+  if ($unassignedHostResult["result"] != 0) {
+    print json_encode($unassignedHostResult);
+    return;
+  }
+
+  $unassignedHostList = $unassignedHostResult["hosts"];
+
+  // See if they are duplicates
+  $newHosts = readHostsFile($hostsFileDestination);
+  $duplicateHosts = array();
+  $logger->log_debug("Checking for Duplicate Hosts.");
+  foreach ($allHostsInfoResult["hosts"] as $hostInfo) {
+    $logger->log_debug("Checking for Duplicate Hosts. hostname = ".
+      $hostInfo["hostName"]. " key does not exist? " . 
+      array_key_exists($hostInfo["hostName"], $unassignedHostList). 
+      " incoming cluster name: $clusterName, host is part of cluster "
+      .$hostInfo["clusterName"]);
+    if (in_array($hostInfo["hostName"], $newHosts) &&
+      (!(array_key_exists($hostInfo["hostName"], $unassignedHostList)) 
+      || ($hostInfo["clusterName"] != $clusterName))) {
+        if (!array_key_exists($hostInfo["clusterName"], $duplicateHosts)) {
+          $duplicateHosts[$hostInfo["clusterName"]] = array();
         }
         }
-        fclose($nodeFileOut);
+
+        array_push($duplicateHosts[$hostInfo["clusterName"]], 
+                   $hostInfo["hostName"]);
       }
       }
-      return;
-    }
+  }
+  $numDupHosts = count($duplicateHosts);
+  $numNewHosts = count($newHosts);
+  if ($numDupHosts != 0) {
+    print (json_encode(array("result" => 3, "error" => "Some hosts in the given file are already being used in cluster", "hosts" => $duplicateHosts)));
+    return;
+  }
 } else {
 } else {
   // Update the state of the cluster.
   // Update the state of the cluster.
   $state = "CONFIGURATION_IN_PROGRESS";
   $state = "CONFIGURATION_IN_PROGRESS";