From 8112f5bcb5c27a2b48fbfff2fe9a5c6595b0273d Mon Sep 17 00:00:00 2001 From: Shiwen Cheng Date: Fri, 5 Mar 2021 21:34:54 +0800 Subject: [PATCH] [Fix][API] Fix KeeperException (#4961) fix #4705 --- .../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 2f899ed1b7..7ce6a74d6b 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 getWorkerGroups(boolean isPaging) { - String workerPath = zookeeperCachedOperator.getZookeeperConfig().getDsRoot() + Constants.ZOOKEEPER_DOLPHINSCHEDULER_WORKERS; List workerGroups = new ArrayList<>(); - List workerGroupList; + List 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 db9bb4fb00..bc95ad1e31 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 result = workerGroupService.queryAllGroup(); Set workerGroups = (Set) result.get(Constants.DATA_LIST); Assert.assertEquals(1, workerGroups.size());