deploy.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 "../orchestrator/HMC.php";
  8. include_once "../db/OrchestratorDB.php";
  9. include_once "../puppet/DBReader.php";
  10. include_once "../puppet/PuppetInvoker.php";
  11. include_once "../util/clusterState.php";
  12. $dbPath = $GLOBALS["DB_PATH"];
  13. $clusterName = $_GET['clusterName'];
  14. $startTime = time();
  15. $hmc = new HMC($dbPath, $clusterName);
  16. /* For returning in our JSON at the very end. */
  17. $result = 0;
  18. $error = "";
  19. $txnId = -1;
  20. $dbAccessor = new HMCDBAccessor($dbPath);
  21. $clusterStateResponse = $dbAccessor->getClusterState($clusterName);
  22. if ($clusterStateResponse['result'] != 0) {
  23. print json_encode($clusterStateResponse);
  24. return;
  25. }
  26. $clusterState = json_decode($clusterStateResponse['state'], true);
  27. /* Run an actual deploy only if this cluster has passed the stage of
  28. * configuring its services (which means the next thing to do is to
  29. * kick off the deploy).
  30. */
  31. if (($clusterState['state'] == 'CONFIGURATION_IN_PROGRESS') &&
  32. ($clusterState['context']['stage'] == 'CONFIGURE_SERVICES')) {
  33. $deployResult = $hmc->deployHDP();
  34. if ($deployResult["result"] != 0) {
  35. print json_encode($deployResult);
  36. return;
  37. }
  38. if (!isset($deployResult["txnId"])) {
  39. print json_encode ( array("result" => 1, "error" => "Could not obtain txn info for triggered command"));
  40. return;
  41. }
  42. $txnId = $deployResult["txnId"];
  43. /* (And when we kick off the deploy is the only time to update the state of the cluster) */
  44. $state = "DEPLOYMENT_IN_PROGRESS";
  45. $displayName = "Deployment in progress";
  46. $context = array (
  47. 'txnId' => $txnId
  48. );
  49. $retval = updateClusterState($clusterName, $state, $displayName, $context);
  50. if ($retval['result'] != 0) {
  51. $result = $retval['result'];
  52. $error = $retval['error'];
  53. }
  54. }
  55. /* In case the deploy is already running or has ended, just return the txnId
  56. * from the DB instead of kicking off a fresh deploy - this is so we can use
  57. * this entrypoint to show the cluster's deploy progress at any time in the
  58. * future, not just during a live deploy.
  59. */
  60. elseif (($clusterState['state'] == 'DEPLOYMENT_IN_PROGRESS') ||
  61. ($clusterState['state'] == 'DEPLOYED')) {
  62. $txnId = $clusterState['context']['txnId'];
  63. }
  64. $thisHostName = trim(strtolower(exec('hostname -f')));
  65. $nagiosGangliaCoHosted = FALSE;
  66. // check if nagios hosted on same server
  67. if (!$nagiosGangliaCoHosted) {
  68. // check if component mapped to this host
  69. $hostMap = $dbAccessor->getHostsForComponent($clusterName, "NAGIOS_SERVER");
  70. if (isset($hostMap["hosts"][$thisHostName])) {
  71. $nagiosGangliaCoHosted = TRUE;
  72. }
  73. }
  74. // if still nothing then check if ganglia server installed on same server
  75. if (!$nagiosGangliaCoHosted) {
  76. // check if component mapped to this host
  77. $hostMap = $dbAccessor->getHostsForComponent($clusterName,
  78. "GANGLIA_MONITOR_SERVER");
  79. if (isset($hostMap["hosts"][$thisHostName])) {
  80. $nagiosGangliaCoHosted = TRUE;
  81. }
  82. }
  83. /* Create the output data... */
  84. $jsonOutput = array(
  85. 'startTime' => $startTime,
  86. 'clusterName' => $clusterName,
  87. 'txnId' => $txnId,
  88. 'nagiosGangliaCoHosted' => $nagiosGangliaCoHosted);
  89. /* ...and spit it out. */
  90. header("Content-type: application/json");
  91. print (json_encode(array("result" => $result, "error" => $error, "response" => $jsonOutput)));
  92. ?>