|
@@ -33,10 +33,15 @@ import java.io.PrintStream;
|
|
|
import java.net.InetSocketAddress;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.StringTokenizer;
|
|
|
|
|
|
+import org.apache.hadoop.fs.FSDataOutputStream;
|
|
|
+import org.apache.hadoop.fs.FileSystem;
|
|
|
+import org.apache.hadoop.fs.Path;
|
|
|
+import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
|
import org.apache.hadoop.hdfs.DFSUtil;
|
|
|
import org.apache.hadoop.hdfs.DFSUtil.ConfiguredNNAddress;
|
|
|
import org.apache.hadoop.hdfs.HdfsConfiguration;
|
|
@@ -55,7 +60,7 @@ public class TestGetConf {
|
|
|
enum TestType {
|
|
|
NAMENODE, BACKUP, SECONDARY, NNRPCADDRESSES
|
|
|
}
|
|
|
-
|
|
|
+ FileSystem localFileSys;
|
|
|
/** Setup federation nameServiceIds in the configuration */
|
|
|
private void setupNameServices(HdfsConfiguration conf, int nameServiceIdCount) {
|
|
|
StringBuilder nsList = new StringBuilder();
|
|
@@ -379,4 +384,70 @@ public class TestGetConf {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ @Test
|
|
|
+ public void TestGetConfExcludeCommand() throws Exception{
|
|
|
+ HdfsConfiguration conf = new HdfsConfiguration();
|
|
|
+ // Set up the hosts/exclude files.
|
|
|
+ localFileSys = FileSystem.getLocal(conf);
|
|
|
+ Path workingDir = localFileSys.getWorkingDirectory();
|
|
|
+ Path dir = new Path(workingDir, System.getProperty("test.build.data", "target/test/data") + "/Getconf/");
|
|
|
+ Path hostsFile = new Path(dir, "hosts");
|
|
|
+ Path excludeFile = new Path(dir, "exclude");
|
|
|
+
|
|
|
+ // Setup conf
|
|
|
+ conf.set(DFSConfigKeys.DFS_HOSTS, hostsFile.toUri().getPath());
|
|
|
+ conf.set(DFSConfigKeys.DFS_HOSTS_EXCLUDE, excludeFile.toUri().getPath());
|
|
|
+ writeConfigFile(hostsFile, null);
|
|
|
+ writeConfigFile(excludeFile, null);
|
|
|
+ String[] args = {"-excludeFile"};
|
|
|
+ String ret = runTool(conf, args, true);
|
|
|
+ assertEquals(excludeFile.toUri().getPath(),ret.trim());
|
|
|
+ cleanupFile(localFileSys, excludeFile.getParent());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void TestGetConfIncludeCommand() throws Exception{
|
|
|
+ HdfsConfiguration conf = new HdfsConfiguration();
|
|
|
+ // Set up the hosts/exclude files.
|
|
|
+ localFileSys = FileSystem.getLocal(conf);
|
|
|
+ Path workingDir = localFileSys.getWorkingDirectory();
|
|
|
+ Path dir = new Path(workingDir, System.getProperty("test.build.data", "target/test/data") + "/Getconf/");
|
|
|
+ Path hostsFile = new Path(dir, "hosts");
|
|
|
+ Path excludeFile = new Path(dir, "exclude");
|
|
|
+
|
|
|
+ // Setup conf
|
|
|
+ conf.set(DFSConfigKeys.DFS_HOSTS, hostsFile.toUri().getPath());
|
|
|
+ conf.set(DFSConfigKeys.DFS_HOSTS_EXCLUDE, excludeFile.toUri().getPath());
|
|
|
+ writeConfigFile(hostsFile, null);
|
|
|
+ writeConfigFile(excludeFile, null);
|
|
|
+ String[] args = {"-includeFile"};
|
|
|
+ String ret = runTool(conf, args, true);
|
|
|
+ assertEquals(hostsFile.toUri().getPath(),ret.trim());
|
|
|
+ cleanupFile(localFileSys, excludeFile.getParent());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void writeConfigFile(Path name, ArrayList<String> nodes)
|
|
|
+ throws IOException {
|
|
|
+ // delete if it already exists
|
|
|
+ if (localFileSys.exists(name)) {
|
|
|
+ localFileSys.delete(name, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ FSDataOutputStream stm = localFileSys.create(name);
|
|
|
+
|
|
|
+ if (nodes != null) {
|
|
|
+ for (Iterator<String> it = nodes.iterator(); it.hasNext();) {
|
|
|
+ String node = it.next();
|
|
|
+ stm.writeBytes(node);
|
|
|
+ stm.writeBytes("\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ stm.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void cleanupFile(FileSystem fileSys, Path name) throws IOException {
|
|
|
+ assertTrue(fileSys.exists(name));
|
|
|
+ fileSys.delete(name, true);
|
|
|
+ assertTrue(!fileSys.exists(name));
|
|
|
+ }
|
|
|
}
|