Unverified Commit fa1ce86a authored by aiwenmo's avatar aiwenmo Committed by GitHub

[Fix-2731] [scheduler] Fix push task to dolphinscheduler (#2732)

parent 5df10a4a
...@@ -35,7 +35,6 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -35,7 +35,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import cn.hutool.core.collection.CollUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -84,9 +83,6 @@ public class SchedulerController { ...@@ -84,9 +83,6 @@ public class SchedulerController {
example = "1") example = "1")
public Result<List<TaskMainInfo>> getTaskMainInfos(@ApiParam(value = "dinky任务id") @RequestParam Long dinkyTaskId) { public Result<List<TaskMainInfo>> getTaskMainInfos(@ApiParam(value = "dinky任务id") @RequestParam Long dinkyTaskId) {
List<TaskMainInfo> taskMainInfos = schedulerService.getTaskMainInfos(dinkyTaskId); List<TaskMainInfo> taskMainInfos = schedulerService.getTaskMainInfos(dinkyTaskId);
if (CollUtil.isEmpty(taskMainInfos)) {
return Result.failed();
}
return Result.succeed(taskMainInfos); return Result.succeed(taskMainInfos);
} }
......
...@@ -28,7 +28,7 @@ import org.dinky.scheduler.result.PageInfo; ...@@ -28,7 +28,7 @@ import org.dinky.scheduler.result.PageInfo;
import org.dinky.scheduler.result.Result; import org.dinky.scheduler.result.Result;
import org.dinky.scheduler.utils.MyJSONUtil; import org.dinky.scheduler.utils.MyJSONUtil;
import org.dinky.scheduler.utils.ParamUtil; import org.dinky.scheduler.utils.ParamUtil;
import org.dinky.scheduler.utils.ReadFileUtil; import org.dinky.utils.JsonUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
...@@ -75,7 +75,7 @@ public class ProcessClient { ...@@ -75,7 +75,7 @@ public class ProcessClient {
.getDolphinschedulerToken() .getDolphinschedulerToken()
.getValue()) .getValue())
.form(ParamUtil.getPageParams(processName)) .form(ParamUtil.getPageParams(processName))
.timeout(5000) .timeout(20000)
.execute() .execute()
.body(); .body();
PageInfo<JSONObject> data = MyJSONUtil.toPageBean(content); PageInfo<JSONObject> data = MyJSONUtil.toPageBean(content);
...@@ -85,7 +85,11 @@ public class ProcessClient { ...@@ -85,7 +85,11 @@ public class ProcessClient {
} }
for (JSONObject jsonObject : data.getTotalList()) { for (JSONObject jsonObject : data.getTotalList()) {
lists.add(MyJSONUtil.toBean(jsonObject, ProcessDefinition.class)); ProcessDefinition processDefinition = MyJSONUtil.toBean(jsonObject, ProcessDefinition.class);
// The locations of processDefinition is json string
List<DagNodeLocation> locations = jsonObject.getBeanList("locations", DagNodeLocation.class);
processDefinition.setLocations(locations);
lists.add(processDefinition);
} }
return lists; return lists;
} }
...@@ -127,7 +131,7 @@ public class ProcessClient { ...@@ -127,7 +131,7 @@ public class ProcessClient {
SystemConfiguration.getInstances() SystemConfiguration.getInstances()
.getDolphinschedulerToken() .getDolphinschedulerToken()
.getValue()) .getValue())
.timeout(5000) .timeout(20000)
.execute() .execute()
.body(); .body();
...@@ -148,6 +152,7 @@ public class ProcessClient { ...@@ -148,6 +152,7 @@ public class ProcessClient {
Long processCode, Long processCode,
String processName, String processName,
Long taskCode, Long taskCode,
String taskRelationJson,
String taskDefinitionJson, String taskDefinitionJson,
List<DagNodeLocation> locations, List<DagNodeLocation> locations,
boolean isModify) { boolean isModify) {
...@@ -160,8 +165,8 @@ public class ProcessClient { ...@@ -160,8 +165,8 @@ public class ProcessClient {
params.put("name", processName); params.put("name", processName);
params.put("description", "系统添加"); params.put("description", "系统添加");
params.put("tenantCode", "default"); params.put("tenantCode", "default");
params.put("locations", locations); params.put("locations", JsonUtils.toJsonString(locations));
params.put("taskRelationJson", ReadFileUtil.taskRelation(Collections.singletonMap("code", taskCode))); params.put("taskRelationJson", taskRelationJson);
params.put("taskDefinitionJson", taskDefinitionJson); params.put("taskDefinitionJson", taskDefinitionJson);
params.put("executionType", "PARALLEL"); params.put("executionType", "PARALLEL");
...@@ -178,7 +183,7 @@ public class ProcessClient { ...@@ -178,7 +183,7 @@ public class ProcessClient {
.getDolphinschedulerToken() .getDolphinschedulerToken()
.getValue()) .getValue())
.form(params) .form(params)
.timeout(5000) .timeout(20000)
.execute(); .execute();
String content = httpResponse.body(); String content = httpResponse.body();
return MyJSONUtil.verifyResult(MyJSONUtil.toBean(content, new TypeReference<Result<ProcessDefinition>>() {})); return MyJSONUtil.verifyResult(MyJSONUtil.toBean(content, new TypeReference<Result<ProcessDefinition>>() {}));
......
...@@ -138,7 +138,7 @@ public class TaskClient { ...@@ -138,7 +138,7 @@ public class TaskClient {
SystemConfiguration.getInstances() SystemConfiguration.getInstances()
.getDolphinschedulerToken() .getDolphinschedulerToken()
.getValue()) .getValue())
.timeout(5000) .timeout(20000)
.execute() .execute()
.body(); .body();
......
...@@ -26,6 +26,8 @@ import lombok.Data; ...@@ -26,6 +26,8 @@ import lombok.Data;
@Data @Data
public class DagNodeLocation implements Serializable { public class DagNodeLocation implements Serializable {
private static final long serialVersionUID = -5243356147439794746L;
private long taskCode; private long taskCode;
private long x; private long x;
private long y; private long y;
......
...@@ -67,4 +67,16 @@ public class ProcessTaskRelation { ...@@ -67,4 +67,16 @@ public class ProcessTaskRelation {
@ApiModelProperty(value = "更新时间") @ApiModelProperty(value = "更新时间")
private Date updateTime; private Date updateTime;
public static ProcessTaskRelation generateProcessTaskRelation(long taskCode) {
ProcessTaskRelation processTaskRelation = new ProcessTaskRelation();
processTaskRelation.setName("");
processTaskRelation.setPreTaskCode(0);
processTaskRelation.setPreTaskVersion(0);
processTaskRelation.setPostTaskCode(taskCode);
processTaskRelation.setPostTaskVersion(1);
processTaskRelation.setConditionType(ConditionType.NONE);
processTaskRelation.setConditionParams("{}");
return processTaskRelation;
}
} }
...@@ -74,6 +74,9 @@ public class TaskDefinition { ...@@ -74,6 +74,9 @@ public class TaskDefinition {
@ApiModelProperty(value = "运行标志 yes 正常/no 禁止执行") @ApiModelProperty(value = "运行标志 yes 正常/no 禁止执行")
private Flag flag; private Flag flag;
@ApiModelProperty(value = "Cache run: yes/no ")
private Flag isCache;
@ApiModelProperty(value = "优先级") @ApiModelProperty(value = "优先级")
private Priority taskPriority; private Priority taskPriority;
......
...@@ -53,6 +53,9 @@ public class TaskRequest { ...@@ -53,6 +53,9 @@ public class TaskRequest {
@ApiModelProperty(value = "运行标志 yes 正常/no 禁止执行") @ApiModelProperty(value = "运行标志 yes 正常/no 禁止执行")
private String flag; private String flag;
@ApiModelProperty(value = "Cache run: yes/no")
private String isCache;
@ApiModelProperty(value = "任务参数 默认DINKY参数") @ApiModelProperty(value = "任务参数 默认DINKY参数")
private String taskParams; private String taskParams;
......
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.scheduler.utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
public class ReadFileUtil {
private static final Logger logger = LoggerFactory.getLogger(ReadFileUtil.class);
public static String taskDefinition(Map<String, Object> maps) {
InputStream in = ReadFileUtil.class.getResourceAsStream("/json/taskDefinition.json");
String readFile = readFile(in);
if (maps == null || maps.isEmpty()) {
return readFile;
}
return StrUtil.format(readFile, maps);
}
public static String taskRelation(Map<String, Object> maps) {
InputStream in = ReadFileUtil.class.getResourceAsStream("/json/taskRelation.json");
String readFile = readFile(in);
if (maps == null || maps.isEmpty()) {
return readFile;
}
return StrUtil.format(readFile, maps);
}
public static String createTaskDefinition(Map<String, Object> maps) {
InputStream in = ReadFileUtil.class.getResourceAsStream("/json/createTaskDefinition.json");
String readFile = readFile(in);
if (maps == null || maps.isEmpty()) {
return readFile;
}
return StrUtil.format(readFile, maps);
}
/** 读取文件 */
public static String readFile(InputStream inputStream) {
try {
BufferedReader reader = IoUtil.getUtf8Reader(inputStream);
int ch;
StringBuilder sb = new StringBuilder();
while ((ch = reader.read()) != -1) {
sb.append((char) ch);
}
IoUtil.close(reader);
return sb.toString();
} catch (IOException e) {
logger.error(e.getMessage(), e);
return null;
}
}
}
...@@ -109,6 +109,8 @@ export default { ...@@ -109,6 +109,8 @@ export default {
'datastudio.header.pushdolphin.timeoutFlagTip': 'Please select a timeout warning', 'datastudio.header.pushdolphin.timeoutFlagTip': 'Please select a timeout warning',
'datastudio.header.pushdolphin.flag': 'Run flag', 'datastudio.header.pushdolphin.flag': 'Run flag',
'datastudio.header.pushdolphin.flagTip': 'Please select the run flag', 'datastudio.header.pushdolphin.flagTip': 'Please select the run flag',
'datastudio.header.pushdolphin.isCache': 'Cache run',
'datastudio.header.pushdolphin.isCacheTip': 'Please select cache run',
'datastudio.header.pushdolphin.timeoutNotifyStrategy': 'Timeout notification strategy', 'datastudio.header.pushdolphin.timeoutNotifyStrategy': 'Timeout notification strategy',
'datastudio.header.pushdolphin.timeoutNotifyStrategyTip': 'datastudio.header.pushdolphin.timeoutNotifyStrategyTip':
'Please select a timeout notification strategy', 'Please select a timeout notification strategy',
......
...@@ -102,6 +102,8 @@ export default { ...@@ -102,6 +102,8 @@ export default {
'datastudio.header.pushdolphin.timeoutFlagTip': '请选择超时警告', 'datastudio.header.pushdolphin.timeoutFlagTip': '请选择超时警告',
'datastudio.header.pushdolphin.flag': '运行标志', 'datastudio.header.pushdolphin.flag': '运行标志',
'datastudio.header.pushdolphin.flagTip': '请选择运行标志', 'datastudio.header.pushdolphin.flagTip': '请选择运行标志',
'datastudio.header.pushdolphin.isCache': '缓存执行',
'datastudio.header.pushdolphin.isCacheTip': '请选择是否缓存执行',
'datastudio.header.pushdolphin.timeoutNotifyStrategy': '超时通知策略', 'datastudio.header.pushdolphin.timeoutNotifyStrategy': '超时通知策略',
'datastudio.header.pushdolphin.timeoutNotifyStrategyTip': '请选择超时通知策略', 'datastudio.header.pushdolphin.timeoutNotifyStrategyTip': '请选择超时通知策略',
'datastudio.header.pushdolphin.timeout': '超时时间(分钟)', 'datastudio.header.pushdolphin.timeout': '超时时间(分钟)',
......
...@@ -30,6 +30,7 @@ export const transformPushDolphinParams = ( ...@@ -30,6 +30,7 @@ export const transformPushDolphinParams = (
description: dolphinTaskDefinition.description, description: dolphinTaskDefinition.description,
timeoutFlag: dolphinTaskDefinition.timeoutFlag === 'OPEN', timeoutFlag: dolphinTaskDefinition.timeoutFlag === 'OPEN',
flag: dolphinTaskDefinition.flag === 'YES', flag: dolphinTaskDefinition.flag === 'YES',
isCache: dolphinTaskDefinition.isCache === 'YES',
upstreamCodes: dolphinTaskDefinition.upstreamTaskMap upstreamCodes: dolphinTaskDefinition.upstreamTaskMap
? Object.keys(dolphinTaskDefinition.upstreamTaskMap) ? Object.keys(dolphinTaskDefinition.upstreamTaskMap)
: [], : [],
...@@ -46,6 +47,7 @@ export const transformPushDolphinParams = ( ...@@ -46,6 +47,7 @@ export const transformPushDolphinParams = (
description: pushDolphinParams.description, description: pushDolphinParams.description,
timeoutFlag: pushDolphinParams.timeoutFlag ? 'OPEN' : 'CLOSE', timeoutFlag: pushDolphinParams.timeoutFlag ? 'OPEN' : 'CLOSE',
flag: pushDolphinParams.flag ? 'YES' : 'NO', flag: pushDolphinParams.flag ? 'YES' : 'NO',
isCache: pushDolphinParams.isCache ? 'YES' : 'NO',
timeoutNotifyStrategy: (pushDolphinParams.timeoutNotifyStrategy as string[]).join('') timeoutNotifyStrategy: (pushDolphinParams.timeoutNotifyStrategy as string[]).join('')
}; };
return falseTransformValue; return falseTransformValue;
......
...@@ -239,6 +239,13 @@ export const PushDolphin: React.FC<PushDolphinProps> = (props) => { ...@@ -239,6 +239,13 @@ export const PushDolphin: React.FC<PushDolphinProps> = (props) => {
{...SWITCH_OPTIONS()} {...SWITCH_OPTIONS()}
name={'flag'} name={'flag'}
/> />
<ProFormSwitch
label={l('datastudio.header.pushdolphin.isCache')}
rules={[{ required: true, message: l('datastudio.header.pushdolphin.isCacheTip') }]}
{...SWITCH_OPTIONS()}
name={'isCache'}
/>
</ProFormGroup> </ProFormGroup>
{/*如果是失败告警,则需要设置告警策略*/} {/*如果是失败告警,则需要设置告警策略*/}
{formValues.timeoutFlag && ( {formValues.timeoutFlag && (
......
...@@ -55,7 +55,6 @@ import { API_CONSTANTS } from '@/services/endpoints'; ...@@ -55,7 +55,6 @@ 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 { DolphinTaskDefinition, DolphinTaskMinInfo } from '@/types/Studio/data.d';
import { l } from '@/utils/intl'; import { l } from '@/utils/intl';
import { SuccessMessageAsync } from '@/utils/messages';
import { import {
ApartmentOutlined, ApartmentOutlined,
BugOutlined, BugOutlined,
...@@ -190,8 +189,6 @@ const HeaderContainer = (props: connect) => { ...@@ -190,8 +189,6 @@ const HeaderContainer = (props: connect) => {
const handlerDebug = async () => { const handlerDebug = async () => {
if (!currentData) return; if (!currentData) return;
const saved = currentData.step == JOB_LIFE_CYCLE.PUBLISH ? true : await handleSave();
if (!saved) return;
// @ts-ignore // @ts-ignore
const editor = currentTab.monacoInstance.editor const editor = currentTab.monacoInstance.editor
.getEditors() .getEditors()
...@@ -217,7 +214,6 @@ const HeaderContainer = (props: connect) => { ...@@ -217,7 +214,6 @@ const HeaderContainer = (props: connect) => {
jobState: res.data.status, jobState: res.data.status,
runningLog: res.msg runningLog: res.msg
}); });
await SuccessMessageAsync(l('pages.datastudio.editor.debug.success'));
currentData.status = JOB_STATUS.RUNNING; currentData.status = JOB_STATUS.RUNNING;
// Common sql task is synchronized, so it needs to automatically update the status to finished. // Common sql task is synchronized, so it needs to automatically update the status to finished.
if (isSql(currentData.dialect)) { if (isSql(currentData.dialect)) {
...@@ -251,7 +247,6 @@ const HeaderContainer = (props: connect) => { ...@@ -251,7 +247,6 @@ const HeaderContainer = (props: connect) => {
jobState: res.data.status, jobState: res.data.status,
runningLog: res.msg runningLog: res.msg
}); });
await SuccessMessageAsync(l('pages.datastudio.editor.exec.success'));
currentData.status = JOB_STATUS.RUNNING; currentData.status = JOB_STATUS.RUNNING;
// Common sql task is synchronized, so it needs to automatically update the status to finished. // Common sql task is synchronized, so it needs to automatically update the status to finished.
if (isSql(currentData.dialect)) { if (isSql(currentData.dialect)) {
......
...@@ -267,6 +267,7 @@ export interface DolphinTaskDefinition { ...@@ -267,6 +267,7 @@ export interface DolphinTaskDefinition {
taskParamList: TaskParamProperty[]; taskParamList: TaskParamProperty[];
taskParamMap: Map<string, string>; taskParamMap: Map<string, string>;
flag: string; // 0 no 1 yes flag: string; // 0 no 1 yes
isCache: string; // 0 no 1 yes
taskPriority: string; // 0 highest 1 high 2 medium 3 low 4 lowest taskPriority: string; // 0 highest 1 high 2 medium 3 low 4 lowest
userName: string; userName: string;
projectName: string; projectName: string;
...@@ -303,6 +304,7 @@ export interface PushDolphinParams { ...@@ -303,6 +304,7 @@ export interface PushDolphinParams {
timeout: number; timeout: number;
timeoutFlag: boolean | string; timeoutFlag: boolean | string;
flag: boolean | string; flag: boolean | string;
isCache: boolean | string;
timeoutNotifyStrategy: string[] | string; timeoutNotifyStrategy: string[] | string;
description: string; description: string;
} }
...@@ -48,6 +48,7 @@ export const InitPushDolphinParams: PushDolphinParams = { ...@@ -48,6 +48,7 @@ export const InitPushDolphinParams: PushDolphinParams = {
timeout: 30, timeout: 30,
timeoutFlag: false, timeoutFlag: false,
flag: false, flag: false,
isCache: false,
timeoutNotifyStrategy: ['WARN'], timeoutNotifyStrategy: ['WARN'],
description: '' description: ''
}; };
......
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