falcon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From suh...@apache.org
Subject falcon git commit: FALCON-1071 Feed Listing API default behaviour for start and end not handled properly. Contributed by Suhas Vasu
Date Wed, 18 Mar 2015 07:46:43 GMT
Repository: falcon
Updated Branches:
  refs/heads/master 04ef0fdb4 -> d4800401a


FALCON-1071 Feed Listing API default behaviour for start and end not handled properly. Contributed
by Suhas Vasu


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

Branch: refs/heads/master
Commit: d4800401afc1d1aa70b74b8afebf5ca73321a09a
Parents: 04ef0fd
Author: Suhas Vasu <suhas.v@inmobi.com>
Authored: Wed Mar 18 13:16:26 2015 +0530
Committer: Suhas Vasu <suhas.v@inmobi.com>
Committed: Wed Mar 18 13:16:26 2015 +0530

----------------------------------------------------------------------
 CHANGES.txt                                     |  3 ++
 .../org/apache/falcon/entity/EntityUtil.java    |  7 ++--
 .../apache/falcon/entity/EntityUtilTest.java    | 36 ++++++++++++++++++--
 .../resource/AbstractInstanceManager.java       | 24 +++++++++----
 4 files changed, 60 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/falcon/blob/d4800401/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 9be6461..b7a14f2 100755
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -88,6 +88,9 @@ Trunk (Unreleased)
    Seetharam)
 
   OPTIMIZATIONS
+   FALCON-1071 Feed Listing API default behaviour for start and end
+   not handled properly. (Suhas Vasu)
+
    FALCON-1063 Falcon CLI list entities operation throws NullPointerException
    (Pallavi Rao via Suhas Vasu)
 

http://git-wip-us.apache.org/repos/asf/falcon/blob/d4800401/common/src/main/java/org/apache/falcon/entity/EntityUtil.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/falcon/entity/EntityUtil.java b/common/src/main/java/org/apache/falcon/entity/EntityUtil.java
index f27bcad..c553d1e 100644
--- a/common/src/main/java/org/apache/falcon/entity/EntityUtil.java
+++ b/common/src/main/java/org/apache/falcon/entity/EntityUtil.java
@@ -317,11 +317,14 @@ public final class EntityUtil {
         return count + 1;
     }
 
-    public static Date getNextInstanceTime(Date instanceTime, Frequency frequency, TimeZone
tz) {
+    public static Date getNextInstanceTime(Date instanceTime, Frequency frequency, TimeZone
tz, int instanceCount) {
+        if (tz == null) {
+            tz = TimeZone.getTimeZone("UTC");
+        }
         Calendar insCal = Calendar.getInstance(tz);
         insCal.setTime(instanceTime);
 
-        final int freq = frequency.getFrequencyAsInt();
+        final int freq = frequency.getFrequencyAsInt() * instanceCount;
         insCal.add(frequency.getTimeUnit().getCalendarUnit(), freq);
 
         return insCal.getTime();

http://git-wip-us.apache.org/repos/asf/falcon/blob/d4800401/common/src/test/java/org/apache/falcon/entity/EntityUtilTest.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/falcon/entity/EntityUtilTest.java b/common/src/test/java/org/apache/falcon/entity/EntityUtilTest.java
index 370be5f..bfdb9f8 100644
--- a/common/src/test/java/org/apache/falcon/entity/EntityUtilTest.java
+++ b/common/src/test/java/org/apache/falcon/entity/EntityUtilTest.java
@@ -28,9 +28,11 @@ import org.apache.falcon.entity.v0.feed.LateArrival;
 import org.apache.falcon.entity.v0.process.Cluster;
 import org.apache.falcon.entity.v0.process.Process;
 import org.testng.Assert;
+import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
 import java.text.DateFormat;
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.TimeZone;
@@ -220,7 +222,6 @@ public class EntityUtilTest extends AbstractTestBase {
         Date startDate = getDate("2012-06-02 10:00 UTC");
         Date nextAfter = getDate("2136-06-02 10:00 UTC");
         Frequency frequency = Frequency.fromString("months(1)");
-        TimeZone timeZone = TimeZone.getTimeZone("UTC");
         Date expectedResult = nextAfter;
         Date result = EntityUtil.getNextStartTime(startDate, frequency, tz, nextAfter);
         Assert.assertEquals(result, expectedResult);
@@ -246,7 +247,7 @@ public class EntityUtilTest extends AbstractTestBase {
     }
 
     @Test
-    public void testGetLateProcessFeed() throws FalconException{
+    public void testGetLateProcessFeed() throws FalconException {
         Feed feed = new Feed();
 
         Assert.assertNull(EntityUtil.getLateProcess(feed));
@@ -256,4 +257,35 @@ public class EntityUtilTest extends AbstractTestBase {
         Assert.assertNotNull(EntityUtil.getLateProcess(feed));
     }
 
+    @Test(dataProvider = "NextInstanceExpressions")
+    public void testGetNextInstances(String instanceTimeStr, String frequencyStr, int instanceIncrementCount,
+                                     String expectedInstanceTimeStr) throws Exception {
+
+        Date instanceTime = getDate(instanceTimeStr);
+        Frequency frequency = Frequency.fromString(frequencyStr);
+
+        Date nextInstanceTime = EntityUtil.getNextInstanceTime(instanceTime, frequency, tz,
instanceIncrementCount);
+
+        Assert.assertEquals(nextInstanceTime, getDate(expectedInstanceTimeStr));
+
+    }
+
+    @DataProvider(name = "NextInstanceExpressions")
+    public Object[][] nextInstanceExpressions() throws ParseException {
+        String instanceTimeStr = "2014-01-01 00:00 UTC";
+        return new Object[][] {
+            {instanceTimeStr, "minutes(1)", 1, "2014-01-01 00:01 UTC"},
+            {instanceTimeStr, "minutes(1)", 25, "2014-01-01 00:25 UTC"},
+
+            {instanceTimeStr, "hours(1)", 1, "2014-01-01 01:00 UTC"},
+            {instanceTimeStr, "hours(1)", 5, "2014-01-01 05:00 UTC"},
+
+            {instanceTimeStr, "days(1)", 1, "2014-01-02 00:00 UTC"},
+            {instanceTimeStr, "days(1)", 10, "2014-01-11 00:00 UTC"},
+
+            {instanceTimeStr, "months(1)", 1, "2014-02-01 00:00 UTC"},
+            {instanceTimeStr, "months(1)", 7, "2014-08-01 00:00 UTC"},
+        };
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/falcon/blob/d4800401/prism/src/main/java/org/apache/falcon/resource/AbstractInstanceManager.java
----------------------------------------------------------------------
diff --git a/prism/src/main/java/org/apache/falcon/resource/AbstractInstanceManager.java b/prism/src/main/java/org/apache/falcon/resource/AbstractInstanceManager.java
index caf623b..9630a3b 100644
--- a/prism/src/main/java/org/apache/falcon/resource/AbstractInstanceManager.java
+++ b/prism/src/main/java/org/apache/falcon/resource/AbstractInstanceManager.java
@@ -200,6 +200,8 @@ public abstract class AbstractInstanceManager extends AbstractEntityManager
{
         }
     }
 
+    //RESUME CHECKSTYLE CHECK ParameterNumberCheck
+
     private InstancesResult getInstanceResultSubset(InstancesResult resultSet, String filterBy,
                                                     String orderBy, String sortOrder, Integer
offset,
                                                     Integer numResults) throws FalconException
{
@@ -330,8 +332,6 @@ public abstract class AbstractInstanceManager extends AbstractEntityManager
{
         return instanceSet;
     }
 
-    //RESUME CHECKSTYLE CHECK ParameterNumberCheck
-
     public FeedInstanceResult getListing(String type, String entity, String startStr,
                                          String endStr, String colo) {
         checkColo(colo);
@@ -367,7 +367,7 @@ public abstract class AbstractInstanceManager extends AbstractEntityManager
{
             Pair<Date, Date> startAndEndDate = getStartAndEndDate(entityObject, startTime,
null);
             Date start = startAndEndDate.first;
             Date end = EntityUtil.getNextInstanceTime(start, EntityUtil.getFrequency(entityObject),
-                    EntityUtil.getTimeZone(entityObject));
+                    EntityUtil.getTimeZone(entityObject), 1);
             AbstractWorkflowEngine wfEngine = getWorkflowEngine();
             return wfEngine.getInstanceParams(entityObject, start, end, lifeCycles);
         } catch (Throwable e) {
@@ -496,7 +496,7 @@ public abstract class AbstractInstanceManager extends AbstractEntityManager
{
         throws FalconException {
         Pair<Date, Date> clusterStartEndDates = EntityUtil.getEntityStartEndDates(entityObject);
         Frequency frequency = EntityUtil.getFrequency(entityObject);
-        Date endDate = getEndDate(endStr, clusterStartEndDates.second);
+        Date endDate = getEndDate(startStr, endStr, clusterStartEndDates.second, frequency);
         Date startDate = getStartDate(startStr, endDate, clusterStartEndDates.first, frequency);
 
         if (startDate.after(endDate)) {
@@ -506,8 +506,20 @@ public abstract class AbstractInstanceManager extends AbstractEntityManager
{
         return new Pair<Date, Date>(startDate, endDate);
     }
 
-    private Date getEndDate(String endStr, Date clusterEndDate) throws FalconException {
-        Date endDate = StringUtils.isEmpty(endStr) ? new Date() : EntityUtil.parseDateUTC(endStr);
+    private Date getEndDate(String startStr, String endStr, Date clusterEndDate,
+                            Frequency frequency) throws FalconException {
+        Date endDate;
+        if (StringUtils.isEmpty(endStr)) {
+            if (!StringUtils.isEmpty(startStr)) {
+                // set endDate to startDate + 10 times frequency
+                endDate = EntityUtil.getNextInstanceTime(EntityUtil.parseDateUTC(startStr),
frequency, null, 10);
+            } else {
+                // set endDate to currentTime
+                endDate = new Date();
+            }
+        } else {
+            endDate = EntityUtil.parseDateUTC(endStr);
+        }
         if (endDate.after(clusterEndDate)) {
             endDate = clusterEndDate;
         }


Mime
View raw message