Browse Source

[Bug] [API] task definition release/delete bug (#7232)

* fix worker group display

* fix workflow query bug

* fix workflow query bug

* fix task definition release/delete bug
3.0.0/version-upgrade
JinYong Li 3 years ago committed by GitHub
parent
commit
544b015f76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java
  2. 7
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java

31
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java

@ -210,6 +210,19 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
} }
int delete = taskDefinitionMapper.deleteByCode(taskCode); int delete = taskDefinitionMapper.deleteByCode(taskCode);
if (delete > 0) { if (delete > 0) {
List<ProcessTaskRelation> taskRelationList = processTaskRelationMapper.queryUpstreamByCode(projectCode, taskCode);
if (!processTaskRelationList.isEmpty()) {
int deleteRelation = 0;
int deleteRelationLog = 0;
for (ProcessTaskRelation processTaskRelation : taskRelationList) {
ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog(processTaskRelation);
deleteRelation += processTaskRelationMapper.deleteRelation(processTaskRelationLog);
deleteRelationLog += processTaskRelationLogMapper.deleteRelation(processTaskRelationLog);
}
if ((deleteRelation & deleteRelationLog) == 0) {
throw new ServiceException(Status.DELETE_TASK_PROCESS_RELATION_ERROR);
}
}
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
} else { } else {
putMsg(result, Status.DELETE_TASK_DEFINE_BY_CODE_ERROR); putMsg(result, Status.DELETE_TASK_DEFINE_BY_CODE_ERROR);
@ -496,6 +509,7 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
* @param releaseState releaseState * @param releaseState releaseState
* @return update result code * @return update result code
*/ */
@Transactional(rollbackFor = RuntimeException.class)
@Override @Override
public Map<String, Object> releaseTaskDefinition(User loginUser, long projectCode, long code, ReleaseState releaseState) { public Map<String, Object> releaseTaskDefinition(User loginUser, long projectCode, long code, ReleaseState releaseState) {
Project project = projectMapper.queryByCode(projectCode); Project project = projectMapper.queryByCode(projectCode);
@ -514,11 +528,15 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
putMsg(result, Status.TASK_DEFINE_NOT_EXIST, code); putMsg(result, Status.TASK_DEFINE_NOT_EXIST, code);
return result; return result;
} }
TaskDefinitionLog taskDefinitionLog = taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(code, taskDefinition.getVersion());
if (taskDefinitionLog == null) {
putMsg(result, Status.TASK_DEFINE_NOT_EXIST, code);
return result;
}
switch (releaseState) { switch (releaseState) {
case OFFLINE: case OFFLINE:
taskDefinition.setFlag(Flag.NO); taskDefinition.setFlag(Flag.NO);
taskDefinitionMapper.updateById(taskDefinition); taskDefinitionLog.setFlag(Flag.NO);
break; break;
case ONLINE: case ONLINE:
String resourceIds = taskDefinition.getResourceIds(); String resourceIds = taskDefinition.getResourceIds();
@ -534,13 +552,18 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
} }
} }
taskDefinition.setFlag(Flag.YES); taskDefinition.setFlag(Flag.YES);
taskDefinitionMapper.updateById(taskDefinition); taskDefinitionLog.setFlag(Flag.NO);
break; break;
default: default:
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, RELEASESTATE); putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, RELEASESTATE);
return result; return result;
} }
int update = taskDefinitionMapper.updateById(taskDefinition);
int updateLog = taskDefinitionLogMapper.updateById(taskDefinitionLog);
if ((update == 0 && updateLog == 1) || (update == 1 && updateLog == 0)) {
putMsg(result, Status.UPDATE_TASK_DEFINITION_ERROR);
throw new ServiceException(Status.UPDATE_TASK_DEFINITION_ERROR);
}
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
return result; return result;
} }

7
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java

@ -309,7 +309,14 @@ public class TaskDefinitionServiceImplTest {
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
TaskDefinition taskDefinition = new TaskDefinition(); TaskDefinition taskDefinition = new TaskDefinition();
taskDefinition.setProjectCode(projectCode); taskDefinition.setProjectCode(projectCode);
taskDefinition.setVersion(1);
taskDefinition.setCode(taskCode);
String params = "{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"echo 1\",\"conditionResult\":{\"successNode\":[\"\"],\"failedNode\":[\"\"]},\"dependence\":{}}";
taskDefinition.setTaskParams(params);
taskDefinition.setTaskType(TaskType.SHELL.getDesc());
Mockito.when(taskDefinitionMapper.queryByCode(taskCode)).thenReturn(taskDefinition); Mockito.when(taskDefinitionMapper.queryByCode(taskCode)).thenReturn(taskDefinition);
TaskDefinitionLog taskDefinitionLog = new TaskDefinitionLog(taskDefinition);
Mockito.when(taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(taskCode, taskDefinition.getVersion())).thenReturn(taskDefinitionLog);
Map<String, Object> offlineTaskResult = taskDefinitionService.releaseTaskDefinition(loginUser, projectCode, taskCode, ReleaseState.OFFLINE); Map<String, Object> offlineTaskResult = taskDefinitionService.releaseTaskDefinition(loginUser, projectCode, taskCode, ReleaseState.OFFLINE);
Assert.assertEquals(Status.SUCCESS, offlineTaskResult.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, offlineTaskResult.get(Constants.STATUS));

Loading…
Cancel
Save