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