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

Add a control layer for submitting tasks to stream back results #2689

Closed
wants to merge 6 commits into from
Closed
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
51 changes: 26 additions & 25 deletions dinky-admin/src/main/java/org/dinky/controller/TaskController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@

package org.dinky.controller;

import cn.hutool.core.lang.tree.Tree;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dinky.data.annotations.ExecuteProcess;
import org.dinky.data.annotations.Log;
import org.dinky.data.annotations.ProcessId;
import org.dinky.data.dto.DebugDTO;
import org.dinky.data.dto.TaskDTO;
import org.dinky.data.dto.TaskRollbackVersionDTO;
import org.dinky.data.dto.TaskSaveDTO;
import org.dinky.data.dto.TaskSubmitDto;
import org.dinky.data.dto.*;
import org.dinky.data.enums.BusinessType;
import org.dinky.data.enums.JobLifeCycle;
import org.dinky.data.enums.ProcessType;
Expand All @@ -41,27 +45,10 @@
import org.dinky.gateway.result.SavePointResult;
import org.dinky.job.JobResult;
import org.dinky.service.TaskService;

import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

import cn.hutool.core.lang.tree.Tree;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.util.List;

@Slf4j
@RestController
Expand All @@ -72,10 +59,24 @@ public class TaskController {

private final TaskService taskService;

@GetMapping("/submitTask")
@GetMapping("/submitTask2")
@ApiOperation("Submit Task")
@Log(title = "Submit Task", businessType = BusinessType.SUBMIT)
@ExecuteProcess(type = ProcessType.FLINK_SUBMIT)
public Result<JobResult> submitTask2(@ProcessId @RequestParam Integer id) throws Exception {
JobResult jobResult =
Comment on lines +66 to +67
Copy link
Contributor

Choose a reason for hiding this comment

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

You should extend method named debugTask.

taskService.submitTask2(TaskSubmitDto.builder().id(id).build());
if (jobResult.isSuccess()) {
return Result.succeed(jobResult, Status.EXECUTE_SUCCESS);
} else {
return Result.failed(jobResult, jobResult.getError());
}
}

@GetMapping("/submitTask")
@ApiOperation("Submit Task")
@Log(title = "Submit Task", businessType = BusinessType.SUBMIT)
@ExecuteProcess(type = ProcessType.SQL_SUBMIT)
public Result<JobResult> submitTask(@ProcessId @RequestParam Integer id) throws Exception {
JobResult jobResult =
taskService.submitTask(TaskSubmitDto.builder().id(id).build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,7 @@ public interface DataBaseService extends ISuperService<DataBase> {
*/
JobResult executeCommonSql(SqlDTO sqlDTO);

JobResult executeCommonSql2(SqlDTO sqlDTO);

List<DataBase> selectListByKeyWord(String keyword);
}
25 changes: 13 additions & 12 deletions dinky-admin/src/main/java/org/dinky/service/TaskService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@

package org.dinky.service;

import org.dinky.data.dto.AbstractStatementDTO;
import org.dinky.data.dto.DebugDTO;
import org.dinky.data.dto.TaskDTO;
import org.dinky.data.dto.TaskRollbackVersionDTO;
import org.dinky.data.dto.TaskSubmitDto;
import cn.hutool.core.lang.tree.Tree;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.dinky.data.dto.*;
import org.dinky.data.enums.JobLifeCycle;
import org.dinky.data.exception.ExcuteException;
import org.dinky.data.exception.NotSupportExplainExcepition;
Expand All @@ -38,15 +37,9 @@
import org.dinky.gateway.result.SavePointResult;
import org.dinky.job.JobResult;
import org.dinky.mybatis.service.ISuperService;

import java.util.List;

import org.springframework.web.multipart.MultipartFile;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

import cn.hutool.core.lang.tree.Tree;
import java.util.List;

/**
* 作业 服务类
Expand All @@ -71,6 +64,14 @@ public interface TaskService extends ISuperService<Task> {
* @throws ExcuteException If there is an error executing the task.
*/
JobResult submitTask(TaskSubmitDto submitDto) throws Exception;
/**
* Submit the given task and return the job result.
*
* @param submitDto The param of the task to submit.
* @return A {@link JobResult} object representing the result of the submitted task.
* @throws ExcuteException If there is an error executing the task.
*/
JobResult submitTask2(TaskSubmitDto submitDto) throws Exception;

/**
* Debug the given task and return the job result.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,35 @@

package org.dinky.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.dinky.assertion.Asserts;
import org.dinky.context.ResultSetHolder;
import org.dinky.data.annotations.ProcessStep;
import org.dinky.data.constant.CommonConstant;
import org.dinky.data.dto.DataBaseDTO;
import org.dinky.data.dto.SqlDTO;
import org.dinky.data.dto.TaskDTO;
import org.dinky.data.enums.ProcessStepType;
import org.dinky.data.enums.Status;
import org.dinky.data.model.Column;
import org.dinky.data.model.DataBase;
import org.dinky.data.model.QueryData;
import org.dinky.data.model.Schema;
import org.dinky.data.model.SqlGeneration;
import org.dinky.data.model.Table;
import org.dinky.data.model.*;
import org.dinky.data.result.SqlExplainResult;
import org.dinky.job.JobResult;
import org.dinky.mapper.DataBaseMapper;
import org.dinky.metadata.driver.Driver;
import org.dinky.metadata.result.JdbcSelectResult;
import org.dinky.mybatis.service.impl.SuperServiceImpl;
import org.dinky.service.DataBaseService;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.MDC;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.stream.Stream;

/**
* DataBaseServiceImpl
Expand All @@ -61,6 +56,7 @@
*/
@Service
public class DataBaseServiceImpl extends SuperServiceImpl<DataBaseMapper, DataBase> implements DataBaseService {
private ResultSetHolder resultSetHolder= ResultSetHolder.getInstances();

@Override
public String testConnect(DataBaseDTO db) {
Expand Down Expand Up @@ -295,9 +291,48 @@ public JobResult executeCommonSql(SqlDTO sqlDTO) {
result.setError(selectResult.getError());
}
result.setEndTime(LocalDateTime.now());
try (Driver driver = Driver.build(dataBase.getDriverConfig())) {
Stream<JdbcSelectResult> jdbcSelectResultStream = driver.executeSql2(sqlDTO.getStatement(), sqlDTO.getMaxRowNum());
jdbcSelectResultStream.forEach(res->{
System.out.println(res.getRowData());
});
}

return result;
}
@Override
@ProcessStep(type = ProcessStepType.SUBMIT_EXECUTE_COMMON_SQL)
public JobResult executeCommonSql2(SqlDTO sqlDTO) {
JobResult result = new JobResult();
result.setStatement(sqlDTO.getStatement());
result.setStartTime(LocalDateTime.now());

if (Asserts.isNull(sqlDTO.getDatabaseId())) {
result.setSuccess(false);
result.setError("please assign data source");
result.setEndTime(LocalDateTime.now());
return result;
}

DataBase dataBase = getById(sqlDTO.getDatabaseId());
if (Asserts.isNull(dataBase)) {
result.setSuccess(false);
result.setError("data source not exist.");
result.setEndTime(LocalDateTime.now());
return result;
}
List<JdbcSelectResult> SelectResult= new ArrayList<>();
try (Driver driver = Driver.build(dataBase.getDriverConfig())) {
Stream<JdbcSelectResult> jdbcSelectResultStream = driver.executeSql2(sqlDTO.getStatement(), sqlDTO.getMaxRowNum());
jdbcSelectResultStream.forEach(res->{
String processName = MDC.get("PROCESS_NAME");
resultSetHolder.append(processName,res);
SelectResult.add(res);
});
}
result.setResultList(SelectResult);
return result;
}
/**
* @param keyword
* @return
Expand Down
Loading
Loading