Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature][Data Studio]add getJobInstanceByTaskName api #3822

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions dinky-admin/src/main/java/org/dinky/controller/APIController.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,19 @@ public Result<JobInstance> getJobInstanceByTaskId(@RequestParam Integer id) {
return Result.succeed(jobInstanceService.getJobInstanceByTaskId(id));
}

@GetMapping("/getJobInstanceByTaskName")
@ApiOperation("Get Job Instance By Task Id")
@ApiImplicitParam(
Copy link
Contributor

@Zzm0809 Zzm0809 Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please modify the parameter description below correctly

name = "id",
value = "Task Id",
required = true,
dataType = "Integer",
dataTypeClass = Integer.class)
public Result<JobInstance> getJobInstanceByTaskId(@RequestParam String taskName) {
taskService.initTenantByTaskName(taskName);
return Result.succeed(jobInstanceService.getJobInstanceByTaskName(taskName));
}

@GetMapping(value = "/exportSql")
@ApiOperation("Export Sql")
@Log(title = "Export Sql", businessType = BusinessType.EXPORT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public interface JobInstanceMapper extends SuperMapper<JobInstance> {

JobInstance getJobInstanceByTaskId(Integer id);

JobInstance getJobInstanceByTaskName(String taskName);

@InterceptorIgnore(tenantLine = "true")
Integer getTenantByJobInstanceId(@Param("id") Integer id);
}
3 changes: 3 additions & 0 deletions dinky-admin/src/main/java/org/dinky/mapper/TaskMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ List<Task> queryOnLineTaskByDoneStatus(
@InterceptorIgnore(tenantLine = "true")
Integer getTenantByTaskId(@Param("id") Integer id);

@InterceptorIgnore(tenantLine = "true")
Integer getTenantByTaskName(@Param("taskName") String taskName);

List<JobTypeOverView> getTaskOnlineRate();

JobModelOverview getJobStreamingOrBatchModelOverview();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public interface JobInstanceService extends ISuperService<JobInstance> {
*/
JobInstance getJobInstanceByTaskId(Integer id);

JobInstance getJobInstanceByTaskName(String taskName);

/**
* List all job instances in the system.
*
Expand Down
6 changes: 6 additions & 0 deletions dinky-admin/src/main/java/org/dinky/service/TaskService.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ public interface TaskService extends ISuperService<Task> {
*/
void initTenantByTaskId(Integer id);

/**
* Initialize the tenant by task name.
* @param taskName task name
*/
void initTenantByTaskName(String taskName);

/**
* Change the life cycle of the given task.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ public JobInstance getJobInstanceByTaskId(Integer id) {
return baseMapper.getJobInstanceByTaskId(id);
}

@Override
public JobInstance getJobInstanceByTaskName(String taskName) {
return baseMapper.getJobInstanceByTaskName(taskName);
}

@Override
public ProTableResult<JobInstanceVo> listJobInstances(JsonNode para) {
int current = para.has("current") ? para.get("current").asInt() : 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,14 @@ public void initTenantByTaskId(Integer id) {
log.info("Init task tenan finished..");
}

@Override
public void initTenantByTaskName(String taskName) {
Integer tenantId = baseMapper.getTenantByTaskName(taskName);
Asserts.checkNull(tenantId, Status.TASK_NOT_EXIST.getMessage());
TenantContextHolder.set(tenantId);
log.info("Init task tenant finished..");
}

@Override
@Transactional(rollbackFor = Exception.class)
public boolean changeTaskLifeRecyle(Integer taskId, JobLifeCycle lifeCycle) throws SqlExplainExcepition {
Expand Down
7 changes: 7 additions & 0 deletions dinky-admin/src/main/resources/mapper/JobInstanceMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@
order by id desc limit 1
</select>

<select id="getJobInstanceByTaskName" resultType="org.dinky.data.model.job.JobInstance">
select *
from dinky_job_instance
where name = #{taskName}
order by id desc limit 1
Copy link
Contributor

@Zzm0809 Zzm0809 Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is your need to get the latest task execution instance? Or do you just need to get any one?

</select>

<select id="getTenantByJobInstanceId" resultType="java.lang.Integer">
select tenant_id
from dinky_job_instance
Expand Down
6 changes: 6 additions & 0 deletions dinky-admin/src/main/resources/mapper/TaskMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
where id = #{id}
</select>

<select id="getTenantByTaskName" resultType="java.lang.Integer">
select tenant_id
from dinky_task
where name = #{taskName}
</select>

<select id="queryOnLineTaskByDoneStatus" resultType="org.dinky.data.model.Task">
select t.id as id, t.name as name
from dinky_task t
Expand Down
Loading