Skip to content

Commit

Permalink
Merge pull request #291 from djedi23/nodeRm
Browse files Browse the repository at this point in the history
add Node.remove hidden API
  • Loading branch information
apocas authored Sep 8, 2016
2 parents 42085e8 + c3eec6a commit 5a6427c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
30 changes: 30 additions & 0 deletions lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,34 @@ Node.prototype.inspect = function(callback) {
};


/**
* Remove a Node.
* Warning: This method is not documented in the API.
*
* @param {object} options
* @param {function} callback
*/
Node.prototype.remove = function(callback) {
if (typeof callback !== 'function') {
return JSON.stringify({
id: this.id
});
}

var optsf = {
path: '/nodes/' + this.id,
method: 'DELETE',
statusCodes: {
200: true,
404: 'no such node',
500: 'server error'
}
};

this.modem.dial(optsf, function(err, data) {
callback(err, data);
});
};


module.exports = Node;
11 changes: 10 additions & 1 deletion test/swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ describe("#swarm", function() {
}
node.inspect(handler);
});

it("should remove node", function(done) {
function handler(err, data) {
// error is [Error: (HTTP code 500) server error - rpc error: code = 9 desc = node xxxxxxxxxx is a cluster manager and is a member of the raft cluster. It must be demoted to worker before removal ]
expect(err).to.not.be.null;
expect(data).to.be.null;
done();
}
node.remove(handler);
});
});
});

Expand All @@ -251,5 +261,4 @@ describe("#swarm", function() {
);
});
});

});

0 comments on commit 5a6427c

Please sign in to comment.