Merge branch 'v3.4.0' into jenkins_auto_build

This commit is contained in:
tjq 2020-11-28 22:48:52 +08:00
commit 39610ba18e
14 changed files with 779 additions and 552 deletions

View File

@ -5,13 +5,13 @@
Source Server Type : MySQL
Source Server Version : 80021
Source Host : localhost:3306
Source Schema : powerjob-daily
Source Schema : powerjob-db-template
Target Server Type : MySQL
Target Server Version : 80021
File Encoding : 65001
Date: 08/10/2020 12:39:10
Date: 28/11/2020 17:05:50
*/
SET NAMES utf8mb4;
@ -30,7 +30,7 @@ CREATE TABLE `app_info` (
`password` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `appNameUK` (`app_name`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- ----------------------------
-- Table structure for container_info
@ -77,7 +77,7 @@ CREATE TABLE `instance_info` (
KEY `IDX5b1nhpe5je7gc5s1ur200njr7` (`job_id`),
KEY `IDXjnji5lrr195kswk6f7mfhinrs` (`app_id`),
KEY `IDXa98hq3yu0l863wuotdjl7noum` (`instance_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- ----------------------------
-- Table structure for job_info
@ -111,7 +111,7 @@ CREATE TABLE `job_info` (
`time_expression_type` int DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `IDXk2xprmn3lldmlcb52i36udll1` (`app_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- ----------------------------
-- Table structure for oms_lock
@ -126,7 +126,7 @@ CREATE TABLE `oms_lock` (
`ownerip` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `lockNameUK` (`lock_name`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- ----------------------------
-- Table structure for server_info
@ -148,12 +148,12 @@ DROP TABLE IF EXISTS `user_info`;
CREATE TABLE `user_info` (
`id` bigint NOT NULL AUTO_INCREMENT,
`email` varchar(255) DEFAULT NULL,
`extra` varchar(255) DEFAULT NULL,
`gmt_create` datetime(6) DEFAULT NULL,
`gmt_modified` datetime(6) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`phone` varchar(255) DEFAULT NULL,
`username` varchar(255) DEFAULT NULL,
`extra` varchar(255) DEFAULT NULL,
`web_hook` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
@ -178,7 +178,7 @@ CREATE TABLE `workflow_info` (
`wf_name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `IDX7uo5w0e3beeho3fnx9t7eiol3` (`app_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- ----------------------------
-- Table structure for workflow_instance_info
@ -189,6 +189,7 @@ CREATE TABLE `workflow_instance_info` (
`actual_trigger_time` bigint DEFAULT NULL,
`app_id` bigint DEFAULT NULL,
`dag` longtext,
`expected_trigger_time` bigint DEFAULT NULL,
`finished_time` bigint DEFAULT NULL,
`gmt_create` datetime(6) DEFAULT NULL,
`gmt_modified` datetime(6) DEFAULT NULL,
@ -198,6 +199,6 @@ CREATE TABLE `workflow_instance_info` (
`wf_instance_id` bigint DEFAULT NULL,
`workflow_id` bigint DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
SET FOREIGN_KEY_CHECKS = 1;

View File

@ -0,0 +1,71 @@
package com.github.kfcfans.powerjob.server.service;
import com.github.kfcfans.powerjob.common.OmsConstant;
import com.github.kfcfans.powerjob.common.TimeExpressionType;
import com.github.kfcfans.powerjob.server.common.utils.CronExpression;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.time.DateFormatUtils;
import java.text.ParseException;
import java.util.Collections;
import java.util.Date;
import java.util.List;
/**
* 校验服务
*
* @author tjq
* @since 2020/11/28
*/
public class ValidateService {
private static final int NEXT_N_TIMES = 5;
/**
* 计算指定时间表达式接下来的运行状况
* @param timeExpressionType 时间表达式类型
* @param timeExpression 时间表达式
* @return 最近 N 次运行的时间
* @throws Exception 异常
*/
public static List<String> calculateNextTriggerTime(TimeExpressionType timeExpressionType, String timeExpression) throws Exception {
switch (timeExpressionType) {
case API: return Lists.newArrayList(OmsConstant.NONE);
case WORKFLOW: return Lists.newArrayList("VALID: depends on workflow");
case CRON: return calculateCronExpression(timeExpression);
case FIX_RATE: return calculateFixRate(timeExpression);
case FIX_DELAY: return Lists.newArrayList("VALID: depends on execution cost time");
}
// impossible
return Collections.emptyList();
}
private static List<String> calculateFixRate(String timeExpression) {
List<String> result = Lists.newArrayList();
long delay = Long.parseLong(timeExpression);
for (int i = 0; i < NEXT_N_TIMES; i++) {
long nextTime = System.currentTimeMillis() + i * delay;
result.add(DateFormatUtils.format(nextTime, OmsConstant.TIME_PATTERN));
}
return result;
}
private static List<String> calculateCronExpression(String expression) throws ParseException {
CronExpression cronExpression = new CronExpression(expression);
List<String> result = Lists.newArrayList();
Date time = new Date();
for (int i = 0; i < NEXT_N_TIMES; i++) {
Date nextValidTime = cronExpression.getNextValidTimeAfter(time);
if (nextValidTime == null) {
break;
}
result.add(DateFormatUtils.format(nextValidTime.getTime(), OmsConstant.TIME_PATTERN));
time = nextValidTime;
}
if (result.isEmpty()) {
result.add("INVALID: no next validate schedule time");
}
return result;
}
}

View File

@ -3,6 +3,7 @@ package com.github.kfcfans.powerjob.server.web;
import com.github.kfcfans.powerjob.common.PowerJobException;
import com.github.kfcfans.powerjob.common.response.ResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.messaging.handler.annotation.support.MethodArgumentTypeMismatchException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
@ -34,6 +35,6 @@ public class ControllerExceptionHandler {
} else {
log.error("[ControllerException] http request failed.", e);
}
return ResultDTO.failed(e.getMessage());
return ResultDTO.failed(ExceptionUtils.getMessage(e));
}
}

View File

@ -0,0 +1,32 @@
package com.github.kfcfans.powerjob.server.web.controller;
import com.github.kfcfans.powerjob.common.TimeExpressionType;
import com.github.kfcfans.powerjob.common.response.ResultDTO;
import com.github.kfcfans.powerjob.server.service.ValidateService;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 校验控制器
*
* @author tjq
* @since 2020/11/28
*/
@RestController
@RequestMapping("/validate")
public class ValidateController {
@GetMapping("/timeExpression")
public ResultDTO<List<String>> checkTimeExpression(TimeExpressionType timeExpressionType, String timeExpression) {
try {
return ResultDTO.success(ValidateService.calculateNextTriggerTime(timeExpressionType, timeExpression));
} catch (Exception e) {
return ResultDTO.success(Lists.newArrayList(ExceptionUtils.getMessage(e)));
}
}
}

View File

@ -51,7 +51,9 @@ public class WorkflowInstanceInfoVO {
vo.setWorkflowId(String.valueOf(wfInstanceDO.getWorkflowId()));
// 格式化时间
if (wfInstanceDO.getExpectedTriggerTime() != null) {
vo.setExpectedTriggerTime(DateFormatUtils.format(wfInstanceDO.getExpectedTriggerTime(), OmsConstant.TIME_PATTERN));
}
vo.setActualTriggerTime(DateFormatUtils.format(wfInstanceDO.getActualTriggerTime(), OmsConstant.TIME_PATTERN));
if (wfInstanceDO.getFinishedTime() == null) {
vo.setFinishedTime(OmsConstant.NONE);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long