You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
379 lines
15 KiB
379 lines
15 KiB
<?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="queryByWorkflowCodeVersionStatus" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance"> |
|
select |
|
<include refid="baseSql"/> |
|
from t_ds_process_instance |
|
where process_definition_code=#{workflowDefinitionCode} |
|
and process_definition_version = #{workflowDefinitionVersion} |
|
<if test="states != null and states.length != 0"> |
|
and state in |
|
<foreach collection="states" item="i" open="(" close=")" separator=","> |
|
#{i} |
|
</foreach> |
|
</if> |
|
</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>
|
|
|