org.apache.hadoop.cli.util.CommandExecutor Java Examples

The following examples show how to use org.apache.hadoop.cli.util.CommandExecutor. 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: TestCacheAdminCLI.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public CommandExecutor getExecutor(String tag)
    throws IllegalArgumentException {
  if (getType() instanceof CLICommandCacheAdmin) {
    return new CacheAdminCmdExecutor(tag, new CacheAdmin(conf));
  }
  return super.getExecutor(tag);
}
 
Example #2
Source File: TestCryptoAdminCLI.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public CommandExecutor getExecutor(String tag)
    throws IllegalArgumentException {
  if (getType() instanceof CLICommandCryptoAdmin) {
    return new CryptoAdminCmdExecutor(tag, new CryptoAdmin(conf));
  }
  return super.getExecutor(tag);
}
 
Example #3
Source File: TestCacheAdminCLI.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public CommandExecutor getExecutor(String tag)
    throws IllegalArgumentException {
  if (getType() instanceof CLICommandCacheAdmin) {
    return new CacheAdminCmdExecutor(tag, new CacheAdmin(conf));
  }
  return super.getExecutor(tag);
}
 
Example #4
Source File: TestCryptoAdminCLI.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public CommandExecutor getExecutor(String tag)
    throws IllegalArgumentException {
  if (getType() instanceof CLICommandCryptoAdmin) {
    return new CryptoAdminCmdExecutor(tag, new CryptoAdmin(conf));
  }
  return super.getExecutor(tag);
}
 
Example #5
Source File: TestCLI.java    From RDFS with Apache License 2.0 5 votes vote down vote up
/**
 * Compare the actual output with the expected output
 * @param compdata
 * @return
 */
private boolean compareTestOutput(ComparatorData compdata) {
  // Compare the output based on the comparator
  String comparatorType = compdata.getComparatorType();
  Class<?> comparatorClass = null;
  
  // If testMode is "test", then run the command and compare the output
  // If testMode is "nocompare", then run the command and dump the output.
  // Do not compare
  
  boolean compareOutput = false;
  
  if (testMode.equals(TESTMODE_TEST)) {
    try {
  	// Initialize the comparator class and run its compare method
      comparatorClass = Class.forName("org.apache.hadoop.cli.util." + 
        comparatorType);
      ComparatorBase comp = (ComparatorBase) comparatorClass.newInstance();
      compareOutput = comp.compare(CommandExecutor.getLastCommandOutput(), 
        compdata.getExpectedOutput());
    } catch (Exception e) {
      LOG.info("Error in instantiating the comparator" + e);
    }
  }
  
  return compareOutput;
}
 
Example #6
Source File: TestCLI.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
/**
 * Compare the actual output with the expected output
 * @param compdata
 * @return
 */
private boolean compareTestOutput(ComparatorData compdata) {
  // Compare the output based on the comparator
  String comparatorType = compdata.getComparatorType();
  Class<?> comparatorClass = null;
  
  // If testMode is "test", then run the command and compare the output
  // If testMode is "nocompare", then run the command and dump the output.
  // Do not compare
  
  boolean compareOutput = false;
  
  if (testMode.equals(TESTMODE_TEST)) {
    try {
  	// Initialize the comparator class and run its compare method
      comparatorClass = Class.forName("org.apache.hadoop.cli.util." + 
        comparatorType);
      ComparatorBase comp = (ComparatorBase) comparatorClass.newInstance();
      compareOutput = comp.compare(CommandExecutor.getLastCommandOutput(), 
        compdata.getExpectedOutput());
    } catch (Exception e) {
      LOG.info("Error in instantiating the comparator" + e);
    }
  }
  
  return compareOutput;
}
 
Example #7
Source File: CLITestCmdDFS.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public CommandExecutor getExecutor(String tag) throws IllegalArgumentException {
  if (getType() instanceof CLICommandDFSAdmin)
    return new FSCmdExecutor(tag, new DFSAdmin());
  return super.getExecutor(tag);
}
 
Example #8
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 #9
Source File: TestCLI.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
protected CommandExecutor.Result execute(CLICommand cmd) throws Exception {
  return cmd.getExecutor("").executeCommand(cmd.getCmd());

}
 
Example #10
Source File: CLITestCmdDFS.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
public CommandExecutor getExecutor(String tag) throws IllegalArgumentException {
  if (getType() instanceof CLICommandDFSAdmin)
    return new FSCmdExecutor(tag, new DFSAdmin());
  return super.getExecutor(tag);
}
 
Example #11
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();
  }
}
 
Example #12
Source File: TestCLI.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
protected CommandExecutor.Result execute(CLICommand cmd) throws Exception {
  return cmd.getExecutor("").executeCommand(cmd.getCmd());

}
 
Example #13
Source File: CLITestCmdMR.java    From hadoop with Apache License 2.0 2 votes vote down vote up
/**
 * This is not implemented because HadoopArchive constructor requires JobConf
 * to create an archive object. Because TestMRCLI uses setup method from
 * TestHDFSCLI the initialization of executor objects happens before a config
 * is created and updated. Thus, actual calls to executors happen in the body
 * of the test method.
 */
@Override
public CommandExecutor getExecutor(String tag)
    throws IllegalArgumentException {
  throw new IllegalArgumentException("Method isn't supported");
}
 
Example #14
Source File: CLITestCmdMR.java    From big-c with Apache License 2.0 2 votes vote down vote up
/**
 * This is not implemented because HadoopArchive constructor requires JobConf
 * to create an archive object. Because TestMRCLI uses setup method from
 * TestHDFSCLI the initialization of executor objects happens before a config
 * is created and updated. Thus, actual calls to executors happen in the body
 * of the test method.
 */
@Override
public CommandExecutor getExecutor(String tag)
    throws IllegalArgumentException {
  throw new IllegalArgumentException("Method isn't supported");
}