Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improve][Connector-V2][HDFS] Support setting hdfs-site.xml #3778

Merged
merged 1 commit into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.seatunnel.common.constants.PluginType;
import org.apache.seatunnel.connectors.seatunnel.file.config.HadoopConf;
import org.apache.seatunnel.connectors.seatunnel.file.exception.FileConnectorException;
import org.apache.seatunnel.connectors.seatunnel.file.hdfs.source.config.HdfsSourceConfig;
import org.apache.seatunnel.connectors.seatunnel.file.sink.BaseFileSink;

import org.apache.seatunnel.shade.com.typesafe.config.Config;
Expand All @@ -42,5 +43,8 @@ public void prepare(Config pluginConfig) throws PrepareFailException {
}
super.prepare(pluginConfig);
hadoopConf = new HadoopConf(pluginConfig.getString(FS_DEFAULT_NAME_KEY));
if (pluginConfig.hasPath(HdfsSourceConfig.HDFS_SITE_PATH.key())) {
hadoopConf.setHdfsSitePath(pluginConfig.getString(HdfsSourceConfig.HDFS_SITE_PATH.key()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public void prepare(Config pluginConfig) throws PrepareFailException {
readStrategy.setPluginConfig(pluginConfig);
String path = pluginConfig.getString(HdfsSourceConfig.FILE_PATH.key());
hadoopConf = new HadoopConf(pluginConfig.getString(HdfsSourceConfig.DEFAULT_FS.key()));
if (pluginConfig.hasPath(HdfsSourceConfig.HDFS_SITE_PATH.key())) {
hadoopConf.setHdfsSitePath(pluginConfig.getString(HdfsSourceConfig.HDFS_SITE_PATH.key()));
}
try {
filePaths = readStrategy.getFileNamesByPath(hadoopConf, path);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,8 @@ public class BaseSinkConfig {
.intType()
.defaultValue(DEFAULT_BATCH_SIZE)
.withDescription("The batch size of each split file");
public static final Option<String> HDFS_SITE_PATH = Options.key("hdfs_site_path")
.stringType()
.noDefaultValue()
.withDescription("The path of hdfs-site.xml");
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,8 @@ public class BaseSourceConfig {
.booleanType()
.defaultValue(true)
.withDescription("Whether parse partition fields from file path");
public static final Option<String> HDFS_SITE_PATH = Options.key("hdfs_site_path")
.stringType()
.noDefaultValue()
.withDescription("The path of hdfs-site.xml");
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import lombok.Data;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;

import java.io.Serializable;
import java.util.HashMap;
Expand All @@ -30,6 +31,7 @@ public class HadoopConf implements Serializable {
private static final String SCHEMA = "hdfs";
protected Map<String, String> extraOptions = new HashMap<>();
protected String hdfsNameKey;
protected String hdfsSitePath;

public HadoopConf(String hdfsNameKey) {
this.hdfsNameKey = hdfsNameKey;
Expand All @@ -47,5 +49,8 @@ public void setExtraOptionsForConfiguration(Configuration configuration) {
if (!extraOptions.isEmpty()) {
extraOptions.forEach(configuration::set);
}
if (hdfsSitePath != null) {
configuration.addResource(new Path(hdfsSitePath));
}
}
}