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 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 deleteConfAction()
 {
     // 1.receive arguments
     $res = "";
     $argus = self::commonArgusProcess($res);
     if ($argus == FALSE) {
         echo json_encode($res);
         return false;
     }
     $user = $argus["user"];
     $path = $argus["path"];
     $idc = $argus["idc"];
     $main_buss_id = $argus["main_buss_id"];
     $sub_buss_id = $argus["sub_buss_id"];
     $desc = $argus["desc"];
     // 2.get node
     $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;
     }
     // 3.validate path
     $node_type = $cur_node["node_type_code"];
     $qconf_node_path = PathUtil::getQconfPath($path);
     $zk_web = new QconfZkWebBase(Log::INFO);
     $idc_list = preg_split("/[,]+/", $idc);
     if ($node_type == InfoDescUtil::NODE_TYPE_NORMAL_FATHER) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_SUB_NODE_NOT_NULL);
         QconfMgrLog::err(__FILE__, __LINE__, "node:{$path} has children who is normal node");
         echo json_encode($res);
         return;
     } else {
         if ($node_type == InfoDescUtil::NODE_TYPE_SERV_FATHER) {
             foreach ($idc_list as $idc_each) {
                 $idc_host = ZkConf::getZkHost($idc_each);
                 $zk_web->connect($idc_host);
                 $children = $zk_web->get_children($qconf_node_path);
                 if ($children == -1) {
                     $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_ZOOKEEPER_FAIL);
                     echo json_encode($res);
                     OpServ::insert(InfoDescUtil::OP_TYPE_DEL, $path, $idc, InfoDescUtil::OP_STATUS_ZOO_FAILED, $main_buss_id, $sub_buss_id, $user, "");
                     return;
                 }
                 //children exist
                 if (count($children) > 0) {
                     QconfMgrLog::err(__FILE__, __LINE__, "node:{$path} has service node as its children!");
                     $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_SUB_NODE_NOT_NULL);
                     echo json_encode($res);
                     return;
                 }
             }
         }
     }
     $node_id = $cur_node["node_id"];
     foreach ($idc_list as $idc_each) {
         mysql_query("BEGIN");
         // 4.delete from database
         $ret_db = NodeServ::delNodeByIdc($node_id, $idc_each);
         if ($ret_db === TRUE && $cur_node["node_level"] == 1) {
             $ret_db = PermServ::delPermByIdc(trim($path, "\\/"), $main_buss_id, $idc);
             if ($ret_db === TRUE) {
                 // notify admins
                 AdminConf::notifyAdmin("Delete root node " . $path . " for {$user} on {$idc_each}", $user, FALSE);
             }
         }
         if ($ret_db === FALSE) {
             mysql_query("ROLLBACK");
             QconfMgrLog::err(__FILE__, __LINE__, "delete from database for node:{$path}, idc:{$idc_each} failed!");
             $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_MYSQL_FAIL);
             echo json_encode($res);
             OpServ::insert(InfoDescUtil::OP_TYPE_DEL, $path, $idc, InfoDescUtil::OP_STATUS_MYSQL_FAILED, $main_buss_id, $sub_buss_id, $user, "");
             return;
         }
         // 5.delete from zookeeper
         $idc_host = ZkConf::getZkHost($idc_each);
         $zk_web->connect($idc_host);
         $retry_time = 0;
         $ret_zk = -1;
         while ($retry_time++ < 3 && $ret_zk === -1) {
             if ($node_type == InfoDescUtil::NODE_TYPE_SERV_FATHER) {
                 $ret_zk = $zk_web->delete_group_path($qconf_node_path);
             } else {
                 $ret_zk = $zk_web->delete_conf($qconf_node_path);
             }
             if ($ret_zk === -1) {
                 QconfMgrLog::err(__FILE__, __LINE__, "fail to delete conf from zookeeper! retry time {$retry_time}");
             }
         }
         if ($retry_time >= 3) {
             mysql_query("ROLLBACK");
             QconfMgrLog::err(__FILE__, __LINE__, "delete from zookeeper for node:{$path}, idc:{$idc_each} failed!");
             $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_ZOOKEEPER_FAIL);
             echo json_encode($res);
             OpServ::insert(InfoDescUtil::OP_TYPE_DEL, $path, $idc, InfoDescUtil::OP_STATUS_ZOO_FAILED, $main_buss_id, $sub_buss_id, $user, "");
             return;
         }
         mysql_query("COMMIT");
     }
     OpServ::insert(InfoDescUtil::OP_TYPE_DEL, $path, $idc, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $user, "");
     $res = array("errno" => "0", "errmsg" => "", "data" => "delete success");
     $json = json_encode($res);
     echo $json;
 }
 public function setConfWithLink($zk_web, $node_whole, $idc, $value)
 {
     $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 set value for {$node_whole} on {$idc}");
         $ret = $zk_web->set_conf(PathUtil::getQconfPath($node_whole), $value);
         $retry_time++;
     }
     if ($ret === -1) {
         QconfMgrLog::err(__FILE__, __LINE__, "Failed to set conf value by node_whole, {$node_whole}!");
         return InfoDescUtil::ERR_ZOOKEEPER_FAIL;
     }
     return InfoDescUtil::QCONF_OK;
 }