示例#1
0
 static function listConfig($zkClient, $configs)
 {
     /*{{{*/
     if (empty($configs)) {
         throw new LogConfException("configs empty! \n");
     }
     if (array_key_exists('hostname', $configs) && !empty($configs['hostname'])) {
         // get logkafka/conf/$hostname znode value
         $hostname = $configs['hostname'];
         $tmp_ret = AdminUtils::getLogCollectionConf($zkClient, $hostname);
         if ($tmp_ret['errno'] == 0) {
             $lk_host_confs = $tmp_ret['data'];
         } else {
             echo $tmp_ret['errmsg'];
         }
         $tmp_ret = AdminUtils::getLogCollectionState($zkClient, $hostname);
         if ($tmp_ret['errno'] == 0) {
             $lk_host_stats = $tmp_ret['data'];
         } else {
             echo $tmp_ret['errmsg'];
         }
         if (empty($lk_host_confs)) {
             echo "No logkafka configurations for hostname({$hostname}).\n";
             return;
         }
         if (array_key_exists('log_path', $configs) && !empty($configs['log_path'])) {
             AdminUtils::listConfigByHostAndPath($zkClient, $lk_host_confs, $lk_host_stats, $hostname, $configs['log_path']);
         } else {
             $paths = array_keys($lk_host_confs);
             foreach ($paths as $path) {
                 AdminUtils::listConfigByHostAndPath($zkClient, $lk_host_confs, $lk_host_stats, $hostname, $path);
             }
         }
     } else {
         // get logkafka/conf/<all hostname> znode value
         $tmp_ret = AdminUtils::getLogkafkaHosts($zkClient);
         if ($tmp_ret['errno'] == 0) {
             $hosts = $tmp_ret['data'];
         } else {
             echo $tmp_ret['errmsg'];
         }
         if (empty($hosts)) {
             echo "No logkafka configurations.\n";
             return;
         }
         foreach ($hosts as $host) {
             $tmp_ret = AdminUtils::getLogCollectionConf($zkClient, $host);
             if ($tmp_ret['errno'] == 0) {
                 $lk_host_confs = $tmp_ret['data'];
             } else {
                 echo $tmp_ret['errmsg'];
             }
             $tmp_ret = AdminUtils::getLogCollectionState($zkClient, $host);
             if ($tmp_ret['errno'] == 0) {
                 $lk_host_stats = $tmp_ret['data'];
             } else {
                 echo $tmp_ret['errmsg'];
             }
             if (empty($lk_host_confs)) {
                 echo "No logkafka configurations for host({$host}).\n";
                 continue;
             }
             if (array_key_exists('log_path', $configs) && !empty($configs['log_path'])) {
                 AdminUtils::listConfigByHostAndPath($zkClient, $lk_host_confs, $lk_host_stats, $host, $configs['log_path']);
             } else {
                 $paths = array_keys($lk_host_confs);
                 foreach ($paths as $path) {
                     AdminUtils::listConfigByHostAndPath($zkClient, $lk_host_confs, $lk_host_stats, $host, $path);
                 }
             }
         }
     }
 }