You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by om...@apache.org on 2012/05/11 16:40:05 UTC

svn commit: r1337185 - in /incubator/ambari/branches/ambari-186: CHANGES.txt hmc/php/frontend/addNodes/obtainNodesInfo.php hmc/php/frontend/addNodes/verifyAndUpdateNodesInfo.php

Author: omalley
Date: Fri May 11 14:40:05 2012
New Revision: 1337185

URL: http://svn.apache.org/viewvc?rev=1337185&view=rev
Log:
AMBARI-196. Support capturing os information correctly during node 
discovery. (hitesh via omalley)

Modified:
    incubator/ambari/branches/ambari-186/CHANGES.txt
    incubator/ambari/branches/ambari-186/hmc/php/frontend/addNodes/obtainNodesInfo.php
    incubator/ambari/branches/ambari-186/hmc/php/frontend/addNodes/verifyAndUpdateNodesInfo.php

Modified: incubator/ambari/branches/ambari-186/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/CHANGES.txt?rev=1337185&r1=1337184&r2=1337185&view=diff
==============================================================================
--- incubator/ambari/branches/ambari-186/CHANGES.txt (original)
+++ incubator/ambari/branches/ambari-186/CHANGES.txt Fri May 11 14:40:05 2012
@@ -2,6 +2,9 @@ Ambari Change log
 
 Release 0.x.x - unreleased
 
+  AMBARI-196. Support capturing os information correctly during node 
+  discovery. (hitesh via omalley)
+
   AMBARI-203. Fix for duplicate jdk definition (ramya via omalley)
 
   AMBARI-202. Add check to verify jdk path after install (ramya via vgogate)

Modified: incubator/ambari/branches/ambari-186/hmc/php/frontend/addNodes/obtainNodesInfo.php
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/hmc/php/frontend/addNodes/obtainNodesInfo.php?rev=1337185&r1=1337184&r2=1337185&view=diff
==============================================================================
--- incubator/ambari/branches/ambari-186/hmc/php/frontend/addNodes/obtainNodesInfo.php (original)
+++ incubator/ambari/branches/ambari-186/hmc/php/frontend/addNodes/obtainNodesInfo.php Fri May 11 14:40:05 2012
@@ -20,12 +20,16 @@ function getCommandLine() {
   $freeCmd = "free -m | sed \\\"1 d\\\" | awk '{ print \\\$2 }' | sed -n 1p ;";
   $cpuCmd = "grep -c processor /proc/cpuinfo ;";
   $archCmd = "uname -m ;";
-  $mntPointCmd = "df -lkh | sed \\\"1 d\\\" | grep -vw \\\"/boot\\\" | grep -vw \\\"/dev\/shm\\\" | grep -vw \\\"/home\\\" | grep -vw \/ | awk '{ print \\\$(NF)}' ;";
-  $osTypeCmd = "ls -a /etc/*release | grep -o 'redhat\|Suse' ;";
-  $osInfoCmd = 'cat `ls /etc/*release | grep "redhat\|SuSE"` ;';
+  $mntPointCmd = "df -lkh | sed \\\"1 d\\\" | grep -vw \\\"/boot\\\" | grep -vw \\\"/dev\/shm\\\" | grep -vw \\\"/home\\\" | grep -vw \/ | awk '{ print \\\$(NF)}' ; ";
+  $osTypeCmd = "if [ -f /usr/bin/lsb_release ] ; then lsb_release -si | tr '[:upper:]' '[:lower:]' | cut -d ' ' -f 1; lsb_release -sr | cut -d . -f 1; "
+      . "else cat \\`ls /etc/*release | grep \\\"redhat\|SuSE\\\"\\` | head -1 | awk '{ first=\\\"\\\"; ver=\\\"\\\"; for(i=1; i<=NF; i++) { if ( i == 1 ) print \\\$i; if ( \\\$i ~ /[0-9]+/ ) { print \\\$i; break; } } }' | tr '[:upper:]' '[:lower:]' ; "
+      . "fi ; ";
+  $osInfoCmd = "if [ -f /usr/bin/lsb_release ] ; then lsb_release -sd | tr '\\\"' ' '; "
+      . " else cat \\`ls /etc/*release | grep \\\"redhat\|SuSE\\\"\\` | head -1 ; "
+      . " fi; uname -a ; ";
   $ipCmd = "hostname -i ;";
-  $publicDnsCmd = "curl --connect-timeout 3 -f -s http://169.254.169.254/latest/meta-data/public-hostname && echo \"\" || hostname ;";
-  $privateDnsCmd = "curl --connect-timeout 3 -f -s http://169.254.169.254/latest/meta-data/local-hostname && echo \"\" || hostname ;";
+  $publicDnsCmd = "curl --connect-timeout 3 -f -s http://169.254.169.254/latest/meta-data/public-hostname && echo '' || hostname ;";
+  $privateDnsCmd = "curl --connect-timeout 3 -f -s http://169.254.169.254/latest/meta-data/local-hostname && echo '' || hostname ;";
 
   $cmdLine = $freeCmd.$echoCmd.$cpuCmd.$echoCmd.$archCmd.$echoCmd.$mntPointCmd.$echoCmd.$osTypeCmd.$echoCmd.$osInfoCmd.$echoCmd.$ipCmd.$echoCmd.$publicDnsCmd.$echoCmd.$privateDnsCmd.$echoCmd;
 

Modified: incubator/ambari/branches/ambari-186/hmc/php/frontend/addNodes/verifyAndUpdateNodesInfo.php
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/hmc/php/frontend/addNodes/verifyAndUpdateNodesInfo.php?rev=1337185&r1=1337184&r2=1337185&view=diff
==============================================================================
--- incubator/ambari/branches/ambari-186/hmc/php/frontend/addNodes/verifyAndUpdateNodesInfo.php (original)
+++ incubator/ambari/branches/ambari-186/hmc/php/frontend/addNodes/verifyAndUpdateNodesInfo.php Fri May 11 14:40:05 2012
@@ -35,14 +35,16 @@ mkdir($outputDir);
 $allHosts = array();
 $allBadHosts = array();
 
-function updateStatusForNode ($outDir, $nodeName, $status)
+function updateStatusForNode ($outDir, $nodeName, $status, $error = "")
 {
   global $logger;
 
   $outArray = array();
   $doneFileName = $outDir . $nodeName . ".done";
   $outFileName = $outDir . $nodeName . ".out";
-  $logger->log_debug("out file name is $doneFileName");
+  $errFileName = $outDir . $nodeName . ".err";
+
+  $logger->log_debug("done file name is $doneFileName");
   $fd = fopen($doneFileName, "w");
   if ($fd == FALSE) {
     $outArray['success'] = FALSE;
@@ -63,7 +65,7 @@ function updateStatusForNode ($outDir, $
   $fd = fopen($outFileName, "w");
   if ($fd == FALSE) {
     $outArray['success'] = FALSE;
-    $outArray['reason'] = "Failed to update out status: $status for node: $nodeName";
+    $outArray['reason'] = "Failed to write out status: $status for node: $nodeName";
     return $outArray;
   }
 
@@ -76,12 +78,30 @@ function updateStatusForNode ($outDir, $
   }
   fclose($fd);
 
+  if ($status != 0) {
+    $fd = fopen($errFileName, "w");
+    if ($fd == FALSE) {
+      $outArray['success'] = FALSE;
+      $outArray['reason'] = "Failed to write err info: $error for node: $nodeName";
+      return $outArray;
+    }
+
+    $retval = fwrite($fd, $error);
+    if ($retval == FALSE) {
+      $outArray['success'] = FALSE;
+      $outArray['reason'] = "Failed to write err info: $error for node: $nodeName";
+    } else {
+      $outArray['success'] = TRUE;
+    }
+    fclose($fd);
+  }
+
   return $outArray;
 }
 
-function updateFailedStatusForNode ($outDir, $nodeName)
+function updateFailedStatusForNode ($outDir, $nodeName, $error)
 {
-  return updateStatusForNode($outDir, $nodeName, 255);
+  return updateStatusForNode($outDir, $nodeName, 255, $error);
 }
 
 function updateSuccessStatusForNode ($outDir, $nodeName)
@@ -121,34 +141,38 @@ function populateVal ($line, $count, $ar
   switch ($count)
   {
   case 0:
-    $arr["totalMem"] = rtrim($line);
+    $arr["totalMem"] = trim($line);
     break;
 
   case 1:
-    $arr["cpuCount"] = rtrim($line);
+    $arr["cpuCount"] = trim($line);
     break;
 
   case 2:
-    $arr["osArch"] = rtrim($line);
+    $arr["osArch"] = trim($line);
     break;
 
   case 3:
-    $arr["disksInfo"][] = rtrim($line);
+    $arr["disksInfo"][] = trim($line);
     break;
 
   case 4:
-    $arr["osType"] = rtrim($line);
+    if (!isset($arr["osType"])) {
+      $arr["osType"] = "";
+    }
+    $arr["osType"] .= trim($line);
     break;
-
   case 5:
     if (!isset($arr["os"])) {
       $arr["os"] = "";
     }
-    $arr["os"] = $arr["os"] . " " . rtrim($line);
+    if ($arr["os"] != "") {
+      $arr["os"] .= ";";
+    }
+    $arr["os"] .= trim($line);
     break;
-
   case 6:
-    $arr["ip"] = rtrim($line);
+    $arr["ip"] = trim($line);
     break;
   case 7:
     if (!isset($arr["attributes"])) {
@@ -193,14 +217,16 @@ if ($dirHandle = opendir($prevOutputDir)
         $failedCount += 1;
         $nodeStatus = "FAILED";
         $finalOpStatus = "FAILED";
-        updateFailedStatusForNode($outputDir, $nodeName);
+        updateFailedStatusForNode($outputDir, $nodeName,
+            "Command to discover node information failed, exit_code=" . $doneFileContents);
         $logger->log_debug( "Contents of done file for $clusterName : $doneFileContents");
       }
     } else {
       $failedCount += 1;
       $nodeStatus = "FAILED";
       $finalOpStatus = "FAILED";
-      updateFailedStatusForNode($outputDir, $nodeName);
+      updateFailedStatusForNode($outputDir, $nodeName,
+          "Command to discover node information failed, no exit code found");
       $logger->log_debug("Update failed because file contents of $doneFile is empty");
     }
 
@@ -225,6 +251,8 @@ if ($dirHandle = opendir($prevOutputDir)
         $thisHostArray["badHealthReason"] = "No data obtained for host";
         $finalOpStatus = "FAILED";
         $nodeStatus = "FAILED";
+        updateFailedStatusForNode($outputDir, $nodeName,
+            $thisHostArray["badHealthReason"]);
       } else {
         $goodReturnValCount = 0;
         while (!feof($hostOutFd)) {
@@ -238,7 +266,8 @@ if ($dirHandle = opendir($prevOutputDir)
             $thisHostArray["badHealthReason"] = getBadNodeReason($goodReturnValCount);
             $finalOpStatus = "FAILED";
             $nodeStatus = "FAILED";
-            updateFailedStatusForNode($outputDir, $nodeName);
+            updateFailedStatusForNode($outputDir, $nodeName,
+                $thisHostArray["badHealthReason"]);
             // write to file if bad so as to be shown as json in frontend.
             array_push($badHostsList, $thisHostArray);
             break;
@@ -250,6 +279,17 @@ if ($dirHandle = opendir($prevOutputDir)
       }
 
       if ($nodeStatus == "SUCCESS") {
+        if ($thisHostArray["osType"] != "redhatenterpriseserver5"
+            && $thisHostArray["osType"] != "centos5") {
+          $thisHostArray["badHealthReason"] = "Unsupported OS";
+          $finalOpStatus = "FAILED";
+          $nodeStatus = "FAILED";
+          updateFailedStatusForNode($outputDir, $nodeName,
+              $thisHostArray["badHealthReason"]);
+        }
+      }
+
+      if ($nodeStatus == "SUCCESS") {
         $successCount += 1;
         updateSuccessStatusForNode($outputDir, $nodeName);
       }