Browse Source

[3.0.2-prepare] Fix issues after cherry-pick and run CI (#12808)

3.0.2-release
Eric Gao 2 years ago committed by GitHub
parent
commit
c3a98dd9d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java
  2. 10
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java
  3. 1
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorServiceTest.java
  4. 6
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java
  5. 20
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java
  6. 1
      dolphinscheduler-bom/pom.xml
  7. 42
      dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/DateUtilsTest.java
  8. 4
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java
  9. 2
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/utils/WorkflowUtils.java
  10. 6
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/utils/WorkflowUtilsTest.java

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

@ -750,7 +750,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
for (ProcessDefinition process : processDefinitionList) {
try {
this.deleteProcessDefinitionByCode(loginUser, process.getCode());
this.deleteProcessDefinitionByCode(loginUser, projectCode, process.getCode());
} catch (Exception e) {
throw new ServiceException(Status.DELETE_PROCESS_DEFINE_ERROR, process.getName(), e.getMessage());
}

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

@ -98,12 +98,17 @@ import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* process instance service impl
*/
@Service
public class ProcessInstanceServiceImpl extends BaseServiceImpl implements ProcessInstanceService {
private static final Logger logger = LoggerFactory.getLogger(ProcessInstanceServiceImpl.class);
public static final String TASK_TYPE = "taskType";
public static final String LOCAL_PARAMS_LIST = "localParamsList";
@ -679,7 +684,10 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
ProcessInstance processInstance = processInstanceMapper.queryDetailById(processInstanceId);
if (processInstance == null) {
throw new RuntimeException("workflow instance is null");
logger.error("Process instance does not exist, projectCode:{}, processInstanceId:{}.", projectCode,
processInstanceId);
putMsg(result, Status.PROCESS_INSTANCE_NOT_EXIST, processInstanceId);
return result;
}
ProcessDefinition processDefinition = processDefineMapper.queryByCode(processInstance.getProcessDefinitionCode());

1
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorServiceTest.java

@ -59,6 +59,7 @@ import java.util.Map;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;

6
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java

@ -722,12 +722,16 @@ public class ProcessDefinitionServiceTest {
Mockito.when(dataSourceMapper.queryDataSourceByNameAndUserId(userId, "mysql_1")).thenReturn(dataSource);
long projectCode = 1001;
Map<String, Object> result = new HashMap<>();
result.put(Constants.STATUS, Status.SUCCESS);
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Mockito.when(projectService.checkProjectAndAuth(loginUser, getProject(projectCode), projectCode)).thenReturn(result);
Mockito.when(processService.saveTaskDefine(Mockito.same(loginUser), Mockito.eq(projectCode), Mockito.notNull(), Mockito.anyBoolean())).thenReturn(2);
Mockito.when(processService.saveProcessDefine(Mockito.same(loginUser), Mockito.notNull(), Mockito.notNull(), Mockito.anyBoolean())).thenReturn(1);
Mockito.when(processService.saveTaskRelation(Mockito.same(loginUser), Mockito.eq(projectCode), Mockito.anyLong(),
Mockito.eq(1), Mockito.notNull(), Mockito.notNull(), Mockito.anyBoolean())).thenReturn(0);
Map<String, Object> result = processDefinitionService.importSqlProcessDefinition(loginUser, projectCode, mockMultipartFile);
result = processDefinitionService.importSqlProcessDefinition(loginUser, projectCode, mockMultipartFile);
Assert.assertEquals(result.get(Constants.STATUS), Status.SUCCESS);
}

20
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java

@ -201,7 +201,7 @@ public class ProcessInstanceServiceTest {
Result successRes = processInstanceService.queryProcessInstanceList(loginUser, projectCode, 1, "2020-01-01 00:00:00",
"2020-01-02 00:00:00", "", loginUser.getUserName(), ExecutionStatus.SUBMITTED_SUCCESS,
"192.168.xx.xx", 1, 10);
Assert.assertEquals(Status.SUCCESS.getCode(), (int)successRes.getCode());
Assert.assertEquals(Status.SUCCESS.getCode(), (int) successRes.getCode());
// data parameter empty
when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1L), eq(""), eq(-1), Mockito.any(),
@ -209,7 +209,7 @@ public class ProcessInstanceServiceTest {
successRes = processInstanceService.queryProcessInstanceList(loginUser, projectCode, 1, "",
"", "", loginUser.getUserName(), ExecutionStatus.SUBMITTED_SUCCESS,
"192.168.xx.xx", 1, 10);
Assert.assertEquals(Status.SUCCESS.getCode(), (int)successRes.getCode());
Assert.assertEquals(Status.SUCCESS.getCode(), (int) successRes.getCode());
//executor null
when(usersService.queryUser(loginUser.getId())).thenReturn(null);
@ -218,7 +218,7 @@ public class ProcessInstanceServiceTest {
"2020-01-02 00:00:00", "", "admin", ExecutionStatus.SUBMITTED_SUCCESS,
"192.168.xx.xx", 1, 10);
Assert.assertEquals(Status.SUCCESS.getCode(), (int)executorExistRes.getCode());
Assert.assertEquals(Status.SUCCESS.getCode(), (int) executorExistRes.getCode());
//executor name empty
when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1L), eq(""), eq(0), Mockito.any(),
@ -226,7 +226,7 @@ public class ProcessInstanceServiceTest {
Result executorEmptyRes = processInstanceService.queryProcessInstanceList(loginUser, projectCode, 1, "2020-01-01 00:00:00",
"2020-01-02 00:00:00", "", "", ExecutionStatus.SUBMITTED_SUCCESS,
"192.168.xx.xx", 1, 10);
Assert.assertEquals(Status.SUCCESS.getCode(), (int)executorEmptyRes.getCode());
Assert.assertEquals(Status.SUCCESS.getCode(), (int) executorEmptyRes.getCode());
}
@ -299,7 +299,7 @@ public class ProcessInstanceServiceTest {
Assert.assertEquals(Status.SUCCESS, workerExistRes.get(Constants.STATUS));
when(processService.findProcessDefinition(processInstance.getProcessDefinitionCode(),
processInstance.getProcessDefinitionVersion())).thenReturn(null);;
processInstance.getProcessDefinitionVersion())).thenReturn(null);
workerExistRes = processInstanceService.queryProcessInstanceById(loginUser, projectCode, 1);
Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, workerExistRes.get(Constants.STATUS));
}
@ -430,7 +430,7 @@ public class ProcessInstanceServiceTest {
when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result);
when(processService.findProcessInstanceDetailById(1)).thenReturn(null);
Map<String, Object> processInstanceNullRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1,
shellJson, taskJson,"2020-02-21 00:00:00", true, "", "", 0, "");
shellJson, taskJson, "2020-02-21 00:00:00", true, "", "", 0, "");
Assert.assertEquals(Status.PROCESS_INSTANCE_NOT_EXIST, processInstanceNullRes.get(Constants.STATUS));
//process instance not finish
@ -438,7 +438,7 @@ public class ProcessInstanceServiceTest {
processInstance.setState(ExecutionStatus.RUNNING_EXECUTION);
putMsg(result, Status.SUCCESS, projectCode);
Map<String, Object> processInstanceNotFinishRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1,
shellJson, taskJson,"2020-02-21 00:00:00", true, "", "", 0, "");
shellJson, taskJson, "2020-02-21 00:00:00", true, "", "", 0, "");
Assert.assertEquals(Status.PROCESS_INSTANCE_STATE_OPERATION_ERROR, processInstanceNotFinishRes.get(Constants.STATUS));
//process instance finish
@ -463,7 +463,7 @@ public class ProcessInstanceServiceTest {
putMsg(result, Status.SUCCESS, projectCode);
when(taskPluginManager.checkTaskParameters(Mockito.any())).thenReturn(true);
Map<String, Object> processInstanceFinishRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1,
taskRelationJson, taskDefinitionJson,"2020-02-21 00:00:00", true, "", "", 0, "root");
taskRelationJson, taskDefinitionJson, "2020-02-21 00:00:00", true, "", "", 0, "root");
Assert.assertEquals(Status.SUCCESS, processInstanceFinishRes.get(Constants.STATUS));
//success
@ -472,7 +472,7 @@ public class ProcessInstanceServiceTest {
when(processService.saveProcessDefine(loginUser, processDefinition, Boolean.FALSE, Boolean.FALSE)).thenReturn(1);
Map<String, Object> successRes = processInstanceService.updateProcessInstance(loginUser, projectCode, 1,
taskRelationJson, taskDefinitionJson,"2020-02-21 00:00:00", Boolean.FALSE, "", "", 0, "root");
taskRelationJson, taskDefinitionJson, "2020-02-21 00:00:00", Boolean.FALSE, "", "", 0, "root");
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
}
@ -542,7 +542,7 @@ public class ProcessInstanceServiceTest {
processInstance.setScheduleTime(new Date());
processInstance.setGlobalParams("");
when(processInstanceMapper.queryDetailById(1)).thenReturn(processInstance);
Map<String, Object> successRes = processInstanceService.viewVariables(1L,1);
Map<String, Object> successRes = processInstanceService.viewVariables(1L, 1);
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
when(processInstanceMapper.queryDetailById(1)).thenReturn(null);

1
dolphinscheduler-bom/pom.xml

@ -87,6 +87,7 @@
<hibernate-validator.version>6.2.2.Final</hibernate-validator.version>
<aws-sdk.version>1.12.160</aws-sdk.version>
<joda-time.version>2.10.13</joda-time.version>
<gson.version>2.9.1</gson.version>
</properties>

42
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/DateUtilsTest.java

@ -171,50 +171,50 @@ public class DateUtilsTest {
public void testFormat2Duration() {
// days hours minutes seconds
Date d1 = DateUtils.stringToDate("2020-01-20 11:00:00");
Date d2 = DateUtils.stringToDate("2020-01-21 12:10:10");
String duration = DateUtils.format2Duration(d2, d1);
Date start = DateUtils.stringToDate("2020-01-20 11:00:00");
Date end = DateUtils.stringToDate("2020-01-21 12:10:10");
String duration = DateUtils.format2Duration(start, end);
Assert.assertEquals("1d 1h 10m 10s", duration);
duration = DateUtils.format2Duration(d2, d1);
duration = DateUtils.format2Duration(end, start);
Assert.assertNull(duration);
// hours minutes seconds
d1 = DateUtils.stringToDate("2020-01-20 11:00:00");
d2 = DateUtils.stringToDate("2020-01-20 12:10:10");
duration = DateUtils.format2Duration(d2, d1);
start = DateUtils.stringToDate("2020-01-20 11:00:00");
end = DateUtils.stringToDate("2020-01-20 12:10:10");
duration = DateUtils.format2Duration(start, end);
Assert.assertEquals("1h 10m 10s", duration);
// minutes seconds
d1 = DateUtils.stringToDate("2020-01-20 11:00:00");
d2 = DateUtils.stringToDate("2020-01-20 11:10:10");
duration = DateUtils.format2Duration(d2, d1);
start = DateUtils.stringToDate("2020-01-20 11:00:00");
end = DateUtils.stringToDate("2020-01-20 11:10:10");
duration = DateUtils.format2Duration(start, end);
Assert.assertEquals("10m 10s", duration);
// minutes seconds
d1 = DateUtils.stringToDate("2020-01-20 11:10:00");
d2 = DateUtils.stringToDate("2020-01-20 11:10:10");
duration = DateUtils.format2Duration(d2, d1);
start = DateUtils.stringToDate("2020-01-20 11:10:00");
end = DateUtils.stringToDate("2020-01-20 11:10:10");
duration = DateUtils.format2Duration(start, end);
Assert.assertEquals("10s", duration);
d1 = DateUtils.stringToDate("2020-01-20 11:10:00");
d2 = DateUtils.stringToDate("2020-01-21 11:10:10");
duration = DateUtils.format2Duration(d2, d1);
start = DateUtils.stringToDate("2020-01-20 11:10:00");
end = DateUtils.stringToDate("2020-01-21 11:10:10");
duration = DateUtils.format2Duration(start, end);
Assert.assertEquals("1d 10s", duration);
d1 = DateUtils.stringToDate("2020-01-20 11:10:00");
d2 = DateUtils.stringToDate("2020-01-20 16:10:10");
duration = DateUtils.format2Duration(d2, d1);
start = DateUtils.stringToDate("2020-01-20 11:10:00");
end = DateUtils.stringToDate("2020-01-20 16:10:10");
duration = DateUtils.format2Duration(start, end);
Assert.assertEquals("5h 10s", duration);
}
@Test
public void testNullDuration() {
public void durationShouldNotBeNullWhenOnlyEndDateIsNull() {
// days hours minutes seconds
Date d1 = DateUtils.stringToDate("2020-01-20 11:00:00");
Date d2 = null;
Assert.assertNull(DateUtils.format2Duration(d1, d2));
Assert.assertNotNull(DateUtils.format2Duration(d1, d2));
}
@Test

4
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java

@ -393,11 +393,11 @@ public class ProcessDefinition {
this.projectCode = projectCode;
}
public int getWarningGroupId() {
public Integer getWarningGroupId() {
return warningGroupId;
}
public void setWarningGroupId(int warningGroupId) {
public void setWarningGroupId(Integer warningGroupId) {
this.warningGroupId = warningGroupId;
}

2
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/utils/WorkflowUtils.java

@ -34,7 +34,7 @@ public class WorkflowUtils {
* @return workflow duration
*/
public static String getWorkflowInstanceDuration (ProcessInstance processInstance) {
return processInstance.getState() != null && processInstance.getState().isFinished() ?
return processInstance.getState() != null && processInstance.getState().typeIsFinished() ?
DateUtils.format2Duration(processInstance.getStartTime(), processInstance.getEndTime()) :
DateUtils.format2Duration(processInstance.getStartTime(), new Date());
}

6
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/utils/WorkflowUtilsTest.java

@ -18,9 +18,9 @@
package org.apache.dolphinscheduler.dao.utils;
import java.util.Date;
import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus;
import org.apache.dolphinscheduler.common.utils.DateUtils;
import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
import org.apache.dolphinscheduler.plugin.task.api.enums.ExecutionStatus;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@ -40,11 +40,11 @@ class WorkflowUtilsTest {
System.currentTimeMillis();
Assertions.assertNotEquals("1d 1h 10m 10s", noStateDuration);
processInstance.setState(WorkflowExecutionStatus.RUNNING_EXECUTION);
processInstance.setState(ExecutionStatus.RUNNING_EXECUTION);
String notFinishDuration = WorkflowUtils.getWorkflowInstanceDuration(processInstance);
Assertions.assertNotEquals("1d 1h 10m 10s", notFinishDuration);
processInstance.setState(WorkflowExecutionStatus.SUCCESS);
processInstance.setState(ExecutionStatus.SUCCESS);
String successDuration = WorkflowUtils.getWorkflowInstanceDuration(processInstance);
Assertions.assertEquals("1d 1h 10m 10s", successDuration);
}

Loading…
Cancel
Save