public static function getAllZk() { $zks = json_decode(QConf::getConf("/qconf/zk/location"), TRUE); foreach ($zk as $idc => $l) { echo "{$idc} => {$l}" . PHP_EOL; QconfMgrLog::err(__FILE__, __LINE__, "{$idc} => {$l}"); } return $zks; }
public function query($query) { if ($this->connect()) { if (FALSE === ($ret = mysql_query($query, $this->conn))) { QconfMgrLog::err(__FILE__, __LINE__, "Exec failed! {$query}"); QconfMgrLog::err(__FILE__, __LINE__, mysql_error()); } return $ret; } return FALSE; }
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 static function recordOp($op_type_code, $hostname, $node_whole, $idc, $data_type, $value_md5, $update_time) { $op_time = date('Y-m-d H:i:s', time()); ArgsUtil::setSQLEscape($op_type_code); ArgsUtil::setSQLEscape($hostname); ArgsUtil::setSQLEscape($node_whole); ArgsUtil::setSQLEscape($idc); ArgsUtil::setSQLEscape($data_type); ArgsUtil::setSQLEscape($value_md5); ArgsUtil::setSQLEscape($update_time); ArgsUtil::setSQLEscape($op_time); $query = "insert into qconf_feedback_op (op_type_code, hostname, node_whole, idc, data_type, value_md5, update_time, op_time) \n values ('{$op_type_code}', '{$hostname}', '{$node_whole}', '{$idc}', '{$data_type}', '{$value_md5}', '{$update_time}', '{$op_time}')"; $res = self::executeQuery($query); if ($res === FALSE) { QconfMgrLog::err(__FILE__, __LINE__, "EXEC '{$query}' failed!"); return FALSE; } return TRUE; }
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 static function modNodeType($parent_node_id) { if ($parent_node_id === NULL || $parent_node_id === "") { QconfMgrLog::err(__FILE__, __LINE__, "'parent_node_id' is NULL"); return FALSE; } ArgsUtil::setVal($parent_node_id); $query = "select * from qconf_node where node_id = '{$parent_node_id}'"; $res = self::executeQuery($query); if ($res === FALSE) { return FALSE; } $p_row = mysql_fetch_array($res, MYSQL_ASSOC); if ($p_row === FALSE) { QconfMgrLog::err(__FILE__, __LINE__, "EXEC '{$query}' failed!"); return FALSE; } if ($p_row['node_type_code'] == InfoDescUtil::NODE_TYPE_NORMAL) { $update = "update qconf_node set node_type_code = '" . InfoDescUtil::NODE_TYPE_SERV_FATHER . "' where node_id = '{$parent_node_id}'"; $ret = self::executeQuery($update); if ($ret === FALSE) { QconfMgrLog::err(__FILE__, __LINE__, "EXEC '{$update}' failed!"); return FALSE; } } return TRUE; }
public static function delPermByIdc($perm_node, $main_buss_id, $idc) { if ($perm_node === NULL || $perm_node === "" || $main_buss_id === NULL || $main_buss_id === "" || $idc === NULL || $idc === "") { QconfMgrLog::err(__FILE__, __LINE__, "perm_node, main_buss_id or idc is NULL"); return FALSE; } ArgsUtil::setSQLEscape($perm_node); ArgsUtil::setSQLEscape($main_buss_id); ArgsUtil::setSQLEscape($idc); $query = "select * from qconf_perm where node = '{$perm_node}' and main_buss_id = '{$main_buss_id}'"; $res = self::executeQuery($query); if ($res === FALSE) { return FALSE; } // 1. not found the perm $num = mysql_num_rows($res); if ($num === 0) { QconfMgrLog::err(__FILE__, __LINE__, "EXEC '{$query}' failed!"); return FALSE; } $row = mysql_fetch_array($res, MYSQL_ASSOC); $perm_id = $row["perm_id"]; $idc_list = preg_split("/[,]+/", $row['idc']); foreach ($idc_list as $idc_tmp) { if (strcmp($idc, $idc_tmp) !== 0) { $idc_left .= ",{$idc_tmp}"; } } if (!isset($idc_left)) { $query = "delete from qconf_perm where perm_id = '{$perm_id}'"; } else { $idc_left = trim($idc_left, ","); $query = "update qconf_perm set idc = '{$idc_left}' where perm_id = '{$perm_id}'"; } // 2. update the idc info $res = self::executeQuery($query); if ($res === FALSE) { QconfMgrLog::err(__FILE__, __LINE__, "EXEC {$query} failed!"); return FALSE; } return TRUE; }
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; }
private static function existFeedback($fd_id) { if ($fd_id === NULL) { QconfMgrLog::err(__FILE__, __LINE__, "fd_id is NULL"); return FALSE; } $query = "select count(feedback_id) from qconf_feedback where feedback_id = '{$fd_id}'"; $res = self::executeQuery($query); if ($res === FALSE) { QconfMgrLog::err(__FILE__, __LINE__, "execute {$query} failed"); return FALSE; } $num = $res['count']; if ($num === 0) { return FALSE; } return TRUE; }
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; }
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; }
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; }
private static function check_path($path, $op_user) { // 1. check length $snappath = SnapShotUtil::getSnapShotPath($path, $op_user); $snappath_length = strlen($snappath); if ($snappath_length >= InfoDescUtil::SNAPSHOT_PATH_MAX_LENGTH) { QconfMgrLog::err(__FILE__, __LINE__, "path of snapshot is too long, path_lengrh({$snappath_length})"); return InfoDescUtil::ERR_SNAPSHOT_PATH_TO_LONG; } // 2. check character $path_reg = "/^[\\w\\d_\\-\\.:\\/]+\$/"; $is_illegal = preg_match($path_reg, $path); if ($is_illegal === 0) { QconfMgrLog::err(__FILE__, __LINE__, "illegal path, path({$path})"); return InfoDescUtil::ERR_SNAPSHOT_PATH_ILLEGAL; } return InfoDescUtil::QCONF_OK; }
private function changeToNormalPath($path) { if ($path === NULL || $path === '') { QconfMgrLog::err(__FILE__, __LINE__, "path is NULL"); return FALSE; } $sub_path = trim($path); $sub_path = trim($sub_path, '#'); $sub_path = str_replace('#', '/', $sub_path); $sub_path = '/' . $sub_path; return $sub_path; }
public function deleteNormal($normal_user, $node_whole) { if ($normal_user === NULL || $normal_user === "" || $node_whole === NULL || $node_whole === "") { QconfMgrLog::err(__FILE__, __LINE__, "normal_user or node is NULL"); return FALSE; } $node_whole = "/" . trim($node_whole, "/") . "/"; ArgsUtil::setSQLEscape($normal_user); ArgsUtil::setSQLEscape($node_whole); $query = "select count(*) from qconf_normal_perm where binary user_name = '{$normal_user}' and binary node = '{$node_whole}'"; $res = self::executeQuery($query); if ($res === FALSE) { return FALSE; } $ret_arr = mysql_fetch_array($res, MYSQL_NUM); if ($ret_arr[0] <= 0) { return InfoDescUtil::ERR_USER_PERM_NODE_NOT_EXIST; } $query = "delete from qconf_normal_perm where binary user_name = '{$normal_user}' and binary node = '{$node_whole}'"; $res = self::executeQuery($query); if ($res === FALSE) { return FALSE; } return InfoDescUtil::QCONF_OK; }
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; }
/** * 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; }
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 static function getFeedback($feedback_id) { if ($feedback_id === NULL) { QconfMgrLog::err(__FILE__, __LINE__, "feedback_id is NULL"); return FALSE; } $query = "select * from qconf_feedback where feedback_id = '{$feedback_id}'"; $res = self::executeQuery($query); if ($res === FALSE) { QconfMgrLog::err(__FILE__, __LINE__, "execute {$query} failed"); return FALSE; } $row = mysql_fetch_array($res, MYSQL_ASSOC); return $row; }
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 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; }