You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by garrensmith <gi...@git.apache.org> on 2015/10/07 15:18:21 UTC

[GitHub] couchdb-nmo pull request: [WIP] Active tasks

GitHub user garrensmith opened a pull request:

    https://github.com/apache/couchdb-nmo/pull/7

    [WIP] Active tasks

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/garrensmith/couchdb-nmo active-tasks

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/couchdb-nmo/pull/7.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #7
    
----
commit 147aa2f75856578fef57c9273bc52c3760a5db40
Author: Garren Smith <ga...@gmail.com>
Date:   2015-10-06T13:31:34Z

    Basic active tasks

commit 24b576a2eb1c94738e027131dc5ce53e8305203d
Author: Garren Smith <ga...@gmail.com>
Date:   2015-10-07T13:17:53Z

    clean up tests

----


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#issuecomment-147670383
  
    +1 - merge after fixing the two minor nits.
    
    thanks again!


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by garrensmith <gi...@git.apache.org>.
Github user garrensmith commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#discussion_r41842667
  
    --- Diff: src/activetasks.js ---
    @@ -0,0 +1,129 @@
    +import nmo from './nmo.js';
    +import Wreck from 'wreck';
    +import Promise from 'bluebird';
    +import log from 'npmlog';
    +import prettyjson from 'prettyjson';
    +import { validUrl, removeUsernamePw } from './utils';
    +
    +/* TODO:
    +  * active tasks implementation
    +  * tests
    +  * docs
    +*/
    +
    +export function cli (cluster, filter) {
    +  return new Promise((resolve, reject) => {
    +    if (!cluster) {
    +      const msg = [
    +        'Usage:',
    +        '',
    +        'nmo activetasks <cluster> [<filter>] [--json]',
    +        'nmo activetasks <url> [<filter>] [--json]'
    +      ].join('\n');
    +
    +      const err = new Error(msg);
    +      err.type = 'EUSAGE';
    +      return reject(err);
    +    }
    +
    +    // `cluster` argument can be a cluster or a url.
    +    // This function checks that and returns an appropriate url
    +    const url = getUrlFromCluster(cluster);
    --- End diff --
    
    Great idea. Thanks.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by garrensmith <gi...@git.apache.org>.
Github user garrensmith commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#discussion_r41785344
  
    --- Diff: doc/api/nmo-activetasks.md ---
    @@ -0,0 +1,15 @@
    +nmo-activetasks(3) -- activetasks
    +==============================
    +
    +## SYNOPSIS
    +
    +    nmo.commands.activetasks.getActiveTask(url, filter)
    +
    +
    +## DESCRIPTION
    +
    +Get the list of active tasks from a specified url and filter it according to
    +the supplied filter.
    +
    +The filter can be either the task type e.g replication, view_indexer or a
    +database name found in either the source, target or database field.
    --- End diff --
    
    I'm not quite sure what you mean? Its basically a very basic filter that either filters on type of active task or on a database name found in either source, target or database field.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#discussion_r41848300
  
    --- Diff: doc/cli/nmo-activetasks ---
    @@ -0,0 +1,27 @@
    +nmo-activetasks(1) -- view activetasks
    +===========================================
    +
    +## SYNOPSIS
    +
    +    nmo activetasks cluster, [<filter>] [--json]
    +    nmo activetasks url, [<filter>] [--json]
    --- End diff --
    
    remove the both commas


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#discussion_r41784933
  
    --- Diff: doc/api/nmo-activetasks.md ---
    @@ -0,0 +1,15 @@
    +nmo-activetasks(3) -- activetasks
    +==============================
    +
    +## SYNOPSIS
    +
    +    nmo.commands.activetasks.getActiveTask(url, filter)
    --- End diff --
    
    just export `getActiveTask` as default (example https://github.com/apache/couchdb-nmo/blob/master/src/isonline.js#L54) and you can change the api consistent to the other existing:
    ```
    nmo.commands.activetasks(url, filter)
    ```


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#discussion_r41785081
  
    --- Diff: doc/api/nmo-activetasks.md ---
    @@ -0,0 +1,15 @@
    +nmo-activetasks(3) -- activetasks
    +==============================
    +
    +## SYNOPSIS
    +
    +    nmo.commands.activetasks.getActiveTask(url, filter)
    --- End diff --
    
    is it 
    
    ```
    nmo.commands.activetasks.getActiveTask(<url>, [filter])
    ```
    
    ?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#discussion_r41785289
  
    --- Diff: src/activetasks.js ---
    @@ -0,0 +1,129 @@
    +import nmo from './nmo.js';
    +import Wreck from 'wreck';
    +import Promise from 'bluebird';
    +import log from 'npmlog';
    +import prettyjson from 'prettyjson';
    +import { validUrl, removeUsernamePw } from './utils';
    +
    +/* TODO:
    +  * active tasks implementation
    +  * tests
    +  * docs
    +*/
    +
    +export function cli (cluster, filter) {
    +  return new Promise((resolve, reject) => {
    +    if (!cluster) {
    +      const msg = [
    +        'Usage:',
    +        '',
    +        'nmo activetasks <cluster> [<filter>] [--json]',
    +        'nmo activetasks <url> [<filter>] [--json]'
    +      ].join('\n');
    +
    +      const err = new Error(msg);
    +      err.type = 'EUSAGE';
    +      return reject(err);
    +    }
    +
    +    // `cluster` argument can be a cluster or a url.
    +    // This function checks that and returns an appropriate url
    +    const url = getUrlFromCluster(cluster);
    +    getActiveTask(url, filter).then(tasks => {
    +      const jsonOut = nmo.config.get('json');
    +
    +      if (jsonOut) {
    +        console.log(tasks);
    --- End diff --
    
    you can early return here and reduce the nesting


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by garrensmith <gi...@git.apache.org>.
Github user garrensmith commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#discussion_r41785260
  
    --- Diff: doc/api/nmo-activetasks.md ---
    @@ -0,0 +1,15 @@
    +nmo-activetasks(3) -- activetasks
    +==============================
    +
    +## SYNOPSIS
    +
    +    nmo.commands.activetasks.getActiveTask(url, filter)
    +
    +
    +## DESCRIPTION
    +
    +Get the list of active tasks from a specified url and filter it according to
    --- End diff --
    
    Sorry I meant to say it can be either a url or a cluster.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#discussion_r41785012
  
    --- Diff: doc/api/nmo-activetasks.md ---
    @@ -0,0 +1,15 @@
    +nmo-activetasks(3) -- activetasks
    +==============================
    +
    +## SYNOPSIS
    +
    +    nmo.commands.activetasks.getActiveTask(url, filter)
    +
    +
    +## DESCRIPTION
    +
    +Get the list of active tasks from a specified url and filter it according to
    +the supplied filter.
    +
    +The filter can be either the task type e.g replication, view_indexer or a
    +database name found in either the source, target or database field.
    --- End diff --
    
    i guess a filter is not needed for all types?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#discussion_r41785998
  
    --- Diff: test/config.js ---
    @@ -207,19 +206,19 @@ lab.experiment('config', () => {
     
           console.log = (...args) => {
             assert.deepEqual(jsonData, args[0]);
    +        done();
           };
     
    -      nmo.load({nmoconf: __dirname + '/fixtures/randomini', json: true})
    +      config.load({nmoconf: __dirname + '/fixtures/randomini', json: true})
             .then((res) => {
    -          config.cli('get').then((result) => {
    -            done();
    -          });
    +          oldConsole('FILE', fs.readFileSync(__dirname + '/fixtures/randomini', 'utf8'));
    +          config.cli('get');
    --- End diff --
    
    that refactor is cool, thanks for cleaning it up!


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by garrensmith <gi...@git.apache.org>.
Github user garrensmith closed the pull request at:

    https://github.com/apache/couchdb-nmo/pull/7


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#discussion_r41785958
  
    --- Diff: test/config.js ---
    @@ -207,19 +206,19 @@ lab.experiment('config', () => {
     
           console.log = (...args) => {
             assert.deepEqual(jsonData, args[0]);
    +        done();
           };
     
    -      nmo.load({nmoconf: __dirname + '/fixtures/randomini', json: true})
    +      config.load({nmoconf: __dirname + '/fixtures/randomini', json: true})
             .then((res) => {
    -          config.cli('get').then((result) => {
    -            done();
    -          });
    +          oldConsole('FILE', fs.readFileSync(__dirname + '/fixtures/randomini', 'utf8'));
    --- End diff --
    
    debug output?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#discussion_r41786743
  
    --- Diff: src/nmo.js ---
    @@ -34,10 +42,7 @@ Object.defineProperty(nmo, 'cli', {
       }
     });
     
    -nmo.version = pkg.version;
    -
    -const commandFuncs = {}, cliFuncs = {};
    -nmo.load = function load (opts) {
    +nmo.load = function (opts) {
    --- End diff --
    
    the now anonymous function was named for a reason, so you could identify it easily in stacktraces / a dump of the JavaScript heap (vs <anonymous function> or <closure> for an anonymous function)


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#discussion_r41848122
  
    --- Diff: src/activetasks.js ---
    @@ -0,0 +1,113 @@
    +import nmo from './nmo.js';
    +import Wreck from 'wreck';
    +import Promise from 'bluebird';
    +import log from 'npmlog';
    +import prettyjson from 'prettyjson';
    +import {getUrlFromCluster, validUrl, removeUsernamePw } from './utils';
    +
    +/* TODO:
    +  * active tasks implementation
    +  * tests
    +  * docs
    +*/
    --- End diff --
    
    i think we can delete the comment


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#discussion_r41848202
  
    --- Diff: doc/api/nmo-activetasks.md ---
    @@ -0,0 +1,15 @@
    +nmo-activetasks(3) -- activetasks
    +==============================
    +
    +## SYNOPSIS
    +
    +    nmo.commands.activetasks.getActiveTask([<url> || <cluster>], [filter])
    --- End diff --
    
    remove `.getActiveTask`


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#discussion_r41785140
  
    --- Diff: doc/api/nmo-activetasks.md ---
    @@ -0,0 +1,15 @@
    +nmo-activetasks(3) -- activetasks
    +==============================
    +
    +## SYNOPSIS
    +
    +    nmo.commands.activetasks.getActiveTask(url, filter)
    +
    +
    +## DESCRIPTION
    +
    +Get the list of active tasks from a specified url and filter it according to
    --- End diff --
    
    why is it not a cluster but an url? (i am also not sure what it should be)


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by garrensmith <gi...@git.apache.org>.
Github user garrensmith commented on the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#issuecomment-147739334
  
    Thanks for all the help @robertkowalski. Its now merged in.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#discussion_r41785262
  
    --- Diff: src/activetasks.js ---
    @@ -0,0 +1,129 @@
    +import nmo from './nmo.js';
    +import Wreck from 'wreck';
    +import Promise from 'bluebird';
    +import log from 'npmlog';
    +import prettyjson from 'prettyjson';
    +import { validUrl, removeUsernamePw } from './utils';
    +
    +/* TODO:
    +  * active tasks implementation
    +  * tests
    +  * docs
    +*/
    +
    +export function cli (cluster, filter) {
    +  return new Promise((resolve, reject) => {
    +    if (!cluster) {
    +      const msg = [
    +        'Usage:',
    +        '',
    +        'nmo activetasks <cluster> [<filter>] [--json]',
    +        'nmo activetasks <url> [<filter>] [--json]'
    +      ].join('\n');
    +
    +      const err = new Error(msg);
    +      err.type = 'EUSAGE';
    +      return reject(err);
    +    }
    +
    +    // `cluster` argument can be a cluster or a url.
    +    // This function checks that and returns an appropriate url
    +    const url = getUrlFromCluster(cluster);
    --- End diff --
    
    if you move it inside the api call the api works for urls and clusters


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#discussion_r41785903
  
    --- Diff: test/config.js ---
    @@ -55,6 +53,7 @@ lab.experiment('config', () => {
     
           config.load({nmoconf: __dirname + '/fixtures/randomini'})
             .then((res) => {
    +          oldConsole('RES', res);
    --- End diff --
    
    debug output?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#discussion_r41785705
  
    --- Diff: test/activetasks.js ---
    @@ -0,0 +1,230 @@
    +import assert from 'assert';
    +import nock from 'nock';
    +import Lab from 'lab';
    +export const lab = Lab.script();
    +import { createConfigFile } from './common';
    +
    +import nmo from '../src/nmo.js';
    +import { filterTasks, cli, getUrlFromCluster, getActiveTask }  from '../src/activetasks.js';
    +
    +lab.experiment('activetasks', () => {
    +  createConfigFile();
    +  lab.beforeEach((done) => {
    +    nmo
    +      .load({nmoconf: __dirname + '/fixtures/randomini'})
    +      .then(() => done())
    +      .catch(() => done());
    +  });
    +
    +  lab.experiment('cli', () => {
    +    const oldConsole = console.log;
    +
    +    lab.afterEach(done => {
    +      console.log = oldConsole;
    +      done();
    +    });
    +
    +    lab.test('no arguments', done => {
    +      cli().catch(err => {
    +        assert.ok(/Usage/.test(err.message));
    +        done();
    +      });
    +    });
    +
    +    lab.test('does json', done => {
    +      nock('http://127.0.0.11')
    +        .get('/_active_tasks')
    +        .reply(200, []);
    +
    +      console.log = msg => {
    +        assert.deepEqual(msg, []);
    +        done();
    +      };
    +
    +      nmo
    +        .load({nmoconf: __dirname + '/fixtures/randomini', json: true})
    +        .then(() => {
    +          cli('http://127.0.0.11');
    +        });
    +
    +    });
    +
    +    lab.test('rejests errors', done => {
    +      cli('http://127.0.0.11')
    +      .catch(err => {
    +        assert.ok(err);
    +        done();
    +      });
    +    });
    +
    +    lab.test('Not existing cluster', (done) => {
    +
    +      cli('wrong').catch(err => {
    +        assert.ok(/'wrong' is not a cluster /.test(err.message));
    +        done();
    +      });
    +    });
    +
    +    lab.test('returns no active tasks for filter', done => {
    +      console.log = function (msg) {
    +        assert.ok(/for that filter/.test(msg));
    +        done();
    +      };
    +
    +      nock('http://127.0.0.11')
    +        .get('/_active_tasks')
    +        .reply(200, []);
    +
    +      cli('http://127.0.0.11', 'filter');
    +    });
    +
    +
    +    lab.test('returns no active tasks', done => {
    +      console.log = function (msg) {
    +        assert.ok(/There are no active tasks/.test(msg));
    +        done();
    +      };
    +
    +      nock('http://127.0.0.11')
    +        .get('/_active_tasks')
    +        .reply(200, []);
    +
    +      cli('http://127.0.0.11');
    +    });
    +
    +    lab.test('returns active tasks', done => {
    +      const resp = `[{"node":"node1@127.0.0.1","pid":"<0.8331.5>",
    +                    "changes_pending":null,"checkpoint_interval":5000,
    +                    "checkpointed_source_seq":"1234",
    +                    "continuous":true,"database":null,
    +                    "doc_id":null,"doc_write_failures":0,"docs_read":44,
    +                    "docs_written":44,"missing_revisions_found":44,
    +                    "replication_id":"123123123",
    +                    "revisions_checked":44,
    +                    "source":"http://127.0.0.1:15984/mango-query/",
    +                    "source_seq":"1231",
    +                    "started_on":1444135320,
    +                    "target":"http://127.0.0.1:15984/test-mango/",
    +                    "through_seq":"12313","type":"replication",
    +                    "updated_on":1444135325,"user":null}]`;
    +
    +      nock('http://127.0.0.11')
    +        .get('/_active_tasks')
    +        .reply(200, resp);
    +
    +      console.log = msg => {
    +        if (!/Active/.test(msg)) { return; }
    +
    +        assert.ok(/Active Tasks:/.test(msg));
    +        done();
    +      };
    +
    +      cli('http://127.0.0.11');
    +    });
    +
    +  });
    +
    +  lab.experiment('getUrlFromCluster', () => {
    +
    +    lab.test('it returns url for url passed to it', done => {
    +      const url = 'http://127.0.0.1';
    +      const out = getUrlFromCluster(url);
    --- End diff --
    
    maybe we can put this method even into `utils.js` -  i remember that we used something similiar somewhere else


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by garrensmith <gi...@git.apache.org>.
Github user garrensmith commented on the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#issuecomment-149462513
  
    Merged.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#discussion_r41786144
  
    --- Diff: test/common.js ---
    @@ -11,29 +10,30 @@ export const NODE_TWO = 'http://127.0.0.1:' + PORT_TWO;
     export const NODE_WITH_PW = 'http://a:b@127.0.0.1:' + PORT;
     export const NODE_TWO_WITH_PW = 'http://a:b@127.0.0.1:' + PORT_TWO;
     
    -export function createTestServers () {
    -  const promises = [PORT, PORT_TWO].map((port) => {
    -    return createTestServer(port);
    -  });
    +const data = `[clusterone]
    +node0=http://127.0.0.1
    +node1=http://192.168.0.1
     
    -  return Promise.all(promises);
    -}
    +[onenodecluster]
    +node1=iamalonelylnode
     
    -export function stopTestServers (servers) {
    -  const s = servers.map((s) => {
    -    const close = Promise.promisify(s.close).bind(s);
    -    return close();
    -  });
    -  return Promise.all(s);
    -}
    +[clustervalidurlsbothdown]
    +node0=http:\/\/neverexists.neverexists
    +node1=http:\/\/neverexists2.neverexists
    +
    +[clustervalidurlsonedown]
    +node1=http:\/\/neverexists2.neverexists
    +node2=${NODE}
    +
    +[clustervalidurls]
    +node1=${NODE}
    +node2=${NODE_TWO}
     
    -export function createTestServer (port) {
    -  let i = 0;
    -  return new Promise((resolve) => {
    -    const s = http.createServer((req, res) => {
    +[clustervalidurlswithpw]
    +node1=${NODE_WITH_PW}
    +node2=${NODE_TWO_WITH_PW}
    +`;
     
    -      res.writeHead(200, {'Content-Type': 'application/json'});
    -      res.end(JSON.stringify({ok: true}));
    -    }).listen(port, '127.0.0.1', () => { resolve(s); });
    -  });
    +export function createConfigFile () {
    +  fs.writeFileSync(__dirname + '/fixtures/randomini', data, 'utf-8');
    --- End diff --
    
    <3


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-nmo pull request: Active tasks

Posted by garrensmith <gi...@git.apache.org>.
Github user garrensmith commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/7#discussion_r41842552
  
    --- Diff: src/activetasks.js ---
    @@ -0,0 +1,129 @@
    +import nmo from './nmo.js';
    +import Wreck from 'wreck';
    +import Promise from 'bluebird';
    +import log from 'npmlog';
    +import prettyjson from 'prettyjson';
    +import { validUrl, removeUsernamePw } from './utils';
    +
    +/* TODO:
    +  * active tasks implementation
    +  * tests
    +  * docs
    +*/
    +
    +export function cli (cluster, filter) {
    +  return new Promise((resolve, reject) => {
    +    if (!cluster) {
    +      const msg = [
    +        'Usage:',
    +        '',
    +        'nmo activetasks <cluster> [<filter>] [--json]',
    +        'nmo activetasks <url> [<filter>] [--json]'
    +      ].join('\n');
    +
    +      const err = new Error(msg);
    +      err.type = 'EUSAGE';
    +      return reject(err);
    +    }
    +
    +    // `cluster` argument can be a cluster or a url.
    +    // This function checks that and returns an appropriate url
    +    const url = getUrlFromCluster(cluster);
    +    getActiveTask(url, filter).then(tasks => {
    +      const jsonOut = nmo.config.get('json');
    +
    +      if (jsonOut) {
    +        console.log(tasks);
    --- End diff --
    
    I also thought of that. But  I cannot because I need to resolve the promise at the end.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---