You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ke...@apache.org on 2023/04/10 02:58:29 UTC
[dolphinscheduler] branch 3.1.6-prepare updated (daabcdaa01 -> 0df149c370)
This is an automated email from the ASF dual-hosted git repository.
kerwin pushed a change to branch 3.1.6-prepare
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
from daabcdaa01 [maven-release-plugin] prepare for next development iteration
new 298091bf3b cherry-pick [Bug] [Cron] Parse corn expression error#13841
new 0df149c370 fix: when sudo enable is false, execute command will failed (#13860)
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../service/impl/ProcessDefinitionServiceImpl.java | 5 +++--
.../api/service/impl/SchedulerServiceImpl.java | 8 ++++----
.../dolphinscheduler/service/cron/CronUtils.java | 20 +++++++++++++++++++-
.../dolphinscheduler/service/cron/CronUtilsTest.java | 6 ++++++
.../plugin/task/api/utils/OSUtils.java | 2 +-
5 files changed, 33 insertions(+), 8 deletions(-)
[dolphinscheduler] 01/02: cherry-pick [Bug] [Cron] Parse corn expression error#13841
Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kerwin pushed a commit to branch 3.1.6-prepare
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
commit 298091bf3b64dd7a2ab648ca701a256a44e79bc0
Author: 旺阳 <qi...@cisco.com>
AuthorDate: Sun Apr 9 12:50:42 2023 +0800
cherry-pick [Bug] [Cron] Parse corn expression error#13841
---
.../service/impl/ProcessDefinitionServiceImpl.java | 5 +++--
.../api/service/impl/SchedulerServiceImpl.java | 8 ++++----
.../dolphinscheduler/service/cron/CronUtils.java | 20 +++++++++++++++++++-
.../dolphinscheduler/service/cron/CronUtilsTest.java | 6 ++++++
4 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java
index 26410f9a56..30916f15a5 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java
@@ -111,6 +111,7 @@ import org.apache.dolphinscheduler.plugin.task.api.enums.TaskTimeoutStrategy;
import org.apache.dolphinscheduler.plugin.task.api.model.Property;
import org.apache.dolphinscheduler.plugin.task.api.parameters.ParametersNode;
import org.apache.dolphinscheduler.plugin.task.api.parameters.SqlParameters;
+import org.apache.dolphinscheduler.service.cron.CronUtils;
import org.apache.dolphinscheduler.service.model.TaskNode;
import org.apache.dolphinscheduler.service.process.ProcessService;
import org.apache.dolphinscheduler.service.task.TaskPluginManager;
@@ -2368,8 +2369,8 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
putMsg(result, Status.SCHEDULE_START_TIME_END_TIME_SAME);
return result;
}
- if (!org.quartz.CronExpression.isValidExpression(scheduleObj.getCrontab())) {
- logger.error("{} verify failure", scheduleObj.getCrontab());
+ if (!CronUtils.isValidExpression(scheduleObj.getCrontab())) {
+ log.error("CronExpression verify failure, cron:{}.", scheduleObj.getCrontab());
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, scheduleObj.getCrontab());
return result;
}
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java
index c3eada0bea..1b63c52623 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java
@@ -177,9 +177,8 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
scheduleObj.setStartTime(scheduleParam.getStartTime());
scheduleObj.setEndTime(scheduleParam.getEndTime());
- if (!org.quartz.CronExpression.isValidExpression(scheduleParam.getCrontab())) {
- logger.error("{} verify failure", scheduleParam.getCrontab());
-
+ if (!CronUtils.isValidExpression(scheduleParam.getCrontab())) {
+ logger.error("Schedule crontab verify failure, crontab:{}.", scheduleParam.getCrontab());
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, scheduleParam.getCrontab());
return result;
}
@@ -664,7 +663,8 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
schedule.setStartTime(scheduleParam.getStartTime());
schedule.setEndTime(scheduleParam.getEndTime());
- if (!org.quartz.CronExpression.isValidExpression(scheduleParam.getCrontab())) {
+ if (!CronUtils.isValidExpression(scheduleParam.getCrontab())) {
+ logger.error("Schedule crontab verify failure, crontab:{}.", scheduleParam.getCrontab());
putMsg(result, Status.SCHEDULE_CRON_CHECK_FAILED, scheduleParam.getCrontab());
return;
}
diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/cron/CronUtils.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/cron/CronUtils.java
index b6c236f24e..11869ea943 100644
--- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/cron/CronUtils.java
+++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/cron/CronUtils.java
@@ -80,11 +80,29 @@ public class CronUtils {
public static Cron parse2Cron(String cronExpression) throws CronParseException {
try {
return QUARTZ_CRON_PARSER.parse(cronExpression);
- } catch (Exception ex) {
+ } catch (IllegalArgumentException ex) {
throw new CronParseException(String.format("Parse corn expression: [%s] error", cronExpression), ex);
}
}
+ /**
+ * Indicates whether the specified cron expression can be parsed into a
+ * valid cron expression
+ *
+ * @param cronExpression the expression to evaluate
+ * @return a boolean indicating whether the given expression is a valid cron
+ * expression
+ */
+ public static boolean isValidExpression(String cronExpression) {
+ try {
+ parse2Cron(cronExpression);
+ } catch (CronParseException e) {
+ return false;
+ }
+
+ return true;
+ }
+
/**
* get max cycle
*
diff --git a/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/cron/CronUtilsTest.java b/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/cron/CronUtilsTest.java
index 1e2b2548eb..c94d63983f 100644
--- a/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/cron/CronUtilsTest.java
+++ b/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/cron/CronUtilsTest.java
@@ -237,4 +237,10 @@ public class CronUtilsTest {
expirationTime = CronUtils.getExpirationTime(startTime, CycleEnum.YEAR);
Assert.assertEquals("2020-02-07 18:30:00", DateUtils.dateToString(expirationTime));
}
+
+ @Test
+ public void testValid() {
+ Assertions.assertFalse(CronUtils.isValidExpression("0 0 13/0 * * ? *"));
+ Assertions.assertTrue(CronUtils.isValidExpression("0 0 13-0 * * ? *"));
+ }
}
[dolphinscheduler] 02/02: fix: when sudo enable is false, execute command will failed (#13860)
Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kerwin pushed a commit to branch 3.1.6-prepare
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
commit 0df149c370508acbf476c4f20834326aa20da786
Author: huangxinan1990 <12...@users.noreply.github.com>
AuthorDate: Fri Apr 7 17:13:22 2023 +0800
fix: when sudo enable is false, execute command will failed (#13860)
---
.../java/org/apache/dolphinscheduler/plugin/task/api/utils/OSUtils.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/OSUtils.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/OSUtils.java
index 7bb2b32561..f8bfeae494 100644
--- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/OSUtils.java
+++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/OSUtils.java
@@ -39,7 +39,7 @@ public class OSUtils {
* @return result of sudo execute command
*/
public static String getSudoCmd(String tenantCode, String command) {
- return StringUtils.isEmpty(tenantCode) ? command : "sudo -u " + tenantCode + " " + command;
+ return StringUtils.isEmpty(tenantCode) || !isSudoEnable() ? command : "sudo -u " + tenantCode + " " + command;
}
/**