PuppetClassDependencies.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. include_once "../util/Logger.php";
  3. define ("SERVICE_STATE_RUNNING", "running");
  4. define ("SERVICE_STATE_INSTALLED_AND_CONFIGURED", "installed_and_configured");
  5. define ("SERVICE_STATE_STOPPED", "stopped");
  6. define ("SERVICE_STATE_UNINSTALLED", "uninstalled");
  7. define ("SERVICE_STATE_NO_OP", "no_op");
  8. define ("SERVICE_STATE_NOT_APPLICABLE", "na");
  9. define ("SERVICE_STATE_KEY", "service_state");
  10. //This class defines the classes that must be present together
  11. //on a single node manifest in given service states. Also defines the
  12. //parameters for those classes. It also defines parameters for a
  13. //class by declaring dependency on itself.
  14. //However, the actual order of the classes on a single host is NOT
  15. //determined by this class. Therefore one can define both forward and backward
  16. //dependencies.
  17. class PuppetClassDependencies {
  18. private $hostLevelDependencies;
  19. function __construct() {
  20. $this->hostLevelDependencies = array();
  21. //HDFS
  22. $this->addDependency("hdp-hadoop::namenode", SERVICE_STATE_RUNNING, "hdp-hadoop::namenode::service_check", array());
  23. //MapReduce
  24. $this->addDependency("hdp-hadoop::jobtracker", SERVICE_STATE_RUNNING, "hdp-hadoop::jobtracker::service_check", array());
  25. //ZooKeeper
  26. $this->addDependency("hdp-zookeeper", SERVICE_STATE_RUNNING, "hdp-zookeeper::zookeeper::service_check", array());
  27. //HBase
  28. $this->addDependency("hdp-hbase::master", SERVICE_STATE_INSTALLED_AND_CONFIGURED, "hdp-zookeeper::client",
  29. array("service_state" => SERVICE_STATE_INSTALLED_AND_CONFIGURED));
  30. $this->addDependency("hdp-hbase::master", SERVICE_STATE_INSTALLED_AND_CONFIGURED, "hdp-hadoop::client",
  31. array("service_state" => SERVICE_STATE_INSTALLED_AND_CONFIGURED));
  32. $this->addDependency("hdp-hbase::master", SERVICE_STATE_RUNNING, "hdp-zookeeper::client",
  33. array("service_state" => SERVICE_STATE_NO_OP));
  34. $this->addDependency("hdp-hbase::master", SERVICE_STATE_RUNNING, "hdp-hadoop::client",
  35. array("service_state" => SERVICE_STATE_NO_OP));
  36. $this->addDependency("hdp-hbase::master", SERVICE_STATE_UNINSTALLED, "hdp-zookeeper::client",
  37. array("service_state" => SERVICE_STATE_UNINSTALLED));
  38. $this->addDependency("hdp-hbase::master", SERVICE_STATE_UNINSTALLED, "hdp-hadoop::client",
  39. array("service_state" => SERVICE_STATE_UNINSTALLED));
  40. $this->addDependency("hdp-hbase::regionserver", SERVICE_STATE_INSTALLED_AND_CONFIGURED, "hdp-zookeeper::client",
  41. array("service_state" => SERVICE_STATE_INSTALLED_AND_CONFIGURED));
  42. $this->addDependency("hdp-hbase::regionserver", SERVICE_STATE_INSTALLED_AND_CONFIGURED, "hdp-hadoop::client",
  43. array("service_state" => SERVICE_STATE_INSTALLED_AND_CONFIGURED));
  44. $this->addDependency("hdp-hbase::regionserver", SERVICE_STATE_RUNNING, "hdp-zookeeper::client",
  45. array("service_state" => SERVICE_STATE_NO_OP));
  46. $this->addDependency("hdp-hbase::regionserver", SERVICE_STATE_RUNNING, "hdp-hadoop::client",
  47. array("service_state" => SERVICE_STATE_NO_OP));
  48. $this->addDependency("hdp-hbase::regionserver", SERVICE_STATE_UNINSTALLED, "hdp-zookeeper::client",
  49. array("service_state" => SERVICE_STATE_UNINSTALLED));
  50. $this->addDependency("hdp-hbase::regionserver", SERVICE_STATE_UNINSTALLED, "hdp-hadoop::client",
  51. array("service_state" => SERVICE_STATE_UNINSTALLED));
  52. //Oozie
  53. $this->addDependency("hdp-oozie::server", SERVICE_STATE_INSTALLED_AND_CONFIGURED, "hdp-hadoop::client",
  54. array("service_state" => SERVICE_STATE_INSTALLED_AND_CONFIGURED));
  55. $this->addDependency("hdp-oozie::server", SERVICE_STATE_RUNNING, "hdp-hadoop::client",
  56. array("service_state" => SERVICE_STATE_NO_OP));
  57. $this->addDependency("hdp-oozie::server", SERVICE_STATE_UNINSTALLED, "hdp-hadoop::client",
  58. array("service_state" => SERVICE_STATE_UNINSTALLED));
  59. //Hive depends on Hcat
  60. $this->addDependency("hdp-hive::server", SERVICE_STATE_INSTALLED_AND_CONFIGURED, "hdp-hcat",
  61. array("service_state" => SERVICE_STATE_INSTALLED_AND_CONFIGURED));
  62. $this->addDependency("hdp-hive::server", SERVICE_STATE_RUNNING, "hdp-hcat",
  63. array("service_state" => SERVICE_STATE_NO_OP));
  64. $this->addDependency("hdp-hive::server", SERVICE_STATE_UNINSTALLED, "hdp-hcat",
  65. array("service_state" => SERVICE_STATE_UNINSTALLED));
  66. $this->addDependency("hdp-hive::client", SERVICE_STATE_INSTALLED_AND_CONFIGURED, "hdp-hcat",
  67. array("service_state" => SERVICE_STATE_INSTALLED_AND_CONFIGURED));
  68. $this->addDependency("hdp-hive::client", SERVICE_STATE_UNINSTALLED, "hdp-hcat",
  69. array("service_state" => SERVICE_STATE_UNINSTALLED));
  70. //Hive Service Check
  71. $this->addDependency("hdp-hive::hive::service_check", SERVICE_STATE_NOT_APPLICABLE,
  72. "hdp-hcat::hcat::service_check", array());
  73. //Pig
  74. $this->addDependency("hdp-pig", SERVICE_STATE_INSTALLED_AND_CONFIGURED, "hdp-hadoop::client",
  75. array("service_state" => SERVICE_STATE_INSTALLED_AND_CONFIGURED));
  76. $this->addDependency("hdp-pig", SERVICE_STATE_UNINSTALLED, "hdp-hadoop::client",
  77. array("service_state" => SERVICE_STATE_UNINSTALLED));
  78. //Sqoop
  79. $this->addDependency("hdp-sqoop", SERVICE_STATE_INSTALLED_AND_CONFIGURED, "hdp-hadoop::client",
  80. array("service_state" => SERVICE_STATE_INSTALLED_AND_CONFIGURED));
  81. $this->addDependency("hdp-sqoop", SERVICE_STATE_UNINSTALLED, "hdp-hadoop::client",
  82. array("service_state" => SERVICE_STATE_UNINSTALLED));
  83. //Templeton
  84. $this->addDependency("hdp-templeton::server", SERVICE_STATE_INSTALLED_AND_CONFIGURED, "hdp-zookeeper::client",
  85. array("service_state" => SERVICE_STATE_INSTALLED_AND_CONFIGURED));
  86. $this->addDependency("hdp-templeton::server", SERVICE_STATE_INSTALLED_AND_CONFIGURED, "hdp-hadoop::client",
  87. array("service_state" => SERVICE_STATE_INSTALLED_AND_CONFIGURED));
  88. $this->addDependency("hdp-templeton::server", SERVICE_STATE_INSTALLED_AND_CONFIGURED, "hdp-pig",
  89. array("service_state" => SERVICE_STATE_INSTALLED_AND_CONFIGURED));
  90. $this->addDependency("hdp-templeton::server", SERVICE_STATE_INSTALLED_AND_CONFIGURED, "hdp-hcat",
  91. array("service_state" => SERVICE_STATE_INSTALLED_AND_CONFIGURED));
  92. $this->addDependency("hdp-templeton::server", SERVICE_STATE_RUNNING, "hdp-zookeeper::client",
  93. array("service_state" => SERVICE_STATE_NO_OP));
  94. $this->addDependency("hdp-templeton::server", SERVICE_STATE_RUNNING, "hdp-hadoop::client",
  95. array("service_state" => SERVICE_STATE_NO_OP));
  96. $this->addDependency("hdp-templeton::server", SERVICE_STATE_RUNNING, "hdp-pig",
  97. array("service_state" => SERVICE_STATE_NO_OP));
  98. $this->addDependency("hdp-templeton::server", SERVICE_STATE_RUNNING, "hdp-hcat",
  99. array("service_state" => SERVICE_STATE_NO_OP));
  100. $this->addDependency("hdp-templeton::server", SERVICE_STATE_UNINSTALLED, "hdp-zookeeper::client",
  101. array("service_state" => SERVICE_STATE_UNINSTALLED));
  102. $this->addDependency("hdp-templeton::server", SERVICE_STATE_UNINSTALLED, "hdp-hadoop::client",
  103. array("service_state" => SERVICE_STATE_UNINSTALLED));
  104. $this->addDependency("hdp-templeton::server", SERVICE_STATE_UNINSTALLED, "hdp-pig",
  105. array("service_state" => SERVICE_STATE_UNINSTALLED));
  106. $this->addDependency("hdp-templeton::server", SERVICE_STATE_UNINSTALLED, "hdp-hcat",
  107. array("service_state" => SERVICE_STATE_UNINSTALLED));
  108. //Ganglia
  109. $this->addDependency("hdp-ganglia::monitor", SERVICE_STATE_RUNNING, "hdp-ganglia::hdp-gmond::service_check", array());
  110. $this->addDependency("hdp-ganglia::monitor_and_server", SERVICE_STATE_RUNNING, "hdp-ganglia::hdp-gmond::service_check", array());
  111. $this->addDependency("hdp-ganglia::monitor_and_server", SERVICE_STATE_RUNNING, "hdp-ganglia::hdp-gmetad::service_check", array());
  112. $this->addDependency("hdp-ganglia::monitor_and_server", SERVICE_STATE_RUNNING, "hdp-monitor-webserver", array());
  113. //Nagios
  114. $this->addDependency("hdp-nagios::server", SERVICE_STATE_INSTALLED_AND_CONFIGURED, "hdp-oozie::client",
  115. array("service_state" => SERVICE_STATE_INSTALLED_AND_CONFIGURED));
  116. $this->addDependency("hdp-nagios::server", SERVICE_STATE_INSTALLED_AND_CONFIGURED, "hdp-hcat",
  117. array("service_state" => SERVICE_STATE_INSTALLED_AND_CONFIGURED));
  118. $this->addDependency("hdp-nagios::server", SERVICE_STATE_INSTALLED_AND_CONFIGURED, "hdp-hive::client",
  119. array("service_state" => SERVICE_STATE_INSTALLED_AND_CONFIGURED));
  120. $this->addDependency("hdp-nagios::server", SERVICE_STATE_RUNNING, "hdp-oozie::client",
  121. array("service_state" => SERVICE_STATE_NO_OP));
  122. $this->addDependency("hdp-nagios::server", SERVICE_STATE_RUNNING, "hdp-hcat",
  123. array("service_state" => SERVICE_STATE_NO_OP));
  124. $this->addDependency("hdp-nagios::server", SERVICE_STATE_RUNNING, "hdp-hive::client",
  125. array("service_state" => SERVICE_STATE_NO_OP));
  126. $this->addDependency("hdp-nagios::server", SERVICE_STATE_UNINSTALLED, "hdp-oozie::client",
  127. array("service_state" => SERVICE_STATE_UNINSTALLED));
  128. $this->addDependency("hdp-nagios::server", SERVICE_STATE_UNINSTALLED, "hdp-hcat",
  129. array("service_state" => SERVICE_STATE_UNINSTALLED));
  130. $this->addDependency("hdp-nagios::server", SERVICE_STATE_UNINSTALLED, "hdp-hive::client",
  131. array("service_state" => SERVICE_STATE_UNINSTALLED));
  132. $this->addDependency("hdp-nagios::server", SERVICE_STATE_RUNNING, "hdp-nagios::nagios::service_check", array());
  133. $this->addDependency("hdp-nagios::server", SERVICE_STATE_RUNNING, "hdp-monitor-webserver", array());
  134. //Dashboard
  135. $this->addDependency("hdp-dashboard", SERVICE_STATE_RUNNING, "hdp-dashboard::dashboard::service_check", array());
  136. }
  137. private function addDependency($role, $serviceState, $dep, $states) {
  138. if (!isset($this->hostLevelDependencies[$role])) {
  139. $this->hostLevelDependencies[$role] = array();
  140. }
  141. if (!isset($this->hostLevelDependencies[$role][$serviceState])) {
  142. $this->hostLevelDependencies[$role][$serviceState] = array();
  143. }
  144. if (!isset($this->hostLevelDependencies[$role][$serviceState][$dep])) {
  145. $this->hostLevelDependencies[$role][$serviceState][$dep] = $states;
  146. } else {
  147. $prevStates = $this->hostLevelDependencies[$role][$serviceState][$dep];
  148. foreach ($states as $k => $v) {
  149. $prevStates[$k] = $v;
  150. }
  151. $this->hostLevelDependencies[$role][$serviceState][$dep] = $prevStates;
  152. }
  153. }
  154. public function getHostLevelDependencies($role, $serviceState) {
  155. $dependencies = array("hdp" => array() );
  156. if (!isset($this->hostLevelDependencies[$role][$serviceState])) {
  157. return $dependencies;
  158. }
  159. $deps = $this->hostLevelDependencies[$role][$serviceState];
  160. if (empty($deps)) {
  161. return $dependencies;
  162. }
  163. $reqs = array_keys($deps);
  164. while (!(empty($reqs))) {
  165. $d = array_pop($reqs);
  166. $moreReqs;
  167. if(isset($this->hostLevelDependencies[$d])) {
  168. $depSvcState = SERVICE_STATE_NOT_APPLICABLE;
  169. if (isset($this->hostLevelDependencies[$d][SERVICE_STATE_KEY])) {
  170. $depSvcState = $this->hostLevelDependencies[$d][SERVICE_STATE_KEY];
  171. }
  172. $moreReqs = NULL;
  173. if (isset($this->hostLevelDependencies[$d][$depSvcState])) {
  174. $moreReqs = $this->hostLevelDependencies[$d][$depSvcState];
  175. }
  176. if (!empty($moreReqs)) {
  177. foreach($moreReqs as $r => $v) {
  178. $deps[$r] = $v;
  179. if (!in_array($r, $reqs)) {
  180. array_push($reqs, $r);
  181. }
  182. }
  183. }
  184. }
  185. $dependencies[$d] = $deps[$d];
  186. }
  187. return $dependencies;
  188. }
  189. }
  190. ?>