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;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import cn.hutool.core.collection.CollUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
......@@ -84,9 +83,6 @@ public class SchedulerController {
example = "1")
public Result<List<TaskMainInfo>> getTaskMainInfos(@ApiParam(value = "dinky任务id") @RequestParam Long dinkyTaskId) {
List<TaskMainInfo> taskMainInfos = schedulerService.getTaskMainInfos(dinkyTaskId);
if (CollUtil.isEmpty(taskMainInfos)) {
return Result.failed();
}
return Result.succeed(taskMainInfos);
}
......
......@@ -28,7 +28,7 @@ import org.dinky.scheduler.result.PageInfo;
import org.dinky.scheduler.result.Result;
import org.dinky.scheduler.utils.MyJSONUtil;
import org.dinky.scheduler.utils.ParamUtil;
import org.dinky.scheduler.utils.ReadFileUtil;
import org.dinky.utils.JsonUtils;
import java.util.ArrayList;
import java.util.Collections;
......@@ -75,7 +75,7 @@ public class ProcessClient {
.getDolphinschedulerToken()
.getValue())
.form(ParamUtil.getPageParams(processName))
.timeout(5000)
.timeout(20000)
.execute()
.body();
PageInfo<JSONObject> data = MyJSONUtil.toPageBean(content);
......@@ -85,7 +85,11 @@ public class ProcessClient {
}
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;
}
......@@ -127,7 +131,7 @@ public class ProcessClient {
SystemConfiguration.getInstances()
.getDolphinschedulerToken()
.getValue())
.timeout(5000)
.timeout(20000)
.execute()
.body();
......@@ -148,6 +152,7 @@ public class ProcessClient {
Long processCode,
String processName,
Long taskCode,
String taskRelationJson,
String taskDefinitionJson,
List<DagNodeLocation> locations,
boolean isModify) {
......@@ -160,8 +165,8 @@ public class ProcessClient {
params.put("name", processName);
params.put("description", "系统添加");
params.put("tenantCode", "default");
params.put("locations", locations);
params.put("taskRelationJson", ReadFileUtil.taskRelation(Collections.singletonMap("code", taskCode)));
params.put("locations", JsonUtils.toJsonString(locations));
params.put("taskRelationJson", taskRelationJson);
params.put("taskDefinitionJson", taskDefinitionJson);
params.put("executionType", "PARALLEL");
......@@ -178,7 +183,7 @@ public class ProcessClient {
.getDolphinschedulerToken()
.getValue())
.form(params)
.timeout(5000)
.timeout(20000)
.execute();
String content = httpResponse.body();
return MyJSONUtil.verifyResult(MyJSONUtil.toBean(content, new TypeReference<Result<ProcessDefinition>>() {}));
......
......@@ -138,7 +138,7 @@ public class TaskClient {
SystemConfiguration.getInstances()
.getDolphinschedulerToken()
.getValue())
.timeout(5000)
.timeout(20000)
.execute()
.body();
......
......@@ -26,6 +26,8 @@ import lombok.Data;
@Data
public class DagNodeLocation implements Serializable {
private static final long serialVersionUID = -5243356147439794746L;
private long taskCode;
private long x;
private long y;
......
......@@ -67,4 +67,16 @@ public class ProcessTaskRelation {
@ApiModelProperty(value = "更新时间")
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 {
@ApiModelProperty(value = "运行标志 yes 正常/no 禁止执行")
private Flag flag;
@ApiModelProperty(value = "Cache run: yes/no ")
private Flag isCache;
@ApiModelProperty(value = "优先级")
private Priority taskPriority;
......
......@@ -53,6 +53,9 @@ public class TaskRequest {
@ApiModelProperty(value = "运行标志 yes 正常/no 禁止执行")
private String flag;
@ApiModelProperty(value = "Cache run: yes/no")
private String isCache;
@ApiModelProperty(value = "任务参数 默认DINKY参数")
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 {
'datastudio.header.pushdolphin.timeoutFlagTip': 'Please select a timeout warning',
'datastudio.header.pushdolphin.flag': '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.timeoutNotifyStrategyTip':
'Please select a timeout notification strategy',
......
......@@ -102,6 +102,8 @@ export default {
'datastudio.header.pushdolphin.timeoutFlagTip': '请选择超时警告',
'datastudio.header.pushdolphin.flag': '运行标志',
'datastudio.header.pushdolphin.flagTip': '请选择运行标志',
'datastudio.header.pushdolphin.isCache': '缓存执行',
'datastudio.header.pushdolphin.isCacheTip': '请选择是否缓存执行',
'datastudio.header.pushdolphin.timeoutNotifyStrategy': '超时通知策略',
'datastudio.header.pushdolphin.timeoutNotifyStrategyTip': '请选择超时通知策略',
'datastudio.header.pushdolphin.timeout': '超时时间(分钟)',
......
......@@ -30,6 +30,7 @@ export const transformPushDolphinParams = (
description: dolphinTaskDefinition.description,
timeoutFlag: dolphinTaskDefinition.timeoutFlag === 'OPEN',
flag: dolphinTaskDefinition.flag === 'YES',
isCache: dolphinTaskDefinition.isCache === 'YES',
upstreamCodes: dolphinTaskDefinition.upstreamTaskMap
? Object.keys(dolphinTaskDefinition.upstreamTaskMap)
: [],
......@@ -46,6 +47,7 @@ export const transformPushDolphinParams = (
description: pushDolphinParams.description,
timeoutFlag: pushDolphinParams.timeoutFlag ? 'OPEN' : 'CLOSE',
flag: pushDolphinParams.flag ? 'YES' : 'NO',
isCache: pushDolphinParams.isCache ? 'YES' : 'NO',
timeoutNotifyStrategy: (pushDolphinParams.timeoutNotifyStrategy as string[]).join('')
};
return falseTransformValue;
......
......@@ -239,6 +239,13 @@ export const PushDolphin: React.FC<PushDolphinProps> = (props) => {
{...SWITCH_OPTIONS()}
name={'flag'}
/>
<ProFormSwitch
label={l('datastudio.header.pushdolphin.isCache')}
rules={[{ required: true, message: l('datastudio.header.pushdolphin.isCacheTip') }]}
{...SWITCH_OPTIONS()}
name={'isCache'}
/>
</ProFormGroup>
{/*如果是失败告警,则需要设置告警策略*/}
{formValues.timeoutFlag && (
......
......@@ -55,7 +55,6 @@ import { API_CONSTANTS } from '@/services/endpoints';
import { Jobs } from '@/types/DevOps/data.d';
import { DolphinTaskDefinition, DolphinTaskMinInfo } from '@/types/Studio/data.d';
import { l } from '@/utils/intl';
import { SuccessMessageAsync } from '@/utils/messages';
import {
ApartmentOutlined,
BugOutlined,
......@@ -190,8 +189,6 @@ const HeaderContainer = (props: connect) => {
const handlerDebug = async () => {
if (!currentData) return;
const saved = currentData.step == JOB_LIFE_CYCLE.PUBLISH ? true : await handleSave();
if (!saved) return;
// @ts-ignore
const editor = currentTab.monacoInstance.editor
.getEditors()
......@@ -217,7 +214,6 @@ const HeaderContainer = (props: connect) => {
jobState: res.data.status,
runningLog: res.msg
});
await SuccessMessageAsync(l('pages.datastudio.editor.debug.success'));
currentData.status = JOB_STATUS.RUNNING;
// Common sql task is synchronized, so it needs to automatically update the status to finished.
if (isSql(currentData.dialect)) {
......@@ -251,7 +247,6 @@ const HeaderContainer = (props: connect) => {
jobState: res.data.status,
runningLog: res.msg
});
await SuccessMessageAsync(l('pages.datastudio.editor.exec.success'));
currentData.status = JOB_STATUS.RUNNING;
// Common sql task is synchronized, so it needs to automatically update the status to finished.
if (isSql(currentData.dialect)) {
......
......@@ -267,6 +267,7 @@ export interface DolphinTaskDefinition {
taskParamList: TaskParamProperty[];
taskParamMap: Map<string, string>;
flag: string; // 0 no 1 yes
isCache: string; // 0 no 1 yes
taskPriority: string; // 0 highest 1 high 2 medium 3 low 4 lowest
userName: string;
projectName: string;
......@@ -303,6 +304,7 @@ export interface PushDolphinParams {
timeout: number;
timeoutFlag: boolean | string;
flag: boolean | string;
isCache: boolean | string;
timeoutNotifyStrategy: string[] | string;
description: string;
}
......@@ -48,6 +48,7 @@ export const InitPushDolphinParams: PushDolphinParams = {
timeout: 30,
timeoutFlag: false,
flag: false,
isCache: false,
timeoutNotifyStrategy: ['WARN'],
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