14 require_once
'hce_cli_api.inc.php';
15 require_once
'hce_sphinx_api.inc.php';
20 defined(
'HCE_CLUSTER_CMD_TIMEOUT') or define('HCE_CLUSTER_CMD_TIMEOUT', 100);
24 defined('HCE_CLUSTER_CMD_STRUCTURE_CHECK') or define('HCE_CLUSTER_CMD_STRUCTURE_CHECK', 'STRUCTURE_CHECK');
25 defined('HCE_CLUSTER_CMD_NODE_SHUTDOWN') or define('HCE_CLUSTER_CMD_NODE_SHUTDOWN', 'NODE_SHUTDOWN');
26 defined('HCE_CLUSTER_CMD_NODE_PROPERTIES') or define('HCE_CLUSTER_CMD_NODE_PROPERTIES', 'NODE_PROPERTIES');
27 defined('HCE_CLUSTER_CMD_NODE_RESOURCE_USAGE') or define('HCE_CLUSTER_CMD_NODE_RESOURCE_USAGE', 'NODE_RESOURCE_USAGE');
29 defined('HCE_CLUSTER_CMD_NODE_ECHO') or define('HCE_CLUSTER_CMD_NODE_ECHO', 'NODE_ECHO');
30 defined('HCE_CLUSTER_CMD_NODE_TIME') or define('HCE_CLUSTER_CMD_NODE_TIME', 'NODE_TIME');
31 defined('HCE_CLUSTER_CMD_NODE_LLSET') or define('HCE_CLUSTER_CMD_NODE_LLSET', 'NODE_LLSET');
32 defined('HCE_CLUSTER_CMD_NODE_LLGET') or define('HCE_CLUSTER_CMD_NODE_LLGET', 'NODE_LLGET');
33 defined('HCE_CLUSTER_CMD_NODE_HB_DELAY_SET') or define('HCE_CLUSTER_CMD_NODE_HB_DELAY_SET', 'NODE_HB_DELAY_SET');
34 defined('HCE_CLUSTER_CMD_NODE_HB_DELAY_GET') or define('HCE_CLUSTER_CMD_NODE_HB_DELAY_GET', 'NODE_HB_DELAY_GET');
35 defined('HCE_CLUSTER_CMD_NODE_HB_TIMEOUT_SET') or define('HCE_CLUSTER_CMD_NODE_HB_TIMEOUT_SET', 'NODE_HB_TIMEOUT_SET');
36 defined('HCE_CLUSTER_CMD_NODE_HB_TIMEOUT_GET') or define('HCE_CLUSTER_CMD_NODE_HB_TIMEOUT_GET', 'NODE_HB_TIMEOUT_GET');
37 defined('HCE_CLUSTER_CMD_NODE_HB_MODE_SET') or define('HCE_CLUSTER_CMD_NODE_HB_MODE_SET', 'NODE_HB_MODE_SET');
38 defined('HCE_CLUSTER_CMD_NODE_HB_MODE_GET') or define('HCE_CLUSTER_CMD_NODE_HB_MODE_GET', 'NODE_HB_MODE_GET');
39 defined('HCE_CLUSTER_CMD_NODE_POLL_TIMEOUT_SET') or define('HCE_CLUSTER_CMD_NODE_POLL_TIMEOUT_SET', 'NODE_POLL_TIMEOUT_SET');
40 defined('HCE_CLUSTER_CMD_NODE_POLL_TIMEOUT_GET') or define('HCE_CLUSTER_CMD_NODE_POLL_TIMEOUT_GET', 'NODE_POLL_TIMEOUT_GET');
41 defined('HCE_CLUSTER_CMD_NODE_PROPERTY_INTERVAL_SET') or define('HCE_CLUSTER_CMD_NODE_PROPERTY_INTERVAL_SET', 'NODE_PROPERTY_INTERVAL_SET');
42 defined('HCE_CLUSTER_CMD_NODE_PROPERTY_INTERVAL_GET') or define('HCE_CLUSTER_CMD_NODE_PROPERTY_INTERVAL_GET', 'NODE_PROPERTY_INTERVAL_GET');
43 defined('HCE_CLUSTER_CMD_NODE_DUMP_INTERVAL_SET') or define('HCE_CLUSTER_CMD_NODE_DUMP_INTERVAL_SET', 'NODE_DUMP_INTERVAL_SET');
44 defined('HCE_CLUSTER_CMD_NODE_DUMP_INTERVAL_GET') or define('HCE_CLUSTER_CMD_NODE_DUMP_INTERVAL_GET', 'NODE_DUMP_INTERVAL_GET');
45 defined('HCE_CLUSTER_CMD_NODE_MMSET') or define('HCE_CLUSTER_CMD_NODE_MMSET', 'NODE_MMSET');
46 defined('HCE_CLUSTER_CMD_NODE_MMGET') or define('HCE_CLUSTER_CMD_NODE_MMGET', 'NODE_MMGET');
47 defined('HCE_CLUSTER_CMD_NODE_MPMSET') or define('HCE_CLUSTER_CMD_NODE_MPMSET', 'NODE_MPMSET');
48 defined('HCE_CLUSTER_CMD_NODE_MPMGET') or define('HCE_CLUSTER_CMD_NODE_MPMGET', 'NODE_MPMGET');
49 defined('HCE_CLUSTER_CMD_NODE_MRCSSET') or define('HCE_CLUSTER_CMD_NODE_MRCSSET', 'NODE_MRCSSET');
50 defined('HCE_CLUSTER_CMD_NODE_MRCSGET') or define('HCE_CLUSTER_CMD_NODE_MRCSGET', 'NODE_MRCSGET');
51 defined('HCE_CLUSTER_CMD_NODE_SPHINX') or define('HCE_CLUSTER_CMD_NODE_SPHINX', 'SPHINX');
52 defined('HCE_CLUSTER_CMD_NODE_DRCE') or define('HCE_CLUSTER_CMD_NODE_DRCE', 'DRCE');
57 defined('HCE_CLUSTER_CMD_PROPERTY_NAME_LOG') or define('HCE_CLUSTER_CMD_PROPERTY_NAME_LOG', 'log');
62 defined('HCE_CLUSTER_SCHEMA_ROLE_ROUTER') or define('HCE_CLUSTER_SCHEMA_ROLE_ROUTER', 'router');
63 defined('HCE_CLUSTER_SCHEMA_ROLE_SMANAGER') or define('HCE_CLUSTER_SCHEMA_ROLE_SMANAGER', 'smanager');
64 defined('HCE_CLUSTER_SCHEMA_ROLE_RMANAGER') or define('HCE_CLUSTER_SCHEMA_ROLE_RMANAGER', 'rmanager');
65 defined('HCE_CLUSTER_SCHEMA_ROLE_RMANAGER_RR') or define('HCE_CLUSTER_SCHEMA_ROLE_RMANAGER_RR', 'rmanager-round-robin');
66 defined('HCE_CLUSTER_SCHEMA_ROLE_RMANAGER_RND') or define('HCE_CLUSTER_SCHEMA_ROLE_RMANAGER_RND', 'rmanager-rnd');
67 defined('HCE_CLUSTER_SCHEMA_ROLE_RMANAGER_RU') or define('HCE_CLUSTER_SCHEMA_ROLE_RMANAGER_RU', 'rmanager-resources-usage');
68 defined('HCE_CLUSTER_SCHEMA_ROLE_REPLICA') or define('HCE_CLUSTER_SCHEMA_ROLE_REPLICA', 'replica');
73 defined('HCE_CLUSTER_SCHEMA_ROLE_CODE_ROUTER') or define('HCE_CLUSTER_SCHEMA_ROLE_CODE_ROUTER', 3);
74 defined('HCE_CLUSTER_SCHEMA_ROLE_CODE_SMANAGER') or define('HCE_CLUSTER_SCHEMA_ROLE_CODE_SMANAGER', 0);
75 defined('HCE_CLUSTER_SCHEMA_ROLE_CODE_RMANAGER') or define('HCE_CLUSTER_SCHEMA_ROLE_CODE_RMANAGER', 1);
76 defined('HCE_CLUSTER_SCHEMA_ROLE_CODE_REPLICA') or define('HCE_CLUSTER_SCHEMA_ROLE_CODE_REPLICA', 2);
77 defined('HCE_CLUSTER_SCHEMA_ROLE_CODE_RMANAGER_RND') or define('HCE_CLUSTER_SCHEMA_ROLE_CODE_RMANAGER_RND', 4);
78 defined('HCE_CLUSTER_SCHEMA_ROLE_CODE_RMANAGER_RU') or define('HCE_CLUSTER_SCHEMA_ROLE_CODE_RMANAGER_RU', 5);
83 defined('HCE_CLUSTER_SCHEMA_ERROR_WRONG_DATA') or define('HCE_CLUSTER_SCHEMA_ERROR_WRONG_DATA', 'wrong data or network error');
88 defined('HCE_CLUSTER_SCHEMA_PORTS_DEFAULT') or define('HCE_CLUSTER_SCHEMA_PORTS_DEFAULT', '5540,5541,5542,5543,5544,5545,5546,5547,5548,5549,5550,5551,5552,5553,5554,5555,5556,5557,5558,5559');
93 defined('HCE_CLUSTER_CMD_DATE_FORMAT') or define('HCE_CLUSTER_CMD_DATE_FORMAT', 'Y-m-d H:i:s');
94 defined('HCE_CLUSTER_CMD_TIME_FORMAT') or define('HCE_CLUSTER_CMD_TIME_FORMAT', 'H:i:s');
99 defined('HCE_CLUSTER_CMD_PROPERTIES_FIELD_TIME') or define('HCE_CLUSTER_CMD_PROPERTIES_FIELD_TIME', 'startedAt');
100 defined('HCE_CLUSTER_CMD_PROPERTIES_FIELD_NAME') or define('HCE_CLUSTER_CMD_PROPERTIES_FIELD_NAME', 'name');
101 defined('HCE_CLUSTER_CMD_PROPERTIES_FIELD_CIDENTITY') or define('HCE_CLUSTER_CMD_PROPERTIES_FIELD_CIDENTITY', 'clientIdentity');
102 defined('HCE_CLUSTER_CMD_PROPERTIES_FIELD_CSTRING') or define('HCE_CLUSTER_CMD_PROPERTIES_FIELD_CSTRING', 'connectionString');
103 defined('HCE_CLUSTER_CMD_PROPERTIES_FIELD_NODEMODE') or define('HCE_CLUSTER_CMD_PROPERTIES_FIELD_NODEMODE', 'nodeMode');
112 $ret=
'Usage: manager.php --command=<command> [--host=<host>] [--port=<port>] [--<option_name>=<option_value>,...] [--timeout=<timeout_ms>]'.
113 ' [--log=<log_level_mask{0 - warnings, 1 - errors, 2 - debug}>] [--scan=<host_port_recombination{0 - for each host scan all listed ports, 1 - treate host and ports as pairs}>]'.
114 ' [--ignore=<ignore_errors_mode{0 - not ignore, 1 - ignore not critical, 2 - ignore all}>] [-sphinx_properties_formatted] [--view={"json", "chart"}]'.PHP_EOL.PHP_EOL.
115 'Cluster and node level commands:'.PHP_EOL.
116 ' STRUCTURE_CHECK [--view={"json", "chart"}] [--fields={rhasc}] - detect and check cluster structure, return schema in json (default) or ASCII chart view'.PHP_EOL.
117 ' fields: r - role, h - host, a - admin, s - server, c - client connections'.PHP_EOL.
118 ' NODE_SHUTDOWN - shutdown node'.PHP_EOL.
119 ' NODE_ECHO - simple ping node with echo'.PHP_EOL.
120 ' NODE_TIME - returns json with time of live of node, msec'.PHP_EOL.
121 ' NODE_PROPERTIES --handler=<handler_names_csv>, --realtime=<parameters_json> - returns json with node properties of all handlers, for sample: {"parameters":"", "realtime":0}'.PHP_EOL.
122 ' NODE_LLSET --handler=<handler_names_csv>, --level=<log_levels_value_csv> - set log level(s) for handler(s)'.PHP_EOL.
123 ' NODE_LLGET --handler=<handler_names_csv> - returns json with log level(s) for handler(s)'.PHP_EOL.
124 ' NODE_HB_DELAY_SET --handler=<handler_names_csv>, --hddelay=<heartbeat_delay> - set heartbeat delay value for handler(s)'.PHP_EOL.
125 ' NODE_HB_DELAY_GET --handler=<handler_names_csv> - returns json with heartbeat delay values of handler(s)'.PHP_EOL.
126 ' NODE_HB_TIMEOUT_SET --handler=<handler_names_csv>, --hbtimeout=<heartbeat_timeout> - set heartbeat timeout value for handler(s)'.PHP_EOL.
127 ' NODE_HB_TIMEOUT_GET --handler=<handler_names_csv> - returns json with heartbeat timeout values of handler(s)'.PHP_EOL.
128 ' NODE_HB_MODE_SET --handler=<handler_names_csv>, --hbmode=<heartbeat_mode> - set heartbeat mode value for handler(s)'.PHP_EOL.
129 ' NODE_HB_MODE_GET --handler=<handler_names_csv> - returns json with heartbeat mode values of handler(s)'.PHP_EOL.
130 ' NODE_POLL_TIMEOUT_SET --handler=<handler_names_csv>, --ptimeout=<poll_timeout> - set poll timeout value for handler(s)'.PHP_EOL.
131 ' NODE_POLL_TIMEOUT_GET --handler=<handler_names_csv> - returns json with poll timeout values of handler(s)'.PHP_EOL.
132 ' NODE_PROPERTY_INTERVAL_SET --handler=<handler_names_csv>, --interval=<property_interval> - set property interval value for handler(s)'.PHP_EOL.
133 ' NODE_PROPERTY_INTERVAL_GET --handler=<handler_names_csv> - returns json with property interval values of handler(s)'.PHP_EOL.
134 ' NODE_DUMP_INTERVAL_SET --handler=<handler_names_csv>, --interval=<dump_interval> - set dump interval value for handler(s)'.PHP_EOL.
135 ' NODE_DUMP_INTERVAL_GET --handler=<handler_names_csv> - returns json with dump interval values of handler(s)'.PHP_EOL.
136 ' NODE_MMSET --mode=<manager_mode_name{"smanager", "rmanager"}> - set manager mode'.PHP_EOL.
137 ' NODE_MMGET - get manager mode'.PHP_EOL.
138 ' NODE_MPMSET --purge=<purge_mode> - set purge mode'.PHP_EOL.
139 ' NODE_MPMGET - get purge mode'.PHP_EOL.
140 ' NODE_MRCSSET --csize=<collected_size> - set resources usage collected size'.PHP_EOL.
141 ' NODE_MRCSGET - get resources usage collected size'.PHP_EOL.
142 ' NODE_RECOVER_NOTIFICATION_CONNECTION - recover notification connection'.PHP_EOL.
143 ' NODE_ROUTES - get HCE-node routes list'.PHP_EOL.
144 ' NODE_RESOURCE_USAGE - get HCE-node resources usage list'.PHP_EOL.
145 'Sphinx search level commands:'.PHP_EOL.
146 ' INDEX_REMOVE'.PHP_EOL.
147 ' INDEX_DELETE_DOC_NUMBER'.PHP_EOL.
148 ' INDEX_CHECK'.PHP_EOL.
149 ' INDEX_START'.PHP_EOL.
150 ' INDEX_STOP'.PHP_EOL.
151 ' INDEX_CREATE'.PHP_EOL.
152 ' INDEX_APPEND_DATA_FILE'.PHP_EOL.
153 ' INDEX_STORE_DATA_FILE'.PHP_EOL.
154 ' INDEX_STORE_SCHEMA_FILE'.PHP_EOL.
155 ' INDEX_PACK_DOC_DATA'.PHP_EOL.
156 ' INDEX_MERGE'.PHP_EOL.
157 ' INDEX_DELETE_DATA_FILE'.PHP_EOL.
158 ' INDEX_REBUILD'.PHP_EOL.
159 ' INDEX_DELETE_SCHEMA_FILE'.PHP_EOL.
160 ' INDEX_DELETE_DOC'.PHP_EOL.
161 ' INDEX_RENAME'.PHP_EOL.
162 ' INDEX_COPY'.PHP_EOL.
163 ' INDEX_SET_CONFIG_VAR'.PHP_EOL.
164 ' INDEX_CONNECT'.PHP_EOL.
165 ' INDEX_DISCONNECT'.PHP_EOL.
166 'DRCE level commands:'.PHP_EOL.
167 ' DRCE --request=request_type{SET, CHECK, TERMINATE, GET, DELETE} --id=<task_id> --json=<json_protocol_file>'.PHP_EOL.
168 ' DRCE_SET_HOST - set DRCE host value'.PHP_EOL.
169 ' DRCE_GET_HOST - get DRCE host value'.PHP_EOL.
170 ' DRCE_SET_PORT - set DRCE connection port value'.PHP_EOL.
171 ' DRCE_GET_PORT - get DRCE connection port value'.PHP_EOL.
172 ' DRCE_GET_TASKS - get DRCE tasks list'.PHP_EOL.
173 ' DRCE_GET_TASKS_INFO - get DRCE tasks list info'.PHP_EOL.
187 $timestampedProperties=array(
'startedAt',
'pstatsAt',
'heartbeatAt',
'heartbeatedAt');
191 $properties=explode($delimiter, $response_str);
192 if(isset($properties[0]) && $properties[0]==HCE_ADMIN_NODE_ADMIN_ERROR_OK){
193 foreach($properties as $property){
194 $property=explode(
'=', $property);
195 if(count($property)>1){
196 if($time_format!==null && in_array($property[0], $timestampedProperties)){
197 $ret[$property[0]]=date($time_format, ceil($property[1]/1000));
199 $ret[$property[0]]=$property[1];
220 $handlers=array(HCE_HANDLER_ADMIN, HCE_HANDLER_ROUTER_SERVER_PROXY, HCE_HANDLER_DATA_SERVER_PROXY, HCE_HANDLER_DATA_CLIENT_PROXY, HCE_HANDLER_DATA_PROCESSOR_DATA,
221 HCE_HANDLER_DATA_CLIENT_DATA, HCE_HANDLER_DATA_REDUCER_PROXY);
223 $ret=array(
'error'=>0,
'data'=>null,
'host'=>$host,
'port'=>$port);
228 foreach($handlers as $handler){
231 if($hce_responses[
'error']==HCE_PROTOCOL_ERROR_OK){
232 foreach($hce_responses[
'messages'] as $hce_message){
233 $ret[
'data'][$handler]=$hce_message[
'body'];
236 $ret[
'error']=$hce_responses[
'error'];
238 if($handler==HCE_HANDLER_ADMIN){
262 $ret=array(
'error'=>0,
'data'=>null,
'host'=>$host,
'port'=>$port);
270 if($hce_responses[
'error']==HCE_PROTOCOL_ERROR_OK){
271 foreach($hce_responses[
'messages'] as $hce_message){
272 $ret[
'data'][$handler]=$hce_message[
'body'];
275 $ret[
'error']=$hce_responses[
'error'];
294 $hosts=explode(
',',
$args[
'host']);
295 $ports=explode(
',',
$args[
'port']);
297 if(isset(
$args[
'realtime'])) {
298 $param_value=
$args[
'realtime'];
304 if(
$args[
'scan']==0){
305 if(count($hosts)!=count($ports)){
307 for($i=0; $i<count($hosts); $i++){
310 for($j=0; $j<count($ports); $j++){
312 if(
$args[
'log'] > 0){
313 echo
'trying exact '.$host.
':'.$port.
'...'.PHP_EOL;
320 for($i=0; $i<count($hosts); $i++){
324 if(
$args[
'log'] > 0){
325 echo
'trying exact '.$host.
':'.$port.
'...'.PHP_EOL;
332 for($i=0; $i<count($hosts); $i++){
333 if(
$args[
'log'] & 1 > 0){
334 echo
'trying scan '.$hosts[$i].
':'.$ports[$i].
'...'.PHP_EOL;
351 $ret=array(
'error_code'=>0,
'error_message'=>
'',
'data'=>null);
357 foreach($node_info as $node=>$node_data){
363 if($r[
'error_code']>0){
364 if(
$args[
'log'] & 1 > 0){
365 $ret[
'error_code']=1;
366 $ret[
'error_message']=
'structure error : '.$r[
'error_message'].PHP_EOL;
370 if($ret[
'error_code']==0 || ($ret[
'error_code']>0 &&
$args[
'ignore']==0)){
372 $schema_cover=array(
'cluster'=>array(
'name'=>
$args[
'name'],
'nodes'=>array()));
373 foreach($node_info as $node_data){
374 if($node_data[
'structure'][
'role']){
375 $schema_cover[
'cluster'][
'nodes'][]=$node_data[
'structure'][
'schema'];
379 if(count($schema_cover[
'cluster'][
'nodes'])>0){
380 if(!isset(
$args[
'view']) ||
$args[
'view']!=
'chart'){
384 $insertNodeInASCIIChartArray =
function($chartArray, $targetNodeName, $nodeName) use(&$insertNodeInASCIIChartArray){
385 foreach($chartArray as $key=>$val){
386 $lines=explode(PHP_EOL, $key);
387 if($lines[0]==$targetNodeName){
389 $chartArray[$key]=array_merge($val, array($nodeName=>null));
391 $chartArray[$key]=array($nodeName=>null);
396 $chartArray[$key]=$insertNodeInASCIIChartArray($val, $targetNodeName, $nodeName);
405 $getNodeFieldsValues =
function($node, $fields=null){
408 $fields_names=array(
'n'=>
'name',
'r'=>
'role',
'h'=>
'host',
'a'=>
'admin',
's'=>
'server',
'c'=>
'client');
413 if(!in_array(
'n', $fields)){
414 $fields=array_merge(array(
'n'), $fields);
417 foreach($fields_names as $key=>$val){
418 if(in_array($key, $fields)){
419 if(in_array($key, array(
'a',
's',
'c'))){
420 if($node[$val]!=
'' && $node[$val]!=
'0'){
421 $values.=strtoupper($key).
'['.str_replace(
'tcp://',
'', $node[$val]).
']'.PHP_EOL;
424 $values.=$node[$val].PHP_EOL;
433 $fields=str_split((isset(
$args[
'fields']) ?
$args[
'fields'] :
'n'));
438 foreach($schema_cover[
'cluster'][
'nodes'] as $node){
439 if($node[
'role']==HCE_CLUSTER_SCHEMA_ROLE_ROUTER){
440 $chartArray[$getNodeFieldsValues($node, $fields)]=null;
445 foreach($schema_cover[
'cluster'][
'nodes'] as $node){
446 if(isset($node[
'connection']) && $node[
'connection']!=
''
447 && ($node[
'role']==HCE_CLUSTER_SCHEMA_ROLE_SMANAGER || $node[
'role']==HCE_CLUSTER_SCHEMA_ROLE_RMANAGER || $node[
'role']==HCE_CLUSTER_SCHEMA_ROLE_RMANAGER_RR
448 || $node[
'role']==HCE_CLUSTER_SCHEMA_ROLE_RMANAGER_RND || $node[
'role']==HCE_CLUSTER_SCHEMA_ROLE_RMANAGER_RU)){
450 $chartArray=$insertNodeInASCIIChartArray($chartArray, $node[
'connection'], $getNodeFieldsValues($node, $fields));
454 foreach($schema_cover[
'cluster'][
'nodes'] as $node){
455 if(isset($node[
'connection']) && $node[
'connection']!=
'' && $node[
'role']==HCE_CLUSTER_SCHEMA_ROLE_REPLICA){
457 $chartArray=$insertNodeInASCIIChartArray($chartArray, $node[
'connection'], $getNodeFieldsValues($node, $fields));
467 $chartArray[
'']=null;
469 foreach($schema_cover[
'cluster'][
'nodes'] as $node){
470 if((!isset($node[
'connection']) || trim($node[
'connection'])==
'') && $node[
'role']!==
'router'){
471 $chartArray=$insertNodeInASCIIChartArray($chartArray,
'', $getNodeFieldsValues($node, $fields));
475 $ret[
'data'].=
cli_getASCIITreeFromArray($chartArray, array(
'max_width'=>1,
'hline_char'=>
' ',
'vline_char'=>
' ')).PHP_EOL;
492 $connection_names=array(
'client'=>
'client',
'server'=>
'server',
'admin'=>
'admin');
494 $ret=array(
'error'=>0,
'role'=>null,
'schema'=>array(
'name'=>null,
'role'=>null,
'host'=>null, $connection_names[
'client']=>null, $connection_names[
'server']=>null, $connection_names[
'admin']=>null));
496 if($node[
'error']==0){
497 $handlers=$node[
'data'];
498 $ret[
'schema'][
'host']=$node[
'host'];
500 if(array_key_exists(HCE_HANDLER_ROUTER_SERVER_PROXY, $handlers) && array_key_exists(HCE_HANDLER_DATA_SERVER_PROXY, $handlers)){
503 if($properties!==
false){
504 $ret[
'role']=HCE_CLUSTER_SCHEMA_ROLE_ROUTER;
505 $ret[
'schema'][
'role']=$ret[
'role'];
506 $ret[
'schema'][$connection_names[
'client']]=$properties[HCE_CLUSTER_CMD_PROPERTIES_FIELD_CSTRING];
510 if($properties!==
false){
511 $ret[
'schema'][$connection_names[
'server']]=$properties[HCE_CLUSTER_CMD_PROPERTIES_FIELD_CSTRING];
516 if(array_key_exists(HCE_HANDLER_DATA_SERVER_PROXY, $handlers) && array_key_exists(HCE_HANDLER_DATA_CLIENT_PROXY, $handlers)){
519 if($properties!==
false){
520 if($properties[HCE_CLUSTER_CMD_PROPERTIES_FIELD_NODEMODE]==HCE_CLUSTER_SCHEMA_ROLE_CODE_SMANAGER){
521 $ret[
'role']=HCE_CLUSTER_SCHEMA_ROLE_SMANAGER;
522 }elseif($properties[HCE_CLUSTER_CMD_PROPERTIES_FIELD_NODEMODE]==HCE_CLUSTER_SCHEMA_ROLE_CODE_RMANAGER){
523 $ret[
'role']=HCE_CLUSTER_SCHEMA_ROLE_RMANAGER;
524 }elseif($properties[HCE_CLUSTER_CMD_PROPERTIES_FIELD_NODEMODE]==HCE_CLUSTER_SCHEMA_ROLE_CODE_RMANAGER_RND){
525 $ret[
'role']=HCE_CLUSTER_SCHEMA_ROLE_RMANAGER_RND;
526 }elseif($properties[HCE_CLUSTER_CMD_PROPERTIES_FIELD_NODEMODE]==HCE_CLUSTER_SCHEMA_ROLE_CODE_RMANAGER_RU){
527 $ret[
'role']=HCE_CLUSTER_SCHEMA_ROLE_RMANAGER_RU;
529 $ret[
'schema'][$connection_names[
'server']]=$properties[HCE_CLUSTER_CMD_PROPERTIES_FIELD_CSTRING];
533 if($properties!==
false){
534 $ret[
'schema'][$connection_names[
'client']]=$properties[HCE_CLUSTER_CMD_PROPERTIES_FIELD_CSTRING];
539 if(array_key_exists(HCE_HANDLER_DATA_CLIENT_DATA, $handlers) && array_key_exists(HCE_HANDLER_DATA_PROCESSOR_DATA, $handlers)){
542 if($properties!==
false){
543 $ret[
'role']=HCE_CLUSTER_SCHEMA_ROLE_REPLICA;
544 $ret[
'schema'][$connection_names[
'client']]=$properties[HCE_CLUSTER_CMD_PROPERTIES_FIELD_CSTRING];
545 $ret[
'schema'][$connection_names[
'server']]=
'';
557 if(array_key_exists(HCE_HANDLER_ADMIN, $handlers)){
560 if($properties!==
false){
561 $ret[
'schema'][
'name']=$properties[HCE_CLUSTER_CMD_PROPERTIES_FIELD_CIDENTITY];
562 $ret[
'schema'][$connection_names[
'admin']]=$properties[HCE_CLUSTER_CMD_PROPERTIES_FIELD_CSTRING];
568 $ret[
'schema'][
'role']=$ret[
'role'];
571 $ret[
'error']=HCE_CLUSTER_SCHEMA_ERROR_WRONG_DATA.
' ['.$node[
'error'].
']';
585 $ret=array(
'error_code'=>0,
'error_message'=>
'');
586 foreach($node_info as $node=>$node_data){
587 foreach($node_info as $node1=>$node_data1){
588 if($node_data1[
'error']==0 && $node_data[
'error']==0 && isset($node_data[
'structure'][
'schema'][
'server']) && isset($node_data1[
'structure'][
'schema'][
'client'])){
590 $schema=parse_url($node_data[
'structure'][
'schema'][
'server']);
592 if($node_data[
'structure'][
'schema'][
'host']!=
'localhost' && isset($schema[
'host']) && ($schema[
'host']==
'*' || $schema[
'host']==
'localhost')){
594 $schema[
'host']=$node_data[
'structure'][
'schema'][
'host'];
598 $schema1=parse_url($node_data1[
'structure'][
'schema'][
'client']);
600 if($node_data1[
'structure'][
'schema'][
'host']!=
'localhost' && isset($schema1[
'host']) && ($schema1[
'host']==
'*' || $schema1[
'host']==
'localhost')){
602 $schema1[
'host']=$node_data1[
'structure'][
'schema'][
'host'];
606 if(isset($schema[
'host']) && isset($schema1[
'host']) && isset($schema[
'port']) && isset($schema1[
'port']) &&
607 ($schema[
'host']==$schema1[
'host'] || $schema[
'host']==
'*') && ($schema[
'port']==$schema1[
'port'])){
608 $node_info[$node1][
'structure'][
'schema'][
'connection']=$node_data[
'structure'][
'schema'][
'name'];
631 foreach($node_info as $node=>$node_data){
632 if($node_data[
'error']==0){
634 if($ret[$node][
'error']==0){
635 $ret[$node]=$ret[$node][
'data'];
637 $ret[$node]=
'Error '.$ret[$node][
'error'];
640 if($node_data[
'error']==-5){
641 $node_data[
'error']=
'Node not found at '.$node.
' or connection timeout.';
643 $ret[$node]=
'Error '.$node_data[
'error'];