Skip to content

Commit

Permalink
[Feature-534][admin,web] Add task open API page
Browse files Browse the repository at this point in the history
[Feature-534][admin,web] Add task open API page
  • Loading branch information
aiwenmo authored May 26, 2022
2 parents 9df82df + 6e73586 commit 27146ee
Show file tree
Hide file tree
Showing 7 changed files with 302 additions and 31 deletions.
53 changes: 48 additions & 5 deletions dlink-admin/src/main/java/com/dlink/controller/APIController.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
package com.dlink.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.dlink.common.result.Result;
import com.dlink.dto.*;
import com.dlink.dto.APICancelDTO;
import com.dlink.dto.APIExecuteJarDTO;
import com.dlink.dto.APIExecuteSqlDTO;
import com.dlink.dto.APIExplainSqlDTO;
import com.dlink.dto.APISavePointDTO;
import com.dlink.dto.APISavePointTaskDTO;
import com.dlink.service.APIService;
import com.dlink.service.StudioService;
import com.dlink.service.TaskService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
* APIController
Expand All @@ -27,7 +39,7 @@ public class APIController {
@Autowired
private TaskService taskService;

@GetMapping(value = "/submitTask")
@GetMapping("/submitTask")
public Result submitTask(@RequestParam Integer id) {
return Result.succeed(taskService.submitTask(id), "执行成功");
}
Expand Down Expand Up @@ -74,7 +86,38 @@ public Result executeJar(@RequestBody APIExecuteJarDTO apiExecuteJarDTO) {

@PostMapping("/savepointTask")
public Result savepointTask(@RequestBody APISavePointTaskDTO apiSavePointTaskDTO) {
return Result.succeed(taskService.savepointTask(apiSavePointTaskDTO.getTaskId(),apiSavePointTaskDTO.getType()), "执行成功");
return Result.succeed(taskService.savepointTask(apiSavePointTaskDTO.getTaskId(), apiSavePointTaskDTO.getType()), "执行成功");
}

/**
* 重启任务
*/
@GetMapping("/restartTask")
public Result restartTask(@RequestParam Integer id) {
return Result.succeed(taskService.restartTask(id), "重启成功");
}

/**
* 上线任务
*/
@GetMapping("/onLineTask")
public Result onLineTask(@RequestParam Integer id) {
return taskService.onLineTask(id);
}

/**
* 下线任务
*/
@GetMapping("/offLineTask")
public Result offLineTask(@RequestParam Integer id) {
return taskService.offLineTask(id, null);
}

/**
* 重新上线任务
*/
@GetMapping("/reOnLineTask")
public Result reOnLineTask(@RequestParam Integer id) {
return taskService.reOnLineTask(id);
}
}
27 changes: 22 additions & 5 deletions dlink-admin/src/main/java/com/dlink/controller/TaskController.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
package com.dlink.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.dlink.common.result.ProTableResult;
import com.dlink.common.result.Result;
import com.dlink.job.JobResult;
import com.dlink.model.Task;
import com.dlink.service.TaskService;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import lombok.extern.slf4j.Slf4j;

/**
* 任务 Controller
Expand Down Expand Up @@ -180,5 +189,13 @@ public Result restartTask(@RequestParam Integer id, @RequestParam Boolean isOnLi
return Result.succeed(taskService.restartTask(id), "重启成功");
}
}

/**
* 获取当前的 API 的地址
*/
@GetMapping(value = "/getTaskAPIAddress")
public Result getTaskAPIAddress() {
return Result.succeed(taskService.getTaskAPIAddress(), "重启成功");
}
}

6 changes: 4 additions & 2 deletions dlink-admin/src/main/java/com/dlink/service/TaskService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.dlink.service;


import java.util.List;

import com.dlink.common.result.Result;
import com.dlink.db.service.ISuperService;
import com.dlink.job.JobResult;
Expand All @@ -9,8 +11,6 @@
import com.dlink.model.Task;
import com.dlink.result.SqlExplainResult;

import java.util.List;

/**
* 作业 服务类
*
Expand Down Expand Up @@ -56,4 +56,6 @@ public interface TaskService extends ISuperService<Task> {
JobInstance refreshJobInstance(Integer id, boolean isCoercive);

JobInfoDetail refreshJobInfoDetail(Integer id);

String getTaskAPIAddress();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
package com.dlink.service.impl;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dlink.alert.Alert;
import com.dlink.alert.AlertConfig;
Expand All @@ -11,6 +23,7 @@
import com.dlink.common.result.Result;
import com.dlink.config.Dialect;
import com.dlink.constant.FlinkRestResultConstant;
import com.dlink.constant.NetConstant;
import com.dlink.daemon.task.DaemonFactory;
import com.dlink.daemon.task.DaemonTaskConfig;
import com.dlink.db.service.impl.SuperServiceImpl;
Expand All @@ -21,26 +34,44 @@
import com.dlink.gateway.config.SavePointType;
import com.dlink.gateway.model.JobInfo;
import com.dlink.gateway.result.SavePointResult;
import com.dlink.job.*;
import com.dlink.job.FlinkJobTask;
import com.dlink.job.Job;
import com.dlink.job.JobConfig;
import com.dlink.job.JobManager;
import com.dlink.job.JobResult;
import com.dlink.mapper.TaskMapper;
import com.dlink.metadata.driver.Driver;
import com.dlink.metadata.result.JdbcSelectResult;
import com.dlink.model.*;
import com.dlink.model.AlertGroup;
import com.dlink.model.AlertHistory;
import com.dlink.model.AlertInstance;
import com.dlink.model.Cluster;
import com.dlink.model.DataBase;
import com.dlink.model.Jar;
import com.dlink.model.JobHistory;
import com.dlink.model.JobInfoDetail;
import com.dlink.model.JobInstance;
import com.dlink.model.JobLifeCycle;
import com.dlink.model.JobStatus;
import com.dlink.model.Savepoints;
import com.dlink.model.Statement;
import com.dlink.model.SystemConfiguration;
import com.dlink.model.Task;
import com.dlink.result.SqlExplainResult;
import com.dlink.service.*;
import com.dlink.service.AlertGroupService;
import com.dlink.service.AlertHistoryService;
import com.dlink.service.ClusterConfigurationService;
import com.dlink.service.ClusterService;
import com.dlink.service.DataBaseService;
import com.dlink.service.JarService;
import com.dlink.service.JobHistoryService;
import com.dlink.service.JobInstanceService;
import com.dlink.service.SavepointsService;
import com.dlink.service.StatementService;
import com.dlink.service.TaskService;
import com.dlink.utils.CustomStringJavaCompiler;
import com.dlink.utils.JSONUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* 任务 服务实现类
*
Expand Down Expand Up @@ -79,6 +110,8 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
private String username;
@Value("${spring.datasource.password}")
private String password;
@Value("${server.port}")
private String serverPort;

private String buildParas(Integer id) {
return "--id " + id + " --driver " + driver + " --url " + url + " --username " + username + " --password " + password;
Expand Down Expand Up @@ -226,7 +259,7 @@ public Task getTaskInfoById(Integer id) {
JobInstance jobInstance = jobInstanceService.getJobInstanceByTaskId(id);
if (Asserts.isNotNull(jobInstance) && !JobStatus.isDone(jobInstance.getStatus())) {
task.setJobInstanceId(jobInstance.getId());
}else {
} else {
task.setJobInstanceId(0);
}
}
Expand Down Expand Up @@ -588,6 +621,19 @@ public JobInfoDetail refreshJobInfoDetail(Integer id) {
return jobInstanceService.getJobInfoDetailInfo(refreshJobInstance(id, true));
}

@Override
public String getTaskAPIAddress() {
try {
InetAddress inetAddress = InetAddress.getLocalHost();
if (inetAddress != null) {
return inetAddress.getHostAddress() + NetConstant.COLON + serverPort;
}
} catch (UnknownHostException e) {
e.printStackTrace();
}
return "127.0.0.1:" + serverPort;
}

private void handleJobDone(JobInstance jobInstance) {
if (Asserts.isNull(jobInstance.getTaskId())) {
return;
Expand Down
34 changes: 29 additions & 5 deletions dlink-web/src/components/Studio/StudioMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
PauseCircleTwoTone, CarryOutTwoTone, DeleteTwoTone, PlayCircleTwoTone, CameraTwoTone, SnippetsTwoTone,
FileAddTwoTone, FolderOpenTwoTone, SafetyCertificateTwoTone, SaveTwoTone, FlagTwoTone, CodeTwoTone,
EnvironmentOutlined, SmileOutlined, RocketTwoTone, QuestionCircleTwoTone, MessageOutlined, ClusterOutlined
, EditTwoTone, RestTwoTone, ShrinkOutlined
, EditTwoTone, RestTwoTone, ShrinkOutlined, ApiTwoTone
} from "@ant-design/icons";
import Space from "antd/es/space";
import Divider from "antd/es/divider";
Expand All @@ -14,6 +14,7 @@ import {StateType} from "@/pages/DataStudio/model";
import {connect} from "umi";
import {CODE, postDataArray} from "@/components/Common/crud";
import {executeSql, getJobPlan} from "@/pages/DataStudio/service";
import TaskAPI from "@/pages/API/TaskAPI";
import StudioHelp from "./StudioHelp";
import StudioGraph from "./StudioGraph";
import {
Expand Down Expand Up @@ -456,6 +457,18 @@ const StudioMenu = (props: any) => {
return itemList;
};

const showAPI = () => {
Modal.info({
title: current.task.alias + ' API 手册',
width: 1000,
content: (
<TaskAPI task={current.task}/>
),
onOk() {
},
});
};

const showHelp = () => {
Modal.info({
title: '使用帮助',
Expand Down Expand Up @@ -499,14 +512,12 @@ const StudioMenu = (props: any) => {
<Divider className={styles["ant-divider-horizontal-0"]}/>
<Col span={24}>
<Row>
<Col span={4}>
<Col span={16}>
<Breadcrumb className={styles["dw-path"]}>
<EnvironmentOutlined/>
<Divider type="vertical"/>
{getPathItem(currentPath)}
</Breadcrumb>
</Col>
<Col span={12}>
{currentSession.session &&
(
<Breadcrumb className={styles["dw-path"]}>
Expand Down Expand Up @@ -645,14 +656,27 @@ const StudioMenu = (props: any) => {
/>
</Tooltip> : undefined
}
<Tooltip title="查看 API">
<Button
type="text"
icon={<ApiTwoTone />}
onClick={showAPI}
/>
</Tooltip>
<Tooltip title="查看使用帮助">
<Button
type="text"
icon={<QuestionCircleTwoTone/>}
onClick={showHelp}
/>
</Tooltip>
</Col> : undefined}
</Col> : <Col span={8}><Tooltip title="查看使用帮助">
<Button
type="text"
icon={<QuestionCircleTwoTone/>}
onClick={showHelp}
/>
</Tooltip></Col>}
</Row>
</Col>
<StudioExplain
Expand Down
Loading

0 comments on commit 27146ee

Please sign in to comment.