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

The following examples show how to use org.apache.hadoop.cli.util.CommandExecutor. These examples are extracted from open source projects. 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 Project: hadoop   Source File: TestCacheAdminCLI.java    License: 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 Project: hadoop   Source File: TestCryptoAdminCLI.java    License: 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 Project: big-c   Source File: TestCacheAdminCLI.java    License: 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 Project: big-c   Source File: TestCryptoAdminCLI.java    License: 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 Project: RDFS   Source File: TestCLI.java    License: 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 Project: hadoop-gpu   Source File: TestCLI.java    License: 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 Project: hadoop   Source File: CLITestCmdDFS.java    License: 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 Project: hadoop   Source File: TestStorageRestore.java    License: 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 Project: hadoop   Source File: TestCLI.java    License: 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 Project: big-c   Source File: CLITestCmdDFS.java    License: 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 Project: big-c   Source File: TestStorageRestore.java    License: 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 Project: big-c   Source File: TestCLI.java    License: 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 Project: hadoop   Source File: CLITestCmdMR.java    License: 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 Project: big-c   Source File: CLITestCmdMR.java    License: 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");
}