pratyakshsharma commented on a change in pull request #1150: [HUDI-288]: Add support for ingesting multiple kafka streams in a single DeltaStreamer deployment URL: https://github.com/apache/incubator-hudi/pull/1150#discussion_r399519630
########## File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/deltastreamer/HoodieMultiTableDeltaStreamer.java ########## @@ -0,0 +1,259 @@ +/* + * 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.hudi.utilities.deltastreamer; + +import org.apache.hadoop.fs.FileUtil; +import org.apache.hudi.DataSourceWriteOptions; +import org.apache.hudi.common.util.FSUtils; +import org.apache.hudi.common.util.TypedProperties; +import org.apache.hudi.exception.HoodieException; +import org.apache.hudi.utilities.UtilHelpers; +import org.apache.hudi.utilities.deltastreamer.HoodieDeltaStreamer.Config; +import org.apache.hudi.utilities.schema.SchemaRegistryProvider; + +import com.beust.jcommander.JCommander; +import com.google.common.base.Strings; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; +import org.apache.spark.api.java.JavaSparkContext; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * Wrapper over HoodieDeltaStreamer.java class. + * Helps with ingesting incremental data into hoodie datasets for multiple tables. + * Currently supports only COPY_ON_WRITE storage type. + */ +public class HoodieMultiTableDeltaStreamer { + + private static Logger logger = LogManager.getLogger(HoodieMultiTableDeltaStreamer.class); + + private List<TableExecutionObject> tableExecutionObjects; + private transient JavaSparkContext jssc; + private Set<String> successTables; + private Set<String> failedTables; + + public HoodieMultiTableDeltaStreamer(String[] args, JavaSparkContext jssc) throws IOException { + this.tableExecutionObjects = new ArrayList<>(); + this.successTables = new HashSet<>(); + this.failedTables = new HashSet<>(); + this.jssc = jssc; + String commonPropsFile = getCommonPropsFileName(args); + String configFolder = getConfigFolder(args); + FileSystem fs = FSUtils.getFs(commonPropsFile, jssc.hadoopConfiguration()); + configFolder = configFolder.charAt(configFolder.length() - 1) == '/' ? configFolder.substring(0, configFolder.length() - 1) : configFolder; + checkIfPropsFileAndConfigFolderExist(commonPropsFile, configFolder, fs); + TypedProperties properties = UtilHelpers.readConfig(fs, new Path(commonPropsFile), new ArrayList<>()).getConfig(); + //get the tables to be ingested and their corresponding config files from this properties instance + populateTableExecutionObjectList(properties, configFolder, fs, args); + } + + private void checkIfPropsFileAndConfigFolderExist(String commonPropsFile, String configFolder, FileSystem fs) throws IOException { + if (!fs.exists(new Path(commonPropsFile))) { + throw new IllegalArgumentException("Please provide valid common config file path!"); + } + + if (!fs.exists(new Path(configFolder))) { + fs.mkdirs(new Path(configFolder)); + } + } + + private void checkIfTableConfigFileExists(String configFolder, FileSystem fs, String configFilePath) throws IOException { + if (!fs.exists(new Path(configFilePath)) || !fs.isFile(new Path(configFilePath))) { + throw new IllegalArgumentException("Please provide valid table config file path!"); + } + + Path path = new Path(configFilePath); + Path filePathInConfigFolder = new Path(configFolder, path.getName()); + if (!fs.exists(filePathInConfigFolder)) { + FileUtil.copy(fs, path, fs, filePathInConfigFolder, false, fs.getConf()); + } + } + + //commonProps are passed as parameter which contain table to config file mapping + private void populateTableExecutionObjectList(TypedProperties properties, String configFolder, FileSystem fs, String[] args) throws IOException { + List<String> tablesToBeIngested = getTablesToBeIngested(properties); Review comment: Done ---------------------------------------------------------------- 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 With regards, Apache Git Services