Browse Source

Simplify constants variables (#6183)

* Combine `alter` and `registry` properties,
  bese on https://github.com/apache/dolphinscheduler/pull/6180
* Remove duplicate variable `SLASH` and `SINGLE_SLASH`
2.0.7-release
Jiajie Zhong 3 years ago committed by GitHub
parent
commit
170280fab2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java
  2. 74
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java
  3. 4
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/registry/WorkerRegistryClient.java
  4. 10
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/registry/RegistryClient.java

6
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java

@ -138,7 +138,7 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro
} }
} }
// check zookeeper // check zookeeper
String workerGroupPath = Constants.REGISTRY_DOLPHINSCHEDULER_WORKERS + Constants.SLASH + workerGroup.getName(); String workerGroupPath = Constants.REGISTRY_DOLPHINSCHEDULER_WORKERS + Constants.SINGLE_SLASH + workerGroup.getName();
return RegistryCenterUtils.isNodeExisted(workerGroupPath); return RegistryCenterUtils.isNodeExisted(workerGroupPath);
} }
@ -266,7 +266,7 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro
} }
for (String workerGroup : workerGroupList) { for (String workerGroup : workerGroupList) {
String workerGroupPath = workerPath + Constants.SLASH + workerGroup; String workerGroupPath = workerPath + Constants.SINGLE_SLASH + workerGroup;
List<String> childrenNodes = null; List<String> childrenNodes = null;
try { try {
childrenNodes = RegistryCenterUtils.getChildrenNodes(workerGroupPath); childrenNodes = RegistryCenterUtils.getChildrenNodes(workerGroupPath);
@ -280,7 +280,7 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro
wg.setName(workerGroup); wg.setName(workerGroup);
if (isPaging) { if (isPaging) {
wg.setAddrList(String.join(Constants.COMMA, childrenNodes)); wg.setAddrList(String.join(Constants.COMMA, childrenNodes));
String registeredValue = RegistryCenterUtils.getNodeData(workerGroupPath + Constants.SLASH + childrenNodes.get(0)); String registeredValue = RegistryCenterUtils.getNodeData(workerGroupPath + Constants.SINGLE_SLASH + childrenNodes.get(0));
wg.setCreateTime(DateUtils.stringToDate(registeredValue.split(Constants.COMMA)[6])); wg.setCreateTime(DateUtils.stringToDate(registeredValue.split(Constants.COMMA)[6]));
wg.setUpdateTime(DateUtils.stringToDate(registeredValue.split(Constants.COMMA)[7])); wg.setUpdateTime(DateUtils.stringToDate(registeredValue.split(Constants.COMMA)[7]));
wg.setSystemDefault(true); wg.setSystemDefault(true);

74
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java

@ -72,6 +72,28 @@ public final class Constants {
*/ */
public static final String COMMON_PROPERTIES_PATH = "/common.properties"; public static final String COMMON_PROPERTIES_PATH = "/common.properties";
/**
* alter properties
*/
public static final String ALERT_PLUGIN_BINDING = "alert.plugin.binding";
public static final String ALERT_PLUGIN_DIR = "alert.plugin.dir";
public static final int ALERT_RPC_PORT = 50052;
/**
* registry properties
*/
public static final String REGISTRY_DOLPHINSCHEDULER_MASTERS = "/nodes/master";
public static final String REGISTRY_DOLPHINSCHEDULER_WORKERS = "/nodes/worker";
public static final String REGISTRY_DOLPHINSCHEDULER_DEAD_SERVERS = "/dead-servers";
public static final String REGISTRY_DOLPHINSCHEDULER_NODE = "/nodes";
public static final String REGISTRY_DOLPHINSCHEDULER_LOCK_MASTERS = "/lock/masters";
public static final String REGISTRY_DOLPHINSCHEDULER_LOCK_FAILOVER_MASTERS = "/lock/failover/masters";
public static final String REGISTRY_DOLPHINSCHEDULER_LOCK_FAILOVER_WORKERS = "/lock/failover/workers";
public static final String REGISTRY_DOLPHINSCHEDULER_LOCK_FAILOVER_STARTUP_MASTERS = "/lock/failover/startup-masters";
public static final String REGISTRY_PLUGIN_BINDING = "registry.plugin.binding";
public static final String REGISTRY_PLUGIN_DIR = "registry.plugin.dir";
public static final String REGISTRY_SERVERS = "registry.servers";
/** /**
* fs.defaultFS * fs.defaultFS
*/ */
@ -183,58 +205,11 @@ public final class Constants {
*/ */
public static final String RESOURCE_STORAGE_TYPE = "resource.storage.type"; public static final String RESOURCE_STORAGE_TYPE = "resource.storage.type";
/**
* MasterServer directory registered in zookeeper
*/
public static final String REGISTRY_DOLPHINSCHEDULER_MASTERS = "/nodes/master";
/**
* WorkerServer directory registered in zookeeper
*/
public static final String REGISTRY_DOLPHINSCHEDULER_WORKERS = "/nodes/worker";
/**
* all servers directory registered in zookeeper
*/
public static final String REGISTRY_DOLPHINSCHEDULER_DEAD_SERVERS = "/dead-servers";
/**
* registry node prefix
*/
public static final String REGISTRY_DOLPHINSCHEDULER_NODE = "/nodes";
/**
* MasterServer lock directory registered in zookeeper
*/
public static final String REGISTRY_DOLPHINSCHEDULER_LOCK_MASTERS = "/lock/masters";
/**
* MasterServer failover directory registered in zookeeper
*/
public static final String REGISTRY_DOLPHINSCHEDULER_LOCK_FAILOVER_MASTERS = "/lock/failover/masters";
/**
* WorkerServer failover directory registered in zookeeper
*/
public static final String REGISTRY_DOLPHINSCHEDULER_LOCK_FAILOVER_WORKERS = "/lock/failover/workers";
/**
* MasterServer startup failover runing and fault tolerance process
*/
public static final String REGISTRY_DOLPHINSCHEDULER_LOCK_FAILOVER_STARTUP_MASTERS = "/lock/failover/startup-masters";
/** /**
* comma , * comma ,
*/ */
public static final String COMMA = ","; public static final String COMMA = ",";
/**
* slash /
*/
public static final String SLASH = "/";
/** /**
* COLON : * COLON :
*/ */
@ -416,11 +391,6 @@ public final class Constants {
*/ */
public static final int RPC_PORT = 50051; public static final int RPC_PORT = 50051;
/***
* alert rpc port
*/
public static final int ALERT_RPC_PORT = 50052;
/** /**
* forbid running task * forbid running task
*/ */

4
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/registry/WorkerRegistryClient.java

@ -19,7 +19,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.DEFAULT_WORKER_GROUP;
import static org.apache.dolphinscheduler.common.Constants.REGISTRY_DOLPHINSCHEDULER_WORKERS; import static org.apache.dolphinscheduler.common.Constants.REGISTRY_DOLPHINSCHEDULER_WORKERS;
import static org.apache.dolphinscheduler.common.Constants.SLASH; import static org.apache.dolphinscheduler.common.Constants.SINGLE_SLASH;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.IStoppable; import org.apache.dolphinscheduler.common.IStoppable;
@ -134,7 +134,7 @@ public class WorkerRegistryClient {
String workerZkPathPrefix = REGISTRY_DOLPHINSCHEDULER_WORKERS; String workerZkPathPrefix = REGISTRY_DOLPHINSCHEDULER_WORKERS;
for (String workGroup : this.workerGroups) { for (String workGroup : this.workerGroups) {
StringJoiner workerPathJoiner = new StringJoiner(SLASH); StringJoiner workerPathJoiner = new StringJoiner(SINGLE_SLASH);
workerPathJoiner.add(workerZkPathPrefix); workerPathJoiner.add(workerZkPathPrefix);
if (StringUtils.isEmpty(workGroup)) { if (StringUtils.isEmpty(workGroup)) {
workGroup = DEFAULT_WORKER_GROUP; workGroup = DEFAULT_WORKER_GROUP;

10
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/registry/RegistryClient.java

@ -122,9 +122,9 @@ public class RegistryClient extends RegistryCenter {
if (nodeType == NodeType.WORKER) { if (nodeType == NodeType.WORKER) {
List<String> workerList = new ArrayList<>(); List<String> workerList = new ArrayList<>();
for (String group : serverList) { for (String group : serverList) {
List<String> groupServers = getChildrenKeys(path + Constants.SLASH + group); List<String> groupServers = getChildrenKeys(path + SINGLE_SLASH + group);
for (String groupServer : groupServers) { for (String groupServer : groupServers) {
workerList.add(group + Constants.SLASH + groupServer); workerList.add(group + SINGLE_SLASH + groupServer);
} }
} }
serverList = workerList; serverList = workerList;
@ -147,9 +147,9 @@ public class RegistryClient extends RegistryCenter {
for (String server : serverList) { for (String server : serverList) {
String host = server; String host = server;
if (nodeType == NodeType.WORKER && hostOnly) { if (nodeType == NodeType.WORKER && hostOnly) {
host = server.split(Constants.SLASH)[1]; host = server.split(SINGLE_SLASH)[1];
} }
serverMap.putIfAbsent(host, get(path + Constants.SLASH + server)); serverMap.putIfAbsent(host, get(path + SINGLE_SLASH + server));
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("get server list failed", e); logger.error("get server list failed", e);
@ -182,7 +182,7 @@ public class RegistryClient extends RegistryCenter {
for (String server : serverList) { for (String server : serverList) {
String host = server; String host = server;
if (nodeType == NodeType.WORKER && hostOnly) { if (nodeType == NodeType.WORKER && hostOnly) {
host = server.split(Constants.SLASH)[1]; host = server.split(SINGLE_SLASH)[1];
} }
serverSet.add(host); serverSet.add(host);
} }

Loading…
Cancel
Save