assignMasters.php 7.2 KB

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