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);
} }
......
...@@ -33,14 +33,15 @@ import org.dinky.scheduler.model.DagNodeLocation; ...@@ -33,14 +33,15 @@ import org.dinky.scheduler.model.DagNodeLocation;
import org.dinky.scheduler.model.DinkyTaskParams; import org.dinky.scheduler.model.DinkyTaskParams;
import org.dinky.scheduler.model.DinkyTaskRequest; import org.dinky.scheduler.model.DinkyTaskRequest;
import org.dinky.scheduler.model.ProcessDefinition; import org.dinky.scheduler.model.ProcessDefinition;
import org.dinky.scheduler.model.ProcessTaskRelation;
import org.dinky.scheduler.model.Project; import org.dinky.scheduler.model.Project;
import org.dinky.scheduler.model.TaskDefinition; import org.dinky.scheduler.model.TaskDefinition;
import org.dinky.scheduler.model.TaskMainInfo; import org.dinky.scheduler.model.TaskMainInfo;
import org.dinky.scheduler.model.TaskRequest; import org.dinky.scheduler.model.TaskRequest;
import org.dinky.service.CatalogueService; import org.dinky.service.CatalogueService;
import org.dinky.service.SchedulerService; import org.dinky.service.SchedulerService;
import org.dinky.utils.JsonUtils;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
...@@ -76,6 +77,13 @@ public class SchedulerServiceImpl implements SchedulerService { ...@@ -76,6 +77,13 @@ public class SchedulerServiceImpl implements SchedulerService {
*/ */
@Override @Override
public boolean pushAddTask(DinkyTaskRequest dinkyTaskRequest) { public boolean pushAddTask(DinkyTaskRequest dinkyTaskRequest) {
// Use root catalog as process (workflow) name.
Catalogue catalogue = catalogueService.getOne(
new LambdaQueryWrapper<Catalogue>().eq(Catalogue::getTaskId, dinkyTaskRequest.getTaskId()));
if (catalogue == null) {
log.error(Status.DS_GET_NODE_LIST_ERROR.getMessage());
throw new BusException(Status.DS_GET_NODE_LIST_ERROR);
}
DinkyTaskParams dinkyTaskParams = new DinkyTaskParams(); DinkyTaskParams dinkyTaskParams = new DinkyTaskParams();
dinkyTaskParams.setTaskId(dinkyTaskRequest.getTaskId()); dinkyTaskParams.setTaskId(dinkyTaskRequest.getTaskId());
...@@ -84,77 +92,91 @@ public class SchedulerServiceImpl implements SchedulerService { ...@@ -84,77 +92,91 @@ public class SchedulerServiceImpl implements SchedulerService {
dinkyTaskRequest.setTaskParams(JSONUtil.parseObj(dinkyTaskParams).toString()); dinkyTaskRequest.setTaskParams(JSONUtil.parseObj(dinkyTaskParams).toString());
dinkyTaskRequest.setTaskType(TASK_TYPE); dinkyTaskRequest.setTaskType(TASK_TYPE);
Catalogue catalogue = catalogueService.getOne(
new LambdaQueryWrapper<Catalogue>().eq(Catalogue::getTaskId, dinkyTaskRequest.getTaskId()));
if (catalogue == null) {
log.error(Status.DS_GET_NODE_LIST_ERROR.getMessage());
throw new BusException(Status.DS_GET_NODE_LIST_ERROR);
}
String processName = getDinkyNames(catalogue, 0); String processName = getDinkyNames(catalogue, 0);
long projectCode = SystemInit.getProject().getCode(); long projectCode = SystemInit.getProject().getCode();
// Get process from dolphin scheduler
ProcessDefinition process = processClient.getProcessDefinitionInfo(projectCode, processName); ProcessDefinition process = processClient.getProcessDefinitionInfo(projectCode, processName);
String taskName = catalogue.getName() + ":" + catalogue.getId(); String taskName = catalogue.getName() + ":" + catalogue.getId();
dinkyTaskRequest.setName(taskName); dinkyTaskRequest.setName(taskName);
TaskRequest taskRequest = new TaskRequest(); TaskRequest taskRequest = new TaskRequest();
JSONArray array = new JSONArray();
Long taskCode = taskClient.genTaskCode(projectCode); Long taskCode = taskClient.genTaskCode(projectCode);
// If the process does not exist, a process needs to be created.
if (process == null) { if (process == null) {
dinkyTaskRequest.setCode(taskCode); dinkyTaskRequest.setCode(taskCode);
BeanUtil.copyProperties(dinkyTaskRequest, taskRequest); BeanUtil.copyProperties(dinkyTaskRequest, taskRequest);
taskRequest.setTimeoutFlag(dinkyTaskRequest.getTimeoutFlag()); taskRequest.setTimeoutFlag(dinkyTaskRequest.getTimeoutFlag());
taskRequest.setFlag(dinkyTaskRequest.getFlag()); taskRequest.setFlag(dinkyTaskRequest.getFlag());
taskRequest.setIsCache(dinkyTaskRequest.getIsCache());
JSONObject jsonObject = JSONUtil.parseObj(taskRequest); JSONObject jsonObject = JSONUtil.parseObj(taskRequest);
array.set(jsonObject); JSONArray taskArray = new JSONArray();
taskArray.set(jsonObject);
log.info(Status.DS_ADD_WORK_FLOW_DEFINITION_SUCCESS.getMessage()); log.info(Status.DS_ADD_WORK_FLOW_DEFINITION_SUCCESS.getMessage());
// 随机出一个 x y 坐标
DagNodeLocation dagNodeLocation = new DagNodeLocation(); DagNodeLocation dagNodeLocation = new DagNodeLocation();
dagNodeLocation.setTaskCode(taskCode); dagNodeLocation.setTaskCode(taskCode);
dagNodeLocation.setX(RandomUtil.randomLong(200, 500)); dagNodeLocation.setX(RandomUtil.randomLong(200, 500));
dagNodeLocation.setY(RandomUtil.randomLong(100, 400)); dagNodeLocation.setY(RandomUtil.randomLong(100, 400));
log.info("DagNodeLocation Info: {}", dagNodeLocation); log.info("DagNodeLocation Info: {}", dagNodeLocation);
ProcessTaskRelation processTaskRelation = ProcessTaskRelation.generateProcessTaskRelation(taskCode);
JSONObject processTaskRelationJSONObject = JSONUtil.parseObj(processTaskRelation);
JSONArray taskRelationArray = new JSONArray();
taskRelationArray.set(processTaskRelationJSONObject);
processClient.createOrUpdateProcessDefinition( processClient.createOrUpdateProcessDefinition(
projectCode, null, processName, taskCode, array.toString(), Arrays.asList(dagNodeLocation), false); projectCode,
null,
processName,
taskCode,
taskRelationArray.toString(),
taskArray.toString(),
Arrays.asList(dagNodeLocation),
false);
return true;
} }
if (process != null && process.getReleaseState() == ReleaseState.ONLINE) { // If the workflow is in an online state, it cannot be updated.
if (process.getReleaseState() == ReleaseState.ONLINE) {
log.error(Status.DS_WORK_FLOW_DEFINITION_ONLINE.getMessage(), processName); log.error(Status.DS_WORK_FLOW_DEFINITION_ONLINE.getMessage(), processName);
} }
TaskMainInfo taskMainInfo = taskClient.getTaskMainInfo(projectCode, processName, taskName, "DINKY"); TaskMainInfo taskMainInfo = taskClient.getTaskMainInfo(projectCode, processName, taskName, TASK_TYPE);
// If task name exist, update task definition.
if (taskMainInfo != null) { if (taskMainInfo != null) {
// if task name exist, update task definition
log.warn(Status.DS_WORK_FLOW_DEFINITION_TASK_NAME_EXIST.getMessage(), processName, taskName); log.warn(Status.DS_WORK_FLOW_DEFINITION_TASK_NAME_EXIST.getMessage(), processName, taskName);
return pushUpdateTask( return pushUpdateTask(
projectCode, taskMainInfo.getProcessDefinitionCode(), taskMainInfo.getTaskCode(), dinkyTaskRequest); projectCode, taskMainInfo.getProcessDefinitionCode(), taskMainInfo.getTaskCode(), dinkyTaskRequest);
} }
// If the task does not exist, a dinky task needs to be created.
dinkyTaskRequest.setCode(taskCode); dinkyTaskRequest.setCode(taskCode);
BeanUtil.copyProperties(dinkyTaskRequest, taskRequest); BeanUtil.copyProperties(dinkyTaskRequest, taskRequest);
taskRequest.setTimeoutFlag(dinkyTaskRequest.getTimeoutFlag()); taskRequest.setTimeoutFlag(dinkyTaskRequest.getTimeoutFlag());
taskRequest.setFlag(dinkyTaskRequest.getFlag()); taskRequest.setFlag(dinkyTaskRequest.getFlag());
taskRequest.setIsCache(dinkyTaskRequest.getIsCache());
String taskDefinitionJsonObj = JSONUtil.toJsonStr(taskRequest); String taskDefinitionJsonObj = JSONUtil.toJsonStr(taskRequest);
if (process != null) { taskClient.createTaskDefinition(
taskClient.createTaskDefinition( projectCode, process.getCode(), dinkyTaskRequest.getUpstreamCodes(), taskDefinitionJsonObj);
projectCode, process.getCode(), dinkyTaskRequest.getUpstreamCodes(), taskDefinitionJsonObj); // update the location of process
// 更新 process 的 location 信息 updateProcessDefinition(process, taskCode, taskRequest, projectCode);
updateProcessDefinition(process, taskCode, taskRequest, array, projectCode);
log.info(Status.DS_ADD_TASK_DEFINITION_SUCCESS.getMessage()); log.info(Status.DS_ADD_TASK_DEFINITION_SUCCESS.getMessage());
return true; return true;
}
return false;
} }
private void updateProcessDefinition( private void updateProcessDefinition(ProcessDefinition process, Long taskCode, TaskRequest task, long projectCode) {
ProcessDefinition process, Long taskCode, TaskRequest taskRequest, JSONArray array, long projectCode) {
JSONObject jsonObject = JSONUtil.parseObj(taskRequest);
array.set(jsonObject);
List<DagNodeLocation> locations = new ArrayList<>(); DagData dagData = processClient.getProcessDefinitionInfo(projectCode, process.getCode());
if (dagData == null) {
log.error(Status.DS_WORK_FLOW_DEFINITION_NOT_EXIST.getMessage());
throw new BusException(Status.DS_WORK_FLOW_DEFINITION_NOT_EXIST);
}
List<ProcessTaskRelation> processTaskRelationList = dagData.getProcessTaskRelationList();
List<TaskDefinition> taskDefinitionList = dagData.getTaskDefinitionList();
List<DagNodeLocation> locations = process.getLocations();
if (CollUtil.isNotEmpty(process.getLocations())) { if (CollUtil.isNotEmpty(process.getLocations())) {
boolean matched = process.getLocations().stream().anyMatch(location -> location.getTaskCode() == taskCode); boolean matched = process.getLocations().stream().anyMatch(location -> location.getTaskCode() == taskCode);
...@@ -175,13 +197,13 @@ public class SchedulerServiceImpl implements SchedulerService { ...@@ -175,13 +197,13 @@ public class SchedulerServiceImpl implements SchedulerService {
.getAsLong(); .getAsLong();
long yMin = process.getLocations().stream() long yMin = process.getLocations().stream()
.mapToLong(DagNodeLocation::getY) .mapToLong(DagNodeLocation::getY)
.max() .min()
.getAsLong(); .getAsLong();
// 随机出一个 x y 坐标 // 随机出一个 x y 坐标
DagNodeLocation dagNodeLocation = new DagNodeLocation(); DagNodeLocation dagNodeLocation = new DagNodeLocation();
dagNodeLocation.setTaskCode(taskCode); dagNodeLocation.setTaskCode(taskCode);
dagNodeLocation.setX(RandomUtil.randomLong(xMax, xMin)); dagNodeLocation.setX(RandomUtil.randomLong(xMin == xMax ? 0 : xMin, xMax));
dagNodeLocation.setY(RandomUtil.randomLong(yMax, yMin)); dagNodeLocation.setY(RandomUtil.randomLong(yMin == yMax ? 0 : yMin, yMax));
locations = process.getLocations(); locations = process.getLocations();
locations.add(dagNodeLocation); locations.add(dagNodeLocation);
} }
...@@ -194,13 +216,27 @@ public class SchedulerServiceImpl implements SchedulerService { ...@@ -194,13 +216,27 @@ public class SchedulerServiceImpl implements SchedulerService {
locations.add(dagNodeLocation); locations.add(dagNodeLocation);
} }
JSONArray taskArray = new JSONArray();
taskDefinitionList.removeIf(taskDefinition -> (task.getName()).equalsIgnoreCase(taskDefinition.getName()));
taskArray.addAll(taskDefinitionList);
taskArray.add(task);
String processTaskRelationListJson = JsonUtils.toJsonString(processTaskRelationList);
processClient.createOrUpdateProcessDefinition( processClient.createOrUpdateProcessDefinition(
projectCode, process.getCode(), process.getName(), taskCode, array.toString(), locations, true); projectCode,
process.getCode(),
process.getName(),
taskCode,
processTaskRelationListJson,
taskArray.toString(),
locations,
true);
log.info( log.info(
Status.DS_PROCESS_DEFINITION_UPDATE.getMessage(), Status.DS_PROCESS_DEFINITION_UPDATE.getMessage(),
process.getName(), process.getName(),
taskCode, taskCode,
array.toString(), taskArray.toString(),
locations); locations);
} }
...@@ -251,14 +287,13 @@ public class SchedulerServiceImpl implements SchedulerService { ...@@ -251,14 +287,13 @@ public class SchedulerServiceImpl implements SchedulerService {
BeanUtil.copyProperties(dinkyTaskRequest, taskRequest); BeanUtil.copyProperties(dinkyTaskRequest, taskRequest);
taskRequest.setTimeoutFlag(dinkyTaskRequest.getTimeoutFlag()); taskRequest.setTimeoutFlag(dinkyTaskRequest.getTimeoutFlag());
taskRequest.setFlag(dinkyTaskRequest.getFlag()); taskRequest.setFlag(dinkyTaskRequest.getFlag());
taskRequest.setIsCache(dinkyTaskRequest.getIsCache());
String taskDefinitionJsonObj = JSONUtil.toJsonStr(taskRequest); String taskDefinitionJsonObj = JSONUtil.toJsonStr(taskRequest);
Long updatedTaskDefinition = taskClient.updateTaskDefinition( Long updatedTaskDefinition = taskClient.updateTaskDefinition(
projectCode, taskCode, dinkyTaskRequest.getUpstreamCodes(), taskDefinitionJsonObj); projectCode, taskCode, dinkyTaskRequest.getUpstreamCodes(), taskDefinitionJsonObj);
JSONObject jsonObject = JSONUtil.parseObj(taskRequest);
JSONArray array = new JSONArray(); updateProcessDefinition(process, taskCode, taskRequest, projectCode);
array.set(jsonObject);
updateProcessDefinition(process, taskCode, taskRequest, array, projectCode);
if (updatedTaskDefinition != null && updatedTaskDefinition > 0) { if (updatedTaskDefinition != null && updatedTaskDefinition > 0) {
log.info(Status.MODIFY_SUCCESS.getMessage()); log.info(Status.MODIFY_SUCCESS.getMessage());
return true; return true;
...@@ -309,7 +344,7 @@ public class SchedulerServiceImpl implements SchedulerService { ...@@ -309,7 +344,7 @@ public class SchedulerServiceImpl implements SchedulerService {
String processName = getDinkyNames(catalogue, 0); String processName = getDinkyNames(catalogue, 0);
String taskName = catalogue.getName() + ":" + catalogue.getId(); String taskName = catalogue.getName() + ":" + catalogue.getId();
TaskMainInfo taskMainInfo = taskClient.getTaskMainInfo(projectCode, processName, taskName, "DINKY"); TaskMainInfo taskMainInfo = taskClient.getTaskMainInfo(projectCode, processName, taskName, TASK_TYPE);
TaskDefinition taskDefinition = null; TaskDefinition taskDefinition = null;
if (taskMainInfo == null) { if (taskMainInfo == null) {
log.error(Status.DS_WORK_FLOW_DEFINITION_NOT_EXIST.getMessage(), processName, taskName); log.error(Status.DS_WORK_FLOW_DEFINITION_NOT_EXIST.getMessage(), processName, taskName);
......
...@@ -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