DBReader.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?php
  2. include_once "../util/Logger.php";
  3. class DBReader {
  4. private $logger;
  5. private $dbPath;
  6. function __construct($db) {
  7. $this->dbPath = $db;
  8. $this->logger = new HMCLogger("DBReader");
  9. }
  10. public function getAllConfigs($clusterId) {
  11. $dbAccessor = new HMCDBAccessor($this->dbPath);
  12. $allConfigs = $dbAccessor->getServiceConfig($clusterId);
  13. $puppetConfigs = array();
  14. foreach ($allConfigs["properties"] as $key => $value) {
  15. $puppetValue = $value;
  16. if (isset($this->configValuePrefix[$key])) {
  17. $puppetValue = $this->configValuePrefix[$key] . $puppetValue;
  18. }
  19. if (isset($this->configValueSuffix[$key])) {
  20. $puppetValue = $puppetValue . $this->configValueSuffix[$key] ;
  21. }
  22. $puppetConfigs[$key] = $puppetValue;
  23. }
  24. return $puppetConfigs;
  25. }
  26. public function getAllHostAttributes($clusterName) {
  27. $dbAccessor = new HMCDBAccessor($this->dbPath);
  28. $allHostAttributes = $dbAccessor->getAllHostsInfo($clusterName,
  29. array("=" => array ( "discoveryStatus" => "SUCCESS")), array());
  30. return $allHostAttributes;
  31. }
  32. public function getHostNames($clusterId) {
  33. $dbAccessor = new HMCDBAccessor($this->dbPath);
  34. $allHostComponents = $dbAccessor->getAllHostsByComponent($clusterId);
  35. $hostNames = array();
  36. foreach ($allHostComponents["components"] as $componentName => $componentInfo) {
  37. if (!isset($componentInfo["hosts"])) {
  38. continue;
  39. }
  40. foreach($componentInfo["hosts"] as $hostname => $hostInfo) {
  41. if (!isset($this->hostKeyMap[$componentName])) {
  42. $this->logger->log_trace("No puppet handling needed for component "
  43. . $componentName);
  44. continue;
  45. }
  46. $puppetHostKey = $this->hostKeyMap[$componentName];
  47. if (!isset($hostNames[$puppetHostKey])) {
  48. $hostNames[$puppetHostKey] = array();
  49. }
  50. if (!in_array($hostname, $hostNames[$puppetHostKey])) {
  51. $hostNames[$puppetHostKey][] = $hostname;
  52. }
  53. }
  54. }
  55. return $hostNames;
  56. }
  57. function getHostRolesStates($clusterId, $nodes, $components) {
  58. //get roles for each host from db
  59. $dbAccessor = new HMCDBAccessor($this->dbPath);
  60. $allHostComponents = $dbAccessor->getAllHostsByComponent($clusterId);
  61. $allHostRoleConfigs = $dbAccessor->getHostRoleConfigs($clusterId);
  62. $hostRoles = array();
  63. foreach ($allHostComponents["components"] as $componentName => $componentInfo) {
  64. if (!isset($componentInfo["hosts"])) {
  65. continue;
  66. }
  67. foreach($componentInfo["hosts"] as $hostname => $hostInfo) {
  68. if (!in_array($hostname, $nodes)) {
  69. continue;
  70. }
  71. if (!isset($hostRoles[$hostname])) {
  72. $hostRoles[$hostname] = array();
  73. }
  74. if (!isset($this->componentToPuppetClassMap[$componentName])) {
  75. $this->logger->log_trace("No puppet handling needed for component "
  76. . $componentName);
  77. continue;
  78. }
  79. $puppetClass = $this->componentToPuppetClassMap[$componentName];
  80. $hostRoles[$hostname][$puppetClass] = array();
  81. if (in_array($componentName, $components)) {
  82. $hostRoles[$hostname][$puppetClass]["service_state"] =
  83. $hostInfo["desiredState"];
  84. } else {
  85. $hostRoles[$hostname][$puppetClass]["service_state"] = "no_op";
  86. }
  87. if (isset($allHostRoleConfigs["properties"])
  88. && isset($allHostRoleConfigs["properties"][$componentName])
  89. && isset($allHostRoleConfigs["properties"][$componentName][$hostname])) {
  90. foreach ($allHostRoleConfigs["properties"][$componentName][$hostname] as $key => $val) {
  91. $hostRoles[$hostname][$puppetClass][$key] = $val;
  92. }
  93. }
  94. }
  95. }
  96. return $hostRoles;
  97. }
  98. private $componentToPuppetClassMap = array (
  99. "NAMENODE" => "hdp-hadoop::namenode",
  100. "DATANODE"=> "hdp-hadoop::datanode",
  101. "SNAMENODE" => "hdp-hadoop::snamenode",
  102. "JOBTRACKER" => "hdp-hadoop::jobtracker",
  103. "TASKTRACKER" => "hdp-hadoop::tasktracker",
  104. "HDFS_CLIENT" => "hdp-hadoop::client",
  105. "MAPREDUCE_CLIENT" => "hdp-hadoop::client",
  106. "ZOOKEEPER_SERVER" => "hdp-zookeeper",
  107. "ZOOKEEPER_CLIENT" => "hdp-zookeeper::client",
  108. "HBASE_MASTER" => "hdp-hbase::master",
  109. "HBASE_REGIONSERVER" => "hdp-hbase::regionserver",
  110. "HBASE_CLIENT" => "hdp-hbase::client",
  111. "PIG_CLIENT" => "hdp-pig",
  112. "SQOOP_CLIENT" => "hdp-sqoop",
  113. "OOZIE_SERVER" => "hdp-oozie::server",
  114. "OOZIE_CLIENT" => "hdp-oozie::client",
  115. "HIVE_CLIENT" => "hdp-hive::client",
  116. "HCATALOG_CLIENT" => "hdp-hcat",
  117. "HCATALOG_SERVER" => "hdp-hcat::server",
  118. "HIVE_SERVER" => "hdp-hive::server",
  119. "HIVE_MYSQL" => "hdp-mysql::server",
  120. "TEMPLETON_SERVER" => "hdp-templeton::server",
  121. "TEMPLETON_CLIENT" => "hdp-templeton::client",
  122. "DASHBOARD" => "hdp-dashboard",
  123. "NAGIOS_SERVER" => "hdp-nagios::server",
  124. "GANGLIA_MONITOR_SERVER" => "hdp-ganglia::monitor_and_server",
  125. "GANGLIA_MONITOR" => "hdp-ganglia::monitor",
  126. "HTTPD" => "hdp-monitor-webserver"
  127. );
  128. //Store the database key for each role
  129. private $hostKeyMap =
  130. array(
  131. "NAMENODE" => "namenode_host",
  132. "JOBTRACKER" => "jtnode_host",
  133. "SNAMENODE" => "snamenode_host",
  134. "ZOOKEEPER_SERVER" => "zookeeper_hosts",
  135. "HBASE_MASTER" => "hbase_master_host",
  136. "HCATALOG_SERVER" => "hcat_server_host",
  137. "HIVE_SERVER" => "hive_server_host",
  138. "OOZIE_SERVER" => "oozie_server",
  139. "TEMPLETON_SERVER" => "templeton_server_host",
  140. "DASHBOARD" => "dashboard_host",
  141. "NAGIOS_SERVER" => "nagios_server_host",
  142. "GANGLIA_MONITOR_SERVER" => "ganglia_server_host",
  143. "DATANODE" => "slave_hosts",
  144. "TASKTRACKER" => "slave_hosts",
  145. "HBASE_REGIONSERVER" => "hbase_rs_hosts"
  146. );
  147. /****** Not used but may be used later *****
  148. //Store the database key for each configuration
  149. private $configKeyMap =
  150. array(
  151. "mapred_user" => "mapred_user",
  152. "hdfs_user" => "hdfs_user",
  153. "dataNodeDir" => "dfs_data_dir",
  154. "nameNodeDir" => "dfs_name_dir",
  155. "dfs_replication" => "dfs_replication",
  156. "mapred_local_dir" => "mapred_local_dir",
  157. "hadoop_logdirprefix" => "hadoop_logdirprefix",
  158. "hadoop_piddirprefix" => "hadoop_piddirprefix",
  159. "zk_user" => "zk_user",
  160. "zk_log_dir" => "zk_log_dir",
  161. "zk_data_dir" => "zk_data_dir",
  162. "zk_pid_dir" => "zk_pid_dir",
  163. "hbase_user" => "hbase_user",
  164. "hbase_log_dir" => "hbase_log_dir",
  165. "hbase_pid_dir" => "hbase_pid_dir",
  166. "hcat_user" => "hcat_user",
  167. "hcat_database_name" => "hcat_database_name",
  168. "hcat_metastore_user_name" => "hcat_metastore_user_name",
  169. "hcat_metastore_user_passwd" => "hcat_metastore_user_passwd",
  170. "hcat_logdirprefix" => "hcat_logdirprefix",
  171. "hcat_piddirprefix" => "hcat_piddirprefix",
  172. "oozie_user" => "oozie_user",
  173. "oozie_log_dir" => "oozie_log_dir",
  174. "oozie_pid_dir" => "oozie_pid_dir",
  175. "oozie_data_dir" => "oozie_data_dir",
  176. "templeton_user" => "templeton_user",
  177. "templeton_log_dir" => "templeton_log_dir",
  178. "templeton_pid_dir" => "templeton_pid_dir"
  179. );
  180. /*** Not used but may be used later *****
  181. private $serviceStateMap = array(
  182. "running" => "running",
  183. "installed_and_configured" => "installed_and_configured",
  184. "no_op" => "no_op",
  185. "stopped" => "stopped"
  186. );
  187. ******/
  188. private $configValueSuffix = array (
  189. "hadoop_heapsize" => "m",
  190. "namenode_heapsize" => "m",
  191. "namenode_opt_newsize" => "m",
  192. "dtnode_heapsize" => "m",
  193. "jtnode_opt_newsize" => "m",
  194. "jtnode_opt_maxnewsize" => "m",
  195. "jtnode_heapsize" => "m",
  196. "mapred_child_java_opts_sz" => "m",
  197. "io_sort_mb" => "m",
  198. "hbase_master_heapsize" => "m",
  199. "hbase_regionserver_heapsize" => "m"
  200. );
  201. private $configValuePrefix = array (
  202. "mapred_child_java_opts_sz" => "-Xmx"
  203. );
  204. }
  205. ?>