Java Code Examples for org.apache.hadoop.cli.util.CommandExecutor#executeCommand()

The following examples show how to use org.apache.hadoop.cli.util.CommandExecutor#executeCommand() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestStorageRestore.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Test dfsadmin -restoreFailedStorage command
 * @throws Exception
 */
@Test
public void testDfsAdminCmd() throws Exception {
  cluster = new MiniDFSCluster.Builder(config).
                               numDataNodes(2).
                               manageNameDfsDirs(false).build();
  cluster.waitActive();
  try {

    FSImage fsi = cluster.getNameNode().getFSImage();

    // it is started with dfs.namenode.name.dir.restore set to true (in SetUp())
    boolean restore = fsi.getStorage().getRestoreFailedStorage();
    LOG.info("Restore is " + restore);
    assertEquals(restore, true);

    // now run DFSAdmnin command

    String cmd = "-fs NAMENODE -restoreFailedStorage false";
    String namenode = config.get(DFSConfigKeys.FS_DEFAULT_NAME_KEY, "file:///");
    CommandExecutor executor =
        new CLITestCmdDFS(cmd, new CLICommandDFSAdmin()).getExecutor(namenode);

    executor.executeCommand(cmd);
    restore = fsi.getStorage().getRestoreFailedStorage();
    assertFalse("After set true call restore is " + restore, restore);

    // run one more time - to set it to true again
    cmd = "-fs NAMENODE -restoreFailedStorage true";
    executor.executeCommand(cmd);
    restore = fsi.getStorage().getRestoreFailedStorage();
    assertTrue("After set false call restore is " + restore, restore);
    
    // run one more time - no change in value
    cmd = "-fs NAMENODE -restoreFailedStorage check";
    CommandExecutor.Result cmdResult = executor.executeCommand(cmd);
    restore = fsi.getStorage().getRestoreFailedStorage();
    assertTrue("After check call restore is " + restore, restore);
    String commandOutput = cmdResult.getCommandOutput();
    commandOutput.trim();
    assertTrue(commandOutput.contains("restoreFailedStorage is set to true"));
    

  } finally {
    cluster.shutdown();
  }
}
 
Example 2
Source File: TestStorageRestore.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Test dfsadmin -restoreFailedStorage command
 * @throws Exception
 */
@Test
public void testDfsAdminCmd() throws Exception {
  cluster = new MiniDFSCluster.Builder(config).
                               numDataNodes(2).
                               manageNameDfsDirs(false).build();
  cluster.waitActive();
  try {

    FSImage fsi = cluster.getNameNode().getFSImage();

    // it is started with dfs.namenode.name.dir.restore set to true (in SetUp())
    boolean restore = fsi.getStorage().getRestoreFailedStorage();
    LOG.info("Restore is " + restore);
    assertEquals(restore, true);

    // now run DFSAdmnin command

    String cmd = "-fs NAMENODE -restoreFailedStorage false";
    String namenode = config.get(DFSConfigKeys.FS_DEFAULT_NAME_KEY, "file:///");
    CommandExecutor executor =
        new CLITestCmdDFS(cmd, new CLICommandDFSAdmin()).getExecutor(namenode);

    executor.executeCommand(cmd);
    restore = fsi.getStorage().getRestoreFailedStorage();
    assertFalse("After set true call restore is " + restore, restore);

    // run one more time - to set it to true again
    cmd = "-fs NAMENODE -restoreFailedStorage true";
    executor.executeCommand(cmd);
    restore = fsi.getStorage().getRestoreFailedStorage();
    assertTrue("After set false call restore is " + restore, restore);
    
    // run one more time - no change in value
    cmd = "-fs NAMENODE -restoreFailedStorage check";
    CommandExecutor.Result cmdResult = executor.executeCommand(cmd);
    restore = fsi.getStorage().getRestoreFailedStorage();
    assertTrue("After check call restore is " + restore, restore);
    String commandOutput = cmdResult.getCommandOutput();
    commandOutput.trim();
    assertTrue(commandOutput.contains("restoreFailedStorage is set to true"));
    

  } finally {
    cluster.shutdown();
  }
}