|
|
@ -41,15 +41,31 @@ import java.util.Map;
|
|
|
|
@Slf4j
|
|
|
|
@Slf4j
|
|
|
|
public class ZookeeperRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh {
|
|
|
|
public class ZookeeperRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static final String ZK_CONNECT_STR = "zk-connect-str";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static final String ROOT_NODE = "root-node";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static final String CONFIG_VERSION = "config-version";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static final String NODE = "node";
|
|
|
|
|
|
|
|
|
|
|
|
private CuratorFramework curatorFramework;
|
|
|
|
private CuratorFramework curatorFramework;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public String getProperties() {
|
|
|
|
|
|
|
|
Map<String, String> zkConfigs = bootstrapConfigProperties.getZookeeper();
|
|
|
|
|
|
|
|
String nodePath = ZKPaths.makePath(ZKPaths.makePath(zkConfigs.get(ROOT_NODE),
|
|
|
|
|
|
|
|
zkConfigs.get(CONFIG_VERSION)), zkConfigs.get(NODE));
|
|
|
|
|
|
|
|
return nodePathResolver(nodePath);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void afterPropertiesSet() {
|
|
|
|
public void afterPropertiesSet() {
|
|
|
|
Map<String, String> zkConfigs = bootstrapConfigProperties.getZookeeper();
|
|
|
|
Map<String, String> zkConfigs = bootstrapConfigProperties.getZookeeper();
|
|
|
|
curatorFramework = CuratorFrameworkFactory.newClient(zkConfigs.get("zk-connect-str"),
|
|
|
|
curatorFramework = CuratorFrameworkFactory.newClient(zkConfigs.get(ZK_CONNECT_STR),
|
|
|
|
new ExponentialBackoffRetry(1000, 3));
|
|
|
|
new ExponentialBackoffRetry(1000, 3));
|
|
|
|
String nodePath = ZKPaths.makePath(ZKPaths.makePath(zkConfigs.get("root-node"),
|
|
|
|
String nodePath = ZKPaths.makePath(ZKPaths.makePath(zkConfigs.get(ROOT_NODE),
|
|
|
|
zkConfigs.get("config-version")), zkConfigs.get("node"));
|
|
|
|
zkConfigs.get(CONFIG_VERSION)), zkConfigs.get(NODE));
|
|
|
|
final ConnectionStateListener connectionStateListener = (client, newState) -> {
|
|
|
|
final ConnectionStateListener connectionStateListener = (client, newState) -> {
|
|
|
|
if (newState == ConnectionState.CONNECTED) {
|
|
|
|
if (newState == ConnectionState.CONNECTED) {
|
|
|
|
loadNode(nodePath);
|
|
|
|
loadNode(nodePath);
|
|
|
@ -81,6 +97,20 @@ public class ZookeeperRefresherHandler extends AbstractConfigThreadPoolDynamicRe
|
|
|
|
* @param nodePath zk config node path.
|
|
|
|
* @param nodePath zk config node path.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void loadNode(String nodePath) {
|
|
|
|
public void loadNode(String nodePath) {
|
|
|
|
|
|
|
|
String content = nodePathResolver(nodePath);
|
|
|
|
|
|
|
|
if (content != null) {
|
|
|
|
|
|
|
|
dynamicRefresh(content);
|
|
|
|
|
|
|
|
registerNotifyAlarmManage();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* resolver for zk config
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param nodePath zk config node path
|
|
|
|
|
|
|
|
* @return resolver result
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private String nodePathResolver(String nodePath) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
final GetChildrenBuilder childrenBuilder = curatorFramework.getChildren();
|
|
|
|
final GetChildrenBuilder childrenBuilder = curatorFramework.getChildren();
|
|
|
|
final List<String> children = childrenBuilder.watched().forPath(nodePath);
|
|
|
|
final List<String> children = childrenBuilder.watched().forPath(nodePath);
|
|
|
@ -97,10 +127,10 @@ public class ZookeeperRefresherHandler extends AbstractConfigThreadPoolDynamicRe
|
|
|
|
}
|
|
|
|
}
|
|
|
|
content.append(nodeName).append("=").append(value).append("\n");
|
|
|
|
content.append(nodeName).append("=").append(value).append("\n");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
dynamicRefresh(content.toString());
|
|
|
|
return content.toString();
|
|
|
|
registerNotifyAlarmManage();
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
log.error("Load zookeeper node error, nodePath is: {}", nodePath, ex);
|
|
|
|
log.error("Load zookeeper node error, nodePath is: {}", nodePath, ex);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|