nodesAction.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 'commandUtils.php';
  8. include_once '../util/clusterState.php';
  9. include_once "../util/HMCTxnUtils.php";
  10. $logger = new HMCLogger("setupNodes");
  11. $dbAccessor = new HMCDBAccessor($GLOBALS["DB_PATH"]);
  12. $clusterName = $_GET['clusterName'];
  13. $action = $_GET['action'];
  14. $deployUser = $_POST['ClusterDeployUser'];
  15. $propertiesArr = $dbAccessor->getConfigPropertiesMetaInfo();
  16. if ($propertiesArr["result"] != 0) {
  17. $logger->log_error("Could not get config meta info from DB, error="
  18. . $propertiesArr["error"]);
  19. print json_encode(array( "result" => 1, "error" => "Error in config properties meta info"));
  20. return;
  21. }
  22. // Use meta info defaults
  23. // Override with current svc configs
  24. // Override with POST params
  25. $repoFilePath = $propertiesArr["configs"]["yum_repo_file"]["value"];
  26. $hdpArtifactsDownloadUrl = $propertiesArr["configs"]["apache_artifacts_download_url"]["value"];
  27. $gplArtifactsDownloadUrl = $propertiesArr["configs"]["gpl_artifacts_download_url"]["value"];
  28. $currentConfigs = $dbAccessor->getServiceConfig($clusterName);
  29. if ($currentConfigs["result"] != 0) {
  30. $logger->log_error("Could not get configs from DB, error="
  31. . $currentConfigs["error"]);
  32. print json_encode(array( "result" => 1, "error" => "Could not get configs from DB"));
  33. return;
  34. }
  35. if (isset($currentConfigs["properties"]["yum_repo_file"])
  36. && $currentConfigs["properties"]["yum_repo_file"] != "") {
  37. $repoFilePath = $currentConfigs["properties"]["yum_repo_file"];
  38. }
  39. if (isset($currentConfigs["properties"]["apache_artifacts_download_url"])
  40. && $currentConfigs["properties"]["apache_artifacts_download_url"] != "") {
  41. $hdpArtifactsDownloadUrl = $currentConfigs["properties"]["apache_artifacts_download_url"];
  42. }
  43. if (isset($currentConfigs["properties"]["gpl_artifacts_download_url"])
  44. && $currentConfigs["properties"]["gpl_artifacts_download_url"] != "") {
  45. $gplArtifactsDownloadUrl = $currentConfigs["properties"]["gpl_artifacts_download_url"];
  46. }
  47. if (isset($_POST['yumRepoFilePath'])
  48. && trim($_POST['yumRepoFilePath']) != "") {
  49. $repoFilePath = trim($_POST['yumRepoFilePath']);
  50. }
  51. if (isset($_POST['hdpArtifactsDownloadUrl'])
  52. && trim($_POST['hdpArtifactsDownloadUrl']) != "") {
  53. $hdpArtifactsDownloadUrl = trim($_POST['hdpArtifactsDownloadUrl']);
  54. }
  55. if (isset($_POST['gplArtifactsDownloadUrl'])
  56. && trim($_POST['gplArtifactsDownloadUrl']) != "") {
  57. $gplArtifactsDownloadUrl = trim($_POST['gplArtifactsDownloadUrl']);
  58. }
  59. header("Content-type: application/json");
  60. if (!file_exists($repoFilePath)) {
  61. $logger->log_warn("Invalid repo file provided, file does not exist"
  62. . ", repoFile=" . $repoFilePath);
  63. print (json_encode(array(
  64. "result" => 1,
  65. "error" => "Invalid repo file path specified"
  66. )
  67. ));
  68. return;
  69. }
  70. // TODO - error checks for download urls
  71. /*
  72. if (parse_url($hdpArtifactsDownloadUrl) === FALSE
  73. || parse_url($gplArtifactsDownloadUrl) === FALSE) {
  74. $logger->log_warn("Invalid download urls provided, could not parse"
  75. . ", hdpArtifactsDownloadUrl=" . $hdpArtifactsDownloadUrl
  76. . ", gplArtifactsDownloadUrl=" . $gplArtifactsDownloadUrl);
  77. print (json_encode(array(
  78. "result" => 1,
  79. "error" => "Invalid download urls specified")));
  80. return;
  81. }
  82. */
  83. $configs = array ( "yum_repo_file" => $repoFilePath,
  84. "apache_artifacts_download_url" => $hdpArtifactsDownloadUrl,
  85. "gpl_artifacts_download_url" => $gplArtifactsDownloadUrl);
  86. $dbResponse = $dbAccessor->updateServiceConfigs($clusterName, $configs);
  87. if ($dbResponse["result"] != 0) {
  88. $logger->log_error("Got error while persisting configs: ".$dbResponse["error"]);
  89. return $dbResponse;
  90. }
  91. $stagesFiles = "";
  92. if ($action == "addNodes") {
  93. $stagesFile = "./addNodes/stages.php";
  94. } else if ($action == "uninstall") {
  95. $stagesFile = "./uninstall/stages.php";
  96. } else {
  97. print (json_encode(array(
  98. "result" => 1,
  99. "error" => "Invalid action",
  100. )
  101. ));
  102. return;
  103. }
  104. error_log("ClusterName: ".$clusterName);
  105. $logger->log_debug("ClusterName: $clusterName\n");
  106. $logger->log_debug("Deploy User: $deployUser\n");
  107. // this api just creates a new transaction id for the db
  108. $status = "";
  109. $createTxResult = HMCTxnUtils::createNewTransaction($dbAccessor, $clusterName, $status);
  110. if ($createTxResult == FALSE) {
  111. $msg = "SETUP: Failed to create new transaction in background: $createTxResult\n";
  112. $logger->log_error($msg);
  113. print (json_encode(array("result" => 1, "error" => "$msg")));
  114. return;
  115. }
  116. $rootTxnId = $createTxResult;
  117. $logger->log_error("Txn Id ===== $rootTxnId\n");
  118. $logger->log_error("Clustername ===== $clusterName");
  119. $cmd = $GLOBALS["PHP_EXEC_PATH"] . " " . "../util/sequentialScriptRunner.php";
  120. // $cmd = $GLOBALS["PHP_EXEC_PATH"] . " " . "./addNodes/addNodesOrchestrator.php";
  121. $hostsFile = getHostsFilePath($clusterName);
  122. $args = "$clusterName $deployUser $rootTxnId $hostsFile $stagesFile";
  123. $execBackgroundResult = HMCTxnUtils::execBackgroundProcess($dbAccessor, $clusterName, $rootTxnId, $cmd, $args, "");
  124. if ($execBackgroundResult == FALSE) {
  125. $msg = "Failed to execute addNodesOrchestrator in background: $execBackgroundResult\n";
  126. $logger->log_error($msg);
  127. print (json_encode(array("result" => 1, "error" => "$msg")));
  128. return;
  129. }
  130. $result = 0;
  131. $error = "";
  132. $state = "CONFIGURATION_IN_PROGRESS";
  133. $displayName = "Configuration in progress";
  134. $context = array (
  135. 'stage' => "ADD_NODES",
  136. 'txnId' => $rootTxnId
  137. );
  138. // update state of the cluster to be configuration in progress
  139. $retval = updateClusterState($clusterName, $state, $displayName, $context);
  140. if ($retval['result'] != 0) {
  141. $result = $retval['result'];
  142. $error = $retval['error'];
  143. }
  144. print (json_encode(array(
  145. "result" => $result,
  146. "error" => $error,
  147. "response" => array(
  148. "clusterName" => $clusterName,
  149. "txnId" => $rootTxnId,
  150. )
  151. )
  152. ));
  153. ?>