Skip to content

Commit e138423

Browse files
committed
Configure HDFS high availability
1 parent c1e8fe4 commit e138423

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

src/main/java/org/radarcns/hdfs/RestructureAvroRecords.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,26 @@ public static void main(String [] args) {
109109
.doDeduplicate(commandLineArgs.deduplicate).format(commandLineArgs.format)
110110
.doStage(!commandLineArgs.noStage);
111111

112+
// Configure high availability
113+
if (commandLineArgs.hdfsUri1 != null || commandLineArgs.hdfsUri2 != null || commandLineArgs.hdfsHa != null) {
114+
if (commandLineArgs.hdfsUri1 == null || commandLineArgs.hdfsUri2 == null || commandLineArgs.hdfsHa == null) {
115+
logger.error("HDFS High availability name node configuration is incomplete. Configure --namenode-1, --namenode-2 and --namenode-ha");
116+
System.exit(1);
117+
}
118+
119+
String[] haNames = commandLineArgs.hdfsHa.split(",");
120+
if (haNames.length != 2) {
121+
logger.error("Cannot process HDFS High Availability mode for other than two name nodes.");
122+
System.exit(1);
123+
}
124+
125+
builder.putHdfsConfig("dfs.nameservices", commandLineArgs.hdfsUri);
126+
builder.putHdfsConfig("dfs.ha.namenodes." + commandLineArgs.hdfsUri, commandLineArgs.hdfsHa);
127+
builder.putHdfsConfig("dfs.namenode.rpc-address." + commandLineArgs.hdfsUri + "." + haNames[0], commandLineArgs.hdfsUri1);
128+
builder.putHdfsConfig("dfs.namenode.rpc-address." + commandLineArgs.hdfsUri + "." + haNames[1], commandLineArgs.hdfsUri2);
129+
builder.putHdfsConfig("dfs.client.failover.proxy.provider." + commandLineArgs.hdfsUri,"org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider");
130+
}
131+
112132
RestructureAvroRecords restr = builder.build();
113133

114134
try {
@@ -156,7 +176,8 @@ private RestructureAvroRecords(RestructureAvroRecords.Builder builder) {
156176
}
157177

158178
public void setInputWebHdfsURL(String fileSystemURL) {
159-
conf.set("fs.defaultFS", fileSystemURL);
179+
conf.set("fs.defaultFS", "hdfs://" + fileSystemURL);
180+
conf.set("fs.default.name", conf.get("fs.defaultFS"));
160181
}
161182

162183
public void setOutputPath(String path) {

src/main/java/org/radarcns/hdfs/util/commandline/CommandLineArgs.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,18 @@ public class CommandLineArgs {
2020
@Parameter(names = { "-d", "--deduplicate" }, description = "Boolean to define if to use deduplication or not.")
2121
public boolean deduplicate;
2222

23-
@Parameter(names = { "-u", "--hdfs-uri" }, description = "The HDFS uri to connect to. Eg - 'hdfs://<HOST>:<RPC_PORT>/<PATH>'.", required = true, validateWith = { HdfsUriValidator.class, PathValidator.class })
23+
@Parameter(names = { "-n", "--nameservice"}, description = "The HDFS name services to connect to. Eg - '<HOST>' for single configurations or <CLUSTER_ID> for high availability web services.", required = true, validateWith = { PathValidator.class })
2424
public String hdfsUri;
2525

26+
@Parameter(names = { "--namenode-1" }, description = "High availability HDFS name node to also connect to. Eg - '<HOST>:<RPC_PORT>'.", validateWith = { PathValidator.class })
27+
public String hdfsUri1;
28+
29+
@Parameter(names = { "--namenode-2" }, description = "High availability HDFS name node to also connect to. Eg - '<HOST>:<RPC_PORT>'.", validateWith = { PathValidator.class })
30+
public String hdfsUri2;
31+
32+
@Parameter(names = { "--namenode-ha"}, description = "High availability HDFS name node names. Eg - 'nn1,nn2'.", validateWith = { PathValidator.class })
33+
public String hdfsHa;
34+
2635
@Parameter(names = { "-o", "--output-directory"}, description = "The output folder where the files are to be extracted.", required = true, validateWith = PathValidator.class)
2736
public String outputDirectory;
2837

src/main/java/org/radarcns/hdfs/util/commandline/HdfsUriValidator.java

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)