|
|
@ -140,7 +140,8 @@ public abstract class AbstractZKClient { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* heartbeat for zookeeper |
|
|
|
* heartbeat for zookeeper |
|
|
|
* @param znode |
|
|
|
* @param znode zookeeper node |
|
|
|
|
|
|
|
* @param serverType server type |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void heartBeatForZk(String znode, String serverType){ |
|
|
|
public void heartBeatForZk(String znode, String serverType){ |
|
|
|
try { |
|
|
|
try { |
|
|
@ -175,11 +176,12 @@ public abstract class AbstractZKClient { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* check dead server or not , if dead, stop self |
|
|
|
* check dead server or not , if dead, stop self |
|
|
|
* |
|
|
|
* |
|
|
|
* @param zNode node path |
|
|
|
* @param zNode node path |
|
|
|
* @param serverType master or worker prefix |
|
|
|
* @param serverType master or worker prefix |
|
|
|
* @throws Exception |
|
|
|
* @return true if not exists |
|
|
|
|
|
|
|
* @throws Exception errors |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected boolean checkIsDeadServer(String zNode, String serverType) throws Exception { |
|
|
|
protected boolean checkIsDeadServer(String zNode, String serverType) throws Exception{ |
|
|
|
//ip_sequenceno
|
|
|
|
//ip_sequenceno
|
|
|
|
String[] zNodesPath = zNode.split("\\/"); |
|
|
|
String[] zNodesPath = zNode.split("\\/"); |
|
|
|
String ipSeqNo = zNodesPath[zNodesPath.length - 1]; |
|
|
|
String ipSeqNo = zNodesPath[zNodesPath.length - 1]; |
|
|
@ -213,8 +215,8 @@ public abstract class AbstractZKClient { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* create zookeeper path according the zk node type. |
|
|
|
* create zookeeper path according the zk node type. |
|
|
|
* @param zkNodeType |
|
|
|
* @param zkNodeType zookeeper node type |
|
|
|
* @return |
|
|
|
* @return register zookeeper path |
|
|
|
* @throws Exception |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private String createZNodePath(ZKNodeType zkNodeType) throws Exception { |
|
|
|
private String createZNodePath(ZKNodeType zkNodeType) throws Exception { |
|
|
@ -231,8 +233,9 @@ public abstract class AbstractZKClient { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* register server, if server already exists, return null. |
|
|
|
* register server, if server already exists, return null. |
|
|
|
* @param zkNodeType |
|
|
|
* @param zkNodeType zookeeper node type |
|
|
|
* @return register server path in zookeeper |
|
|
|
* @return register server path in zookeeper |
|
|
|
|
|
|
|
* @throws Exception errors |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String registerServer(ZKNodeType zkNodeType) throws Exception { |
|
|
|
public String registerServer(ZKNodeType zkNodeType) throws Exception { |
|
|
|
String registerPath = null; |
|
|
|
String registerPath = null; |
|
|
@ -257,7 +260,7 @@ public abstract class AbstractZKClient { |
|
|
|
* @param zNode node path |
|
|
|
* @param zNode node path |
|
|
|
* @param zkNodeType master or worker |
|
|
|
* @param zkNodeType master or worker |
|
|
|
* @param opType delete or add |
|
|
|
* @param opType delete or add |
|
|
|
* @throws Exception |
|
|
|
* @throws Exception errors |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void handleDeadServer(String zNode, ZKNodeType zkNodeType, String opType) throws Exception { |
|
|
|
public void handleDeadServer(String zNode, ZKNodeType zkNodeType, String opType) throws Exception { |
|
|
|
//ip_sequenceno
|
|
|
|
//ip_sequenceno
|
|
|
@ -291,7 +294,7 @@ public abstract class AbstractZKClient { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* for stop server |
|
|
|
* for stop server |
|
|
|
* @param serverStoppable |
|
|
|
* @param serverStoppable server stoppable interface
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setStoppable(IStoppable serverStoppable){ |
|
|
|
public void setStoppable(IStoppable serverStoppable){ |
|
|
|
this.stoppable = serverStoppable; |
|
|
|
this.stoppable = serverStoppable; |
|
|
@ -299,7 +302,7 @@ public abstract class AbstractZKClient { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* get active master num |
|
|
|
* get active master num |
|
|
|
* @return |
|
|
|
* @return active master number |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public int getActiveMasterNum(){ |
|
|
|
public int getActiveMasterNum(){ |
|
|
|
List<String> childrenList = new ArrayList<>(); |
|
|
|
List<String> childrenList = new ArrayList<>(); |
|
|
@ -340,8 +343,8 @@ public abstract class AbstractZKClient { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* get server list. |
|
|
|
* get server list. |
|
|
|
* @param zkNodeType |
|
|
|
* @param zkNodeType zookeeper node type |
|
|
|
* @return |
|
|
|
* @return server list |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public List<Server> getServersList(ZKNodeType zkNodeType){ |
|
|
|
public List<Server> getServersList(ZKNodeType zkNodeType){ |
|
|
|
Map<String, String> masterMap = getServerMaps(zkNodeType); |
|
|
|
Map<String, String> masterMap = getServerMaps(zkNodeType); |
|
|
@ -361,8 +364,8 @@ public abstract class AbstractZKClient { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* get master server list map. |
|
|
|
* get master server list map. |
|
|
|
* result : {host : resource info} |
|
|
|
* @param zkNodeType zookeeper node type |
|
|
|
* @return |
|
|
|
* @return result : {host : resource info} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Map<String, String> getServerMaps(ZKNodeType zkNodeType){ |
|
|
|
public Map<String, String> getServerMaps(ZKNodeType zkNodeType){ |
|
|
|
|
|
|
|
|
|
|
@ -383,10 +386,9 @@ public abstract class AbstractZKClient { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* check the zookeeper node already exists |
|
|
|
* check the zookeeper node already exists |
|
|
|
* @param host |
|
|
|
* @param host host |
|
|
|
* @param zkNodeType |
|
|
|
* @param zkNodeType zookeeper node type |
|
|
|
* @return |
|
|
|
* @return true if exists |
|
|
|
* @throws Exception |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean checkZKNodeExists(String host, ZKNodeType zkNodeType) { |
|
|
|
public boolean checkZKNodeExists(String host, ZKNodeType zkNodeType) { |
|
|
|
String path = getZNodeParentPath(zkNodeType); |
|
|
|
String path = getZNodeParentPath(zkNodeType); |
|
|
@ -406,36 +408,36 @@ public abstract class AbstractZKClient { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* get zkclient |
|
|
|
* get zkclient |
|
|
|
* @return |
|
|
|
* @return zookeeper client |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public CuratorFramework getZkClient() { |
|
|
|
public CuratorFramework getZkClient() { |
|
|
|
return zkClient; |
|
|
|
return zkClient; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* get worker node parent path |
|
|
|
* |
|
|
|
* @return |
|
|
|
* @return get worker node parent path |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected String getWorkerZNodeParentPath(){return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_WORKERS);}; |
|
|
|
protected String getWorkerZNodeParentPath(){return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_WORKERS);}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* get master node parent path |
|
|
|
* |
|
|
|
* @return |
|
|
|
* @return get master node parent path |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected String getMasterZNodeParentPath(){return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_MASTERS);} |
|
|
|
protected String getMasterZNodeParentPath(){return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_MASTERS);} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* get master lock path |
|
|
|
* |
|
|
|
* @return |
|
|
|
* @return get master lock path |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String getMasterLockPath(){ |
|
|
|
public String getMasterLockPath(){ |
|
|
|
return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_LOCK_MASTERS); |
|
|
|
return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_LOCK_MASTERS); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* get zookeeper node parent path |
|
|
|
* |
|
|
|
* @param zkNodeType |
|
|
|
* @param zkNodeType zookeeper node type |
|
|
|
* @return |
|
|
|
* @return get zookeeper node parent path |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String getZNodeParentPath(ZKNodeType zkNodeType) { |
|
|
|
public String getZNodeParentPath(ZKNodeType zkNodeType) { |
|
|
|
String path = ""; |
|
|
|
String path = ""; |
|
|
@ -453,32 +455,32 @@ public abstract class AbstractZKClient { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* get dead server node parent path |
|
|
|
* |
|
|
|
* @return |
|
|
|
* @return get dead server node parent path |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected String getDeadZNodeParentPath(){ |
|
|
|
protected String getDeadZNodeParentPath(){ |
|
|
|
return conf.getString(ZOOKEEPER_DOLPHINSCHEDULER_DEAD_SERVERS); |
|
|
|
return conf.getString(ZOOKEEPER_DOLPHINSCHEDULER_DEAD_SERVERS); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* get master start up lock path |
|
|
|
* |
|
|
|
* @return |
|
|
|
* @return get master start up lock path |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String getMasterStartUpLockPath(){ |
|
|
|
public String getMasterStartUpLockPath(){ |
|
|
|
return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_LOCK_FAILOVER_STARTUP_MASTERS); |
|
|
|
return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_LOCK_FAILOVER_STARTUP_MASTERS); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* get master failover lock path |
|
|
|
* |
|
|
|
* @return |
|
|
|
* @return get master failover lock path |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String getMasterFailoverLockPath(){ |
|
|
|
public String getMasterFailoverLockPath(){ |
|
|
|
return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_LOCK_FAILOVER_MASTERS); |
|
|
|
return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_LOCK_FAILOVER_MASTERS); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* get worker failover lock path |
|
|
|
* |
|
|
|
* @return |
|
|
|
* @return get worker failover lock path |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String getWorkerFailoverLockPath(){ |
|
|
|
public String getWorkerFailoverLockPath(){ |
|
|
|
return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_LOCK_FAILOVER_WORKERS); |
|
|
|
return conf.getString(Constants.ZOOKEEPER_DOLPHINSCHEDULER_LOCK_FAILOVER_WORKERS); |
|
|
@ -486,7 +488,7 @@ public abstract class AbstractZKClient { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* release mutex |
|
|
|
* release mutex |
|
|
|
* @param mutex |
|
|
|
* @param mutex mutex |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static void releaseMutex(InterProcessMutex mutex) { |
|
|
|
public static void releaseMutex(InterProcessMutex mutex) { |
|
|
|
if (mutex != null){ |
|
|
|
if (mutex != null){ |
|
|
@ -519,8 +521,8 @@ public abstract class AbstractZKClient { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* create zookeeper node path if not exists |
|
|
|
* create zookeeper node path if not exists |
|
|
|
* @param zNodeParentPath |
|
|
|
* @param zNodeParentPath zookeeper parent path |
|
|
|
* @throws Exception |
|
|
|
* @throws Exception errors |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void createNodePath(String zNodeParentPath) throws Exception { |
|
|
|
private void createNodePath(String zNodeParentPath) throws Exception { |
|
|
|
if(null == zkClient.checkExists().forPath(zNodeParentPath)){ |
|
|
|
if(null == zkClient.checkExists().forPath(zNodeParentPath)){ |
|
|
@ -531,8 +533,9 @@ public abstract class AbstractZKClient { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* server self dead, stop all threads |
|
|
|
* server self dead, stop all threads |
|
|
|
* @param serverHost |
|
|
|
* @param serverHost server host |
|
|
|
* @param zkNodeType |
|
|
|
* @param zkNodeType zookeeper node type |
|
|
|
|
|
|
|
* @return true if server dead and stop all threads |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected boolean checkServerSelfDead(String serverHost, ZKNodeType zkNodeType) { |
|
|
|
protected boolean checkServerSelfDead(String serverHost, ZKNodeType zkNodeType) { |
|
|
|
if (serverHost.equals(OSUtils.getHost())) { |
|
|
|
if (serverHost.equals(OSUtils.getHost())) { |
|
|
@ -547,8 +550,8 @@ public abstract class AbstractZKClient { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* get host ip, string format: masterParentPath/ip_000001/value |
|
|
|
* get host ip, string format: masterParentPath/ip_000001/value |
|
|
|
* @param path |
|
|
|
* @param path path |
|
|
|
* @return |
|
|
|
* @return host ip, string format: masterParentPath/ip_000001/value |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected String getHostByEventDataPath(String path) { |
|
|
|
protected String getHostByEventDataPath(String path) { |
|
|
|
int startIndex = path.lastIndexOf("/")+1; |
|
|
|
int startIndex = path.lastIndexOf("/")+1; |
|
|
@ -562,9 +565,10 @@ public abstract class AbstractZKClient { |
|
|
|
} |
|
|
|
} |
|
|
|
/** |
|
|
|
/** |
|
|
|
* acquire zk lock |
|
|
|
* acquire zk lock |
|
|
|
* @param zkClient |
|
|
|
* @param zkClient zk client |
|
|
|
* @param zNodeLockPath |
|
|
|
* @param zNodeLockPath zk lock path |
|
|
|
* @throws Exception |
|
|
|
* @return zk lock |
|
|
|
|
|
|
|
* @throws Exception errors |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public InterProcessMutex acquireZkLock(CuratorFramework zkClient,String zNodeLockPath)throws Exception{ |
|
|
|
public InterProcessMutex acquireZkLock(CuratorFramework zkClient,String zNodeLockPath)throws Exception{ |
|
|
|
InterProcessMutex mutex = new InterProcessMutex(zkClient, zNodeLockPath); |
|
|
|
InterProcessMutex mutex = new InterProcessMutex(zkClient, zNodeLockPath); |
|
|
|