Created
February 7, 2017 10:15
-
-
Save m0ppers/e9c3bebb73e04615b253a8cad98e7b13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
let responseBody = ''; | |
let requestBody = '[["/"]]'; | |
let req = http.request({ | |
hostname: 'localhost', | |
port: 4001, | |
path: '/_api/agency/read', | |
method: 'post', | |
headers: { | |
'Content-Type': 'application/json', | |
'Content-Length': Buffer.byteLength(requestBody) | |
} | |
}, res => { | |
res.setEncoding('utf8'); | |
res.on('data', data => { | |
responseBody += data; | |
}); | |
res.on('end', () => { | |
let agency = JSON.parse(responseBody)[0]; | |
let inSync = Object.keys(agency.arango.Plan.Databases).reduce((inSync, database) => { | |
inSync = Object.keys(agency.arango.Plan.Collections[database]).reduce((inSync, cid) => { | |
return Object.keys(agency.arango.Plan.Collections[database][cid].shards).reduce((inSync, shardId) => { | |
let expected = agency.arango.Plan.Collections[database][cid].shards[shardId]; | |
let actual = agency.arango.Current.Collections[database][cid][shardId].servers; | |
// poor mans isEqual | |
if (JSON.stringify(expected) != JSON.stringify(actual)) { | |
process.stderr.write('Found out of sync shard ' + database | |
+ '(' + agency.arango.Plan.Collections[database][cid].name + ')' | |
+ ': ' + shardId + ' expected ' + JSON.stringify(expected) + ' actual ' + JSON.stringify(actual) + '\n'); | |
inSync = false; | |
} | |
return inSync; | |
}, inSync); | |
}, inSync); | |
return inSync; | |
}, true); | |
process.exit(inSync ? 0 : 1); | |
}); | |
}); | |
req.write(requestBody); | |
req.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment