Skip to content

Commit

Permalink
refactor api model
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzm0809 committed Sep 15, 2023
1 parent 4dc9984 commit 0dcded3
Show file tree
Hide file tree
Showing 159 changed files with 4,670 additions and 361 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
Expand All @@ -44,6 +45,7 @@

import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver;

import cn.dev33.satoken.config.SaTokenConfig;
import lombok.RequiredArgsConstructor;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
Expand All @@ -64,6 +66,9 @@ public class Knife4jConfig {
@Value("${dinky.version}")
private String dinkyVersion;

@Autowired
SaTokenConfig saTokenConfigure;

private final OpenApiExtensionResolver openApiExtensionResolver;

@Bean(value = "defaultApi2")
Expand Down Expand Up @@ -99,7 +104,7 @@ public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(
CorsEndpointProperties corsProperties,
WebEndpointProperties webEndpointProperties,
Environment environment) {
List<ExposableEndpoint<?>> allEndpoints = new ArrayList();
List<ExposableEndpoint<?>> allEndpoints = new ArrayList<>();
Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
allEndpoints.addAll(webEndpoints);
allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
Expand Down
119 changes: 115 additions & 4 deletions dinky-admin/src/main/java/org/dinky/controller/APIController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@

package org.dinky.controller;

import org.dinky.data.annotation.Log;
import org.dinky.data.dto.APICancelDTO;
import org.dinky.data.dto.APIExecuteJarDTO;
import org.dinky.data.dto.APIExecuteSqlDTO;
import org.dinky.data.dto.APIExplainSqlDTO;
import org.dinky.data.dto.APISavePointDTO;
import org.dinky.data.dto.APISavePointTaskDTO;
import org.dinky.data.enums.BusinessType;
import org.dinky.data.enums.Status;
import org.dinky.data.model.JobInstance;
import org.dinky.data.result.APIJobResult;
Expand All @@ -50,6 +48,8 @@
import com.fasterxml.jackson.databind.node.ObjectNode;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -75,6 +75,7 @@ public class APIController {
@GetMapping("/submitTask")
@ApiOperation("Submit Task")
// @Log(title = "Submit Task", businessType = BusinessType.SUBMIT)
@ApiImplicitParam(name = "id", value = "Task Id", required = true, dataType = "Integer")
public Result<JobResult> submitTask(@RequestParam Integer id) {
taskService.initTenantByTaskId(id);
return Result.succeed(taskService.submitTask(id), Status.EXECUTE_SUCCESS);
Expand All @@ -83,59 +84,113 @@ public Result<JobResult> submitTask(@RequestParam Integer id) {
@PostMapping("/executeSql")
@ApiOperation("Execute Sql")
// @Log(title = "Execute Sql", businessType = BusinessType.EXECUTE)
@ApiImplicitParam(
name = "apiExecuteSqlDTO",
value = "API Execute Sql DTO",
required = true,
dataType = "APIExecuteSqlDTO",
dataTypeClass = APIExecuteSqlDTO.class)
public Result<APIJobResult> executeSql(@RequestBody APIExecuteSqlDTO apiExecuteSqlDTO) {
return Result.succeed(apiService.executeSql(apiExecuteSqlDTO), Status.EXECUTE_SUCCESS);
}

@PostMapping("/explainSql")
@ApiOperation("Explain Sql")
// @Log(title = "Explain Sql", businessType = BusinessType.EXECUTE)
@ApiImplicitParam(
name = "apiExecuteSqlDTO",
value = "API Execute Sql DTO",
required = true,
dataType = "APIExecuteSqlDTO",
dataTypeClass = APIExecuteSqlDTO.class)
public Result<ExplainResult> explainSql(@RequestBody APIExplainSqlDTO apiExecuteSqlDTO) {
return Result.succeed(apiService.explainSql(apiExecuteSqlDTO), Status.EXECUTE_SUCCESS);
}

@PostMapping("/getJobPlan")
@ApiOperation("Get Job Plan")
@ApiImplicitParam(
name = "apiExecuteSqlDTO",
value = "API Execute Sql DTO",
required = true,
dataType = "APIExecuteSqlDTO",
dataTypeClass = APIExecuteSqlDTO.class)
public Result<ObjectNode> getJobPlan(@RequestBody APIExplainSqlDTO apiExecuteSqlDTO) {
return Result.succeed(apiService.getJobPlan(apiExecuteSqlDTO), Status.EXECUTE_SUCCESS);
}

@PostMapping("/getStreamGraph")
@ApiOperation("Get Stream Graph")
@ApiImplicitParam(
name = "apiExecuteSqlDTO",
value = "API Execute Sql DTO",
required = true,
dataType = "APIExecuteSqlDTO",
dataTypeClass = APIExecuteSqlDTO.class)
public Result<ObjectNode> getStreamGraph(@RequestBody APIExplainSqlDTO apiExecuteSqlDTO) {
return Result.succeed(apiService.getStreamGraph(apiExecuteSqlDTO), Status.EXECUTE_SUCCESS);
}

@GetMapping("/getJobData")
@ApiOperation("Get Job Data")
@ApiImplicitParam(
name = "jobId",
value = "Job Id",
required = true,
dataType = "String",
dataTypeClass = String.class)
public Result<SelectResult> getJobData(@RequestParam String jobId) {
return Result.succeed(studioService.getJobData(jobId));
}

@PostMapping("/cancel")
@Log(title = "Cancel Flink Job", businessType = BusinessType.TRIGGER)
// @Log(title = "Cancel Flink Job", businessType = BusinessType.TRIGGER)
@ApiOperation("Cancel Flink Job")
@ApiImplicitParam(
name = "apiCancelDTO",
value = "API Cancel DTO",
required = true,
dataType = "APICancelDTO",
dataTypeClass = APICancelDTO.class)
public Result<Boolean> cancel(@RequestBody APICancelDTO apiCancelDTO) {
return Result.succeed(apiService.cancel(apiCancelDTO), Status.EXECUTE_SUCCESS);
}

@PostMapping("/savepoint")
@Log(title = "Savepoint Trigger", businessType = BusinessType.TRIGGER)
// @Log(title = "Savepoint Trigger", businessType = BusinessType.TRIGGER)
@ApiOperation("Savepoint Trigger")
@ApiImplicitParam(
name = "apiSavePointDTO",
value = "API SavePoint DTO",
required = true,
dataType = "APISavePointDTO",
dataTypeClass = APISavePointDTO.class)
public Result<SavePointResult> savepoint(@RequestBody APISavePointDTO apiSavePointDTO) {
return Result.succeed(apiService.savepoint(apiSavePointDTO), Status.EXECUTE_SUCCESS);
}

@PostMapping("/executeJar")
@ApiOperation("Execute Jar")
// @Log(title = "Execute Jar", businessType = BusinessType.EXECUTE)
@ApiImplicitParam(
name = "apiExecuteJarDTO",
value = "API Execute Jar DTO",
required = true,
dataType = "APIExecuteJarDTO",
dataTypeClass = APIExecuteJarDTO.class)
public Result<APIJobResult> executeJar(@RequestBody APIExecuteJarDTO apiExecuteJarDTO) {
return Result.succeed(apiService.executeJar(apiExecuteJarDTO), Status.EXECUTE_SUCCESS);
}

@PostMapping("/savepointTask")
@ApiOperation("Savepoint Task")
// @Log(title = "Savepoint Task", businessType = BusinessType.TRIGGER)
@ApiImplicitParam(
name = "apiSavePointTaskDTO",
value = "API SavePoint Task DTO",
required = true,
dataType = "APISavePointTaskDTO",
dataTypeClass = APISavePointTaskDTO.class)
public Result<Boolean> savepointTask(@RequestBody APISavePointTaskDTO apiSavePointTaskDTO) {
return Result.succeed(
taskService.savepointTask(apiSavePointTaskDTO.getTaskId(), apiSavePointTaskDTO.getType()), "执行成功");
Expand All @@ -145,6 +200,12 @@ public Result<Boolean> savepointTask(@RequestBody APISavePointTaskDTO apiSavePoi
@GetMapping("/restartTask")
@ApiOperation("Restart Task")
// @Log(title = "Restart Task", businessType = BusinessType.EXECUTE)
@ApiImplicitParam(
name = "id",
value = "Task Id",
required = true,
dataType = "Integer",
dataTypeClass = Integer.class)
public Result<JobResult> restartTask(@RequestParam Integer id) {
taskService.initTenantByTaskId(id);
return Result.succeed(taskService.restartTask(id, null), Status.RESTART_SUCCESS);
Expand All @@ -154,6 +215,20 @@ public Result<JobResult> restartTask(@RequestParam Integer id) {
@GetMapping("/selectSavePointRestartTask")
@ApiOperation("Select SavePoint Restart Task")
// @Log(title = "Select SavePoint Restart Task", businessType = BusinessType.EXECUTE)
@ApiImplicitParams({
@ApiImplicitParam(
name = "id",
value = "Task Id",
required = true,
dataType = "Integer",
dataTypeClass = Integer.class),
@ApiImplicitParam(
name = "savePointPath",
value = "SavePoint Path",
required = true,
dataType = "String",
dataTypeClass = String.class)
})
public Result<JobResult> restartTask(@RequestParam Integer id, @RequestParam String savePointPath) {
taskService.initTenantByTaskId(id);
return Result.succeed(taskService.restartTask(id, savePointPath), Status.RESTART_SUCCESS);
Expand All @@ -163,6 +238,12 @@ public Result<JobResult> restartTask(@RequestParam Integer id, @RequestParam Str
@GetMapping("/onLineTask")
@ApiOperation("Online Task")
// @Log(title = "Online Task", businessType = BusinessType.EXECUTE)
@ApiImplicitParam(
name = "id",
value = "Task Id",
required = true,
dataType = "Integer",
dataTypeClass = Integer.class)
public Result<JobResult> onLineTask(@RequestParam Integer id) {
taskService.initTenantByTaskId(id);
return taskService.onLineTask(id);
Expand All @@ -172,6 +253,12 @@ public Result<JobResult> onLineTask(@RequestParam Integer id) {
@GetMapping("/offLineTask")
@ApiOperation("Offline Task")
// @Log(title = "Offline Task", businessType = BusinessType.EXECUTE)
@ApiImplicitParam(
name = "id",
value = "Task Id",
required = true,
dataType = "Integer",
dataTypeClass = Integer.class)
public Result<Void> offLineTask(@RequestParam Integer id) {
taskService.initTenantByTaskId(id);
return taskService.offLineTask(id, null);
Expand All @@ -181,6 +268,12 @@ public Result<Void> offLineTask(@RequestParam Integer id) {
@GetMapping("/reOnLineTask")
@ApiOperation("ReOnline Task")
// @Log(title = "ReOnline Task", businessType = BusinessType.EXECUTE)
@ApiImplicitParam(
name = "id",
value = "Task Id",
required = true,
dataType = "Integer",
dataTypeClass = Integer.class)
public Result<JobResult> reOnLineTask(@RequestParam Integer id) {
taskService.initTenantByTaskId(id);
return taskService.reOnLineTask(id, null);
Expand All @@ -190,6 +283,12 @@ public Result<JobResult> reOnLineTask(@RequestParam Integer id) {
@GetMapping("/selectSavePointReOnLineTask")
@ApiOperation("Select SavePoint ReOnline Task")
// @Log(title = "Select SavePoint ReOnline Task", businessType = BusinessType.EXECUTE)
@ApiImplicitParam(
name = "id",
value = "Task Id",
required = true,
dataType = "Integer",
dataTypeClass = Integer.class)
public Result<JobResult> selectSavePointReOnLineTask(@RequestParam Integer id, @RequestParam String savePointPath) {
taskService.initTenantByTaskId(id);
return taskService.reOnLineTask(id, savePointPath);
Expand All @@ -199,6 +298,12 @@ public Result<JobResult> selectSavePointReOnLineTask(@RequestParam Integer id, @
@GetMapping("/getJobInstance")
@ApiOperation("Get Job Instance")
// @Log(title = "Get Job Instance", businessType = BusinessType.QUERY)
@ApiImplicitParam(
name = "id",
value = "Job Instance Id",
required = true,
dataType = "Integer",
dataTypeClass = Integer.class)
public Result<JobInstance> getJobInstance(@RequestParam Integer id) {
jobInstanceService.initTenantByJobInstanceId(id);
return Result.succeed(jobInstanceService.getById(id));
Expand All @@ -208,6 +313,12 @@ public Result<JobInstance> getJobInstance(@RequestParam Integer id) {
@GetMapping("/getJobInstanceByTaskId")
@ApiOperation("Get Job Instance By Task Id")
// @Log(title = "Get Job Instance By Task Id", businessType = BusinessType.QUERY)
@ApiImplicitParam(
name = "id",
value = "Task Id",
required = true,
dataType = "Integer",
dataTypeClass = Integer.class)
public Result<JobInstance> getJobInstanceByTaskId(@RequestParam Integer id) {
taskService.initTenantByTaskId(id);
return Result.succeed(jobInstanceService.getJobInstanceByTaskId(id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -64,6 +65,7 @@ public class AdminController {
* @return {@link Result}{@link UserDTO} obtain the user's UserDTO
*/
@PostMapping("/login")
@ApiImplicitParam(name = "loginDTO", value = "LoginDTO", required = true, dataTypeClass = LoginDTO.class)
@ApiOperation(value = "Login", notes = "Login")
public Result<UserDTO> login(@RequestBody LoginDTO loginDTO) {
return userService.loginUser(loginDTO);
Expand Down Expand Up @@ -102,6 +104,7 @@ public Result<UserDTO> getCurrentUserInfo() {
*/
@PostMapping("/chooseTenant")
@SaCheckLogin
@ApiImplicitParam(name = "tenantId", value = "tenantId", required = true, dataTypeClass = Integer.class)
@ApiOperation(value = "Choose Tenant To Login", notes = "Choose Tenant To Login")
public Result<Tenant> switchingTenant(@RequestParam("tenantId") Integer tenantId) {
return userService.chooseTenant(tenantId);
Expand All @@ -118,4 +121,11 @@ public Result<Tenant> switchingTenant(@RequestParam("tenantId") Integer tenantId
public Result<SaTokenInfo> getTokenInfo() {
return Result.succeed(StpUtil.getTokenInfo());
}

@GetMapping("/keepAlive")
@SaCheckLogin
@ApiOperation(value = "Query Current User Token Info", notes = "Query Current User Token Info")
public Result<SaTokenInfo> keepAlive() {
return Result.succeed(StpUtil.getTokenInfo());
}
}
Loading

0 comments on commit 0dcded3

Please sign in to comment.