Пример #1
0
 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;
 }