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

fix bug (#2933)

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