Unverified Commit bc9e32b0 authored by aiwenmo's avatar aiwenmo Committed by GitHub

[Optimization-2703][studio] Optimize online debug task (#2704)

* [Optimization-2703][studio] Optimize online debug task * add selection * optimize result refresh --------- Co-authored-by: 's avatarwenmo <32723967+wenmo@users.noreply.github.com>
parent 64bb8ae4
......@@ -22,7 +22,6 @@ package org.dinky.controller;
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;
......@@ -96,8 +95,8 @@ public class TaskController {
dataType = "DebugDTO",
paramType = "body")
@ExecuteProcess(type = ProcessType.FLINK_SUBMIT)
public Result<JobResult> debugTask(@RequestBody DebugDTO debugDTO) throws Exception {
JobResult result = taskService.debugTask(debugDTO);
public Result<JobResult> debugTask(@RequestBody TaskDTO task) throws Exception {
JobResult result = taskService.debugTask(task);
if (result.isSuccess()) {
return Result.succeed(result, Status.DEBUG_SUCCESS);
}
......
......@@ -57,7 +57,7 @@ public class TaskDTO extends AbstractStatementDTO {
@ApiModelProperty(
value = "Run Mode",
dataType = "String",
example = "BATCH",
example = "Local",
notes = "The execution mode for the SQL query")
private String type;
......@@ -199,14 +199,14 @@ public class TaskDTO extends AbstractStatementDTO {
dataType = "boolean",
example = "false",
notes = "Flagindicatingwhethertousechangelogs")
private boolean useChangeLog;
private boolean useChangeLog = false;
@ApiModelProperty(
value = "Use Auto Cancel",
dataType = "boolean",
example = "false",
notes = "Flag indicating whether to use auto-canceling")
private boolean useAutoCancel;
private boolean useAutoCancel = true;
@ApiModelProperty(value = "Session", dataType = "String", example = "session_id", notes = "The session identifier")
private String session;
......@@ -219,7 +219,7 @@ public class TaskDTO extends AbstractStatementDTO {
dataType = "Integer",
example = "100",
notes = "The maximum number of rows to return")
private Integer maxRowNum;
private Integer maxRowNum = 100;
public JobConfig getJobConfig() {
......
......@@ -20,7 +20,6 @@
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;
......@@ -75,11 +74,11 @@ public interface TaskService extends ISuperService<Task> {
/**
* Debug the given task and return the job result.
*
* @param debugDTO The param of preview task.
* @param task The param of preview task.
* @return A {@link JobResult} object representing the result of the submitted task.
* @throws ExcuteException If there is an error debugging the task.
*/
JobResult debugTask(DebugDTO debugDTO) throws Exception;
JobResult debugTask(TaskDTO task) throws Exception;
/**
* Restart the given task and return the job result.
......
......@@ -26,7 +26,6 @@ import org.dinky.data.annotations.ProcessStep;
import org.dinky.data.app.AppParamConfig;
import org.dinky.data.constant.CommonConstant;
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;
......@@ -204,6 +203,9 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
// Submit and export task
@ProcessStep(type = ProcessStepType.SUBMIT_BUILD_CONFIG)
public JobConfig buildJobSubmitConfig(TaskDTO task) {
if (Asserts.isNull(task.getType())) {
task.setType(GatewayType.LOCAL.getLongValue());
}
task.setStatement(buildEnvSql(task) + task.getStatement());
JobConfig config = task.getJobConfig();
Savepoints savepoints = savepointsService.getSavePointWithStrategy(task);
......@@ -238,6 +240,9 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
// Savepoint and cancel task
@ProcessStep(type = ProcessStepType.SUBMIT_BUILD_CONFIG)
public JobConfig buildJobConfig(TaskDTO task) {
if (Asserts.isNull(task.getType())) {
task.setType(GatewayType.LOCAL.getLongValue());
}
JobConfig config = task.getJobConfig();
if (GatewayType.get(task.getType()).isDeployCluster()) {
log.info("Init gateway config, type:{}", task.getType());
......@@ -317,24 +322,18 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
@Override
@ProcessStep(type = ProcessStepType.SUBMIT_TASK)
public JobResult debugTask(DebugDTO debugDTO) throws Exception {
initTenantByTaskId(debugDTO.getId());
TaskDTO taskDTO = this.getTaskInfoById(debugDTO.getId());
public JobResult debugTask(TaskDTO task) throws Exception {
// Debug mode need return result
taskDTO.setUseResult(true);
taskDTO.setUseChangeLog(debugDTO.isUseChangeLog());
taskDTO.setUseAutoCancel(debugDTO.isUseAutoCancel());
taskDTO.setMaxRowNum(debugDTO.getMaxRowNum());
task.setUseResult(true);
// Debug mode need execute
taskDTO.setStatementSet(false);
task.setStatementSet(false);
// 注解自调用会失效,这里通过获取对象方法绕过此限制
TaskServiceImpl taskServiceBean = applicationContext.getBean(TaskServiceImpl.class);
JobResult jobResult = taskServiceBean.executeJob(taskDTO);
JobResult jobResult = taskServiceBean.executeJob(task);
if (Job.JobStatus.SUCCESS == jobResult.getStatus()) {
log.info("Job debug success");
Task task = new Task(debugDTO.getId(), jobResult.getJobInstanceId());
if (!this.updateById(task)) {
Task newTask = new Task(task.getId(), jobResult.getJobInstanceId());
if (!this.updateById(newTask)) {
throw new BusException(Status.TASK_UPDATE_FAILED.getMessage());
}
} else {
......
......@@ -19,10 +19,12 @@
package org.dinky.service.task;
import org.dinky.assertion.Asserts;
import org.dinky.config.Dialect;
import org.dinky.data.annotations.SupportDialect;
import org.dinky.data.dto.TaskDTO;
import org.dinky.data.result.SqlExplainResult;
import org.dinky.gateway.enums.GatewayType;
import org.dinky.job.JobManager;
import org.dinky.job.JobResult;
import org.dinky.service.impl.TaskServiceImpl;
......@@ -42,6 +44,10 @@ public class FlinkSqlTask extends BaseTask {
public FlinkSqlTask(TaskDTO task) {
super(task);
// Default run mode is local.
if (Asserts.isNull(task.getType())) {
task.setType(GatewayType.LOCAL.getLongValue());
}
this.jobManager = getJobManager();
}
......
......@@ -23,7 +23,7 @@ import {
isDataStudioTabsItemType,
mapDispatchToProps
} from '@/pages/DataStudio/function';
import { isSql } from '@/pages/DataStudio/HeaderContainer/service';
import { isSql } from '@/pages/DataStudio/HeaderContainer/function';
import { StateType } from '@/pages/DataStudio/model';
import { handleGetOption, handleGetOptionWithoutMsg } from '@/services/BusinessCrud';
import { DIALECT } from '@/services/constants';
......@@ -126,7 +126,6 @@ const Result = (props: any) => {
return;
}
const params = currentTabs.params;
const consoleData = currentTabs.console;
if (consoleData.result && !isRefresh) {
setData(consoleData.result);
......@@ -166,7 +165,7 @@ const Result = (props: any) => {
useEffect(() => {
setData({});
loadData();
}, [currentTabs, currentTabs?.console?.result]);
}, [currentTabs?.console?.result]);
const getColumns = (columns: string[]) => {
return columns?.map((item) => {
......
......@@ -17,7 +17,6 @@
*
*/
import { isSql } from '@/pages/DataStudio/HeaderContainer/service';
import { TabsPageType, TaskDataType } from '@/pages/DataStudio/model';
import { JOB_LIFE_CYCLE, JOB_STATUS } from '@/pages/DevOps/constants';
import { DIALECT } from '@/services/constants';
......@@ -59,3 +58,25 @@ export const isCanPushDolphin = (data: TaskDataType | undefined) => {
data?.dialect?.toLowerCase() !== DIALECT.PYTHON_LONG
: false;
};
export const isSql = (dialect: string) => {
if (!dialect) {
return false;
}
switch (dialect.toLowerCase()) {
case DIALECT.SQL:
case DIALECT.MYSQL:
case DIALECT.ORACLE:
case DIALECT.SQLSERVER:
case DIALECT.POSTGRESQL:
case DIALECT.CLICKHOUSE:
case DIALECT.PHOENIX:
case DIALECT.DORIS:
case DIALECT.HIVE:
case DIALECT.STARROCKS:
case DIALECT.PRESTO:
return true;
default:
return false;
}
};
......@@ -28,7 +28,8 @@ import {
isCanPushDolphin,
isOnline,
isRunning,
projectCommonShow
projectCommonShow,
isSql
} from '@/pages/DataStudio/HeaderContainer/function';
import PushDolphin from '@/pages/DataStudio/HeaderContainer/PushDolphin';
import {
......@@ -36,8 +37,7 @@ import {
changeTaskLife,
debugTask,
executeSql,
getJobPlan,
isSql
getJobPlan
} from '@/pages/DataStudio/HeaderContainer/service';
import {
DataStudioTabsItemType,
......@@ -189,9 +189,17 @@ const HeaderContainer = (props: connect) => {
const handlerDebug = async () => {
if (!currentData) return;
let selectsql = null;
if (currentTab.editorInstance) {
selectsql = currentTab.editorInstance.getModel().getValueInRange(currentTab.editorInstance.getSelection());
}
if (selectsql == null || selectsql == '') {
selectsql = currentData.statement;
}
const res = await debugTask(
l('pages.datastudio.editor.debugging', '', { jobName: currentData.name }),
currentData
{...currentData, statement: selectsql}
);
if (!res) return;
......@@ -203,6 +211,10 @@ const HeaderContainer = (props: connect) => {
});
await SuccessMessageAsync(l('pages.datastudio.editor.debug.success'));
currentData.status = JOB_STATUS.RUNNING;
// Common sql task is synchronized, so it needs to automatically update the status to finished.
if (isSql(currentData.dialect)) {
currentData.status = JOB_STATUS.FINISHED;
}
if (currentTab) currentTab.console.result = res.data.result;
saveTabs({ ...props.tabs });
};
......@@ -380,7 +392,7 @@ const HeaderContainer = (props: connect) => {
currentTab?.type == TabsPageType.project &&
!isRunning(currentData) &&
(currentTab?.subType?.toLowerCase() === DIALECT.FLINK_SQL ||
currentTab?.subType?.toLowerCase() === DIALECT.FLINKJAR),
isSql(currentTab?.subType?.toLowerCase())),
props: {
style: { background: '#52c41a' },
type: 'primary'
......
......@@ -43,25 +43,3 @@ export function cancelTask(title: string, id: number) {
export function changeTaskLife(title = '', id: number, life: number) {
return handleGetOption('api/task/changeTaskLife', title, { taskId: id, lifeCycle: life });
}
export const isSql = (dialect: string) => {
if (!dialect) {
return false;
}
switch (dialect.toLowerCase()) {
case DIALECT.SQL:
case DIALECT.MYSQL:
case DIALECT.ORACLE:
case DIALECT.SQLSERVER:
case DIALECT.POSTGRESQL:
case DIALECT.CLICKHOUSE:
case DIALECT.PHOENIX:
case DIALECT.DORIS:
case DIALECT.HIVE:
case DIALECT.STARROCKS:
case DIALECT.PRESTO:
return true;
default:
return false;
}
};
......@@ -18,7 +18,7 @@
*/
import { getCurrentData } from '@/pages/DataStudio/function';
import { isSql } from '@/pages/DataStudio/HeaderContainer/service';
import { isSql } from '@/pages/DataStudio/HeaderContainer/function';
import { BtnRoute, useTasksDispatch } from '@/pages/DataStudio/LeftContainer/BtnContext';
import { TableDataNode } from '@/pages/DataStudio/LeftContainer/Catalog/data';
import { StateType } from '@/pages/DataStudio/model';
......
......@@ -18,7 +18,7 @@
*/
import { LeftBottomKey, RightMenuKey } from '@/pages/DataStudio/data.d';
import { isSql } from '@/pages/DataStudio/HeaderContainer/service';
import { isSql } from '@/pages/DataStudio/HeaderContainer/function';
import { getTabIcon } from '@/pages/DataStudio/MiddleContainer/function';
import { DIALECT } from '@/services/constants';
import { Catalogue } from '@/types/Studio/data.d';
......
......@@ -106,6 +106,7 @@ const StudioEditor: React.FC<EditorProps & connect> = (props) => {
editor.focus();
editorInstance.current = editor;
tabsItem.monacoInstance = monaco;
tabsItem.editorInstance = editor;
editor.onDidChangeCursorPosition((e) => {
props.footContainer.codePosition = [e.position.lineNumber, e.position.column];
......@@ -143,7 +144,7 @@ const StudioEditor: React.FC<EditorProps & connect> = (props) => {
/>
<CodeEdit
monacoRef={tabsItem?.monacoInstance}
editorRef={editorInstance}
editorRef={tabsItem?.editorInstance}
code={tabsItem?.params?.taskData?.statement}
language={matchLanguage(tabsItem?.subType)}
editorDidMount={editorDidMount}
......
......@@ -164,6 +164,7 @@ export interface TabsItemType {
closable: boolean;
path: string[];
monacoInstance: React.RefObject<Monaco | undefined>;
editorInstance: editor.IStandaloneCodeEditor | undefined;
console: ConsoleType;
isModified: boolean;
}
......
......@@ -25,7 +25,7 @@ import Result from '@/pages/DataStudio/BottomContainer/Result';
import JsonToSql from '@/pages/DataStudio/BottomContainer/Tools/JsonToSql';
import TextComparison from '@/pages/DataStudio/BottomContainer/Tools/TextComparison';
import { LeftBottomKey, LeftMenuKey, RightMenuKey } from '@/pages/DataStudio/data.d';
import { isSql } from '@/pages/DataStudio/HeaderContainer/service';
import { isSql } from '@/pages/DataStudio/HeaderContainer/function';
import Catalog from '@/pages/DataStudio/LeftContainer/Catalog';
import DataSource from '@/pages/DataStudio/LeftContainer/DataSource';
import GlobalVariable from '@/pages/DataStudio/LeftContainer/GlobaleVar';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment