[ 
https://issues.apache.org/jira/browse/GOBBLIN-759?focusedWorklogId=387983&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-387983
 ]

ASF GitHub Bot logged work on GOBBLIN-759:
------------------------------------------

                Author: ASF GitHub Bot
            Created on: 15/Feb/20 18:59
            Start Date: 15/Feb/20 18:59
    Worklog Time Spent: 10m 
      Work Description: amarnathkarthik commented on pull request #2633: 
GOBBLIN-759: Added feature to support DistCP to copy files that were …
URL: https://github.com/apache/incubator-gobblin/pull/2633#discussion_r379849413
 
 

 ##########
 File path: 
gobblin-data-management/src/main/java/org/apache/gobblin/data/management/copy/ModifiedDateRangeBasedFileFilter.java
 ##########
 @@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.gobblin.data.management.copy;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Properties;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.apache.hadoop.fs.FileSystem;
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
+import org.joda.time.Period;
+import org.joda.time.format.PeriodFormatter;
+import org.joda.time.format.PeriodFormatterBuilder;
+
+import com.google.common.collect.ImmutableList;
+
+import org.apache.gobblin.configuration.ConfigurationKeys;
+
+
+/**
+ * A {@link CopyableFileFilter} that drops a {@link CopyableFile} if file 
modified time not between the loop back window
+ *  <code>sourceFs<code>
+ */
+@Slf4j
+public class ModifiedDateRangeBasedFileFilter implements CopyableFileFilter {
+
+  private final Properties props;
+  private Period minLookBackPeriod;
+  private Period maxLookBackPeriod;
+  private DateTime currentTime;
+  private DateTime minLookBackTime;
+  private DateTime maxLookBackTime;
+
+  public static final String CONFIGURATION_KEY_PREFIX = 
"gobblin.dataset.filter.";
+  public static final String MODIFIED_MIN_LOOK_BACK_TIME_KEY =
+      CONFIGURATION_KEY_PREFIX + "selection.modified.min.lookbackTime";
+  public static final String MODIFIED_MAX_LOOK_BACK_TIME_KEY =
+      CONFIGURATION_KEY_PREFIX + "selection.modified.max.lookbackTime";
+  public static final String DEFAULT_DATE_PATTERN_TIMEZONE = 
ConfigurationKeys.PST_TIMEZONE_NAME;
+  public static final String DATE_PATTERN_TIMEZONE_KEY = 
CONFIGURATION_KEY_PREFIX + "datetime.timezone";
+
+  public ModifiedDateRangeBasedFileFilter(Properties properties) {
+    this.props = properties;
+    PeriodFormatter periodFormatter =
+        new 
PeriodFormatterBuilder().appendDays().appendSuffix("d").appendHours().appendSuffix("h").toFormatter();
+    this.minLookBackPeriod = 
props.containsKey(MODIFIED_MIN_LOOK_BACK_TIME_KEY) ? 
periodFormatter.parsePeriod(
+        props.getProperty(MODIFIED_MIN_LOOK_BACK_TIME_KEY)) : new 
Period(DateTime.now().getMillis());
+    this.maxLookBackPeriod = 
props.containsKey(MODIFIED_MAX_LOOK_BACK_TIME_KEY) ? 
periodFormatter.parsePeriod(
+        props.getProperty(MODIFIED_MAX_LOOK_BACK_TIME_KEY)) : new 
Period(DateTime.now().minusDays(1).getMillis());
+    this.currentTime = properties.containsKey(DATE_PATTERN_TIMEZONE_KEY) ? 
DateTime.now(
+        DateTimeZone.forID(props.getProperty(DATE_PATTERN_TIMEZONE_KEY)))
+        : DateTime.now(DateTimeZone.forID(DEFAULT_DATE_PATTERN_TIMEZONE));
+    this.minLookBackTime = this.currentTime.minus(minLookBackPeriod);
+    this.maxLookBackTime = this.currentTime.minus(maxLookBackPeriod);
+  }
+
+  /**
+   * For every {@link CopyableFile} in <code>copyableFiles</code> checks if a 
{@link CopyableFile#getOrigin()#getPath()#getModificationTime()}
+   * + date between the min and max look back window on <code>sourceFs</code> 
{@inheritDoc}
+   *
+   * @see CopyableFileFilter#filter(FileSystem,
+   *      FileSystem, Collection)
+   */
+  @Override
+  public Collection<CopyableFile> filter(FileSystem sourceFs, FileSystem 
targetFs,
+      Collection<CopyableFile> copyableFiles) {
+    Iterator<CopyableFile> iterator = copyableFiles.iterator();
+
+    ImmutableList.Builder<CopyableFile> filtered = ImmutableList.builder();
+
+    while (iterator.hasNext()) {
+      CopyableFile file = iterator.next();
+      boolean fileWithInModWindow = 
isFileModifiedBtwLookBackPeriod(file.getOrigin().getModificationTime());
+      if (fileWithInModWindow) {
+        filtered.add(file);
+      }
+    }
+
+    return filtered.build();
+  }
+
+  /**
+   *
+   * @param modTime file modification time in long.
+   * @return <code>true</code> if the file modification time between look back 
window;
+   *         <code>false</code> if file modification time not between look 
back window.
+   *
+   */
+  private boolean isFileModifiedBtwLookBackPeriod(long modTime) {
 
 Review comment:
   Fixed
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 387983)
    Time Spent: 5h 20m  (was: 5h 10m)

> DistCP files modified in last n days within a look back period
> --------------------------------------------------------------
>
>                 Key: GOBBLIN-759
>                 URL: https://issues.apache.org/jira/browse/GOBBLIN-759
>             Project: Apache Gobblin
>          Issue Type: Improvement
>            Reporter: Karthik Amarnath
>            Priority: Major
>          Time Spent: 5h 20m
>  Remaining Estimate: 0h
>
> *Feature Request:*
>  # DistCP only the files modified in last n days within the look back window.
>  # DistCP will copy only the files modified even when the source file which 
> were NOT modified in last n days in the destination directory.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to