|
21 | 21 | // THE SOFTWARE. |
22 | 22 | 'use strict'; |
23 | 23 |
|
24 | | -var createTable = require('./lib/table.js'); |
25 | | -var ClusterManager = require('./lib/cluster.js'); |
| 24 | +var assertTruthy = require('./lib/util.js').assertTruthy; |
| 25 | +var Cluster = require('./lib/cluster.js'); |
26 | 26 | var parseStatusCommand = require('./parser.js').parseStatusCommand; |
| 27 | +var printTable = require('./lib/table.js').print; |
| 28 | + |
| 29 | +function getDampScoreRange(allStats, statusMember) { |
| 30 | + var lowest = Number.MAX_VALUE; |
| 31 | + var highest = 0; |
| 32 | + |
| 33 | + allStats.forEach(function each(stat) { |
| 34 | + stat.members.forEach(function each(member) { |
| 35 | + if (member.address !== statusMember.address) return; |
| 36 | + |
| 37 | + var dampScore = member.dampScore; |
| 38 | + if (typeof dampScore === 'undefined') { |
| 39 | + return; |
| 40 | + } |
| 41 | + |
| 42 | + if (dampScore < lowest) { |
| 43 | + lowest = dampScore; |
| 44 | + } |
| 45 | + |
| 46 | + if (dampScore > highest) { |
| 47 | + highest = dampScore; |
| 48 | + } |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + return lowest + '..' + highest; |
| 53 | +} |
27 | 54 |
|
28 | 55 | function main() { |
29 | 56 | var command = parseStatusCommand(); |
30 | | - var clusterManager = new ClusterManager({ |
| 57 | + var cluster = new Cluster({ |
31 | 58 | useTChannelV1: command.useTChannelV1, |
32 | 59 | coordAddr: command.coordinator |
33 | 60 | }); |
34 | | - clusterManager.fetchStats(function onStats(err) { |
35 | | - if (err) { |
36 | | - console.error('Error: ' + err.message); |
37 | | - process.exit(1); |
38 | | - } |
39 | | - |
40 | | - if (clusterManager.getPartitionCount() > 1) { |
41 | | - console.error('Error: cluster is partitioned. An accurate status cannot be provided.'); |
42 | | - process.exit(1); |
43 | | - } |
44 | | - |
45 | | - var table = createTable([]); |
46 | | - var cluster = clusterManager.getClusterAt(0); |
47 | | - if (!cluster) { |
48 | | - console.error('Error: no members in the cluster could be reached'); |
49 | | - process.exit(1); |
50 | | - } |
51 | | - cluster.membership.forEach(function each(member) { |
52 | | - table.push([member.address, member.status]); |
| 61 | + cluster.fetchStats(function onStats(err) { |
| 62 | + assertTruthy(!err, (err && err.message)); |
| 63 | + assertTruthy(cluster.getClusterAt(0), |
| 64 | + 'Error: no members in the cluster could be reached'); |
| 65 | + assertTruthy(cluster.getPartitionCount() === 1, |
| 66 | + 'Error: cluster is partitioned. ' + |
| 67 | + 'An accurate status cannot be provided'); |
| 68 | + |
| 69 | + var partition = cluster.getPartitionAt(0); |
| 70 | + printTable(command, [ |
| 71 | + 'ADDRESS', |
| 72 | + 'STATUS', |
| 73 | + 'DAMPSCORE' |
| 74 | + ], function addRows(table) { |
| 75 | + // Add status information to table |
| 76 | + partition.membership.forEach(function each(member) { |
| 77 | + table.push([member.address, member.status, |
| 78 | + getDampScoreRange(cluster.allStats, member)]); |
| 79 | + }); |
53 | 80 | }); |
54 | | - console.log(table.toString()); |
55 | 81 | process.exit(); |
56 | 82 | }); |
57 | 83 | } |
|
0 commit comments