@@ -21,6 +21,19 @@ class ZookeeperManager extends EventEmitter {
2121 this . _connect ( ) ;
2222 }
2323
24+ zkDetails ( client ) {
25+ const localAddress = client . connectionManager ?. socket ?. address ( ) ;
26+ return {
27+ sessionId : `0x${ client . getSessionId ( ) . toString ( 'hex' ) } ` ,
28+ socket : `${ localAddress . address || '' } :${ localAddress . port || '' } ` ,
29+ state : client . getState ( ) ,
30+ xid : client . connectionManager ?. xid ,
31+ zxid : client . connectionManager ?. zxid ?. toString ( 'hex' ) ,
32+ nextServerIndex : client . connectionManager ?. nextServerIndex ,
33+ serverAttempts : client . connectionManager ?. serverAttempts ,
34+ } ;
35+ }
36+
2437 /**
2538 * Establishes a connection to the ZooKeeper server.
2639 *
@@ -51,6 +64,10 @@ class ZookeeperManager extends EventEmitter {
5164 async . series ( [
5265 // Check zookeeper client is connected
5366 next => this . client . once ( 'connected' , next ) ,
67+ next => {
68+ this . log . info ( 'connected to zookeeper' , { zk : this . zkDetails ( this . client ) } ) ;
69+ next ( ) ;
70+ } ,
5471 // Create namespace if it exists and options.autoCreateNamespace is true
5572 next => {
5673 // TODO: ARTESCA-10337 The 'autoCreateNamespace' functionality is currently specific to
@@ -82,7 +99,12 @@ class ZookeeperManager extends EventEmitter {
8299 const hostPort = this . connectionString . slice ( 0 , nsIndex ) ;
83100 rootZkClient = zookeeper . createClient ( hostPort , this . options ) ;
84101 rootZkClient . connect ( ) ;
85- rootZkClient . once ( 'connected' , ( ) => next ( ) ) ;
102+ rootZkClient . once ( 'connected' , ( ) => {
103+ this . log . info ( 'connected to root zookeeper' , {
104+ zk : this . zkDetails ( rootZkClient ) ,
105+ } ) ;
106+ next ( ) ;
107+ } ) ;
86108 } ,
87109 // Once connected, use the root zookeeper client to create the namespace
88110 next => rootZkClient . mkdirp ( namespace , err => {
@@ -99,15 +121,17 @@ class ZookeeperManager extends EventEmitter {
99121 this . client . once ( 'expired' , ( ) => {
100122 this . log . info ( 'zookeeper client expired' , {
101123 method : 'ZookeeperManager.once.expired' ,
124+ zk : this . zkDetails ( this . client ) ,
102125 } ) ;
103126 // establish a new session with the ZooKeeper.
104127 this . _connect ( ) ;
105128 } ) ;
106129
107130 this . client . on ( 'state' , state => {
108- this . log . debug ( 'zookeeper new state' , {
131+ this . log . info ( 'zookeeper new state' , {
109132 state,
110133 method : 'ZookeeperManager.on.state' ,
134+ zk : this . zkDetails ( this . client ) ,
111135 } ) ;
112136 } ) ;
113137
@@ -131,6 +155,7 @@ class ZookeeperManager extends EventEmitter {
131155 * @return {undefined }
132156 */
133157 close ( ) {
158+ this . log . info ( 'closing existing zookeeper client' , { zk : this . zkDetails ( this . client ) } ) ;
134159 this . client . close ( ) ;
135160 return ;
136161 }
0 commit comments