Browse Source

[Fix][API] Fix KeeperException (#4961)

fix #4705
pull/3/MERGE
Shiwen Cheng 4 years ago committed by GitHub
parent
commit
8112f5bcb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java
  2. 4
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkerGroupServiceTest.java

21
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.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -50,7 +52,7 @@ import org.springframework.stereotype.Service;
@Service @Service
public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGroupService { 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 @Autowired
protected ZookeeperCachedOperator zookeeperCachedOperator; protected ZookeeperCachedOperator zookeeperCachedOperator;
@ -137,27 +139,22 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro
* @return WorkerGroup list * @return WorkerGroup list
*/ */
private List<WorkerGroup> getWorkerGroups(boolean isPaging) { private List<WorkerGroup> getWorkerGroups(boolean isPaging) {
String workerPath = zookeeperCachedOperator.getZookeeperConfig().getDsRoot() + Constants.ZOOKEEPER_DOLPHINSCHEDULER_WORKERS; String workerPath = zookeeperCachedOperator.getZookeeperConfig().getDsRoot() + Constants.ZOOKEEPER_DOLPHINSCHEDULER_WORKERS;
List<WorkerGroup> workerGroups = new ArrayList<>(); List<WorkerGroup> workerGroups = new ArrayList<>();
List<String> workerGroupList; List<String> workerGroupList = null;
try { try {
workerGroupList = zookeeperCachedOperator.getChildrenKeys(workerPath); workerGroupList = zookeeperCachedOperator.getChildrenKeys(workerPath);
} catch (Exception e) { } catch (Exception e) {
if (e.getMessage().contains(NO_NODE_EXCEPTION_REGEX)) { logger.error("getWorkerGroups exception: {}, workerPath: {}, isPaging: {}", e.getMessage(), workerPath, isPaging);
if (isPaging) { }
return workerGroups;
}
//ignore noNodeException return Default if (workerGroupList == null || workerGroupList.isEmpty()) {
if (!isPaging) {
WorkerGroup wg = new WorkerGroup(); WorkerGroup wg = new WorkerGroup();
wg.setName(DEFAULT_WORKER_GROUP); wg.setName(DEFAULT_WORKER_GROUP);
workerGroups.add(wg); workerGroups.add(wg);
return workerGroups;
} else {
throw e;
} }
return workerGroups;
} }
for (String workerGroup : workerGroupList) { for (String workerGroup : workerGroupList) {

4
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkerGroupServiceTest.java

@ -110,9 +110,7 @@ public class WorkerGroupServiceTest {
} }
@Test @Test
public void testQueryAllGroupWithNoNodeException() { public void testQueryAllGroupWithDefault() {
String workerPath = zookeeperCachedOperator.getZookeeperConfig().getDsRoot() + Constants.ZOOKEEPER_DOLPHINSCHEDULER_WORKERS;
Mockito.when(zookeeperCachedOperator.getChildrenKeys(workerPath)).thenThrow(new RuntimeException("KeeperException$NoNodeException"));
Map<String, Object> result = workerGroupService.queryAllGroup(); Map<String, Object> result = workerGroupService.queryAllGroup();
Set<String> workerGroups = (Set<String>) result.get(Constants.DATA_LIST); Set<String> workerGroups = (Set<String>) result.get(Constants.DATA_LIST);
Assert.assertEquals(1, workerGroups.size()); Assert.assertEquals(1, workerGroups.size());

Loading…
Cancel
Save