[Groonga-commit] droonga/express-droonga at 77a7dc8 [master] Store cluster id from the engine node

Back to archive index

YUKI Hiroshi null+****@clear*****
Sun Nov 30 18:33:53 JST 2014


YUKI Hiroshi	2014-11-30 18:33:53 +0900 (Sun, 30 Nov 2014)

  New Revision: 77a7dc80ab5248efa3571e297c1794526895d5ff
  https://github.com/droonga/express-droonga/commit/77a7dc80ab5248efa3571e297c1794526895d5ff

  Message:
    Store cluster id from the engine node

  Modified files:
    bin/express-droonga-report-live-engine-hosts
    lib/droonga-protocol/connection-pool.js

  Modified: bin/express-droonga-report-live-engine-hosts (+1 -3)
===================================================================
--- bin/express-droonga-report-live-engine-hosts    2014-11-30 18:04:47 +0900 (029490b)
+++ bin/express-droonga-report-live-engine-hosts    2014-11-30 18:33:53 +0900 (73fee61)
@@ -13,9 +13,7 @@ var client = new SerfClient({
 
 client.getLiveEngineNodes()
   .then(function(members) {
-    members.forEach(function(member) {
-      console.log(member.HostName);
-    });
+    console.log(JSON.stringify(members);
     process.exit(0);
   })
   .catch(function(error) {

  Modified: lib/droonga-protocol/connection-pool.js (+16 -10)
===================================================================
--- lib/droonga-protocol/connection-pool.js    2014-11-30 18:04:47 +0900 (245ee14)
+++ lib/droonga-protocol/connection-pool.js    2014-11-30 18:33:53 +0900 (ac9bc49)
@@ -110,9 +110,9 @@ ConnectionPool.prototype = {
     return this._hostNames.length;
   },
 
-  getHostNamesFromCluster: function(retryCount) {
+  getEnginesFromCluster: function(retryCount) {
     if (this._watching)
-      return this.getHostNamesFromClusterMember(this._serf.rpcAddress);
+      return this.getEnginesFromClusterMember(this._serf.rpcAddress);
 
     retryCount = retryCount || 0;
     var hostName = this._hostNames[retryCount];
@@ -123,17 +123,17 @@ ConnectionPool.prototype = {
         reject(error);
       }).bind(this));
 
-    return this.getHostNamesFromClusterMember(hostName)
-                 .then(function(hostNames) {
-                   return hostNames;
+    return this.getEnginesFromClusterMember(hostName)
+                 .then(function(engines) {
+                   return engines;
                  })
                  .catch((function(error) {
                    this._logger.error('Failed to get the list of droonga-engine hosts from the cluster member ' + hostName + '.');
                    this._logger.error(error);
-                   return this.getHostNamesFromCluster(retryCount + 1);
+                   return this.getEnginesFromCluster(retryCount + 1);
                  }).bind(this));
   },
-  getHostNamesFromClusterMember: function(rpcAddress) {
+  getEnginesFromClusterMember: function(rpcAddress) {
     return Q.Promise((function(resolve, reject, notify) {
       if (!rpcAddress)
         reject(new Error('no RPC address is given'));
@@ -151,7 +151,8 @@ ConnectionPool.prototype = {
       exec(commandLine, function(error, stdin, stdout) {
         if (error)
           return reject(error);
-        resolve(stdin.trim().split('\n'));
+        var engines = JSON.parse(stdin.trim());
+        resolve(engines);
       });
     }).bind(this));
   },
@@ -177,10 +178,15 @@ ConnectionPool.prototype = {
   },
 
   updateHostNamesFromCluster: function() {
-    return this.getHostNamesFromCluster()
-                 .then((function(hostNames) {
+    return this.getEnginesFromCluster()
+                 .then((function(engines) {
+                   this.clusterId = engines[0].Tags.cluster_id;
+                   var hostNames = engines.map(function(engine) {
+                     return engine.HostName;
+                   });
                    this.hostNames = hostNames;
                    this._logger.info('List of droonga-engine hosts is successfully initialized from the cluster.');
+                   this._logger.info('cluster id: '+this.clusterId);
                    this._logger.info(hostNames);
                    return hostNames;
                  }).bind(this))
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index