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; }
<?php /* echo OpServ::insert("1", "/dba/mdb", "bjdt,shht,lyct,zwt", "0", 60, 61, NULL, NULL) . PHP_EOL; */ $b = OpServ::getMsgById("aefd7f5ef029282e703181abd479179e"); var_dump($b); $b = OpServ::getMsgById("aefd7f5ef029282e703181abd479179f"); var_dump($b); $b = OpServ::getMsgById("81546e565d6dfec7dc9bb22146dc43c6"); var_dump($b); $b = OpServ::getMsgById("88c8d8ff1dbe5b271b494f6d168a4cd9"); var_dump($b); /* $b = OpServ::getMsgById("aabbcc"); var_dump($b); $b = OpServ::listByCondition(NULL, "zhong'chao'", "", NULL, NULL); var_dump($b); $b = OpServ::listByCondition("/dba", NULL, NULL, NULL, NULL); var_dump($b); $b = OpServ::listByCondition(NULL, "zhong", NULL, NULL, NULL); var_dump($b); $b = OpServ::listByCondition(NULL, NULL, "zw", NULL, NULL); var_dump($b); $b = OpServ::listByCondition(NULL, NULL, NULL, 60, NULL);
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; }
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; }
private function addOrUpdateConfInternal($node_whole, $idc, $node_val, $main_buss_id, $sub_buss_id, $note, $op_user, $value_overwrite) { //echo "node_whole($node_whole), idc($idc), node_val($node_val), main_buss_id($main_buss_id)"; // 1. parameter is not right if ($node_whole === "" || $idc === "" || $main_buss_id === "" || $sub_buss_id === "") { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS); QconfMgrLog::err(__FILE__, __LINE__, "parameter 'node_whole' 'idc' 'main_buss_id' or 'sub_buss_id' is null!"); return $res; } // 1. check whether node already exist $cur_node = NodeServ::getNodeByNodeWhole($node_whole, $main_buss_id); $node_id = $cur_node["node_id"]; $idc = trim($idc, ","); $idc_list = preg_split("/[,]+/", $idc); if ($cur_node === FALSE) { // 2.1 add conf $ret = ExtraController::addConfAfterParamValidation($op_user, $node_whole, $idc, $main_buss_id, $sub_buss_id, $note, $node_val); if ($ret != 0) { $res = InfoDescUtil::getErrorMsg($ret); return $res; } } else { //distinguish idcs need to be add or modified $need_addidc_idcs = array(); $need_modify_idcs = ""; $cur_idcs = $cur_node["idc"]; $cur_idcs_array = explode(',', $cur_idcs); foreach ($idc_list as $idc_each) { $exist_idc = in_array($idc_each, $cur_idcs_array); if ($exist_idc === FALSE) { $need_addidc_idcs[$idc_each] = $node_val; } else { $need_modify_idcs .= $idc_each . ","; } } $need_modify_idcs = trim($need_modify_idcs, ","); // 2.2 add idc if (count($need_addidc_idcs) > 0) { $qconf_node_type = $cur_node["node_type_code"]; $failed_idcs = self::retryOperation($need_addidc_idcs, $node_whole, $qconf_node_type, $main_buss_id, $sub_buss_id, $op_user); if (count($failed_idcs) != 0) { //failed return $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_ZOOKEEPER_FAIL); foreach ($failed_idcs as $fail_idc => $value) { OpServ::insert(InfoDescUtil::OP_TYPE_EXPANSION, $node_whole, $add_idcs, InfoDescUtil::OP_STATUS_ZOO_FAILED, $main_buss_id, $sub_buss_id, $op_user, ""); if ($res["data"] != "") { $res["data"] .= ","; } $res["data"] .= "{$fail_idc}"; } return $res; } $add_idcs = ""; foreach ($need_addidc_idcs as $one_idc => $value) { $add_idcs .= ",{$one_idc}"; } $add_idcs = trim($add_idcs, ","); $ret = NodeServ::modIdc($node_id, $add_idcs); if ($ret === FALSE) { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_MYSQL_FAIL); OpServ::insert(InfoDescUtil::OP_TYPE_EXPANSION, $node_whole, $add_idcs, InfoDescUtil::OP_STATUS_MYSQL_FAILED, $main_buss_id, $sub_buss_id, $op_user, ""); return $res; } foreach ($need_addidc_idcs as $one_idc => $value) { OpServ::insert(InfoDescUtil::OP_TYPE_EXPANSION, $node_whole, $one_idc, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $op_user, $value); } } if ($need_modify_idcs != "" && $value_overwrite === TRUE) { // 3.3 modify conf $res = ExtraController::modifyConfAfterParamValidation($op_user, $node_whole, $need_modify_idcs, $main_buss_id, $sub_buss_id, $note, $node_val); if ($res["errno"] != "0") { return $res; } } } // 6. return success $res = array("errno" => "0", "errmsg" => "", "data" => "add or update node success!"); return $res; }