Github user robertkowalski commented on a diff in the pull request:
https://github.com/apache/couchdb-nmo/pull/3#discussion_r39057636
--- Diff: src/couch-config.js ---
@@ -0,0 +1,160 @@
+import * as utils from './utils.js';
+import log from 'npmlog';
+import Wreck from 'wreck';
+import Promise from 'bluebird';
+import prettyjson from 'prettyjson';
+import nmo from './nmo.js';
+import isonline, { getClusterUrls } from './isonline.js';
+
+export function cli (cmd, cluster, section, key, value) {
+ return new Promise((resolve, reject) => {
+
+ if (!cmd || !cluster || !exports[cmd]) {
+ const err = new Error('Usage: nmo couch-config add/set <cluster>
...');
+ err.type = 'EUSAGE';
+ return reject(err);
+ }
+
+ exports[cmd].apply(exports[cmd], [cluster, getClusterNodes(cluster),
section, key, value])
+ .then(resolve)
+ .catch(reject);
+ });
+}
+
+export function getClusterNodes (clusterName) {
+ const nodes = nmo.config.get(clusterName);
+ if (!nodes) {
+ const err = new Error('Cluster does not exist');
+ err.type = 'EUSAGE';
+ throw err;
+ }
+
+ return nodes;
+}
+
+export function get (cluster, nodes, section) {
+ const promise = Promise.reduce(Object.keys(nodes), (obj, node) => {
+ let url = buildConfigUrl(node, nodes[node], section);
+ return getConfig(node, url).then(({node, config}) => {
+ obj[node] = config;
+ return obj;
+ });
+ }, {});
+
+ promise.then((nodeConfigs) => {
+ Object.keys(nodeConfigs).forEach(node => {
+ console.log('NODE:', node);
+ console.log(prettyjson.render(nodeConfigs[node], {}));
+ });
+ });
+
+ return promise;
+}
+
+export function set(cluster, nodes, section, key, value) {
+ const urls = getClusterUrls(cluster);
+ return isonline.apply(isonline, urls).then(results => {
+ const offline = Object.keys(results).filter(node => {
+ if (!results[node]) {
+ return true;
+ }
+
+ return false
+ });
+
+ if (offline.length > 0) {
+ const msg = offline.map(node => 'Node ' + offline + ' is
offline.').join('');
+ var err = new Error(msg);
+ err.type = 'EUSAGE';
+ throw err;
+ }
+
+ var promises = Object.keys(nodes).map(node => {
+ return setConfig(node, buildConfigUrl(node, nodes[node], section,
key), value);
+ });
+
+ const allPromise = Promise.all(promises);
+ allPromise
+ .then((resp) => {
+ console.log(prettyjson.render(resp));
+ })
+ .catch((err) => {
+ console.log('ERR', err);
+ throw err;
--- End diff --
i think just throwing is enough, the rest will get logged by npmlog when
the excpetion is caught
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---