Browse Source

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
Tboy 5 years ago
parent
commit
ff7d03e01f

+ 6 - 6
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkerGroupController.java

@@ -113,8 +113,8 @@ public class WorkerGroupController extends BaseController{
             Map<String, Object> 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<String, Object> 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<String, Object> 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());
         }
     }
 }

+ 5 - 1
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"),

+ 4 - 2
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<String,Object> deleteWorkerGroupById(Integer id) {
 
         Map<String, Object> result = new HashMap<>(5);
 
-        List<ProcessInstance> processInstances = processInstanceMapper.queryByWorkerGroupIdAndStatus(id, org.apache.dolphinscheduler.common.Constants.NOT_TERMINATED_STATES);
+        List<ProcessInstance> 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;
     }