@@ -29,13 +29,15 @@ var Stats = require('./stats.js');
2929var format = require ( 'util' ) . format ;
3030var startsWith = require ( './util.js' ) . startsWith ;
3131
32+ var discover = require ( './discover' ) . discover ;
33+
3234function Cluster ( opts ) {
3335 opts = opts || {
3436 dumpTo : 'ringpop-admin-stats.dump'
3537 } ;
3638
3739 this . useTChannelV1 = opts . useTChannelV1 ;
38- this . coordAddr = opts . coordAddr ;
40+ this . discoveryUri = opts . discoveryUri ;
3941 this . adminClient = new AdminClient ( {
4042 useTChannelV1 : this . useTChannelV1
4143 } ) ;
@@ -84,29 +86,8 @@ Cluster.prototype.getPartitionCount = function getPartitionCount() {
8486} ;
8587
8688Cluster . prototype . getSeedList = function getSeedList ( callback ) {
87- var self = this ;
88- // figure out if the coordinator is a file
89- fs . exists ( self . coordAddr , function ( exists ) {
90- if ( exists ) {
91- // treat the coordinator as a bootstrap file
92- fs . readFile ( self . coordAddr , function ( err , body ) {
93- if ( err ) {
94- return callback ( err ) ;
95- }
96-
97- try {
98- body = JSON . parse ( body ) ;
99- } catch ( e ) {
100- return callback ( e ) ;
101- }
102-
103- // seed the list with the hosts in the bootstrap file
104- return callback ( null , body ) ;
105- } ) ;
106- } else {
107- return callback ( null , [ self . coordAddr ] ) ;
108- }
109- } ) ;
89+ // use the discover library to fetch the seedlist
90+ discover ( this . discoveryUri , callback ) ;
11091} ;
11192
11293Cluster . prototype . fetchStats = function fetchStats ( callback ) {
@@ -128,7 +109,8 @@ Cluster.prototype.fetchStats = function fetchStats(callback) {
128109
129110 this . getSeedList ( function ( err , seeds ) {
130111 if ( err ) {
131- return callback ( err ) ;
112+ callback ( err ) ;
113+ return ;
132114 }
133115 queueMembers ( seeds ) ;
134116 } ) ;
@@ -179,7 +161,7 @@ Cluster.prototype.fetchStats = function fetchStats(callback) {
179161
180162 function onComplete ( err , allStats ) {
181163 if ( allStats . length === 0 ) {
182- var addr = self . coordAddr ;
164+ var addr = self . discoveryUri ;
183165 var msg = format ( 'Failed to connect to ringpop listening on %s.' , addr ) ;
184166
185167 // Check if user tries to connect to localhost or 127.0.0.1.
@@ -221,13 +203,13 @@ Cluster.prototype.fetchStats = function fetchStats(callback) {
221203
222204Cluster . prototype . lookup = function lookup ( key , callback ) {
223205 var self = this ;
224- this . fetchStats ( function onStats ( err ) {
206+
207+ this . getSeedList ( function ( err , seeds ) {
225208 if ( err ) {
226209 callback ( err ) ;
227210 return ;
228211 }
229-
230- self . adminClient . lookup ( self . coordAddr , key , callback ) ;
212+ self . adminClient . lookup ( seeds [ 0 ] , key , callback ) ;
231213 } ) ;
232214} ;
233215
0 commit comments