Example #1
0
 protected function call_acm($group_key, $key, $sub_key = null)
 {
     $acm_zk_path = $this->conf['zk_path'] . '/acm';
     $zk_expire = $this->conf['zk_expire'];
     $acm_conf = Ak_Zookeeper::getCached($acm_zk_path, 2, $zk_expire, 'Ak_McClient::checkAcmConf');
     if (!is_array($acm_conf)) {
         Ak_Log::warning("acm zk conf formate error!");
         return false;
     }
     for ($i = 1; $i <= $acm_conf['acm_idc_num']; ++$i) {
         $server_name = "server{$i}";
         if (!is_array($acm_conf['children'][$server_name])) {
             Ak_Log::warning("acm {$server_name} not exist!");
             continue;
         }
         $server_conf = $acm_conf['children'][$server_name];
         $this->span_idc->registerResource(self::ACM_RESOURCE, $server_conf['idc'], $server_name);
     }
     $resources = $this->span_idc->getResource($this->conf['span_idc_strategy_index'], self::ACM_RESOURCE, $this->conf['curr_idc']);
     if (count($resources) == 0) {
         Ak_Log::warning("get resources is empty!");
         return false;
     }
     foreach ($resources as $server_name) {
         $acm_path = $this->conf['zk_path'] . "/acm/{$server_name}";
         $aclient_conf = array('Source' => 'Galileo', 'Protocol' => 'Nshead', 'Scheduler' => 'Closest', 'GalileoConf' => array('Path' => $acm_path), 'ClosestConf' => array('AlwaysRetry' => true), 'NsheadConf' => array('ConnectTimeOut' => $this->conf['acm_connect_timeout'], 'WriteTimeOut' => $this->conf['acm_write_timeout'], 'ReadTimeOut' => $this->conf['acm_read_timeout']));
         $client = new Ak_AClient();
         $client->SetConf($aclient_conf);
         $idc_list = array();
         for ($i = 0; $i < $this->zk_conf['idc_num']; $i++) {
             $idc_list[] = $i;
         }
         $data = array('command_no' => $this->zk_conf['delete_cmd'], 'pid' => $this->conf['pid'], 'group_key' => (string) $group_key, 'key' => (string) $key, 'idc_list' => $idc_list);
         if ($sub_key !== null) {
             $data['has_sub_key'] = 1;
             $data['sub_key'] = $sub_key;
         }
         $input = array('body' => mc_pack_array2pack($data, PHP_MC_PACK_V2));
         $output = $client->Call($input);
         if ($output == null) {
             Ak_Log::warning("aclient call acm [{$server_name}] failed");
         } else {
             $res = mc_pack_pack2array($output['body']);
             if ($res['error_no'] !== 0) {
                 Ak_Log::warning("call acm [{$server_name}] output err_no is {$res['errno']}");
             } else {
                 return true;
             }
         }
     }
     return false;
 }