| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- <?php
- define("OPT", "opts");
- define("STAGE", "stage");
- define("SERVICESTATE", "service_state");
- class NodeManifest {
- private $node;
- private $roles;
- function __construct($n) {
- $this->node = $n;
- $this->roles = array();
- }
- public function setRoleStage($r, $stage) {
- $this->setRoleState($r, STAGE, $stage);
- }
- public function setRoleState($r, $stateKey, $stateValue) {
- if (!isset($this->roles[$r])) {
- $this->roles[$r] = array();
- $this->roles[$r][$stateKey] = $stateValue;
- } else {
- $this->roles[$r][$stateKey] = $stateValue;
- }
- }
- public function setRoleOpt($r, $optKey, $optVal) {
- if (!isset($this->roles[$r])) {
- $this->roles[$r] = array();
- }
- if (!isset($this->roles[$r][OPT])) {
- $this->roles[$r][OPT] = array();
- $this->roles[$r][OPT][$optKey] = $optVal;
- } else {
- $this->roles[$r][OPT][$optKey] = $optVal;
- }
- }
- private function generateStageChain() {
- $chain = "";
- $stages = array();
- foreach($this->roles as $roleName => $val) {
- $stages[] = $val[STAGE];
- }
- asort($stages, SORT_NUMERIC);
- $first = true;
- foreach ($stages as $s) {
- if ($first) {
- $first = false;
- } else {
- $chain = $chain . " -> ";
- }
- $chain = $chain . "stage{" . $s . " :}";
- }
- return $chain;
- }
- private function generateOptList($optList) {
- $optChain = "";
- $first = true;
- foreach($optList as $key => $val) {
- if ($first) {
- $first = false;
- } else {
- $optChain = $optChain . ", ";
- }
- $optChain = $optChain . $key . " => " . $val ;
- }
- return $optChain;
- }
- private function generateRoleLine($r) {
- $roleLine = "";
- $roleLine = $roleLine . "class {'" . $r . "': ";
- $isFirst = true;
- if (isset($this->roles[$r][OPT])) {
- $roleLine = $roleLine . OPT . " => {";
- $roleLine = $roleLine . $this->generateOptList($this->roles[$r][OPT]);
- $roleLine = $roleLine . "}";
- $isFirst = false;
- }
- foreach($this->roles[$r] as $key => $value) {
- if ($key != OPT) {
- if (!$isFirst) {
- $roleLine = $roleLine . ", ";
- } else {
- $isFirst = false;
- }
- $roleLine = $roleLine . $key . " => " . $value;
- }
- }
- $roleLine = $roleLine . "}";
- return $roleLine;
- }
- public function generateNodeManifest() {
- $manifest = "node /" . $this->node . "/ {\n";
- $manifest = $manifest . $this->generateStageChain();
- $manifest = $manifest . "\n";
- $stages = array();
- foreach($this->roles as $roleName => $val) {
- $stages[] = $val[STAGE];
- }
- asort($stages, SORT_NUMERIC);
- foreach($stages as $theStage) {
- //Print in the order of the stages
- foreach ($this->roles as $roleName => $roleVal) {
- if ($roleVal[STAGE] == $theStage) {
- $manifest = $manifest . $this->generateRoleLine($roleName);
- $manifest = $manifest . "\n";
- }
- }
- }
- $manifest = $manifest . "}\n";
- return $manifest;
- }
- public function setNamenodeRoleState($state, $stage) {
- $role = "hdp-hadoop::namenode";
- $this->setRoleState($role, SERVICESTATE, $state);
- $this->setRoleStage($role, $stage);
- }
- public function setSecondaryNamenodeRoleState($state, $stage) {
- $role = "hdp-hadoop::snamenode";
- $this->setRoleState($role, SERVICESTATE, $state);
- $this->setRoleStage($role, $stage);
- }
- public function setDatanodeRoleState($state, $stage) {
- $role = "hdp-hadoop::datanode";
- $this->setRoleState($role, SERVICESTATE, $state);
- $this->setRoleStage($role, $stage);
- }
- public function setJobTrackerRoleState($state, $stage) {
- $role = "hdp-hadoop::jobtracker";
- $this->setRoleState($role, SERVICESTATE, $state);
- $this->setRoleStage($role, $stage);
- }
- public function setTaskTrackerRoleState($state, $stage) {
- $role = "hdp-hadoop::tasktracker";
- $this->setRoleState($role, SERVICESTATE, $state);
- $this->setRoleStage($role, $stage);
- }
- public function setHadoopClientRoleState($state, $stage) {
- $role = "hdp-hadoop::client";
- $this->setRoleState($role, SERVICESTATE, $state);
- $this->setRoleStage($role, $stage);
- }
- public function setZooKeeperRoleState($state, $stage) {
- $role = "hdp-zookeeper";
- $this->setRoleState($role, SERVICESTATE, $state);
- $this->setRoleStage($role, $stage);
- }
- public function setZooKeeperClientRoleState($state, $stage) {
- $role = "hdp-zookeeper::client";
- $this->setRoleState($role, SERVICESTATE, $state);
- $this->setRoleStage($role, $stage);
- }
- public function setHbaseMasterRoleState($state, $stage) {
- $role = "hdp-hbase::master";
- $this->setRoleState($role, SERVICESTATE, $state);
- $this->setRoleStage($role, $stage);
- }
- public function setHbaseRegionServerRoleState($state, $stage) {
- $role = "hdp-hbase::regionserver";
- $this->setRoleState($role, SERVICESTATE, $state);
- $this->setRoleStage($role, $stage);
- }
- public function setHbaseClientRoleState($state, $stage) {
- $role = "hdp-hbase::client";
- $this->setRoleState($role, SERVICESTATE, $state);
- $this->setRoleStage($role, $stage);
- }
- }
- ?>
|