Unverified Commit 716eb700 authored by aiwenmo's avatar aiwenmo Committed by GitHub

[Optimization-1215][admin] Optimizate execute console (#1216)

parent b34a901d
...@@ -32,7 +32,7 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -32,7 +32,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import cn.dev33.satoken.SaManager; import cn.dev33.satoken.stp.StpUtil;
/** /**
* ProcessController * ProcessController
...@@ -55,6 +55,6 @@ public class ProcessController { ...@@ -55,6 +55,6 @@ public class ProcessController {
@GetMapping("/getConsoleByUserId") @GetMapping("/getConsoleByUserId")
public Result<String> getConsoleByUserId() { public Result<String> getConsoleByUserId() {
return Result.data(processService.getConsoleByUserId(SaManager.getStpLogic(null).getLoginIdAsInt())); return Result.data(processService.getConsoleByUserId(StpUtil.getLoginIdAsInt()));
} }
} }
...@@ -82,7 +82,7 @@ import com.fasterxml.jackson.databind.JsonNode; ...@@ -82,7 +82,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import cn.dev33.satoken.SaManager; import cn.dev33.satoken.stp.StpUtil;
/** /**
* StudioServiceImpl * StudioServiceImpl
...@@ -176,15 +176,19 @@ public class StudioServiceImpl implements StudioService { ...@@ -176,15 +176,19 @@ public class StudioServiceImpl implements StudioService {
} }
private JobResult executeFlinkSql(StudioExecuteDTO studioExecuteDTO) { private JobResult executeFlinkSql(StudioExecuteDTO studioExecuteDTO) {
ProcessEntity process = ProcessContextHolder.registerProcess(
ProcessEntity.init(ProcessType.FLINKEXECUTE, StpUtil.getLoginIdAsInt()));
addFlinkSQLEnv(studioExecuteDTO); addFlinkSQLEnv(studioExecuteDTO);
process.info("Initializing Flink Job Config...");
JobConfig config = studioExecuteDTO.getJobConfig(); JobConfig config = studioExecuteDTO.getJobConfig();
buildSession(config); buildSession(config);
// init UDF // init UDF
udfService.init(studioExecuteDTO.getStatement(), config); udfService.init(studioExecuteDTO.getStatement(), config);
JobManager jobManager = JobManager.build(config); JobManager jobManager = JobManager.build(config);
process.infoSuccess();
process.start();
JobResult jobResult = jobManager.executeSql(studioExecuteDTO.getStatement()); JobResult jobResult = jobManager.executeSql(studioExecuteDTO.getStatement());
process.finish();
RunTimeUtil.recovery(jobManager); RunTimeUtil.recovery(jobManager);
return jobResult; return jobResult;
} }
...@@ -200,29 +204,33 @@ public class StudioServiceImpl implements StudioService { ...@@ -200,29 +204,33 @@ public class StudioServiceImpl implements StudioService {
@Override @Override
public JobResult executeCommonSql(SqlDTO sqlDTO) { public JobResult executeCommonSql(SqlDTO sqlDTO) {
ProcessEntity process = ProcessContextHolder.registerProcess(
ProcessEntity.init(ProcessType.SQLEXECUTE, StpUtil.getLoginIdAsInt()));
JobResult result = new JobResult(); JobResult result = new JobResult();
result.setStatement(sqlDTO.getStatement()); result.setStatement(sqlDTO.getStatement());
result.setStartTimeNow(); result.setStartTimeNow();
process.info("Initializing Database Connection...");
if (Asserts.isNull(sqlDTO.getDatabaseId())) { if (Asserts.isNull(sqlDTO.getDatabaseId())) {
result.setSuccess(false); result.setSuccess(false);
result.setError("请指定数据源"); result.setError("请指定数据源");
result.setEndTimeNow(); result.setEndTimeNow();
return result; return result;
} }
DataBase dataBase = dataBaseService.getById(sqlDTO.getDatabaseId()); DataBase dataBase = dataBaseService.getById(sqlDTO.getDatabaseId());
if (Asserts.isNull(dataBase)) { if (Asserts.isNull(dataBase)) {
process.error("The database does not exist.");
result.setSuccess(false); result.setSuccess(false);
result.setError("数据源不存在"); result.setError("The database does not exist.");
result.setEndTimeNow(); result.setEndTimeNow();
return result; return result;
} }
JdbcSelectResult selectResult; JdbcSelectResult selectResult;
try (Driver driver = Driver.build(dataBase.getDriverConfig())) { try (Driver driver = Driver.build(dataBase.getDriverConfig())) {
process.infoSuccess();
process.start();
selectResult = driver.executeSql(sqlDTO.getStatement(), sqlDTO.getMaxRowNum()); selectResult = driver.executeSql(sqlDTO.getStatement(), sqlDTO.getMaxRowNum());
} }
process.finish();
result.setResult(selectResult); result.setResult(selectResult);
if (selectResult.isSuccess()) { if (selectResult.isSuccess()) {
result.setSuccess(true); result.setSuccess(true);
...@@ -256,23 +264,18 @@ public class StudioServiceImpl implements StudioService { ...@@ -256,23 +264,18 @@ public class StudioServiceImpl implements StudioService {
private List<SqlExplainResult> explainFlinkSql(StudioExecuteDTO studioExecuteDTO) { private List<SqlExplainResult> explainFlinkSql(StudioExecuteDTO studioExecuteDTO) {
ProcessEntity process = ProcessContextHolder.registerProcess( ProcessEntity process = ProcessContextHolder.registerProcess(
ProcessEntity.init(ProcessType.FLINKEXPLAIN, SaManager.getStpLogic(null).getLoginIdAsInt(), "admin")); ProcessEntity.init(ProcessType.FLINKEXPLAIN, StpUtil.getLoginIdAsInt()));
addFlinkSQLEnv(studioExecuteDTO); addFlinkSQLEnv(studioExecuteDTO);
process.info("Initializing Flink Job Config..."); process.info("Initializing Flink Job Config...");
JobConfig config = studioExecuteDTO.getJobConfig(); JobConfig config = studioExecuteDTO.getJobConfig();
// If you are using explainSql | getStreamGraph | getJobPlan, make the dialect change to local. // If you are using explainSql | getStreamGraph | getJobPlan, make the dialect change to local.
config.buildLocal(); config.buildLocal();
buildSession(config); buildSession(config);
process.infoSuccess();
process.start();
// init UDF // init UDF
udfService.init(studioExecuteDTO.getStatement(), config); udfService.init(studioExecuteDTO.getStatement(), config);
JobManager jobManager = JobManager.build(config); JobManager jobManager = JobManager.build(config);
process.infoSuccess();
process.start();
List<SqlExplainResult> sqlExplainResults = List<SqlExplainResult> sqlExplainResults =
jobManager.explainSql(studioExecuteDTO.getStatement()).getSqlExplainResults(); jobManager.explainSql(studioExecuteDTO.getStatement()).getSqlExplainResults();
process.finish(); process.finish();
...@@ -280,17 +283,27 @@ public class StudioServiceImpl implements StudioService { ...@@ -280,17 +283,27 @@ public class StudioServiceImpl implements StudioService {
} }
private List<SqlExplainResult> explainCommonSql(StudioExecuteDTO studioExecuteDTO) { private List<SqlExplainResult> explainCommonSql(StudioExecuteDTO studioExecuteDTO) {
ProcessEntity process = ProcessContextHolder.registerProcess(
ProcessEntity.init(ProcessType.SQLEXPLAIN, StpUtil.getLoginIdAsInt()));
process.info("Initializing Flink Job Config...");
if (Asserts.isNull(studioExecuteDTO.getDatabaseId())) { if (Asserts.isNull(studioExecuteDTO.getDatabaseId())) {
return Collections.singletonList(SqlExplainResult.fail(studioExecuteDTO.getStatement(), "请指定数据源")); process.error("The database does not exist.");
return Collections.singletonList(
SqlExplainResult.fail(studioExecuteDTO.getStatement(), "Please specify the database."));
} }
DataBase dataBase = dataBaseService.getById(studioExecuteDTO.getDatabaseId()); DataBase dataBase = dataBaseService.getById(studioExecuteDTO.getDatabaseId());
if (Asserts.isNull(dataBase)) { if (Asserts.isNull(dataBase)) {
return Collections.singletonList(SqlExplainResult.fail(studioExecuteDTO.getStatement(), "数据源不存在")); process.error("The database does not exist.");
return Collections.singletonList(
SqlExplainResult.fail(studioExecuteDTO.getStatement(), "The database does not exist."));
} }
try (Driver driver = Driver.build(dataBase.getDriverConfig())) { try (Driver driver = Driver.build(dataBase.getDriverConfig())) {
return driver.explain(studioExecuteDTO.getStatement()); process.infoSuccess();
process.start();
List<SqlExplainResult> explain = driver.explain(studioExecuteDTO.getStatement());
process.finish();
return explain;
} }
} }
......
...@@ -48,25 +48,23 @@ public class ProcessEntity { ...@@ -48,25 +48,23 @@ public class ProcessEntity {
private int stepIndex = 0; private int stepIndex = 0;
private List<ProcessStep> steps; private List<ProcessStep> steps;
private Integer userId; private Integer userId;
private String userName;
public static final ProcessEntity NULL_PROCESS = new ProcessEntity(); public static final ProcessEntity NULL_PROCESS = new ProcessEntity();
public ProcessEntity() { public ProcessEntity() {
} }
public ProcessEntity(String pid, String name, Integer taskId, ProcessType type, Integer userId, String userName) { public ProcessEntity(String pid, String name, Integer taskId, ProcessType type, Integer userId) {
this.pid = pid; this.pid = pid;
this.name = name; this.name = name;
this.taskId = taskId; this.taskId = taskId;
this.type = type; this.type = type;
this.userId = userId; this.userId = userId;
this.userName = userName;
} }
public ProcessEntity(String name, Integer taskId, ProcessType type, ProcessStatus status, LocalDateTime startTime, public ProcessEntity(String name, Integer taskId, ProcessType type, ProcessStatus status, LocalDateTime startTime,
LocalDateTime endTime, long time, LocalDateTime endTime, long time,
List<ProcessStep> steps, Integer userId, String userName) { List<ProcessStep> steps, Integer userId) {
this.name = name; this.name = name;
this.taskId = taskId; this.taskId = taskId;
this.type = type; this.type = type;
...@@ -76,19 +74,18 @@ public class ProcessEntity { ...@@ -76,19 +74,18 @@ public class ProcessEntity {
this.time = time; this.time = time;
this.steps = steps; this.steps = steps;
this.userId = userId; this.userId = userId;
this.userName = userName;
} }
public static ProcessEntity init(ProcessType type, Integer userId, String userName) { public static ProcessEntity init(ProcessType type, Integer userId) {
return init(type.getValue() + "_TEMP", null, type, userId, userName); return init(type.getValue() + "_TEMP", null, type, userId);
} }
public static ProcessEntity init(Integer taskId, ProcessType type, Integer userId, String userName) { public static ProcessEntity init(Integer taskId, ProcessType type, Integer userId) {
return init(type.getValue() + taskId, taskId, type, userId, userName); return init(type.getValue() + taskId, taskId, type, userId);
} }
public static ProcessEntity init(String name, Integer taskId, ProcessType type, Integer userId, String userName) { public static ProcessEntity init(String name, Integer taskId, ProcessType type, Integer userId) {
ProcessEntity process = new ProcessEntity(UUID.randomUUID().toString(), name, taskId, type, userId, userName); ProcessEntity process = new ProcessEntity(UUID.randomUUID().toString(), name, taskId, type, userId);
process.setStatus(ProcessStatus.INITIALIZING); process.setStatus(ProcessStatus.INITIALIZING);
process.setStartTime(LocalDateTime.now()); process.setStartTime(LocalDateTime.now());
process.setSteps(new ArrayList<>()); process.setSteps(new ArrayList<>());
...@@ -248,14 +245,6 @@ public class ProcessEntity { ...@@ -248,14 +245,6 @@ public class ProcessEntity {
this.userId = userId; this.userId = userId;
} }
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public List<ProcessStep> getSteps() { public List<ProcessStep> getSteps() {
return steps; return steps;
} }
......
...@@ -30,8 +30,10 @@ import com.dlink.assertion.Asserts; ...@@ -30,8 +30,10 @@ import com.dlink.assertion.Asserts;
public enum ProcessType { public enum ProcessType {
FLINKEXPLAIN("FlinkExplain"), FLINKEXPLAIN("FlinkExplain"),
FLINKEXECUTE("FlinkExecute"),
FLINKSUBMIT("FlinkSubmit"), FLINKSUBMIT("FlinkSubmit"),
SQLEXPLAIN("SQLExplain"), SQLEXPLAIN("SQLExplain"),
SQLEXECUTE("SQLExecute"),
SQKSUBMIT("SQLSubmit"), SQKSUBMIT("SQLSubmit"),
UNKNOWN("Unknown"); UNKNOWN("Unknown");
......
...@@ -51,8 +51,12 @@ public class ConsolePool extends AbstractPool<StringBuilder> { ...@@ -51,8 +51,12 @@ public class ConsolePool extends AbstractPool<StringBuilder> {
} }
public static void write(String str, Integer userId) { public static void write(String str, Integer userId) {
String user = String.valueOf(userId); String user = userId.toString();
consoleEntityMap.getOrDefault(user, new StringBuilder("Dinky User Console:")).append(str); if (consoleEntityMap.containsKey(user)) {
consoleEntityMap.get(user).append(str);
} else {
StringBuilder sb = new StringBuilder("Dinky User Console:");
consoleEntityMap.put(user, sb.append(str));
}
} }
} }
...@@ -28,7 +28,6 @@ export type ProcessItem = { ...@@ -28,7 +28,6 @@ export type ProcessItem = {
time: number, time: number,
steps: ProcessStep[], steps: ProcessStep[],
userId: number, userId: number,
userName: string,
}; };
export type ProcessStep = { export type ProcessStep = {
......
...@@ -138,10 +138,6 @@ const ProcessList: React.FC<{}> = (props: any) => { ...@@ -138,10 +138,6 @@ const ProcessList: React.FC<{}> = (props: any) => {
title: '操作人ID', title: '操作人ID',
sorter: true, sorter: true,
dataIndex: 'userId', dataIndex: 'userId',
}, {
title: '操作人名',
sorter: true,
dataIndex: 'userName',
} }
]; ];
......
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