@ -16,6 +16,7 @@
* /
package org.apache.dolphinscheduler.api.utils ;
import org.apache.dolphinscheduler.common.Constants ;
import org.apache.dolphinscheduler.common.utils.StringUtils ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
@ -43,6 +44,8 @@ public class ZooKeeperState {
private int watches = - 1 ;
private int connections = - 1 ;
private boolean healthFlag = false ;
public ZooKeeperState ( String connectionString ) {
String host = connectionString . substring ( 0 ,
connectionString . indexOf ( ':' ) ) ;
@ -55,6 +58,9 @@ public class ZooKeeperState {
public void getZookeeperInfo ( ) {
String content = cmd ( "srvr" ) ;
if ( StringUtils . isNotBlank ( content ) ) {
if ( Constants . STRING_FALSE . equals ( content ) ) {
healthFlag = true ;
} else {
try ( Scanner scannerForStat = new Scanner ( content ) ) {
while ( scannerForStat . hasNext ( ) ) {
String line = scannerForStat . nextLine ( ) ;
@ -80,8 +86,13 @@ public class ZooKeeperState {
}
}
}
String wchsText = cmd ( "wchs" ) ;
if ( StringUtils . isNotBlank ( wchsText ) ) {
if ( Constants . STRING_FALSE . equals ( wchsText ) ) {
healthFlag = true ;
} else {
try ( Scanner scannerForWchs = new Scanner ( wchsText ) ) {
while ( scannerForWchs . hasNext ( ) ) {
String line = scannerForWchs . nextLine ( ) ;
@ -91,9 +102,13 @@ public class ZooKeeperState {
}
}
}
}
String consText = cmd ( "cons" ) ;
if ( StringUtils . isNotBlank ( consText ) ) {
if ( Constants . STRING_FALSE . equals ( consText ) ) {
healthFlag = true ;
} else {
Scanner scannerForCons = new Scanner ( consText ) ;
if ( StringUtils . isNotBlank ( consText ) ) {
connections = 0 ;
@ -106,6 +121,7 @@ public class ZooKeeperState {
scannerForCons . close ( ) ;
}
}
}
public boolean ruok ( ) {
@ -121,7 +137,7 @@ public class ZooKeeperState {
private class SendThread extends Thread {
private String cmd ;
private String ret = "" ;
private String ret = Constants . STRING_FALSE ;
public SendThread ( String cmd ) {
this . cmd = cmd ;
@ -150,7 +166,7 @@ public class ZooKeeperState {
} catch ( InterruptedException e ) {
logger . error ( "send " + cmd + " to server " + host + ":" + port + " failed!" , e ) ;
}
return "" ;
return Constants . STRING_FALSE ;
}
public Logger getLogger ( ) {
@ -209,6 +225,10 @@ public class ZooKeeperState {
return connections ;
}
public boolean isHealthFlag ( ) {
return healthFlag ;
}
@Override
public String toString ( ) {
return "ZooKeeperState [host=" + host + ", port=" + port
@ -217,7 +237,7 @@ public class ZooKeeperState {
+ ", sent=" + sent + ", outStanding=" + outStanding + ", zxid="
+ zxid + ", mode=" + mode + ", nodeCount=" + nodeCount
+ ", watches=" + watches + ", connections="
+ connections + "]" ;
+ connections + ",healthFlag=" + healthFlag + " ]" ;
}