You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by an...@apache.org on 2018/05/21 10:18:45 UTC
oozie git commit: OOZIE-2867 [Coordinators] Emphasize Region/City
timezone format (dbist13 via rkanter, andras.piros)
Repository: oozie
Updated Branches:
refs/heads/master 71b668fbe -> ef32fbb0e
OOZIE-2867 [Coordinators] Emphasize Region/City timezone format (dbist13 via rkanter, andras.piros)
Project: http://git-wip-us.apache.org/repos/asf/oozie/repo
Commit: http://git-wip-us.apache.org/repos/asf/oozie/commit/ef32fbb0
Tree: http://git-wip-us.apache.org/repos/asf/oozie/tree/ef32fbb0
Diff: http://git-wip-us.apache.org/repos/asf/oozie/diff/ef32fbb0
Branch: refs/heads/master
Commit: ef32fbb0e3ebefd43db5e04149b65d641cdf6ec5
Parents: 71b668f
Author: Andras Piros <an...@cloudera.com>
Authored: Mon May 21 12:15:38 2018 +0200
Committer: Andras Piros <an...@cloudera.com>
Committed: Mon May 21 12:15:38 2018 +0200
----------------------------------------------------------------------
.../java/org/apache/oozie/cli/OozieCLI.java | 3 ++-
.../java/org/apache/oozie/util/DateUtils.java | 25 +++++++++++++++++---
.../org/apache/oozie/util/TestDateUtils.java | 13 ++++++++--
.../site/twiki/CoordinatorFunctionalSpec.twiki | 11 ++++++---
release-log.txt | 1 +
5 files changed, 44 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/oozie/blob/ef32fbb0/client/src/main/java/org/apache/oozie/cli/OozieCLI.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/oozie/cli/OozieCLI.java b/client/src/main/java/org/apache/oozie/cli/OozieCLI.java
index 4abc750..2828633 100644
--- a/client/src/main/java/org/apache/oozie/cli/OozieCLI.java
+++ b/client/src/main/java/org/apache/oozie/cli/OozieCLI.java
@@ -2267,7 +2267,8 @@ public class OozieCLI {
}
private void printAvailableTimeZones() {
- System.out.println("The format is \"SHORT_NAME (ID)\"\nGive the ID to the -timezone argument");
+ System.out.println("The format is \"SHORT_NAME (ID)\"\nGive the ID (GMT, UTC or Region/City)" +
+ "to the -timezone argument");
System.out.println("GMT offsets can also be used (e.g. GMT-07:00, GMT-0700, GMT+05:30, GMT+0530)");
System.out.println("Available Time Zones:");
for (String tzId : TimeZone.getAvailableIDs()) {
http://git-wip-us.apache.org/repos/asf/oozie/blob/ef32fbb0/core/src/main/java/org/apache/oozie/util/DateUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/oozie/util/DateUtils.java b/core/src/main/java/org/apache/oozie/util/DateUtils.java
index 261dc3d..e63a1fb 100644
--- a/core/src/main/java/org/apache/oozie/util/DateUtils.java
+++ b/core/src/main/java/org/apache/oozie/util/DateUtils.java
@@ -18,6 +18,7 @@
package org.apache.oozie.util;
+import com.google.common.annotations.VisibleForTesting;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
@@ -29,7 +30,6 @@ import java.util.GregorianCalendar;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import org.apache.hadoop.conf.Configuration;
import org.apache.oozie.coord.TimeUnit;
import org.apache.oozie.service.ConfigurationService;
@@ -38,9 +38,9 @@ import org.apache.oozie.service.ConfigurationService;
* Date utility classes to parse and format datetimes in Oozie expected datetime formats.
*/
public class DateUtils {
-
+ private static final XLog LOG = XLog.getLog(DateUtils.class);
private static final Pattern GMT_OFFSET_COLON_PATTERN = Pattern.compile("^GMT(\\-|\\+)(\\d{2})(\\d{2})$");
-
+ private static final Pattern THREE_LETTER_ID_PATTERN = Pattern.compile("[A-Z]{3}");
public static final TimeZone UTC = getTimeZone("UTC");
public static final String ISO8601_UTC_MASK = "yyyy-MM-dd'T'HH:mm'Z'";
@@ -141,6 +141,12 @@ public class DateUtils {
}
tzId = handleGMTOffsetTZNames(tzId); // account for GMT-####
TimeZone tz = TimeZone.getTimeZone(tzId);
+
+ // Check whether tzID can handle DST shifts
+ if (!isThreeLetterTZName(tzId)) {
+ LOG.warn("GMT, UTC or Region/City Timezone formats are preferred instead of " + 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);
@@ -149,6 +155,19 @@ public class DateUtils {
}
/**
+ * Check whether 3-letter timezone ID is in preferred format,
+ * UTC, GMT or Region/City, the other three-letter codes may not handle
+ * DST shifts properly.
+ * @param tzId
+ * @return true if format is not appropriate for DST shift
+ */
+ @VisibleForTesting
+ static boolean isThreeLetterTZName(String tzId) {
+ Matcher m = THREE_LETTER_ID_PATTERN.matcher(tzId);
+ return m.matches() && !tzId.equalsIgnoreCase("UTC") && !tzId.equalsIgnoreCase("GMT");
+ }
+
+ /**
* Parses a datetime in ISO8601 format in UTC timezone
*
* @param s string with the datetime to parse.
http://git-wip-us.apache.org/repos/asf/oozie/blob/ef32fbb0/core/src/test/java/org/apache/oozie/util/TestDateUtils.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/util/TestDateUtils.java b/core/src/test/java/org/apache/oozie/util/TestDateUtils.java
index 2fcac51..1df7b78 100644
--- a/core/src/test/java/org/apache/oozie/util/TestDateUtils.java
+++ b/core/src/test/java/org/apache/oozie/util/TestDateUtils.java
@@ -15,14 +15,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.oozie.util;
import org.apache.hadoop.conf.Configuration;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
-
import java.text.ParseException;
import java.util.Date;
import java.util.TimeZone;
@@ -137,4 +135,15 @@ public class TestDateUtils {
public void testGetTimeZoneInvalidFormatNull() throws Exception {
DateUtils.getTimeZone(null);
}
+
+ @Test
+ public void testIsThreeLetterTZName() {
+ Assert.assertTrue(DateUtils.isThreeLetterTZName("PST"));
+ Assert.assertTrue(DateUtils.isThreeLetterTZName("PDT"));
+ Assert.assertTrue(DateUtils.isThreeLetterTZName("BST"));
+ Assert.assertTrue(DateUtils.isThreeLetterTZName("CST"));
+ Assert.assertFalse(DateUtils.isThreeLetterTZName("UTC"));
+ Assert.assertFalse(DateUtils.isThreeLetterTZName("GMT"));
+ Assert.assertFalse(DateUtils.isThreeLetterTZName("America/Los_Angeles"));
+ }
}
http://git-wip-us.apache.org/repos/asf/oozie/blob/ef32fbb0/docs/src/site/twiki/CoordinatorFunctionalSpec.twiki
----------------------------------------------------------------------
diff --git a/docs/src/site/twiki/CoordinatorFunctionalSpec.twiki b/docs/src/site/twiki/CoordinatorFunctionalSpec.twiki
index bc32806..cd416d4 100644
--- a/docs/src/site/twiki/CoordinatorFunctionalSpec.twiki
+++ b/docs/src/site/twiki/CoordinatorFunctionalSpec.twiki
@@ -136,7 +136,7 @@ time zone is other than =UTC=, the qualifier must be the GMT offset, =(+/-)####=
For example, a datetime in =UTC= is =2012-08-12T00:00Z=, the same datetime in =GMT+5:30= is =2012-08-12T05:30+0530=.
-For simplicity, there rest of this specification uses =UTC= datetimes.
+For simplicity, the rest of this specification uses =UTC= datetimes.
#datetime
---+++ 4.1. Datetime
@@ -166,8 +166,13 @@ There is no widely accepted standard to identify timezones.
Oozie Coordinator will understand the following timezone identifiers:
* Generic NON-DST timezone identifier: =GMT[+/-]##:##= (i.e.: GMT+05:30)
+ * UTC timezone identifier: =UTC= (i.e.: 2009-06-06T00:00Z)
* ZoneInfo identifiers, with DST support, understood by Java JDK (about 600 IDs) (i.e.: America/Los_Angeles)
+Due to DST shift from PST to PDT, it is preferred that GMT, UTC or Region/City timezone notation is used in
+favor of direct three-letter ID (PST, PDT, BST, etc.). For example, America/Los_Angeles switches from PST to PDT
+at a DST shift. If used directly, PST will not handle DST shift when time is switched to PDT.
+
Oozie Coordinator must provide a tool for developers to list all supported timezone identifiers.
---+++ 4.3. Timezones and Daylight-Saving
@@ -3445,12 +3450,12 @@ In other words, it offsets the =baseDate= by the difference from Oozie processin
account for daylight saving time based on the given =baseDate= and =timezone=.
The =timezone= argument accepts any timezone or GMT offset that is returned by the
-[[DG_CommandLineTool#Getting_a_list_of_time_zones]["info -timezones"]] command. For example, "America/Los_Angeles" or "PST".
+[[DG_CommandLineTool#Getting_a_list_of_time_zones]["info -timezones"]] command. For example, "America/Los_Angeles".
For example, if =baseDate= is '2012-06-13T00:00Z' and =timezone= is 'America/Los_Angeles', the return date will be
'2012-06-12T17:00Z'. But if =baseDate= is '2012-12-13T00:00Z', then the return date will be '2012-12-12T16:00Z'. The difference
in return dates occurs because the former occurs during Summer when DST is in effect (UTC-0700) and the latter occurs during Winter
-when DST is no in effect (UTC-0800).
+when DST is not in effect (UTC-0800).
*%GREEN% Example: %ENDCOLOR%*:
http://git-wip-us.apache.org/repos/asf/oozie/blob/ef32fbb0/release-log.txt
----------------------------------------------------------------------
diff --git a/release-log.txt b/release-log.txt
index 7f8d651..e46b4cc 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -1,5 +1,6 @@
-- Oozie 5.1.0 release (trunk - unreleased)
+OOZIE-2867 [Coordinators] Emphasize Region/City timezone format (dbist13 via rkanter, andras.piros)
OOZIE-3242 Flaky test TestXCommand#testXCommandLifecycleLockingFailingToLock (pbacsko via gezapeti)
OOZIE-3226 [tools] TestOozieDBCLI#testOozieDBCLI() fails (pbacsko via gezapeti)
OOZIE-2968 TestJavaActionExecutor.testCredentialsSkip fails intermittently (pbacsko via gezapeti)