From 1cd5070b5dcfdc202a3db08c426dc35053626cab Mon Sep 17 00:00:00 2001 From: Rick Cheng Date: Tue, 13 Jun 2023 08:30:34 +0800 Subject: [PATCH] [Improvement-14329][common] Remove the duplicate BusinessTimeUtils (#14330) --- .../task/api/parser/BusinessTimeUtils.java | 78 ------------------- .../api/parser/TimePlaceholderUtilsTest.java | 5 +- .../plugin/task/dq/rule/RuleManager.java | 7 +- 3 files changed, 7 insertions(+), 83 deletions(-) delete mode 100644 dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parser/BusinessTimeUtils.java diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parser/BusinessTimeUtils.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parser/BusinessTimeUtils.java deleted file mode 100644 index 585e102343..0000000000 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parser/BusinessTimeUtils.java +++ /dev/null @@ -1,78 +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 org.apache.dolphinscheduler.plugin.task.api.parser; - -import static org.apache.dolphinscheduler.common.utils.DateUtils.addDays; -import static org.apache.dolphinscheduler.common.utils.DateUtils.format; -import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.PARAMETER_BUSINESS_DATE; -import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.PARAMETER_CURRENT_DATE; -import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.PARAMETER_DATETIME; -import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.PARAMETER_FORMAT_DATE; -import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.PARAMETER_FORMAT_TIME; - -import org.apache.dolphinscheduler.spi.enums.CommandType; - -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -/** - * business time utils - */ -public class BusinessTimeUtils { - - private BusinessTimeUtils() { - throw new IllegalStateException("BusinessTimeUtils class"); - } - - /** - * get business time in parameters by different command types - * - * @param commandType command type - * @param runTime run time or schedule time - * @return business time - */ - public static Map getBusinessTime(CommandType commandType, Date runTime) { - Date businessDate = runTime; - switch (commandType) { - case COMPLEMENT_DATA: - case START_PROCESS: - case START_CURRENT_TASK_PROCESS: - case RECOVER_TOLERANCE_FAULT_PROCESS: - case RECOVER_SUSPENDED_PROCESS: - case START_FAILURE_TASK_PROCESS: - case REPEAT_RUNNING: - case SCHEDULER: - default: - businessDate = addDays(new Date(), -1); - if (runTime != null) { - /** - * If there is a scheduled time, take the scheduling time. Recovery from failed nodes, suspension of recovery, re-run for scheduling - */ - businessDate = addDays(runTime, -1); - } - break; - } - Date businessCurrentDate = addDays(businessDate, 1); - Map result = new HashMap<>(); - result.put(PARAMETER_CURRENT_DATE, format(businessCurrentDate, PARAMETER_FORMAT_DATE)); - result.put(PARAMETER_BUSINESS_DATE, format(businessDate, PARAMETER_FORMAT_DATE)); - result.put(PARAMETER_DATETIME, format(businessCurrentDate, PARAMETER_FORMAT_TIME)); - return result; - } -} diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parser/TimePlaceholderUtilsTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parser/TimePlaceholderUtilsTest.java index 65024f65c2..dc8e16b9e3 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parser/TimePlaceholderUtilsTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parser/TimePlaceholderUtilsTest.java @@ -17,8 +17,9 @@ package org.apache.dolphinscheduler.plugin.task.api.parser; +import org.apache.dolphinscheduler.common.enums.CommandType; import org.apache.dolphinscheduler.common.utils.DateUtils; -import org.apache.dolphinscheduler.spi.enums.CommandType; +import org.apache.dolphinscheduler.common.utils.placeholder.BusinessTimeUtils; import java.util.Date; import java.util.Map; @@ -30,7 +31,7 @@ public class TimePlaceholderUtilsTest { Date date = DateUtils.parse("2022-08-26 00:00:00", "yyyy-MM-dd HH:mm:ss"); - Map timeParams = BusinessTimeUtils.getBusinessTime(CommandType.COMPLEMENT_DATA, date); + Map timeParams = BusinessTimeUtils.getBusinessTime(CommandType.COMPLEMENT_DATA, date, null); @Test public void timePlaceHolderForThisDay() { diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/main/java/org/apache/dolphinscheduler/plugin/task/dq/rule/RuleManager.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/main/java/org/apache/dolphinscheduler/plugin/task/dq/rule/RuleManager.java index 60533d0a89..b71b9e911c 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/main/java/org/apache/dolphinscheduler/plugin/task/dq/rule/RuleManager.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/main/java/org/apache/dolphinscheduler/plugin/task/dq/rule/RuleManager.java @@ -21,10 +21,11 @@ import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.SINGLE_Q import static org.apache.dolphinscheduler.plugin.task.api.utils.DataQualityConstants.COMPARISON_TYPE; import static org.apache.dolphinscheduler.plugin.task.api.utils.DataQualityConstants.UNIQUE_CODE; +import org.apache.dolphinscheduler.common.enums.CommandType; import org.apache.dolphinscheduler.common.utils.JSONUtils; +import org.apache.dolphinscheduler.common.utils.placeholder.BusinessTimeUtils; import org.apache.dolphinscheduler.plugin.task.api.DataQualityTaskExecutionContext; import org.apache.dolphinscheduler.plugin.task.api.enums.dp.RuleType; -import org.apache.dolphinscheduler.plugin.task.api.parser.BusinessTimeUtils; import org.apache.dolphinscheduler.plugin.task.dq.exception.DataQualityException; import org.apache.dolphinscheduler.plugin.task.dq.rule.entity.DqRuleInputEntry; import org.apache.dolphinscheduler.plugin.task.dq.rule.parameter.DataQualityConfiguration; @@ -34,7 +35,6 @@ import org.apache.dolphinscheduler.plugin.task.dq.rule.parser.MultiTableComparis import org.apache.dolphinscheduler.plugin.task.dq.rule.parser.SingleTableCustomSqlRuleParser; import org.apache.dolphinscheduler.plugin.task.dq.rule.parser.SingleTableRuleParser; import org.apache.dolphinscheduler.plugin.task.dq.utils.RuleParserUtils; -import org.apache.dolphinscheduler.spi.enums.CommandType; import java.util.Date; import java.util.Map; @@ -108,7 +108,8 @@ public class RuleManager { JSONUtils.toList(dataQualityTaskExecutionContext.getRuleInputEntryList(), DqRuleInputEntry.class)); inputParameterValueResult.putAll(inputParameterValue); - inputParameterValueResult.putAll(BusinessTimeUtils.getBusinessTime(CommandType.START_PROCESS, new Date())); + inputParameterValueResult + .putAll(BusinessTimeUtils.getBusinessTime(CommandType.START_PROCESS, new Date(), null)); inputParameterValueResult.putIfAbsent(COMPARISON_TYPE, NONE_COMPARISON_TYPE); inputParameterValueResult.put(UNIQUE_CODE, SINGLE_QUOTES + RuleParserUtils.generateUniqueCode(inputParameterValueResult) + SINGLE_QUOTES);