-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #650 from peishengsheng/feat_1.2
[feat_1.2][taier-service] fix work flow show
- Loading branch information
Showing
5 changed files
with
391 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...ta-develop/src/main/java/com/dtstack/taier/develop/enums/develop/ESchedulePeriodType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.dtstack.taier.develop.enums.develop; | ||
|
||
|
||
import com.dtstack.taier.common.exception.RdosDefineException; | ||
|
||
/** | ||
* Reason: | ||
* Date: 2017/5/4 | ||
* Company: www.dtstack.com | ||
* @author xuchao | ||
*/ | ||
|
||
public enum ESchedulePeriodType { | ||
|
||
/** | ||
* 分钟 | ||
*/ | ||
MIN(0), | ||
|
||
/** | ||
* 小时 | ||
*/ | ||
HOUR(1), | ||
|
||
/** | ||
* 天 | ||
*/ | ||
DAY(2), | ||
|
||
/** | ||
* 周 | ||
*/ | ||
WEEK(3), | ||
|
||
/** | ||
* 月 | ||
*/ | ||
MONTH(4); | ||
|
||
private int val; | ||
|
||
ESchedulePeriodType(int val){ | ||
this.val = val; | ||
} | ||
|
||
public int getVal(){ | ||
return this.val; | ||
} | ||
|
||
|
||
public static ESchedulePeriodType getEnumByVal(Integer val) { | ||
for (ESchedulePeriodType periodType : ESchedulePeriodType.values()) { | ||
if (periodType.getVal() == val) { | ||
return periodType; | ||
} | ||
} | ||
throw new RdosDefineException(String.format("val:%s 没有匹配到对应的周期调度类型", val)); | ||
} | ||
|
||
} |
232 changes: 232 additions & 0 deletions
232
...velop/src/main/java/com/dtstack/taier/develop/enums/develop/WorkFlowScheduleConfEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
package com.dtstack.taier.develop.enums.develop; | ||
|
||
import com.alibaba.fastjson.JSONObject; | ||
import com.dtstack.taier.common.exception.ErrorCode; | ||
import com.dtstack.taier.common.exception.RdosDefineException; | ||
import com.dtstack.taier.dao.domain.Task; | ||
import org.apache.commons.lang.ArrayUtils; | ||
import org.apache.commons.lang.StringUtils; | ||
|
||
/** | ||
* 工作流调度属性工具类 | ||
* | ||
* @author 昆卡 | ||
* @version 4.3.x-SNAPSHOT | ||
* @since 2021/10/25 | ||
*/ | ||
|
||
public enum WorkFlowScheduleConfEnum { | ||
/** | ||
* 分钟 | ||
*/ | ||
MIN(String.valueOf(ESchedulePeriodType.MIN.getVal())) { | ||
@Override | ||
public void checkWorkFlowChildScheduleConf(JSONObject oldJsonObject, JSONObject newJsonObject) { | ||
validate(oldJsonObject, newJsonObject, BEGIN_DATE_KEY_NAME, END_DATE_KEY_NAME, BEGIN_HOUR_KEY_NAME, | ||
BEGIN_MIN_KEY_NAME, GAP_MIN_KEY_NAME, END_HOUR_KEY_NAME, END_MIN_KEY_NAME); | ||
} | ||
|
||
@Override | ||
public void handleWorkFlowChildScheduleConf(Task childNodeTask, JSONObject parentJsonObject) { | ||
applyParentScheduleConf(childNodeTask, parentJsonObject, BEGIN_DATE_KEY_NAME, END_DATE_KEY_NAME, | ||
BEGIN_HOUR_KEY_NAME, BEGIN_MIN_KEY_NAME, GAP_MIN_KEY_NAME, END_HOUR_KEY_NAME, END_MIN_KEY_NAME, | ||
PERIOD_TYPE); | ||
} | ||
}, | ||
|
||
/** | ||
* 小时 | ||
*/ | ||
HOUR(String.valueOf(ESchedulePeriodType.HOUR.getVal())) { | ||
@Override | ||
public void checkWorkFlowChildScheduleConf(JSONObject oldJsonObject, JSONObject newJsonObject) { | ||
validate(oldJsonObject, newJsonObject, BEGIN_DATE_KEY_NAME, END_DATE_KEY_NAME, BEGIN_HOUR_KEY_NAME, | ||
BEGIN_MIN_KEY_NAME, GAP_HOUR_KEY_NAME, END_HOUR_KEY_NAME, END_MIN_KEY_NAME); | ||
} | ||
|
||
@Override | ||
public void handleWorkFlowChildScheduleConf(Task childNodeTask, JSONObject parentJsonObject) { | ||
applyParentScheduleConf(childNodeTask, parentJsonObject, BEGIN_HOUR_KEY_NAME, BEGIN_MIN_KEY_NAME, | ||
BEGIN_DATE_KEY_NAME, END_DATE_KEY_NAME, GAP_HOUR_KEY_NAME, END_HOUR_KEY_NAME, END_MIN_KEY_NAME, | ||
PERIOD_TYPE); | ||
} | ||
}, | ||
|
||
/** | ||
* 天 | ||
*/ | ||
DAY(String.valueOf(ESchedulePeriodType.DAY.getVal())) { | ||
@Override | ||
public void checkWorkFlowChildScheduleConf(JSONObject oldJsonObject, JSONObject newJsonObject) { | ||
validate(oldJsonObject, newJsonObject, BEGIN_DATE_KEY_NAME, END_DATE_KEY_NAME, HOUR_KEY_NAME, MIN_KEY_NAME); | ||
} | ||
|
||
@Override | ||
public void handleWorkFlowChildScheduleConf(Task childNodeTask, JSONObject parentJsonObject) { | ||
applyParentScheduleConf(childNodeTask, parentJsonObject, BEGIN_DATE_KEY_NAME, END_DATE_KEY_NAME, HOUR_KEY_NAME, | ||
MIN_KEY_NAME, PERIOD_TYPE); | ||
} | ||
}, | ||
|
||
/** | ||
* 周 | ||
*/ | ||
WEEK(String.valueOf(ESchedulePeriodType.WEEK.getVal())) { | ||
@Override | ||
public void checkWorkFlowChildScheduleConf(JSONObject oldJsonObject, JSONObject newJsonObject) { | ||
validate(oldJsonObject, newJsonObject, BEGIN_DATE_KEY_NAME, END_DATE_KEY_NAME, WEEKDAY_KEY_NAME, HOUR_KEY_NAME, | ||
MIN_KEY_NAME); | ||
} | ||
|
||
@Override | ||
public void handleWorkFlowChildScheduleConf(Task childNodeTask, JSONObject parentJsonObject) { | ||
applyParentScheduleConf(childNodeTask, parentJsonObject, BEGIN_DATE_KEY_NAME, END_DATE_KEY_NAME, WEEKDAY_KEY_NAME, | ||
HOUR_KEY_NAME, MIN_KEY_NAME, PERIOD_TYPE); | ||
} | ||
}, | ||
|
||
/** | ||
* 月 | ||
*/ | ||
MONTH(String.valueOf(ESchedulePeriodType.MONTH.getVal())) { | ||
@Override | ||
public void checkWorkFlowChildScheduleConf(JSONObject oldJsonObject, JSONObject newJsonObject) { | ||
validate(oldJsonObject, newJsonObject, BEGIN_DATE_KEY_NAME, END_DATE_KEY_NAME, DAY_KEY_NAME, HOUR_KEY_NAME, | ||
MIN_KEY_NAME); | ||
} | ||
|
||
@Override | ||
public void handleWorkFlowChildScheduleConf(Task childNodeTask, JSONObject parentJsonObject) { | ||
applyParentScheduleConf(childNodeTask, parentJsonObject, BEGIN_DATE_KEY_NAME, END_DATE_KEY_NAME, DAY_KEY_NAME, | ||
HOUR_KEY_NAME, MIN_KEY_NAME, PERIOD_TYPE); | ||
} | ||
} | ||
; | ||
/** | ||
* 开始小时键名 | ||
*/ | ||
private static final String BEGIN_HOUR_KEY_NAME = "beginHour"; | ||
/** | ||
* 开始分钟键名 | ||
*/ | ||
private static final String BEGIN_MIN_KEY_NAME = "beginMin"; | ||
/** | ||
* 间隔分钟键名 | ||
*/ | ||
private static final String GAP_MIN_KEY_NAME = "gapMin"; | ||
/** | ||
* 结束小时键名 | ||
*/ | ||
private static final String END_HOUR_KEY_NAME = "endHour"; | ||
/** | ||
* 结束分钟键名 | ||
*/ | ||
private static final String END_MIN_KEY_NAME = "endMin"; | ||
/** | ||
* 间隔小时键名 | ||
*/ | ||
private static final String GAP_HOUR_KEY_NAME = "gapHour"; | ||
/** | ||
* 小时键名 | ||
*/ | ||
private static final String HOUR_KEY_NAME = "hour"; | ||
/** | ||
* 分钟键名 | ||
*/ | ||
private static final String MIN_KEY_NAME = "min"; | ||
/** | ||
* 星期键名 | ||
*/ | ||
private static final String WEEKDAY_KEY_NAME = "weekDay"; | ||
/** | ||
* 天键名 | ||
*/ | ||
private static final String DAY_KEY_NAME = "day"; | ||
/** | ||
* CRON表达式键名 | ||
*/ | ||
private static final String CRON_KEY_NAME = "cron"; | ||
/** | ||
* 开始日期键名 | ||
*/ | ||
private static final String BEGIN_DATE_KEY_NAME = "beginDate"; | ||
/** | ||
* 结束日期键名 | ||
*/ | ||
private static final String END_DATE_KEY_NAME = "endDate"; | ||
/** | ||
* 调度周期键名 | ||
*/ | ||
private static final String PERIOD_TYPE = "periodType"; | ||
|
||
/** | ||
* 调度周期 | ||
*/ | ||
private final String periodType; | ||
|
||
/** | ||
* 处理工作流子节点调度配置 | ||
* | ||
* @param oldJsonObject 老周期配置json对象 | ||
* @param newJsonObject 新周期配置json对象 | ||
*/ | ||
public abstract void checkWorkFlowChildScheduleConf(JSONObject oldJsonObject, JSONObject newJsonObject); | ||
|
||
/** | ||
* 处理工作流子节点调度配置,父的属性部分给到子 | ||
* | ||
* @param childNodeTask 子节点任务 | ||
* @param parentJsonObject 工作流周期配置json对象 | ||
*/ | ||
public abstract void handleWorkFlowChildScheduleConf(Task childNodeTask, JSONObject parentJsonObject); | ||
|
||
/** | ||
* 获取工作流调度周期枚举对象 | ||
* | ||
* @param periodType 调度周期 | ||
*/ | ||
public static String getCurrentPeriodType(String periodType) { | ||
if (StringUtils.isEmpty(periodType)) { | ||
throw new RdosDefineException(ErrorCode.INVALID_PARAMETERS); | ||
} | ||
for (WorkFlowScheduleConfEnum workFlowScheduleConfEnum : WorkFlowScheduleConfEnum.values()) { | ||
if (!workFlowScheduleConfEnum.getPeriodType().equals(periodType)) { | ||
continue; | ||
} | ||
return workFlowScheduleConfEnum.name(); | ||
} | ||
throw new RdosDefineException("未知的调度周期"); | ||
} | ||
|
||
private static void validate(JSONObject oldJsonObject, JSONObject newJsonObject, String... keyNameArray) { | ||
if (ArrayUtils.isEmpty(keyNameArray)) { | ||
return; | ||
} | ||
for (String keyName : keyNameArray) { | ||
if (!String.valueOf(oldJsonObject.getOrDefault(keyName, StringUtils.EMPTY)).equals(newJsonObject.getString(keyName))) { | ||
throw new RdosDefineException(ErrorCode.UNSUPPORTED_OPERATION); | ||
} | ||
} | ||
} | ||
|
||
private static void applyParentScheduleConf(Task childNodeTask, JSONObject parentJsonObject, String... keyNameArray) { | ||
if (ArrayUtils.isEmpty(keyNameArray)) { | ||
return; | ||
} | ||
final JSONObject childJsonObject = JSONObject.parseObject(childNodeTask.getScheduleConf()); | ||
for (String keyName : keyNameArray) { | ||
if (parentJsonObject.containsKey(keyName)) { | ||
childJsonObject.put(keyName, parentJsonObject.get(keyName)); | ||
} | ||
} | ||
childNodeTask.setScheduleConf(childJsonObject.toJSONString()); | ||
} | ||
|
||
public String getPeriodType() { | ||
return periodType; | ||
} | ||
|
||
WorkFlowScheduleConfEnum(String periodType) { | ||
this.periodType = periodType; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.