Unverified Commit 2d54ad79 authored by Zzm0809's avatar Zzm0809 Committed by GitHub

Support init task value (#2724)

* Spotless Apply * Spotless Apply * support-init-task-value * Spotless Apply --------- Co-authored-by: 's avatarZzm0809 <Zzm0809@users.noreply.github.com>
parent be7b7701
......@@ -147,6 +147,9 @@ public class CatalogueController {
dataType = "CatalogueTaskDTO",
dataTypeClass = CatalogueTaskDTO.class)
public Result<Catalogue> createTask(@RequestBody CatalogueTaskDTO catalogueTaskDTO) {
if (catalogueService.checkCatalogueTaskNameIsExist(catalogueTaskDTO.getName())) {
return Result.failed(Status.TASK_IS_EXIST);
}
Catalogue catalogue = catalogueService.saveOrUpdateCatalogueAndTask(catalogueTaskDTO);
if (catalogue.getId() != null) {
return Result.succeed(catalogue, Status.SAVE_SUCCESS);
......
......@@ -80,4 +80,7 @@ public class CatalogueTaskDTO {
dataType = "TaskExtConfig",
notes = "The task's extended configuration in JSON format")
private TaskExtConfig configJson;
@ApiModelProperty(value = "Task", dataType = "TaskDTO", notes = "The task information")
private TaskDTO task;
}
......@@ -131,4 +131,11 @@ public interface CatalogueService extends ISuperService<Catalogue> {
* @return A boolean value indicating whether the operation was successful.
*/
Boolean saveOrUpdateOrRename(Catalogue catalogue);
/**
* Check if the catalogue task name is exist
* @param name catalogue task name
* @return true if the catalogue task name is exist
*/
boolean checkCatalogueTaskNameIsExist(String name);
}
......@@ -22,6 +22,7 @@ package org.dinky.service.impl;
import static org.dinky.assertion.Asserts.isNull;
import org.dinky.assertion.Asserts;
import org.dinky.config.Dialect;
import org.dinky.data.dto.CatalogueTaskDTO;
import org.dinky.data.enums.JobLifeCycle;
import org.dinky.data.enums.Status;
......@@ -31,6 +32,7 @@ import org.dinky.data.model.job.History;
import org.dinky.data.model.job.JobHistory;
import org.dinky.data.model.job.JobInstance;
import org.dinky.data.result.Result;
import org.dinky.gateway.enums.GatewayType;
import org.dinky.mapper.CatalogueMapper;
import org.dinky.mybatis.service.impl.SuperServiceImpl;
import org.dinky.service.CatalogueService;
......@@ -58,6 +60,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Opt;
import cn.hutool.core.util.ObjectUtil;
import lombok.RequiredArgsConstructor;
......@@ -86,7 +89,8 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
}
/**
* build catalogue tree
* build catalogue tree
*
* @param catalogueList catalogue list
* @return catalogue tree
*/
......@@ -114,6 +118,7 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
/**
* recursion build catalogue and children
*
* @param list
* @param catalogues
*/
......@@ -140,6 +145,7 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
/**
* Determine whether there are child nodes
*
* @param list
* @param catalogue
* @return
......@@ -150,6 +156,7 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
/**
* get child list
*
* @param list
* @param catalogue
* @return
......@@ -171,13 +178,46 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
.eq(Catalogue::getName, name));
}
/**
* check catalogue task name is exist
* @param name name
* @return true if exist , otherwise false
*/
@Override
public boolean checkCatalogueTaskNameIsExist(String name) {
return getBaseMapper().exists(new LambdaQueryWrapper<Catalogue>().eq(Catalogue::getName, name));
}
/**
* init some value
* @param catalogueTask {@link CatalogueTaskDTO}
* @return {@link Task}
*/
private Task initTaskValue(CatalogueTaskDTO catalogueTask) {
Task task = new Task();
if (Opt.ofNullable(catalogueTask.getTask()).isPresent()) {
task = catalogueTask.getTask().buildTask();
} else {
task.setStep(JobLifeCycle.DEVELOP.getValue());
task.setEnabled(true);
if (Dialect.isFlinkSql(catalogueTask.getType(), false)) {
task.setType(GatewayType.LOCAL.getLongValue());
task.setParallelism(1);
task.setSavePointStrategy(0); // 0 is disabled
task.setEnvId(-1); // -1 is disabled
task.setAlertGroupId(-1); // -1 is disabled
}
}
return task;
}
@Transactional(rollbackFor = Exception.class)
@Override
public Catalogue saveOrUpdateCatalogueAndTask(CatalogueTaskDTO catalogueTaskDTO) {
Task task = null;
Catalogue catalogue = null;
if (catalogueTaskDTO.getId() == null) {
task = new Task();
task = initTaskValue(catalogueTaskDTO);
catalogue = new Catalogue();
} else {
catalogue = baseMapper.selectById(catalogueTaskDTO.getId());
......@@ -439,10 +479,11 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
/**
* <p>
* 1. save catalogue
* 2. save task
* 3. save statement
* 4. rename
* 1. save catalogue
* 2. save task
* 3. save statement
* 4. rename
*
* @param catalogue
* @return
*/
......
......@@ -109,6 +109,19 @@ public enum Dialect {
}
}
public static boolean isFlinkSql(String value, boolean includeFlinksqlEnv) {
Dialect dialect = Dialect.get(value);
switch (dialect) {
case FLINK_SQL:
case FLINK_JAR:
return true;
case FLINK_SQL_ENV:
return includeFlinksqlEnv;
default:
return false;
}
}
public static boolean isJarDialect(String value) {
Dialect dialect = Dialect.get(value);
switch (dialect) {
......
......@@ -183,6 +183,7 @@ public enum Status {
TASK_SQL_EXPLAN_FAILED(12007, "task.sql.explain.failed"),
TASK_UPDATE_FAILED(12008, "task.update.failed"),
TASK_IS_ONLINE(12009, "task.is.online"),
TASK_IS_EXIST(12010, "task.is.existed"),
/**
* alert instance
......
......@@ -103,6 +103,7 @@ failed=Failed
added.failed=Added Failed
task.not.exist=Task Not Exist
task.is.online= Task is online, modification is prohibited
task.is.existed=Task is existed
cluster.instance.deploy=Deploy Success
clear.failed=Clear Failed
rename.success=Rename Successfully
......
......@@ -103,6 +103,7 @@ failed=获取失败
added.failed=新增失败
task.not.exist=任务不存在
task.is.online=任务已上线,禁止修改
task.is.existed=作业已存在
cluster.instance.deploy=部署完成
clear.failed=清除失败
rename.success=重命名成功
......
......@@ -19,8 +19,9 @@
import { FormContextValue } from '@/components/Context/FormContext';
import { JOB_TYPE } from '@/pages/DataStudio/LeftContainer/Project/constants';
import { isUDF } from '@/pages/DataStudio/LeftContainer/Project/function';
import { isFlinkJob, isUDF } from '@/pages/DataStudio/LeftContainer/Project/function';
import { queryDataByParams } from '@/services/BusinessCrud';
import { RUN_MODE } from '@/services/constants';
import { API_CONSTANTS } from '@/services/endpoints';
import { Catalogue } from '@/types/Studio/data';
import { l } from '@/utils/intl';
......@@ -109,7 +110,21 @@ const JobModal: React.FC<JobModalProps> = (props) => {
const { selectKeys } = formData.configJson.udfConfig;
formData.configJson.udfConfig.templateId = selectKeys[selectKeys.length - 1];
}
onSubmit({ ...values, ...formData } as Catalogue);
// if this type is flink job, init task value and submit
if (isFlinkJob(formData.type ?? '')) {
const initTaskValue = {
savePointStrategy: -1, // -1 is disabled
parallelism: 1, // default parallelism
envId: -1, // -1 is disabled
step: 1, // default step is develop
alertGroupId: -1, // -1 is disabled
type: RUN_MODE.LOCAL, // default run mode is local
dialect: formData.type
};
onSubmit({ ...values, ...formData, task: initTaskValue } as Catalogue);
} else {
onSubmit({ ...values, ...formData } as Catalogue);
}
};
/**
......
......@@ -66,7 +66,6 @@ export type Task = {
clusterId: number;
clusterConfigurationId: number;
databaseId: number;
jarId: number;
envId: number;
alertGroupId: number;
note: string;
......@@ -78,7 +77,6 @@ export type Task = {
savePoints: SavePoint[];
configJson: TaskExtConfig;
path: string;
jarName: string;
clusterConfigurationName: string;
databaseName: string;
envName: string;
......
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