xichen01 commented on code in PR #8275: URL: https://github.com/apache/ozone/pull/8275#discussion_r2058890062
########## hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestOmLCFilter.java: ########## @@ -0,0 +1,84 @@ +/* + * 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.VALID_OM_LC_AND_OPERATOR; +import static org.apache.hadoop.ozone.om.helpers.OMLCUtils.VALID_OM_LC_FILTER; +import static org.apache.hadoop.ozone.om.helpers.OMLCUtils.assertOMException; +import static org.apache.hadoop.ozone.om.helpers.OMLCUtils.getOmLCFilterBuilder; +import static org.apache.hadoop.ozone.om.helpers.OMLCUtils.getOmLCRuleBuilder; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import org.apache.commons.lang3.tuple.Pair; +import org.apache.hadoop.ozone.om.exceptions.OMException; +import org.junit.jupiter.api.Test; + +/** + * Test OmLCExpiration. + */ +class TestOmLCFilter { + + @Test + public void testInValidOmLCRulePrefixFilterCoExist() throws OMException { + OmLCRule.Builder rule1 = getOmLCRuleBuilder("id", "prefix", true, 1, VALID_OM_LC_FILTER); + assertOMException(rule1::build, INVALID_REQUEST, "Filter and Prefix cannot be used together"); + + OmLCRule.Builder rule2 = getOmLCRuleBuilder("id", "", true, 1, VALID_OM_LC_FILTER); + assertOMException(rule2::build, INVALID_REQUEST, "Filter and Prefix cannot be used together"); + } + + @Test + public void testValidFilter() throws OMException { + OmLCFilter lcFilter1 = getOmLCFilterBuilder("prefix", null, null).build(); + assertDoesNotThrow(lcFilter1::valid); + + OmLCFilter lcFilter2 = getOmLCFilterBuilder(null, Pair.of("key", "value"), null).build(); + assertDoesNotThrow(lcFilter2::valid); + + OmLCFilter lcFilter3 = getOmLCFilterBuilder(null, null, VALID_OM_LC_AND_OPERATOR).build(); + assertDoesNotThrow(lcFilter3::valid); + + OmLCFilter lcFilter4 = getOmLCFilterBuilder(null, null, null).build(); + assertDoesNotThrow(lcFilter4::valid); Review Comment: Yes, This is valid, add a comment for this ########## hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmLCExpiration.java: ########## @@ -0,0 +1,139 @@ +/* + * 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.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; +import net.jcip.annotations.Immutable; +import org.apache.hadoop.ozone.om.exceptions.OMException; + +/** + * A class that encapsulates lifecycle rule expiration action. + * This class extends OmLCAction and represents the expiration + * action type in lifecycle configuration. + */ +@Immutable +public final class OmLCExpiration implements OmLCAction { + private final int days; + private final String date; + + private OmLCExpiration() { + throw new UnsupportedOperationException("Default constructor is not supported. Use Builder."); + } + + private OmLCExpiration(Builder builder) { + this.days = builder.days; + this.date = builder.date; + } + + public int getDays() { + return days; + } + + public String getDate() { + return date; + } + + @Override + public ActionType getActionType() { + return ActionType.EXPIRATION; + } + + /** + * Validates the expiration configuration. + * - Days must be a positive number greater than zero + * - Either days or date should be specified, but not both or neither + * - The date value must conform to the ISO 8601 format + * - The date value must be in the future + * - The date value must be at midnight UTC (00:00:00Z) + * Review Comment: Added. -- 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: issues-unsubscr...@ozone.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org For additional commands, e-mail: issues-h...@ozone.apache.org