@@ -11,63 +11,65 @@ internal class SniffResponse
1111 private static Regex AddressRe { get ; } = new Regex ( @"^((?<fqdn>[^/]+)/)?(?<ip>[^:]+):(?<port>\d+)$" ) ;
1212
1313 public string cluster_name { get ; set ; }
14- public Dictionary < string , SniffNode > nodes { get ; set ; }
14+ public Dictionary < string , NodeInfo > nodes { get ; set ; }
1515
1616 public IEnumerable < Node > ToNodes ( bool forceHttp = false )
1717 {
18- foreach ( var kv in nodes . Where ( n=> n . Value . HttpEnabled ) )
18+ foreach ( var kv in nodes . Where ( n => n . Value . HttpEnabled ) )
1919 {
20- yield return new Node ( this . ParseToUri ( kv . Value . http_address , forceHttp ) )
20+ yield return new Node ( this . ParseToUri ( kv . Value . http ? . bound_address . FirstOrDefault ( ) , forceHttp ) )
2121 {
2222 Name = kv . Value . name ,
2323 Id = kv . Key ,
2424 MasterEligible = kv . Value . MasterEligible ,
2525 HoldsData = kv . Value . HoldsData ,
26- HttpEnabled = kv . Value . HttpEnabled ,
2726 } ;
2827 }
2928 }
3029
31- private Uri ParseToUri ( string httpAdress , bool forceHttp )
30+ private Uri ParseToUri ( string boundAddress , bool forceHttp )
3231 {
33- if ( httpAdress . IsNullOrEmpty ( ) ) return null ;
32+ if ( boundAddress . IsNullOrEmpty ( ) ) return null ;
3433 var suffix = forceHttp ? "s" : string . Empty ;
35- var match = AddressRe . Match ( httpAdress ) ;
36- if ( ! match . Success ) throw new Exception ( $ "Can not parse http_address : { httpAdress } to Uri") ;
34+ var match = AddressRe . Match ( boundAddress ) ;
35+ if ( ! match . Success ) throw new Exception ( $ "Can not parse bound_address : { boundAddress } to Uri") ;
3736
3837 var fqdn = match . Groups [ "fqdn" ] . Value ? . Trim ( ) ;
3938 var ip = match . Groups [ "ip" ] . Value ? . Trim ( ) ;
4039 var port = match . Groups [ "port" ] . Value ? . Trim ( ) ;
4140 var host = ! fqdn . IsNullOrEmpty ( ) ? fqdn : ip ;
4241
4342 return new Uri ( $ "http{ suffix } ://{ host } :{ port } ") ;
44-
4543 }
46-
4744 }
4845
49- internal class SniffNode
46+ internal class NodeInfo
5047 {
5148 public string name { get ; set ; }
5249 public string transport_address { get ; set ; }
53- public string http_address { get ; set ; }
5450 public string host { get ; set ; }
5551 public string ip { get ; set ; }
5652 public string version { get ; set ; }
57- public string build { get ; set ; }
53+ public string build_hash { get ; set ; }
54+ public IList < string > roles { get ; set ; }
55+ public NodeInfoHttp http { get ; set ; }
5856 public IDictionary < string , string > settings { get ; set ; }
5957
60- internal bool MasterEligible => ! ( ( this . settings ? . ContainsKey ( "node. master") ) . GetValueOrDefault ( false ) && Convert . ToBoolean ( this . settings [ "node.master" ] ) == false ) ;
61- internal bool HoldsData => ! ( ( this . settings ? . ContainsKey ( "node. data") ) . GetValueOrDefault ( false ) && Convert . ToBoolean ( this . settings [ "node.data" ] ) == false ) ;
58+ internal bool MasterEligible => this . roles ? . Contains ( " master") ?? false ;
59+ internal bool HoldsData => this . roles ? . Contains ( " data") ?? false ;
6260 internal bool HttpEnabled
6361 {
6462 get
6563 {
66- if ( this . settings == null ) return true ;
67- if ( ! this . settings . ContainsKey ( "http.enabled" ) ) return true ;
68- return Convert . ToBoolean ( this . settings [ " http.enabled" ] ) ;
64+ if ( this . settings != null && this . settings . ContainsKey ( "http.enabled" ) )
65+ return Convert . ToBoolean ( this . settings [ "http.enabled" ] ) ;
66+ return http != null ;
6967 }
7068 }
7169 }
7270
71+ internal class NodeInfoHttp
72+ {
73+ public IList < string > bound_address { get ; set ; }
74+ }
7375}
0 commit comments