From 4e28b568ccb0237d0838817e553407ea90fef967 Mon Sep 17 00:00:00 2001 From: wangqi Date: Fri, 6 Sep 2024 20:47:53 +0800 Subject: [PATCH] feature: update schedule type --- .../carp/framework/common/dict/DictType.java | 9 +++ .../dict/schedule/ScheduleEngineType.java | 61 +++++++++++++++++ .../common/dict/schedule/ScheduleJobType.java | 60 +++++++++++++++++ .../common/dict/schedule/ScheduleType.java | 61 +++++++++++++++++ .../repository/entity/ScheduleJobConfig.java | 24 +++---- .../repository/entity/ScheduleJobGroup.java | 11 +-- .../entity/ScheduleJobInstance.java | 18 ++--- .../service/dto/ScheduleJobConfigDTO.java | 12 +++- .../service/dto/ScheduleJobInstanceDTO.java | 4 ++ .../impl/ScheduleJobConfigServiceImpl.java | 10 ++- .../param/ScheduleJobConfigAddParam.java | 11 ++- .../param/ScheduleJobConfigListParam.java | 11 ++- .../param/ScheduleJobConfigPageParam.java | 11 ++- .../param/ScheduleJobInstanceAddParam.java | 4 ++ .../param/ScheduleJobInstanceUpdateParam.java | 4 ++ .../mapper/ScheduleJobConfigMapper.xml | 4 +- .../mapper/ScheduleJobInstanceMapper.xml | 3 +- ...onService.java => WorkflowDagService.java} | 19 +++--- .../service/impl/WorkflowDagServiceImpl.java | 67 +++++++++++++++++++ .../param/WorkflowDefinitionListParam.java | 38 ----------- tools/docker/mysql/init.d/carp-scheduler.sql | 5 +- 21 files changed, 356 insertions(+), 91 deletions(-) create mode 100644 carp-framework/carp-framework-common/src/main/java/cn/sliew/carp/framework/common/dict/schedule/ScheduleEngineType.java create mode 100644 carp-framework/carp-framework-common/src/main/java/cn/sliew/carp/framework/common/dict/schedule/ScheduleJobType.java create mode 100644 carp-framework/carp-framework-common/src/main/java/cn/sliew/carp/framework/common/dict/schedule/ScheduleType.java rename carp-modules/carp-module-workflow/carp-module-workflow-api/src/main/java/cn/sliew/carp/module/workflow/api/service/{WorkflowDefinitionService.java => WorkflowDagService.java} (65%) create mode 100644 carp-modules/carp-module-workflow/carp-module-workflow-api/src/main/java/cn/sliew/carp/module/workflow/api/service/impl/WorkflowDagServiceImpl.java delete mode 100644 carp-modules/carp-module-workflow/carp-module-workflow-api/src/main/java/cn/sliew/carp/module/workflow/api/service/param/WorkflowDefinitionListParam.java diff --git a/carp-framework/carp-framework-common/src/main/java/cn/sliew/carp/framework/common/dict/DictType.java b/carp-framework/carp-framework-common/src/main/java/cn/sliew/carp/framework/common/dict/DictType.java index 85ca1513..7981d8b4 100644 --- a/carp-framework/carp-framework-common/src/main/java/cn/sliew/carp/framework/common/dict/DictType.java +++ b/carp-framework/carp-framework-common/src/main/java/cn/sliew/carp/framework/common/dict/DictType.java @@ -26,6 +26,10 @@ import cn.sliew.carp.framework.common.dict.k8s.ClusterStatus; import cn.sliew.carp.framework.common.dict.k8s.ClusterType; import cn.sliew.carp.framework.common.dict.oam.AppType; +import cn.sliew.carp.framework.common.dict.schedule.ScheduleEngineType; +import cn.sliew.carp.framework.common.dict.schedule.ScheduleJobType; +import cn.sliew.carp.framework.common.dict.schedule.ScheduleStatus; +import cn.sliew.carp.framework.common.dict.schedule.ScheduleType; import cn.sliew.carp.framework.common.dict.security.*; import com.baomidou.mybatisplus.annotation.EnumValue; import com.fasterxml.jackson.annotation.JsonCreator; @@ -59,6 +63,11 @@ public enum DictType implements DictDefinition { DATASOURCE_TYPE("datasource_type", "数据源类型", DataSourceType.class), DS_REDIS_MODE("datasource_redis_mode", "Redis Mode", RedisMode.class), + + SCHEDULE_TYPE("schedule_type", "Schedule Type", ScheduleType.class), + SCHEDULE_STATUS("schedule_status", "Schedule Status", ScheduleStatus.class), + SCHEDULE_JOB_TYPE("schedule_job_type", "Schedule Job Type", ScheduleJobType.class), + SCHEDULE_ENGINE_TYPE("schedule_engine_type", "Schedule Engine Type", ScheduleEngineType.class), ; @JsonCreator diff --git a/carp-framework/carp-framework-common/src/main/java/cn/sliew/carp/framework/common/dict/schedule/ScheduleEngineType.java b/carp-framework/carp-framework-common/src/main/java/cn/sliew/carp/framework/common/dict/schedule/ScheduleEngineType.java new file mode 100644 index 00000000..3dd1a9b5 --- /dev/null +++ b/carp-framework/carp-framework-common/src/main/java/cn/sliew/carp/framework/common/dict/schedule/ScheduleEngineType.java @@ -0,0 +1,61 @@ +/* + * 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 cn.sliew.carp.framework.common.dict.schedule; + +import cn.sliew.carp.framework.common.dict.DictInstance; +import com.baomidou.mybatisplus.annotation.EnumValue; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonFormat; + +import java.util.Arrays; + +@JsonFormat(shape = JsonFormat.Shape.OBJECT) +public enum ScheduleEngineType implements DictInstance { + + INTERNAL("internal", "内置"), + TEMPORAL("temporal", "Tempolra"), + DOLPHINSCHEDULER("dolphin-scheduler", "DolphinScheduler"), + ; + + @JsonCreator + public static ScheduleEngineType of(String value) { + return Arrays.stream(values()) + .filter(instance -> instance.getValue().equals(value)) + .findAny().orElseThrow(() -> new EnumConstantNotPresentException(ScheduleEngineType.class, value)); + } + + @EnumValue + private String value; + private String label; + + ScheduleEngineType(String value, String label) { + this.value = value; + this.label = label; + } + + @Override + public String getValue() { + return value; + } + + @Override + public String getLabel() { + return label; + } +} diff --git a/carp-framework/carp-framework-common/src/main/java/cn/sliew/carp/framework/common/dict/schedule/ScheduleJobType.java b/carp-framework/carp-framework-common/src/main/java/cn/sliew/carp/framework/common/dict/schedule/ScheduleJobType.java new file mode 100644 index 00000000..004d2ae4 --- /dev/null +++ b/carp-framework/carp-framework-common/src/main/java/cn/sliew/carp/framework/common/dict/schedule/ScheduleJobType.java @@ -0,0 +1,60 @@ +/* + * 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 cn.sliew.carp.framework.common.dict.schedule; + +import cn.sliew.carp.framework.common.dict.DictInstance; +import com.baomidou.mybatisplus.annotation.EnumValue; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonFormat; + +import java.util.Arrays; + +@JsonFormat(shape = JsonFormat.Shape.OBJECT) +public enum ScheduleJobType implements DictInstance { + + NORMAL("0", "普通"), + WORKFLOW("1", "WorkFlow"), + ; + + @JsonCreator + public static ScheduleJobType of(String value) { + return Arrays.stream(values()) + .filter(instance -> instance.getValue().equals(value)) + .findAny().orElseThrow(() -> new EnumConstantNotPresentException(ScheduleJobType.class, value)); + } + + @EnumValue + private String value; + private String label; + + ScheduleJobType(String value, String label) { + this.value = value; + this.label = label; + } + + @Override + public String getValue() { + return value; + } + + @Override + public String getLabel() { + return label; + } +} diff --git a/carp-framework/carp-framework-common/src/main/java/cn/sliew/carp/framework/common/dict/schedule/ScheduleType.java b/carp-framework/carp-framework-common/src/main/java/cn/sliew/carp/framework/common/dict/schedule/ScheduleType.java new file mode 100644 index 00000000..ed7c17d5 --- /dev/null +++ b/carp-framework/carp-framework-common/src/main/java/cn/sliew/carp/framework/common/dict/schedule/ScheduleType.java @@ -0,0 +1,61 @@ +/* + * 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 cn.sliew.carp.framework.common.dict.schedule; + +import cn.sliew.carp.framework.common.dict.DictInstance; +import cn.sliew.carp.framework.common.dict.common.YesOrNo; +import com.baomidou.mybatisplus.annotation.EnumValue; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonFormat; + +import java.util.Arrays; + +@JsonFormat(shape = JsonFormat.Shape.OBJECT) +public enum ScheduleType implements DictInstance { + + SYSTEM("0", "系统"), + USER("1", "用户"), + ; + + @JsonCreator + public static ScheduleType of(String value) { + return Arrays.stream(values()) + .filter(instance -> instance.getValue().equals(value)) + .findAny().orElseThrow(() -> new EnumConstantNotPresentException(ScheduleType.class, value)); + } + + @EnumValue + private String value; + private String label; + + ScheduleType(String value, String label) { + this.value = value; + this.label = label; + } + + @Override + public String getValue() { + return value; + } + + @Override + public String getLabel() { + return label; + } +} diff --git a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/repository/entity/ScheduleJobConfig.java b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/repository/entity/ScheduleJobConfig.java index 3414e0dd..c28ee41b 100644 --- a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/repository/entity/ScheduleJobConfig.java +++ b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/repository/entity/ScheduleJobConfig.java @@ -18,36 +18,36 @@ package cn.sliew.module.scheduler.repository.entity; +import cn.sliew.carp.framework.common.dict.schedule.ScheduleEngineType; +import cn.sliew.carp.framework.common.dict.schedule.ScheduleJobType; +import cn.sliew.carp.framework.common.dict.schedule.ScheduleType; import cn.sliew.carp.framework.mybatis.entity.BaseAuditDO; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Getter; -import lombok.Setter; +import lombok.Data; -@Getter -@Setter +@Data @TableName("schedule_job_config") -@Schema(name = "ScheduleJobConfig", description = "schedule job config") public class ScheduleJobConfig extends BaseAuditDO { - @Schema(description = "任务分组 id") @TableField("job_group_id") private Long jobGroupId; - @Schema(description = "任务类型") @TableField("`type`") - private String type; + private ScheduleType type; + + @TableField("`engine_type`") + private ScheduleEngineType engineType; + + @TableField("`job_type`") + private ScheduleJobType jobType; - @Schema(description = "任务名称") @TableField("`name`") private String name; - @Schema(description = "任务处理器") @TableField("`handler`") private String handler; - @Schema(description = "remark") @TableField("remark") private String remark; } diff --git a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/repository/entity/ScheduleJobGroup.java b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/repository/entity/ScheduleJobGroup.java index eca25e83..74287c8d 100644 --- a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/repository/entity/ScheduleJobGroup.java +++ b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/repository/entity/ScheduleJobGroup.java @@ -21,25 +21,18 @@ import cn.sliew.carp.framework.mybatis.entity.BaseAuditDO; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Getter; -import lombok.Setter; +import lombok.Data; -@Getter -@Setter +@Data @TableName("schedule_job_group") -@Schema(name = "ScheduleJobGroup", description = "schedule job group") public class ScheduleJobGroup extends BaseAuditDO { - @Schema(description = "命名空间") @TableField("namespace") private String namespace; - @Schema(description = "分组名称") @TableField("`name`") private String name; - @Schema(description = "remark") @TableField("remark") private String remark; } diff --git a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/repository/entity/ScheduleJobInstance.java b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/repository/entity/ScheduleJobInstance.java index 90e225d0..3366a992 100644 --- a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/repository/entity/ScheduleJobInstance.java +++ b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/repository/entity/ScheduleJobInstance.java @@ -21,41 +21,33 @@ import cn.sliew.carp.framework.mybatis.entity.BaseAuditDO; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Getter; -import lombok.Setter; +import lombok.Data; -@Getter -@Setter +@Data @TableName("schedule_job_instance") -@Schema(name = "ScheduleJobInstance", description = "schedule job instance") public class ScheduleJobInstance extends BaseAuditDO { - @Schema(description = "任务配置id") @TableField("job_config_id") private Long jobConfigId; - @Schema(description = "实例名称") @TableField("`name`") private String name; - @Schema(description = "CRON表达式") @TableField("cron") private String cron; - @Schema(description = "参数") + @TableField("props") + private String props; + @TableField("params") private String params; - @Schema(description = "超时时间(毫秒)") @TableField("timeout") private Long timeout; - @Schema(description = "状态") @TableField("`status`") private String status; - @Schema(description = "remark") @TableField("remark") private String remark; } diff --git a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/dto/ScheduleJobConfigDTO.java b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/dto/ScheduleJobConfigDTO.java index 53dc626e..042870a2 100644 --- a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/dto/ScheduleJobConfigDTO.java +++ b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/dto/ScheduleJobConfigDTO.java @@ -18,7 +18,11 @@ package cn.sliew.module.scheduler.service.dto; +import cn.sliew.carp.framework.common.dict.schedule.ScheduleEngineType; +import cn.sliew.carp.framework.common.dict.schedule.ScheduleJobType; +import cn.sliew.carp.framework.common.dict.schedule.ScheduleType; import cn.sliew.carp.framework.common.model.BaseDTO; +import com.baomidou.mybatisplus.annotation.TableField; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -29,8 +33,14 @@ public class ScheduleJobConfigDTO extends BaseDTO { @Schema(description = "任务分组 id") private Long jobGroupId; + @Schema(description = "类型") + private ScheduleType type; + + @Schema(description = "引擎类型") + private ScheduleEngineType engineType; + @Schema(description = "任务类型") - private String type; + private ScheduleJobType jobType; @Schema(description = "任务名称") private String name; diff --git a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/dto/ScheduleJobInstanceDTO.java b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/dto/ScheduleJobInstanceDTO.java index b0062938..1923749e 100644 --- a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/dto/ScheduleJobInstanceDTO.java +++ b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/dto/ScheduleJobInstanceDTO.java @@ -19,6 +19,7 @@ package cn.sliew.module.scheduler.service.dto; import cn.sliew.carp.framework.common.model.BaseDTO; +import com.fasterxml.jackson.databind.JsonNode; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -35,6 +36,9 @@ public class ScheduleJobInstanceDTO extends BaseDTO { @Schema(description = "CRON表达式") private String cron; + @Schema(description = "属性") + private JsonNode props; + @Schema(description = "参数") private String params; diff --git a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/impl/ScheduleJobConfigServiceImpl.java b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/impl/ScheduleJobConfigServiceImpl.java index b3ec1ba2..b85b34cc 100644 --- a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/impl/ScheduleJobConfigServiceImpl.java +++ b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/impl/ScheduleJobConfigServiceImpl.java @@ -18,6 +18,7 @@ package cn.sliew.module.scheduler.service.impl; +import cn.sliew.carp.framework.common.dict.schedule.ScheduleType; import cn.sliew.carp.framework.common.model.PageResult; import cn.sliew.carp.framework.mybatis.DataSourceConstants; import cn.sliew.module.scheduler.repository.entity.ScheduleJobConfig; @@ -49,7 +50,9 @@ public PageResult list(ScheduleJobConfigPageParam param) { Page page = new Page<>(param.getCurrent(), param.getPageSize()); LambdaQueryWrapper queryChainWrapper = Wrappers.lambdaQuery(ScheduleJobConfig.class) .eq(ScheduleJobConfig::getJobGroupId, param.getJobGroupId()) - .eq(StringUtils.hasText(param.getType()), ScheduleJobConfig::getType, param.getType()) + .eq(param.getType() != null, ScheduleJobConfig::getType, param.getType()) + .eq(param.getEngineType() != null, ScheduleJobConfig::getEngineType, param.getEngineType()) + .eq(param.getJobType() != null, ScheduleJobConfig::getJobType, param.getJobType()) .like(StringUtils.hasText(param.getName()), ScheduleJobConfig::getName, param.getName()) .like(StringUtils.hasText(param.getHandler()), ScheduleJobConfig::getHandler, param.getHandler()) .orderByAsc(ScheduleJobConfig::getId); @@ -63,7 +66,9 @@ public PageResult list(ScheduleJobConfigPageParam param) { public List listAll(ScheduleJobConfigListParam param) { LambdaQueryWrapper queryChainWrapper = Wrappers.lambdaQuery(ScheduleJobConfig.class) .eq(ScheduleJobConfig::getJobGroupId, param.getJobGroupId()) - .eq(StringUtils.hasText(param.getType()), ScheduleJobConfig::getType, param.getType()) + .eq(param.getType() != null, ScheduleJobConfig::getType, param.getType()) + .eq(param.getEngineType() != null, ScheduleJobConfig::getEngineType, param.getEngineType()) + .eq(param.getJobType() != null, ScheduleJobConfig::getJobType, param.getJobType()) .orderByAsc(ScheduleJobConfig::getId); List list = list(queryChainWrapper); return ScheduleJobConfigConvert.INSTANCE.toDto(list); @@ -79,6 +84,7 @@ public ScheduleJobConfigDTO get(Long id) { public boolean add(ScheduleJobConfigAddParam param) { ScheduleJobConfig entity = new ScheduleJobConfig(); BeanUtils.copyProperties(param, entity); + entity.setType(ScheduleType.USER); return save(entity); } diff --git a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/param/ScheduleJobConfigAddParam.java b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/param/ScheduleJobConfigAddParam.java index 59885fbd..906f1ce1 100644 --- a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/param/ScheduleJobConfigAddParam.java +++ b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/param/ScheduleJobConfigAddParam.java @@ -18,6 +18,9 @@ package cn.sliew.module.scheduler.service.param; +import cn.sliew.carp.framework.common.dict.schedule.ScheduleEngineType; +import cn.sliew.carp.framework.common.dict.schedule.ScheduleJobType; +import cn.sliew.carp.framework.common.dict.schedule.ScheduleType; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; @@ -30,9 +33,13 @@ public class ScheduleJobConfigAddParam { @Schema(description = "任务分组 id") private Long jobGroupId; - @NotBlank + @NotNull + @Schema(description = "引擎类型") + private ScheduleEngineType engineType; + + @NotNull @Schema(description = "任务类型") - private String type; + private ScheduleJobType jobType; @NotBlank @Schema(description = "任务名称") diff --git a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/param/ScheduleJobConfigListParam.java b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/param/ScheduleJobConfigListParam.java index 3ca5e647..db7d0ddd 100644 --- a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/param/ScheduleJobConfigListParam.java +++ b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/param/ScheduleJobConfigListParam.java @@ -18,6 +18,9 @@ package cn.sliew.module.scheduler.service.param; +import cn.sliew.carp.framework.common.dict.schedule.ScheduleEngineType; +import cn.sliew.carp.framework.common.dict.schedule.ScheduleJobType; +import cn.sliew.carp.framework.common.dict.schedule.ScheduleType; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; import lombok.Data; @@ -29,6 +32,12 @@ public class ScheduleJobConfigListParam { @Schema(description = "任务分组 id") private Long jobGroupId; + @Schema(description = "类型") + private ScheduleType type; + + @Schema(description = "引擎类型") + private ScheduleEngineType engineType; + @Schema(description = "任务类型") - private String type; + private ScheduleJobType jobType; } diff --git a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/param/ScheduleJobConfigPageParam.java b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/param/ScheduleJobConfigPageParam.java index 1c58845c..594e6d9e 100644 --- a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/param/ScheduleJobConfigPageParam.java +++ b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/param/ScheduleJobConfigPageParam.java @@ -18,6 +18,9 @@ package cn.sliew.module.scheduler.service.param; +import cn.sliew.carp.framework.common.dict.schedule.ScheduleEngineType; +import cn.sliew.carp.framework.common.dict.schedule.ScheduleJobType; +import cn.sliew.carp.framework.common.dict.schedule.ScheduleType; import cn.sliew.carp.framework.common.model.PageParam; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; @@ -30,8 +33,14 @@ public class ScheduleJobConfigPageParam extends PageParam { @Schema(description = "任务分组 id") private Long jobGroupId; + @Schema(description = "类型") + private ScheduleType type; + + @Schema(description = "引擎类型") + private ScheduleEngineType engineType; + @Schema(description = "任务类型") - private String type; + private ScheduleJobType jobType; @Schema(description = "任务名称") private String name; diff --git a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/param/ScheduleJobInstanceAddParam.java b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/param/ScheduleJobInstanceAddParam.java index cbb324f7..56a62fe3 100644 --- a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/param/ScheduleJobInstanceAddParam.java +++ b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/param/ScheduleJobInstanceAddParam.java @@ -18,6 +18,7 @@ package cn.sliew.module.scheduler.service.param; +import com.fasterxml.jackson.databind.JsonNode; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; @@ -38,6 +39,9 @@ public class ScheduleJobInstanceAddParam { @Schema(description = "CRON表达式") private String cron; + @Schema(description = "属性") + private JsonNode props; + @Schema(description = "参数") private String params; diff --git a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/param/ScheduleJobInstanceUpdateParam.java b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/param/ScheduleJobInstanceUpdateParam.java index 8120bb6e..462a80c3 100644 --- a/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/param/ScheduleJobInstanceUpdateParam.java +++ b/carp-modules/carp-module-scheduler/src/main/java/cn/sliew/module/scheduler/service/param/ScheduleJobInstanceUpdateParam.java @@ -18,6 +18,7 @@ package cn.sliew.module.scheduler.service.param; +import com.fasterxml.jackson.databind.JsonNode; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; @@ -38,6 +39,9 @@ public class ScheduleJobInstanceUpdateParam { @Schema(description = "CRON表达式") private String cron; + @Schema(description = "属性") + private JsonNode props; + @Schema(description = "参数") private String params; diff --git a/carp-modules/carp-module-scheduler/src/main/resources/cn/sliew/carp/module/scheduler/repository/mapper/ScheduleJobConfigMapper.xml b/carp-modules/carp-module-scheduler/src/main/resources/cn/sliew/carp/module/scheduler/repository/mapper/ScheduleJobConfigMapper.xml index a4472de4..5d5f0bca 100644 --- a/carp-modules/carp-module-scheduler/src/main/resources/cn/sliew/carp/module/scheduler/repository/mapper/ScheduleJobConfigMapper.xml +++ b/carp-modules/carp-module-scheduler/src/main/resources/cn/sliew/carp/module/scheduler/repository/mapper/ScheduleJobConfigMapper.xml @@ -28,6 +28,8 @@ + + @@ -40,7 +42,7 @@ create_time, editor, update_time, - job_group_id, `type`, `name`, `handler`, remark + job_group_id, `type`, `engine_type`, `job_type`, `name`, `handler`, remark diff --git a/carp-modules/carp-module-scheduler/src/main/resources/cn/sliew/carp/module/scheduler/repository/mapper/ScheduleJobInstanceMapper.xml b/carp-modules/carp-module-scheduler/src/main/resources/cn/sliew/carp/module/scheduler/repository/mapper/ScheduleJobInstanceMapper.xml index 8a6c671b..f42865d6 100644 --- a/carp-modules/carp-module-scheduler/src/main/resources/cn/sliew/carp/module/scheduler/repository/mapper/ScheduleJobInstanceMapper.xml +++ b/carp-modules/carp-module-scheduler/src/main/resources/cn/sliew/carp/module/scheduler/repository/mapper/ScheduleJobInstanceMapper.xml @@ -29,6 +29,7 @@ + @@ -42,7 +43,7 @@ create_time, editor, update_time, - job_config_id, `name`, cron, params, timeout, `status`, remark + job_config_id, `name`, cron, props, params, timeout, `status`, remark diff --git a/carp-modules/carp-module-workflow/carp-module-workflow-api/src/main/java/cn/sliew/carp/module/workflow/api/service/WorkflowDefinitionService.java b/carp-modules/carp-module-workflow/carp-module-workflow-api/src/main/java/cn/sliew/carp/module/workflow/api/service/WorkflowDagService.java similarity index 65% rename from carp-modules/carp-module-workflow/carp-module-workflow-api/src/main/java/cn/sliew/carp/module/workflow/api/service/WorkflowDefinitionService.java rename to carp-modules/carp-module-workflow/carp-module-workflow-api/src/main/java/cn/sliew/carp/module/workflow/api/service/WorkflowDagService.java index 60eccaa6..d66a8225 100644 --- a/carp-modules/carp-module-workflow/carp-module-workflow-api/src/main/java/cn/sliew/carp/module/workflow/api/service/WorkflowDefinitionService.java +++ b/carp-modules/carp-module-workflow/carp-module-workflow-api/src/main/java/cn/sliew/carp/module/workflow/api/service/WorkflowDagService.java @@ -18,19 +18,20 @@ package cn.sliew.carp.module.workflow.api.service; -import cn.sliew.carp.framework.dag.service.dto.DagConfigDTO; +import cn.sliew.carp.framework.dag.service.dto.DagConfigComplexDTO; import cn.sliew.carp.framework.dag.service.dto.DagConfigStepDTO; -import cn.sliew.carp.module.workflow.api.service.param.WorkflowDefinitionListParam; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.google.common.graph.Graph; +import cn.sliew.carp.framework.dag.x6.graph.DagGraphVO; -public interface WorkflowDefinitionService { +public interface WorkflowDagService { - Page list(WorkflowDefinitionListParam param); + Long initialize(String name, String remark); - DagConfigDTO get(Long id); + void destroy(Long dagId); - Graph getDag(Long id); + DagConfigComplexDTO getDag(Long dagId); + + DagConfigStepDTO getStep(Long stepId); + + void update(Long dagId, DagGraphVO graph); - DagConfigStepDTO getTaskDefinition(Long dagConfigStepId); } diff --git a/carp-modules/carp-module-workflow/carp-module-workflow-api/src/main/java/cn/sliew/carp/module/workflow/api/service/impl/WorkflowDagServiceImpl.java b/carp-modules/carp-module-workflow/carp-module-workflow-api/src/main/java/cn/sliew/carp/module/workflow/api/service/impl/WorkflowDagServiceImpl.java new file mode 100644 index 00000000..035a1a8b --- /dev/null +++ b/carp-modules/carp-module-workflow/carp-module-workflow-api/src/main/java/cn/sliew/carp/module/workflow/api/service/impl/WorkflowDagServiceImpl.java @@ -0,0 +1,67 @@ +/* + * 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 cn.sliew.carp.module.workflow.api.service.impl; + +import cn.sliew.carp.framework.dag.service.DagConfigComplexService; +import cn.sliew.carp.framework.dag.service.DagConfigStepService; +import cn.sliew.carp.framework.dag.service.dto.DagConfigComplexDTO; +import cn.sliew.carp.framework.dag.service.dto.DagConfigStepDTO; +import cn.sliew.carp.framework.dag.service.param.DagConfigSimpleAddParam; +import cn.sliew.carp.framework.dag.x6.graph.DagGraphVO; +import cn.sliew.carp.module.workflow.api.service.WorkflowDagService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class WorkflowDagServiceImpl implements WorkflowDagService { + + @Autowired + private DagConfigComplexService dagConfigComplexService; + @Autowired + private DagConfigStepService dagConfigStepService; + + @Override + public Long initialize(String name, String remark) { + DagConfigSimpleAddParam param = new DagConfigSimpleAddParam(); + param.setType("WorkFlow"); + param.setName(name); + param.setRemark(remark); + return dagConfigComplexService.insert(param); + } + + @Override + public void destroy(Long dagId) { + dagConfigComplexService.delete(dagId); + } + + @Override + public DagConfigComplexDTO getDag(Long dagId) { + return dagConfigComplexService.selectOne(dagId); + } + + @Override + public DagConfigStepDTO getStep(Long stepId) { + return dagConfigStepService.get(stepId); + } + + @Override + public void update(Long dagId, DagGraphVO graph) { + dagConfigComplexService.replace(dagId, graph); + } +} diff --git a/carp-modules/carp-module-workflow/carp-module-workflow-api/src/main/java/cn/sliew/carp/module/workflow/api/service/param/WorkflowDefinitionListParam.java b/carp-modules/carp-module-workflow/carp-module-workflow-api/src/main/java/cn/sliew/carp/module/workflow/api/service/param/WorkflowDefinitionListParam.java deleted file mode 100644 index 1a603d1a..00000000 --- a/carp-modules/carp-module-workflow/carp-module-workflow-api/src/main/java/cn/sliew/carp/module/workflow/api/service/param/WorkflowDefinitionListParam.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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 cn.sliew.carp.module.workflow.api.service.param; - -import cn.sliew.carp.framework.common.dict.workflow.WorkflowType; -import cn.sliew.carp.framework.common.model.PageParam; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotNull; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Data -@EqualsAndHashCode(callSuper = true) -public class WorkflowDefinitionListParam extends PageParam { - - @NotNull - @Schema(description = "workflow type") - private WorkflowType type; - - @Schema(description = "workflow name") - private String name; -} diff --git a/tools/docker/mysql/init.d/carp-scheduler.sql b/tools/docker/mysql/init.d/carp-scheduler.sql index be2c20c6..673cabbe 100644 --- a/tools/docker/mysql/init.d/carp-scheduler.sql +++ b/tools/docker/mysql/init.d/carp-scheduler.sql @@ -21,7 +21,9 @@ CREATE TABLE `schedule_job_config` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID', `job_group_id` bigint(20) NOT NULL COMMENT '任务分组 id', - `type` varchar(8) NOT NULL COMMENT '任务类型', + `type` varchar(8) NOT NULL COMMENT '类型。系统、用户', + `engine_type` varchar(8) NOT NULL COMMENT '引擎类型。内置、temporal、DolphinScheduler', + `job_type` varchar(8) NOT NULL COMMENT '任务类型。normal、workflow', `name` varchar(64) NOT NULL COMMENT '任务名称', `handler` varchar(64) COMMENT '任务处理器', `remark` varchar(255) COMMENT 'remark', @@ -40,6 +42,7 @@ CREATE TABLE `schedule_job_instance` `job_config_id` bigint(20) NOT NULL COMMENT '任务配置id', `name` varchar(255) NOT NULL COMMENT '实例名称', `cron` varchar(128) COMMENT 'CRON表达式', + `props` varchar(255) COMMENT '属性', `params` varchar(255) COMMENT '参数', `timeout` bigint(20) COMMENT '超时时间(毫秒)', `status` varchar(4) NOT NULL COMMENT '状态',