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/27 18:08:50 UTC

svn commit: r1377728 - in /incubator/oozie/trunk: client/src/main/java/org/apache/oozie/cli/OozieCLI.java core/src/main/java/org/apache/oozie/servlet/BaseAdminServlet.java docs/src/site/twiki/DG_CommandLineTool.twiki release-log.txt

Author: tucu
Date: Mon Aug 27 16:08:49 2012
New Revision: 1377728

URL: http://svn.apache.org/viewvc?rev=1377728&view=rev
Log:
OOZIE-966 Fix formatting in CLI output when GMT-#### and GMT-##:## formatted timezones are used (rkanter via tucu)

Modified:
    incubator/oozie/trunk/client/src/main/java/org/apache/oozie/cli/OozieCLI.java
    incubator/oozie/trunk/core/src/main/java/org/apache/oozie/servlet/BaseAdminServlet.java
    incubator/oozie/trunk/docs/src/site/twiki/DG_CommandLineTool.twiki
    incubator/oozie/trunk/release-log.txt

Modified: incubator/oozie/trunk/client/src/main/java/org/apache/oozie/cli/OozieCLI.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/client/src/main/java/org/apache/oozie/cli/OozieCLI.java?rev=1377728&r1=1377727&r2=1377728&view=diff
==============================================================================
--- incubator/oozie/trunk/client/src/main/java/org/apache/oozie/cli/OozieCLI.java (original)
+++ incubator/oozie/trunk/client/src/main/java/org/apache/oozie/cli/OozieCLI.java Mon Aug 27 16:08:49 2012
@@ -32,6 +32,8 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.TimeZone;
 import java.util.concurrent.Callable;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.xml.XMLConstants;
 import javax.xml.parsers.DocumentBuilder;
@@ -153,6 +155,8 @@ public class OozieCLI {
     private static final String MAPRED_INPUT = "mapred.input.dir";
     private static final String MAPRED_OUTPUT = "mapred.output.dir";
 
+    private static final Pattern GMT_OFFSET_SHORTEN_PATTERN = Pattern.compile("(.* )GMT((?:-|\\+)\\d{2}:\\d{2})");
+
     static {
         StringBuilder sb = new StringBuilder();
         for (int i = 0; i < LINE_WIDTH; i++) {
@@ -1441,7 +1445,14 @@ public class OozieCLI {
         if (timeZoneId != null) {
             dateFormater.setTimeZone(TimeZone.getTimeZone(timeZoneId));
         }
-        return dateFormater.format(date);
+        String dateString = dateFormater.format(date);
+        // Most TimeZones are 3 or 4 characters; GMT offsets (e.g. GMT-07:00) are 9, so lets remove the "GMT" part to make it 6
+        // to fit better
+        Matcher m = GMT_OFFSET_SHORTEN_PATTERN.matcher(dateString);
+        if (m.matches() && m.groupCount() == 2) {
+            dateString = m.group(1) + m.group(2);
+        }
+        return dateString;
     }
 
     private void validateCommand(CommandLine commandLine) throws OozieCLIException {
@@ -1556,10 +1567,11 @@ 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("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()) {
-            // skip id's that are like "GMT+01:00" because they won't get parsed correctly later (but allow just "GMT")
-            if (!tzId.contains("GMT") || tzId.equals("GMT")) {
+            // skip id's that are like "Etc/GMT+01:00" because their display names are like "GMT-01:00", which is confusing
+            if (!tzId.startsWith("Etc/GMT")) {
                 TimeZone tZone = TimeZone.getTimeZone(tzId);
                 System.out.println("      " + tZone.getDisplayName(false, TimeZone.SHORT) + " (" + tzId + ")");
             }

Modified: incubator/oozie/trunk/core/src/main/java/org/apache/oozie/servlet/BaseAdminServlet.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/servlet/BaseAdminServlet.java?rev=1377728&r1=1377727&r2=1377728&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/servlet/BaseAdminServlet.java (original)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/servlet/BaseAdminServlet.java Mon Aug 27 16:08:49 2012
@@ -18,7 +18,6 @@
 package org.apache.oozie.servlet;
 
 import java.io.IOException;
-import java.util.Arrays;
 import java.util.Map;
 import java.util.TimeZone;
 
@@ -184,18 +183,44 @@ public abstract class BaseAdminServlet e
 
     protected abstract void getQueueDump(JSONObject json) throws XServletException;
     
+    private static final JSONArray GMTOffsetTimeZones = new JSONArray();
+    static {
+        prepareGMTOffsetTimeZones();
+    }
+
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    private static void prepareGMTOffsetTimeZones() {
+        for (String tzId : new String[]{"GMT-12:00", "GMT-11:00", "GMT-10:00", "GMT-09:00", "GMT-08:00", "GMT-07:00", "GMT-06:00",
+                                        "GMT-05:00", "GMT-04:00", "GMT-03:00", "GMT-02:00", "GMT-01:00", "GMT+01:00", "GMT+02:00",
+                                        "GMT+03:00", "GMT+04:00", "GMT+05:00", "GMT+06:00", "GMT+07:00", "GMT+08:00", "GMT+09:00",
+                                        "GMT+10:00", "GMT+11:00", "GMT+12:00"}) {
+            TimeZone tz = TimeZone.getTimeZone(tzId);
+            JSONObject json = new JSONObject();
+            json.put(JsonTags.TIME_ZOME_DISPLAY_NAME, tz.getDisplayName(false, TimeZone.SHORT) + " (" + tzId + ")");
+            json.put(JsonTags.TIME_ZONE_ID, tzId);
+            GMTOffsetTimeZones.add(json);
+        }
+    }
+
+    @SuppressWarnings({"unchecked", "rawtypes"})
     private JSONArray availableTimeZonesToJsonArray() {
         JSONArray array = new JSONArray();
         for (String tzId : TimeZone.getAvailableIDs()) {
-            // skip id's that are like "GMT+01:00" because they won't get parsed correctly later (but allow just "GMT")
-            if (!tzId.contains("GMT") || tzId.equals("GMT")) {
-                JSONObject json = new JSONObject();    
+            // skip id's that are like "Etc/GMT+01:00" because their display names are like "GMT-01:00", which is confusing
+            if (!tzId.startsWith("Etc/GMT")) {
+                JSONObject json = new JSONObject();
                 TimeZone tZone = TimeZone.getTimeZone(tzId);
                 json.put(JsonTags.TIME_ZOME_DISPLAY_NAME, tZone.getDisplayName(false, TimeZone.SHORT) + " (" + tzId + ")");
                 json.put(JsonTags.TIME_ZONE_ID, tzId);
                 array.add(json);
             }
         }
+
+        // The combo box this populates cannot be edited, so the user can't type in GMT offsets (like in the CLI), so we'll add
+        // in some hourly offsets here (though the user will not be able to use other offsets without editing the cookie manually
+        // and they are not in order)
+        array.addAll(GMTOffsetTimeZones);
+
         return array;
     }
 

Modified: incubator/oozie/trunk/docs/src/site/twiki/DG_CommandLineTool.twiki
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/docs/src/site/twiki/DG_CommandLineTool.twiki?rev=1377728&r1=1377727&r2=1377728&view=diff
==============================================================================
--- incubator/oozie/trunk/docs/src/site/twiki/DG_CommandLineTool.twiki (original)
+++ incubator/oozie/trunk/docs/src/site/twiki/DG_CommandLineTool.twiki Mon Aug 27 16:08:49 2012
@@ -741,6 +741,7 @@ $ oozie info -timezones
 .
 The format is "SHORT_NAME (ID)"
 Give the ID to the -timezone argument
+GMT offsets can also be used (e.g. GMT-07:00, GMT-0700, GMT+05:30, GMT+0530)
 Available Time Zones :
       SST (Pacific/Midway)
       NUT (Pacific/Niue)

Modified: incubator/oozie/trunk/release-log.txt
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/release-log.txt?rev=1377728&r1=1377727&r2=1377728&view=diff
==============================================================================
--- incubator/oozie/trunk/release-log.txt (original)
+++ incubator/oozie/trunk/release-log.txt Mon Aug 27 16:08:49 2012
@@ -1,4 +1,8 @@
--- Oozie 3.3.0 release (trunk - unreleased)
+-- Oozie 3.4.0 release (trunk - unreleased)
+
+OOZIE-966 Fix formatting in CLI output when GMT-#### and GMT-##:## formatted timezones are used (rkanter via tucu)
+
+-- Oozie 3.3.0 release (unreleased)
 
 OOZIE-960 TestStatusTransitService failing intermittently (virag)
 OOZIE-968 source oozie environment from conf in oozie db setup script (svenkat via virag)