Skip to content

Commit

Permalink
[Optimization-2703][studio] Optimize online debug task (#2704)
Browse files Browse the repository at this point in the history
* [Optimization-2703][studio] Optimize online debug task

* add selection

* optimize result refresh

---------

Co-authored-by: wenmo <[email protected]>
  • Loading branch information
aiwenmo and aiwenmo authored Dec 21, 2023
1 parent 64bb8ae commit bc9e32b
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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;
Expand Down Expand Up @@ -96,8 +95,8 @@ public Result<JobResult> submitTask(@ProcessId @RequestParam Integer id) throws
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);
}
Expand Down
8 changes: 4 additions & 4 deletions dinky-admin/src/main/java/org/dinky/data/dto/TaskDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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() {

Expand Down
5 changes: 2 additions & 3 deletions dinky-admin/src/main/java/org/dinky/service/TaskService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
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;
Expand Down Expand Up @@ -204,6 +203,9 @@ public JobResult executeJob(TaskDTO task) throws Exception {
// 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);
Expand Down Expand Up @@ -238,6 +240,9 @@ public JobConfig buildJobSubmitConfig(TaskDTO task) {
// 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());
Expand Down Expand Up @@ -317,24 +322,18 @@ public JobResult submitTask(TaskSubmitDto submitDto) throws Exception {

@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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -126,7 +126,6 @@ const Result = (props: any) => {
return;
}

const params = currentTabs.params;
const consoleData = currentTabs.console;
if (consoleData.result && !isRefresh) {
setData(consoleData.result);
Expand Down Expand Up @@ -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) => {
Expand Down
23 changes: 22 additions & 1 deletion dinky-web/src/pages/DataStudio/HeaderContainer/function.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
};
22 changes: 17 additions & 5 deletions dinky-web/src/pages/DataStudio/HeaderContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ import {
isCanPushDolphin,
isOnline,
isRunning,
projectCommonShow
projectCommonShow,
isSql
} from '@/pages/DataStudio/HeaderContainer/function';
import PushDolphin from '@/pages/DataStudio/HeaderContainer/PushDolphin';
import {
cancelTask,
changeTaskLife,
debugTask,
executeSql,
getJobPlan,
isSql
getJobPlan
} from '@/pages/DataStudio/HeaderContainer/service';
import {
DataStudioTabsItemType,
Expand Down Expand Up @@ -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;
Expand All @@ -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 });
};
Expand Down Expand Up @@ -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'
Expand Down
22 changes: 0 additions & 22 deletions dinky-web/src/pages/DataStudio/HeaderContainer/service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions dinky-web/src/pages/DataStudio/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export interface TabsItemType {
closable: boolean;
path: string[];
monacoInstance: React.RefObject<Monaco | undefined>;
editorInstance: editor.IStandaloneCodeEditor | undefined;
console: ConsoleType;
isModified: boolean;
}
Expand Down
2 changes: 1 addition & 1 deletion dinky-web/src/pages/DataStudio/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit bc9e32b

Please sign in to comment.