You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by tu...@apache.org on 2012/08/25 01:47:04 UTC
svn commit: r1377153 - in /incubator/oozie/trunk:
core/src/main/java/org/apache/oozie/util/DateUtils.java
core/src/test/java/org/apache/oozie/util/TestDateUtils.java release-log.txt
Author: tucu
Date: Fri Aug 24 23:47:03 2012
New Revision: 1377153
URL: http://svn.apache.org/viewvc?rev=1377153&view=rev
Log:
OOZIE-965 Allow the timezone attribute in coordinator jobs to use a format like GMT-#### (rkanter via tucu)
Modified:
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/DateUtils.java
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/util/TestDateUtils.java
incubator/oozie/trunk/release-log.txt
Modified: incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/DateUtils.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/DateUtils.java?rev=1377153&r1=1377152&r2=1377153&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/DateUtils.java (original)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/DateUtils.java Fri Aug 24 23:47:03 2012
@@ -26,6 +26,7 @@ import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.hadoop.conf.Configuration;
@@ -36,6 +37,8 @@ import org.apache.oozie.coord.TimeUnit;
*/
public class DateUtils {
+ private static final Pattern GMT_OFFSET_COLON_PATTERN = Pattern.compile("^GMT(\\-|\\+)(\\d{2})(\\d{2})$");
+
public static final TimeZone UTC = getTimeZone("UTC");
public static final String ISO8601_UTC_MASK = "yyyy-MM-dd'T'HH:mm'Z'";
@@ -50,7 +53,7 @@ public class DateUtils {
private static boolean OOZIE_IN_UTC = true;
- private static final String VALID_TIMEZONE_MASK = "^UTC$|^GMT(\\+|\\-)\\d{4}$";
+ private static final Pattern VALID_TIMEZONE_PATTERN = Pattern.compile("^UTC$|^GMT(\\+|\\-)\\d{4}$");
/**
* Configures the Datetime parsing with Oozie processing timezone.
@@ -62,8 +65,7 @@ public class DateUtils {
*/
public static void setConf(Configuration conf) {
String tz = conf.get(OOZIE_PROCESSING_TIMEZONE_KEY, OOZIE_PROCESSING_TIMEZONE_DEFAULT);
- Pattern pattern = Pattern.compile(VALID_TIMEZONE_MASK);
- if (!pattern.matcher(tz).find()) {
+ if (!VALID_TIMEZONE_PATTERN.matcher(tz).matches()) {
throw new RuntimeException("Invalid Oozie timezone, it must be 'UTC' or 'GMT(+/-)####");
}
ACTIVE_TIMEZONE = TimeZone.getTimeZone(tz);
@@ -107,6 +109,25 @@ public class DateUtils {
}
/**
+ * {@link TimeZone#getTimeZone(java.lang.String)} takes the timezone ID as an argument; for invalid IDs it returns the
+ * <code>GMT</code> TimeZone. A timezone ID formatted like <code>GMT-####</code> is not a valid ID, however, it will actually
+ * map this to the <code>GMT-##:##</code> TimeZone, instead of returning the <code>GMT</code> TimeZone. We check (later)
+ * check that a timezone ID is valid by calling {@link TimeZone#getTimeZone(java.lang.String)} and seeing if the returned
+ * TimeZone ID is equal to the original; because we want to allow <code>GMT-####</code>, while still disallowing actual
+ * invalid IDs, we have to manually replace <code>GMT-####</code> with <code>GMT-##:##</code> first.
+ *
+ * @param tzId The timezone ID
+ * @return If tzId matches <code>GMT-####</code>, then we return <code>GMT-##:##</code>; otherwise, we return tzId unaltered
+ */
+ private static String handleGMTOffsetTZNames(String tzId) {
+ Matcher m = GMT_OFFSET_COLON_PATTERN.matcher(tzId);
+ if (m.matches() && m.groupCount() == 3) {
+ tzId = "GMT" + m.group(1) + m.group(2) + ":" + m.group(3);
+ }
+ return tzId;
+ }
+
+ /**
* Returns the {@link TimeZone} for the given timezone ID.
*
* @param tzId timezone ID.
@@ -116,7 +137,9 @@ public class DateUtils {
if (tzId == null) {
throw new IllegalArgumentException("Invalid TimeZone: " + tzId);
}
+ tzId = handleGMTOffsetTZNames(tzId); // account for GMT-####
TimeZone tz = TimeZone.getTimeZone(tzId);
+ // If these are not equal, it means that the tzId is not valid (invalid tzId's return GMT)
if (!tz.getID().equals(tzId)) {
throw new IllegalArgumentException("Invalid TimeZone: " + tzId);
}
Modified: incubator/oozie/trunk/core/src/test/java/org/apache/oozie/util/TestDateUtils.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/util/TestDateUtils.java?rev=1377153&r1=1377152&r2=1377153&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/test/java/org/apache/oozie/util/TestDateUtils.java (original)
+++ incubator/oozie/trunk/core/src/test/java/org/apache/oozie/util/TestDateUtils.java Fri Aug 24 23:47:03 2012
@@ -24,6 +24,7 @@ import org.junit.Test;
import java.text.ParseException;
import java.util.Date;
+import java.util.TimeZone;
public class TestDateUtils {
@@ -97,4 +98,42 @@ public class TestDateUtils {
DateUtils.setConf(conf);
}
+ @Test
+ public void testGetTimeZoneValidFormats() throws Exception {
+ Assert.assertEquals(TimeZone.getTimeZone("America/Los_Angeles"), DateUtils.getTimeZone("America/Los_Angeles"));
+
+ Assert.assertEquals(TimeZone.getTimeZone("PST"), DateUtils.getTimeZone("PST"));
+
+ Assert.assertEquals(TimeZone.getTimeZone("GMT"), DateUtils.getTimeZone("GMT"));
+
+ // Check that these four TimeZones are all equal
+ TimeZone GMTOffsetColon = TimeZone.getTimeZone("GMT-07:00");
+ TimeZone GMTOffsetNoColon = TimeZone.getTimeZone("GMT-0700");
+ TimeZone oozieGMTOffsetColon = DateUtils.getTimeZone("GMT-07:00");
+ TimeZone oozieGMTOffsetNoColon = DateUtils.getTimeZone("GMT-0700");
+ Assert.assertEquals(GMTOffsetColon, GMTOffsetNoColon);
+ Assert.assertEquals(GMTOffsetNoColon, oozieGMTOffsetColon);
+ Assert.assertEquals(oozieGMTOffsetColon, oozieGMTOffsetNoColon);
+ Assert.assertFalse(TimeZone.getTimeZone("GMT").equals(oozieGMTOffsetNoColon));
+
+ // Check that these four TimeZones are all equal
+ GMTOffsetColon = TimeZone.getTimeZone("GMT+05:30");
+ GMTOffsetNoColon = TimeZone.getTimeZone("GMT+0530");
+ oozieGMTOffsetColon = DateUtils.getTimeZone("GMT+05:30");
+ oozieGMTOffsetNoColon = DateUtils.getTimeZone("GMT+0530");
+ Assert.assertEquals(GMTOffsetColon, GMTOffsetNoColon);
+ Assert.assertEquals(GMTOffsetNoColon, oozieGMTOffsetColon);
+ Assert.assertEquals(oozieGMTOffsetColon, oozieGMTOffsetNoColon);
+ Assert.assertFalse(TimeZone.getTimeZone("GMT").equals(oozieGMTOffsetNoColon));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testGetTimeZoneInvalidFormat() throws Exception {
+ DateUtils.getTimeZone("This_is_not_a_TimeZone_id");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testGetTimeZoneInvalidFormatNull() throws Exception {
+ DateUtils.getTimeZone(null);
+ }
}
Modified: incubator/oozie/trunk/release-log.txt
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/release-log.txt?rev=1377153&r1=1377152&r2=1377153&view=diff
==============================================================================
--- incubator/oozie/trunk/release-log.txt (original)
+++ incubator/oozie/trunk/release-log.txt Fri Aug 24 23:47:03 2012
@@ -1,5 +1,6 @@
-- Oozie 3.3.0 release (trunk - unreleased)
+OOZIE-965 Allow the timezone attribute in coordinator jobs to use a format like GMT-#### (rkanter via tucu)
OOZIE-848 Bulk Monitoring API - Consolidated view of jobs (mona via virag)
OOZIE-934 Exception reporting during Services startup is inadequate (mona via virag)
OOZIE-914 Make sure all commands do their JPA writes within a single JPA executor (mona via virag)