This is an automated email from the ASF dual-hosted git repository.
kirs pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new 8112f5b [Fix][API] Fix KeeperException (#4961)
8112f5b is described below
commit 8112f5bcb5c27a2b48fbfff2fe9a5c6595b0273d
Author: Shiwen Cheng <[email protected]>
AuthorDate: Fri Mar 5 21:34:54 2021 +0800
[Fix][API] Fix KeeperException (#4961)
fix #4705
---
.../api/service/impl/WorkerGroupServiceImpl.java | 21 +++++++++------------
.../api/service/WorkerGroupServiceTest.java | 4 +---
2 files changed, 10 insertions(+), 15 deletions(-)
diff --git
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java
index 2f899ed..7ce6a74 100644
---
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java
+++
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java
@@ -40,6 +40,8 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -50,7 +52,7 @@ import org.springframework.stereotype.Service;
@Service
public class WorkerGroupServiceImpl extends BaseServiceImpl implements
WorkerGroupService {
- private static final String NO_NODE_EXCEPTION_REGEX =
"KeeperException$NoNodeException";
+ private static final Logger logger =
LoggerFactory.getLogger(WorkerGroupServiceImpl.class);
@Autowired
protected ZookeeperCachedOperator zookeeperCachedOperator;
@@ -137,27 +139,22 @@ public class WorkerGroupServiceImpl extends
BaseServiceImpl implements WorkerGro
* @return WorkerGroup list
*/
private List<WorkerGroup> getWorkerGroups(boolean isPaging) {
-
String workerPath =
zookeeperCachedOperator.getZookeeperConfig().getDsRoot() +
Constants.ZOOKEEPER_DOLPHINSCHEDULER_WORKERS;
List<WorkerGroup> workerGroups = new ArrayList<>();
- List<String> workerGroupList;
+ List<String> workerGroupList = null;
try {
workerGroupList =
zookeeperCachedOperator.getChildrenKeys(workerPath);
} catch (Exception e) {
- if (e.getMessage().contains(NO_NODE_EXCEPTION_REGEX)) {
- if (isPaging) {
- return workerGroups;
- }
+ logger.error("getWorkerGroups exception: {}, workerPath: {},
isPaging: {}", e.getMessage(), workerPath, isPaging);
+ }
- //ignore noNodeException return Default
+ if (workerGroupList == null || workerGroupList.isEmpty()) {
+ if (!isPaging) {
WorkerGroup wg = new WorkerGroup();
wg.setName(DEFAULT_WORKER_GROUP);
workerGroups.add(wg);
- return workerGroups;
-
- } else {
- throw e;
}
+ return workerGroups;
}
for (String workerGroup : workerGroupList) {
diff --git
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkerGroupServiceTest.java
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkerGroupServiceTest.java
index db9bb4f..bc95ad1 100644
---
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkerGroupServiceTest.java
+++
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkerGroupServiceTest.java
@@ -110,9 +110,7 @@ public class WorkerGroupServiceTest {
}
@Test
- public void testQueryAllGroupWithNoNodeException() {
- String workerPath =
zookeeperCachedOperator.getZookeeperConfig().getDsRoot() +
Constants.ZOOKEEPER_DOLPHINSCHEDULER_WORKERS;
-
Mockito.when(zookeeperCachedOperator.getChildrenKeys(workerPath)).thenThrow(new
RuntimeException("KeeperException$NoNodeException"));
+ public void testQueryAllGroupWithDefault() {
Map<String, Object> result = workerGroupService.queryAllGroup();
Set<String> workerGroups = (Set<String>)
result.get(Constants.DATA_LIST);
Assert.assertEquals(1, workerGroups.size());