jojochuang commented on code in PR #5043: URL: https://github.com/apache/ozone/pull/5043#discussion_r1261856958
########## hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/OmUpdateEventValidator.java: ########## @@ -0,0 +1,94 @@ +/* + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.recon.tasks; + +import com.google.common.annotations.VisibleForTesting; +import org.apache.hadoop.ozone.om.codec.OMDBDefinition; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +/** + * OmUpdateEventValidator is a utility class for validating OMDBUpdateEvents + * It can be further extended to different types of validations. + */ +public class OmUpdateEventValidator { + + private static Logger log = + LoggerFactory.getLogger(OmUpdateEventValidator.class); + private OMDBDefinition omdbDefinition; + + public OmUpdateEventValidator(OMDBDefinition omdbDefinition) { + this.omdbDefinition = omdbDefinition; + } + + /** + * Validates the OMDBUpdateEvent based on the expected value type for a + * given table. + * + * @param tableName the name of the table associated with the event. + * @param actualValueType the actual value type of the event. + * @param keyType the key type of the event. + * @param action the action performed on the event. + * @return true if the event is valid, false otherwise. + * @throws IOException if an I/O error occurs during the validation. + */ + public boolean isValidEvent(String tableName, + Object actualValueType, + Object keyType, + OMDBUpdateEvent.OMDBUpdateAction action) + throws IOException { + + String expectedValueTypeString = + omdbDefinition.getColumnFamily(tableName).getValueType().getName(); + String actualValueTypeString = actualValueType.getClass().getName(); + + // Check if both objects are of the same type + if (expectedValueTypeString.equals(actualValueTypeString)) { + // Both objects are of the same type + return true; + } else { + // Objects are not of the same type + logError(keyType.toString(), tableName, action.toString(), Review Comment: ```suggestion logWarn(keyType.toString(), tableName, action.toString(), ``` ########## hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/OmUpdateEventValidator.java: ########## @@ -0,0 +1,94 @@ +/* + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.recon.tasks; + +import com.google.common.annotations.VisibleForTesting; +import org.apache.hadoop.ozone.om.codec.OMDBDefinition; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +/** + * OmUpdateEventValidator is a utility class for validating OMDBUpdateEvents + * It can be further extended to different types of validations. + */ +public class OmUpdateEventValidator { + + private static Logger log = + LoggerFactory.getLogger(OmUpdateEventValidator.class); + private OMDBDefinition omdbDefinition; + + public OmUpdateEventValidator(OMDBDefinition omdbDefinition) { + this.omdbDefinition = omdbDefinition; + } + + /** + * Validates the OMDBUpdateEvent based on the expected value type for a + * given table. + * + * @param tableName the name of the table associated with the event. + * @param actualValueType the actual value type of the event. + * @param keyType the key type of the event. + * @param action the action performed on the event. + * @return true if the event is valid, false otherwise. + * @throws IOException if an I/O error occurs during the validation. + */ + public boolean isValidEvent(String tableName, + Object actualValueType, + Object keyType, + OMDBUpdateEvent.OMDBUpdateAction action) + throws IOException { + + String expectedValueTypeString = + omdbDefinition.getColumnFamily(tableName).getValueType().getName(); + String actualValueTypeString = actualValueType.getClass().getName(); + + // Check if both objects are of the same type + if (expectedValueTypeString.equals(actualValueTypeString)) { + // Both objects are of the same type + return true; + } else { + // Objects are not of the same type + logError(keyType.toString(), tableName, action.toString(), + expectedValueTypeString, + actualValueTypeString); + return false; + } + } + + /** + * Logs an error message indicating a validation failure. + */ + private void logError(String keyType, String tableName, String action, Review Comment: ```suggestion private void logWarn(String keyType, String tableName, String action, ``` -- 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]
