public static void main(String[] argv) throws Exception { int res = ToolRunner.run(new DFSHAAdmin(), argv); System.exit(res); } }
@Override public void setConf(Configuration conf) { this.conf = DFSHAAdmin.addSecurityConfiguration(conf); }
/** * Try to map the given namenode ID to its service address. */ @Override protected HAServiceTarget resolveTarget(String nnId) { HdfsConfiguration conf = (HdfsConfiguration)getConf(); return new NNHAServiceTarget(conf, nameserviceId, nnId); }
@Test(timeout=30000) public void testManualFailoverWithDFSHAAdmin() throws Exception { DFSHAAdmin tool = new DFSHAAdmin(); tool.setConf(conf); assertEquals(0, tool.run(new String[]{"-failover", "nn1", "nn2"})); waitForHAState(0, HAServiceState.STANDBY); waitForHAState(1, HAServiceState.ACTIVE); assertEquals(0, tool.run(new String[]{"-failover", "nn2", "nn1"})); waitForHAState(0, HAServiceState.ACTIVE); waitForHAState(1, HAServiceState.STANDBY); }
@Before public void setup() throws IOException { conf = new Configuration(); cluster = new MiniDFSCluster.Builder(conf) .nnTopology(MiniDFSNNTopology.simpleHATopology()).numDataNodes(0) .build(); tool = new DFSHAAdmin(); tool.setConf(conf); tool.setErrOut(new PrintStream(errOutBytes)); cluster.waitActive(); nn1Port = cluster.getNameNodePort(0); }
@Override protected int runCmd(String[] argv) throws Exception { if (argv.length < 1) { printUsage(errOut); return -1; } int i = 0; String cmd = argv[i++]; if ("-ns".equals(cmd)) { if (i == argv.length) { errOut.println("Missing nameservice ID"); printUsage(errOut); return -1; } nameserviceId = argv[i++]; if (i >= argv.length) { errOut.println("Missing command"); printUsage(errOut); return -1; } argv = Arrays.copyOfRange(argv, i, argv.length); } return super.runCmd(argv); }
@Before public void setup() throws IOException { mockProtocol = MockitoUtil.mockProtocol(HAServiceProtocol.class); mockZkfcProtocol = MockitoUtil.mockProtocol(ZKFCProtocol.class); tool = new DFSHAAdmin() { @Override protected HAServiceTarget resolveTarget(String nnId) { HAServiceTarget target = super.resolveTarget(nnId); HAServiceTarget spy = Mockito.spy(target); // OVerride the target to return our mock protocol try { Mockito.doReturn(mockProtocol).when(spy).getProxy( Mockito.<Configuration>any(), Mockito.anyInt()); Mockito.doReturn(mockZkfcProtocol).when(spy).getZKFCProxy( Mockito.<Configuration>any(), Mockito.anyInt()); } catch (IOException e) { throw new AssertionError(e); // mock setup doesn't really throw } return spy; } }; tool.setConf(getHAConf()); tool.setErrOut(new PrintStream(errOutBytes)); tool.setOut(new PrintStream(outBytes)); }
@Test public void testFailoverWithFenceAndBadFencer() throws Exception { Mockito.doReturn(STANDBY_READY_RESULT).when(mockProtocol).getServiceStatus(); HdfsConfiguration conf = getHAConf(); conf.set(DFSConfigKeys.DFS_HA_FENCE_METHODS_KEY, "foobar!"); tool.setConf(conf); assertEquals(-1, runTool("-failover", "nn1", "nn2", "--forcefence")); }
private Object runTool(String ... args) throws Exception { errOutBytes.reset(); outBytes.reset(); LOG.info("Running: DFSHAAdmin " + Joiner.on(" ").join(args)); int ret = tool.run(args); errOutput = new String(errOutBytes.toByteArray(), Charsets.UTF_8); output = new String(outBytes.toByteArray(), Charsets.UTF_8); LOG.info("Err_output:\n" + errOutput + "\nOutput:\n" + output); return ret; }
@Override protected HAServiceTarget resolveTarget(String nnId) { HAServiceTarget target = super.resolveTarget(nnId); HAServiceTarget spy = Mockito.spy(target); // OVerride the target to return our mock protocol try { Mockito.doReturn(mockProtocol).when(spy).getProxy( Mockito.<Configuration>any(), Mockito.anyInt()); Mockito.doReturn(mockZkfcProtocol).when(spy).getZKFCProxy( Mockito.<Configuration>any(), Mockito.anyInt()); } catch (IOException e) { throw new AssertionError(e); // mock setup doesn't really throw } return spy; } };
@Override protected int runCmd(String[] argv) throws Exception { if (argv.length < 1) { printUsage(errOut); return -1; } int i = 0; String cmd = argv[i++]; if ("-ns".equals(cmd)) { if (i == argv.length) { errOut.println("Missing nameservice ID"); printUsage(errOut); return -1; } nameserviceId = argv[i++]; if (i >= argv.length) { errOut.println("Missing command"); printUsage(errOut); return -1; } argv = Arrays.copyOfRange(argv, i, argv.length); } return super.runCmd(argv); }
@Test public void testFailoverWithFencerConfiguredAndForce() throws Exception { Mockito.doReturn(STANDBY_READY_RESULT).when(mockProtocol).getServiceStatus(); HdfsConfiguration conf = getHAConf(); conf.set(DFSConfigKeys.DFS_HA_FENCE_METHODS_KEY, getFencerTrueCommand()); tool.setConf(conf); assertEquals(0, runTool("-failover", "nn1", "nn2", "--forcefence")); }
private int runTool(String ... args) throws Exception { errOutBytes.reset(); LOG.info("Running: DFSHAAdmin " + Joiner.on(" ").join(args)); int ret = tool.run(args); errOutput = new String(errOutBytes.toByteArray(), Charsets.UTF_8); LOG.info("Output:\n" + errOutput); return ret; } }
@Override public void setConf(Configuration conf) { if (conf != null) { conf = addSecurityConfiguration(conf); } super.setConf(conf); }
public static void main(String[] argv) throws Exception { int res = ToolRunner.run(new DFSHAAdmin(), argv); System.exit(res); } }
@Override protected int runCmd(String[] argv) throws Exception { if (argv.length < 1) { printUsage(errOut); return -1; } int i = 0; String cmd = argv[i++]; if ("-ns".equals(cmd)) { if (i == argv.length) { errOut.println("Missing nameservice ID"); printUsage(errOut); return -1; } nameserviceId = argv[i++]; if (i >= argv.length) { errOut.println("Missing command"); printUsage(errOut); return -1; } argv = Arrays.copyOfRange(argv, i, argv.length); } return super.runCmd(argv); }
@Test public void testFailoverWithForceActive() throws Exception { Mockito.doReturn(STANDBY_READY_RESULT).when(mockProtocol).getServiceStatus(); HdfsConfiguration conf = getHAConf(); conf.set(DFSConfigKeys.DFS_HA_FENCE_METHODS_KEY, getFencerTrueCommand()); tool.setConf(conf); assertEquals(0, runTool("-failover", "nn1", "nn2", "--forceactive")); }
@Override public void setConf(Configuration conf) { this.conf = DFSHAAdmin.addSecurityConfiguration(conf); }
/** * Try to map the given namenode ID to its service address. */ @Override protected HAServiceTarget resolveTarget(String nnId) { HdfsConfiguration conf = (HdfsConfiguration)getConf(); return new NNHAServiceTarget(conf, nameserviceId, nnId); }