deploy.php 4.1 KB

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