ashishkumar50 commented on code in PR #8275:
URL: https://github.com/apache/ozone/pull/8275#discussion_r2045250006


##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmLifecycleConfiguration.java:
##########
@@ -0,0 +1,249 @@
+/*
+ * 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.hadoop.ozone.om.helpers;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.Auditable;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+
+/**
+ * A class that encapsulates lifecycle configuration.
+ */
+public class OmLifecycleConfiguration extends WithObjectID
+    implements Auditable {
+
+  // Ref: 
https://docs.aws.amazon.com/AmazonS3/latest/userguide/intro-lifecycle-rules.html#intro-lifecycle-rule-id
+  public static final int LC_MAX_RULES = 1000;
+  private String volume;
+  private String bucket;
+  private String owner;
+  private long creationTime;
+  private List<OmLCRule> rules;
+
+  OmLifecycleConfiguration(OmLifecycleConfiguration.Builder builder) {
+    super(builder);
+    this.volume = builder.volume;
+    this.bucket = builder.bucket;
+    this.owner = builder.owner;
+    this.rules = builder.rules;
+    this.creationTime = builder.creationTime;
+  }
+
+  public List<OmLCRule> getRules() {
+    return rules;
+  }
+
+  public void setRules(List<OmLCRule> rules) {
+    this.rules = rules;
+  }
+
+  public String getBucket() {
+    return bucket;
+  }
+
+  public void setBucket(String bucket) {
+    this.bucket = bucket;
+  }
+
+  public String getOwner() {
+    return owner;
+  }
+
+  public void setOwner(String owner) {
+    this.owner = owner;
+  }
+
+  public String getVolume() {
+    return volume;
+  }
+
+  public void setVolume(String volume) {
+    this.volume = volume;
+  }
+
+  public long getCreationTime() {
+    return creationTime;
+  }
+
+  public void setCreationTime(long creationTime) {
+    this.creationTime = creationTime;
+  }
+
+  /**
+   * Validates the lifecycle configuration.
+   * - Volume, Bucket and Owner cannot be blank
+   * - At least one rule needs to be specified
+   * - Number of rules should not exceed the allowed limit
+   * - Rules must have unique IDs
+   * - Each rule is validated individually
+   *
+   * @throws OMException if the validation fails
+   */
+  public void valid() throws OMException {
+    if (StringUtils.isBlank(volume)) {
+      throw new OMException("Invalid lifecycle configuration: Volume cannot be 
blank.",
+          OMException.ResultCodes.INVALID_REQUEST);
+    }
+
+    if (StringUtils.isBlank(bucket)) {
+      throw new OMException("Invalid lifecycle configuration: Bucket cannot be 
blank.",
+          OMException.ResultCodes.INVALID_REQUEST);
+    }
+
+    if (StringUtils.isBlank(owner)) {
+      throw new OMException("Invalid lifecycle configuration: Owner cannot be 
blank.",
+          OMException.ResultCodes.INVALID_REQUEST);
+    }

Review Comment:
   There are many `if` condition in this method, can you merge few.



##########
hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestOmLCExpiration.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.hadoop.ozone.om.helpers;
+
+import static 
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.INVALID_REQUEST;
+import static org.apache.hadoop.ozone.om.helpers.OMLCUtils.assertOMException;
+import static org.apache.hadoop.ozone.om.helpers.OMLCUtils.getFutureDateString;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test OmLCExpiration.
+ */
+class TestOmLCExpiration {
+
+  @Test
+  public void testCreateValidOmLCExpiration() {
+    OmLCExpiration exp1 = new OmLCExpiration.Builder()
+        .setDays(30)
+        .build();
+    assertDoesNotThrow(exp1::valid);
+
+    OmLCExpiration exp2 = new OmLCExpiration.Builder()
+        .setDate("2099-10-10T00:00:00Z")
+        .build();
+    assertDoesNotThrow(exp2::valid);
+
+    OmLCExpiration exp3 = new OmLCExpiration.Builder()
+        .setDays(1)
+        .build();
+    assertDoesNotThrow(exp3::valid);
+
+    OmLCExpiration exp4 = new OmLCExpiration.Builder()
+        .setDate("2099-12-31T00:00:00Z")
+        .build();
+    assertDoesNotThrow(exp4::valid);
+
+    OmLCExpiration exp5 = new OmLCExpiration.Builder()
+        .setDate("2099-02-15T00:00:00.000Z")
+        .build();
+    assertDoesNotThrow(exp5::valid);
+  }
+
+  @Test
+  public void testCreateInValidOmLCExpiration() {
+    OmLCExpiration exp1 = new OmLCExpiration.Builder()
+        .setDays(30)
+        .setDate(getFutureDateString(100))
+        .build();
+    assertOMException(exp1::valid, INVALID_REQUEST,
+        "Either 'days' or 'date' should be specified, but not both or 
neither.");
+
+    OmLCExpiration exp2 = new OmLCExpiration.Builder()
+        .setDays(-1)
+        .build();
+    assertOMException(exp2::valid, INVALID_REQUEST,
+        "'Days' for Expiration action must be a positive integer");
+
+    OmLCExpiration exp3 = new OmLCExpiration.Builder()
+        .setDate(null)
+        .build();
+    assertOMException(exp3::valid, INVALID_REQUEST,
+        "Either 'days' or 'date' should be specified, but not both or 
neither.");
+
+    OmLCExpiration exp4 = new OmLCExpiration.Builder()
+        .setDate("")
+        .build();
+    assertOMException(exp4::valid, INVALID_REQUEST,
+        "Either 'days' or 'date' should be specified, but not both or 
neither.");
+
+    OmLCExpiration exp5 = new OmLCExpiration.Builder()
+        .build();
+    assertOMException(exp5::valid, INVALID_REQUEST,
+        "Either 'days' or 'date' should be specified, but not both or 
neither.");
+
+    OmLCExpiration exp6 = new OmLCExpiration.Builder()
+        .setDate("10-10-2099")
+        .build();
+    assertOMException(exp6::valid, INVALID_REQUEST,
+        "'Date' must be in ISO 8601 format");
+
+    OmLCExpiration exp7 = new OmLCExpiration.Builder()
+        .setDate("2099-12-31T00:00:00")
+        .build();
+    assertOMException(exp7::valid, INVALID_REQUEST,
+        "'Date' must be in ISO 8601 format");
+
+    // Testing for date in the past
+    OmLCExpiration exp8 = new OmLCExpiration.Builder()
+        .setDate(getFutureDateString(-1))
+        .build();
+    assertOMException(exp8::valid, INVALID_REQUEST,
+        "'Date' must be in the future");
+
+    OmLCExpiration exp9 = new OmLCExpiration.Builder()
+        .setDays(0)
+        .build();
+    assertOMException(exp9::valid, INVALID_REQUEST,
+        "Either 'days' or 'date' should be specified, but not both or 
neither.");

Review Comment:
   `exp9` assert should be `Days' for Expiration action must be a positive 
integer.` ?



##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmLCRule.java:
##########
@@ -0,0 +1,238 @@
+/*
+ * 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.hadoop.ozone.om.helpers;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+
+/**
+ * A class that encapsulates lifecycle rule.
+ */
+public class OmLCRule {
+
+  public static final int LC_ID_LENGTH = 48;
+  // Ref: 
https://docs.aws.amazon.com/AmazonS3/latest/userguide/intro-lifecycle-rules.html#intro-lifecycle-rule-id
+  public static final int LC_ID_MAX_LENGTH = 255;
+
+  private String id;
+  private String prefix;
+  private boolean enabled;
+  private boolean isPrefixEnable;
+  private boolean isTagEnable;
+  // List of actions for this rule
+  private List<OmLCAction> actions;
+  private OmLCFilter filter;
+
+  OmLCRule(String id, String prefix, boolean enabled,
+      List<OmLCAction> actions, OmLCFilter filter) {
+    this.id = id;
+    this.prefix = prefix;
+    this.enabled = enabled;
+    this.actions = actions;
+    this.filter = filter;
+
+    if (StringUtils.isEmpty(this.id)) {
+      this.id = RandomStringUtils.randomAlphanumeric(LC_ID_LENGTH);

Review Comment:
   Can you write a comment here: ID will come from lifecycle config, if not OM 
will generate the ID.



##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmLCRule.java:
##########
@@ -0,0 +1,238 @@
+/*
+ * 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.hadoop.ozone.om.helpers;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+
+/**
+ * A class that encapsulates lifecycle rule.
+ */
+public class OmLCRule {
+
+  public static final int LC_ID_LENGTH = 48;
+  // Ref: 
https://docs.aws.amazon.com/AmazonS3/latest/userguide/intro-lifecycle-rules.html#intro-lifecycle-rule-id
+  public static final int LC_ID_MAX_LENGTH = 255;
+
+  private String id;
+  private String prefix;
+  private boolean enabled;
+  private boolean isPrefixEnable;
+  private boolean isTagEnable;
+  // List of actions for this rule
+  private List<OmLCAction> actions;
+  private OmLCFilter filter;
+
+  OmLCRule(String id, String prefix, boolean enabled,
+      List<OmLCAction> actions, OmLCFilter filter) {
+    this.id = id;
+    this.prefix = prefix;
+    this.enabled = enabled;
+    this.actions = actions;
+    this.filter = filter;
+
+    if (StringUtils.isEmpty(this.id)) {
+      this.id = RandomStringUtils.randomAlphanumeric(LC_ID_LENGTH);
+    }
+
+    OmLifecycleRuleAndOperator andOperator = filter != null ? 
filter.getAndOperator() : null;
+
+    if (prefix != null ||
+        (filter != null && filter.getPrefix() != null) ||
+        (andOperator != null && andOperator.getPrefix() != null)) {
+      isPrefixEnable = true;
+    }
+
+    if ((filter != null && filter.getTag() != null) ||
+        (andOperator != null && !andOperator.getTags().isEmpty())) {
+      isTagEnable = true;
+    }
+  }
+
+  public String getId() {
+    return id;
+  }
+
+  public void setId(String id) {
+    this.id = id;
+  }
+
+  public String getPrefix() {
+    return prefix;
+  }
+
+  public void setPrefix(String prefix) {
+    this.prefix = prefix;
+  }
+
+  public boolean isEnabled() {
+    return enabled;
+  }
+
+  public void setEnabled(boolean enabled) {
+    this.enabled = enabled;
+  }
+
+  public List<OmLCAction> getActions() {
+    return actions;
+  }
+
+  public void setActions(List<OmLCAction> actions) {
+    this.actions = actions;
+  }
+
+  /**
+   * Get the expiration action if present.
+   *
+   * @return the expiration action if present, null otherwise
+   */
+  public OmLCExpiration getExpiration() {
+    if (actions == null || actions.isEmpty()) {
+      return null;
+    }
+
+    for (OmLCAction action : actions) {
+      if (action instanceof OmLCExpiration) {
+        return (OmLCExpiration) action;
+      }
+    }
+    return null;
+  }
+
+  public OmLCFilter getFilter() {
+    return filter;
+  }
+
+  public boolean isPrefixEnable() {
+    return isPrefixEnable;
+  }
+
+  public boolean isTagEnable() {
+    return isTagEnable;
+  }
+
+  public void setFilter(OmLCFilter filter) {
+    this.filter = filter;
+  }
+
+  /**
+   * Validates the lifecycle rule.
+   * - ID length should not exceed the allowed limit
+   * - At least one action must be specified
+   * - Filter and Prefix cannot be used together
+   * - Actions must be valid
+   * - Filter must be valid
+   * - There must be at most one Expiration action per rule
+   *
+   * @throws OMException if the validation fails
+   */
+  public void valid() throws OMException {
+    if (id.length() > LC_ID_MAX_LENGTH) {
+      throw new OMException("ID length should not exceed allowed limit of " + 
LC_ID_MAX_LENGTH,
+          OMException.ResultCodes.INVALID_REQUEST);
+    }
+
+    if (actions == null || actions.isEmpty()) {
+      throw new OMException("At least one action needs to be specified in a 
rule.",
+          OMException.ResultCodes.INVALID_REQUEST);
+    }
+
+    // Check that there is at most one Expiration action
+    for (OmLCAction action : actions) {
+      if (action.getActionType() == OmLCAction.ActionType.EXPIRATION) {
+        if (actions.size() > 1) {

Review Comment:
   There could be different actions, We should check only `EXPIRATION` action 
should not be multiple.



##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmLCRule.java:
##########
@@ -0,0 +1,238 @@
+/*
+ * 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.hadoop.ozone.om.helpers;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+
+/**
+ * A class that encapsulates lifecycle rule.
+ */
+public class OmLCRule {
+
+  public static final int LC_ID_LENGTH = 48;
+  // Ref: 
https://docs.aws.amazon.com/AmazonS3/latest/userguide/intro-lifecycle-rules.html#intro-lifecycle-rule-id
+  public static final int LC_ID_MAX_LENGTH = 255;
+
+  private String id;
+  private String prefix;
+  private boolean enabled;
+  private boolean isPrefixEnable;
+  private boolean isTagEnable;
+  // List of actions for this rule
+  private List<OmLCAction> actions;
+  private OmLCFilter filter;
+
+  OmLCRule(String id, String prefix, boolean enabled,
+      List<OmLCAction> actions, OmLCFilter filter) {
+    this.id = id;
+    this.prefix = prefix;
+    this.enabled = enabled;
+    this.actions = actions;
+    this.filter = filter;
+
+    if (StringUtils.isEmpty(this.id)) {
+      this.id = RandomStringUtils.randomAlphanumeric(LC_ID_LENGTH);
+    }
+
+    OmLifecycleRuleAndOperator andOperator = filter != null ? 
filter.getAndOperator() : null;
+
+    if (prefix != null ||
+        (filter != null && filter.getPrefix() != null) ||
+        (andOperator != null && andOperator.getPrefix() != null)) {
+      isPrefixEnable = true;
+    }
+
+    if ((filter != null && filter.getTag() != null) ||
+        (andOperator != null && !andOperator.getTags().isEmpty())) {
+      isTagEnable = true;
+    }
+  }
+
+  public String getId() {
+    return id;
+  }
+
+  public void setId(String id) {
+    this.id = id;
+  }
+
+  public String getPrefix() {
+    return prefix;
+  }
+
+  public void setPrefix(String prefix) {
+    this.prefix = prefix;
+  }
+
+  public boolean isEnabled() {
+    return enabled;
+  }
+
+  public void setEnabled(boolean enabled) {
+    this.enabled = enabled;
+  }
+
+  public List<OmLCAction> getActions() {
+    return actions;
+  }
+
+  public void setActions(List<OmLCAction> actions) {
+    this.actions = actions;
+  }
+
+  /**
+   * Get the expiration action if present.
+   *
+   * @return the expiration action if present, null otherwise
+   */
+  public OmLCExpiration getExpiration() {
+    if (actions == null || actions.isEmpty()) {
+      return null;
+    }
+
+    for (OmLCAction action : actions) {
+      if (action instanceof OmLCExpiration) {
+        return (OmLCExpiration) action;
+      }
+    }
+    return null;
+  }
+
+  public OmLCFilter getFilter() {
+    return filter;
+  }
+
+  public boolean isPrefixEnable() {
+    return isPrefixEnable;
+  }
+
+  public boolean isTagEnable() {
+    return isTagEnable;
+  }
+
+  public void setFilter(OmLCFilter filter) {
+    this.filter = filter;
+  }
+
+  /**
+   * Validates the lifecycle rule.
+   * - ID length should not exceed the allowed limit
+   * - At least one action must be specified
+   * - Filter and Prefix cannot be used together
+   * - Actions must be valid
+   * - Filter must be valid
+   * - There must be at most one Expiration action per rule
+   *
+   * @throws OMException if the validation fails
+   */
+  public void valid() throws OMException {
+    if (id.length() > LC_ID_MAX_LENGTH) {
+      throw new OMException("ID length should not exceed allowed limit of " + 
LC_ID_MAX_LENGTH,
+          OMException.ResultCodes.INVALID_REQUEST);
+    }
+
+    if (actions == null || actions.isEmpty()) {
+      throw new OMException("At least one action needs to be specified in a 
rule.",
+          OMException.ResultCodes.INVALID_REQUEST);
+    }
+
+    // Check that there is at most one Expiration action
+    for (OmLCAction action : actions) {
+      if (action.getActionType() == OmLCAction.ActionType.EXPIRATION) {
+        if (actions.size() > 1) {
+          throw new OMException("A rule can have at most one Expiration 
action.",
+              OMException.ResultCodes.INVALID_REQUEST);
+        }
+      }
+      action.valid();
+    }
+
+    if (prefix != null && filter != null) {

Review Comment:
   If `prefix` is `empty` and `filter != null` can we allow?



##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmLifecycleRuleAndOperator.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.hadoop.ozone.om.helpers;
+
+import jakarta.annotation.Nonnull;
+import jakarta.annotation.Nullable;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+
+/**
+ * A class that encapsulates lifecycleRule andOperator.
+ */
+public final class OmLifecycleRuleAndOperator {
+
+  private final Map<String, String> tags;
+  private final String prefix;
+
+  private OmLifecycleRuleAndOperator(Map<String, String> tags, String prefix) {
+    this.tags = tags;
+    this.prefix = prefix;
+  }
+
+  @Nonnull
+  public Map<String, String> getTags() {
+    return tags;
+  }
+
+  @Nullable
+  public String getPrefix() {
+    return prefix;
+  }
+
+  /**
+   * Validates the OmLifecycleRuleAndOperator.
+   * Ensures the following:
+   * - Either tags or prefix must be specified.
+   * - If there are tags and no prefix, the tags should be more than one.
+   * - Prefix alone is not allowed.
+   *
+   * @throws OMException if the validation fails.
+   */
+  public void valid() throws OMException {
+    if ((tags == null || tags.isEmpty()) && (prefix == null || 
prefix.isEmpty())) {

Review Comment:
   nit: `Strings.isNullOrEmpty(prefix)`



##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmLifecycleRuleAndOperator.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.hadoop.ozone.om.helpers;
+
+import jakarta.annotation.Nonnull;
+import jakarta.annotation.Nullable;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+
+/**
+ * A class that encapsulates lifecycleRule andOperator.
+ */
+public final class OmLifecycleRuleAndOperator {
+
+  private final Map<String, String> tags;
+  private final String prefix;
+
+  private OmLifecycleRuleAndOperator(Map<String, String> tags, String prefix) {
+    this.tags = tags;
+    this.prefix = prefix;
+  }
+
+  @Nonnull
+  public Map<String, String> getTags() {
+    return tags;
+  }
+
+  @Nullable
+  public String getPrefix() {
+    return prefix;
+  }
+
+  /**
+   * Validates the OmLifecycleRuleAndOperator.
+   * Ensures the following:
+   * - Either tags or prefix must be specified.
+   * - If there are tags and no prefix, the tags should be more than one.
+   * - Prefix alone is not allowed.
+   *
+   * @throws OMException if the validation fails.
+   */
+  public void valid() throws OMException {
+    if ((tags == null || tags.isEmpty()) && (prefix == null || 
prefix.isEmpty())) {
+      throw new OMException("Invalid lifecycle rule andOperator configuration: 
" +
+          "Either 'Tags' or 'Prefix' must be specified.",
+          OMException.ResultCodes.INVALID_REQUEST);
+    }
+
+    if (tags != null && !tags.isEmpty()) {
+      if (prefix == null || prefix.isEmpty()) {
+        if (tags.size() == 1) {

Review Comment:
   Better define boolean `isTagPresent` and `isPrefixPresent` and use 
throughout this method.



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