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