obtainNodesInfo.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. include_once '../util/Logger.php';
  3. include_once '../conf/Config.inc';
  4. include_once 'localDirs.php';
  5. include_once "../util/lock.php";
  6. include_once '../db/HMCDBAccessor.php';
  7. include_once 'commandUtils.php';
  8. include_once '../util/util.php';
  9. $logger = new HMCLogger("obtainNodesInfo");
  10. $dbAccessor = new HMCDBAccessor($GLOBALS["DB_PATH"]);
  11. $lineSeparatorPattern = "HDP-------HDP";
  12. function getCommandLine() {
  13. global $lineSeparatorPattern;
  14. $echoCmd = "echo ".$lineSeparatorPattern."$? ;";
  15. $freeCmd = "free -m | sed \\\"1 d\\\" | awk '{ print \\\$2 }' | sed -n 1p ;";
  16. $cpuCmd = "grep -c processor /proc/cpuinfo ;";
  17. $archCmd = "uname -m ;";
  18. $mntPointCmd = "df -lkh | sed \\\"1 d\\\" | grep -vw \\\"/boot\\\" | grep -vw \\\"/dev\/shm\\\" | grep -vw \\\"/home\\\" | grep -vw \/ | awk '{ print \\\$(NF)}' ; ";
  19. $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; "
  20. . "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:]' ; "
  21. . "fi ; ";
  22. $osInfoCmd = "if [ -f /usr/bin/lsb_release ] ; then lsb_release -sd | tr '\\\"' ' '; "
  23. . " else cat \\`ls /etc/*release | grep \\\"redhat\|SuSE\\\"\\` | head -1 ; "
  24. . " fi; uname -a ; ";
  25. $ipCmd = "hostname -i ;";
  26. $publicDnsCmd = "curl --connect-timeout 3 -f -s http://169.254.169.254/latest/meta-data/public-hostname && echo '' || hostname ;";
  27. $privateDnsCmd = "curl --connect-timeout 3 -f -s http://169.254.169.254/latest/meta-data/local-hostname && echo '' || hostname ;";
  28. $cmdLine = $freeCmd.$echoCmd.$cpuCmd.$echoCmd.$archCmd.$echoCmd.$mntPointCmd.$echoCmd.$osTypeCmd.$echoCmd.$osInfoCmd.$echoCmd.$ipCmd.$echoCmd.$publicDnsCmd.$echoCmd.$privateDnsCmd.$echoCmd;
  29. // uncomment following line for demo purposes.
  30. // $cmdLine = $cmdLine . 'sleep $[ $RANDOM % 5 ]; ';
  31. return $cmdLine;
  32. }
  33. $clusterName = $argv[1];
  34. $deployUser = $argv[2];
  35. $rootTxnId = $argv[3];
  36. $mySubTxnId = $argv[4];
  37. $parentSubTxnId = $argv[5];
  38. $readFromFile = $argv[6];
  39. $opStatus = "STARTED";
  40. $subTransactionReturnValue = $dbAccessor->updateSubTransactionOpStatus($clusterName, $parentSubTxnId, $mySubTxnId, $opStatus);
  41. if ($subTransactionReturnValue["result"] != 0 ) {
  42. $logger->log_error("Got error while updating subTxn: ".$subTransactionReturnValue["error"]);
  43. print json_encode($subTransactionReturnValue);
  44. return;
  45. }
  46. $stageName = "obtainNodesInfo";
  47. $cmdLine = getCommandLine();
  48. $hosts = explode(",", $hostsStr);
  49. runPdsh($clusterName, $stageName, $deployUser, $readFromFile, $cmdLine);
  50. $finalOpStatus = "SUCCESS";
  51. $subTransactionReturnValue = $dbAccessor->updateSubTransactionOpStatus($clusterName, $parentSubTxnId, $mySubTxnId, $finalOpStatus);
  52. if ($subTransactionReturnValue["result"] != 0 ) {
  53. $logger->log_error("Got error while updating subTxn: ".$subTransactionReturnValue["error"]);
  54. print json_encode($subTransactionReturnValue);
  55. return;
  56. }
  57. ?>