@@ -21,6 +21,20 @@ class ZookeeperManager extends EventEmitter {
2121 this . _connect ( ) ;
2222 }
2323
24+ zkDetails ( client ) {
25+ const localAddress = client . connectionManager ?. socket ?. address ( ) ;
26+ const sessionId = client . getSessionId ?. ( ) ;
27+ return {
28+ sessionId : sessionId ? `0x${ sessionId . toString ( 'hex' ) } ` : null ,
29+ socket : localAddress ? `${ localAddress . address || '' } :${ localAddress . port || '' } ` : null ,
30+ state : client . getState ?. ( ) || null ,
31+ xid : client . connectionManager ?. xid ,
32+ zxid : client . connectionManager ?. zxid ?. toString ( 'hex' ) ,
33+ nextServerIndex : client . connectionManager ?. nextServerIndex ,
34+ serverAttempts : client . connectionManager ?. serverAttempts ,
35+ } ;
36+ }
37+
2438 /**
2539 * Establishes a connection to the ZooKeeper server.
2640 *
@@ -51,6 +65,10 @@ class ZookeeperManager extends EventEmitter {
5165 async . series ( [
5266 // Check zookeeper client is connected
5367 next => this . client . once ( 'connected' , next ) ,
68+ next => {
69+ this . log . info ( 'connected to zookeeper' , { zk : this . zkDetails ( this . client ) } ) ;
70+ next ( ) ;
71+ } ,
5472 // Create namespace if it exists and options.autoCreateNamespace is true
5573 next => {
5674 // TODO: ARTESCA-10337 The 'autoCreateNamespace' functionality is currently specific to
@@ -82,7 +100,12 @@ class ZookeeperManager extends EventEmitter {
82100 const hostPort = this . connectionString . slice ( 0 , nsIndex ) ;
83101 rootZkClient = zookeeper . createClient ( hostPort , this . options ) ;
84102 rootZkClient . connect ( ) ;
85- rootZkClient . once ( 'connected' , ( ) => next ( ) ) ;
103+ rootZkClient . once ( 'connected' , ( ) => {
104+ this . log . info ( 'connected to root zookeeper' , {
105+ zk : this . zkDetails ( rootZkClient ) ,
106+ } ) ;
107+ next ( ) ;
108+ } ) ;
86109 } ,
87110 // Once connected, use the root zookeeper client to create the namespace
88111 next => rootZkClient . mkdirp ( namespace , err => {
@@ -99,15 +122,17 @@ class ZookeeperManager extends EventEmitter {
99122 this . client . once ( 'expired' , ( ) => {
100123 this . log . info ( 'zookeeper client expired' , {
101124 method : 'ZookeeperManager.once.expired' ,
125+ zk : this . zkDetails ( this . client ) ,
102126 } ) ;
103127 // establish a new session with the ZooKeeper.
104128 this . _connect ( ) ;
105129 } ) ;
106130
107131 this . client . on ( 'state' , state => {
108- this . log . debug ( 'zookeeper new state' , {
132+ this . log . info ( 'zookeeper new state' , {
109133 state,
110134 method : 'ZookeeperManager.on.state' ,
135+ zk : this . zkDetails ( this . client ) ,
111136 } ) ;
112137 } ) ;
113138
@@ -131,6 +156,7 @@ class ZookeeperManager extends EventEmitter {
131156 * @return {undefined }
132157 */
133158 close ( ) {
159+ this . log . info ( 'closing existing zookeeper client' , { zk : this . zkDetails ( this . client ) } ) ;
134160 this . client . close ( ) ;
135161 return ;
136162 }
0 commit comments