未验证 提交 4a13148b 编写于 作者: H houshitao 提交者: GitHub

[Bug] [API] Before deleting a worker group, check whether there is environment...

[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: Nhoushitao <shitaohou@163.com>
上级 53340fc0
......@@ -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)
......
......@@ -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;
......
......@@ -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());
......
......@@ -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());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册