Hourly dependency configuration, 'currentHour' and 'last24Hours' (#2696)
* [feature] Add hourly dependency scenarios * [Feature] #2680 add DependentUtilsTest UT Co-authored-by: changqun.xu <changqun.xu@17zuoye.com> Co-authored-by: xuchangqun <changqun.x@gmail.com>
This commit is contained in:
parent
184d64e852
commit
cfd83235a2
File diff suppressed because one or more lines are too long
|
|
@ -71,6 +71,9 @@ public class DependentUtils {
|
|||
public static List<DateInterval> getDateIntervalList(Date businessDate, String dateValue){
|
||||
List<DateInterval> result = new ArrayList<>();
|
||||
switch (dateValue){
|
||||
case "currentHour":
|
||||
result = DependentDateUtils.getLastHoursInterval(businessDate, 0);
|
||||
break;
|
||||
case "last1Hour":
|
||||
result = DependentDateUtils.getLastHoursInterval(businessDate, 1);
|
||||
break;
|
||||
|
|
@ -80,6 +83,9 @@ public class DependentUtils {
|
|||
case "last3Hours":
|
||||
result = DependentDateUtils.getLastHoursInterval(businessDate, 3);
|
||||
break;
|
||||
case "last24Hours":
|
||||
result = DependentDateUtils.getSpecialLastDayInterval(businessDate);
|
||||
break;
|
||||
case "today":
|
||||
result = DependentDateUtils.getTodayInterval(businessDate);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -33,6 +33,13 @@ public class DependentDateUtils {
|
|||
*/
|
||||
public static List<DateInterval> getLastHoursInterval(Date businessDate, int hourNumber){
|
||||
List<DateInterval> dateIntervals = new ArrayList<>();
|
||||
if (hourNumber == 0) {
|
||||
Date lastHour = DateUtils.getSomeHourOfDay(businessDate, 0);
|
||||
Date beginTime = DateUtils.getStartOfHour(lastHour);
|
||||
Date endTime = DateUtils.getEndOfHour(lastHour);
|
||||
dateIntervals.add(new DateInterval(beginTime, endTime));
|
||||
return dateIntervals;
|
||||
}
|
||||
for(int index = hourNumber; index > 0; index--){
|
||||
Date lastHour = DateUtils.getSomeHourOfDay(businessDate, -index);
|
||||
Date beginTime = DateUtils.getStartOfHour(lastHour);
|
||||
|
|
@ -76,6 +83,26 @@ public class DependentDateUtils {
|
|||
return dateIntervals;
|
||||
}
|
||||
|
||||
/**
|
||||
* get special last day interval list (yesterday 1:00 - today 1:00)
|
||||
* @param businessDate businessDate
|
||||
* @return DateInterval list
|
||||
*/
|
||||
public static List<DateInterval> getSpecialLastDayInterval(Date businessDate){
|
||||
|
||||
List<DateInterval> dateIntervals = new ArrayList<>();
|
||||
int hourIndex = DateUtils.getHourIndex(businessDate);
|
||||
int startIndex = hourIndex + 23;
|
||||
int endIndex = startIndex - 24;
|
||||
for(int index = startIndex; index > endIndex; index--) {
|
||||
Date lastHour = DateUtils.getSomeHourOfDay(businessDate, -index);
|
||||
Date beginTime = DateUtils.getStartOfHour(lastHour);
|
||||
Date endTime = DateUtils.getEndOfHour(lastHour);
|
||||
dateIntervals.add(new DateInterval(beginTime, endTime));
|
||||
}
|
||||
return dateIntervals;
|
||||
}
|
||||
|
||||
/**
|
||||
* get interval between this month first day and businessDate
|
||||
* @param businessDate businessDate
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.dolphinscheduler.common.utils;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.dolphinscheduler.common.enums.DependResult;
|
||||
import org.apache.dolphinscheduler.common.enums.DependentRelation;
|
||||
import org.apache.dolphinscheduler.common.model.DateInterval;
|
||||
|
|
@ -343,6 +344,45 @@ public class DependentUtilsTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCurretHour() {
|
||||
String dateValue = "currentHour";
|
||||
|
||||
Date curDay = DateUtils.stringToDate("2020-05-15 12:10:00");
|
||||
|
||||
List<DateInterval> dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue);
|
||||
|
||||
DateInterval expect = new DateInterval(DateUtils.getStartOfHour(DateUtils.stringToDate("2020-05-15 12:00:00")), DateUtils.getEndOfHour(DateUtils.stringToDate("2020-05-15 12:59:59")));
|
||||
|
||||
Assert.assertEquals(expect, dateIntervals.get(0));
|
||||
Assert.assertEquals(1, dateIntervals.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLast24Hour() {
|
||||
Date curDay = DateUtils.stringToDate("2020-05-15 12:10:00");
|
||||
String dateValue = "last24Hours";
|
||||
|
||||
List<DateInterval> dateIntervals = DependentUtils.getDateIntervalList(curDay, dateValue);
|
||||
|
||||
List<DateInterval> expect = Lists.newArrayList();
|
||||
for (int a = 1; a < 24; a++) {
|
||||
String i = a + "";
|
||||
if (a < 10) {
|
||||
i = "0" + i;
|
||||
}
|
||||
DateInterval dateInterval = new DateInterval(DateUtils.getStartOfHour(DateUtils.stringToDate("2020-05-14 " + i + ":00:00")), DateUtils.getEndOfHour(DateUtils.stringToDate("2020-05-14 " + i + ":59:59")));
|
||||
expect.add(dateInterval);
|
||||
}
|
||||
DateInterval dateInterval = new DateInterval(DateUtils.getStartOfHour(DateUtils.stringToDate("2020-05-15 00:00:00")), DateUtils.getEndOfHour(DateUtils.stringToDate("2020-05-15 00:59:59")));
|
||||
expect.add(dateInterval);
|
||||
|
||||
Assert.assertEquals(24, dateIntervals.size());
|
||||
|
||||
for (int i = 0; i< expect.size(); i++) {
|
||||
Assert.assertEquals(expect.get(i), dateIntervals.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMonth(){
|
||||
|
|
|
|||
|
|
@ -44,6 +44,10 @@ const cycleList = [
|
|||
*/
|
||||
const dateValueList = {
|
||||
hour: [
|
||||
{
|
||||
value: 'currentHour',
|
||||
label: `${i18n.$t('CurrentHour')}`
|
||||
},
|
||||
{
|
||||
value: 'last1Hour',
|
||||
label: `${i18n.$t('Last1Hour')}`
|
||||
|
|
@ -55,6 +59,10 @@ const dateValueList = {
|
|||
{
|
||||
value: 'last3Hours',
|
||||
label: `${i18n.$t('Last3Hours')}`
|
||||
},
|
||||
{
|
||||
value: 'last24Hours',
|
||||
label: `${i18n.$t('Last24Hours')}`
|
||||
}
|
||||
],
|
||||
day: [
|
||||
|
|
|
|||
|
|
@ -426,9 +426,11 @@ export default {
|
|||
Running: 'Running',
|
||||
'Waiting for dependency to complete': 'Waiting for dependency to complete',
|
||||
Selected: 'Selected',
|
||||
CurrentHour: 'CurrentHour',
|
||||
Last1Hour: 'Last1Hour',
|
||||
Last2Hours: 'Last2Hours',
|
||||
Last3Hours: 'Last3Hours',
|
||||
Last24Hours: 'Last24Hours',
|
||||
today: 'today',
|
||||
Last1Days: 'Last1Days',
|
||||
Last2Days: 'Last2Days',
|
||||
|
|
|
|||
|
|
@ -421,9 +421,11 @@ export default {
|
|||
Running: '正在运行',
|
||||
'Waiting for dependency to complete': '等待依赖完成',
|
||||
Selected: '已选',
|
||||
CurrentHour: '当前小时',
|
||||
Last1Hour: '前1小时',
|
||||
Last2Hours: '前2小时',
|
||||
Last3Hours: '前3小时',
|
||||
Last24Hours: '前24小时',
|
||||
today: '今天',
|
||||
Last1Days: '昨天',
|
||||
Last2Days: '前两天',
|
||||
|
|
|
|||
Loading…
Reference in New Issue