uninstall.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 "../util/util.php";
  27. include_once '../db/HMCDBAccessor.php';
  28. include_once "../orchestrator/HMC.php";
  29. include_once "../db/OrchestratorDB.php";
  30. include_once "../puppet/DBReader.php";
  31. include_once "../puppet/PuppetInvoker.php";
  32. include_once "../util/clusterState.php";
  33. $dbPath = $GLOBALS["DB_PATH"];
  34. $clusterName = $_GET['clusterName'];
  35. /* For returning in our JSON at the very end. */
  36. $result = 0;
  37. $error = "";
  38. $txnId = -1;
  39. $deployUser = "";
  40. $logger = new HMCLogger("Uninstall");
  41. $dbAccessor = new HMCDBAccessor($dbPath);
  42. $clusterStateResponse = $dbAccessor->getClusterState($clusterName);
  43. if ($clusterStateResponse['result'] != 0) {
  44. print json_encode($clusterStateResponse);
  45. return;
  46. }
  47. $clusterState = json_decode($clusterStateResponse['state'], true);
  48. /* Run an actual uninstall only if this cluster is in a deployed state
  49. * (regardless of whether the deploy was a success or failure).
  50. */
  51. if ($clusterState['state'] == 'DEPLOYED') {
  52. $logger->log_info("Uninstall invoked");
  53. $action = $_GET['action'];
  54. $deployUser = $_GET['clusterDeployUser'];
  55. $wipeout = FALSE;
  56. if ($action == "wipeOut") {
  57. $wipeout = TRUE;
  58. } else {
  59. $wipeout = FALSE;
  60. }
  61. ////// need to generate the hosts.txt file with all the good nodes in the cluster
  62. $allHostsInfo = $dbAccessor->getAllHostsInfo($clusterName,
  63. array("=" => array ( "discoveryStatus" => "SUCCESS")));
  64. if ($allHostsInfo["result"] != 0 ) {
  65. $logger->log_error("Got error while getting hostsInfo ".$allHostsInfo["error"]);
  66. print json_encode($allHostsInfo);
  67. return;
  68. }
  69. $hostFileName = getHostsFilePath($clusterName);
  70. $hostFileHdl = fopen($hostFileName, "w");
  71. foreach ($allHostsInfo["hosts"] as $hostInfo) {
  72. fwrite($hostFileHdl, $hostInfo["hostName"]."\n");
  73. }
  74. fclose($hostFileHdl);
  75. ////// end of generating new file
  76. $logger->log_info("Uninstall got wipeout value $wipeout");
  77. // call the wipeout script and return the transaction id
  78. $hmc = new HMC($dbPath, $clusterName);
  79. $uninstallResult = $hmc->uninstallHDP($wipeout);
  80. if ($uninstallResult["result"] != 0) {
  81. print json_encode($uninstallResult);
  82. return;
  83. }
  84. if (!isset($uninstallResult["txnId"])) {
  85. print json_encode ( array("result" => 1, "error" => "Could not obtain txn info for triggered command"));
  86. return;
  87. }
  88. $txnId = $uninstallResult["txnId"];
  89. /* (And when we kick off the uninstall is the only time to update the state
  90. * of the cluster).
  91. */
  92. $state = "UNINSTALLATION_IN_PROGRESS";
  93. $displayName = "Uninstallation in progress";
  94. $context = array (
  95. 'txnId' => $txnId,
  96. 'deployUser' => $deployUser
  97. );
  98. $retval = updateClusterState($clusterName, $state, $displayName, $context);
  99. if ($retval['result'] != 0) {
  100. $result = $retval['result'];
  101. $error = $retval['error'];
  102. }
  103. }
  104. /* In case the uninstall is already running or has ended, just return the txnId
  105. * and deployUser from the DB instead of kicking off a fresh uninstall - this
  106. * is so we can use this entrypoint to show the cluster's uninstall progress at
  107. * any time in the future, not just during a live uninstall.
  108. */
  109. elseif ($clusterState['state'] == 'UNINSTALLATION_IN_PROGRESS') {
  110. $txnId = $clusterState['context']['txnId'];
  111. $deployUser = $clusterState['context']['deployUser'];
  112. }
  113. /* Create the output data... */
  114. $jsonOutput = array(
  115. 'clusterName' => $clusterName,
  116. 'txnId' => $txnId,
  117. 'deployUser' => $deployUser
  118. );
  119. /* ...and spit it out. */
  120. header("Content-type: application/json");
  121. print (json_encode(array("result" => $result, "error" => $error, "response" => $jsonOutput)));
  122. ?>