Skip to content

Commit

Permalink
refactor response data structs and optimize datastudio's project
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzm0809 committed Oct 31, 2023
1 parent f66ab56 commit ba13c7a
Show file tree
Hide file tree
Showing 62 changed files with 514 additions and 426 deletions.
30 changes: 24 additions & 6 deletions dinky-admin/src/main/java/org/dinky/controller/TaskController.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,21 @@ public Result<JobResult> submitTask(@ProcessId @RequestParam Integer id) throws
paramType = "body")
public Result<JobResult> debugTask(@RequestBody DebugDTO debugDTO) throws Exception {
JobResult result = taskService.debugTask(debugDTO);
return Result.succeed(result, Status.EXECUTE_SUCCESS);
if (result.isSuccess()) {
return Result.succeed(result, Status.DEBUG_SUCCESS);
}
return Result.failed(result, Status.DEBUG_FAILED);
}

@GetMapping("/cancel")
@Log(title = "Cancel Flink Job", businessType = BusinessType.TRIGGER)
@ApiOperation("Cancel Flink Job")
public Result<Boolean> cancel(@RequestParam Integer id) {
return Result.succeed(taskService.cancelTaskJob(taskService.getTaskInfoById(id)), Status.EXECUTE_SUCCESS);
public Result<Void> cancel(@RequestParam Integer id) {
if (taskService.cancelTaskJob(taskService.getTaskInfoById(id))) {
return Result.succeed(Status.EXECUTE_SUCCESS);
} else {
return Result.failed(Status.EXECUTE_FAILED);
}
}

/**
Expand All @@ -110,7 +117,11 @@ public Result<Boolean> cancel(@RequestParam Integer id) {
@ApiOperation("Restart Task")
@Log(title = "Restart Task", businessType = BusinessType.REMOTE_OPERATION)
public Result<JobResult> restartTask(@RequestParam Integer id, String savePointPath) throws Exception {
return Result.succeed(taskService.restartTask(id, savePointPath));
JobResult jobResult = taskService.restartTask(id, savePointPath);
if (jobResult.isSuccess()) {
return Result.succeed(jobResult, Status.RESTART_SUCCESS);
}
return Result.failed(jobResult, Status.RESTART_FAILED);
}

@GetMapping("/savepoint")
Expand All @@ -127,7 +138,11 @@ public Result<SavePointResult> savepoint(@RequestParam Integer taskId, @RequestP
@Log(title = "onLineTask", businessType = BusinessType.TRIGGER)
@ApiOperation("onLineTask")
public Result<Boolean> onLineTask(@RequestParam Integer taskId) {
return Result.succeed(taskService.changeTaskLifeRecyle(taskId, JobLifeCycle.ONLINE));
if (taskService.changeTaskLifeRecyle(taskId, JobLifeCycle.ONLINE)) {
return Result.succeed(Status.PUBLISH_SUCCESS);
} else {
return Result.failed(Status.PUBLISH_FAILED);
}
}

@PostMapping("/explainSql")
Expand Down Expand Up @@ -197,7 +212,10 @@ public Result<List<Task>> listFlinkSQLEnv() {
@ApiOperation("Rollback Task")
@Log(title = "Rollback Task", businessType = BusinessType.UPDATE)
public Result<Void> rollbackTask(@RequestBody TaskRollbackVersionDTO dto) {
return taskService.rollbackTask(dto);
if (taskService.rollbackTask(dto)) {
return Result.succeed(Status.VERSION_ROLLBACK_SUCCESS);
}
return Result.failed(Status.VERSION_ROLLBACK_FAILED);
}

@GetMapping(value = "/getTaskAPIAddress")
Expand Down
18 changes: 9 additions & 9 deletions dinky-admin/src/main/java/org/dinky/data/result/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public class Result<T> implements Serializable {
/** result data */
@ApiModelProperty(
value = "Result Data",
name = "datas",
name = "data",
dataType = "T",
required = true,
allowEmptyValue = true,
example = "[]")
private T datas;
private T data;

@ApiModelProperty(
value = "Result Code",
Expand Down Expand Up @@ -95,7 +95,7 @@ public Result(Integer code, String msg) {
}

public void setData(T data) {
this.datas = data;
this.data = data;
}

public Result(Status status) {
Expand All @@ -105,10 +105,10 @@ public Result(Status status) {
}
}

public Result(Integer code, String msg, T datas) {
public Result(Integer code, String msg, T data) {
this.code = code;
this.msg = msg;
this.datas = datas;
this.data = data;
}

public static <T> Result<T> succeed(String msg) {
Expand Down Expand Up @@ -147,12 +147,12 @@ public static <T> Result<T> data(T model) {
return of(model, CodeEnum.SUCCESS.getCode(), "");
}

public static <T> Result<T> of(T datas, Integer code, String msg) {
return new Result<>(datas, code, msg, new DateTime().toString(), code == 0);
public static <T> Result<T> of(T data, Integer code, String msg) {
return new Result<>(data, code, msg, new DateTime().toString(), code == 0);
}

public static <T> Result<T> of(T datas, Integer code, Status status) {
return new Result<>(datas, code, status.getMessage(), new DateTime().toString(), code == 0);
public static <T> Result<T> of(T data, Integer code, Status status) {
return new Result<>(data, code, status.getMessage(), new DateTime().toString(), code == 0);
}

public static <T> Result<T> failed() {
Expand Down
18 changes: 9 additions & 9 deletions dinky-admin/src/main/java/org/dinky/security/SecurityAspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public void afterReturning(JoinPoint joinPoint, Object returnValue) {

// mask sql for explain
// openapi/explainSql
if (returnValue instanceof Result<?> && ((Result<?>) returnValue).getDatas() instanceof ExplainResult) {
ExplainResult exp = ((ExplainResult) ((Result<?>) returnValue).getDatas());
if (returnValue instanceof Result<?> && ((Result<?>) returnValue).getData() instanceof ExplainResult) {
ExplainResult exp = ((ExplainResult) ((Result<?>) returnValue).getData());
List<SqlExplainResult> sqlExplainResults = exp.getSqlExplainResults();
if (CollectionUtils.isEmpty(sqlExplainResults)) {
return;
Expand All @@ -64,12 +64,12 @@ public void afterReturning(JoinPoint joinPoint, Object returnValue) {
}

// /api/studio/explainSql
if (returnValue instanceof Result<?> && ((Result<?>) returnValue).getDatas() instanceof List<?>) {
List<?> list = (List<?>) ((Result<?>) returnValue).getDatas();
if (returnValue instanceof Result<?> && ((Result<?>) returnValue).getData() instanceof List<?>) {
List<?> list = (List<?>) ((Result<?>) returnValue).getData();
if (list.isEmpty() || !(list.get(0) instanceof SqlExplainResult)) {
return;
}
List<SqlExplainResult> sqlExplainResults = ((Result<List<SqlExplainResult>>) returnValue).getDatas();
List<SqlExplainResult> sqlExplainResults = ((Result<List<SqlExplainResult>>) returnValue).getData();
if (CollectionUtils.isEmpty(sqlExplainResults)) {
return;
}
Expand All @@ -93,17 +93,17 @@ public void afterReturning(JoinPoint joinPoint, Object returnValue) {
}

// mask statement for history
if (returnValue instanceof Result<?> && ((Result<?>) returnValue).getDatas() instanceof History) {
History history = ((History) ((Result<?>) returnValue).getDatas());
if (returnValue instanceof Result<?> && ((Result<?>) returnValue).getData() instanceof History) {
History history = ((History) ((Result<?>) returnValue).getData());
if (null != history) {
String statement = history.getStatement();
history.setStatement(mask(statement, SENSITIVE, MASK));
}
}

// /getJobInfoDetail
if (returnValue instanceof Result<?> && ((Result<?>) returnValue).getDatas() instanceof JobInfoDetail) {
JobInfoDetail jobInfoDetail = ((JobInfoDetail) ((Result<?>) returnValue).getDatas());
if (returnValue instanceof Result<?> && ((Result<?>) returnValue).getData() instanceof JobInfoDetail) {
JobInfoDetail jobInfoDetail = ((JobInfoDetail) ((Result<?>) returnValue).getData());
History history = jobInfoDetail.getHistory();
if (null != history) {
String statement = history.getStatement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public interface TaskService extends ISuperService<Task> {
* @param dto The {@link TaskRollbackVersionDTO} object representing the task to rollback.
* @return A {@link Result} object indicating the result of the rollback operation.
*/
Result<Void> rollbackTask(TaskRollbackVersionDTO dto);
boolean rollbackTask(TaskRollbackVersionDTO dto);

/**
* Get the size of all tasks with the given name in the system.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,9 @@ public List<Task> getAllUDF() {
}

@Override
public Result<Void> rollbackTask(TaskRollbackVersionDTO dto) {
public boolean rollbackTask(TaskRollbackVersionDTO dto) {
if (Asserts.isNull(dto.getVersionId()) || Asserts.isNull(dto.getId())) {
return Result.failed("the version is error");
throw new BusException("the version is error");
}

LambdaQueryWrapper<TaskVersion> queryWrapper = new LambdaQueryWrapper<TaskVersion>()
Expand All @@ -575,8 +575,7 @@ public Result<Void> rollbackTask(TaskRollbackVersionDTO dto) {
BeanUtil.copyProperties(taskVersion.getTaskConfigure(), updateTask);
updateTask.setId(taskVersion.getTaskId());
updateTask.setStep(JobLifeCycle.DEVELOP.getValue());
baseMapper.updateById(updateTask);
return Result.succeed("version rollback success!");
return baseMapper.updateById(updateTask) > 0;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion dinky-admin/src/main/resources/db/db-h2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1768,7 +1768,7 @@ INSERT INTO `dinky_sys_menu` VALUES (34, 5, '项目列表', '/datastudio/left/pr
INSERT INTO `dinky_sys_menu` VALUES (35, 5, '元数据', '/datastudio/left/metadata', null, 'datastudio:left:metadata', 'TableOutlined', 'F', 0, 7, '2023-09-01 18:01:09', '2023-09-26 14:49:42', null);
INSERT INTO `dinky_sys_menu` VALUES (36, 5, 'catalog', '/datastudio/left/catalog', null, 'datastudio:left:structure', 'DatabaseOutlined', 'F', 0, 6, '2023-09-01 18:01:30', '2023-09-26 14:49:54', null);
INSERT INTO `dinky_sys_menu` VALUES (37, 5, '作业配置', '/datastudio/right/jobConfig', null, 'datastudio:right:jobConfig', 'SettingOutlined', 'F', 0, 8, '2023-09-01 18:02:15', '2023-09-26 14:50:24', null);
INSERT INTO `dinky_sys_menu` VALUES (38, 5, '执行配置', '/datastudio/right/executeConfig', null, 'datastudio:right:executeConfig', 'ExperimentOutlined', 'F', 0, 9, '2023-09-01 18:03:08', '2023-09-26 14:50:54', null);
INSERT INTO `dinky_sys_menu` VALUES (38, 5, '预览配置', '/datastudio/right/previewConfig', null, 'datastudio:right:previewConfig', 'InsertRowRightOutlined', 'F', 0, 9, '2023-09-01 18:03:08', '2023-09-26 14:50:54', null);
INSERT INTO `dinky_sys_menu` VALUES (39, 5, '版本历史', '/datastudio/right/historyVision', null, 'datastudio:right:historyVision', 'HistoryOutlined', 'F', 0, 10, '2023-09-01 18:03:29', '2023-09-26 14:51:03', null);
INSERT INTO `dinky_sys_menu` VALUES (40, 5, '保存点', '/datastudio/right/savePoint', null, 'datastudio:right:savePoint', 'FolderOutlined', 'F', 0, 11, '2023-09-01 18:03:58', '2023-09-26 14:51:13', null);
INSERT INTO `dinky_sys_menu` VALUES (41, 5, '作业信息', '/datastudio/right/jobInfo', null, 'datastudio:right:jobInfo', 'InfoCircleOutlined', 'F', 0, 8, '2023-09-01 18:04:31', '2023-09-25 18:26:45', null);
Expand Down
7 changes: 7 additions & 0 deletions dinky-common/src/main/java/org/dinky/data/enums/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ public enum Status {
TEST_CONNECTION_FAILED(9030, "test.connection.failed"),
DEBUG_SUCCESS(9031, "debug.success"),
DEBUG_FAILED(9032, "debug.failed"),
PUBLISH_SUCCESS(9033, "publish.success"),
PUBLISH_FAILED(9034, "publish.failed"),
OFFLINE_SUCCESS(9035, "offline.success"),
OFFLINE_FAILED(9036, "offline.failed"),
VERSION_ROLLBACK_SUCCESS(9037, "version.rollback.success"),
VERSION_ROLLBACK_FAILED(9038, "version.rollback.failed"),

/**
* user,tenant,role
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ not.token=Can Not Read Token
execute.success=Execute Successfully
debug.success=Debug Successfully
debug.failed=Debug Failed
publish.success=Publish Successfully
publish.failed=Publish Failed
offline.success=Offline Successfully
offline.failed=Offline Failed
version.rollback.success=Version Rollback Successfully
version.rollback.failed=Version Rollback Failed
token.freezed=token has been frozen
menu.has.assign=Menu Has Assign , Can Not Delete
datasource.status.refresh.success=DataSource Status Refresh Success
Expand Down
Loading

0 comments on commit ba13c7a

Please sign in to comment.