From ff7d03e01fe0d97683692df5892b04399e60abee Mon Sep 17 00:00:00 2001 From: Tboy Date: Wed, 30 Oct 2019 10:51:03 +0800 Subject: [PATCH] add transactional for deleteWorkerGroupById (#1119) * move updateTaskState into try/catch block in case of exception * fix NPE * using conf.getInt instead of getString * for AbstractZKClient, remove the log, for it will print the same log message in createZNodePath. for AlertDao, correct the spelling. * duplicate * refactor getTaskWorkerGroupId * add friendly log * update hearbeat thread num = 1 * fix the bug when worker execute task using queue. and remove checking Tenant user anymore in TaskScheduleThread * 1. move verifyTaskInstanceIsNull after taskInstance 2. keep verifyTenantIsNull/verifyTaskInstanceIsNull clean and readable * fix the message * delete before check to avoid KeeperException$NoNodeException * fix the message * check processInstance state before delete tenant * check processInstance state before delete worker group * refactor * merge api constants into common constatns * update the resource perm * update the dataSource perm * fix CheckUtils.checkUserParams method * update AlertGroupService, extends from BaseService, remove duplicate methods * refactor * modify method name * add hasProjectAndPerm method * using checkProject instead of getResultStatus * delete checkAuth method, using hasProjectAndPerm instead. * correct spelling * add transactional for deleteWorkerGroupById --- .../api/controller/WorkerGroupController.java | 12 ++++++------ .../apache/dolphinscheduler/api/enums/Status.java | 6 +++++- .../api/service/WorkerGroupService.java | 6 ++++-- 3 files changed, 15 insertions(+), 9 deletions(-) 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 be4ff00e1a..bd04868993 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 @@ -113,8 +113,8 @@ public class WorkerGroupController extends BaseController{ Map result = workerGroupService.queryAllGroupPaging(loginUser,pageNo, pageSize, searchVal); return returnDataListPaging(result); }catch (Exception e){ - logger.error(Status.SAVE_ERROR.getMsg(),e); - return error(Status.SAVE_ERROR.getCode(), Status.SAVE_ERROR.getMsg()); + logger.error(Status.QUERY_WORKER_GROUP_FAIL.getMsg(),e); + return error(Status.QUERY_WORKER_GROUP_FAIL.getCode(), Status.QUERY_WORKER_GROUP_FAIL.getMsg()); } } @@ -135,8 +135,8 @@ public class WorkerGroupController extends BaseController{ Map result = workerGroupService.queryAllGroup(); return returnDataList(result); }catch (Exception e){ - logger.error(Status.SAVE_ERROR.getMsg(),e); - return error(Status.SAVE_ERROR.getCode(), Status.SAVE_ERROR.getMsg()); + logger.error(Status.QUERY_WORKER_GROUP_FAIL.getMsg(),e); + return error(Status.QUERY_WORKER_GROUP_FAIL.getCode(), Status.QUERY_WORKER_GROUP_FAIL.getMsg()); } } @@ -163,8 +163,8 @@ public class WorkerGroupController extends BaseController{ Map result = workerGroupService.deleteWorkerGroupById(id); return returnDataList(result); }catch (Exception e){ - logger.error(Status.SAVE_ERROR.getMsg(),e); - return error(Status.SAVE_ERROR.getCode(), Status.SAVE_ERROR.getMsg()); + logger.error(Status.DELETE_WORKER_GROUP_FAIL.getMsg(),e); + return error(Status.DELETE_WORKER_GROUP_FAIL.getCode(), Status.DELETE_WORKER_GROUP_FAIL.getMsg()); } } } 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 479f38d725..6978b2019a 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 @@ -168,7 +168,11 @@ public enum Status { DELETE_TENANT_BY_ID_FAIL_DEFINES(100143,"delete tenant by id fail, for there are {0} process definitions using it"), DELETE_TENANT_BY_ID_FAIL_USERS(100144,"delete tenant by id fail, for there are {0} users using it"), - DELETE_WORKER_GROUP_BY_ID_FAIL(100143,"delete worker group by id fail, for there are {0} process instances in executing using it"), + DELETE_WORKER_GROUP_BY_ID_FAIL(100145,"delete worker group by id fail, for there are {0} process instances in executing using it"), + + QUERY_WORKER_GROUP_FAIL(100146,"query worker group fail "), + DELETE_WORKER_GROUP_FAIL(100147,"delete worker group fail "), + UDF_FUNCTION_NOT_EXIST(20001, "UDF function not found"), UDF_FUNCTION_EXISTS(20002, "UDF function already exists"), diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkerGroupService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkerGroupService.java index 09954938d7..7514e3e282 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkerGroupService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkerGroupService.java @@ -30,6 +30,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.HashMap; @@ -149,17 +150,18 @@ public class WorkerGroupService extends BaseService { * @param id * @return */ + @Transactional(rollbackFor = Exception.class) public Map deleteWorkerGroupById(Integer id) { Map result = new HashMap<>(5); - List processInstances = processInstanceMapper.queryByWorkerGroupIdAndStatus(id, org.apache.dolphinscheduler.common.Constants.NOT_TERMINATED_STATES); + List processInstances = processInstanceMapper.queryByWorkerGroupIdAndStatus(id, Constants.NOT_TERMINATED_STATES); if(CollectionUtils.isNotEmpty(processInstances)){ putMsg(result, Status.DELETE_WORKER_GROUP_BY_ID_FAIL, processInstances.size()); return result; } workerGroupMapper.deleteById(id); - processInstanceMapper.updateProcessInstanceByWorkerGroupId(id, org.apache.dolphinscheduler.common.Constants.DEFAULT_WORKER_ID); + processInstanceMapper.updateProcessInstanceByWorkerGroupId(id, Constants.DEFAULT_WORKER_ID); putMsg(result, Status.SUCCESS); return result; }