-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
ProcessInstanceMapper.xml
364 lines (350 loc) · 14.2 KB
/
ProcessInstanceMapper.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
<?xml version="1.0" encoding="UTF-8" ?>
<!--
~ 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.
-->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper">
<sql id="baseSql">
id
, name, process_definition_version, process_definition_code, project_code, state, recovery, start_time, end_time, run_times,host,
command_type, command_param, task_depend_type, max_try_times, failure_strategy, warning_type,
warning_group_id, schedule_time, command_start_time, global_params, flag,
update_time, is_sub_process, executor_id, history_cmd,
process_instance_priority, worker_group,environment_code, timeout, tenant_code, var_pool,
dry_run, test_flag, next_process_instance_id, restart_time, state_history
</sql>
<select id="queryDetailById" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select
<include refid="baseSql"/>
from t_ds_process_instance
where id = #{processId}
</select>
<select id="queryByHostAndStatus" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select
<include refid="baseSql"/>
from t_ds_process_instance
where 1=1
<if test="host != null and host != ''">
and host=#{host}
</if>
<if test="states != null and states.length != 0">
and state in
<foreach collection="states" item="i" open="(" close=")" separator=",">
#{i}
</foreach>
</if>
order by id asc
</select>
<select id="queryNeedFailoverProcessInstanceHost" resultType="String">
select distinct host
from t_ds_process_instance
<if test="states != null and states.length != 0">
where state in
<foreach collection="states" item="i" open="(" close=")" separator=",">
#{i}
</foreach>
</if>
</select>
<select id="queryTopNProcessInstance" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select
<include refid="baseSql"/>
from t_ds_process_instance
where state = #{status}
<if test="projectCode != 0">
and project_code = #{projectCode}
</if>
and start_time between
#{startTime} and #{endTime}
order by end_time-start_time desc
limit #{size}
</select>
<select id="queryByTenantCodeAndStatus" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select
<include refid="baseSql"/>
from t_ds_process_instance
where 1=1
<if test="tenantCode != ''">
and tenant_code =#{tenantCode}
</if>
<if test="states != null and states.length != 0">
and state in
<foreach collection="states" item="i" open="(" close=")" separator=",">
#{i}
</foreach>
</if>
order by id asc
</select>
<select id="queryByWorkerGroupNameAndStatus" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select
<include refid="baseSql"/>
from t_ds_process_instance
where 1=1
<if test="workerGroupName != ''">
and worker_group =#{workerGroupName}
</if>
<if test="states != null and states.length != 0">
and state in
<foreach collection="states" item="i" open="(" close=")" separator=",">
#{i}
</foreach>
</if>
order by id asc
</select>
<select id="queryProcessInstanceListPaging" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select
<include refid="baseSql"/>
from t_ds_process_instance
where is_sub_process=0
and project_code = #{projectCode}
<if test="processDefinitionCode != 0">
and process_definition_code = #{processDefinitionCode}
</if>
<if test="searchVal != null and searchVal != ''">
and name like concat('%', #{searchVal}, '%')
</if>
<if test="startTime != null">
and start_time <![CDATA[ >= ]]> #{startTime}
</if>
<if test="endTime != null">
and start_time <![CDATA[ <= ]]> #{endTime}
</if>
<if test="states != null and states.length > 0">
and state in
<foreach collection="states" index="index" item="i" open="(" separator="," close=")">
#{i}
</foreach>
</if>
<if test="host != null and host != ''">
and host like concat('%', #{host}, '%')
</if>
<if test="executorName != null and executorName != ''">
and executor_name = #{executorName}
</if>
order by start_time desc, end_time desc
</select>
<update id="setFailoverByHostAndStateArray">
update t_ds_process_instance
set host=null
where host =#{host}
<if test="states != null and states.length != 0">
and state in
<foreach collection="states" index="index" item="i" open="(" close=")" separator=",">
#{i}
</foreach>
</if>
</update>
<update id="updateProcessInstanceByState">
update t_ds_process_instance
set state = #{destState}
where state = #{originState}
</update>
<update id="updateProcessInstanceByTenantCode">
update t_ds_process_instance
set tenant_code = #{destTenantCode}
where tenant_code = #{originTenantCode}
</update>
<update id="updateProcessInstanceByWorkerGroupName">
update t_ds_process_instance
set worker_group = #{destWorkerGroupName}
where worker_group = #{originWorkerGroupName}
</update>
<select id="countWorkflowInstanceStateByProjectCodes" resultType="org.apache.dolphinscheduler.dao.model.WorkflowInstanceStatusCountDto">
select state, count(0) as count
from t_ds_process_instance
where is_sub_process = 0
<if test="startTime != null">
and start_time <![CDATA[ >= ]]> #{startTime}
</if>
<if test="endTime != null">
and start_time <![CDATA[ <= ]]> #{endTime}
</if>
<if test="projectCodes != null and projectCodes.size() != 0">
and project_code in
<foreach collection="projectCodes" index="index" item="i" open="(" close=")" separator=",">
#{i}
</foreach>
</if>
group by state
</select>
<select id="queryByProcessDefineCode" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select
<include refid="baseSql"/>
from t_ds_process_instance
where process_definition_code=#{processDefinitionCode}
order by start_time desc limit #{size}
</select>
<select id="queryLastSchedulerProcess" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select
<include refid="baseSql"/>
from t_ds_process_instance
where process_definition_code=#{processDefinitionCode} and test_flag=#{testFlag}
<if test="startTime!=null and endTime != null ">
and schedule_time <![CDATA[ >= ]]> #{startTime} and schedule_time <![CDATA[ <= ]]> #{endTime}
</if>
order by end_time desc limit 1
</select>
<select id="queryLastManualProcess" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select t1.*
from
(
select
<include refid="baseSql"/>
from t_ds_process_instance
where
process_definition_code=#{processDefinitionCode} and test_flag=#{testFlag}
and schedule_time is null
<if test="startTime!=null and endTime != null ">
and start_time <![CDATA[ >= ]]> #{startTime} and start_time <![CDATA[ <= ]]> #{endTime}
</if>
) as t1
<if test="taskCode != null and taskCode!=0 and taskCode!=-1">
inner join
t_ds_task_instance as t2
on t1.id = t2.process_instance_id and t2.task_code=#{taskCode}
</if>
order by t1.end_time desc limit 1
</select>
<select id="queryFirstScheduleProcessInstance" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select
<include refid="baseSql"/>
from t_ds_process_instance
where process_definition_code = #{processDefinitionCode} and schedule_time is not null
order by schedule_time
limit 1
</select>
<select id="queryFirstStartProcessInstance" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select
<include refid="baseSql"/>
from t_ds_process_instance
where process_definition_code = #{processDefinitionCode} and start_time is not null
order by start_time
limit 1
</select>
<select id="queryByProcessDefineCodeAndStatus" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select
<include refid="baseSql"/>
from t_ds_process_instance
where process_definition_code=#{processDefinitionCode}
<if test="states != null and states.length != 0">
and state in
<foreach collection="states" item="i" open="(" close=")" separator=",">
#{i}
</foreach>
</if>
order by id asc
</select>
<select id="queryByProcessDefineCodeAndProcessDefinitionVersionAndStatusAndNextId"
resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select
<include refid="baseSql"/>
from t_ds_process_instance
where process_definition_code=#{processDefinitionCode}
and process_definition_version = #{processDefinitionVersion}
<if test="states != null and states.length != 0">
and state in
<foreach collection="states" item="i" open="(" close=")" separator=",">
#{i}
</foreach>
</if>
and next_process_instance_id=0
<if test="id != null">
and id <![CDATA[ < ]]> #{id}
</if>
order by id desc
</select>
<select id="loadNextProcess4Serial" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select
<include refid="baseSql"/>
from t_ds_process_instance
where process_definition_code=#{processDefinitionCode}
and state = #{state}
and id <![CDATA[ > ]]> #{id}
order by id asc limit 1
</select>
<select id="queryProcessInstanceListV2Paging" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
SELECT
<include refid="baseSql"/>
FROM t_ds_process_instance
where is_sub_process=0
<if test="projectCode != 0">
and project_code = #{projectCode}
</if>
<if test="processDefinitionCode != 0">
and process_definition_code = #{processDefinitionCode}
</if>
<if test="name != null and name != ''">
and name like concat('%', #{name}, '%')
</if>
<if test="startTime != null and startTime != ''">
and start_time <![CDATA[ >= ]]> #{startTime}
</if>
<if test="endTime != null and endTime != ''">
and start_time <![CDATA[ <= ]]> #{endTime}
</if>
<if test="state != null and state != ''">
and state = #{state}
</if>
<if test="host != null and host != ''">
and host like concat('%', #{host}, '%')
</if>
order by start_time desc, id desc
</select>
<select id="countInstanceStateV2" resultType="org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount">
select t.state, count(0) as count
from t_ds_process_instance t
join t_ds_process_definition d on d.code=t.process_definition_code
join t_ds_project p on p.code=d.project_code
where 1 = 1
and t.is_sub_process = 0
<if test="projectIds != null and projectIds.size() != 0">
and p.id in
<foreach collection="projectIds" index="index" item="i" open="(" close=")" separator=",">
#{i}
</foreach>
</if>
<if test="startTime != null and endTime != null">
and t.start_time <![CDATA[ >= ]]> #{startTime} and t.start_time <![CDATA[ <= ]]> #{endTime}
</if>
<if test="model >= 1">
and p.code = #{projectCode}
</if>
<if test="model >= 2">
and d.code = #{workflowCode}
</if>
group by t.state
</select>
<update id="updateGlobalParamsById">
update t_ds_process_instance
set global_params = #{globalParams}
where id = #{id}
</update>
<update id="updateNextProcessIdById">
update t_ds_process_instance
set next_process_instance_id = #{thisInstanceId}
where id = #{runningInstanceId}
and next_process_instance_id = 0
</update>
<!-- There are some columns with the same names in both tables, we use a sub-query here to avoid ambiguity-->
<select id="queryByTriggerCode" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select
<include refid="baseSql"/>
from t_ds_process_instance a
join
(select trigger_type, job_id, trigger_code from t_ds_trigger_relation) b
on a.id = b.job_id
where b.trigger_type = 0 and b.trigger_code = #{triggerCode}
</select>
</mapper>