Browse Source

[Improvement][api] Refactor the transaction rollbackfor runtimeexception (#3313)

* [Improvement][api] Refactor the transaction rollbackfor runtimeexception

* Remove the unused import
pull/3/MERGE
Yichao Yang 4 years ago committed by GitHub
parent
commit
d006bd3ba5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/ApiApplicationServer.java
  2. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java
  3. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataSourceService.java
  4. 6
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java
  5. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java
  6. 10
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java
  7. 13
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java
  8. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SessionService.java
  9. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UdfFuncService.java
  10. 17
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java
  11. 8
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java

1
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/ApiApplicationServer.java

@ -22,7 +22,6 @@ import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType; import org.springframework.context.annotation.FilterType;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication @SpringBootApplication
@ServletComponentScan @ServletComponentScan

2
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertGroupService.java

@ -177,7 +177,7 @@ public class AlertGroupService extends BaseService{
* @param id alert group id * @param id alert group id
* @return delete result code * @return delete result code
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public Map<String, Object> delAlertgroupById(User loginUser, int id) { public Map<String, Object> delAlertgroupById(User loginUser, int id) {
Map<String, Object> result = new HashMap<>(5); Map<String, Object> result = new HashMap<>(5);
result.put(Constants.STATUS, false); result.put(Constants.STATUS, false);

2
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataSourceService.java

@ -600,7 +600,7 @@ public class DataSourceService extends BaseService{
* @param datasourceId data source id * @param datasourceId data source id
* @return delete result code * @return delete result code
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public Result delete(User loginUser, int datasourceId) { public Result delete(User loginUser, int datasourceId) {
Result result = new Result(); Result result = new Result();
try { try {

6
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java

@ -438,7 +438,7 @@ public class ProcessDefinitionService extends BaseDAGService {
* @param processDefinitionId process definition id * @param processDefinitionId process definition id
* @return delete result code * @return delete result code
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public Map<String, Object> deleteProcessDefinitionById(User loginUser, String projectName, Integer processDefinitionId) { public Map<String, Object> deleteProcessDefinitionById(User loginUser, String projectName, Integer processDefinitionId) {
Map<String, Object> result = new HashMap<>(5); Map<String, Object> result = new HashMap<>(5);
@ -504,7 +504,7 @@ public class ProcessDefinitionService extends BaseDAGService {
* @param releaseState release state * @param releaseState release state
* @return release result code * @return release result code
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public Map<String, Object> releaseProcessDefinition(User loginUser, String projectName, int id, int releaseState) { public Map<String, Object> releaseProcessDefinition(User loginUser, String projectName, int id, int releaseState) {
HashMap<String, Object> result = new HashMap<>(); HashMap<String, Object> result = new HashMap<>();
Project project = projectMapper.queryByName(projectName); Project project = projectMapper.queryByName(projectName);
@ -751,7 +751,7 @@ public class ProcessDefinitionService extends BaseDAGService {
* @param currentProjectName current project name * @param currentProjectName current project name
* @return import process * @return import process
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public Map<String, Object> importProcessDefinition(User loginUser, MultipartFile file, String currentProjectName) { public Map<String, Object> importProcessDefinition(User loginUser, MultipartFile file, String currentProjectName) {
Map<String, Object> result = new HashMap<>(5); Map<String, Object> result = new HashMap<>(5);
String processMetaJson = FileUtils.file2String(file); String processMetaJson = FileUtils.file2String(file);

2
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java

@ -466,7 +466,7 @@ public class ProcessInstanceService extends BaseDAGService {
* @param processInstanceId process instance id * @param processInstanceId process instance id
* @return delete result code * @return delete result code
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public Map<String, Object> deleteProcessInstanceById(User loginUser, String projectName, Integer processInstanceId) { public Map<String, Object> deleteProcessInstanceById(User loginUser, String projectName, Integer processInstanceId) {
Map<String, Object> result = new HashMap<>(5); Map<String, Object> result = new HashMap<>(5);

10
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java

@ -86,7 +86,7 @@ public class ResourcesService extends BaseService {
* @param currentDir current directory * @param currentDir current directory
* @return create directory result * @return create directory result
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public Result createDirectory(User loginUser, public Result createDirectory(User loginUser,
String name, String name,
String description, String description,
@ -160,7 +160,7 @@ public class ResourcesService extends BaseService {
* @param currentDir current directory * @param currentDir current directory
* @return create result code * @return create result code
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public Result createResource(User loginUser, public Result createResource(User loginUser,
String name, String name,
String desc, String desc,
@ -288,7 +288,7 @@ public class ResourcesService extends BaseService {
* @param type resource type * @param type resource type
* @return update result code * @return update result code
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public Result updateResource(User loginUser, public Result updateResource(User loginUser,
int resourceId, int resourceId,
String name, String name,
@ -827,7 +827,7 @@ public class ResourcesService extends BaseService {
* @param content content * @param content content
* @return create result code * @return create result code
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public Result onlineCreateResource(User loginUser, ResourceType type, String fileName, String fileSuffix, String desc, String content,int pid,String currentDirectory) { public Result onlineCreateResource(User loginUser, ResourceType type, String fileName, String fileSuffix, String desc, String content,int pid,String currentDirectory) {
Result result = new Result(); Result result = new Result();
// if resource upload startup // if resource upload startup
@ -889,7 +889,7 @@ public class ResourcesService extends BaseService {
* @param content content * @param content content
* @return update result cod * @return update result cod
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public Result updateResourceContent(int resourceId, String content) { public Result updateResourceContent(int resourceId, String content) {
Result result = new Result(); Result result = new Result();

13
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java

@ -47,7 +47,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.text.ParseException; import java.text.ParseException;
import java.util.*; import java.util.*;
@ -95,9 +94,8 @@ public class SchedulerService extends BaseService {
* @param receiversCc receivers cc * @param receiversCc receivers cc
* @param workerGroup worker group * @param workerGroup worker group
* @return create result code * @return create result code
* @throws IOException ioexception
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public Map<String, Object> insertSchedule(User loginUser, String projectName, public Map<String, Object> insertSchedule(User loginUser, String projectName,
Integer processDefineId, Integer processDefineId,
String schedule, String schedule,
@ -107,7 +105,7 @@ public class SchedulerService extends BaseService {
String receivers, String receivers,
String receiversCc, String receiversCc,
Priority processInstancePriority, Priority processInstancePriority,
String workerGroup) throws IOException { String workerGroup) {
Map<String, Object> result = new HashMap<String, Object>(5); Map<String, Object> result = new HashMap<String, Object>(5);
@ -192,9 +190,8 @@ public class SchedulerService extends BaseService {
* @param receivers receivers * @param receivers receivers
* @param scheduleStatus schedule status * @param scheduleStatus schedule status
* @return update result code * @return update result code
* @throws IOException ioexception
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public Map<String, Object> updateSchedule(User loginUser, public Map<String, Object> updateSchedule(User loginUser,
String projectName, String projectName,
Integer id, Integer id,
@ -206,7 +203,7 @@ public class SchedulerService extends BaseService {
String receiversCc, String receiversCc,
ReleaseState scheduleStatus, ReleaseState scheduleStatus,
Priority processInstancePriority, Priority processInstancePriority,
String workerGroup) throws IOException { String workerGroup) {
Map<String, Object> result = new HashMap<String, Object>(5); Map<String, Object> result = new HashMap<String, Object>(5);
Project project = projectMapper.queryByName(projectName); Project project = projectMapper.queryByName(projectName);
@ -296,7 +293,7 @@ public class SchedulerService extends BaseService {
* @param scheduleStatus schedule status * @param scheduleStatus schedule status
* @return publish result code * @return publish result code
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public Map<String, Object> setScheduleState(User loginUser, public Map<String, Object> setScheduleState(User loginUser,
String projectName, String projectName,
Integer id, Integer id,

2
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SessionService.java

@ -81,7 +81,7 @@ public class SessionService extends BaseService{
* @param ip ip * @param ip ip
* @return session string * @return session string
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public String createSession(User user, String ip) { public String createSession(User user, String ip) {
Session session = null; Session session = null;

2
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UdfFuncService.java

@ -300,7 +300,7 @@ public class UdfFuncService extends BaseService{
* @param id udf function id * @param id udf function id
* @return delete result code * @return delete result code
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public Result delete(int id) { public Result delete(int id) {
Result result = new Result(); Result result = new Result();

17
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java

@ -138,14 +138,14 @@ public class UsersService extends BaseService {
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public User createUser(String userName, public User createUser(String userName,
String userPassword, String userPassword,
String email, String email,
int tenantId, int tenantId,
String phone, String phone,
String queue, String queue,
int state) throws Exception { int state) {
User user = new User(); User user = new User();
Date now = new Date(); Date now = new Date();
@ -430,7 +430,7 @@ public class UsersService extends BaseService {
* @param projectIds project id array * @param projectIds project id array
* @return grant result code * @return grant result code
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public Map<String, Object> grantProject(User loginUser, int userId, String projectIds) { public Map<String, Object> grantProject(User loginUser, int userId, String projectIds) {
Map<String, Object> result = new HashMap<>(5); Map<String, Object> result = new HashMap<>(5);
result.put(Constants.STATUS, false); result.put(Constants.STATUS, false);
@ -480,7 +480,7 @@ public class UsersService extends BaseService {
* @param resourceIds resource id array * @param resourceIds resource id array
* @return grant result code * @return grant result code
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public Map<String, Object> grantResources(User loginUser, int userId, String resourceIds) { public Map<String, Object> grantResources(User loginUser, int userId, String resourceIds) {
Map<String, Object> result = new HashMap<>(5); Map<String, Object> result = new HashMap<>(5);
//only admin can operate //only admin can operate
@ -577,7 +577,7 @@ public class UsersService extends BaseService {
* @param udfIds udf id array * @param udfIds udf id array
* @return grant result code * @return grant result code
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public Map<String, Object> grantUDFFunction(User loginUser, int userId, String udfIds) { public Map<String, Object> grantUDFFunction(User loginUser, int userId, String udfIds) {
Map<String, Object> result = new HashMap<>(5); Map<String, Object> result = new HashMap<>(5);
@ -624,7 +624,7 @@ public class UsersService extends BaseService {
* @param datasourceIds data source id array * @param datasourceIds data source id array
* @return grant result code * @return grant result code
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public Map<String, Object> grantDataSource(User loginUser, int userId, String datasourceIds) { public Map<String, Object> grantDataSource(User loginUser, int userId, String datasourceIds) {
Map<String, Object> result = new HashMap<>(5); Map<String, Object> result = new HashMap<>(5);
result.put(Constants.STATUS, false); result.put(Constants.STATUS, false);
@ -917,10 +917,9 @@ public class UsersService extends BaseService {
* @param repeatPassword repeat password * @param repeatPassword repeat password
* @param email email * @param email email
* @return register result code * @return register result code
* @throws Exception exception
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public Map<String, Object> registerUser(String userName, String userPassword, String repeatPassword, String email) throws Exception { public Map<String, Object> registerUser(String userName, String userPassword, String repeatPassword, String email) {
Map<String, Object> result = new HashMap<>(5); Map<String, Object> result = new HashMap<>(5);
//check user params //check user params

8
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java

@ -107,7 +107,7 @@ public class ProcessService {
* @param command found command * @param command found command
* @return process instance * @return process instance
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public ProcessInstance handleCommand(Logger logger, String host, int validThreadNum, Command command) { public ProcessInstance handleCommand(Logger logger, String host, int validThreadNum, Command command) {
ProcessInstance processInstance = constructProcessInstance(command, host); ProcessInstance processInstance = constructProcessInstance(command, host);
//cannot construct process instance, return null; //cannot construct process instance, return null;
@ -133,7 +133,7 @@ public class ProcessService {
* @param command command * @param command command
* @param message message * @param message message
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public void moveToErrorCommand(Command command, String message) { public void moveToErrorCommand(Command command, String message) {
ErrorCommand errorCommand = new ErrorCommand(command, message); ErrorCommand errorCommand = new ErrorCommand(command, message);
this.errorCommandMapper.insert(errorCommand); this.errorCommandMapper.insert(errorCommand);
@ -827,7 +827,7 @@ public class ProcessService {
* @param taskInstance taskInstance * @param taskInstance taskInstance
* @return task instance * @return task instance
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public TaskInstance submitTask(TaskInstance taskInstance){ public TaskInstance submitTask(TaskInstance taskInstance){
ProcessInstance processInstance = this.findProcessInstanceDetailById(taskInstance.getProcessInstanceId()); ProcessInstance processInstance = this.findProcessInstanceDetailById(taskInstance.getProcessInstanceId());
logger.info("start submit task : {}, instance id:{}, state: {}", logger.info("start submit task : {}, instance id:{}, state: {}",
@ -1477,7 +1477,7 @@ public class ProcessService {
* process need failover process instance * process need failover process instance
* @param processInstance processInstance * @param processInstance processInstance
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = RuntimeException.class)
public void processNeedFailoverProcessInstances(ProcessInstance processInstance){ public void processNeedFailoverProcessInstances(ProcessInstance processInstance){
//1 update processInstance host is null //1 update processInstance host is null
processInstance.setHost(Constants.NULL); processInstance.setHost(Constants.NULL);

Loading…
Cancel
Save