nodesActionProgress.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. $logger = new HMCLogger("Add nodes poller");
  8. $clusterName = $_GET['clusterName'];
  9. $action = $_GET['action'];
  10. $rootTxnId = $_GET['txnId'];
  11. $stagesFiles = "";
  12. if ($action == "addNodes") {
  13. $stagesFile = "./addNodes/stages.php";
  14. } else if ($action == "uninstall") {
  15. $stagesFile = "./uninstall/stages.php";
  16. } else {
  17. print (json_encode(array(
  18. "result" => 1,
  19. "error" => "Invalid action",
  20. )
  21. ));
  22. return;
  23. }
  24. include_once $stagesFile;
  25. header("Content-type: application/json");
  26. $logger->log_debug("Cluster Name: $clusterName Root Txn ID: $rootTxnId");
  27. $progressStates = array();
  28. foreach ($stagesInfo as $stage => $stageInfo) {
  29. array_push($progressStates, $stageInfo["description"]);
  30. }
  31. $jsonOutput = array (
  32. 'progressStates'=> $progressStates,
  33. 'currentProgressStateIndex' => 0, // by default is state Sshable
  34. 'encounteredError' => false,
  35. 'stateInfo' => array(),
  36. );
  37. // use the txn id for finding the status to pass back to the user
  38. // the orchestrator txn id could potentially return an error because
  39. // there is a potential race condition before the orchestrator txnId has
  40. // been committed to the db by the backgrounded process.
  41. $dbHandle = new HMCDBAccessor($GLOBALS["DB_PATH"]);
  42. $orchestratorTxnId = $dbHandle->getAllSubTransactionsInfo(
  43. $clusterName, $rootTxnId);
  44. if ($orchestratorTxnId['result'] != 0) { // encountered error
  45. $logger->log_error("Empty orchestrator txn id " .
  46. json_encode($orchestratorTxnId));
  47. // Check if this should return error FIXME
  48. // $jsonOutput['encounteredError'] = true;
  49. print json_encode($jsonOutput);
  50. return;
  51. }
  52. //$logger->log_error(" ==== subTxns info is " . json_encode($orchestratorTxnId));
  53. $keys = array_keys($orchestratorTxnId['subTxns']);
  54. if (count($keys) == 0) {
  55. print json_encode($jsonOutput);
  56. $logger->log_debug("No keys found in orchestrator's child transactions");
  57. return;
  58. }
  59. $firstKey = $keys[0];
  60. if ($firstKey == '') {
  61. print json_encode($jsonOutput);
  62. return;
  63. }
  64. $allSubTxns = $dbHandle->getAllSubTransactionsInfo(
  65. $clusterName, $firstKey);
  66. // the all sub txn ids could potentially return an error because
  67. // there is a potential race condition before the orchestrator's subTxnId has
  68. // been committed to the db by the backgrounded process.
  69. if ($allSubTxns['result'] != 0) {
  70. $logger->log_error("Empty orchestrator txn id " .
  71. json_encode($allSubTxns));
  72. print json_encode($jsonOutput);
  73. exit(0);
  74. }
  75. $jsonOutput['currentProgressStateIndex'] = count($allSubTxns['subTxns']) - 1;
  76. if ($jsonOutput['currentProgressStateIndex'] < 0) {
  77. $jsonOutput['currentProgressStateIndex'] = 0;
  78. }
  79. $jsonOutput['stateInfo'] = $allSubTxns;
  80. // Decode log information store as part of state.
  81. foreach ($jsonOutput['stateInfo']['subTxns'] as $subTxnId => $subTxnInfo) {
  82. $jsonOutput['stateInfo']['subTxns'][$subTxnId]['state'] = json_decode($jsonOutput['stateInfo']['subTxns'][$subTxnId]['state'], true);
  83. }
  84. print json_encode($jsonOutput);
  85. ?>