couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject couchdb-nmo git commit: Couch-config improvements
Date Tue, 06 Oct 2015 07:39:34 GMT
Repository: couchdb-nmo
Updated Branches:
  refs/heads/master a8d0b23d7 -> 17d6fefdb


Couch-config improvements

* Add json support for couch-config get
* Add better error handling if nodes offline


Project: http://git-wip-us.apache.org/repos/asf/couchdb-nmo/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-nmo/commit/17d6fefd
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-nmo/tree/17d6fefd
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-nmo/diff/17d6fefd

Branch: refs/heads/master
Commit: 17d6fefdbb09afbbdc8c0860279cc3c6e2878b5e
Parents: a8d0b23
Author: Garren Smith <garren.smith@gmail.com>
Authored: Wed Sep 30 16:11:07 2015 +0200
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Tue Oct 6 09:39:12 2015 +0200

----------------------------------------------------------------------
 src/couch-config.js  | 15 +++++++++++++++
 test/couch-config.js | 30 ++++++++++++++++++++++++++++--
 2 files changed, 43 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-nmo/blob/17d6fefd/src/couch-config.js
----------------------------------------------------------------------
diff --git a/src/couch-config.js b/src/couch-config.js
index 4012f12..676e386 100644
--- a/src/couch-config.js
+++ b/src/couch-config.js
@@ -49,6 +49,13 @@ export function get (cluster, nodes, section) {
   }, {});
 
   promise.then((nodeConfigs) => {
+    const jsonOut = nmo.config.get('json');
+
+    if (jsonOut) {
+      console.log(nodeConfigs);
+      return nodeConfigs;
+    }
+
     Object.keys(nodeConfigs).forEach(node => {
       console.log('NODE:', node);
       console.log(prettyjson.render(nodeConfigs[node], {}));
@@ -148,6 +155,14 @@ export function getConfig (node, url) {
 
     Wreck.get(url, (err, res, payload) => {
       if (err) {
+        if (err.code === 'ECONNREFUSED' || err.code === 'ENOTFOUND') {
+          const noNodeErr = new Error('Could not find node ' + node +
+            ' this could mean the node is down.');
+          noNodeErr.type = 'EUSAGE';
+          return reject(noNodeErr);
+        }
+
+        err.type = 'EUSAGE';
         return reject(err);
       }
 

http://git-wip-us.apache.org/repos/asf/couchdb-nmo/blob/17d6fefd/test/couch-config.js
----------------------------------------------------------------------
diff --git a/test/couch-config.js b/test/couch-config.js
index a533eb7..68eabf7 100644
--- a/test/couch-config.js
+++ b/test/couch-config.js
@@ -98,7 +98,7 @@ lab.experiment('couch-config', () => {
     lab.test('gets config bad url returns false', (done) => {
       getConfig('node1', 'http://127.0.0.2/')
       .catch(err => {
-        assert.deepEqual(err.code, 'ECONNREFUSED');
+        assert.ok(/Could not find node/.test(err.message));
         done();
       });
     });
@@ -159,7 +159,33 @@ lab.experiment('couch-config', () => {
       });
     });
 
-    lab.test('get prints config', (done) => {
+    lab.test('get returns json if set', done => {
+      const nodes = {
+        node1: 'http://127.0.0.100'
+      };
+
+      const resp = {
+        config1: 'hello',
+        config2: 'boom'
+      };
+
+      nock('http://127.0.0.100')
+        .get('/_node/node1/_config/uuid')
+        .reply(200, resp);
+
+      nmo
+        .load({nmoconf: __dirname + '/fixtures/randomini', json: true})
+        .then(() => {
+
+          get('cluster', nodes, 'uuid')
+          .then(jsonresp => {
+            assert.deepEqual({node1: resp}, jsonresp);
+            done();
+          });
+        });
+    });
+
+    lab.test('get prints config', done => {
       const nodes = {
         node1: 'http://127.0.0.1'
       };


Mime
View raw message