Skip to content

Commit

Permalink
Merge pull request #382 from ShiningRay/master
Browse files Browse the repository at this point in the history
Get service logs
  • Loading branch information
apocas authored Jun 9, 2017
2 parents c2ee55b + 93be2dc commit ce60eaa
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 8 deletions.
55 changes: 51 additions & 4 deletions lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,16 @@ Service.prototype.remove = function(callback) {
*/
Service.prototype.update = function(auth, opts, callback) {
var self = this;
if (!callback && typeof opts === 'function') {
callback = opts;
opts = auth;
auth = opts.authconfig || undefined;
if (!callback) {
var t = typeof opts;
if(t === 'function'){
callback = opts;
opts = auth;
auth = opts.authconfig || undefined;
} else if (t === 'undefined'){
opts = auth;
auth = opts.authconfig || undefined;
}
}

var optsf = {
Expand Down Expand Up @@ -124,4 +130,45 @@ Service.prototype.update = function(auth, opts, callback) {
};



/**
* Service logs
* @param {Object} opts Logs options. (optional)
* @param {Function} callback Callback with data
*/
Service.prototype.logs = function(opts, callback) {
var self = this;
var args = util.processArgs(opts, callback, {});

var optsf = {
path: '/services/' + this.id + '/logs?',
method: 'GET',
isStream: true,
statusCodes: {
200: true,
404: 'no such service',
500: 'server error',
503: 'node is not part of a swarm'
},
options: args.opts
};

if(args.callback === undefined) {
return new this.modem.Promise(function(resolve, reject) {
self.modem.dial(optsf, function(err, data) {
if (err) {
return reject(err);
}
resolve(data);
});
});
} else {
this.modem.dial(optsf, function(err, data) {
args.callback(err, data);
});
}
};



module.exports = Service;
30 changes: 26 additions & 4 deletions test/swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,38 @@ describe("#swarm", function() {
service.update(opts, handler);
});

it("should delete service", function(done) {
this.timeout(5000);

function handler(err, data) {

it("should get the logs for a service as a stream", function(done) {
this.timeout(30000);

var logs_opts = {
follow: true,
stdout: true,
stderr: true,
timestamps: true
};

function handler(err, stream) {
expect(err).to.be.null;
expect(stream.pipe).to.be.ok;
done();
}

service.remove(handler);
service.logs(logs_opts, handler);
});

it("should delete service", function(done) {
this.timeout(5000);

function handler(err, data) {
expect(err).to.be.null;
done();
}

service.remove(handler);
});

});

describe("#tasks", function() {
Expand Down

0 comments on commit ce60eaa

Please sign in to comment.