Skip to content

Commit

Permalink
always send strings
Browse files Browse the repository at this point in the history
stringify responses too
  • Loading branch information
Raynos committed Feb 26, 2015
1 parent 081bc41 commit db738d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
12 changes: 6 additions & 6 deletions lib/swim.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ AdminJoiner.prototype.sendJoin = function sendJoin() {
timeout: this.ringpop.pingReqTimeout
};
var local = this.ringpop.membership.localMember;
var body = {
var body = JSON.stringify({
app: this.ringpop.app,
source: local.address,
incarnationNumber: local.incarnationNumber
};
});
var self = this;
this.ringpop.channel.send(options, '/protocol/join', null, body, function (err, res1, res2) {
self.onJoin(err, res1, res2);
Expand Down Expand Up @@ -185,12 +185,12 @@ function PingReqSender(ring, member, target, callback) {
host: member.address,
timeout: this.ring.pingReqTimeout
};
var body = {
var body = JSON.stringify({
checksum: this.checksum,
changes: this.ring.issueMembershipChanges(),
source: this.ring.whoami(),
target: target.address
};
});

var self = this;
this.ring.channel.send(options, '/protocol/ping-req', null, body, function(err, res1, res2) {
Expand Down Expand Up @@ -225,11 +225,11 @@ function PingSender(ring, member, callback) {
timeout: ring.pingTimeout
};
var changes = ring.issueMembershipChanges();
var body = {
var body = JSON.stringify({
checksum: ring.membership.checksum,
changes: changes,
source: ring.whoami()
};
});

this.ring.debugLog('ping send member=' + this.address + ' changes=' + JSON.stringify(changes), 'p');

Expand Down
18 changes: 11 additions & 7 deletions lib/tchannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ RingPopTChannel.prototype.health = function (arg1, arg2, hostInfo, cb) {
};

RingPopTChannel.prototype.adminStats = function (arg1, arg2, hostInfo, cb) {
cb(null, null, this.ringPop.getStats());
cb(null, null, JSON.stringify(this.ringPop.getStats()));
};

RingPopTChannel.prototype.adminDebugSet = function (arg1, arg2, hostInfo, cb) {
Expand Down Expand Up @@ -94,7 +94,9 @@ RingPopTChannel.prototype.adminJoin = function (arg1, arg2, hostInfo, cb) {
if (err) {
return cb(err);
}
cb(null, { candidateHosts: candidateHosts });
cb(null, JSON.stringify({
candidateHosts: candidateHosts
}));
});
} else {
cb(new Error('bad JSON in request'));
Expand All @@ -112,7 +114,7 @@ RingPopTChannel.prototype.adminReload = function (arg1, arg2, hostInfo, cb) {

RingPopTChannel.prototype.adminTick = function (arg1, arg2, hostInfo, cb) {
this.ringPop.handleTick(function onTick(err, resp) {
cb(err, null, resp);
cb(err, null, JSON.stringify(resp));
});
};

Expand All @@ -134,7 +136,7 @@ RingPopTChannel.prototype.protocolJoin = function (arg1, arg2, hostInfo, cb) {
source: source,
incarnationNumber: incarnationNumber
}, function(err, res) {
cb(err, null, res);
cb(err, null, JSON.stringify(res));
});
};

Expand All @@ -152,7 +154,9 @@ RingPopTChannel.prototype.protocolLeave = function (arg1, arg2, hostInfo, cb) {
// that handled leave request, aka this node. This will
// not be obvious to the requester as the leave could
// happen through haproxy.
cb(null, null, { coordinator: this.ringPop.whoami() });
cb(null, null, JSON.stringify({
coordinator: this.ringPop.whoami()
}));
};

RingPopTChannel.prototype.protocolPing = function (arg1, arg2, hostInfo, cb) {
Expand All @@ -166,7 +170,7 @@ RingPopTChannel.prototype.protocolPing = function (arg1, arg2, hostInfo, cb) {
changes: body.changes,
checksum: body.checksum
}, function(err, res) {
cb(err, null, res);
cb(err, null, JSON.stringify(res));
});
};

Expand All @@ -182,7 +186,7 @@ RingPopTChannel.prototype.protocolPingReq = function (arg1, arg2, hostInfo, cb)
changes: body.changes,
checksum: body.checksum
}, function(err, result) {
cb(err, null, result);
cb(err, null, JSON.stringify(result));
});
};

Expand Down

0 comments on commit db738d4

Please sign in to comment.