DFSAdmin extends FsShell { public int triggerBlockReport(String[] argv) throws IOException { List<String> args = new LinkedList<String>(); for (int j = 1; j < argv.length; j++) { args.add(argv[j]); } InetSocketAddress namenodeAddr = null; String nnHostPort = StringUtils.popOptionWithArgument("-namenode", args); if (nnHostPort != null) { namenodeAddr = NetUtils.createSocketAddr(nnHostPort); } boolean incremental = StringUtils.popOption("-incremental", args); String hostPort = StringUtils.popFirstNonOption(args); if (hostPort == null) { System.err.println("You must specify a host:port pair."); return 1; } if (!args.isEmpty()) { System.err.print("Can't understand arguments: " + Joiner.on(" ").join(args) + "\n"); return 1; } ClientDatanodeProtocol dnProxy = getDataNodeProxy(hostPort); try { dnProxy.triggerBlockReport( new BlockReportOptions.Factory(). setNamenodeAddr(namenodeAddr). setIncremental(incremental). build()); } catch (IOException e) { System.err.println("triggerBlockReport error: " + e); return 1; } System.out.println("Triggering " + (incremental ? "an incremental " : "a full ") + "block report on " + hostPort + (namenodeAddr == null ? "" : " to namenode " + nnHostPort) + "."); return 0; } DFSAdmin();  DFSAdmin(Configuration conf); void report(String[] argv, int i); void setSafeMode(String[] argv, int idx); int triggerBlockReport(String[] argv); void allowSnapshot(String[] argv); void disallowSnapshot(String[] argv); void provisionSnapshotTrash(String[] argv); int saveNamespace(String[] argv); int rollEdits(); int restoreFailedStorage(String arg); int refreshNodes(); int listOpenFiles(String[] argv); int setBalancerBandwidth(String[] argv, int idx); int getBalancerBandwidth(String[] argv, int idx); int fetchImage(final String[] argv, final int idx); int finalizeUpgrade(); int getUpgradeStatus(); int upgrade(String arg); int metaSave(String[] argv, int idx); int printTopology(); int refreshServiceAcl(); int refreshUserToGroupsMappings(); int refreshSuperUserGroupsConfiguration(); int refreshCallQueue(); int reconfig(String[] argv, int i); int genericRefresh(String[] argv, int i); @Override int run(String[] argv); static void main(String[] argv);  }
@Test(timeout = 30000) public void testTriggerBlockReport() throws Exception { redirectStream(); final DFSAdmin dfsAdmin = new DFSAdmin(conf); final DataNode dn = cluster.getDataNodes().get(0); final NameNode nn = cluster.getNameNode(); final String dnAddr = String.format( "%s:%d", dn.getXferAddress().getHostString(), dn.getIpcPort()); final String nnAddr = nn.getHostAndPort(); resetStream(); final List<String> outs = Lists.newArrayList(); final int ret = ToolRunner.run(dfsAdmin, new String[]{"-triggerBlockReport", dnAddr, "-incremental", "-namenode", nnAddr}); assertEquals(0, ret); scanIntoList(out, outs); assertEquals(1, outs.size()); assertThat(outs.get(0), is(allOf(containsString("Triggering an incremental block report on "), containsString(" to namenode ")))); }