From f2a42098bf04a015028ba85d5da408aec67d33bf Mon Sep 17 00:00:00 2001 From: Nozomi Anzai Date: Thu, 7 Jan 2016 16:41:55 +0900 Subject: [PATCH] Adopt pcp_watchdog_info in ver3.5 --- bootstrap.php | 24 ++++++++++++++++++------ command.php | 36 ++++++++++++++++++++++++++---------- innerWatchdog.php | 34 ++++++++++------------------------ 3 files changed, 54 insertions(+), 40 deletions(-) diff --git a/bootstrap.php b/bootstrap.php index 24385c4..7edd935 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -1,6 +1,6 @@ 'END', + WATCHDOG_INIT => 'INIT', + WATCHDOG_NORMAL => 'NORMAL', + WATCHDOG_MASTER => 'MASTER', + WATCHDOG_DOWN => 'DOWN', + ); +} // timeout seconds // (The parameter "pcp_timeout" existed till V3.0.) diff --git a/command.php b/command.php index fa88432..8f8c9be 100644 --- a/command.php +++ b/command.php @@ -19,7 +19,7 @@ * is" without express or implied warranty. * * @author Ryuma Ando - * @copyright 2003-2015 PgPool Global Development Group + * @copyright 2003-2016 PgPool Global Development Group * @version CVS: $Id$ */ @@ -152,6 +152,9 @@ function execPcp($command, $extra_args = array()) case 'PCP_WATCHDOG_INFO': $cmd = _PGPOOL2_PCP_DIR . '/pcp_watchdog_info' . $args; $ret = exec($cmd, $output, $return_var); + if (3.5 <= _PGPOOL2_VERSION) { + $ret = $output[2]; + } break; default: @@ -218,23 +221,37 @@ function getNodeInfo($i) */ function getWatchdogInfo($i = '') { - global $tpl; + global $tpl, $g_watchdog_status_str_arr; - $result = execPcp('PCP_WATCHDOG_INFO', $i); + $result = execPcp('PCP_WATCHDOG_INFO', + (3.5 <= _PGPOOL2_VERSION) ? array('n' => $i) : array($i) + ); - if (!array_key_exists('SUCCESS', $result)) { + if (! array_key_exists('SUCCESS', $result)) { $errorCode = 'e1013'; $tpl->assign('errorCode', $errorCode); $tpl->display('innerError.tpl'); exit(); } - $arr = explode(" ", $result['SUCCESS']); - $rtn['hostname'] = $arr[0]; - $rtn['pgpool_port'] = $arr[1]; - $rtn['wd_port'] = $arr[2]; - $rtn['status'] = $arr[3]; + $arr = explode(' ', $result['SUCCESS']); + if (3.5 <= _PGPOOL2_VERSION) { + // ex.) Linux_dhcp-177-180_9999 133.137.177.180 9999 9000 4 MASTER + $rtn['hostname'] = $arr[1]; + $rtn['pgpool_port'] = $arr[2]; + $rtn['wd_port'] = $arr[3]; + $rtn['status'] = $arr[4]; + $rtn['status_str'] = $arr[5]; + + } else { + // ex.) 133.137.177.180 9999 9000 3 + $rtn['hostname'] = $arr[0]; + $rtn['pgpool_port'] = $arr[1]; + $rtn['wd_port'] = $arr[2]; + $rtn['status'] = $arr[3]; + $rtn['status_str'] = $g_watchdog_status_str_arr[$rtn['status']]; + } return $rtn; } @@ -261,4 +278,3 @@ function checkPcppass() exit(); } } -?> diff --git a/innerWatchdog.php b/innerWatchdog.php index 31b9543..9b4c723 100644 --- a/innerWatchdog.php +++ b/innerWatchdog.php @@ -19,7 +19,7 @@ * is" without express or implied warranty. * * @author Ryuma Ando - * @copyright 2003-2013 PgPool Global Development Group + * @copyright 2003-2016 PgPool Global Development Group * @version CVS: $Id$ */ @@ -49,33 +49,19 @@ $params = readConfigParams(array('port', // get watchdog information $watchdogInfo = array(); -for ($i = 0; $i < count($params['other_pgpool_hostname']); $i++) { - $watchdogInfo[] = getWatchdogInfo($i); -} -$watchdogInfo['local'] = getWatchdogInfo(); +if (3.5 <= _PGPOOL2_VERSION) { + $watchdogInfo['local'] = getWatchdogInfo(0); + for ($i = 0; $i < count($params['other_pgpool_hostname']); $i++) { + $watchdogInfo[] = getWatchdogInfo($i + 1); + } -foreach ($watchdogInfo as $key => $info) { - switch ($info['status']) { - case WATCHDOG_INIT: - $watchdogInfo[$key]['status_str'] = $message['strWdInit']; - break; - case WATCHDOG_STANDBY: - $watchdogInfo[$key]['status_str'] = $message['strWdStandby']; - break; - case WATCHDOG_ACTIVE: - $watchdogInfo[$key]['status_str'] = $message['strWdActive']; - break; - case WATCHDOG_DOWN: - $watchdogInfo[$key]['status_str'] = $message['strWdDown']; - break; - default: - $watchdogInfo[$key]['status_str'] = $message['strUnknown']; - break; +} else { + $watchdogInfo['local'] = getWatchdogInfo(); + for ($i = 0; $i < count($params['other_pgpool_hostname']); $i++) { + $watchdogInfo[] = getWatchdogInfo($i); } } $tpl->assign('params', $params); $tpl->assign('watchdogInfo', $watchdogInfo); $tpl->display('innerWatchdog.tpl'); - -?> -- 2.39.5