This is an automated email from the ASF dual-hosted git repository.

caishunfeng pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new 4a13148bfc [Bug] [API] Before deleting a worker group, check whether 
there is environment that reference the worker group. (#12534)
4a13148bfc is described below

commit 4a13148bfc20ab29c4782d08514326725b435ab9
Author: houshitao <[email protected]>
AuthorDate: Thu Oct 27 16:34:08 2022 +0800

    [Bug] [API] Before deleting a worker group, check whether there is 
environment that reference the worker group. (#12534)
    
    * [Bug] [API] Before deleting a worker group, check whether there is 
environment that reference the worker group.
    
    Co-authored-by: houshitao <[email protected]>
---
 docs/docs/en/guide/project/workflow-definition.md            |  3 +--
 .../java/org/apache/dolphinscheduler/api/enums/Status.java   |  4 ++--
 .../api/service/impl/WorkerGroupServiceImpl.java             | 12 ++++++++++++
 .../dolphinscheduler/api/service/WorkerGroupServiceTest.java |  7 ++++++-
 4 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/docs/docs/en/guide/project/workflow-definition.md 
b/docs/docs/en/guide/project/workflow-definition.md
index 1dacff17e2..876cea9fef 100644
--- a/docs/docs/en/guide/project/workflow-definition.md
+++ b/docs/docs/en/guide/project/workflow-definition.md
@@ -78,8 +78,7 @@ Workflow running parameter description:
 * **Complement(Backfill)**: Run workflow for a specified historical period. 
There are two strategies: serial complement and parallel complement.
 
   > You could select the time period or fill in it manually in UI. The date 
range is left closed and right closed time interval (startDate <= N <= endDate)
-
-  * Serial complement: Run the workflow from start date to end date according 
to the time period you set in serial.
+  > * Serial complement: Run the workflow from start date to end date 
according to the time period you set in serial.
 
   ![workflow-serial](../../../../img/new_ui/dev/project/workflow-serial.png)
 
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 b129c9f90f..2c67861426 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
@@ -506,8 +506,8 @@ public enum Status {
     FUNCTION_DISABLED(1400002, "The current feature is disabled.", "当前功能已被禁用"),
     SCHEDULE_TIME_NUMBER(1400003, "The number of complement dates exceed 
100.", "补数日期个数超过100"),
     DESCRIPTION_TOO_LONG_ERROR(1400004, "description is too long error", 
"描述过长"),
-    ;
-
+    DELETE_WORKER_GROUP_BY_ID_FAIL_ENV(1400005,
+            "delete worker group fail, for there are [{0}] enviroments 
using:{1}", "删除工作组失败,有 [{0}] 个环境正在使用:{1}");
     private final int code;
     private final String enMsg;
     private final String zhMsg;
diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java
index 860c410b1f..11b0ef6933 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java
@@ -28,11 +28,13 @@ import 
org.apache.dolphinscheduler.common.constants.Constants;
 import org.apache.dolphinscheduler.common.enums.AuthorizationType;
 import org.apache.dolphinscheduler.common.enums.NodeType;
 import org.apache.dolphinscheduler.common.enums.UserType;
+import org.apache.dolphinscheduler.dao.entity.EnvironmentWorkerGroupRelation;
 import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
 import org.apache.dolphinscheduler.dao.entity.Schedule;
 import org.apache.dolphinscheduler.dao.entity.TaskInstance;
 import org.apache.dolphinscheduler.dao.entity.User;
 import org.apache.dolphinscheduler.dao.entity.WorkerGroup;
+import 
org.apache.dolphinscheduler.dao.mapper.EnvironmentWorkerGroupRelationMapper;
 import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper;
 import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper;
 import org.apache.dolphinscheduler.dao.mapper.WorkerGroupMapper;
@@ -78,6 +80,9 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl 
implements WorkerGro
     @Autowired
     private RegistryClient registryClient;
 
+    @Autowired
+    private EnvironmentWorkerGroupRelationMapper 
environmentWorkerGroupRelationMapper;
+
     @Autowired
     private ProcessService processService;
 
@@ -343,6 +348,13 @@ public class WorkerGroupServiceImpl extends 
BaseServiceImpl implements WorkerGro
             putMsg(result, Status.DELETE_WORKER_GROUP_BY_ID_FAIL, 
processInstances.size());
             return result;
         }
+        List<EnvironmentWorkerGroupRelation> 
environmentWorkerGroupRelationList =
+                
environmentWorkerGroupRelationMapper.queryByWorkerGroupName(workerGroup.getName());
+        if (CollectionUtils.isNotEmpty(environmentWorkerGroupRelationList)) {
+            putMsg(result, Status.DELETE_WORKER_GROUP_BY_ID_FAIL_ENV, 
environmentWorkerGroupRelationList.size(),
+                    workerGroup.getName());
+            return result;
+        }
         workerGroupMapper.deleteById(id);
         
processInstanceMapper.updateProcessInstanceByWorkerGroupName(workerGroup.getName(),
 "");
         logger.info("Delete worker group complete, workerGroupName:{}.", 
workerGroup.getName());
diff --git 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkerGroupServiceTest.java
 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkerGroupServiceTest.java
index 987c718997..6013a0226b 100644
--- 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkerGroupServiceTest.java
+++ 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkerGroupServiceTest.java
@@ -34,6 +34,7 @@ import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
 import org.apache.dolphinscheduler.dao.entity.TaskInstance;
 import org.apache.dolphinscheduler.dao.entity.User;
 import org.apache.dolphinscheduler.dao.entity.WorkerGroup;
+import 
org.apache.dolphinscheduler.dao.mapper.EnvironmentWorkerGroupRelationMapper;
 import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper;
 import org.apache.dolphinscheduler.dao.mapper.WorkerGroupMapper;
 import org.apache.dolphinscheduler.service.process.ProcessService;
@@ -86,6 +87,9 @@ public class WorkerGroupServiceTest {
     @Mock
     private ResourcePermissionCheckService resourcePermissionCheckService;
 
+    @Mock
+    private EnvironmentWorkerGroupRelationMapper 
environmentWorkerGroupRelationMapper;
+
     private final String GROUP_NAME = "testWorkerGroup";
 
     private User getLoginUser() {
@@ -262,7 +266,8 @@ public class WorkerGroupServiceTest {
         Mockito.when(workerGroupMapper.deleteById(1)).thenReturn(1);
         
Mockito.when(processInstanceMapper.updateProcessInstanceByWorkerGroupName(workerGroup.getName(),
 ""))
                 .thenReturn(1);
-
+        
Mockito.when(environmentWorkerGroupRelationMapper.queryByWorkerGroupName(workerGroup.getName()))
+                .thenReturn(null);
         Map<String, Object> successResult = 
workerGroupService.deleteWorkerGroupById(loginUser, 1);
         Assertions.assertEquals(Status.SUCCESS.getCode(),
                 ((Status) successResult.get(Constants.STATUS)).getCode());

Reply via email to