Adopt pcp_watchdog_info in ver3.5
authorNozomi Anzai <anzai@sraoss.co.jp>
Thu, 7 Jan 2016 07:41:55 +0000 (16:41 +0900)
committerNozomi Anzai <anzai@sraoss.co.jp>
Thu, 7 Jan 2016 07:41:55 +0000 (16:41 +0900)
bootstrap.php
command.php
innerWatchdog.php

index 24385c4da4f3f980b47239f51eeb2676694c861a..7edd9358f4ca83e301efe1b1fcb619f6c358ea75 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright  2003-2013 PgPool Global Development Group
+ * @copyright  2003-2016 PgPool Global Development Group
  */
 
 // Session
@@ -27,11 +27,23 @@ define('NODE_ACTIVE_CONNECTED',  2);
 define('NODE_DOWN',              3);
 define('NODE_NOT_LOADED',       -1); // only for pgpoolAdmin
 
-// watchdog status in "pcp_watchdog_info" result
-define('WATCHDOG_INIT',    1);
-define('WATCHDOG_STANDBY', 2);
-define('WATCHDOG_ACTIVE',  3);
-define('WATCHDOG_DOWN',    4);
+// watchdog status in "pcp_watchdog_info" result (- 3.4)
+// (defined in $src/inclucde/watchdog/watchdog.h
+$g_watchdog_status_str_arr = array();
+if (_PGPOOL2_VERSION < 3.5) {
+    define('WATCHDOG_END',     0);
+    define('WATCHDOG_INIT',    1);
+    define('WATCHDOG_NORMAL',  2);
+    define('WATCHDOG_MASTER',  3);
+    define('WATCHDOG_DOWN',    4);
+    $g_watchdog_status_str_arr = array(
+        WATCHDOG_END    => 'END',
+        WATCHDOG_INIT   => 'INIT',
+        WATCHDOG_NORMAL => 'NORMAL',
+        WATCHDOG_MASTER => 'MASTER',
+        WATCHDOG_DOWN   => 'DOWN',
+    );
+}
 
 // timeout seconds
 // (The parameter "pcp_timeout" existed till V3.0.)
index fa884326b72b8cbc7bde19156705ffbdce585a30..8f8c9be5245a41ea77246b46a7c2c00e0b1f9010 100644 (file)
@@ -19,7 +19,7 @@
  * is" without express or implied warranty.
  *
  * @author     Ryuma Ando <ando@ecomas.co.jp>
- * @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();
     }
 }
-?>
index 31b9543b6272548b7da32632c56004c8b2e6a1a0..9b4c723f4453603d7e1dc7fc4b8f88a9040bb4c2 100644 (file)
@@ -19,7 +19,7 @@
  * is" without express or implied warranty.
  *
  * @author     Ryuma Ando <ando@ecomas.co.jp>
- * @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');
-
-?>