obtainNodesInfo.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /*
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one
  5. * or more contributor license agreements. See the NOTICE file
  6. * distributed with this work for additional information
  7. * regarding copyright ownership. The ASF licenses this file
  8. * to you under the Apache License, Version 2.0 (the
  9. * "License"); you may not use this file except in compliance
  10. * with the License. You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing,
  15. * software distributed under the License is distributed on an
  16. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17. * KIND, either express or implied. See the License for the
  18. * specific language governing permissions and limitations
  19. * under the License.
  20. *
  21. */
  22. include_once '../util/Logger.php';
  23. include_once '../conf/Config.inc';
  24. include_once 'localDirs.php';
  25. include_once "../util/lock.php";
  26. include_once '../db/HMCDBAccessor.php';
  27. include_once 'commandUtils.php';
  28. include_once '../util/util.php';
  29. $logger = new HMCLogger("obtainNodesInfo");
  30. $dbAccessor = new HMCDBAccessor($GLOBALS["DB_PATH"]);
  31. $lineSeparatorPattern = "HDP-------HDP";
  32. function getCommandLine() {
  33. global $lineSeparatorPattern;
  34. $echoCmd = "echo ".$lineSeparatorPattern."$? ;";
  35. $freeCmd = "free -m | sed \\\"1 d\\\" | awk '{ print \\\$2 }' | sed -n 1p ;";
  36. $cpuCmd = "grep -c processor /proc/cpuinfo ;";
  37. $archCmd = "uname -m ;";
  38. $mntPointCmd = "df -lkh | sed \\\"1 d\\\" | grep -vw \\\"/boot\\\" | grep -vw \\\"/dev\/shm\\\" | grep -vw \\\"/home\\\" | grep -vw \/ | awk '{ print \\\$(NF)}' ; ";
  39. $osTypeCmd = "if [ -f /usr/bin/lsb_release ] ; then lsb_release -sd | tr '[:upper:]' '[:lower:]' | tr '\\\"' ' ' | awk '{ for(i=1; i<=NF; i++) { print \\\$i; print '\\n'; if ( \\\$i ~ /[0-9]+/ ) { break; } } }' ; "
  40. . "else cat \\`ls /etc/*release | grep \\\"redhat\|SuSE\\\"\\` | head -1 | awk '{ for(i=1; i<=NF; i++) { print \\\$i; print '\\n'; if ( \\\$i ~ /[0-9]+/ ) { break; } } }' | tr '[:upper:]' '[:lower:]' ; "
  41. . "fi ; ";
  42. $osInfoCmd = "if [ -f /usr/bin/lsb_release ] ; then lsb_release -sd | tr '\\\"' ' '; "
  43. . " else cat \\`ls /etc/*release | grep \\\"redhat\|SuSE\\\"\\` | head -1 ; "
  44. . " fi; uname -a ; ";
  45. $ipCmd = "hostname -i ;";
  46. $publicDnsCmd = "curl --connect-timeout 3 -f -s http://169.254.169.254/latest/meta-data/public-hostname && echo '' || hostname ;";
  47. $privateDnsCmd = "curl --connect-timeout 3 -f -s http://169.254.169.254/latest/meta-data/local-hostname && echo '' || hostname ;";
  48. $cmdLine = $freeCmd.$echoCmd.$cpuCmd.$echoCmd.$archCmd.$echoCmd.$mntPointCmd.$echoCmd.$osTypeCmd.$echoCmd.$osInfoCmd.$echoCmd.$ipCmd.$echoCmd.$publicDnsCmd.$echoCmd.$privateDnsCmd.$echoCmd;
  49. // uncomment following line for demo purposes.
  50. // $cmdLine = $cmdLine . 'sleep $[ $RANDOM % 5 ]; ';
  51. return $cmdLine;
  52. }
  53. $clusterName = $argv[1];
  54. $deployUser = $argv[2];
  55. $rootTxnId = $argv[3];
  56. $mySubTxnId = $argv[4];
  57. $parentSubTxnId = $argv[5];
  58. $readFromFile = $argv[6];
  59. $opStatus = "STARTED";
  60. $subTransactionReturnValue = $dbAccessor->updateSubTransactionOpStatus($clusterName, $parentSubTxnId, $mySubTxnId, $opStatus);
  61. if ($subTransactionReturnValue["result"] != 0 ) {
  62. $logger->log_error("Got error while updating subTxn: ".$subTransactionReturnValue["error"]);
  63. print json_encode($subTransactionReturnValue);
  64. return;
  65. }
  66. $stageName = "obtainNodesInfo";
  67. $cmdLine = getCommandLine();
  68. $hosts = explode(",", $hostsStr);
  69. runPdsh($clusterName, $stageName, $deployUser, $readFromFile, $cmdLine);
  70. $finalOpStatus = "SUCCESS";
  71. $subTransactionReturnValue = $dbAccessor->updateSubTransactionOpStatus($clusterName, $parentSubTxnId, $mySubTxnId, $finalOpStatus);
  72. if ($subTransactionReturnValue["result"] != 0 ) {
  73. $logger->log_error("Got error while updating subTxn: ".$subTransactionReturnValue["error"]);
  74. print json_encode($subTransactionReturnValue);
  75. return;
  76. }
  77. ?>