|
@@ -42,6 +42,7 @@ import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_
|
|
|
import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_ROUTER_MONITOR_NAMENODE;
|
|
|
import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_ROUTER_RPC_ADDRESS_KEY;
|
|
|
import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_ROUTER_RPC_BIND_HOST_KEY;
|
|
|
+import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_ROUTER_SAFEMODE_ENABLE;
|
|
|
import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.FEDERATION_FILE_RESOLVER_CLIENT_CLASS;
|
|
|
import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.FEDERATION_NAMENODE_RESOLVER_CLIENT_CLASS;
|
|
|
import static org.junit.Assert.assertEquals;
|
|
@@ -75,6 +76,7 @@ import org.apache.hadoop.hdfs.MiniDFSNNTopology.NNConf;
|
|
|
import org.apache.hadoop.hdfs.MiniDFSNNTopology.NSConf;
|
|
|
import org.apache.hadoop.hdfs.server.federation.resolver.ActiveNamenodeResolver;
|
|
|
import org.apache.hadoop.hdfs.server.federation.resolver.FederationNamenodeServiceState;
|
|
|
+import org.apache.hadoop.hdfs.server.federation.resolver.FederationNamespaceInfo;
|
|
|
import org.apache.hadoop.hdfs.server.federation.resolver.FileSubclusterResolver;
|
|
|
import org.apache.hadoop.hdfs.server.federation.resolver.NamenodeStatusReport;
|
|
|
import org.apache.hadoop.hdfs.server.federation.router.Router;
|
|
@@ -91,15 +93,16 @@ import org.slf4j.LoggerFactory;
|
|
|
/**
|
|
|
* Test utility to mimic a federated HDFS cluster with multiple routers.
|
|
|
*/
|
|
|
-public class RouterDFSCluster {
|
|
|
+public class MiniRouterDFSCluster {
|
|
|
|
|
|
private static final Logger LOG =
|
|
|
- LoggerFactory.getLogger(RouterDFSCluster.class);
|
|
|
+ LoggerFactory.getLogger(MiniRouterDFSCluster.class);
|
|
|
|
|
|
public static final String TEST_STRING = "teststring";
|
|
|
public static final String TEST_DIR = "testdir";
|
|
|
public static final String TEST_FILE = "testfile";
|
|
|
|
|
|
+ private static final Random RND = new Random();
|
|
|
|
|
|
/** Nameservices in the federated cluster. */
|
|
|
private List<String> nameservices;
|
|
@@ -345,7 +348,8 @@ public class RouterDFSCluster {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public RouterDFSCluster(boolean ha, int numNameservices, int numNamenodes,
|
|
|
+ public MiniRouterDFSCluster(
|
|
|
+ boolean ha, int numNameservices, int numNamenodes,
|
|
|
long heartbeatInterval, long cacheFlushInterval) {
|
|
|
this.highAvailability = ha;
|
|
|
this.heartbeatInterval = heartbeatInterval;
|
|
@@ -353,12 +357,13 @@ public class RouterDFSCluster {
|
|
|
configureNameservices(numNameservices, numNamenodes);
|
|
|
}
|
|
|
|
|
|
- public RouterDFSCluster(boolean ha, int numNameservices) {
|
|
|
+ public MiniRouterDFSCluster(boolean ha, int numNameservices) {
|
|
|
this(ha, numNameservices, 2,
|
|
|
DEFAULT_HEARTBEAT_INTERVAL_MS, DEFAULT_CACHE_INTERVAL_MS);
|
|
|
}
|
|
|
|
|
|
- public RouterDFSCluster(boolean ha, int numNameservices, int numNamenodes) {
|
|
|
+ public MiniRouterDFSCluster(
|
|
|
+ boolean ha, int numNameservices, int numNamenodes) {
|
|
|
this(ha, numNameservices, numNamenodes,
|
|
|
DEFAULT_HEARTBEAT_INTERVAL_MS, DEFAULT_CACHE_INTERVAL_MS);
|
|
|
}
|
|
@@ -480,6 +485,9 @@ public class RouterDFSCluster {
|
|
|
conf.setClass(FEDERATION_FILE_RESOLVER_CLIENT_CLASS,
|
|
|
MockResolver.class, FileSubclusterResolver.class);
|
|
|
|
|
|
+ // Disable safemode on startup
|
|
|
+ conf.setBoolean(DFS_ROUTER_SAFEMODE_ENABLE, false);
|
|
|
+
|
|
|
// Set the nameservice ID for the default NN monitor
|
|
|
conf.set(DFS_NAMESERVICE_ID, nsId);
|
|
|
if (nnId != null) {
|
|
@@ -549,8 +557,7 @@ public class RouterDFSCluster {
|
|
|
}
|
|
|
|
|
|
public String getRandomNameservice() {
|
|
|
- Random r = new Random();
|
|
|
- int randIndex = r.nextInt(nameservices.size());
|
|
|
+ int randIndex = RND.nextInt(nameservices.size());
|
|
|
return nameservices.get(randIndex);
|
|
|
}
|
|
|
|
|
@@ -772,6 +779,22 @@ public class RouterDFSCluster {
|
|
|
waitNamenodeRegistered(nnResolver, nsId, nnId, state);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Wait for name spaces to be active.
|
|
|
+ * @throws Exception If we cannot check the status or we timeout.
|
|
|
+ */
|
|
|
+ public void waitActiveNamespaces() throws Exception {
|
|
|
+ for (RouterContext r : this.routers) {
|
|
|
+ Router router = r.router;
|
|
|
+ final ActiveNamenodeResolver resolver = router.getNamenodeResolver();
|
|
|
+ for (FederationNamespaceInfo ns : resolver.getNamespaces()) {
|
|
|
+ final String nsId = ns.getNameserviceId();
|
|
|
+ waitNamenodeRegistered(
|
|
|
+ resolver, nsId, FederationNamenodeServiceState.ACTIVE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Get the federated path for a nameservice.
|
|
|
* @param nsId Nameservice identifier.
|