private static function validation_internal($settings, $level, $node_prefix, $main_buss_id, $idc)
 {
     // 1. check array not empty
     if (empty($settings)) {
         QconfMgrLog::err(__FILE__, __LINE__, "empty array under {$node_prefix}!");
         return InfoDescUtil::ERR_IMPORT_EMPTY_ARRAY;
     }
     // 2. check node level
     if ($level > InfoDescUtil::IMPORT_NODE_MAX_LEVEL) {
         QconfMgrLog::err(__FILE__, __LINE__, "too many node levels under {$node_prefix}!");
         return InfoDescUtil::ERR_IMPORT_TOO_MANY_LEVELS;
     }
     foreach ($settings as $key => $value) {
         // 4. check node path
         if (!ImportValidation::check_path($key)) {
             QconfMgrLog::err(__FILE__, __LINE__, "Illegal setting key : {$key}!");
             return InfoDescUtil::ERR_IMPORT_ILEGAL_PATH;
         }
         // 5. check add node under service node
         $node_whole = $node_prefix . "/" . $key;
         $cur_node = NodeServ::getNodeByNodeWhole($node_whole, $main_buss_id);
         $value_is_array = is_array($value);
         if ($cur_node != FALSE) {
             $cur_node_type = $cur_node["node_type_code"];
             if ($cur_node_type === InfoDescUtil::NODE_TYPE_SERV_FATHER && $value_is_array === TRUE) {
                 QconfMgrLog::err(__FILE__, __LINE__, "try to add node under service node  : {$key}!");
                 return InfoDescUtil::ERR_IMPORT_ADD_UNDER_SERV_FATHER;
             }
         }
         // 6. recursive check child
         if ($value_is_array === TRUE) {
             $check_res = self::validation_internal($value, $level + 1, $node_whole, $main_buss_id, $idc);
             if ($check_res != InfoDescUtil::IMPORT_OK) {
                 return $check_res;
             } else {
                 continue;
             }
         }
         // 7. record status
         if ($cur_node === FALSE) {
             $status = InfoDescUtil::IMPORT_NODE_STATUS_NO_EXIST;
         } else {
             $cur_idc = $cur_node["idc"];
             $data_idcs = explode(',', $cur_idc);
             $exist_idc = in_array($idc, $data_idcs);
             if ($exist_idc === FALSE) {
                 $status = InfoDescUtil::IMPORT_NODE_STATUS_NO_EXIST;
             } else {
                 $status = InfoDescUtil::IMPORT_NODE_STATUS_EXIST;
             }
         }
         $value_status = array("value" => $value, "status" => $status);
         self::$_check_results[$node_whole] = $value_status;
     }
     return InfoDescUtil::IMPORT_OK;
 }
 public function checkFeedbackAction()
 {
     $node_id = $this->getRequest("node_id", "");
     $idc = $this->getRequest("idc", "");
     $page = $this->getRequest("page", 1);
     $page_count = $this->getRequest("pageCount", 20);
     // 1. parameter is not right
     if ($node_id === "" || $idc === "") {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS);
         QconfMgrLog::err(__FILE__, __LINE__, "parameter node_id or idc is null!");
         echo json_encode($res);
         return;
     }
     ArgsUtil::setVal($page);
     ArgsUtil::setVal($page_count);
     if ($page <= 0) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS);
         QconfMgrLog::err(__FILE__, __LINE__, "parameter page error!");
         echo json_encode($res);
         return;
     }
     if ($page_count < 0) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS);
         QconfMgrLog::err(__FILE__, __LINE__, "parameter page_count error!");
         echo json_encode($res);
         return;
     }
     // 2. idc zookeeper server not exist
     $idc_host = ZkConf::getZkHost($idc);
     if ($idc_host === NULL) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_IDC_NOT_EXIST);
         QconfMgrLog::err(__FILE__, __LINE__, "'{$idc}' is not int ZOOKEEPER_SVR!");
         echo json_encode($res);
         return;
     }
     // 3. get the node info from database
     $dbnode = NodeServ::getNode($node_id);
     if ($dbnode === FALSE) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_NODE_NOT_EXIST);
         QconfMgrLog::err(__FILE__, __LINE__, "node : {$node_id} is not exist!");
         echo json_encode($res);
         return;
     }
     $node_whole = $dbnode["node_whole"];
     $node_type_code = $dbnode["node_type_code"];
     $data_type = $node_type_code == InfoDescUtil::NODE_TYPE_SERV_FATHER ? InfoDescUtil::FEEDBACK_DATA_TYPE_SERVICE : InfoDescUtil::FEEDBACK_DATA_TYPE_VALUE;
     $cur_node_idc = $dbnode["idc"];
     $cur_idcs_array = explode(',', $cur_node_idc);
     $exist_idc = in_array($idc, $cur_idcs_array);
     if ($exist_idc === FALSE) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_IDC_NOT_IN_DATABASE);
         QconfMgrLog::err(__FILE__, __LINE__, "node : {$node_id} does not exist on idc : {$idc}!");
         echo json_encode($res);
         return;
     }
     // 4. get feedbacks on current node
     $start = ($page - 1) * $page_count;
     $qconf_path = PathUtil::getQconfPath($node_whole);
     $feedbacks = FeedbackServ::queryFeedbackByNode($qconf_path, $idc, $data_type, $start, $page_count);
     if ($feedbacks === FALSE) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_MYSQL_FAIL);
         QconfMgrLog::err(__FILE__, __LINE__, "failed to query feedbacks by node:{$node_whole},\n                idc({$idc}), data_type({$data_type}), page({$page}), page_count({$page_count})!");
         echo json_encode($res);
         return;
     }
     $total_count = FeedbackServ::feedbackAmountByNode($qconf_path, $idc, $data_type);
     if ($total_count === FALSE) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_MYSQL_FAIL);
         QconfMgrLog::err(__FILE__, __LINE__, "failed to get feedbacks amount by node:{$node_whole}, idc({$idc}), data_type({$data_type})");
         echo json_encode($res);
         return;
     }
     // 5. calcuate value_md5
     $zk_web = new QconfZkWebBase(Log::INFO);
     $zk_web->connect($idc_host);
     $retry_time = 0;
     if ($data_type == InfoDescUtil::FEEDBACK_DATA_TYPE_SERVICE) {
         // 5.1 calcuate value_md5 for service father node
         $services = -1;
         while ($services === -1 && $retry_time <= InfoDescUtil::ZK_MAX_RETRY_TIME) {
             QconfMgrLog::err(__FILE__, __LINE__, "retry {$retry_time} of " . InfoDescUtil::ZK_MAX_RETRY_TIME . " to get services {$node_whole} on {$idc_host}");
             $services = $zk_web->get_group_services_with_status($qconf_path);
             $retry_time++;
         }
         if ($services === -1) {
             $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_ZOOKEEPER_FAIL);
             QconfMgrLog::err(__FILE__, __LINE__, "The children of path: {$qconf_path} are null!");
             echo json_encode($res);
             return;
         }
         ksort($services);
         foreach ($services as $serv => $status) {
             $ser_combine .= "{$serv}#{$status},";
         }
         $ser_combine = trim($ser_combine, ',');
         //echo $ser_combine;
         $node_md5 = md5($ser_combine);
     } else {
         // 5.2 calcuate value_md5 for value
         $node_val = -1;
         while ($node_val === -1 && $retry_time <= InfoDescUtil::ZK_MAX_RETRY_TIME) {
             QconfMgrLog::err(__FILE__, __LINE__, "retry {$retry_time} of " . InfoDescUtil::ZK_MAX_RETRY_TIME . " to get value of {$node_whole} on {$idc}");
             $node_val = $zk_web->get_conf($qconf_path);
             $retry_time++;
         }
         if ($node_val === -1) {
             $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_ZOOKEEPER_FAIL);
             QconfMgrLog::err(__FILE__, __LINE__, "failed to get value of {$qconf_path}!");
             echo json_encode($res);
             return;
         }
         $node_md5 = md5($node_val);
     }
     // 6. encapsulate feedback result
     $fd_result = array();
     foreach ($feedbacks as $feedback) {
         $fd_one = array("feedback_id" => $feedback["feedback_id"], "hostname" => $feedback["hostname"], "ip" => $feedback["ip"], "status" => $feedback["value_md5"] == $node_md5 ? "0" : "1", "update_time" => $feedback["update_time"]);
         $fd_result[] = $fd_one;
     }
     $result = array("curPage" => "{$page}", "totalCount" => "{$total_count}", "listing" => $fd_result);
     $res = array("errno" => "0", "errmsg" => "", "data" => $result);
     $json = json_encode($res);
     echo $json;
 }
 public function modifyScriptAction()
 {
     session_start();
     $user = $this->getRequest("user", "");
     $password = $this->getRequest("password", "");
     $path = trim($this->getRequest("path", ""), "/");
     $node_val = trim($this->getRequest("node_val", ""), "/");
     $idc = $this->getRequest("idc", "");
     $sub_buss_id = $this->getRequest("sub_buss_id", "");
     $main_buss_id = $this->getRequest("main_buss_id", "");
     $desc = $this->getRequest("desc", "");
     // parameter null
     if ($user === "" || $password === '' || $path === "" || $idc === "" || $node_val === "" || $main_buss_id === "") {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS);
         QconfMgrLog::err(__FILE__, __LINE__, "paramter: 'user', 'password', 'path', 'idc', 'node_val', 'main_buss_id' and 'sub_buss_id' are required!");
         echo json_encode($res);
         return;
     }
     //user validation
     $permision = self::getPermission("test_admin");
     if ($user != "test_admin" || $permision === FALSE || $password != $permision["pwd"]) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_PERM_NO_AUTHORITY);
         QconfMgrLog::err(__FILE__, __LINE__, "user validation failed!");
         echo json_encode($res);
         return;
     }
     // idc exist validation
     $idc_host = ZkConf::getZkHost($idc);
     if ($idc_host === NULL) {
         //idc didnot exist
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_IDC_NOT_EXIST);
         QconfMgrLog::err(__FILE__, __LINE__, "idc({$idc}) not exist!");
         echo json_encode($res);
         return;
     }
     //parameter replenish
     $path = trim($path, "/");
     $path = "/" . $path;
     // check whether node already exist
     $cur_node = NodeServ::getNodeByNodeWhole($path, $main_buss_id);
     if ($cur_node === FALSE) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_NODE_NOT_EXIST);
         QconfMgrLog::err(__FILE__, __LINE__, "node:{$path} didn't exist in database");
         echo json_encode($res);
         return;
     }
     if ($cur_node["node_type_code"] != InfoDescUtil::NODE_TYPE_SERV_FATHER) {
         QconfMgrLog::err(__FILE__, __LINE__, "node:{$path} is not a service father node");
         $res = array("errno" => "0", "errmsg" => "", "data" => "node:{$path} is not a service father node");
         echo json_encode($res);
         return;
     }
     if ($sub_buss_id === "") {
         $sub_buss_id = "NULL";
     }
     $res = self::modifyConfAfterParamValidation($user, $path, $idc, $main_buss_id, $sub_buss_id, $desc, $node_val);
     $json = json_encode($res);
     echo $json;
 }
 public function addServiceAction()
 {
     $node_id = $this->getRequest("node_id", "");
     $idc = $this->getRequest("idc", "");
     $service_name = $this->getRequest("service_name", "");
     $op_user = $this->userInfo["userName"];
     // 1. parameter is not right
     if ($node_id === "" || $idc === "" || $service_name === "") {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS);
         QconfMgrLog::err(__FILE__, __LINE__, "parameter 'node_id', 'idc', 'service_name', is null!");
         echo json_encode($res);
         return;
     }
     // 2. check node_id
     $node_row = NodeServ::getNode($node_id);
     if ($node_row === FALSE || count($node_row) === 0) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_NODE_NOT_EXIST);
         QconfMgrLog::err(__FILE__, __LINE__, "'node_id : {$node_id} not exist!'");
         echo json_encode($res);
         return;
     }
     $db_node_whole = $node_row["node_whole"];
     //[USERPERM CHECK]
     $userperm_ret = UserPermServ::checkPerm($op_user, $db_node_whole);
     if ($userperm_ret === FALSE) {
         QconfMgrLog::err(__FILE__, __LINE__, "Insufficient permission of {$op_user} on node {$db_node_whole}");
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_USER_PERM_PERMISSION_DENIED);
         echo json_encode($res);
         return;
     }
     // 3. check node type code
     $node_type_code = $node_row["node_type_code"];
     if ($node_type_code === InfoDescUtil::NODE_TYPE_NORMAL_FATHER) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_NODE_TYPE);
         QconfMgrLog::err(__FILE__, __LINE__, "node {$node_id} is not a normal father node!'");
         echo json_encode($res);
         return;
     } else {
         if ($node_type_code === InfoDescUtil::NODE_TYPE_NORMAL) {
             //[SNAPSHOT CHECK]
             $main_buss_id = $node_row["main_buss_id"];
             $snapshot_ret = SnapShotUtil::existSnapShotForNode($main_buss_id, $db_node_whole, $snapshot_path);
             if ($snapshot_ret === FALSE) {
                 QconfMgrLog::err(__FILE__, __LINE__, "snapshot operation failed");
                 $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_SNAPSHOT_MODULE_FAILED);
                 echo json_encode($res);
                 return;
             }
             if ($snapshot_ret === InfoDescUtil::SNAPSHOT_FILE_EXIST) {
                 QconfMgrLog::err(__FILE__, __LINE__, "snapshot existed on current node node_whole({$node_whole})");
                 $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_SNAPSHOT_LOCKED_NODE);
                 $res["errmsg"] .= ": {$snapshot_path}";
                 echo json_encode($res);
                 return;
             }
         }
     }
     // 4. check idc exist
     $idc = trim($idc, ",");
     $idc_list = preg_split("/[,]+/", $idc);
     $failed_idcs = "";
     foreach ($idc_list as $idc_each) {
         $idc_host = ZkConf::getZkHost($idc_each);
         if ($idc_host === NULL) {
             //idc does not exist
             $failed_idcs .= ",{$idc_each}";
         }
     }
     if ($failed_idcs != "") {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_IDC_NOT_EXIST);
         $res["data"] .= trim($failed_idcs, ",");
         echo json_encode($res);
         return;
     }
     // 5. add add in zookeeper
     $failed_idcs = self::retryOperation($node_id, $idc_list, $service_name, $op_user, InfoDescUtil::OP_TYPE_BATCH_ADD_SERV);
     // 6. send result
     if (count($failed_idcs) === 0) {
         //success return
         $res = array("errno" => "0", "errmsg" => "", "data" => "add service success!");
         $json = json_encode($res);
         echo $json;
         return;
     } else {
         //failed return
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BATCH_FAIL_EXIST);
         foreach ($failed_idcs as $fail_idc) {
             if ($res["data"] != "") {
                 $res["data"] .= ",";
             }
             $res["data"] .= $fail_idc;
         }
         $json = json_encode($res);
         echo $json;
         return;
     }
 }
 public function addNormalAction()
 {
     $main_buss_id = $this->getRequest("main_buss_id", "");
     $user_name = $this->getRequest("user_name", "");
     $node_whole = trim($this->getRequest("node_whole", ""));
     $op_user = $this->userInfo["userName"];
     if ($main_buss_id === "" || $user_name === "" || $node_whole === "") {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS);
         QconfMgrLog::err(__FILE__, __LINE__, "parameter 'main_buss_id' or 'user_name' or 'node_whole' is null!");
         echo json_encode($res);
         return;
     }
     // Check whether op_user is admin
     $is_admin = UserPermServ::checkAdmin($op_user, $main_buss_id);
     if ($is_admin !== InfoDescUtil::QCONF_OK) {
         if ($is_admin === FALSE) {
             $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_MYSQL_FAIL);
         } else {
             $res = InfoDescUtil::getErrorMsg($is_admin);
         }
         QconfMgrLog::err(__FILE__, __LINE__, "admin:{$op_user} of main_buss_id:{$main_buss_id} list normals failed!");
         echo json_encode($res);
         return;
     }
     // Check whether the $node_whole of $main_buss_id exist
     $node_whole = "/" . trim($node_whole, "/");
     $flags = NodeServ::checkNode($node_whole, $main_buss_id);
     if ($flags === FALSE) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_NODE_NOT_EXIST);
         QconfMgrLog::err(__FILE__, __LINE__, "{$node_whole} is not in qconf_node table!");
         echo json_encode($res);
         return;
     }
     $flags = UserPermServ::addNormal($op_user, $user_name, $node_whole, $main_buss_id);
     if ($flags !== InfoDescUtil::QCONF_OK) {
         OpServ::insert(InfoDescUtil::OP_TYPE_USER_PERM_NORMAL_ADD, $node_whole, "", InfoDescUtil::OP_STATUS_MYSQL_FAILED, $main_buss_id, "NULL", $op_user, "add {$user_name} perm failed!");
         if ($flags === FALSE) {
             $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_MYSQL_FAIL);
         } else {
             $res = InfoDescUtil::getErrorMsg($flags);
         }
         QconfMgrLog::err(__FILE__, __LINE__, "admin:{$op_user} of main_buss_id:{$main_buss_id} add user:{$user_name} of node:{$node_whole}; {$flags} failed!");
         echo json_encode($res);
         return;
     }
     OpServ::insert(InfoDescUtil::OP_TYPE_USER_PERM_NORMAL_ADD, $node_whole, "", InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, "NULL", $op_user, "add {$user_name} perm success!");
     $res = array("errno" => "0", "errmsg" => "", "data" => "add normal user success");
     $json = json_encode($res);
     echo $json;
 }
Beispiel #6
0
 public static function modIdc($node_id, $idc)
 {
     if ($node_id === NULL || $node_id === "" || $idc === NULL) {
         QconfMgrLog::err(__FILE__, __LINE__, "node_id or idc is NULL");
         return FALSE;
     }
     ArgsUtil::setSQLEscape($node_id);
     ArgsUtil::setSQLEscape($idc);
     $idc_list = preg_split("/[,]+/", trim($idc, ","));
     while ($node_id != 0) {
         $row = NodeServ::getNode($node_id);
         if ($row === FALSE) {
             return FALSE;
         }
         $p_idcs = trim($row["idc"], ",");
         $p_idcs_list = preg_split("/[,]+/", $p_idcs);
         $diff_list = array_diff($idc_list, $p_idcs_list);
         $diff_idc = implode(",", $diff_list);
         $new_idc = $p_idcs . "," . $diff_idc;
         $new_idc = trim($new_idc, ",");
         $ret = self::modColById($node_id, "idc", $new_idc);
         if ($ret === FALSE) {
             return FALSE;
         }
         $node_id = $row["parent_node_id"];
     }
     return TRUE;
 }
 public function passNodeAction()
 {
     $this->setNoViewRender(true);
     //        $perm_id = isset($_POST['perm_id']) ? $_POST['perm_id'] : "";
     $perm_id = $this->getRequest("perm_id", "");
     $admin_user = $this->userInfo["userName"];
     // 2. parameter is not right
     if ($perm_id === "") {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS);
         QconfMgrLog::err(__FILE__, __LINE__, "'perm_id' is NULL!");
         echo json_encode($res);
         return;
     }
     // 3. get the perm_id value failed
     $res = PermServ::selectById($perm_id);
     if ($res === FALSE) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_MYSQL_FAIL);
         QconfMgrLog::err(__FILE__, __LINE__, "get the value of perm_id '{$perm_id}' failed!");
         echo json_encode($res);
         return;
     }
     $main_buss_id = $res["main_buss_id"];
     $qconf_path = PathUtil::getQconfPath($res["node"]);
     $node = $res["node"];
     $node_val = $res["node_val"];
     $idc = trim($res['idc'], ",");
     $idc_list = preg_split("/[,]+/", $idc);
     $succ_flgs = TRUE;
     $op_user = $res["apply_user"];
     $sub_buss_id = "NULL";
     $op_user_email = $res["apply_user_email"];
     $apply_status_code = $res["apply_status_code"];
     if (intval($apply_status_code) !== intval(InfoDescUtil::APPLY_STATUS_EXAMINE)) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_NODE_EXIST);
         QconfMgrLog::err(__FILE__, __LINE__, "{$node} has already been deal with!");
         echo json_encode($res);
         return;
     }
     if ($idc != "") {
         foreach ($idc_list as $idc_tmp) {
             $idc_host = ZkConf::getZkHost($idc_tmp);
             // 3. idc zookeeper server not exist
             if ($idc_host === NULL) {
                 $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_IDC_NOT_EXIST);
                 QconfMgrLog::err(__FILE__, __LINE__, "{$idc_host} is not in ZOOKEEPER_SVR");
                 $succ_flgs = FALSE;
                 continue;
             }
             $zk_web = new QconfZkWebBase(Log::INFO);
             $zk_web->connect($idc_host);
             $ret = -1;
             $retry_time = 0;
             while ($ret === -1 && $retry_time <= InfoDescUtil::ZK_MAX_RETRY_TIME) {
                 QconfMgrLog::err(__FILE__, __LINE__, "retry {$retry_time} of " . InfoDescUtil::ZK_MAX_RETRY_TIME . " to add conf for {$qconf_path} on {$idc_host}");
                 $ret = $zk_web->add_conf($qconf_path, $node_val);
                 $retry_time++;
             }
             if ($ret === -1) {
                 // 4. zookeeper add failed
                 $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_ZOOKEEPER_FAIL);
                 OpServ::insert(InfoDescUtil::OP_TYPE_AUDIT_PASS, $qconf_path, $idc_tmp, InfoDescUtil::OP_STATUS_ZOO_FAILED, $main_buss_id, $sub_buss_id, $op_user, "");
                 QconfMgrLog::err(__FILE__, __LINE__, "add {$qconf_path} on {$idc_tmp} failed!");
                 $succ_flgs = FALSE;
                 continue;
             }
             $idc_on .= ",{$idc_tmp}";
         }
     }
     // 6. the zookeeper operation has failed
     if ($succ_flgs === FALSE) {
         $idc_on = trim($idc_on, ",");
         if ($idc_on != NULL) {
             $ret = NodeServ::addRoot($node, $main_buss_id, $idc_on);
             $ret = PermServ::modPerm($perm_id, InfoDescUtil::APPLY_STATUS_PASS);
             if ($ret === TRUE) {
                 NotifyUtil::notifyByQHEmail($op_user_email, "node: '{$node}' apply on '{$idc}' has been PASSED", " 在机房 {$idc_on} 申请的根节点 {$node} 已经被通过! ");
             }
         }
         echo json_encode($res);
         return;
     }
     $ret = NodeServ::addRoot($node, $main_buss_id, $idc);
     // 7. database operation failed
     if ($ret === FALSE) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_MYSQL_FAIL);
         OpServ::insert(InfoDescUtil::OP_TYPE_AUDIT_PASS, $qconf_path, $idc, InfoDescUtil::OP_STATUS_MYSQL_FAILED, $main_buss_id, $sub_buss_id, $op_user, "");
         QconfMgrLog::err(__FILE__, __LINE__, "addRoot in qconf_node failed!");
         echo json_encode($res);
         return;
     }
     $ret = PermServ::modPerm($perm_id, InfoDescUtil::APPLY_STATUS_PASS);
     // 8. update the apply staus failed
     if ($ret === FALSE) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_MYSQL_FAIL);
         OpServ::insert(InfoDescUtil::OP_TYPE_AUDIT_PASS, $qconf_path, $idc, InfoDescUtil::OP_STATUS_MYSQL_FAILED, $main_buss_id, $sub_buss_id, $op_user, "");
         QconfMgrLog::err(__FILE__, __LINE__, "update the apply stats in qconf_perm failed!");
         echo json_encode($res);
         return;
     }
     OpServ::insert(InfoDescUtil::OP_TYPE_AUDIT_PASS, $qconf_path, $idc, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $op_user, $node_val);
     // 9. return the data
     $res = array("errno" => "0", "errmsg" => "", "data" => "");
     NotifyUtil::notifyByQHEmail($op_user_email, "node: '{$node}' apply on '{$idc}' has been PASSED", " 在机房 {$idc} 申请的根节点 {$node} 已经通过! ", $admin_user);
     $json = json_encode($res);
     echo $json;
 }
 public function rollbackAction()
 {
     $path = trim($this->getRequest("path", ""), "/");
     $idc = $this->getRequest("idc", "");
     $main_buss_id = $this->getRequest("main_buss_id", "");
     $op_user = $this->userInfo["userName"];
     // 1. parameter null
     if ($path === "" || $main_buss_id === "" || $idc === "") {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS);
         QconfMgrLog::err(__FILE__, __LINE__, "parameter 'main_buss_id', 'path' or 'idc' is null!");
         echo json_encode($res);
         return;
     }
     // 2. check node exist
     $path = "/" . $path;
     $node = NodeServ::getNodeByNodeWhole($path, $main_buss_id);
     if ($node === FALSE) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_NODE_NOT_EXIST);
         QconfMgrLog::err(__FILE__, __LINE__, "node({$path}) with main_buss_id({$main_buss_id}) not exist!");
         echo json_encode($res);
         return;
     }
     $node_whole = $node["node_whole"];
     //[USERPERM CHECK]
     $userperm_ret = UserPermServ::checkPerm($op_user, $node_whole);
     if ($userperm_ret === FALSE) {
         QconfMgrLog::err(__FILE__, __LINE__, "Insufficient permission of {$op_user} on node {$node_whole}");
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_USER_PERM_PERMISSION_DENIED);
         echo json_encode($res);
         return;
     }
     $main_buss_id = $node["main_buss_id"];
     $sub_buss_id = $node["sub_buss_id"];
     // 3. idc validation
     $cur_idcs = $node["idc"];
     $check_res = self::idcValidation($idc, $cur_idcs);
     if ($check_res["errno"] != "0") {
         echo json_encode($check_res);
         return;
     }
     // 4. get snapshot content
     $snapshot_content = SnapShotUtil::getSnapShotContent($main_buss_id, $node_whole);
     if ($snapshot_content === FALSE) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_SNAPSHOT_MODULE_FAILED);
         QconfMgrLog::err(__FILE__, __LINE__, "failed to get snapshot by node_whole({$node_whole}), main_buss_id({$main_buss_id})");
         echo json_encode($res);
         return;
     }
     // 5.rollback
     if (!array_key_exists($idc, $snapshot_content)) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_SNAPSHOT_IDC_NOT_EXIST);
         QconfMgrLog::err(__FILE__, __LINE__, "snapshot of node_whole({$node_whole}), main_buss_id({$main_buss_id}) do not exist on idc({$idc}) ");
         echo json_encode($res);
         return;
     }
     $result_idc = $snapshot_content[$idc];
     if (!array_key_exists("conf", $result_idc) || !array_key_exists("serv", $result_idc)) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_SNAPSHOT_FILE_ERROR);
         QconfMgrLog::err(__FILE__, __LINE__, "snapshot error of node_whole({$node_whole}), main_buss_id({$main_buss_id})");
         echo json_encode($res);
         return;
     }
     $idc_host = ZkConf::getZkHost($idc);
     $zk_web = new QconfZkWebBase(Log::INFO);
     $zk_web->connect($idc_host);
     $result_conf = $result_idc["conf"];
     foreach ($result_conf as $key => $value) {
         $set_ret = NodeController::setConfWithLink($zk_web, $key, $idc, $value);
         if ($set_ret != InfoDescUtil::QCONF_OK) {
             OpServ::insert(InfoDescUtil::OP_TYPE_MOD, $key, $idc, InfoDescUtil::OP_STATUS_ZOO_FAILED, $main_buss_id, $sub_buss_id, $op_user, "");
             $res = InfoDescUtil::getErrorMsg($set_ret);
             QconfMgrLog::err(__FILE__, __LINE__, "replace node value by snapshot failed, node_whole({$node_whole}),\n                    main_buss_id({$main_buss_id})");
             echo json_encode($res);
             return;
         }
         OpServ::insert(InfoDescUtil::OP_TYPE_MOD, $key, $idc, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $op_user, $value);
     }
     $result_serv = $result_idc["serv"];
     foreach ($result_serv as $key => $hosts) {
         $current_serv_no_statu = array();
         $snapshot_serv_no_statu = array_keys($hosts);
         $get_ret = ServiceController::getServicesWithLink($zk_web, $key, $idc, $current_serv_no_statu);
         if ($get_ret != InfoDescUtil::QCONF_OK) {
             $res = InfoDescUtil::getErrorMsg($get_ret);
             QconfMgrLog::err(__FILE__, __LINE__, "get service failed, key({$key})!");
             echo json_encode($res);
             return;
         }
         $serv_to_add = array_diff($snapshot_serv_no_statu, $current_serv_no_statu);
         $serv_to_delete = array_diff($current_serv_no_statu, $snapshot_serv_no_statu);
         $serv_to_modify = array_intersect($snapshot_serv_no_statu, $current_serv_no_statu);
         foreach ($serv_to_add as $ser) {
             $show_ser_path = PathUtil::unionPath($key, $ser);
             $add_ret = ServiceController::addServiceWithLink($zk_web, $key, $ser, $idc, $hosts[$ser]);
             if ($add_ret != InfoDescUtil::QCONF_OK) {
                 $res = InfoDescUtil::getErrorMsg($add_ret);
                 OpServ::insert(InfoDescUtil::OP_TYPE_ADD, $show_ser_path, $idc, InfoDescUtil::OP_STATUS_ZOO_FAILED, $main_buss_id, $sub_buss_id, $op_user, "");
                 echo json_encode($res);
                 return;
             }
             OpServ::insert(InfoDescUtil::OP_TYPE_ADD, $show_ser_path, $idc, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $op_user, "");
         }
         foreach ($serv_to_modify as $ser) {
             $show_ser_path = PathUtil::unionPath($key, $ser);
             $snapshot_statu = $hosts[$ser];
             if ($snapshot_statu === InfoDescUtil::SERV_STATUS_UP || $snapshot_statu === InfoDescUtil::SERV_STATUS_DOWN) {
                 $modify_ret = ServiceController::upServiceWithLink($zk_web, $key, $ser, $idc);
                 $modify_type = InfoDescUtil::OP_TYPE_UP;
             } else {
                 if ($snapshot_statu === InfoDescUtil::SERV_STATUS_OFFLINE) {
                     $modify_ret = ServiceController::offlineServiceWithLink($zk_web, $key, $ser, $idc);
                     $modify_type = InfoDescUtil::OP_TYPE_OFFLINE;
                 } else {
                     QconfMgrLog::err(__FILE__, __LINE__, "service status is unknown, show_ser_path({$show_ser_path})!");
                 }
             }
             if ($modify_ret != InfoDescUtil::QCONF_OK) {
                 $res = InfoDescUtil::getErrorMsg($modify_ret);
                 OpServ::insert($modify_type, $show_ser_path, $idc, InfoDescUtil::OP_STATUS_ZOO_FAILED, $main_buss_id, $sub_buss_id, $op_user, "");
                 echo json_encode($res);
                 return;
             }
             OpServ::insert($modify_type, $show_ser_path, $idc, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $op_user, "");
         }
         foreach ($serv_to_delete as $ser) {
             $show_ser_path = PathUtil::unionPath($key, $ser);
             $delete_ret = ServiceController::deleteServiceWithLink($zk_web, $key, $ser, $idc);
             if ($delete_ret != InfoDescUtil::QCONF_OK) {
                 $res = InfoDescUtil::getErrorMsg($delete_ret);
                 OpServ::insert(InfoDescUtil::OP_TYPE_DEL, $show_ser_path, $idc, InfoDescUtil::OP_STATUS_ZOO_FAILED, $main_buss_id, $sub_buss_id, $op_user, "");
                 echo json_encode($res);
                 return;
             }
             OpServ::insert(InfoDescUtil::OP_TYPE_DEL, $show_ser_path, $idc, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $op_user, "");
         }
     }
     OpServ::insert(InfoDescUtil::OP_TYPE_SNAPSHOT_ROLLBACK, $node_whole, $idc, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $op_user, "");
     $res = array("errno" => "0", "errmsg" => "", "data" => "rollback success");
     $json = json_encode($res);
     echo $json;
     return;
 }
 public function modMultiConfAction()
 {
     $node_array = $this->getRequest("node_array", "");
     $main_buss_id = $this->getRequest("main_buss_id", "");
     $sub_buss_id = $this->getRequest("sub_buss_id", "");
     $op_user = $this->userInfo["userName"];
     // 1. parameter is not right
     if ($node_array === "" || $idc === "" || $main_buss_id === "") {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS);
         QconfMgrLog::err(__FILE__, __LINE__, "parameter 'idc'" . " 'node_array' 'main_buss_id' is null!");
         echo json_encode($res);
         return;
     }
     $modify_nodes = json_decode($node_array);
     // 2. validation
     if ($modify_nodes === NULL || !is_array($modify_nodes)) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS);
         QconfMgrLog::err(__FILE__, __LINE__, "node : node_array({$node_array}) format error!");
         echo json_encode($res);
         return;
     }
     $checked_nodes = array();
     foreach ($modify_nodes as $modify_node_info) {
         if (!is_array($modify_node_info)) {
             //TODO reutrn false
         }
         $cur_id = $modify_node_info["node_id"];
         $cur_value = $modify_node_info["value"];
         $cur_idc = $modify_node_info["idc"];
         // check parameter null
         if ($cur_id === null || $cur_value === null || $cur_idc === null) {
             //TODO return false
         }
         //check node exist
         $cur_node = NodeServ::getNode($cur_id);
         if ($dbnode === FALSE) {
             $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_NODE_NOT_EXIST);
             QconfMgrLog::err(__FILE__, __LINE__, "node : {$cur_id} is not exist!");
             echo json_encode($res);
             return;
         }
         //[USERPERM CHECK]
         $cur_node_whole = $cur_node["node_whole"];
         $userperm_ret = UserPermServ::checkPerm($op_user, $cur_node_whole);
         if ($userperm_ret === FALSE) {
             QconfMgrLog::err(__FILE__, __LINE__, "Insufficient permission of {$op_user} on node {$cur_node_whole}");
             $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_USER_PERM_PERMISSION_DENIED);
             echo json_encode($res);
             return;
         }
         // check idc
         $idc_host = ZkConf::getZkHost($cur_idc);
         if ($idc_host === NULL) {
             //TODO return false
         }
         // pass validation
         $item = array();
         $item["idc"] = $cur_idc;
         $item["value"] = $cur_value;
         $item["node"] = $cur_node;
         $checked_nodes[$cur_id] = $item;
     }
     // 3. actually do modification
     foreach ($checked_nodes as $node_id => $item) {
         $idc = $item["idc"];
         $node = $item["node"];
         $node_val = $item["value"];
         $ret = self::modNodeValue($node_id, $idc, $node["node_whole"], $node["main_buss_id"], $node["sub_buss_id"], $node_val, "", $op_user);
         if ($ret != 0) {
             $res = InfoDescUtil::getErrorMsg($ret);
             echo json_encode($res);
             return;
         }
     }
     // return success
     $res = array("errno" => "0", "errmsg" => "", "data" => "modify success!");
     $json = json_encode($res);
     echo $json;
 }