falcon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rostafiyc...@apache.org
Subject git commit: FALCON-706 Parse json with instances to InstancesResult using joda's DateTime. Contributed by Ruslan Ostafiychuk
Date Mon, 13 Oct 2014 06:30:29 GMT
Repository: incubator-falcon
Updated Branches:
  refs/heads/master 66213b056 -> ea8c7c6be


FALCON-706 Parse json with instances to InstancesResult using joda's DateTime. Contributed
by Ruslan Ostafiychuk


Project: http://git-wip-us.apache.org/repos/asf/incubator-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-falcon/commit/ea8c7c6b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-falcon/tree/ea8c7c6b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-falcon/diff/ea8c7c6b

Branch: refs/heads/master
Commit: ea8c7c6be3f2b98611bd26860f668b76997c3243
Parents: 66213b0
Author: Ruslan Ostafiychuk <rostafiychuk@apache.org>
Authored: Mon Oct 13 09:11:33 2014 +0300
Committer: Ruslan Ostafiychuk <rostafiychuk@apache.org>
Committed: Mon Oct 13 09:27:09 2014 +0300

----------------------------------------------------------------------
 falcon-regression/CHANGES.txt                   |  3 +++
 .../regression/core/util/InstanceUtil.java      | 24 ++++++++++++--------
 2 files changed, 18 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/ea8c7c6b/falcon-regression/CHANGES.txt
----------------------------------------------------------------------
diff --git a/falcon-regression/CHANGES.txt b/falcon-regression/CHANGES.txt
index 38e0241..bf9660d 100644
--- a/falcon-regression/CHANGES.txt
+++ b/falcon-regression/CHANGES.txt
@@ -14,6 +14,9 @@ Trunk (Unreleased)
    via Samarth Gupta)
 
   IMPROVEMENTS
+   FALCON-706 Parse json with instances to InstancesResult using joda's DateTime (Ruslan
+   Ostafiychuk)
+
    FALCON-798 optionalTest_updateProcessMakeOptionalCompulsory fixed (Paul
    Isaychuk via Raghav Kumar Gautam)
 

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/ea8c7c6b/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/InstanceUtil.java
----------------------------------------------------------------------
diff --git a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/InstanceUtil.java
b/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/InstanceUtil.java
index d8bef69..73cf8c8 100644
--- a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/InstanceUtil.java
+++ b/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/InstanceUtil.java
@@ -19,6 +19,10 @@
 package org.apache.falcon.regression.core.util;
 
 import com.google.gson.GsonBuilder;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParseException;
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.exception.ExceptionUtils;
@@ -59,6 +63,7 @@ import org.apache.oozie.client.Job.Status;
 import org.apache.oozie.client.OozieClient;
 import org.apache.oozie.client.OozieClientException;
 import org.apache.oozie.client.WorkflowJob;
+import org.joda.time.DateTime;
 import org.testng.Assert;
 
 import java.io.BufferedReader;
@@ -66,9 +71,11 @@ import java.io.IOException;
 import java.io.InputStreamReader;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Type;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.EnumSet;
 import java.util.List;
 import java.util.Map;
@@ -167,15 +174,14 @@ public final class InstanceUtil {
             r.setStatusCode(400);
             return r;
         }
-        if (url.contains("/summary/")) {
-            r = new GsonBuilder().setPrettyPrinting().create()
-                    .fromJson(jsonString, InstancesSummaryResult.class);
-        } else {
-
-            r = new GsonBuilder().create()
-                    .fromJson(jsonString, InstancesResult.class);
-        }
-
+        r = new GsonBuilder().registerTypeAdapter(Date.class, new JsonDeserializer<Date>()
{
+                @Override
+                public Date deserialize(JsonElement json, Type t, JsonDeserializationContext
c)
+                    throws JsonParseException {
+                    return new DateTime(json.getAsString()).toDate();
+                }
+            }).create().fromJson(jsonString,
+            url.contains("/summary/") ? InstancesSummaryResult.class : InstancesResult.class);
         LOGGER.info("r.getMessage(): " + r.getMessage());
         LOGGER.info("r.getStatusCode(): " + r.getStatusCode());
         LOGGER.info("r.getStatus() " + r.getStatus());


Mime
View raw message