Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
DolphinScheduler
提交
ce5e32d7
DolphinScheduler
项目概览
apache
/
DolphinScheduler
上一次同步 1 年多
通知
704
Star
9572
Fork
3514
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
DolphinScheduler
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
ce5e32d7
编写于
11月 07, 2022
作者:
E
Eric Gao
提交者:
GitHub
11月 07, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Fix-#11669][Workflow Instance Page] Fix the duration in Workflow Instance page. (#12264) (#12788)
Co-authored-by:
N
Yann Ann
<
xiaoqiang.yann@gmail.com
>
上级
92e50273
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
130 addition
and
4 deletion
+130
-4
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java
...cheduler/api/service/impl/ProcessInstanceServiceImpl.java
+2
-1
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java
...phinscheduler/api/service/ProcessInstanceServiceTest.java
+20
-0
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java
...a/org/apache/dolphinscheduler/common/utils/DateUtils.java
+11
-3
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/DateUtilsTest.java
...g/apache/dolphinscheduler/common/utils/DateUtilsTest.java
+3
-0
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/utils/WorkflowUtils.java
.../org/apache/dolphinscheduler/dao/utils/WorkflowUtils.java
+43
-0
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/utils/WorkflowUtilsTest.java
.../apache/dolphinscheduler/dao/utils/WorkflowUtilsTest.java
+51
-0
未找到文件。
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java
浏览文件 @
ce5e32d7
...
...
@@ -65,6 +65,7 @@ import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper;
import
org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper
;
import
org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper
;
import
org.apache.dolphinscheduler.dao.mapper.TenantMapper
;
import
org.apache.dolphinscheduler.dao.utils.WorkflowUtils
;
import
org.apache.dolphinscheduler.plugin.task.api.enums.DependResult
;
import
org.apache.dolphinscheduler.plugin.task.api.enums.ExecutionStatus
;
import
org.apache.dolphinscheduler.plugin.task.api.model.Property
;
...
...
@@ -291,7 +292,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce
}
for
(
ProcessInstance
processInstance
:
processInstances
)
{
processInstance
.
setDuration
(
DateUtils
.
format2Duration
(
processInstance
.
getStartTime
(),
processInstance
.
getEndTime
()
));
processInstance
.
setDuration
(
WorkflowUtils
.
getWorkflowInstanceDuration
(
processInstance
));
User
executor
=
idToUserMap
.
get
(
processInstance
.
getExecutorId
());
if
(
null
!=
executor
)
{
processInstance
.
setExecutorName
(
executor
.
getUserName
());
...
...
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java
浏览文件 @
ce5e32d7
...
...
@@ -297,6 +297,11 @@ public class ProcessInstanceServiceTest {
WorkerGroup
workerGroup
=
getWorkGroup
();
Map
<
String
,
Object
>
workerExistRes
=
processInstanceService
.
queryProcessInstanceById
(
loginUser
,
projectCode
,
1
);
Assert
.
assertEquals
(
Status
.
SUCCESS
,
workerExistRes
.
get
(
Constants
.
STATUS
));
when
(
processService
.
findProcessDefinition
(
processInstance
.
getProcessDefinitionCode
(),
processInstance
.
getProcessDefinitionVersion
())).
thenReturn
(
null
);;
workerExistRes
=
processInstanceService
.
queryProcessInstanceById
(
loginUser
,
projectCode
,
1
);
Assert
.
assertEquals
(
Status
.
PROCESS_DEFINE_NOT_EXIST
,
workerExistRes
.
get
(
Constants
.
STATUS
));
}
@Test
...
...
@@ -343,6 +348,11 @@ public class ProcessInstanceServiceTest {
Map
<
String
,
DependResult
>
resultMap
=
processInstanceService
.
parseLogForDependentResult
(
logString
);
Assert
.
assertEquals
(
1
,
resultMap
.
size
());
resultMap
.
clear
();
resultMap
=
processInstanceService
.
parseLogForDependentResult
(
""
);
Assert
.
assertEquals
(
0
,
resultMap
.
size
());
}
@Test
...
...
@@ -379,6 +389,7 @@ public class ProcessInstanceServiceTest {
Map
<
String
,
Object
>
notSubprocessRes
=
processInstanceService
.
querySubProcessInstanceByTaskId
(
loginUser
,
projectCode
,
1
);
Assert
.
assertEquals
(
Status
.
TASK_INSTANCE_NOT_SUB_WORKFLOW_INSTANCE
,
notSubprocessRes
.
get
(
Constants
.
STATUS
));
//sub process not exist
TaskInstance
subTask
=
getTaskInstance
();
subTask
.
setTaskType
(
"SUB_PROCESS"
);
...
...
@@ -533,6 +544,11 @@ public class ProcessInstanceServiceTest {
when
(
processInstanceMapper
.
queryDetailById
(
1
)).
thenReturn
(
processInstance
);
Map
<
String
,
Object
>
successRes
=
processInstanceService
.
viewVariables
(
1L
,
1
);
Assert
.
assertEquals
(
Status
.
SUCCESS
,
successRes
.
get
(
Constants
.
STATUS
));
when
(
processInstanceMapper
.
queryDetailById
(
1
)).
thenReturn
(
null
);
Map
<
String
,
Object
>
processNotExist
=
processInstanceService
.
viewVariables
(
1L
,
1
);
Assert
.
assertEquals
(
Status
.
PROCESS_INSTANCE_NOT_EXIST
,
processNotExist
.
get
(
Constants
.
STATUS
));
}
@Test
...
...
@@ -558,6 +574,10 @@ public class ProcessInstanceServiceTest {
Map
<
String
,
Object
>
successRes
=
processInstanceService
.
viewGantt
(
0L
,
1
);
Assert
.
assertEquals
(
Status
.
SUCCESS
,
successRes
.
get
(
Constants
.
STATUS
));
when
(
processInstanceMapper
.
queryDetailById
(
1
)).
thenReturn
(
null
);
Map
<
String
,
Object
>
processNotExist
=
processInstanceService
.
viewVariables
(
1L
,
1
);
Assert
.
assertEquals
(
Status
.
PROCESS_INSTANCE_NOT_EXIST
,
processNotExist
.
get
(
Constants
.
STATUS
));
}
/**
...
...
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java
浏览文件 @
ce5e32d7
...
...
@@ -333,11 +333,19 @@ public final class DateUtils {
* @param d2 d2
* @return format time
*/
public
static
String
format2Duration
(
Date
d1
,
Date
d2
)
{
if
(
d1
==
null
||
d2
==
null
)
{
public
static
String
format2Duration
(
Date
start
,
Date
end
)
{
if
(
start
==
null
)
{
return
null
;
}
if
(
end
==
null
)
{
end
=
new
Date
();
}
if
(
start
.
after
(
end
))
{
logger
.
warn
(
"start Time {} is later than end Time {}"
,
start
,
end
);
return
null
;
}
return
format2Duration
(
differMs
(
d1
,
d2
));
return
format2Duration
(
differMs
(
start
,
end
));
}
/**
...
...
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/DateUtilsTest.java
浏览文件 @
ce5e32d7
...
...
@@ -176,6 +176,9 @@ public class DateUtilsTest {
String
duration
=
DateUtils
.
format2Duration
(
d2
,
d1
);
Assert
.
assertEquals
(
"1d 1h 10m 10s"
,
duration
);
duration
=
DateUtils
.
format2Duration
(
d2
,
d1
);
Assert
.
assertNull
(
duration
);
// hours minutes seconds
d1
=
DateUtils
.
stringToDate
(
"2020-01-20 11:00:00"
);
d2
=
DateUtils
.
stringToDate
(
"2020-01-20 12:10:10"
);
...
...
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/utils/WorkflowUtils.java
0 → 100644
浏览文件 @
ce5e32d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.dolphinscheduler.dao.utils
;
import
java.util.Date
;
import
org.apache.dolphinscheduler.common.utils.DateUtils
;
import
org.apache.dolphinscheduler.dao.entity.ProcessInstance
;
/**
* workflow utils
*/
public
class
WorkflowUtils
{
/**
* get workflow duration
* if processInstance is running, the endTime will be the current time
*
* @param processInstance workflow instance
* @return workflow duration
*/
public
static
String
getWorkflowInstanceDuration
(
ProcessInstance
processInstance
)
{
return
processInstance
.
getState
()
!=
null
&&
processInstance
.
getState
().
isFinished
()
?
DateUtils
.
format2Duration
(
processInstance
.
getStartTime
(),
processInstance
.
getEndTime
())
:
DateUtils
.
format2Duration
(
processInstance
.
getStartTime
(),
new
Date
());
}
}
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/utils/WorkflowUtilsTest.java
0 → 100644
浏览文件 @
ce5e32d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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.junit.jupiter.api.Assertions
;
import
org.junit.jupiter.api.Test
;
class
WorkflowUtilsTest
{
@Test
public
void
testGetWorkflowInstanceDuration
()
{
ProcessInstance
processInstance
=
new
ProcessInstance
();
processInstance
.
setId
(
1
);
processInstance
.
setState
(
null
);
Date
start
=
DateUtils
.
stringToDate
(
"2020-01-20 11:00:00"
);
Date
end
=
DateUtils
.
stringToDate
(
"2020-01-21 12:10:10"
);
processInstance
.
setStartTime
(
start
);
processInstance
.
setEndTime
(
end
);
String
noStateDuration
=
WorkflowUtils
.
getWorkflowInstanceDuration
(
processInstance
);
System
.
currentTimeMillis
();
Assertions
.
assertNotEquals
(
"1d 1h 10m 10s"
,
noStateDuration
);
processInstance
.
setState
(
WorkflowExecutionStatus
.
RUNNING_EXECUTION
);
String
notFinishDuration
=
WorkflowUtils
.
getWorkflowInstanceDuration
(
processInstance
);
Assertions
.
assertNotEquals
(
"1d 1h 10m 10s"
,
notFinishDuration
);
processInstance
.
setState
(
WorkflowExecutionStatus
.
SUCCESS
);
String
successDuration
=
WorkflowUtils
.
getWorkflowInstanceDuration
(
processInstance
);
Assertions
.
assertEquals
(
"1d 1h 10m 10s"
,
successDuration
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录