public function dispatch($action) { /*{{{*/ $ret = $this->preDispatch(); if ($ret === FALSE) { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_NOT_LOGIN); QconfMgrLog::err(__FILE__, __LINE__, "User not login with domain account!"); echo json_encode($res); return; } else { $this->{$action}(); } $this->postDispatch(); }
public function getValAction() { // $op_id = isset($_GET["op_id"]) ? $_GET["op_id"] : ""; $op_id = $this->getRequest("op_id", ""); // 1. parameter is not right if ($op_id === "") { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS); QconfMgrLog::err(__FILE__, __LINE__, "parameter 'op_id' is null!"); echo json_encode($res); return; } $data = OpServ::getMsgById($op_id); if ($data === FALSE) { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_NODE_NOT_EXIST); QconfMgrLog::err(__FILE__, __LINE__, "parameter 'Node not exist'!"); echo json_encode($res); return; } $res = array("errno" => "0", "errmsg" => "", "data" => $data); $json = json_encode($res); echo $json; }
public function deleteFeedbackAction() { $feedback_id = $this->getRequest("feedback_id", ""); // 1. check parameters if ($feedback_id === "") { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS); QconfMgrLog::err(__FILE__, __LINE__, "parameter feedback_id is null!"); echo json_encode($res); return; } // 2. delete feedback from database $feedback = FeedbackServ::getFeedback($feedback_id); if ($feedback === FALSE || empty($feedback)) { QconfMgrLog::err(__FILE__, __LINE__, "get feedback failed of feedback({$feedback_id})"); $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_FEEDBACK_NOT_EXIST); echo json_encode($res); return; } $delete_res = FeedbackServ::deleteFeedback($feedback_id); if ($delete_res === FALSE) { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_MYSQL_FAIL); QconfMgrLog::err(__FILE__, __LINE__, "failed to delete feedback({$feedback_id})"); echo json_encode($res); return; } // 3. record delete operation $update_time = date('Y-m-d H:i:s', time()); $fd_op_res = FeedbackOpServ::recordOp(InfoDescUtil::OP_TYPE_FEEDBACK_DELETE, $feedback["hostname"], $feedback["node_whole"], $feedback["idc"], $feedback["data_type"], $feedback["value_md5"], $update_time); if ($fd_op_res === FALSE) { QconfMgrLog::err(__FILE__, __LINE__, "failed to feedback op of feedback({$feedback_id})"); } // 4. return result $res = array("errno" => "0", "errmsg" => "", "data" => ""); $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; } }
require_once dirname(".") . "/InfoDescUtil.php"; echo InfoDescUtil::getErrorCodeDesc(0) . PHP_EOL; echo InfoDescUtil::getErrorCodeDesc("0") . PHP_EOL; echo InfoDescUtil::getErrorCodeDesc(1) . PHP_EOL; echo InfoDescUtil::getErrorCodeDesc("1") . PHP_EOL; echo InfoDescUtil::getErrorCodeDesc(2) . PHP_EOL; echo InfoDescUtil::getErrorCodeDesc("2") . PHP_EOL; echo InfoDescUtil::getErrorCodeDesc(3) . PHP_EOL; echo InfoDescUtil::getErrorCodeDesc("3") . PHP_EOL; echo InfoDescUtil::getErrorCodeDesc(4) . PHP_EOL; echo InfoDescUtil::getErrorCodeDesc("4") . PHP_EOL; echo InfoDescUtil::getErrorCodeDesc(5) . PHP_EOL; echo InfoDescUtil::getErrorCodeDesc("5") . PHP_EOL; echo InfoDescUtil::getErrorCodeDesc(6) . PHP_EOL; echo InfoDescUtil::getErrorCodeDesc("6") . PHP_EOL; /* echo InfoDescUtil::getApplyStatus(0) . PHP_EOL; echo InfoDescUtil::getApplyStatus("0") . PHP_EOL; echo InfoDescUtil::getApplyStatus(1) . PHP_EOL; echo InfoDescUtil::getApplyStatus("1") . PHP_EOL; echo InfoDescUtil::getApplyStatus(2) . PHP_EOL; echo InfoDescUtil::getApplyStatus("2") . PHP_EOL; echo InfoDescUtil::getApplyStatus(3) . PHP_EOL; echo InfoDescUtil::getApplyStatus("3") . PHP_EOL; */ /* echo InfoDescUtil::getNodeTypeDesc(0) . PHP_EOL; echo InfoDescUtil::getNodeTypeDesc("0") . PHP_EOL; echo InfoDescUtil::getNodeTypeDesc(1) . PHP_EOL; echo InfoDescUtil::getNodeTypeDesc("1") . PHP_EOL;
private function upOrOfflineService($op_type) { // 1.argument receive and preprocess $res = ""; $argus = self::commonArgusProcess($res); if ($argus === FALSE) { echo json_encode($res); return; } $user = $argus["user"]; $path = $argus["path"]; $idc = $argus["idc"]; $main_buss_id = $argus["main_buss_id"]; $sub_buss_id = $argus["sub_buss_id"]; $service_name = $this->getRequest("service_name", ""); if ($service_name === "") { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS); QconfMgrLog::err(__FILE__, __LINE__, "paramter: 'service_name({$service_name})'is required!"); echo json_encode($res); return; } $service_list = preg_split("/[,]+/", trim($service_name, ",")); //validate for ip_port if (ArgsUtil::ipPortsValidation($service_list) === FALSE) { //failed to add any new services $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS); QconfMgrLog::err(__FILE__, __LINE__, "ilegal services : {$service_name} under {$path}!"); echo json_encode($res); return; } // 2. check node exist and is node father type $check_res = ServiceController::checkServFatherNode($path, $main_buss_id); if ($check_res != InfoDescUtil::QCONF_OK) { $res = InfoDescUtil::getErrorMsg($check_res); echo json_encode($res); return; } // 3. do up or offline $op_type_msg = $op_type === InfoDescUtil::OP_TYPE_OFFLINE ? "offline" : "up"; $idc_list = preg_split("/[,]+/", $idc); // split by , foreach ($idc_list as $idc_each) { $idc_host = ZkConf::getZkHost($idc_each); $zk_web = new QconfZkWebBase(Log::INFO); $zk_web->connect($idc_host); $get_ret = ServiceController::getServicesAndStatusWithLink($zk_web, $path, $idc_each, $exist_services); if ($get_ret != InfoDescUtil::QCONF_OK) { $res = InfoDescUtil::getErrorMsg($get_ret); echo json_encode($res); return; } foreach ($service_list as $service) { $show_ser_path = PathUtil::unionPath($path, $service); // check service exist if (!array_key_exists($service, $exist_services)) { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_SERVICE_NO_EXIST); echo json_encode($res); return; } if ($op_type === InfoDescUtil::OP_TYPE_OFFLINE) { //check up service cout for offline operation $is_last = TRUE; foreach ($exist_services as $one_exist_service => $service_status) { if ($service_status === InfoDescUtil::SERV_STATUS_UP && $one_exist_service != $service) { $is_last = FALSE; break; } } if ($is_last) { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_OFFILE_SERVICE_ONLY); QconfMgrLog::err(__FILE__, __LINE__, "{$service} is the last up service under {$path}"); echo json_encode($res); return; } $ret = ServiceController::offlineServiceWithLink($zk_web, $path, $service, $idc_each); $exist_services[$service] = InfoDescUtil::SERV_STATUS_DOWN; } else { $ret = ServiceController::upServiceWithLink($zk_web, $path, $service, $idc_each); } if ($ret != InfoDescUtil::QCONF_OK) { $res = InfoDescUtil::getErrorMsg($ret); QconfMgrLog::err(__FILE__, __LINE__, "{$op_type_msg} service!"); OpServ::insert($op_type, $show_ser_path, $idc_each, InfoDescUtil::OP_STATUS_ZOO_FAILED, $main_buss_id, $sub_buss_id, $user, ""); echo json_encode($res); return; } OpServ::insert($op_type, $show_ser_path, $idc_each, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $user, $op_type === InfoDescUtil::OP_TYPE_OFFLINE ? InfoDescUtil::SERV_STATUS_OFFLINE : InfoDescUtil::SERV_STATUS_UP); } } $res = array("errno" => "0", "errmsg" => "", "data" => "{$op_type_msg} service success"); $json = json_encode($res); echo $json; return; }
public function deleteAdminAction() { $main_buss_id = $this->getRequest("main_buss_id", ""); $user_name = $this->getRequest("user_name", ""); $node = trim($this->getRequest("node", "")); $op_user = $this->userInfo["userName"]; if ($main_buss_id === "" || $user_name === "" || $node === "") { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS); QconfMgrLog::err(__FILE__, __LINE__, "parameter 'main_buss_id' or 'user_name' or 'node' is null!"); echo json_encode($res); return; } $flags = UserPermServ::checkSuperAdmin($op_user); if ($flags !== InfoDescUtil::QCONF_OK) { if ($flags === FALSE) { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_MYSQL_FAIL); } else { $res = InfoDescUtil::getErrorMsg($flags); } QconfMgrLog::err(__FILE__, __LINE__, "user:{$op_user} is not super admin!"); echo json_encode($res); return; } $flags = UserPermServ::deleteAdmin($user_name, $node); if ($flags !== InfoDescUtil::QCONF_OK) { OpServ::insert(InfoDescUtil::OP_TYPE_USER_PERM_ADMIN_DELETE, $node, "", InfoDescUtil::OP_STATUS_MYSQL_FAILED, $main_buss_id, "NULL", $op_user, "delete admin:{$user_name} perm failed!"); if ($flags === FALSE) { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_MYSQL_FAIL); } else { $res = InfoDescUtil::getErrorMsg($flags); } QconfMgrLog::err(__FILE__, __LINE__, "super admin:{$op_user} delete admin:{$user_name} of node:{$node} failed!"); echo json_encode($res); return; } OpServ::insert(InfoDescUtil::OP_TYPE_USER_PERM_ADMIN_DELETE, $node, "", InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, "NULL", $op_user, "delete amdin:{$user_name} perm success!"); $res = array("errno" => "0", "errmsg" => "", "data" => "delete admin user success"); $json = json_encode($res); echo $json; }
public function rejectNodeAction() { $this->setNoViewRender(true); // $perm_id = isset($_POST['perm_id']) ? $_POST['perm_id'] : ""; $perm_id = $this->getRequest("perm_id", ""); $admin_user = $this->userInfo["userName"]; $sub_buss_id = "NULL"; // 2. parameter is not right if ($perm_id === "") { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS); QconfMgrLog::err(__FILE__, __LINE__, "parameter '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"]; $op_user_email = $res["apply_user_email"]; $node = $res["node"]; $idc = $res["idc"]; $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; } $ret = PermServ::modPerm($perm_id, InfoDescUtil::APPLY_STATUS_NOT_PASS); // 4. update the apply staus failed if ($ret === FALSE) { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_MYSQL_FAIL); QconfMgrLog::err(__FILE__, __LINE__, "update the apply stats in qconf_perm failed!"); echo json_encode($res); return; } OpServ::insert(InfoDescUtil::OP_TYPE_AUDIT_REJECT, $qconf_path, $idc, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $op_user, ""); // 5. return the data $res = array("errno" => "0", "errmsg" => "", "data" => ""); NotifyUtil::notifyByQHEmail($op_user_email, "node: '{$node}' apply on '{$idc}' has been REJECTED", " 在机房 {$idc} 申请的根节点 {$node} 被拒绝! ", $admin_user); $json = json_encode($res); echo $json; }
/** * list the op log */ public static function listByCondition($node, $op_user, $idc, $main_buss_id, $sub_buss_id) { ArgsUtil::setSQLEscape($node); ArgsUtil::setSQLEscape($op_user); ArgsUtil::setSQLEscape($idc); ArgsUtil::setVal($main_buss_id); ArgsUtil::setVal($sub_buss_id); $query = ArgsUtil::getSQLStatOfArgs("main_buss_id", $main_buss_id, "=", "node", $node, "like", "op_user", $op_user, "like", "idc", $idc, "like"); if ($query === FALSE) { // the argument is not right QconfMgrLog::err(__FILE__, __LINE__, "set sql statment failed!"); return FALSE; } $obj = "op_id,op_type_code,node,idc,op_time,op_status_code,main_buss_id,sub_buss_id,op_user"; if ($query !== NULL) { $query = "select {$obj} from qconf_op where " . $query . " order by op_time desc;"; } else { $query = "select {$obj} from qconf_op order by op_time desc;"; } //echo $query . PHP_EOL; // get the records from database, and resolve them $res = self::executeQuery($query); if (mysql_num_rows($res) === 0) { QconfMgrLog::err(__FILE__, __LINE__, "No value of '{$query}'"); return FALSE; } while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) { $row['msg'] = ""; $op_type_code = $row["op_type_code"]; $row["op_type_code"] = InfoDescUtil::getOpTypeDesc($op_type_code); $data[] = $row; } return $data; }
private function idcValidation($idcs, $cur_idcs) { if ($idcs === "" || $cur_idcs === "") { QconfMgrLog::err(__FILE__, __LINE__, "idc({$idc}), cur_idcs({$cur_idcs}) is null!"); return InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS); } $idcs = trim($idcs, ","); $idc_list = preg_split("/[,]+/", $idcs); $cur_idcs_array = explode(',', $cur_idcs); foreach ($idc_list as $idc_each) { // 1 check idc legitimacy $idc_host = ZkConf::getZkHost($idc_each); if ($idc_host === NULL) { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_IDC_NOT_EXIST); QconfMgrLog::err(__FILE__, __LINE__, "Illegal idc : {$idc_each}!"); $res["data"] .= $idc_each; return $res; } // 2 check node exist on all idcs $exist_idc = in_array($idc_each, $cur_idcs_array); if ($exist_idc === FALSE) { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_IDC_NOT_IN_DATABASE); QconfMgrLog::err(__FILE__, __LINE__, "node({$node_whole}) not exist on idc({$idc_each})"); $res["data"] .= $idc_each; return $res; } } $res = array("errno" => "0", "errmsg" => "", "data" => ""); return $res; }
public static function getErrorMsg($error_code) { $res = array("errno" => $error_code, "errmsg" => InfoDescUtil::getErrorCodeDesc($error_code), "data" => ""); return $res; }
public function feedbackAction() { $this->setNoViewRender(true); $hostname = $this->getRequest("hostname", ""); $ip = $this->getRequest("ip", ""); $node_whole = $this->getRequest("node_whole", ""); $idc = $this->getRequest("idc", ""); $value_md5 = $this->getRequest("value_md5", ""); $value = $this->getRequest("value", ""); $update_time = $this->getRequest("update_time", ""); $data_type = $this->getRequest("data_type", ""); // 0. get client ip $client_ip = self::getClientIp(); QconfMgrLog::err(__FILE__, __LINE__, "client_ip({$client_ip})" . "hostname({$hostname}), node_whole({$node_whole}), idc({$idc}), value_md5({$value_md5}) or data_type({$data_type})!"); // 1. validation for parameters if ($hostname === "" || $node_whole === "" || $idc === "" || $value_md5 === "" || $data_type === "") { //$res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS); QconfMgrLog::err(__FILE__, __LINE__, "hostname({$hostname}), node_whole({$node_whole}), idc({$idc}), value_md5({$value_md5}) or data_type({$data_type}) is NULL!"); echo InfoDescUtil::ERR_BAD_ARGS; return; } $md5_len = strlen($value_md5); if ($md5_len != 32) { //$res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_MD5_VALUE); QconfMgrLog::err(__FILE__, __LINE__, "Error length value_md5(value_md5) : {$md5_len}!"); echo InfoDescUtil::ERR_MD5_VALUE; return; } $format_time = date('Y-m-d H:i:s', $update_time); if ($format_time === FALSE) { QconfMgrLog::err(__FILE__, __LINE__, "error update_time format: {$update_time}"); //$res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS); echo InfoDescUtil::ERR_UPDATE_TIME; return; } if ($data_type != InfoDescUtil::QCONF_DATA_TYPE_NODE && $data_type != InfoDescUtil::QCONF_DATA_TYPE_SERVICE) { QconfMgrLog::err(__FILE__, __LINE__, "error data_type: {$data_type}"); //$res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS); echo InfoDescUtil::ERR_DATA_TYPE; return; } if (!ZkConf::isLegalIdc($idc)) { QconfMgrLog::err(__FILE__, __LINE__, "error idc: {$idc}"); $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_IDC_NOT_EXIST); echo InfoDescUtil::ERR_IDC_NOT_EXIST; return; } // 2.distinguish situation need add new item and modify old item $fd_item = FeedbackServ::checkFeedback($hostname, $node_whole, $idc, $data_type); $result = FALSE; if ($fd_item === FALSE) { //add new item $retry_time = 0; while ($result === FALSE && $retry_time < InfoDescUtil::MYSQL_MAX_RETRY_TIME) { $result = FeedbackServ::addFeedback($hostname, $ip, $node_whole, $idc, $data_type, $value_md5, $value, $format_time); if ($retry_time++ > 0) { QconfMgrLog::err(__FILE__, __LINE__, "retry {$retry_time} to add feedback with hostname({$hostname})" . " node_whole({$node_whole}) idc({$idc}), data_type({$data_type})!"); } } if ($result != FALSE) { FeedbackOpServ::recordOp(InfoDescUtil::OP_TYPE_FEEDBACK_ADD, $hostname, $node_whole, $idc, $data_type, $value_md5, $format_time); } } else { $old_update_time = $fd_item["update_time"]; if ($update_time < strtotime($old_update_time)) { QconfMgrLog::err(__FILE__, __LINE__, "update_time early than the last one, discard hostname({$hostname})," . " node_whole({$node_whole}) idc({$idc}), data_type({$data_type})!"); $result = TRUE; } else { $feedback_id = $fd_item["feedback_id"]; $retry_time = 0; while ($result === FALSE && $retry_time < InfoDescUtil::MYSQL_MAX_RETRY_TIME) { $result = FeedbackServ::modifyFeedback($feedback_id, $ip, $value_md5, $value, $format_time); if ($retry_time++ > 0) { QconfMgrLog::err(__FILE__, __LINE__, "retry {$retry_time} to modify feedback with hostname({$hostname})" . " node_whole({$node_whole}) idc({$idc}), data_type({$data_type})!"); } } if ($result != FALSE) { FeedbackOpServ::recordOp(InfoDescUtil::OP_TYPE_FEEDBACK_MODIFY, $hostname, $node_whole, $idc, $data_type, $value_md5, $format_time); } } } // 3. record feedback failed if ($result === FALSE) { QconfMgrLog::err(__FILE__, __LINE__, "Failed to record feedback for hostname({$hostname}),\n node_whole({$node_whole}), idc({$idc})!"); echo InfoDescUtil::ERR_MYSQL_FAIL; return; } echo InfoDescUtil::QCONF_OK; 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; }