diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/registry/MasterRegistryClient.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/registry/MasterRegistryClient.java index 3a2e3044ec..1286818d8b 100644 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/registry/MasterRegistryClient.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/registry/MasterRegistryClient.java @@ -17,6 +17,7 @@ package org.apache.dolphinscheduler.server.master.registry; +import static org.apache.dolphinscheduler.common.Constants.REGISTRY_DOLPHINSCHEDULER_MASTERS; import static org.apache.dolphinscheduler.common.Constants.REGISTRY_DOLPHINSCHEDULER_NODE; import static org.apache.dolphinscheduler.common.Constants.SLEEP_TIME_MILLIS; @@ -134,18 +135,6 @@ public class MasterRegistryClient { unRegistry(); } - /** - * init system node - */ - private void initMasterSystemNode() { - try { - registryClient.persist(Constants.REGISTRY_DOLPHINSCHEDULER_DEAD_SERVERS, ""); - logger.info("initialize master server nodes success."); - } catch (Exception e) { - logger.error("init system node failed", e); - } - } - /** * remove zookeeper node path * @@ -346,7 +335,6 @@ public class MasterRegistryClient { * registry */ public void registry() { - initMasterSystemNode(); String address = NetUtils.getAddr(masterConfig.getListenPort()); localNodePath = getMasterPath(); registryClient.persistEphemeral(localNodePath, ""); @@ -395,7 +383,7 @@ public class MasterRegistryClient { */ public String getMasterPath() { String address = getLocalAddress(); - return registryClient.getMasterPath() + "/" + address; + return REGISTRY_DOLPHINSCHEDULER_MASTERS + "/" + address; } /** diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/registry/ServerNodeManager.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/registry/ServerNodeManager.java index 0162af6bac..6a9167e751 100644 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/registry/ServerNodeManager.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/registry/ServerNodeManager.java @@ -17,6 +17,9 @@ package org.apache.dolphinscheduler.server.master.registry; +import static org.apache.dolphinscheduler.common.Constants.REGISTRY_DOLPHINSCHEDULER_MASTERS; +import static org.apache.dolphinscheduler.common.Constants.REGISTRY_DOLPHINSCHEDULER_WORKERS; + import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.enums.NodeType; import org.apache.dolphinscheduler.common.utils.StringUtils; @@ -131,11 +134,11 @@ public class ServerNodeManager implements InitializingBean { /** * init MasterNodeListener listener */ - registryClient.subscribe(registryClient.getMasterPath(), new MasterDataListener()); + registryClient.subscribe(REGISTRY_DOLPHINSCHEDULER_MASTERS, new MasterDataListener()); /** * init WorkerNodeListener listener */ - registryClient.subscribe(registryClient.getWorkerPath(), new MasterDataListener()); + registryClient.subscribe(REGISTRY_DOLPHINSCHEDULER_WORKERS, new MasterDataListener()); } /** diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/registry/WorkerRegistryClient.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/registry/WorkerRegistryClient.java index 4db4d17533..3b0dedb99d 100644 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/registry/WorkerRegistryClient.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/registry/WorkerRegistryClient.java @@ -18,6 +18,7 @@ package org.apache.dolphinscheduler.server.worker.registry; import static org.apache.dolphinscheduler.common.Constants.DEFAULT_WORKER_GROUP; +import static org.apache.dolphinscheduler.common.Constants.REGISTRY_DOLPHINSCHEDULER_WORKERS; import static org.apache.dolphinscheduler.common.Constants.SLASH; import org.apache.dolphinscheduler.common.Constants; @@ -130,7 +131,7 @@ public class WorkerRegistryClient { public Set getWorkerZkPaths() { Set workerPaths = Sets.newHashSet(); String address = getLocalAddress(); - String workerZkPathPrefix = registryClient.getWorkerPath(); + String workerZkPathPrefix = REGISTRY_DOLPHINSCHEDULER_WORKERS; for (String workGroup : this.workerGroups) { StringJoiner workerPathJoiner = new StringJoiner(SLASH); diff --git a/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/registry/WorkerRegistryClientTest.java b/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/registry/WorkerRegistryClientTest.java index b3517d3cd4..bbc131dc95 100644 --- a/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/registry/WorkerRegistryClientTest.java +++ b/dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/worker/registry/WorkerRegistryClientTest.java @@ -71,8 +71,6 @@ public class WorkerRegistryClientTest { @Before public void before() { - - given(registryClient.getWorkerPath()).willReturn("/nodes/worker"); given(workerConfig.getWorkerGroups()).willReturn(Sets.newHashSet("127.0.0.1")); //given(heartBeatExecutor.getWorkerGroups()).willReturn(Sets.newHashSet("127.0.0.1")); //scheduleAtFixedRate diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/registry/RegistryCenter.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/registry/RegistryCenter.java index 143821fe41..119a60ad58 100644 --- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/registry/RegistryCenter.java +++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/registry/RegistryCenter.java @@ -18,6 +18,8 @@ package org.apache.dolphinscheduler.service.registry; import static org.apache.dolphinscheduler.common.Constants.REGISTRY_DOLPHINSCHEDULER_DEAD_SERVERS; +import static org.apache.dolphinscheduler.common.Constants.REGISTRY_DOLPHINSCHEDULER_MASTERS; +import static org.apache.dolphinscheduler.common.Constants.REGISTRY_DOLPHINSCHEDULER_WORKERS; import org.apache.dolphinscheduler.common.IStoppable; import org.apache.dolphinscheduler.common.utils.PropertyUtils; @@ -57,16 +59,7 @@ public class RegistryCenter { */ protected static String NODES; - /** - * master path - */ - protected static String MASTER_PATH = "/nodes/master"; - private RegistryPluginManager registryPluginManager; - /** - * worker path - */ - protected static String WORKER_PATH = "/nodes/worker"; protected static final String EMPTY = ""; @@ -113,8 +106,9 @@ public class RegistryCenter { * init nodes */ private void initNodes() { - persist(MASTER_PATH, EMPTY); - persist(WORKER_PATH, EMPTY); + persist(REGISTRY_DOLPHINSCHEDULER_MASTERS, EMPTY); + persist(REGISTRY_DOLPHINSCHEDULER_WORKERS, EMPTY); + persist(REGISTRY_DOLPHINSCHEDULER_DEAD_SERVERS, EMPTY); } /** @@ -205,15 +199,6 @@ public class RegistryCenter { return stoppable; } - /** - * get master path - * - * @return master path - */ - public String getMasterPath() { - return MASTER_PATH; - } - /** * whether master path * @@ -221,16 +206,7 @@ public class RegistryCenter { * @return result */ public boolean isMasterPath(String path) { - return path != null && path.contains(MASTER_PATH); - } - - /** - * get worker path - * - * @return worker path - */ - public String getWorkerPath() { - return WORKER_PATH; + return path != null && path.contains(REGISTRY_DOLPHINSCHEDULER_MASTERS); } /** @@ -240,7 +216,7 @@ public class RegistryCenter { * @return worker group path */ public String getWorkerGroupPath(String workerGroup) { - return WORKER_PATH + "/" + workerGroup; + return REGISTRY_DOLPHINSCHEDULER_WORKERS + "/" + workerGroup; } /** @@ -250,7 +226,7 @@ public class RegistryCenter { * @return result */ public boolean isWorkerPath(String path) { - return path != null && path.contains(WORKER_PATH); + return path != null && path.contains(REGISTRY_DOLPHINSCHEDULER_WORKERS); } /** diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/registry/RegistryClient.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/registry/RegistryClient.java index d7afcd9000..d9ebf18492 100644 --- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/registry/RegistryClient.java +++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/registry/RegistryClient.java @@ -22,6 +22,8 @@ import static org.apache.dolphinscheduler.common.Constants.COLON; import static org.apache.dolphinscheduler.common.Constants.DELETE_OP; import static org.apache.dolphinscheduler.common.Constants.DIVISION_STRING; import static org.apache.dolphinscheduler.common.Constants.MASTER_TYPE; +import static org.apache.dolphinscheduler.common.Constants.REGISTRY_DOLPHINSCHEDULER_MASTERS; +import static org.apache.dolphinscheduler.common.Constants.REGISTRY_DOLPHINSCHEDULER_WORKERS; import static org.apache.dolphinscheduler.common.Constants.SINGLE_SLASH; import static org.apache.dolphinscheduler.common.Constants.UNDERLINE; import static org.apache.dolphinscheduler.common.Constants.WORKER_TYPE; @@ -344,7 +346,7 @@ public class RegistryClient extends RegistryCenter { * @return master nodes */ public Set getMasterNodesDirectly() { - List masters = getChildrenKeys(MASTER_PATH); + List masters = getChildrenKeys(REGISTRY_DOLPHINSCHEDULER_MASTERS); return new HashSet<>(masters); } @@ -354,7 +356,7 @@ public class RegistryClient extends RegistryCenter { * @return master nodes */ public Set getWorkerNodesDirectly() { - List workers = getChildrenKeys(WORKER_PATH); + List workers = getChildrenKeys(REGISTRY_DOLPHINSCHEDULER_WORKERS); return new HashSet<>(workers); } @@ -364,7 +366,7 @@ public class RegistryClient extends RegistryCenter { * @return worker group nodes */ public Set getWorkerGroupDirectly() { - List workers = getChildrenKeys(getWorkerPath()); + List workers = getChildrenKeys(REGISTRY_DOLPHINSCHEDULER_WORKERS); return new HashSet<>(workers); }