Author: rkanter
Date: Wed Jul 24 00:49:10 2013
New Revision: 1506380
URL: http://svn.apache.org/r1506380
Log:
OOZIE-1425 param checker should validate cron syntax (bowenzhangusa via rkanter)
Modified:
oozie/trunk/core/pom.xml
oozie/trunk/core/src/main/java/org/apache/oozie/command/coord/CoordSubmitXCommand.java
oozie/trunk/core/src/main/java/org/apache/oozie/util/ParamChecker.java
oozie/trunk/core/src/test/java/org/apache/oozie/util/TestParamChecker.java
oozie/trunk/pom.xml
oozie/trunk/release-log.txt
Modified: oozie/trunk/core/pom.xml
URL:
http://svn.apache.org/viewvc/oozie/trunk/core/pom.xml?rev=1506380&r1=1506379&r2=1506380&view=diff
==============================================================================
--- oozie/trunk/core/pom.xml (original)
+++ oozie/trunk/core/pom.xml Wed Jul 24 00:49:10 2013
@@ -272,6 +272,11 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.quartz-scheduler</groupId>
+ <artifactId>quartz</artifactId>
+ </dependency>
+
<!-- For drawing runtime DAG -->
<dependency>
<groupId>net.sf.jung</groupId>
Modified:
oozie/trunk/core/src/main/java/org/apache/oozie/command/coord/CoordSubmitXCommand.java
URL:
http://svn.apache.org/viewvc/oozie/trunk/core/src/main/java/org/apache/oozie/command/coord/CoordSubmitXCommand.java?rev=1506380&r1=1506379&r2=1506380&view=diff
==============================================================================
---
oozie/trunk/core/src/main/java/org/apache/oozie/command/coord/CoordSubmitXCommand.java
(original)
+++
oozie/trunk/core/src/main/java/org/apache/oozie/command/coord/CoordSubmitXCommand.java
Wed Jul 24 00:49:10 2013
@@ -625,9 +625,10 @@ public class CoordSubmitXCommand extends
// job's main attributes
// frequency
String val = resolveAttribute("frequency", eAppXml, evalFreq);
- int ival = ParamChecker.checkInteger(val, "frequency");
- ParamChecker.checkGTZero(ival, "frequency");
- coordJob.setFrequency(Integer.toString(ival));
+ int ival = 0;
+
+ val = ParamChecker.checkFrequency(val);
+ coordJob.setFrequency(val);
TimeUnit tmp = (evalFreq.getVariable("timeunit") == null) ?
TimeUnit.MINUTE : ((TimeUnit) evalFreq
.getVariable("timeunit"));
addAnAttribute("freq_timeunit", eAppXml, tmp.toString());
Modified: oozie/trunk/core/src/main/java/org/apache/oozie/util/ParamChecker.java
URL:
http://svn.apache.org/viewvc/oozie/trunk/core/src/main/java/org/apache/oozie/util/ParamChecker.java?rev=1506380&r1=1506379&r2=1506380&view=diff
==============================================================================
--- oozie/trunk/core/src/main/java/org/apache/oozie/util/ParamChecker.java
(original)
+++ oozie/trunk/core/src/main/java/org/apache/oozie/util/ParamChecker.java Wed
Jul 24 00:49:10 2013
@@ -21,6 +21,10 @@ import java.util.Date;
import java.util.List;
import java.util.TimeZone;
+import org.apache.commons.lang.StringUtils;
+import org.quartz.CronExpression;
+import java.text.ParseException;
+
/**
* Utility class to check common parameter preconditions.
*/
@@ -215,6 +219,51 @@ public class ParamChecker {
}
/**
+ * Check whether a value is a valid coordinator frequency.
+ *
+ * @param value : value to test
+ * @return If the value is a valid frequency, return the frequency,
Otherwise throw IllegalArgumentException
+ */
+ public static String checkFrequency(String val) {
+ try {
+ Integer.parseInt(val);
+ }
+ catch (NumberFormatException ex) {
+ try {
+ // this part is necessary since Quartz
+ // doesn't support for specifying both a day-of-week
+ // and a day-of-month parameter, nor does it support
+ // using "?" in both fields, but we don't want to
+ // expose it to users.
+ String[] cronArray1 = val.split(" ");
+ String[] cronArray2 = val.split(" ");
+
+ if (cronArray1.length != 5) {
+ throw new IllegalArgumentException(XLog.format(
+ "parameter [{0}] = [{1}] must have 5 bit fields.
Parsing error {2}", "frequency",
+ val, ex.getMessage(), ex));
+ }
+
+ if (!cronArray1[4].trim().equals("?")) {
+ cronArray1[2] = "?";
+ }
+
+ if (!cronArray2[2].trim().equals("?")) {
+ cronArray2[4] = "?";
+ }
+
+ new CronExpression("0 " + StringUtils.join(cronArray1, " "));
+ new CronExpression("0 " + StringUtils.join(cronArray2, " "));
+ }
+ catch (ParseException pex) {
+ throw new IllegalArgumentException(XLog.format(
+ "parameter [{0}] = [{1}] must be an integer or a cron
syntax. Parsing error {2}", "frequency",
+ val, ex.getMessage(), ex));
+ }
+ }
+ return val;
+ }
+ /**
* Check whether the value is Oozie processing timezone data format.
*
* @param value : value to test
Modified:
oozie/trunk/core/src/test/java/org/apache/oozie/util/TestParamChecker.java
URL:
http://svn.apache.org/viewvc/oozie/trunk/core/src/test/java/org/apache/oozie/util/TestParamChecker.java?rev=1506380&r1=1506379&r2=1506380&view=diff
==============================================================================
--- oozie/trunk/core/src/test/java/org/apache/oozie/util/TestParamChecker.java
(original)
+++ oozie/trunk/core/src/test/java/org/apache/oozie/util/TestParamChecker.java
Wed Jul 24 00:49:10 2013
@@ -214,4 +214,28 @@ public class TestParamChecker extends XT
}
+ public void testCheckFrequency() {
+ ParamChecker.checkFrequency("10");
+
+ String cron = "20,30 * * 10 *";
+ ParamChecker.checkFrequency(cron);
+
+ cron = "0/10 10-12 3 5 MON,FRI";
+ ParamChecker.checkFrequency(cron);
+
+ try {
+ ParamChecker.checkFrequency("frequency");
+ fail();
+ }
+ catch (IllegalArgumentException ex) {
+ }
+
+ try {
+ ParamChecker.checkFrequency("10 * w e 1-4");
+ fail();
+ }
+ catch (IllegalArgumentException ex) {
+ }
+ }
+
}
Modified: oozie/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/oozie/trunk/pom.xml?rev=1506380&r1=1506379&r2=1506380&view=diff
==============================================================================
--- oozie/trunk/pom.xml (original)
+++ oozie/trunk/pom.xml Wed Jul 24 00:49:10 2013
@@ -712,6 +712,12 @@
<version>${xerces.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.quartz-scheduler</groupId>
+ <artifactId>quartz</artifactId>
+ <version>2.1.7</version>
+ </dependency>
+
</dependencies>
</dependencyManagement>
Modified: oozie/trunk/release-log.txt
URL:
http://svn.apache.org/viewvc/oozie/trunk/release-log.txt?rev=1506380&r1=1506379&r2=1506380&view=diff
==============================================================================
--- oozie/trunk/release-log.txt (original)
+++ oozie/trunk/release-log.txt Wed Jul 24 00:49:10 2013
@@ -1,5 +1,6 @@
-- Oozie 4.1.0 release (trunk - unreleased)
+OOZIE-1425 param checker should validate cron syntax (bowenzhangusa via
rkanter)
OOZIE-1453 Change "frequency" to string in SyncCoordAction.java (bowenzhangusa
via rkanter)
OOZIE-1447 Sqoop actions that don't launch a map reduce job fail with an
IllegalArgumentException (jarcec via rkanter)
OOZIE-1440 Build fails in certain environments due to xerces OpenJPA issue
(mackrorysd via rkanter)