nodesActionProgress.php 3.9 KB

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