Unverified Commit 189ac1b4 authored by gaoyan's avatar gaoyan Committed by GitHub

fix bug (#2933)

parent 10292818
...@@ -96,9 +96,12 @@ public class APIController { ...@@ -96,9 +96,12 @@ public class APIController {
// @Log(title = "Cancel Flink Job", businessType = BusinessType.TRIGGER) // @Log(title = "Cancel Flink Job", businessType = BusinessType.TRIGGER)
@ApiOperation("Cancel Flink Job") @ApiOperation("Cancel Flink Job")
public Result<Boolean> cancel( public Result<Boolean> cancel(
@RequestParam Integer id, @RequestParam(defaultValue = "false") boolean withSavePoint) { @RequestParam Integer id,
@RequestParam(defaultValue = "false") boolean withSavePoint,
@RequestParam(defaultValue = "true") boolean forceCancel) {
return Result.succeed( return Result.succeed(
taskService.cancelTaskJob(taskService.getTaskInfoById(id), withSavePoint), Status.EXECUTE_SUCCESS); taskService.cancelTaskJob(taskService.getTaskInfoById(id), withSavePoint, forceCancel),
Status.EXECUTE_SUCCESS);
} }
/** /**
......
...@@ -106,8 +106,11 @@ public class TaskController { ...@@ -106,8 +106,11 @@ public class TaskController {
@GetMapping("/cancel") @GetMapping("/cancel")
@Log(title = "Cancel Flink Job", businessType = BusinessType.TRIGGER) @Log(title = "Cancel Flink Job", businessType = BusinessType.TRIGGER)
@ApiOperation("Cancel Flink Job") @ApiOperation("Cancel Flink Job")
public Result<Void> cancel(@RequestParam Integer id, @RequestParam(defaultValue = "false") boolean withSavePoint) { public Result<Void> cancel(
if (taskService.cancelTaskJob(taskService.getTaskInfoById(id), withSavePoint)) { @RequestParam Integer id,
@RequestParam(defaultValue = "false") boolean withSavePoint,
@RequestParam(defaultValue = "false") boolean forceCancel) {
if (taskService.cancelTaskJob(taskService.getTaskInfoById(id), withSavePoint, forceCancel)) {
return Result.succeed(Status.EXECUTE_SUCCESS); return Result.succeed(Status.EXECUTE_SUCCESS);
} else { } else {
return Result.failed(Status.EXECUTE_FAILED); return Result.failed(Status.EXECUTE_FAILED);
......
...@@ -116,7 +116,7 @@ public interface TaskService extends ISuperService<Task> { ...@@ -116,7 +116,7 @@ public interface TaskService extends ISuperService<Task> {
* @param task The {@link TaskDTO} object representing the task to cancel. * @param task The {@link TaskDTO} object representing the task to cancel.
* @return true if the task job is successfully cancelled, false otherwise. * @return true if the task job is successfully cancelled, false otherwise.
*/ */
boolean cancelTaskJob(TaskDTO task, boolean withSavePoint); boolean cancelTaskJob(TaskDTO task, boolean withSavePoint, boolean forceCancel);
/** /**
* Get the stream graph of the given task job. * Get the stream graph of the given task job.
......
...@@ -176,15 +176,6 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen ...@@ -176,15 +176,6 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
Assert.notNull(task, Status.TASK_NOT_EXIST.getMessage()); Assert.notNull(task, Status.TASK_NOT_EXIST.getMessage());
if (!Dialect.isCommonSql(task.getDialect())
&& Asserts.isNotNull(task.getJobInstanceId())
&& task.getJobInstanceId() > 0) {
JobInstance jobInstance = jobInstanceService.getById(task.getJobInstanceId());
if (jobInstance != null && !JobStatus.isDone(jobInstance.getStatus())) {
throw new BusException(Status.TASK_STATUS_IS_NOT_DONE.getMessage());
}
}
if (StringUtils.isNotBlank(submitDto.getSavePointPath())) { if (StringUtils.isNotBlank(submitDto.getSavePointPath())) {
task.setSavePointStrategy(SavePointStrategy.CUSTOM.getValue()); task.setSavePointStrategy(SavePointStrategy.CUSTOM.getValue());
task.setSavePointPath(submitDto.getSavePointPath()); task.setSavePointPath(submitDto.getSavePointPath());
...@@ -378,7 +369,7 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen ...@@ -378,7 +369,7 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
JobManager jobManager = JobManager.build(buildJobConfig(task)); JobManager jobManager = JobManager.build(buildJobConfig(task));
// If a user specifies a savepoint, the savepoint is not automatically triggered // If a user specifies a savepoint, the savepoint is not automatically triggered
if (useSavepoint) { if (useSavepoint) {
jobManager.cancelNormal(jobInstance.getJid()); cancelTaskJob(task, false, true);
} else { } else {
log.info("stop {} with savepoint", jobInstance.getName()); log.info("stop {} with savepoint", jobInstance.getName());
SavePointResult savePointResult = savepointTaskJob(task, SavePointType.CANCEL); SavePointResult savePointResult = savepointTaskJob(task, SavePointType.CANCEL);
...@@ -413,7 +404,7 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen ...@@ -413,7 +404,7 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
} }
@Override @Override
public boolean cancelTaskJob(TaskDTO task, boolean withSavePoint) { public boolean cancelTaskJob(TaskDTO task, boolean withSavePoint, boolean forceCancel) {
if (Dialect.isCommonSql(task.getDialect())) { if (Dialect.isCommonSql(task.getDialect())) {
return true; return true;
} }
...@@ -422,7 +413,19 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen ...@@ -422,7 +413,19 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
ClusterInstance clusterInstance = clusterInstanceService.getById(jobInstance.getClusterId()); ClusterInstance clusterInstance = clusterInstanceService.getById(jobInstance.getClusterId());
Assert.notNull(clusterInstance, Status.CLUSTER_NOT_EXIST.getMessage()); Assert.notNull(clusterInstance, Status.CLUSTER_NOT_EXIST.getMessage());
JobManager jobManager = JobManager.build(buildJobConfig(task)); JobManager jobManager;
try {
jobManager = JobManager.build(buildJobConfig(task));
} catch (Exception e) {
log.error("cancelTaskJob error:{}", e.getMessage());
if (forceCancel) {
jobInstance.setStatus(JobStatus.UNKNOWN.getValue());
jobInstanceService.updateById(jobInstance);
return true;
} else {
throw e;
}
}
boolean isSuccess; boolean isSuccess;
try { try {
......
...@@ -17,20 +17,37 @@ ...@@ -17,20 +17,37 @@
* *
*/ */
import { ButtonRoute } from '@/types/Studio/data';
import { Button } from 'antd'; import { Button } from 'antd';
import { ButtonProps } from 'antd/es/button/button';
import React, { useState } from 'react'; import React, { useState } from 'react';
export const LoadingBtn: React.FC<ButtonProps> = (props) => { export const LoadingBtn: React.FC<ButtonRoute> = (route) => {
const { click, title, icon, hotKeyDesc, props } = route;
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const handleClick = async (event: React.MouseEvent<HTMLElement, MouseEvent>) => { const handleClick = async (event: React.MouseEvent<HTMLElement, MouseEvent>) => {
if (props.onClick) { if (click) {
setLoading(true); setLoading(true);
await props.onClick(event); const result = await click();
if (result instanceof Promise) {
await result;
}
setLoading(false); setLoading(false);
} }
}; };
return <Button {...props} loading={loading} onClick={(event) => handleClick(event)}></Button>; return (
<Button
key={title}
size={'small'}
type={'text'}
icon={icon}
title={hotKeyDesc}
loading={loading}
onClick={(event) => handleClick(event)}
{...props}
>
{title}
</Button>
);
}; };
...@@ -372,6 +372,8 @@ export default { ...@@ -372,6 +372,8 @@ export default {
'pages.datastudio.editor.stop': 'Stop', 'pages.datastudio.editor.stop': 'Stop',
'pages.datastudio.editor.stop.job': 'Stop job', 'pages.datastudio.editor.stop.job': 'Stop job',
'pages.datastudio.editor.stop.jobConfirm': 'Are you sure to stop the job [{jobName}]? ', 'pages.datastudio.editor.stop.jobConfirm': 'Are you sure to stop the job [{jobName}]? ',
'pages.datastudio.editor.stop.force.jobConfirm':
'The current job [{job name}] fails to connect to the cluster to obtain information and cannot be stopped. Change the status forced?',
'pages.datastudio.editor.submitting': 'The new task [{jobName}] is executing', 'pages.datastudio.editor.submitting': 'The new task [{jobName}] is executing',
'pages.datastudio.editor.checking': 'The task [{jobName}] is checking', 'pages.datastudio.editor.checking': 'The task [{jobName}] is checking',
'pages.datastudio.editor.debugging': 'The new task [{jobName}] is debugging', 'pages.datastudio.editor.debugging': 'The new task [{jobName}] is debugging',
......
...@@ -358,6 +358,8 @@ export default { ...@@ -358,6 +358,8 @@ export default {
'pages.datastudio.editor.stop': '停止', 'pages.datastudio.editor.stop': '停止',
'pages.datastudio.editor.stop.job': '停止作业', 'pages.datastudio.editor.stop.job': '停止作业',
'pages.datastudio.editor.stop.jobConfirm': '确定停止作业【{jobName}】吗?', 'pages.datastudio.editor.stop.jobConfirm': '确定停止作业【{jobName}】吗?',
'pages.datastudio.editor.stop.force.jobConfirm':
'当前作业【{jobName}】连接到集群获取信息失败,无法进行停止操作,确定强制修改状态吗?',
'pages.datastudio.editor.submitting': '新任务【{jobName}】正在执行', 'pages.datastudio.editor.submitting': '新任务【{jobName}】正在执行',
'pages.datastudio.editor.checking': '任务【{jobName}】正在检查', 'pages.datastudio.editor.checking': '任务【{jobName}】正在检查',
'pages.datastudio.editor.debugging': '新任务【{jobName}】正在调试', 'pages.datastudio.editor.debugging': '新任务【{jobName}】正在调试',
......
...@@ -183,7 +183,8 @@ const FooterContainer: React.FC<FooterContainerProps & StateType> = (props) => { ...@@ -183,7 +183,8 @@ const FooterContainer: React.FC<FooterContainerProps & StateType> = (props) => {
</div> </div>
<JobRunningModal <JobRunningModal
value={jobRunningMsg} value={jobRunningMsg}
visible={viewJobRunning} //TODO 目前实现不了,禁掉
visible={false}
onCancel={() => setViewJobRunning(false)} onCancel={() => setViewJobRunning(false)}
onOk={() => setViewJobRunning(false)} onOk={() => setViewJobRunning(false)}
/> />
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
*/ */
import { TabsPageType, TaskDataType } from '@/pages/DataStudio/model'; import { TabsPageType, TaskDataType } from '@/pages/DataStudio/model';
import { JOB_LIFE_CYCLE, JOB_STATUS } from '@/pages/DevOps/constants'; import { JOB_LIFE_CYCLE } from '@/pages/DevOps/constants';
import { DIALECT } from '@/services/constants'; import { DIALECT } from '@/services/constants';
/** /**
...@@ -43,10 +43,6 @@ export const isOnline = (data: TaskDataType | undefined) => { ...@@ -43,10 +43,6 @@ export const isOnline = (data: TaskDataType | undefined) => {
return data ? JOB_LIFE_CYCLE.PUBLISH == data.step : false; return data ? JOB_LIFE_CYCLE.PUBLISH == data.step : false;
}; };
export const isRunning = (data: TaskDataType | undefined) => {
return data ? JOB_STATUS.RUNNING == data.status : false;
};
export const isCanPushDolphin = (data: TaskDataType | undefined) => { export const isCanPushDolphin = (data: TaskDataType | undefined) => {
return data return data
? JOB_LIFE_CYCLE.PUBLISH === data.step && ? JOB_LIFE_CYCLE.PUBLISH === data.step &&
......
...@@ -28,7 +28,6 @@ import { ...@@ -28,7 +28,6 @@ import {
buildBreadcrumbItems, buildBreadcrumbItems,
isCanPushDolphin, isCanPushDolphin,
isOnline, isOnline,
isRunning,
isSql, isSql,
projectCommonShow projectCommonShow
} from '@/pages/DataStudio/HeaderContainer/function'; } from '@/pages/DataStudio/HeaderContainer/function';
...@@ -48,13 +47,14 @@ import { ...@@ -48,13 +47,14 @@ import {
VIEW VIEW
} from '@/pages/DataStudio/model'; } from '@/pages/DataStudio/model';
import { JOB_LIFE_CYCLE, JOB_STATUS } from '@/pages/DevOps/constants'; import { JOB_LIFE_CYCLE, JOB_STATUS } from '@/pages/DevOps/constants';
import { isStatusDone } from '@/pages/DevOps/function';
import { SysConfigStateType } from '@/pages/SettingCenter/GlobalSetting/model'; import { SysConfigStateType } from '@/pages/SettingCenter/GlobalSetting/model';
import { SettingConfigKeyEnum } from '@/pages/SettingCenter/GlobalSetting/SettingOverView/constants'; import { SettingConfigKeyEnum } from '@/pages/SettingCenter/GlobalSetting/SettingOverView/constants';
import { handleOption, handlePutDataJson, queryDataByParams } from '@/services/BusinessCrud'; import { handleOption, handlePutDataJson, queryDataByParams } from '@/services/BusinessCrud';
import { DIALECT } from '@/services/constants'; import { DIALECT } from '@/services/constants';
import { API_CONSTANTS } from '@/services/endpoints'; import { API_CONSTANTS } from '@/services/endpoints';
import { Jobs } from '@/types/DevOps/data.d'; import { Jobs } from '@/types/DevOps/data.d';
import { DolphinTaskDefinition, DolphinTaskMinInfo } from '@/types/Studio/data.d'; import { ButtonRoute, DolphinTaskDefinition, DolphinTaskMinInfo } from '@/types/Studio/data.d';
import { l } from '@/utils/intl'; import { l } from '@/utils/intl';
import { import {
ApartmentOutlined, ApartmentOutlined,
...@@ -71,7 +71,6 @@ import { ...@@ -71,7 +71,6 @@ import {
} from '@ant-design/icons'; } from '@ant-design/icons';
import { connect } from '@umijs/max'; import { connect } from '@umijs/max';
import { Breadcrumb, Descriptions, Modal, Space } from 'antd'; import { Breadcrumb, Descriptions, Modal, Space } from 'antd';
import { ButtonProps } from 'antd/es/button/button';
import React, { memo, useEffect, useState } from 'react'; import React, { memo, useEffect, useState } from 'react';
const headerStyle: React.CSSProperties = { const headerStyle: React.CSSProperties = {
...@@ -84,16 +83,6 @@ const headerStyle: React.CSSProperties = { ...@@ -84,16 +83,6 @@ const headerStyle: React.CSSProperties = {
padding: '4px 10px' padding: '4px 10px'
}; };
type ButtonRoute = {
icon?: React.ReactNode;
title?: string;
click?: () => void;
hotKey?: (e: KeyboardEvent) => boolean;
hotKeyDesc?: string;
isShow: boolean;
props?: ButtonProps;
};
const HeaderContainer = (props: connect) => { const HeaderContainer = (props: connect) => {
const { const {
size, size,
...@@ -172,21 +161,31 @@ const HeaderContainer = (props: connect) => { ...@@ -172,21 +161,31 @@ const HeaderContainer = (props: connect) => {
}; };
const handlerStop = () => { const handlerStop = () => {
if (!currentData) return; if (!currentData) return new Promise((resolve) => resolve(false));
//RECONNECTING状态无法停止需要改变提示内容
modal.confirm({ const isReconnect = currentData.status == JOB_STATUS.RECONNECTING;
title: l('pages.datastudio.editor.stop.job'), const content = isReconnect
content: l('pages.datastudio.editor.stop.jobConfirm', '', { ? 'pages.datastudio.editor.stop.force.jobConfirm'
jobName: currentData.name : 'pages.datastudio.editor.stop.job';
}), return new Promise((resolve) => {
okText: l('button.confirm'), modal.confirm({
cancelText: l('button.cancel'), title: l('pages.datastudio.editor.stop.job'),
onOk: async () => { content: l(content, '', {
cancelTask(l('pages.datastudio.editor.stop.job'), currentData.id).then(() => { jobName: currentData.name
currentData.status = JOB_STATUS.CANCELED; }),
saveTabs({ ...props.tabs }); okText: l('button.confirm'),
}); cancelText: l('button.cancel'),
} onOk: async () => {
await cancelTask(l('pages.datastudio.editor.stop.job'), currentData.id).then(() => {
currentData.status = JOB_STATUS.CANCELED;
saveTabs({ ...props.tabs });
});
resolve(true);
},
onCancel: () => {
resolve(false);
}
});
}); });
}; };
...@@ -401,7 +400,7 @@ const HeaderContainer = (props: connect) => { ...@@ -401,7 +400,7 @@ const HeaderContainer = (props: connect) => {
hotKeyDesc: 'Shift+F10', hotKeyDesc: 'Shift+F10',
isShow: isShow:
currentTab?.type == TabsPageType.project && currentTab?.type == TabsPageType.project &&
!isRunning(currentData) && isStatusDone(currentData?.status) &&
currentTab?.subType?.toLowerCase() !== DIALECT.JAVA && currentTab?.subType?.toLowerCase() !== DIALECT.JAVA &&
currentTab?.subType?.toLowerCase() !== DIALECT.SCALA && currentTab?.subType?.toLowerCase() !== DIALECT.SCALA &&
currentTab?.subType?.toLowerCase() !== DIALECT.PYTHON_LONG && currentTab?.subType?.toLowerCase() !== DIALECT.PYTHON_LONG &&
...@@ -420,7 +419,7 @@ const HeaderContainer = (props: connect) => { ...@@ -420,7 +419,7 @@ const HeaderContainer = (props: connect) => {
hotKeyDesc: 'Shift+F9', hotKeyDesc: 'Shift+F9',
isShow: isShow:
currentTab?.type == TabsPageType.project && currentTab?.type == TabsPageType.project &&
!isRunning(currentData) && isStatusDone(currentData?.status) &&
(currentTab?.subType?.toLowerCase() === DIALECT.FLINK_SQL || (currentTab?.subType?.toLowerCase() === DIALECT.FLINK_SQL ||
isSql(currentTab?.subType?.toLowerCase() ?? '')), isSql(currentTab?.subType?.toLowerCase() ?? '')),
props: { props: {
...@@ -433,12 +432,12 @@ const HeaderContainer = (props: connect) => { ...@@ -433,12 +432,12 @@ const HeaderContainer = (props: connect) => {
icon: <PauseOutlined />, icon: <PauseOutlined />,
title: l('pages.datastudio.editor.stop'), title: l('pages.datastudio.editor.stop'),
click: handlerStop, click: handlerStop,
isShow: currentTab?.type == TabsPageType.project && isRunning(currentData), isShow: currentTab?.type == TabsPageType.project && !isStatusDone(currentData?.status),
hotKey: (e: KeyboardEvent) => e.shiftKey && e.key === 'F10', hotKey: (e: KeyboardEvent) => e.shiftKey && e.key === 'F10',
hotKeyDesc: 'Shift+F10', hotKeyDesc: 'Shift+F10',
props: { props: {
type: 'primary', type: 'primary',
danger: true style: { background: '#FF4D4F' }
} }
}, },
{ {
...@@ -495,19 +494,7 @@ const HeaderContainer = (props: connect) => { ...@@ -495,19 +494,7 @@ const HeaderContainer = (props: connect) => {
{routes {routes
.filter((x) => x.isShow) .filter((x) => x.isShow)
.map((route) => { .map((route) => {
return ( return <LoadingBtn {...route} />;
<LoadingBtn
key={route.title}
size={'small'}
type={'text'}
icon={route.icon}
onClick={route.click}
title={route.hotKeyDesc}
{...route.props}
>
{route.title}
</LoadingBtn>
);
})} })}
</Space> </Space>
{contextHolder} {contextHolder}
......
...@@ -36,8 +36,13 @@ export async function executeSql(title: string, id: number) { ...@@ -36,8 +36,13 @@ export async function executeSql(title: string, id: number) {
return handleGetOption('/api/task/submitTask', title, { id }); return handleGetOption('/api/task/submitTask', title, { id });
} }
export function cancelTask(title: string, id: number, withSavePoint: boolean = true) { export function cancelTask(
return handleGetOption(API_CONSTANTS.CANCEL_JOB, title, { id, withSavePoint }); title: string,
id: number,
withSavePoint: boolean = true,
forceCancel: boolean = true
) {
return handleGetOption(API_CONSTANTS.CANCEL_JOB, title, { id, withSavePoint, forceCancel });
} }
export function restartTask(id: number, savePointPath: string, title: string) { export function restartTask(id: number, savePointPath: string, title: string) {
......
...@@ -209,7 +209,12 @@ const JobConfig = (props: any) => { ...@@ -209,7 +209,12 @@ const JobConfig = (props: any) => {
type: selectRunMode type: selectRunMode
})} })}
rules={[ rules={[
{ required: true, message: l('pages.datastudio.label.jobConfig.clusterConfig.tip1') } {
required: true,
message: l('pages.datastudio.label.jobConfig.clusterConfig.tip1', '', {
type: selectRunMode
})
}
]} ]}
options={buildClusterConfigOptions(selectRunMode, clusterConfiguration)} options={buildClusterConfigOptions(selectRunMode, clusterConfiguration)}
allowClear={false} allowClear={false}
......
...@@ -43,7 +43,7 @@ export function isStatusDone(type: string) { ...@@ -43,7 +43,7 @@ export function isStatusDone(type: string) {
} }
export function isNotFinallyStatus(type: string) { export function isNotFinallyStatus(type: string) {
if (!type) { if (!type) {
return true; return false;
} }
switch (type) { switch (type) {
case JOB_STATUS.RECONNECTING: case JOB_STATUS.RECONNECTING:
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
*/ */
import { List } from 'antd'; import { List } from 'antd';
import { ButtonProps } from 'antd/es/button/button';
import React from 'react';
export type Catalogue = { export type Catalogue = {
id: number; id: number;
...@@ -309,3 +311,13 @@ export interface PushDolphinParams { ...@@ -309,3 +311,13 @@ export interface PushDolphinParams {
timeoutNotifyStrategy: string[] | string; timeoutNotifyStrategy: string[] | string;
description: string; description: string;
} }
export type ButtonRoute = {
icon?: React.ReactNode;
title?: string;
click?: () => any;
hotKey?: (e: KeyboardEvent) => boolean;
hotKeyDesc?: string;
isShow: boolean;
props?: ButtonProps;
};
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