예제 #1
0
 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 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;
 }
예제 #3
0
 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;
 }
예제 #4
0
 public function updateConfAction()
 {
     $node_whole = trim($this->getRequest("node_whole", ""), "/");
     $idc = $this->getRequest("idc", "");
     $node_val = $this->getRequest("node_val", "");
     $main_buss_id = $this->getRequest("main_buss_id", "");
     $sub_buss_id = $this->getRequest("sub_buss_id", "");
     $note = $this->getRequest("note", "");
     $op_user = $this->userInfo["userName"];
     // 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!");
         echo json_encode($res);
         return;
     }
     // 2. parameter replenish
     $node_whole = "/" . $node_whole;
     // 3. check whether node already exist
     $cur_node = NodeServ::getNodeByNodeWhole($node_whole, $main_buss_id);
     if ($cur_node === FALSE) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_NODE_NOT_EXIST);
         QconfMgrLog::err(__FILE__, __LINE__, "node({$node_whole}) of main_buss_id({$main_buss_id}) not exist ");
         echo json_encode($res);
         return;
     }
     /*
            //[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;
            }
     */
     // 4. idc validation
     $idc = trim($idc, ",");
     $idc_list = preg_split("/[,]+/", $idc);
     $cur_idcs = $cur_node["idc"];
     $cur_idcs_array = explode(',', $cur_idcs);
     foreach ($idc_list as $idc_each) {
         // 4.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;
             echo json_encode($res);
             return;
         }
         // 4.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;
             echo json_encode($res);
             return;
         }
     }
     // 5.3 modify conf
     $res = ExtraController::modifyConfAfterParamValidation($op_user, $node_whole, $idc, $main_buss_id, $sub_buss_id, $note, $node_val);
     if ($res["errno"] != "0") {
         echo json_encode($res);
         return;
     }
     // 6. return success
     $res = array("errno" => "0", "errmsg" => "", "data" => "update node success!");
     $json = json_encode($res);
     echo $json;
     return;
 }