assignMasters.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 '../util/selectNodes.php';
  28. include_once '../util/clusterState.php';
  29. $logger = new HMCLogger("AssignHosts");
  30. $dbAccessor = new HMCDBAccessor($GLOBALS["DB_PATH"]);
  31. $selectNodes = new SelectNodes();
  32. header("Content-type: application/json");
  33. $clusterName = $_GET['clusterName'];
  34. // TODO: Validate clusterName
  35. $requestData = file_get_contents('php://input');
  36. $componentsToHosts = json_decode($requestData, true);
  37. // needs to persist info that is passed in
  38. $serviceMasters = array();
  39. // Get the info for all services, mainly for isEnabled
  40. $allServicesInfos = $dbAccessor->getAllServicesInfo($clusterName);
  41. if ($allServicesInfos["result"] != 0 ) {
  42. $logger->log_error("Got error while getting all services list ".$allServiceInfos["error"]);
  43. print json_encode($allServicesInfos);
  44. return;
  45. }
  46. // Get the info of all components. TODO: No getServiceComponentInfo() yet, meh..
  47. $allServicesComponents = $dbAccessor->getAllServiceComponentsList();
  48. if ($allServicesComponents["result"] != 0 ) {
  49. $logger->log_error("Got error while getting all services list ".$allServicesComponents["error"]);
  50. print json_encode($allServicesComponents);
  51. return;
  52. }
  53. $suggestedNodes = $selectNodes->updateDBWithRoles($clusterName,
  54. $dbAccessor,
  55. $componentsToHosts
  56. );
  57. $logger->log_trace("Debug Trace". json_encode($allServicesComponents["services"]));
  58. /* hack to unlock front end if the updateDBWithRoles
  59. $allHosts = array();
  60. // For each possible service
  61. foreach ($allServicesComponents["services"] as $serviceName => $serviceInfo) {
  62. // If the service is enabled
  63. $logger->log_error("service enabled thingie " . $allServicesInfos["services"][$serviceName]["isEnabled"]);
  64. if ($allServicesInfos["services"][$serviceName]["isEnabled"]) {
  65. // For each component in the enabled service
  66. foreach ($serviceInfo["components"] as $componentName => $componentInfo) {
  67. $logger->log_error("Looking if component exists " . $componentName);
  68. if (array_key_exists($componentName, $componentsToHosts)) {
  69. // If the component came from the user's host assignment, save the role in the DB.
  70. $addHostToComponentResult = $dbAccessor->addHostsToComponent($clusterName, $componentName, array($componentsToHosts[$componentName]), "May the force be with you", "carrot");
  71. array_push($allHosts, $componentsToHosts[$componentName]);
  72. if ($addHostToComponentResult["result"] != 0 ) {
  73. $logger->log_error("Got error while adding host to component".$addHostToComponentResult["error"]);
  74. print json_encode($addHostToComponentResult);
  75. return;
  76. }
  77. } else {
  78. $logger->log_error("doesn't exists " . $componentName);
  79. }
  80. }
  81. }
  82. }
  83. $dbAccessor->addHostsToComponent($clusterName, "DATANODE",
  84. $allHosts,
  85. "May the force be with you",
  86. "carrot");
  87. $dbAccessor->addHostsToComponent($clusterName, "TASKTRACKER",
  88. $allHosts,
  89. "May the force be with you",
  90. "carrot");
  91. hack till here */
  92. // choose the name node as the canary host.
  93. $nameNodeHost = $componentsToHosts["NAMENODE"];
  94. $AllMountPoints = array();
  95. $nameNodeInfoResult = $dbAccessor->getHostInfo($clusterName, $nameNodeHost[0]);
  96. if ($nameNodeInfoResult["result"] != 0 ) {
  97. $logger->log_error("Got error while getting canary host info ".$nameNodeInfoResult["error"]);
  98. print json_encode($nameNodeInfoResult);
  99. return;
  100. }
  101. $logger->log_info("All mount points: ".$nameNodeInfoResult["disksInfo"]);
  102. $AllMountPoints = json_decode($nameNodeInfoResult["disksInfo"], true);
  103. // generate the mount points info required by javascript in the next phase
  104. $propertiesArr = $dbAccessor->getConfigPropertiesMetaInfo();
  105. if ($propertiesArr["result"] != 0) {
  106. print("Error in config properties meta info");
  107. return;
  108. }
  109. // TODO: Get the displayNames and key names from DB.
  110. $outjson = array(
  111. "clusterName" => $clusterName,
  112. "mountPoints" => $AllMountPoints,
  113. "servicesInfo" => array (
  114. "HDFS" => array(
  115. "dfs_name_dir" => array(
  116. "displayName" => "NameNode directories",
  117. "maxDirectoriesNeeded" => -1,
  118. "suffix" => "hadoop/hdfs/namenode"
  119. ),
  120. "dfs_data_dir" => array(
  121. "displayName" => "DataNode directories",
  122. "maxDirectoriesNeeded" => -1,
  123. "suffix" => "hadoop/hdfs/data"
  124. ),
  125. "fs_checkpoint_dir" => array(
  126. "displayName" => "SecondaryNameNode Checkpoint directory",
  127. "maxDirectoriesNeeded" => 1,
  128. "suffix" => "hadoop/hdfs/namesecondary"
  129. )
  130. ),
  131. "MAPREDUCE" => array(
  132. "mapred_local_dir" => array(
  133. "displayName" => "MapReduce Data Directories",
  134. "maxDirectoriesNeeded" => -1,
  135. "suffix" => "hadoop/mapred"
  136. ),
  137. ),
  138. "OOZIE" => array(
  139. "oozie_data_dir" => array(
  140. "displayName" => "Oozie DB Directory",
  141. "maxDirectoriesNeeded" => 1,
  142. "suffix" => "hadoop/oozie"
  143. ),
  144. ),
  145. "ZOOKEEPER" => array(
  146. "zk_data_dir" => array(
  147. "displayName" => "ZooKeeper Data Directory",
  148. "maxDirectoriesNeeded" => 1,
  149. "suffix" => "hadoop/zookeeper"
  150. ),
  151. ),
  152. ),
  153. );
  154. // Update the state of the cluster.
  155. $result = 0;
  156. $error = "";
  157. $state = "CONFIGURATION_IN_PROGRESS";
  158. $displayName = "Configuration in progress";
  159. $context = array (
  160. 'stage' => "ASSIGN_MASTERS"
  161. );
  162. $retval = updateClusterState($clusterName, $state, $displayName, $context);
  163. if ($retval['result'] != 0) {
  164. $result = $retval['result'];
  165. $error = $retval['error'];
  166. }
  167. print(json_encode(array( "result" => $result, "error" => $error, "response" => $outjson)));
  168. ?>