From 5213290262117d78dcd8936dd28eec2002a3e538 Mon Sep 17 00:00:00 2001 From: calvin Date: Tue, 20 Feb 2024 17:20:00 +0800 Subject: [PATCH] [Feature-14863][API] Support to manage what worker groups can be used for a project. (#15600) --- .../ProjectWorkerGroupController.java | 104 ++++++++ .../api/controller/WorkerGroupController.java | 1 - .../dolphinscheduler/api/enums/Status.java | 9 + .../ProjectWorkerGroupRelationService.java | 48 ++++ ...ProjectWorkerGroupRelationServiceImpl.java | 233 ++++++++++++++++++ ...ProjectWorkerGroupRelationServiceTest.java | 161 ++++++++++++ .../dao/entity/ProjectWorkerGroup.java | 56 +++++ .../dao/mapper/ProjectWorkerGroupMapper.java | 26 ++ .../resources/sql/dolphinscheduler_h2.sql | 15 ++ .../resources/sql/dolphinscheduler_mysql.sql | 17 ++ .../sql/dolphinscheduler_postgresql.sql | 19 ++ .../mysql/dolphinscheduler_ddl.sql | 11 + .../postgresql/dolphinscheduler_ddl.sql | 14 ++ .../mapper/ProjectWorkerGroupMapperTest.java | 113 +++++++++ .../src/locales/en_US/project.ts | 3 +- .../src/locales/zh_CN/project.ts | 3 +- .../modules/projects-worker-group/index.ts | 39 +++ .../modules/projects-worker-group/types.ts | 34 +++ .../service/modules/worker-groups/index.ts | 2 +- .../list/components/use-worker-group.ts | 77 ++++++ .../list/components/worker-group-modal.tsx | 91 +++++++ .../src/views/projects/list/index.tsx | 18 ++ .../src/views/projects/list/use-table.ts | 44 +++- .../src/views/projects/preference/use-form.ts | 2 +- .../node/fields/use-worker-group.ts | 9 +- .../task/components/node/tasks/use-chunjun.ts | 2 +- .../components/node/tasks/use-conditions.ts | 2 +- .../components/node/tasks/use-data-factory.ts | 2 +- .../components/node/tasks/use-data-quality.ts | 2 +- .../components/node/tasks/use-datasync.ts | 2 +- .../task/components/node/tasks/use-datax.ts | 2 +- .../components/node/tasks/use-dependent.ts | 2 +- .../task/components/node/tasks/use-dinky.ts | 2 +- .../task/components/node/tasks/use-dms.ts | 2 +- .../task/components/node/tasks/use-dvc.ts | 2 +- .../task/components/node/tasks/use-dynamic.ts | 2 +- .../task/components/node/tasks/use-emr.ts | 2 +- .../components/node/tasks/use-flink-stream.ts | 2 +- .../task/components/node/tasks/use-flink.ts | 2 +- .../components/node/tasks/use-hive-cli.ts | 2 +- .../task/components/node/tasks/use-http.ts | 2 +- .../task/components/node/tasks/use-java.ts | 2 +- .../task/components/node/tasks/use-jupyter.ts | 2 +- .../task/components/node/tasks/use-k8s.ts | 2 +- .../components/node/tasks/use-kubeflow.ts | 2 +- .../task/components/node/tasks/use-linkis.ts | 2 +- .../task/components/node/tasks/use-mlflow.ts | 2 +- .../task/components/node/tasks/use-mr.ts | 2 +- .../components/node/tasks/use-openmldb.ts | 2 +- .../task/components/node/tasks/use-pigeon.ts | 2 +- .../components/node/tasks/use-procedure.ts | 2 +- .../task/components/node/tasks/use-python.ts | 2 +- .../task/components/node/tasks/use-pytorch.ts | 2 +- .../components/node/tasks/use-remote-shell.ts | 2 +- .../components/node/tasks/use-sagemaker.ts | 2 +- .../components/node/tasks/use-sea-tunnel.ts | 2 +- .../task/components/node/tasks/use-shell.ts | 2 +- .../task/components/node/tasks/use-spark.ts | 2 +- .../task/components/node/tasks/use-sql.ts | 2 +- .../task/components/node/tasks/use-sqoop.ts | 2 +- .../components/node/tasks/use-sub-process.ts | 2 +- .../task/components/node/tasks/use-switch.ts | 2 +- .../components/node/tasks/use-zeppelin.ts | 2 +- .../definition/components/use-modal.ts | 9 +- 64 files changed, 1178 insertions(+), 56 deletions(-) create mode 100644 dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectWorkerGroupController.java create mode 100644 dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectWorkerGroupRelationService.java create mode 100644 dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectWorkerGroupRelationServiceImpl.java create mode 100644 dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectWorkerGroupRelationServiceTest.java create mode 100644 dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProjectWorkerGroup.java create mode 100644 dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectWorkerGroupMapper.java create mode 100644 dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectWorkerGroupMapperTest.java create mode 100644 dolphinscheduler-ui/src/service/modules/projects-worker-group/index.ts create mode 100644 dolphinscheduler-ui/src/service/modules/projects-worker-group/types.ts create mode 100644 dolphinscheduler-ui/src/views/projects/list/components/use-worker-group.ts create mode 100644 dolphinscheduler-ui/src/views/projects/list/components/worker-group-modal.tsx diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectWorkerGroupController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectWorkerGroupController.java new file mode 100644 index 0000000000..a9ac074798 --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectWorkerGroupController.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.api.controller; + +import static org.apache.dolphinscheduler.api.enums.Status.ASSIGN_WORKER_GROUP_TO_PROJECT_ERROR; + +import org.apache.dolphinscheduler.api.exceptions.ApiException; +import org.apache.dolphinscheduler.api.service.ProjectWorkerGroupRelationService; +import org.apache.dolphinscheduler.api.utils.Result; +import org.apache.dolphinscheduler.common.constants.Constants; +import org.apache.dolphinscheduler.dao.entity.User; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import lombok.extern.slf4j.Slf4j; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.tags.Tag; + +/** + * project and worker group controller + */ +@Tag(name = "PROJECT_WORKER_GROUP_TAG") +@RestController +@RequestMapping("projects/{projectCode}/worker-group") +@Slf4j +public class ProjectWorkerGroupController extends BaseController { + + @Autowired + private ProjectWorkerGroupRelationService projectWorkerGroupRelationService; + + /** + * assign worker groups to the project + * + * @param loginUser login user + * @param projectCode project code + @ @RequestParam(value = "workerGroups", required = false) String workerGroups + * @return create result code + */ + @Operation(summary = "assignWorkerGroups", description = "CREATE_PROCESS_DEFINITION_NOTES") + @Parameters({ + @Parameter(name = "projectCode", description = "PROJECT_CODE", schema = @Schema(implementation = long.class, example = "123456")), + @Parameter(name = "workerGroups", description = "WORKER_GROUP_LIST", schema = @Schema(implementation = List.class)) + }) + @PostMapping() + @ResponseStatus(HttpStatus.CREATED) + @ApiException(ASSIGN_WORKER_GROUP_TO_PROJECT_ERROR) + public Result assignWorkerGroups(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, + @Parameter(name = "workerGroups") String[] workerGroups) { + + List workerGroupList = Arrays.stream(workerGroups).collect(Collectors.toList()); + return projectWorkerGroupRelationService.assignWorkerGroupsToProject(loginUser, projectCode, workerGroupList); + } + + /** + * query worker groups that assigned to the project + * + * @param projectCode project code + * @return worker group list + */ + @Operation(summary = "queryWorkerGroups", description = "QUERY_WORKER_GROUP_LIST") + @Parameters({ + @Parameter(name = "projectCode", description = "PROJECT_CODE", schema = @Schema(implementation = long.class, example = "123456")) + }) + @GetMapping() + @ResponseStatus(HttpStatus.OK) + public Map queryWorkerGroups(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode) { + return projectWorkerGroupRelationService.queryWorkerGroupsByProject(loginUser, projectCode); + } + +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkerGroupController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkerGroupController.java index 6b91f7c0ee..8c332a7bbb 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkerGroupController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkerGroupController.java @@ -167,5 +167,4 @@ public class WorkerGroupController extends BaseController { Map result = workerGroupService.getWorkerAddressList(); return returnDataList(result); } - } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java index f84f79847c..113ccb6bd1 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java @@ -585,6 +585,15 @@ public enum Status { WORKER_GROUP_DEPENDENT_ENVIRONMENT_EXISTS(1401002, "You can not modify or remove this worker group, cause it has [{0}] dependent environments.", "不能修改或删除该Worker组,有 [{0}] 个环境配置正在使用"), + + WORKER_GROUP_NOT_EXIST(1402001, "The Worker group [{0}] not exists", "Worker组[{0}]不存在."), + ASSIGN_WORKER_GROUP_TO_PROJECT_ERROR(1402002, "Failed to assign these worker groups to the project", + "给项目分配工作组失败"), + WORKER_GROUP_TO_PROJECT_IS_EMPTY(1402003, "Need to assign at least one worker group to the project", + "需要给项目至少分配一个Worker组"), + USED_WORKER_GROUP_EXISTS(1402004, + "You can not reassign worker groups to the project, cause these worker groups {0} are already used.", + "Worker组{0}被项目中任务或定时引用,无法重新分配"), ; private final int code; private final String enMsg; diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectWorkerGroupRelationService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectWorkerGroupRelationService.java new file mode 100644 index 0000000000..5b809f8d61 --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectWorkerGroupRelationService.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.api.service; + +import org.apache.dolphinscheduler.api.utils.Result; +import org.apache.dolphinscheduler.dao.entity.User; + +import java.util.List; +import java.util.Map; + +/** + * the service of project and worker group + */ +public interface ProjectWorkerGroupRelationService { + + /** + * assign worker groups to a project + * + * @param loginUser the login user + * @param projectCode the project code + * @param workerGroups assigned worker group names + */ + Result assignWorkerGroupsToProject(User loginUser, Long projectCode, List workerGroups); + + /** + * query worker groups that assigned to the project + * + * @param loginUser the login user + * @param projectCode project code + */ + Map queryWorkerGroupsByProject(User loginUser, Long projectCode); + +} diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectWorkerGroupRelationServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectWorkerGroupRelationServiceImpl.java new file mode 100644 index 0000000000..15cbcbb7fa --- /dev/null +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectWorkerGroupRelationServiceImpl.java @@ -0,0 +1,233 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.api.service.impl; + +import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.exceptions.ServiceException; +import org.apache.dolphinscheduler.api.service.ProjectService; +import org.apache.dolphinscheduler.api.service.ProjectWorkerGroupRelationService; +import org.apache.dolphinscheduler.api.utils.Result; +import org.apache.dolphinscheduler.common.constants.Constants; +import org.apache.dolphinscheduler.dao.entity.Project; +import org.apache.dolphinscheduler.dao.entity.ProjectWorkerGroup; +import org.apache.dolphinscheduler.dao.entity.User; +import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; +import org.apache.dolphinscheduler.dao.mapper.ProjectWorkerGroupMapper; +import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; +import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; +import org.apache.dolphinscheduler.dao.mapper.WorkerGroupMapper; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections4.SetUtils; +import org.apache.commons.lang3.StringUtils; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.TreeSet; +import java.util.stream.Collectors; + +import lombok.extern.slf4j.Slf4j; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; + +/** + * task definition service impl + */ +@Service +@Slf4j +public class ProjectWorkerGroupRelationServiceImpl extends BaseServiceImpl + implements + ProjectWorkerGroupRelationService { + + @Autowired + private ProjectWorkerGroupMapper projectWorkerGroupMapper; + + @Autowired + private ProjectMapper projectMapper; + + @Autowired + private WorkerGroupMapper workerGroupMapper; + + @Autowired + private TaskDefinitionMapper taskDefinitionMapper; + + @Autowired + private ScheduleMapper scheduleMapper; + + @Autowired + private ProjectService projectService; + + /** + * assign worker groups to a project + * + * @param loginUser the login user + * @param projectCode the project code + * @param workerGroups assigned worker group names + */ + @Override + public Result assignWorkerGroupsToProject(User loginUser, Long projectCode, List workerGroups) { + + Result result = new Result(); + + if (!isAdmin(loginUser)) { + putMsg(result, Status.USER_NO_OPERATION_PERM); + return result; + } + + if (Objects.isNull(projectCode)) { + putMsg(result, Status.PROJECT_NOT_EXIST); + return result; + } + + if (CollectionUtils.isEmpty(workerGroups)) { + putMsg(result, Status.WORKER_GROUP_TO_PROJECT_IS_EMPTY); + return result; + } + + Project project = projectMapper.queryByCode(projectCode); + if (Objects.isNull(project)) { + putMsg(result, Status.PROJECT_NOT_EXIST); + return result; + } + + Set workerGroupNames = + workerGroupMapper.queryAllWorkerGroup().stream().map(item -> item.getName()).collect( + Collectors.toSet()); + + workerGroupNames.add(Constants.DEFAULT_WORKER_GROUP); + + Set assignedWorkerGroupNames = workerGroups.stream().collect(Collectors.toSet()); + + Set difference = SetUtils.difference(assignedWorkerGroupNames, workerGroupNames); + + if (difference.size() > 0) { + putMsg(result, Status.WORKER_GROUP_NOT_EXIST, difference.toString()); + return result; + } + + Set projectWorkerGroupNames = projectWorkerGroupMapper.selectList(new QueryWrapper() + .lambda() + .eq(ProjectWorkerGroup::getProjectCode, projectCode)).stream().map(item -> item.getWorkerGroup()) + .collect(Collectors.toSet()); + + difference = SetUtils.difference(projectWorkerGroupNames, assignedWorkerGroupNames); + + if (CollectionUtils.isNotEmpty(difference)) { + Set usedWorkerGroups = getAllUsedWorkerGroups(project); + + if (CollectionUtils.isNotEmpty(usedWorkerGroups) && usedWorkerGroups.containsAll(difference)) { + throw new ServiceException(Status.USED_WORKER_GROUP_EXISTS, + SetUtils.intersection(usedWorkerGroups, difference).toSet()); + } + + int deleted = projectWorkerGroupMapper.delete( + new QueryWrapper().lambda().eq(ProjectWorkerGroup::getProjectCode, projectCode) + .in(ProjectWorkerGroup::getWorkerGroup, difference)); + if (deleted > 0) { + log.info("Success to delete worker groups [{}] for the project [{}] .", difference, project.getName()); + } else { + log.error("Failed to delete worker groups [{}] for the project [{}].", difference, project.getName()); + throw new ServiceException(Status.ASSIGN_WORKER_GROUP_TO_PROJECT_ERROR); + } + } + + difference = SetUtils.difference(assignedWorkerGroupNames, projectWorkerGroupNames); + Date now = new Date(); + if (CollectionUtils.isNotEmpty(difference)) { + difference.stream().forEach(workerGroupName -> { + ProjectWorkerGroup projectWorkerGroup = new ProjectWorkerGroup(); + projectWorkerGroup.setProjectCode(projectCode); + projectWorkerGroup.setWorkerGroup(workerGroupName); + projectWorkerGroup.setCreateTime(now); + projectWorkerGroup.setUpdateTime(now); + int create = projectWorkerGroupMapper.insert(projectWorkerGroup); + if (create > 0) { + log.info("Success to add worker group [{}] for the project [{}] .", workerGroupName, + project.getName()); + } else { + log.error("Failed to add worker group [{}] for the project [{}].", workerGroupName, + project.getName()); + throw new ServiceException(Status.ASSIGN_WORKER_GROUP_TO_PROJECT_ERROR); + } + }); + } + + putMsg(result, Status.SUCCESS); + return result; + } + + /** + * query worker groups that assigned to the project + * + * @param projectCode project code + */ + @Override + public Map queryWorkerGroupsByProject(User loginUser, Long projectCode) { + Map result = new HashMap<>(); + + Project project = projectMapper.queryByCode(projectCode); + // check project auth + boolean hasProjectAndPerm = projectService.hasProjectAndPerm(loginUser, project, result, null); + if (!hasProjectAndPerm) { + return result; + } + + Set assignedWorkerGroups = getAllUsedWorkerGroups(project); + + projectWorkerGroupMapper.selectList( + new QueryWrapper().lambda().eq(ProjectWorkerGroup::getProjectCode, projectCode)) + .stream().forEach(projectWorkerGroup -> assignedWorkerGroups.add(projectWorkerGroup.getWorkerGroup())); + + List projectWorkerGroups = assignedWorkerGroups.stream().map(workerGroup -> { + ProjectWorkerGroup projectWorkerGroup = new ProjectWorkerGroup(); + projectWorkerGroup.setProjectCode(projectCode); + projectWorkerGroup.setWorkerGroup(workerGroup); + return projectWorkerGroup; + }).collect(Collectors.toList()); + + result.put(Constants.DATA_LIST, projectWorkerGroups); + putMsg(result, Status.SUCCESS); + return result; + } + + private Set getAllUsedWorkerGroups(Project project) { + Set usedWorkerGroups = new TreeSet<>(); + // query all worker groups that tasks depend on + taskDefinitionMapper.queryAllDefinitionList(project.getCode()).stream().forEach(taskDefinition -> { + if (StringUtils.isNotEmpty(taskDefinition.getWorkerGroup())) { + usedWorkerGroups.add(taskDefinition.getWorkerGroup()); + } + }); + + // query all worker groups that timings depend on + scheduleMapper.querySchedulerListByProjectName(project.getName()) + .stream() + .filter(schedule -> StringUtils.isNotEmpty(schedule.getWorkerGroup())) + .forEach(schedule -> usedWorkerGroups.add(schedule.getWorkerGroup())); + + return usedWorkerGroups; + } + +} diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectWorkerGroupRelationServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectWorkerGroupRelationServiceTest.java new file mode 100644 index 0000000000..a8e8b8beb2 --- /dev/null +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectWorkerGroupRelationServiceTest.java @@ -0,0 +1,161 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.api.service; + +import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.service.impl.ProjectWorkerGroupRelationServiceImpl; +import org.apache.dolphinscheduler.api.utils.Result; +import org.apache.dolphinscheduler.common.constants.Constants; +import org.apache.dolphinscheduler.common.enums.UserType; +import org.apache.dolphinscheduler.dao.entity.Project; +import org.apache.dolphinscheduler.dao.entity.ProjectWorkerGroup; +import org.apache.dolphinscheduler.dao.entity.User; +import org.apache.dolphinscheduler.dao.entity.WorkerGroup; +import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; +import org.apache.dolphinscheduler.dao.mapper.ProjectWorkerGroupMapper; +import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; +import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; +import org.apache.dolphinscheduler.dao.mapper.WorkerGroupMapper; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; + +import com.google.common.collect.Lists; + +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) +public class ProjectWorkerGroupRelationServiceTest { + + @InjectMocks + private ProjectWorkerGroupRelationServiceImpl projectWorkerGroupRelationService; + + @Mock + private ProjectMapper projectMapper; + + @Mock + private ProjectWorkerGroupMapper projectWorkerGroupMapper; + + @Mock + private WorkerGroupMapper workerGroupMapper; + + @Mock + private ProjectService projectService; + + @Mock + private TaskDefinitionMapper taskDefinitionMapper; + + @Mock + private ScheduleMapper scheduleMapper; + + protected final static long projectCode = 1L; + + @Test + public void testAssignWorkerGroupsToProject() { + User loginUser = getAdminUser(); + + Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(null); + Result result = projectWorkerGroupRelationService.assignWorkerGroupsToProject(loginUser, projectCode, + getWorkerGroups()); + Assertions.assertEquals(Status.PROJECT_NOT_EXIST.getCode(), result.getCode()); + + WorkerGroup workerGroup = new WorkerGroup(); + workerGroup.setName("test"); + Mockito.when(projectMapper.queryByCode(Mockito.anyLong())).thenReturn(getProject()); + Mockito.when(workerGroupMapper.queryAllWorkerGroup()).thenReturn(Lists.newArrayList(workerGroup)); + Mockito.when(projectWorkerGroupMapper.insert(Mockito.any())).thenReturn(1); + + result = projectWorkerGroupRelationService.assignWorkerGroupsToProject(loginUser, projectCode, + getWorkerGroups()); + Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode()); + } + + @Test + public void testQueryWorkerGroupsByProject() { + + Mockito.when(projectService.hasProjectAndPerm(Mockito.any(), Mockito.any(), Mockito.anyMap(), Mockito.any())) + .thenReturn(true); + + Mockito.when(projectMapper.queryByCode(projectCode)) + .thenReturn(getProject()); + + Mockito.when(projectWorkerGroupMapper.selectList(Mockito.any())) + .thenReturn(Lists.newArrayList(getProjectWorkerGroup())); + + Mockito.when(taskDefinitionMapper.queryAllDefinitionList(Mockito.anyLong())) + .thenReturn(new ArrayList<>()); + + Mockito.when(scheduleMapper.querySchedulerListByProjectName(Mockito.any())) + .thenReturn(Lists.newArrayList()); + + Map result = + projectWorkerGroupRelationService.queryWorkerGroupsByProject(getGeneralUser(), projectCode); + + ProjectWorkerGroup[] actualValue = + ((List) result.get(Constants.DATA_LIST)).toArray(new ProjectWorkerGroup[0]); + + Assertions.assertEquals(actualValue[0].getWorkerGroup(), getProjectWorkerGroup().getWorkerGroup()); + } + + private List getWorkerGroups() { + return Lists.newArrayList("default"); + } + + private User getGeneralUser() { + User loginUser = new User(); + loginUser.setUserType(UserType.GENERAL_USER); + loginUser.setUserName("userName"); + loginUser.setId(1); + return loginUser; + } + + private User getAdminUser() { + User loginUser = new User(); + loginUser.setUserType(UserType.ADMIN_USER); + loginUser.setUserName("userName"); + loginUser.setId(1); + return loginUser; + } + + private Project getProject() { + Project project = new Project(); + project.setCode(projectCode); + project.setId(1); + project.setName("test"); + project.setUserId(1); + return project; + } + + private ProjectWorkerGroup getProjectWorkerGroup() { + ProjectWorkerGroup projectWorkerGroup = new ProjectWorkerGroup(); + projectWorkerGroup.setId(1); + projectWorkerGroup.setProjectCode(projectCode); + projectWorkerGroup.setWorkerGroup("default"); + return projectWorkerGroup; + } +} diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProjectWorkerGroup.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProjectWorkerGroup.java new file mode 100644 index 0000000000..1bc86bcd7b --- /dev/null +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProjectWorkerGroup.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dolphinscheduler.dao.entity; + +import java.util.Date; + +import lombok.Data; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; + +@Data +@TableName("t_ds_relation_project_worker_group") +public class ProjectWorkerGroup { + + /** + * id + */ + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + /** + * project code + */ + private Long projectCode; + + /** + * worker group + */ + private String workerGroup; + + /** + * create time + */ + private Date createTime; + + /** + * update time + */ + private Date updateTime; +} diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectWorkerGroupMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectWorkerGroupMapper.java new file mode 100644 index 0000000000..40353d4c4a --- /dev/null +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectWorkerGroupMapper.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.dao.mapper; + +import org.apache.dolphinscheduler.dao.entity.ProjectWorkerGroup; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +public interface ProjectWorkerGroupMapper extends BaseMapper { + +} diff --git a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql index 656e34af0e..f74000e731 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql @@ -1038,6 +1038,21 @@ CREATE TABLE t_ds_worker_group -- Records of t_ds_worker_group -- ---------------------------- +-- ---------------------------- +-- Table structure for t_ds_relation_project_worker_group +-- ---------------------------- +DROP TABLE IF EXISTS t_ds_relation_project_worker_group CASCADE; +CREATE TABLE t_ds_relation_project_worker_group +( + id int(11) NOT NULL AUTO_INCREMENT, + project_code bigint(20) NOT NULL, + worker_group varchar(255) DEFAULT NULL, + create_time datetime DEFAULT NULL, + update_time datetime DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE KEY unique_project_worker_group(project_code,worker_group) +); + -- ---------------------------- -- Table structure for t_ds_version -- ---------------------------- diff --git a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql index 9dcdc02203..7bde5063f1 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql @@ -1095,6 +1095,22 @@ CREATE TABLE `t_ds_alert_plugin_instance` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE = utf8_bin; + +-- ---------------------------- +-- Table structure for t_ds_relation_project_worker_group +-- ---------------------------- +DROP TABLE IF EXISTS `t_ds_relation_project_worker_group`; +CREATE TABLE `t_ds_relation_project_worker_group` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'key', + `project_code` bigint(20) NOT NULL COMMENT 'project code', + `worker_group` varchar(255) DEFAULT NULL COMMENT 'worker group', + `create_time` datetime DEFAULT NULL COMMENT 'create time', + `update_time` datetime DEFAULT NULL COMMENT 'update time', + PRIMARY KEY (`id`), + UNIQUE KEY unique_project_worker_group(project_code,worker_group) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE = utf8_bin; + + -- -- Table structure for table `t_ds_dq_comparison_type` -- @@ -1111,6 +1127,7 @@ CREATE TABLE `t_ds_dq_comparison_type` ( PRIMARY KEY (`id`) )ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE = utf8_bin; + INSERT IGNORE INTO `t_ds_dq_comparison_type` (`id`, `type`, `execute_sql`, `output_table`, `name`, `create_time`, `update_time`, `is_inner_source`) VALUES(1, 'FixValue', NULL, NULL, NULL, current_timestamp, current_timestamp, false); diff --git a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql index b54f19a2d1..946a544064 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql @@ -927,6 +927,21 @@ CREATE TABLE t_ds_worker_group ( CONSTRAINT name_unique UNIQUE (name) ) ; +-- +-- Table structure for table t_ds_relation_project_worker_group +-- + +DROP TABLE IF EXISTS t_ds_relation_project_worker_group; +CREATE TABLE t_ds_relation_project_worker_group ( + id int NOT NULL , + project_code bigint DEFAULT NULL , + worker_group varchar(255) NOT NULL, + create_time timestamp DEFAULT NULL, + update_time timestamp DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT t_ds_relation_project_worker_group_un UNIQUE (project_code, worker_group) +); + DROP SEQUENCE IF EXISTS t_ds_access_token_id_sequence; CREATE SEQUENCE t_ds_access_token_id_sequence; ALTER TABLE t_ds_access_token ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_access_token_id_sequence'); @@ -1024,6 +1039,10 @@ DROP SEQUENCE IF EXISTS t_ds_project_preference_id_sequence; CREATE SEQUENCE t_ds_project_preference_id_sequence; ALTER TABLE t_ds_project_preference ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_project_preference_id_sequence'); +DROP SEQUENCE IF EXISTS t_ds_relation_project_worker_group_sequence; +CREATE SEQUENCE t_ds_relation_project_worker_group_sequence; +ALTER TABLE t_ds_relation_project_worker_group ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_relation_project_worker_group_sequence'); + -- Records of t_ds_user?user : admin , password : dolphinscheduler123 INSERT INTO t_ds_user(user_name, user_password, user_type, email, phone, tenant_id, state, create_time, update_time, time_zone) VALUES ('admin', '7ad2410b2f4c074479a8937a28a22b8f', '0', 'xxx@qq.com', '', '-1', 1, '2018-03-27 15:48:50', '2018-10-24 17:40:22', null); diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.2_schema/mysql/dolphinscheduler_ddl.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.2_schema/mysql/dolphinscheduler_ddl.sql index 4a14f326b9..7a3ab5df68 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.2_schema/mysql/dolphinscheduler_ddl.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.2_schema/mysql/dolphinscheduler_ddl.sql @@ -14,3 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +DROP TABLE IF EXISTS `t_ds_relation_project_worker_group`; +CREATE TABLE `t_ds_relation_project_worker_group` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'key', + `project_code` bigint(20) NOT NULL COMMENT 'project code', + `worker_group` varchar(255) DEFAULT NULL COMMENT 'worker group', + `create_time` datetime DEFAULT NULL COMMENT 'create time', + `update_time` datetime DEFAULT NULL COMMENT 'update time', + PRIMARY KEY (`id`), + UNIQUE KEY unique_project_worker_group(project_code,worker_group) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE = utf8_bin; + diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.2_schema/postgresql/dolphinscheduler_ddl.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.2_schema/postgresql/dolphinscheduler_ddl.sql index 4a14f326b9..587bab4159 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.2_schema/postgresql/dolphinscheduler_ddl.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.2_schema/postgresql/dolphinscheduler_ddl.sql @@ -14,3 +14,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +DROP TABLE IF EXISTS t_ds_relation_project_worker_group; +CREATE TABLE t_ds_relation_project_worker_group ( + id int NOT NULL , + project_code bigint DEFAULT NULL , + worker_group varchar(255) NOT NULL, + create_time timestamp DEFAULT NULL, + update_time timestamp DEFAULT NULL, + PRIMARY KEY (id), + CONSTRAINT t_ds_relation_project_worker_group_un UNIQUE (project_code, worker_group) +); + +DROP SEQUENCE IF EXISTS t_ds_relation_project_worker_group_sequence; +CREATE SEQUENCE t_ds_relation_project_worker_group_sequence; +ALTER TABLE t_ds_relation_project_worker_group ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_relation_project_worker_group_sequence'); \ No newline at end of file diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectWorkerGroupMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectWorkerGroupMapperTest.java new file mode 100644 index 0000000000..3629f02240 --- /dev/null +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectWorkerGroupMapperTest.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dolphinscheduler.dao.mapper; + +import org.apache.dolphinscheduler.dao.BaseDaoTest; +import org.apache.dolphinscheduler.dao.entity.ProjectWorkerGroup; + +import java.util.Date; +import java.util.List; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; + +public class ProjectWorkerGroupMapperTest extends BaseDaoTest { + + @Autowired + private ProjectWorkerGroupMapper projectWorkerGroupMapper; + + /** + * insert + * + * @return ProjectWorkerGroup + */ + private ProjectWorkerGroup insertOne() { + // insertOne + ProjectWorkerGroup projectWorkerGroup = new ProjectWorkerGroup(); + + projectWorkerGroup.setProjectCode(1L); + projectWorkerGroup.setWorkerGroup("WorkerGroup1");; + projectWorkerGroupMapper.insert(projectWorkerGroup); + return projectWorkerGroup; + } + + /** + * test update + */ + @Test + public void testUpdate() { + // insertOne + ProjectWorkerGroup projectWorkerGroup = insertOne(); + projectWorkerGroup.setCreateTime(new Date()); + // update + int update = projectWorkerGroupMapper.updateById(projectWorkerGroup); + Assertions.assertEquals(update, 1); + } + + /** + * test delete + */ + @Test + public void testDelete() { + ProjectWorkerGroup projectWorkerGroup = insertOne(); + int delete = projectWorkerGroupMapper.deleteById(projectWorkerGroup.getId()); + Assertions.assertEquals(delete, 1); + } + + /** + * test query + */ + @Test + public void testQuery() { + ProjectWorkerGroup projectWorkerGroup = insertOne(); + // query + List projectUsers = projectWorkerGroupMapper.selectList(null); + Assertions.assertNotEquals(0, projectUsers.size()); + } + + /** + * test delete the relation of project and worker group + */ + @Test + public void testDeleteProjectWorkerGroupRelation() { + + ProjectWorkerGroup projectWorkerGroup = insertOne(); + int delete = projectWorkerGroupMapper.delete(new QueryWrapper() + .lambda() + .eq(ProjectWorkerGroup::getProjectCode, projectWorkerGroup.getProjectCode()) + .eq(ProjectWorkerGroup::getWorkerGroup, projectWorkerGroup.getWorkerGroup())); + + Assertions.assertTrue(delete >= 1); + } + + /** + * test query the relation of project and worker group + */ + @Test + public void testQueryProjectWorkerGroupRelation() { + ProjectWorkerGroup projectWorkerGroup = insertOne(); + projectWorkerGroup = projectWorkerGroupMapper.selectOne(new QueryWrapper() + .lambda() + .eq(ProjectWorkerGroup::getProjectCode, projectWorkerGroup.getProjectCode()) + .eq(ProjectWorkerGroup::getWorkerGroup, projectWorkerGroup.getWorkerGroup())); + + Assertions.assertNotEquals(null, projectWorkerGroup); + } +} diff --git a/dolphinscheduler-ui/src/locales/en_US/project.ts b/dolphinscheduler-ui/src/locales/en_US/project.ts index 21aba58f85..69aee6a0e2 100644 --- a/dolphinscheduler-ui/src/locales/en_US/project.ts +++ b/dolphinscheduler-ui/src/locales/en_US/project.ts @@ -40,7 +40,8 @@ export default { authorize_level: 'Authorize Level', no_permission: 'No Permission', read_permission: 'Read Permission', - all_permission: 'All Permission' + all_permission: 'All Permission', + assign_worker_group: 'Worker Group', }, workflow: { on_line: 'Online', diff --git a/dolphinscheduler-ui/src/locales/zh_CN/project.ts b/dolphinscheduler-ui/src/locales/zh_CN/project.ts index 1c6756a22e..8b84cc7f13 100644 --- a/dolphinscheduler-ui/src/locales/zh_CN/project.ts +++ b/dolphinscheduler-ui/src/locales/zh_CN/project.ts @@ -40,7 +40,8 @@ export default { authorize_level: '权限等级', no_permission: '无权限', read_permission: '读权限', - all_permission: '所有权限' + all_permission: '所有权限', + assign_worker_group: '分配WorkerGroup', }, workflow: { on_line: '线上', diff --git a/dolphinscheduler-ui/src/service/modules/projects-worker-group/index.ts b/dolphinscheduler-ui/src/service/modules/projects-worker-group/index.ts new file mode 100644 index 0000000000..7e280e28ae --- /dev/null +++ b/dolphinscheduler-ui/src/service/modules/projects-worker-group/index.ts @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { axios } from '@/service/service' +import { UpdateProjectWorkerGroupsReq } from "@/service/modules/projects-worker-group/types"; + +export function queryWorkerGroupsByProjectCode( + projectCode: number +): any { + return axios({ + url: `/projects/${projectCode}/worker-group`, + method: 'get' + }) +} + +export function assignWorkerGroups( + data: UpdateProjectWorkerGroupsReq, + projectCode: number +): any { + return axios({ + url: `/projects/${projectCode}/worker-group`, + method: 'post', + data + }) +} \ No newline at end of file diff --git a/dolphinscheduler-ui/src/service/modules/projects-worker-group/types.ts b/dolphinscheduler-ui/src/service/modules/projects-worker-group/types.ts new file mode 100644 index 0000000000..c91ed7e95f --- /dev/null +++ b/dolphinscheduler-ui/src/service/modules/projects-worker-group/types.ts @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +interface ProjectWorkerGroup { + id: number + projectCode: number + workerGroup: string + createTime: string + updateTime: string +} + + +interface UpdateProjectWorkerGroupsReq { + workerGroups: string +} + +export { + ProjectWorkerGroup, + UpdateProjectWorkerGroupsReq +} diff --git a/dolphinscheduler-ui/src/service/modules/worker-groups/index.ts b/dolphinscheduler-ui/src/service/modules/worker-groups/index.ts index acc6eb584c..75f716f17c 100644 --- a/dolphinscheduler-ui/src/service/modules/worker-groups/index.ts +++ b/dolphinscheduler-ui/src/service/modules/worker-groups/index.ts @@ -54,4 +54,4 @@ export function deleteById(id: IdReq): any { method: 'delete', params: id }) -} +} \ No newline at end of file diff --git a/dolphinscheduler-ui/src/views/projects/list/components/use-worker-group.ts b/dolphinscheduler-ui/src/views/projects/list/components/use-worker-group.ts new file mode 100644 index 0000000000..698e753333 --- /dev/null +++ b/dolphinscheduler-ui/src/views/projects/list/components/use-worker-group.ts @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { useI18n } from 'vue-i18n' +import { reactive, ref, SetupContext } from 'vue' +import { useUserStore } from '@/store/user/user' +import { Option } from "naive-ui/es/transfer/src/interface" +import { queryAllWorkerGroups } from "@/service/modules/worker-groups" +import { queryWorkerGroupsByProjectCode, assignWorkerGroups } from "@/service/modules/projects-worker-group" +import { UpdateProjectWorkerGroupsReq } from "@/service/modules/projects-worker-group/types" + +export function useWorkerGroup( + props: any, + ctx: SetupContext<('cancelModal' | 'confirmModal')[]> +) { + const { t } = useI18n() + const userStore = useUserStore() + + const variables = reactive({ + model: { + workerGroupOptions: [] as Option[], + assignedWorkerGroups: ref([] as any) + } + }) + + const initOptions = () => { + variables.model.workerGroupOptions = [] + queryAllWorkerGroups().then((res: any) => { + for (const workerGroup of res) { + variables.model.workerGroupOptions.push({label: workerGroup, value: workerGroup, disabled: workerGroup==='default'}) + } + }) + } + + const initAssignedWorkerGroups = (projectCode: number) => { + variables.model.assignedWorkerGroups = ref([] as any) + queryWorkerGroupsByProjectCode(projectCode).then((res: any) =>{ + res.data.forEach((item: any) => { + variables.model.assignedWorkerGroups.push(item.workerGroup) + }) + }) + } + + initOptions() + + const handleValidate = () => { + if (variables.model?.assignedWorkerGroups.length>0) { + submitModal() + ctx.emit('confirmModal', props.showModalRef) + } + } + + const submitModal = async () => { + if (props.row.code) { + let data: UpdateProjectWorkerGroupsReq = { + workerGroups: variables.model.assignedWorkerGroups.length>0? variables.model.assignedWorkerGroups.join(','):'' + } + assignWorkerGroups(data, props.row.code) + } + } + + return { variables, t, handleValidate, initAssignedWorkerGroups } +} diff --git a/dolphinscheduler-ui/src/views/projects/list/components/worker-group-modal.tsx b/dolphinscheduler-ui/src/views/projects/list/components/worker-group-modal.tsx new file mode 100644 index 0000000000..e84dc4520a --- /dev/null +++ b/dolphinscheduler-ui/src/views/projects/list/components/worker-group-modal.tsx @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + defineComponent, + getCurrentInstance, + PropType, + toRefs, + watch +} from 'vue' +import { NTransfer} from 'naive-ui' +import Modal from '@/components/modal' +import styles from "@/views/security/user-manage/index.module.scss"; +import {useWorkerGroup} from "@/views/projects/list/components/use-worker-group"; + +const props = { + showModalRef: { + type: Boolean as PropType, + default: false + }, + row: { + type: Object as PropType, + default: {} + } +} + +const WorkerGroupModal = defineComponent({ + name: 'WorkerGroupModal', + props, + emits: ['cancelModal', 'confirmModal'], + setup(props, ctx) { + const { variables, t, handleValidate, initAssignedWorkerGroups } = useWorkerGroup(props, ctx) + + const cancelModal = () => { + ctx.emit('cancelModal', props.showModalRef) + } + + const trim = getCurrentInstance()?.appContext.config.globalProperties.trim + + const confirmModal = () => { + handleValidate() + } + + watch( + () => props.showModalRef, + () => { + if (props.showModalRef) { + initAssignedWorkerGroups(props.row.code) + } + } + ) + + return { ...toRefs(variables), t, cancelModal, confirmModal, trim } + }, + render() { + const { t } = this + return ( + + + + ) + } +}) + +export default WorkerGroupModal diff --git a/dolphinscheduler-ui/src/views/projects/list/index.tsx b/dolphinscheduler-ui/src/views/projects/list/index.tsx index 83bcefd5b8..9f687dace7 100644 --- a/dolphinscheduler-ui/src/views/projects/list/index.tsx +++ b/dolphinscheduler-ui/src/views/projects/list/index.tsx @@ -29,6 +29,7 @@ import { useTable } from './use-table' import Card from '@/components/card' import Search from '@/components/input-search' import ProjectModal from './components/project-modal' +import WorkerGroupModal from "@/views/projects/list/components/worker-group-modal"; const list = defineComponent({ name: 'list', @@ -71,6 +72,15 @@ const list = defineComponent({ requestData() } + const onCancelWorkerGroupModal = () => { + variables.showWorkerGroupModalRef = false + } + + const onConfirmWorkerGroupModal = () => { + variables.showWorkerGroupModalRef = false + requestData() + } + const handleChangePageSize = () => { variables.page = 1 requestData() @@ -95,6 +105,8 @@ const list = defineComponent({ handleSearch, onCancelModal, onConfirmModal, + onCancelWorkerGroupModal, + onConfirmWorkerGroupModal, onClearSearch, handleChangePageSize, trim @@ -160,6 +172,12 @@ const list = defineComponent({ onCancelModal={this.onCancelModal} onConfirmModal={this.onConfirmModal} /> + ) } diff --git a/dolphinscheduler-ui/src/views/projects/list/use-table.ts b/dolphinscheduler-ui/src/views/projects/list/use-table.ts index 6cc01d3b27..7d7b8dda86 100644 --- a/dolphinscheduler-ui/src/views/projects/list/use-table.ts +++ b/dolphinscheduler-ui/src/views/projects/list/use-table.ts @@ -25,7 +25,7 @@ import { deleteProject } from '@/service/modules/projects' import { format } from 'date-fns' import { useRouter } from 'vue-router' import { - NButton, + NButton, NDropdown, NEllipsis, NIcon, NPopconfirm, @@ -39,18 +39,29 @@ import { } from '@/common/column-width-config' import type { Router } from 'vue-router' import type { ProjectRes } from '@/service/modules/projects/types' -import { DeleteOutlined, EditOutlined } from '@vicons/antd' +import {ControlOutlined, DeleteOutlined, EditOutlined, UserOutlined} from '@vicons/antd' +import {useUserStore} from "@/store/user/user"; +import {UserInfoRes} from "@/service/modules/users/types"; export function useTable() { const { t } = useI18n() const router: Router = useRouter() + const userStore = useUserStore() + const userInfo = userStore.getUserInfo as UserInfoRes + const IS_ADMIN = userInfo.userType === 'ADMIN_USER' + const handleEdit = (row: any) => { variables.showModalRef = true variables.statusRef = 1 variables.row = row } + const handleAssign = (row: any) => { + variables.showWorkerGroupModalRef = true + variables.row = row + } + const handleDelete = (row: any) => { deleteProject(row.code).then(() => { getTableData({ @@ -137,7 +148,7 @@ export function useTable() { { title: t('project.list.operation'), key: 'actions', - ...COLUMN_WIDTH_CONFIG['operation'](2), + ...COLUMN_WIDTH_CONFIG['operation'](3), render(row: any) { return h(NSpace, null, { default: () => [ @@ -165,6 +176,32 @@ export function useTable() { default: () => t('project.list.edit') } ), + IS_ADMIN && + h( + NTooltip, + { + trigger: 'hover' + }, + { + trigger: () => + h( + NButton, + { + circle: true, + type: 'info', + size: 'small', + class: 'edit', + onClick: () => { + handleAssign(row) + } + }, + { + icon: () => h(NIcon, null, () => h(ControlOutlined)) + } + ), + default: () => t('project.list.assign_worker_group') + } + ), h( NPopconfirm, { @@ -219,6 +256,7 @@ export function useTable() { searchVal: ref(''), totalPage: ref(1), showModalRef: ref(false), + showWorkerGroupModalRef: ref(false), statusRef: ref(0), row: {}, loadingRef: ref(false) diff --git a/dolphinscheduler-ui/src/views/projects/preference/use-form.ts b/dolphinscheduler-ui/src/views/projects/preference/use-form.ts index 4abdda3edf..992bc007a2 100644 --- a/dolphinscheduler-ui/src/views/projects/preference/use-form.ts +++ b/dolphinscheduler-ui/src/views/projects/preference/use-form.ts @@ -111,7 +111,7 @@ export function useForm() { const preferencesItems: IJsonItem[] = [ Fields.useTaskPriority(), useTenant(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(data.model, true), ...Fields.useFailed(), useWarningType(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-worker-group.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-worker-group.ts index d06e8b7ec3..d6ec1f6b8d 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-worker-group.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-worker-group.ts @@ -17,10 +17,10 @@ import { ref, onMounted } from 'vue' import { useI18n } from 'vue-i18n' -import { queryAllWorkerGroups } from '@/service/modules/worker-groups' +import { queryWorkerGroupsByProjectCode } from '@/service/modules/projects-worker-group' import type { IJsonItem } from '../types' -export function useWorkerGroup(): IJsonItem { +export function useWorkerGroup(projectCode: number): IJsonItem { const { t } = useI18n() const options = ref([] as { label: string; value: string }[]) @@ -29,8 +29,9 @@ export function useWorkerGroup(): IJsonItem { const getWorkerGroups = async () => { if (loading.value) return loading.value = true - const res = await queryAllWorkerGroups() - options.value = res.map((item: string) => ({ label: item, value: item })) + await queryWorkerGroupsByProjectCode(projectCode).then((res: any) => { + options.value = res.data.map((item: any) =>({label: item.workerGroup, value: item.workerGroup })) + }) loading.value = false } diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-chunjun.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-chunjun.ts index 1902404ce5..fc24e1a7a8 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-chunjun.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-chunjun.ts @@ -59,7 +59,7 @@ export function useChunjun({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-conditions.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-conditions.ts index c22b2345eb..08e325099f 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-conditions.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-conditions.ts @@ -57,7 +57,7 @@ export function useConditions({ Fields.useRunFlag(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-data-factory.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-data-factory.ts index c845fd0246..91fe1ff2f7 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-data-factory.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-data-factory.ts @@ -58,7 +58,7 @@ export function useDataFactory({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-data-quality.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-data-quality.ts index 457fc3afa6..c45dfa7044 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-data-quality.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-data-quality.ts @@ -69,7 +69,7 @@ export function useDataQuality({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-datasync.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-datasync.ts index 91de2f8cc5..843f90f349 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-datasync.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-datasync.ts @@ -68,7 +68,7 @@ export function useDatasync({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-datax.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-datax.ts index 0df09e14f2..b1344fbf35 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-datax.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-datax.ts @@ -62,7 +62,7 @@ export function useDataX({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-dependent.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-dependent.ts index 02bfcf7ebc..b140eea7f3 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-dependent.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-dependent.ts @@ -60,7 +60,7 @@ export function useDependent({ Fields.useRunFlag(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-dinky.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-dinky.ts index d90e191967..846a6d7872 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-dinky.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-dinky.ts @@ -54,7 +54,7 @@ export function useDinky({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-dms.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-dms.ts index 66c2c643da..7fe0922a73 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-dms.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-dms.ts @@ -69,7 +69,7 @@ export function useDms({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-dvc.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-dvc.ts index 18124ad4ec..d8376a5c9c 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-dvc.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-dvc.ts @@ -55,7 +55,7 @@ export function useDvc({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-dynamic.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-dynamic.ts index d481528eb6..8f498fbfe9 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-dynamic.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-dynamic.ts @@ -64,7 +64,7 @@ export function useDynamic({ Fields.useRunFlag(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useTimeoutAlarm(model), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-emr.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-emr.ts index 6a4dd664ae..7af5aa3e3a 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-emr.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-emr.ts @@ -56,7 +56,7 @@ export function useEmr({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-flink-stream.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-flink-stream.ts index d2186f4466..0b35f9f275 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-flink-stream.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-flink-stream.ts @@ -65,7 +65,7 @@ export function useFlinkStream({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), Fields.useDelayTime(model), ...Fields.useFlink(model), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-flink.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-flink.ts index adb7dd39f7..204bfc7141 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-flink.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-flink.ts @@ -65,7 +65,7 @@ export function useFlink({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-hive-cli.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-hive-cli.ts index f1ae3b302f..e9e485a9b7 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-hive-cli.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-hive-cli.ts @@ -68,7 +68,7 @@ export function useHiveCli({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-http.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-http.ts index 731929cb45..0e5d5fe5ca 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-http.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-http.ts @@ -62,7 +62,7 @@ export function useHttp({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-java.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-java.ts index 32b67a46a3..1eb99de965 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-java.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-java.ts @@ -76,7 +76,7 @@ export function useJava({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-jupyter.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-jupyter.ts index dddd8fee19..1901209e73 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-jupyter.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-jupyter.ts @@ -56,7 +56,7 @@ export function useJupyter({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-k8s.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-k8s.ts index c72443c218..e20a506df6 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-k8s.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-k8s.ts @@ -61,7 +61,7 @@ export function useK8s({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-kubeflow.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-kubeflow.ts index aaef1d6632..1c721a6dcd 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-kubeflow.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-kubeflow.ts @@ -54,7 +54,7 @@ export function useKubeflow({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-linkis.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-linkis.ts index 858c53ae34..5507f79bf6 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-linkis.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-linkis.ts @@ -65,7 +65,7 @@ export function useLinkis({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-mlflow.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-mlflow.ts index efb824c118..b25fdae436 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-mlflow.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-mlflow.ts @@ -62,7 +62,7 @@ export function useMlflow({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-mr.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-mr.ts index 13eec1c0d6..0ea09704d3 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-mr.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-mr.ts @@ -56,7 +56,7 @@ export function useMr({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-openmldb.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-openmldb.ts index e597828f53..18bd0deadc 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-openmldb.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-openmldb.ts @@ -58,7 +58,7 @@ export function useOpenmldb({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-pigeon.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-pigeon.ts index 5d99554b79..22b879919b 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-pigeon.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-pigeon.ts @@ -54,7 +54,7 @@ export function usePigeon({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-procedure.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-procedure.ts index d45e7a3cad..90f2491613 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-procedure.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-procedure.ts @@ -58,7 +58,7 @@ export function useProcedure({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-python.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-python.ts index 91db8b6efd..09f598e1d4 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-python.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-python.ts @@ -58,7 +58,7 @@ export function usePython({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-pytorch.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-pytorch.ts index 3d3a8606f2..ca0776aa38 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-pytorch.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-pytorch.ts @@ -73,7 +73,7 @@ export function usePytorch({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-remote-shell.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-remote-shell.ts index 5e31de6da8..977776510d 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-remote-shell.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-remote-shell.ts @@ -56,7 +56,7 @@ export function useRemoteShell({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-sagemaker.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-sagemaker.ts index fa11be5a97..88a38d8ea7 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-sagemaker.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-sagemaker.ts @@ -59,7 +59,7 @@ export function userSagemaker({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-sea-tunnel.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-sea-tunnel.ts index 7f42217da7..1cf03008b9 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-sea-tunnel.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-sea-tunnel.ts @@ -89,7 +89,7 @@ export function useSeaTunnel({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-shell.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-shell.ts index 8026363e13..96b1c9ce6c 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-shell.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-shell.ts @@ -57,7 +57,7 @@ export function useShell({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-spark.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-spark.ts index 15f7ec508f..05aa0fe1c6 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-spark.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-spark.ts @@ -64,7 +64,7 @@ export function useSpark({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-sql.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-sql.ts index 572435bf53..e733387c1d 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-sql.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-sql.ts @@ -62,7 +62,7 @@ export function useSql({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-sqoop.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-sqoop.ts index 03b625ee4c..e3e58a0594 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-sqoop.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-sqoop.ts @@ -77,7 +77,7 @@ export function useSqoop({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-sub-process.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-sub-process.ts index 77e45686d3..8c855666bc 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-sub-process.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-sub-process.ts @@ -56,7 +56,7 @@ export function useSubProcess({ Fields.useRunFlag(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useTimeoutAlarm(model), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-switch.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-switch.ts index 55452c2582..1e6d3f80cc 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-switch.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-switch.ts @@ -57,7 +57,7 @@ export function useSwitch({ Fields.useRunFlag(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-zeppelin.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-zeppelin.ts index 6516d013cf..c8ac1260e4 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-zeppelin.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/tasks/use-zeppelin.ts @@ -59,7 +59,7 @@ export function useZeppelin({ Fields.useCache(), Fields.useDescription(), Fields.useTaskPriority(), - Fields.useWorkerGroup(), + Fields.useWorkerGroup(projectCode), Fields.useEnvironmentName(model, !data?.id), ...Fields.useTaskGroup(model, projectCode), ...Fields.useFailed(), diff --git a/dolphinscheduler-ui/src/views/projects/workflow/definition/components/use-modal.ts b/dolphinscheduler-ui/src/views/projects/workflow/definition/components/use-modal.ts index cc818103fd..733638a3f0 100644 --- a/dolphinscheduler-ui/src/views/projects/workflow/definition/components/use-modal.ts +++ b/dolphinscheduler-ui/src/views/projects/workflow/definition/components/use-modal.ts @@ -26,7 +26,6 @@ import { importProcessDefinition, queryProcessDefinitionByCode } from '@/service/modules/process-definition' -import { queryAllWorkerGroups } from '@/service/modules/worker-groups' import { queryAllEnvironmentList } from '@/service/modules/environment' import { listNormalAlertGroupById } from '@/service/modules/alert-group' import { startProcessInstance } from '@/service/modules/executors' @@ -39,6 +38,7 @@ import { parseTime } from '@/common/common' import { EnvironmentItem } from '@/service/modules/environment/types' import { ITimingState, ProcessInstanceReq } from './types' import { queryTenantList } from '@/service/modules/tenants' +import { queryWorkerGroupsByProjectCode } from '@/service/modules/projects-worker-group' export function useModal( state: any, @@ -228,11 +228,8 @@ export function useModal( } const getWorkerGroups = () => { - queryAllWorkerGroups().then((res: any) => { - variables.workerGroups = res.map((item: string) => ({ - label: item, - value: item - })) + queryWorkerGroupsByProjectCode(variables.projectCode).then((res: any) => { + variables.workerGroups = res.data.map((item: any) =>({label: item.workerGroup, value: item.workerGroup })) }) }