HDFS-14191. RBF: Remove hard coded router status from FederationMetrics. Contributed by Ranith Sardar.

This commit is contained in:
Surendra Singh Lilhore 2019-01-10 16:18:23 +05:30 committed by Brahma Reddy Battula
parent 4244653e43
commit b8bcbd0ed2
5 changed files with 65 additions and 4 deletions

View File

@ -582,7 +582,7 @@ public class FederationMetrics implements FederationMBean {
@Override @Override
public String getRouterStatus() { public String getRouterStatus() {
return "RUNNING"; return this.router.getRouterState().toString();
} }
/** /**

View File

@ -45,6 +45,7 @@ import org.apache.hadoop.hdfs.server.federation.resolver.FederationNamespaceInfo
import org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys; import org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys;
import org.apache.hadoop.hdfs.server.federation.router.Router; import org.apache.hadoop.hdfs.server.federation.router.Router;
import org.apache.hadoop.hdfs.server.federation.router.RouterRpcServer; import org.apache.hadoop.hdfs.server.federation.router.RouterRpcServer;
import org.apache.hadoop.hdfs.server.federation.router.RouterServiceState;
import org.apache.hadoop.hdfs.server.federation.router.SubClusterTimeoutException; import org.apache.hadoop.hdfs.server.federation.router.SubClusterTimeoutException;
import org.apache.hadoop.hdfs.server.federation.store.MembershipStore; import org.apache.hadoop.hdfs.server.federation.store.MembershipStore;
import org.apache.hadoop.hdfs.server.federation.store.StateStoreService; import org.apache.hadoop.hdfs.server.federation.store.StateStoreService;
@ -232,7 +233,29 @@ public class NamenodeBeanMetrics
@Override @Override
public String getSafemode() { public String getSafemode() {
// We assume that the global federated view is never in safe mode try {
if (!getRouter().isRouterState(RouterServiceState.SAFEMODE)) {
return "Safe mode is ON. " + this.getSafeModeTip();
}
} catch (IOException e) {
return "Failed to get safemode status. Please check router"
+ "log for more detail.";
}
return "";
}
private String getSafeModeTip() throws IOException {
Router rt = getRouter();
String cmd = "Use \"hdfs dfsrouteradmin -safemode leave\" "
+ "to turn safe mode off.";
if (rt.isRouterState(RouterServiceState.INITIALIZING)
|| rt.isRouterState(RouterServiceState.UNINITIALIZED)) {
return "Router is in" + rt.getRouterState()
+ "mode, the router will immediately return to "
+ "normal mode after some time. " + cmd;
} else if (rt.isRouterState(RouterServiceState.SAFEMODE)) {
return "It was turned on manually. " + cmd;
}
return ""; return "";
} }

View File

@ -585,6 +585,13 @@ public class Router extends CompositeService {
return this.state; return this.state;
} }
/**
* Compare router state.
*/
public boolean isRouterState(RouterServiceState routerState) {
return routerState.equals(this.state);
}
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
// Submodule getters // Submodule getters
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////

View File

@ -35,7 +35,7 @@
var BEANS = [ var BEANS = [
{"name": "federation", "url": "/jmx?qry=Hadoop:service=Router,name=FederationState"}, {"name": "federation", "url": "/jmx?qry=Hadoop:service=Router,name=FederationState"},
{"name": "routerstat", "url": "/jmx?qry=Hadoop:service=NameNode,name=NameNodeStatus"}, {"name": "routerstat", "url": "/jmx?qry=Hadoop:service=NameNode,name=NameNodeStatus"},
{"name": "router", "url": "/jmx?qrt=Hadoop:service=NameNode,name=NameNodeInfo"}, {"name": "router", "url": "/jmx?qry=Hadoop:service=NameNode,name=NameNodeInfo"},
{"name": "mem", "url": "/jmx?qry=java.lang:type=Memory"} {"name": "mem", "url": "/jmx?qry=java.lang:type=Memory"}
]; ];

View File

@ -33,6 +33,7 @@ import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.hdfs.server.federation.MiniRouterDFSCluster.RouterContext; import org.apache.hadoop.hdfs.server.federation.MiniRouterDFSCluster.RouterContext;
import org.apache.hadoop.hdfs.server.federation.RouterConfigBuilder; import org.apache.hadoop.hdfs.server.federation.RouterConfigBuilder;
import org.apache.hadoop.hdfs.server.federation.StateStoreDFSCluster; import org.apache.hadoop.hdfs.server.federation.StateStoreDFSCluster;
import org.apache.hadoop.hdfs.server.federation.metrics.FederationMetrics;
import org.apache.hadoop.hdfs.server.federation.resolver.ActiveNamenodeResolver; import org.apache.hadoop.hdfs.server.federation.resolver.ActiveNamenodeResolver;
import org.apache.hadoop.hdfs.server.federation.resolver.MountTableManager; import org.apache.hadoop.hdfs.server.federation.resolver.MountTableManager;
import org.apache.hadoop.hdfs.server.federation.resolver.RemoteLocation; import org.apache.hadoop.hdfs.server.federation.resolver.RemoteLocation;
@ -66,6 +67,7 @@ public class TestRouterAdminCLI {
private static RouterAdmin admin; private static RouterAdmin admin;
private static RouterClient client; private static RouterClient client;
private static Router router;
private static final String TEST_USER = "test-user"; private static final String TEST_USER = "test-user";
@ -80,6 +82,7 @@ public class TestRouterAdminCLI {
// Build and start a router with State Store + admin + RPC // Build and start a router with State Store + admin + RPC
Configuration conf = new RouterConfigBuilder() Configuration conf = new RouterConfigBuilder()
.stateStore() .stateStore()
.metrics()
.admin() .admin()
.rpc() .rpc()
.safemode() .safemode()
@ -90,7 +93,7 @@ public class TestRouterAdminCLI {
cluster.startRouters(); cluster.startRouters();
routerContext = cluster.getRandomRouter(); routerContext = cluster.getRandomRouter();
Router router = routerContext.getRouter(); router = routerContext.getRouter();
stateStore = router.getStateStore(); stateStore = router.getStateStore();
Configuration routerConf = new Configuration(); Configuration routerConf = new Configuration();
@ -720,6 +723,34 @@ public class TestRouterAdminCLI {
err.reset(); err.reset();
} }
@Test
public void testSafeModeStatus() throws Exception {
// ensure the Router become RUNNING state
waitState(RouterServiceState.RUNNING);
assertFalse(routerContext.getRouter().getSafemodeService().isInSafeMode());
assertEquals(0,
ToolRunner.run(admin, new String[] {"-safemode", "enter" }));
FederationMetrics metrics = router.getMetrics();
String jsonString = metrics.getRouterStatus();
// verify state using FederationMetrics
assertEquals(RouterServiceState.SAFEMODE.toString(), jsonString);
assertTrue(routerContext.getRouter().getSafemodeService().isInSafeMode());
System.setOut(new PrintStream(out));
assertEquals(0,
ToolRunner.run(admin, new String[] {"-safemode", "leave" }));
jsonString = metrics.getRouterStatus();
// verify state
assertEquals(RouterServiceState.RUNNING.toString(), jsonString);
assertFalse(routerContext.getRouter().getSafemodeService().isInSafeMode());
out.reset();
assertEquals(0, ToolRunner.run(admin, new String[] {"-safemode", "get" }));
assertTrue(out.toString().contains("false"));
}
@Test @Test
public void testCreateInvalidEntry() throws Exception { public void testCreateInvalidEntry() throws Exception {
String[] argv = new String[] { String[] argv = new String[] {