Gargi-jais11 commented on code in PR #12161:
URL: https://github.com/apache/ozone/pull/12161#discussion_r4783677844


##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/S3LifecycleConfiguration.java:
##########
@@ -654,4 +661,87 @@ private static AndOperator convertFromOzoneAndOperator(
 
     return andOperator;
   }
+
+  /**
+   * Builds the value of the {@code x-amz-expiration} response header for a 
newly written object, in the form
+   * {@code expiry-date="Fri, 27 Nov 2026 00:00:00 GMT", rule-id="rule1"}. 
Among the enabled rules with an
+   * Expiration action that match the object, the one with the earliest expiry 
date is used. For a Days rule,
+   * the expiry date is the creation time plus the given days, rounded up to 
the next midnight UTC, as AWS S3 does.
+   *
+   * @param lifecycleConfiguration lifecycle configuration of the bucket
+   * @param keyName name of the object
+   * @param tags tags of the object
+   * @param creationTime creation time of the object in milliseconds since 
epoch
+   * @return the header value, or null if no enabled Expiration rule matches 
the object
+   */
+  public static String getExpirationHeader(OzoneLifecycleConfiguration 
lifecycleConfiguration, String keyName,
+      Map<String, String> tags, long creationTime) {
+    ZonedDateTime earliest = null;
+    String ruleId = null;
+    for (OzoneLifecycleConfiguration.OzoneLCRule rule : 
lifecycleConfiguration.getRules()) {
+      if (!STATUS_ENABLED.equals(rule.getStatus()) || rule.getExpiration() == 
null
+          || !matches(rule, keyName, tags)) {
+        continue;
+      }
+      ZonedDateTime expiry = getExpiryDate(rule.getExpiration(), creationTime);
+      if (expiry != null && (earliest == null || expiry.isBefore(earliest))) {
+        earliest = expiry;
+        ruleId = rule.getId();
+      }
+    }
+    if (earliest == null) {
+      return null;
+    }
+    return "expiry-date=\"" + RFC1123Util.FORMAT.format(earliest) + "\", 
rule-id=\"" + ruleId + "\"";
+  }
+
+  private static boolean matches(OzoneLifecycleConfiguration.OzoneLCRule rule, 
String keyName,

Review Comment:
   this seems to be re implemented `OmLCRule.match`, `OmLCFilter.match` and 
`OmLifecycleRuleAndOperator.match`, which KeyLifecycleService uses for the 
actual deletion. So the two drift. 
   One difference which already exists: FSO buckets normalize directory-style 
prefixes in OmLCRule.valid / validateAndNormalizePrefix, and this new code 
compares raw prefixes. Could you add a match(String keyPath, Map<String, 
String> tags) method to the OM helpers and use it here, so the header and the 
deletion always are same?



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to