未验证 提交 da696735 编写于 作者: J JiPeng Wang 提交者: GitHub

Merge pull request #82 from insist777/1111

[improvement] Add two parameters in workergroup, and support the appl…
package org.apache.dolphinscheduler.api.dto;
import org.apache.dolphinscheduler.dao.entity.WorkerGroup;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@Data
@AllArgsConstructor
public class WorkerGroupHandleDto {
private WorkerGroup workerGroup;
private String workerGroupName;
private Map<String, WorkerGroup> workerGroupsMap;
private Collection<String> childrenNodes;
private List<WorkerGroup> workerGroups;
}
...@@ -17,9 +17,9 @@ ...@@ -17,9 +17,9 @@
package org.apache.dolphinscheduler.api.service.impl; package org.apache.dolphinscheduler.api.service.impl;
import com.facebook.presto.jdbc.internal.guava.base.Strings;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.dolphinscheduler.api.dto.WorkerGroupHandleDto;
import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.service.WorkerGroupService; import org.apache.dolphinscheduler.api.service.WorkerGroupService;
import org.apache.dolphinscheduler.api.utils.PageInfo; import org.apache.dolphinscheduler.api.utils.PageInfo;
...@@ -50,6 +50,8 @@ import java.util.Map; ...@@ -50,6 +50,8 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.facebook.presto.jdbc.internal.guava.base.Strings;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKER_GROUP_CREATE; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKER_GROUP_CREATE;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKER_GROUP_DELETE; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKER_GROUP_DELETE;
...@@ -256,11 +258,6 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro ...@@ -256,11 +258,6 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro
List<String> availableWorkerGroupList = workerGroups.stream() List<String> availableWorkerGroupList = workerGroups.stream()
.map(WorkerGroup::getName) .map(WorkerGroup::getName)
.collect(Collectors.toList()); .collect(Collectors.toList());
int index = availableWorkerGroupList.indexOf(Constants.DEFAULT_WORKER_GROUP);
if (index > -1) {
availableWorkerGroupList.remove(index);
availableWorkerGroupList.add(0, Constants.DEFAULT_WORKER_GROUP);
}
result.put(Constants.DATA_LIST, availableWorkerGroupList); result.put(Constants.DATA_LIST, availableWorkerGroupList);
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
return result; return result;
...@@ -302,8 +299,8 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro ...@@ -302,8 +299,8 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro
if (workerGroups.size() != 0) { if (workerGroups.size() != 0) {
workerGroupsMap = workerGroups.stream().collect(Collectors.toMap(WorkerGroup::getName, workerGroupItem -> workerGroupItem, (oldWorkerGroup, newWorkerGroup) -> oldWorkerGroup)); workerGroupsMap = workerGroups.stream().collect(Collectors.toMap(WorkerGroup::getName, workerGroupItem -> workerGroupItem, (oldWorkerGroup, newWorkerGroup) -> oldWorkerGroup));
} }
for (String workerGroup : workerGroupList) { for (String workerGroupName : workerGroupList) {
String workerGroupPath = workerPath + Constants.SINGLE_SLASH + workerGroup; String workerGroupPath = workerPath + Constants.SINGLE_SLASH + workerGroupName;
Collection<String> childrenNodes = null; Collection<String> childrenNodes = null;
try { try {
childrenNodes = registryClient.getChildrenKeys(workerGroupPath); childrenNodes = registryClient.getChildrenKeys(workerGroupPath);
...@@ -313,27 +310,22 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro ...@@ -313,27 +310,22 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro
if (childrenNodes == null || childrenNodes.isEmpty()) { if (childrenNodes == null || childrenNodes.isEmpty()) {
continue; continue;
} }
WorkerGroup wg = new WorkerGroup(); WorkerGroup workerGroup = new WorkerGroup();
handleAddrList(wg, workerGroup, workerGroupsMap, childrenNodes); handleAddrList(new WorkerGroupHandleDto(workerGroup, workerGroupName, workerGroupsMap, childrenNodes, workerGroups));
wg.setName(workerGroup); workerGroup.setName(workerGroupName);
if (isPaging) { if (isPaging) {
String registeredValue = registryClient.get(workerGroupPath + Constants.SINGLE_SLASH + childrenNodes.iterator().next()); String registeredValue = registryClient.get(workerGroupPath + Constants.SINGLE_SLASH + childrenNodes.iterator().next());
String[] rv = registeredValue.split(Constants.COMMA); String[] rv = registeredValue.split(Constants.COMMA);
wg.setCreateTime(new Date(Long.parseLong(rv[6]))); workerGroup.setCreateTime(new Date(Long.parseLong(rv[6])));
wg.setUpdateTime(new Date(Long.parseLong(rv[7]))); workerGroup.setUpdateTime(new Date(Long.parseLong(rv[7])));
wg.setSystemDefault(true); workerGroup.setSystemDefault(true);
if (workerGroupsMap != null && workerGroupsMap.containsKey(workerGroup)) {
wg.setDescription(workerGroupsMap.get(workerGroup).getDescription());
workerGroups.remove(workerGroupsMap.get(workerGroup));
}
} }
workerGroups.add(wg); workerGroups.add(workerGroup);
} }
return workerGroups; return workerGroups;
} }
protected void handleAddrList(WorkerGroupHandleDto obj) {
protected void handleAddrList(WorkerGroup wg, String workerGroup, Map<String, WorkerGroup> workerGroupsMap, Collection<String> childrenNodes) { obj.getWorkerGroup().setAddrList(String.join(Constants.COMMA, obj.getChildrenNodes()));
wg.setAddrList(String.join(Constants.COMMA, childrenNodes));
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册