|
|
|
@ -101,12 +101,6 @@ public class ZKMasterClient extends AbstractZKClient {
|
|
|
|
|
// init system znode
|
|
|
|
|
this.initSystemZNode(); |
|
|
|
|
|
|
|
|
|
// monitor master
|
|
|
|
|
this.listenerMaster(); |
|
|
|
|
|
|
|
|
|
// monitor worker
|
|
|
|
|
this.listenerWorker(); |
|
|
|
|
|
|
|
|
|
// register master
|
|
|
|
|
this.registerMaster(); |
|
|
|
|
|
|
|
|
@ -158,31 +152,24 @@ public class ZKMasterClient extends AbstractZKClient {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* monitor master |
|
|
|
|
* handle path events that this class cares about |
|
|
|
|
* @param client zkClient |
|
|
|
|
* @param event path event |
|
|
|
|
* @param path zk path |
|
|
|
|
*/ |
|
|
|
|
public void listenerMaster(){ |
|
|
|
|
registerListener(getZNodeParentPath(ZKNodeType.MASTER), new AbstractListener() { |
|
|
|
|
@Override |
|
|
|
|
protected void dataChanged(CuratorFramework client, TreeCacheEvent event, String path) { |
|
|
|
|
switch (event.getType()) { |
|
|
|
|
case NODE_ADDED: |
|
|
|
|
logger.info("master node added : {}", path); |
|
|
|
|
break; |
|
|
|
|
case NODE_REMOVED: |
|
|
|
|
String serverHost = getHostByEventDataPath(path); |
|
|
|
|
if (checkServerSelfDead(serverHost, ZKNodeType.MASTER)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
removeZKNodePath(path, ZKNodeType.MASTER, true); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
@Override |
|
|
|
|
protected void dataChanged(CuratorFramework client, TreeCacheEvent event, String path) { |
|
|
|
|
if(path.equals(getZNodeParentPath(ZKNodeType.MASTER))){ //monitor master
|
|
|
|
|
logger.info("master path event touch down"); |
|
|
|
|
handleMasterEvent(event,path); |
|
|
|
|
|
|
|
|
|
}else if(path.equals(getZNodeParentPath(ZKNodeType.WORKER))){ //monitor worker
|
|
|
|
|
logger.info("worker path event touch down"); |
|
|
|
|
handleWorkerEvent(event,path); |
|
|
|
|
} |
|
|
|
|
//other path event, ignore
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* remove zookeeper node path |
|
|
|
@ -273,25 +260,40 @@ public class ZKMasterClient extends AbstractZKClient {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* monitor worker |
|
|
|
|
* monitor master |
|
|
|
|
*/ |
|
|
|
|
public void listenerWorker(){ |
|
|
|
|
registerListener(getZNodeParentPath(ZKNodeType.WORKER), new AbstractListener() { |
|
|
|
|
@Override |
|
|
|
|
protected void dataChanged(CuratorFramework client, TreeCacheEvent event, String path) { |
|
|
|
|
switch (event.getType()) { |
|
|
|
|
case NODE_ADDED: |
|
|
|
|
logger.info("worker node added : {}", path); |
|
|
|
|
break; |
|
|
|
|
case NODE_REMOVED: |
|
|
|
|
logger.info("worker node deleted : {}", path); |
|
|
|
|
removeZKNodePath(path, ZKNodeType.WORKER, true); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
public void handleMasterEvent(TreeCacheEvent event, String path){ |
|
|
|
|
switch (event.getType()) { |
|
|
|
|
case NODE_ADDED: |
|
|
|
|
logger.info("master node added : {}", path); |
|
|
|
|
break; |
|
|
|
|
case NODE_REMOVED: |
|
|
|
|
String serverHost = getHostByEventDataPath(path); |
|
|
|
|
if (checkServerSelfDead(serverHost, ZKNodeType.MASTER)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
removeZKNodePath(path, ZKNodeType.MASTER, true); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* monitor worker |
|
|
|
|
*/ |
|
|
|
|
public void handleWorkerEvent(TreeCacheEvent event, String path){ |
|
|
|
|
switch (event.getType()) { |
|
|
|
|
case NODE_ADDED: |
|
|
|
|
logger.info("worker node added : {}", path); |
|
|
|
|
break; |
|
|
|
|
case NODE_REMOVED: |
|
|
|
|
logger.info("worker node deleted : {}", path); |
|
|
|
|
removeZKNodePath(path, ZKNodeType.WORKER, true); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|