|
@@ -25,6 +25,8 @@ import static org.junit.Assert.*;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.net.InetSocketAddress;
|
|
import java.net.InetSocketAddress;
|
|
|
|
+import java.net.URI;
|
|
|
|
+import java.net.URISyntaxException;
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
import java.util.Iterator;
|
|
import java.util.Iterator;
|
|
@@ -41,6 +43,8 @@ import org.apache.hadoop.net.NetUtils;
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.fs.BlockLocation;
|
|
import org.apache.hadoop.fs.BlockLocation;
|
|
|
|
+import org.apache.hadoop.fs.CommonConfigurationKeys;
|
|
|
|
+
|
|
import static org.apache.hadoop.hdfs.DFSConfigKeys.*;
|
|
import static org.apache.hadoop.hdfs.DFSConfigKeys.*;
|
|
|
|
|
|
public class TestDFSUtil {
|
|
public class TestDFSUtil {
|
|
@@ -233,11 +237,12 @@ public class TestDFSUtil {
|
|
* {@link DFSUtil#isDefaultNamenodeAddress(Configuration, InetSocketAddress, String...)}
|
|
* {@link DFSUtil#isDefaultNamenodeAddress(Configuration, InetSocketAddress, String...)}
|
|
*/
|
|
*/
|
|
@Test
|
|
@Test
|
|
- public void testSingleNamenode() {
|
|
|
|
|
|
+ public void testSingleNamenode() throws URISyntaxException {
|
|
HdfsConfiguration conf = new HdfsConfiguration();
|
|
HdfsConfiguration conf = new HdfsConfiguration();
|
|
final String DEFAULT_ADDRESS = "localhost:9000";
|
|
final String DEFAULT_ADDRESS = "localhost:9000";
|
|
final String NN2_ADDRESS = "localhost:9001";
|
|
final String NN2_ADDRESS = "localhost:9001";
|
|
conf.set(DFS_NAMENODE_RPC_ADDRESS_KEY, DEFAULT_ADDRESS);
|
|
conf.set(DFS_NAMENODE_RPC_ADDRESS_KEY, DEFAULT_ADDRESS);
|
|
|
|
+ conf.set(CommonConfigurationKeys.FS_DEFAULT_NAME_KEY, DEFAULT_ADDRESS);
|
|
|
|
|
|
InetSocketAddress testAddress1 = NetUtils.createSocketAddr(DEFAULT_ADDRESS);
|
|
InetSocketAddress testAddress1 = NetUtils.createSocketAddr(DEFAULT_ADDRESS);
|
|
boolean isDefault = DFSUtil.isDefaultNamenodeAddress(conf, testAddress1,
|
|
boolean isDefault = DFSUtil.isDefaultNamenodeAddress(conf, testAddress1,
|
|
@@ -247,6 +252,10 @@ public class TestDFSUtil {
|
|
isDefault = DFSUtil.isDefaultNamenodeAddress(conf, testAddress2,
|
|
isDefault = DFSUtil.isDefaultNamenodeAddress(conf, testAddress2,
|
|
DFS_NAMENODE_SERVICE_RPC_ADDRESS_KEY, DFS_NAMENODE_RPC_ADDRESS_KEY);
|
|
DFS_NAMENODE_SERVICE_RPC_ADDRESS_KEY, DFS_NAMENODE_RPC_ADDRESS_KEY);
|
|
assertFalse(isDefault);
|
|
assertFalse(isDefault);
|
|
|
|
+
|
|
|
|
+ Collection<URI> uris = DFSUtil.getNameServiceUris(conf, DFS_NAMENODE_RPC_ADDRESS_KEY);
|
|
|
|
+ assertEquals(1, uris.size());
|
|
|
|
+ assertTrue(uris.contains(new URI("hdfs://" + DEFAULT_ADDRESS)));
|
|
}
|
|
}
|
|
|
|
|
|
/** Tests to ensure default namenode is used as fallback */
|
|
/** Tests to ensure default namenode is used as fallback */
|
|
@@ -407,13 +416,14 @@ public class TestDFSUtil {
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
- public void testHANameNodesWithFederation() {
|
|
|
|
|
|
+ public void testHANameNodesWithFederation() throws URISyntaxException {
|
|
HdfsConfiguration conf = new HdfsConfiguration();
|
|
HdfsConfiguration conf = new HdfsConfiguration();
|
|
|
|
|
|
final String NS1_NN1_HOST = "ns1-nn1.example.com:8020";
|
|
final String NS1_NN1_HOST = "ns1-nn1.example.com:8020";
|
|
final String NS1_NN2_HOST = "ns1-nn2.example.com:8020";
|
|
final String NS1_NN2_HOST = "ns1-nn2.example.com:8020";
|
|
final String NS2_NN1_HOST = "ns2-nn1.example.com:8020";
|
|
final String NS2_NN1_HOST = "ns2-nn1.example.com:8020";
|
|
final String NS2_NN2_HOST = "ns2-nn2.example.com:8020";
|
|
final String NS2_NN2_HOST = "ns2-nn2.example.com:8020";
|
|
|
|
+ conf.set(CommonConfigurationKeys.FS_DEFAULT_NAME_KEY, "hdfs://ns1");
|
|
|
|
|
|
// Two nameservices, each with two NNs.
|
|
// Two nameservices, each with two NNs.
|
|
conf.set(DFS_FEDERATION_NAMESERVICES, "ns1,ns2");
|
|
conf.set(DFS_FEDERATION_NAMESERVICES, "ns1,ns2");
|
|
@@ -460,6 +470,11 @@ public class TestDFSUtil {
|
|
// Ditto for nameservice IDs, if multiple are defined
|
|
// Ditto for nameservice IDs, if multiple are defined
|
|
assertEquals(null, DFSUtil.getNamenodeNameServiceId(conf));
|
|
assertEquals(null, DFSUtil.getNamenodeNameServiceId(conf));
|
|
assertEquals(null, DFSUtil.getSecondaryNameServiceId(conf));
|
|
assertEquals(null, DFSUtil.getSecondaryNameServiceId(conf));
|
|
|
|
+
|
|
|
|
+ Collection<URI> uris = DFSUtil.getNameServiceUris(conf, DFS_NAMENODE_RPC_ADDRESS_KEY);
|
|
|
|
+ assertEquals(2, uris.size());
|
|
|
|
+ assertTrue(uris.contains(new URI("hdfs://ns1")));
|
|
|
|
+ assertTrue(uris.contains(new URI("hdfs://ns2")));
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -509,4 +524,34 @@ public class TestDFSUtil {
|
|
assertEquals("127.0.0.1:12345",
|
|
assertEquals("127.0.0.1:12345",
|
|
DFSUtil.substituteForWildcardAddress("127.0.0.1:12345", "foo"));
|
|
DFSUtil.substituteForWildcardAddress("127.0.0.1:12345", "foo"));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testGetNNUris() throws Exception {
|
|
|
|
+ HdfsConfiguration conf = new HdfsConfiguration();
|
|
|
|
+
|
|
|
|
+ final String NS1_NN1_HOST = "ns1-nn1.example.com:8020";
|
|
|
|
+ final String NS1_NN2_HOST = "ns1-nn1.example.com:8020";
|
|
|
|
+ final String NS2_NN_HOST = "ns2-nn.example.com:8020";
|
|
|
|
+ final String NN_HOST = "nn.example.com:8020";
|
|
|
|
+
|
|
|
|
+ conf.set(DFS_FEDERATION_NAMESERVICES, "ns1,ns2");
|
|
|
|
+ conf.set(DFSUtil.addKeySuffixes(DFS_HA_NAMENODES_KEY_PREFIX, "ns1"),"nn1,nn2");
|
|
|
|
+ conf.set(DFSUtil.addKeySuffixes(
|
|
|
|
+ DFS_NAMENODE_RPC_ADDRESS_KEY, "ns1", "nn1"), NS1_NN1_HOST);
|
|
|
|
+ conf.set(DFSUtil.addKeySuffixes(
|
|
|
|
+ DFS_NAMENODE_RPC_ADDRESS_KEY, "ns1", "nn2"), NS1_NN2_HOST);
|
|
|
|
+
|
|
|
|
+ conf.set(DFSUtil.addKeySuffixes(DFS_NAMENODE_SERVICE_RPC_ADDRESS_KEY, "ns2"),
|
|
|
|
+ NS2_NN_HOST);
|
|
|
|
+
|
|
|
|
+ conf.set(DFS_NAMENODE_RPC_ADDRESS_KEY, "hdfs://" + NN_HOST);
|
|
|
|
+
|
|
|
|
+ Collection<URI> uris = DFSUtil.getNameServiceUris(conf, DFS_NAMENODE_RPC_ADDRESS_KEY,
|
|
|
|
+ DFS_NAMENODE_SERVICE_RPC_ADDRESS_KEY);
|
|
|
|
+
|
|
|
|
+ assertEquals(3, uris.size());
|
|
|
|
+ assertTrue(uris.contains(new URI("hdfs://ns1")));
|
|
|
|
+ assertTrue(uris.contains(new URI("hdfs://" + NS2_NN_HOST)));
|
|
|
|
+ assertTrue(uris.contains(new URI("hdfs://" + NN_HOST)));
|
|
|
|
+ }
|
|
}
|
|
}
|