当前位置: 首页>>代码示例>>Java>>正文


Java ExitCodeException.getMessage方法代码示例

本文整理汇总了Java中org.apache.hadoop.util.Shell.ExitCodeException.getMessage方法的典型用法代码示例。如果您正苦于以下问题:Java ExitCodeException.getMessage方法的具体用法?Java ExitCodeException.getMessage怎么用?Java ExitCodeException.getMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.util.Shell.ExitCodeException的用法示例。


在下文中一共展示了ExitCodeException.getMessage方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createHardLink

import org.apache.hadoop.util.Shell.ExitCodeException; //导入方法依赖的package包/类
/**
 * Creates a hardlink 
 * @param file - existing source file
 * @param linkName - desired target link file
 */
public static void createHardLink(File file, File linkName) 
throws IOException {
  if (file == null) {
    throw new IOException(
        "invalid arguments to createHardLink: source file is null");
  }
  if (linkName == null) {
    throw new IOException(
        "invalid arguments to createHardLink: link name is null");
  }
 // construct and execute shell command
  String[] hardLinkCommand = getHardLinkCommand.linkOne(file, linkName);
  ShellCommandExecutor shexec = new ShellCommandExecutor(hardLinkCommand);
  try {
    shexec.execute();
  } catch (ExitCodeException e) {
    throw new IOException("Failed to execute command " +
        Arrays.toString(hardLinkCommand) +
        "; command output: \"" + shexec.getOutput() + "\"" +
        "; WrappedException: \"" + e.getMessage() + "\"");
  }
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:28,代码来源:HardLink.java

示例2: testInvalidEnvSyntaxDiagnostics

import org.apache.hadoop.util.Shell.ExitCodeException; //导入方法依赖的package包/类
@Test (timeout = 20000)
public void testInvalidEnvSyntaxDiagnostics() throws IOException  {

  File shellFile = null;
  try {
    shellFile = Shell.appendScriptExtension(tmpDir, "hello");
    Map<Path, List<String>> resources =
        new HashMap<Path, List<String>>();
    FileOutputStream fos = new FileOutputStream(shellFile);
    FileUtil.setExecutable(shellFile, true);

    Map<String, String> env = new HashMap<String, String>();
    // invalid env
    env.put(
        "APPLICATION_WORKFLOW_CONTEXT", "{\"workflowId\":\"609f91c5cd83\"," +
        "\"workflowName\":\"\n\ninsert table " +
        "\npartition (cd_education_status)\nselect cd_demo_sk, cd_gender, " );
    List<String> commands = new ArrayList<String>();
    new DefaultContainerExecutor().writeLaunchEnv(fos, env, resources, commands);
    fos.flush();
    fos.close();

    // It is supposed that LANG is set as C.
    Map<String, String> cmdEnv = new HashMap<String, String>();
    cmdEnv.put("LANG", "C");
    Shell.ShellCommandExecutor shexc
    = new Shell.ShellCommandExecutor(new String[]{shellFile.getAbsolutePath()},
      tmpDir, cmdEnv);
    String diagnostics = null;
    try {
      shexc.execute();
      Assert.fail("Should catch exception");
    } catch(ExitCodeException e){
      diagnostics = e.getMessage();
    }
    Assert.assertTrue(diagnostics.contains(Shell.WINDOWS ?
        "is not recognized as an internal or external command" :
        "command not found"));
    Assert.assertTrue(shexc.getExitCode() != 0);
  }
  finally {
    // cleanup
    if (shellFile != null
        && shellFile.exists()) {
      shellFile.delete();
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:49,代码来源:TestContainerLaunch.java

示例3: testContainerLaunchStdoutAndStderrDiagnostics

import org.apache.hadoop.util.Shell.ExitCodeException; //导入方法依赖的package包/类
@Test (timeout = 20000)
public void testContainerLaunchStdoutAndStderrDiagnostics() throws IOException {

  File shellFile = null;
  try {
    shellFile = Shell.appendScriptExtension(tmpDir, "hello");
    // echo "hello" to stdout and "error" to stderr and exit code with 2;
    String command = Shell.WINDOWS ?
        "@echo \"hello\" & @echo \"error\" 1>&2 & exit /b 2" :
        "echo \"hello\"; echo \"error\" 1>&2; exit 2;";
    PrintWriter writer = new PrintWriter(new FileOutputStream(shellFile));
    FileUtil.setExecutable(shellFile, true);
    writer.println(command);
    writer.close();
    Map<Path, List<String>> resources =
        new HashMap<Path, List<String>>();
    FileOutputStream fos = new FileOutputStream(shellFile, true);

    Map<String, String> env = new HashMap<String, String>();
    List<String> commands = new ArrayList<String>();
    commands.add(command);
    ContainerExecutor exec = new DefaultContainerExecutor();
    exec.writeLaunchEnv(fos, env, resources, commands);
    fos.flush();
    fos.close();

    Shell.ShellCommandExecutor shexc
    = new Shell.ShellCommandExecutor(new String[]{shellFile.getAbsolutePath()}, tmpDir);
    String diagnostics = null;
    try {
      shexc.execute();
      Assert.fail("Should catch exception");
    } catch(ExitCodeException e){
      diagnostics = e.getMessage();
    }
    // test stderr
    Assert.assertTrue(diagnostics.contains("error"));
    // test stdout
    Assert.assertTrue(shexc.getOutput().contains("hello"));
    Assert.assertTrue(shexc.getExitCode() == 2);
  }
  finally {
    // cleanup
    if (shellFile != null
        && shellFile.exists()) {
      shellFile.delete();
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:50,代码来源:TestContainerLaunch.java

示例4: testInvalidSymlinkDiagnostics

import org.apache.hadoop.util.Shell.ExitCodeException; //导入方法依赖的package包/类
@Test (timeout = 20000)
public void testInvalidSymlinkDiagnostics() throws IOException  {

  File shellFile = null;
  File tempFile = null;
  String symLink = Shell.WINDOWS ? "test.cmd" :
    "test";
  File symLinkFile = null;

  try {
    shellFile = Shell.appendScriptExtension(tmpDir, "hello");
    tempFile = Shell.appendScriptExtension(tmpDir, "temp");
    String timeoutCommand = Shell.WINDOWS ? "@echo \"hello\"" :
      "echo \"hello\"";
    PrintWriter writer = new PrintWriter(new FileOutputStream(shellFile));
    FileUtil.setExecutable(shellFile, true);
    writer.println(timeoutCommand);
    writer.close();

    Map<Path, List<String>> resources =
        new HashMap<Path, List<String>>();
    //This is an invalid path and should throw exception because of No such file.
    Path invalidPath = new Path(shellFile.getAbsolutePath()+"randomPath");
    resources.put(invalidPath, Arrays.asList(symLink));
    FileOutputStream fos = new FileOutputStream(tempFile);

    Map<String, String> env = new HashMap<String, String>();
    List<String> commands = new ArrayList<String>();
    if (Shell.WINDOWS) {
      commands.add("cmd");
      commands.add("/c");
      commands.add("\"" + symLink + "\"");
    } else {
      commands.add("/bin/sh ./\\\"" + symLink + "\\\"");
    }
    new DefaultContainerExecutor()
        .writeLaunchEnv(fos, env, resources, commands,
            new Path(localLogDir.getAbsolutePath()));
    fos.flush();
    fos.close();
    FileUtil.setExecutable(tempFile, true);

    Shell.ShellCommandExecutor shexc
    = new Shell.ShellCommandExecutor(new String[]{tempFile.getAbsolutePath()}, tmpDir);
    String diagnostics = null;
    try {
      shexc.execute();
      Assert.fail("Should catch exception");
    } catch(ExitCodeException e){
      diagnostics = e.getMessage();
    }
    Assert.assertNotNull(diagnostics);
    Assert.assertTrue(shexc.getExitCode() != 0);
    symLinkFile = new File(tmpDir, symLink);
  }
  finally {
    // cleanup
    if (shellFile != null
        && shellFile.exists()) {
      shellFile.delete();
    }
    if (tempFile != null
        && tempFile.exists()) {
      tempFile.delete();
    }
    if (symLinkFile != null
        && symLinkFile.exists()) {
      symLinkFile.delete();
    }
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:72,代码来源:TestContainerLaunch.java

示例5: testInvalidEnvSyntaxDiagnostics

import org.apache.hadoop.util.Shell.ExitCodeException; //导入方法依赖的package包/类
@Test (timeout = 20000)
public void testInvalidEnvSyntaxDiagnostics() throws IOException  {

  File shellFile = null;
  try {
    shellFile = Shell.appendScriptExtension(tmpDir, "hello");
    Map<Path, List<String>> resources =
        new HashMap<Path, List<String>>();
    FileOutputStream fos = new FileOutputStream(shellFile);
    FileUtil.setExecutable(shellFile, true);

    Map<String, String> env = new HashMap<String, String>();
    // invalid env
    env.put(
        "APPLICATION_WORKFLOW_CONTEXT", "{\"workflowId\":\"609f91c5cd83\"," +
        "\"workflowName\":\"\n\ninsert table " +
        "\npartition (cd_education_status)\nselect cd_demo_sk, cd_gender, " );
    List<String> commands = new ArrayList<String>();
    new DefaultContainerExecutor()
        .writeLaunchEnv(fos, env, resources, commands,
            new Path(localLogDir.getAbsolutePath()));
    fos.flush();
    fos.close();

    // It is supposed that LANG is set as C.
    Map<String, String> cmdEnv = new HashMap<String, String>();
    cmdEnv.put("LANG", "C");
    Shell.ShellCommandExecutor shexc
    = new Shell.ShellCommandExecutor(new String[]{shellFile.getAbsolutePath()},
      tmpDir, cmdEnv);
    String diagnostics = null;
    try {
      shexc.execute();
      Assert.fail("Should catch exception");
    } catch(ExitCodeException e){
      diagnostics = e.getMessage();
    }
    Assert.assertTrue(diagnostics.contains(Shell.WINDOWS ?
        "is not recognized as an internal or external command" :
        "command not found"));
    Assert.assertTrue(shexc.getExitCode() != 0);
  }
  finally {
    // cleanup
    if (shellFile != null
        && shellFile.exists()) {
      shellFile.delete();
    }
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:51,代码来源:TestContainerLaunch.java

示例6: testContainerLaunchStdoutAndStderrDiagnostics

import org.apache.hadoop.util.Shell.ExitCodeException; //导入方法依赖的package包/类
@Test (timeout = 20000)
public void testContainerLaunchStdoutAndStderrDiagnostics() throws IOException {

  File shellFile = null;
  try {
    shellFile = Shell.appendScriptExtension(tmpDir, "hello");
    // echo "hello" to stdout and "error" to stderr and exit code with 2;
    String command = Shell.WINDOWS ?
        "@echo \"hello\" & @echo \"error\" 1>&2 & exit /b 2" :
        "echo \"hello\"; echo \"error\" 1>&2; exit 2;";
    PrintWriter writer = new PrintWriter(new FileOutputStream(shellFile));
    FileUtil.setExecutable(shellFile, true);
    writer.println(command);
    writer.close();
    Map<Path, List<String>> resources =
        new HashMap<Path, List<String>>();
    FileOutputStream fos = new FileOutputStream(shellFile, true);

    Map<String, String> env = new HashMap<String, String>();
    List<String> commands = new ArrayList<String>();
    commands.add(command);
    ContainerExecutor exec = new DefaultContainerExecutor();
    exec.writeLaunchEnv(fos, env, resources, commands,
        new Path(localLogDir.getAbsolutePath()));
    fos.flush();
    fos.close();

    Shell.ShellCommandExecutor shexc
    = new Shell.ShellCommandExecutor(new String[]{shellFile.getAbsolutePath()}, tmpDir);
    String diagnostics = null;
    try {
      shexc.execute();
      Assert.fail("Should catch exception");
    } catch(ExitCodeException e){
      diagnostics = e.getMessage();
    }
    // test stderr
    Assert.assertTrue(diagnostics.contains("error"));
    // test stdout
    Assert.assertTrue(shexc.getOutput().contains("hello"));
    Assert.assertTrue(shexc.getExitCode() == 2);
  }
  finally {
    // cleanup
    if (shellFile != null
        && shellFile.exists()) {
      shellFile.delete();
    }
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:51,代码来源:TestContainerLaunch.java

示例7: testInvalidSymlinkDiagnostics

import org.apache.hadoop.util.Shell.ExitCodeException; //导入方法依赖的package包/类
@Test (timeout = 20000)
public void testInvalidSymlinkDiagnostics() throws IOException  {

  File shellFile = null;
  File tempFile = null;
  String symLink = Shell.WINDOWS ? "test.cmd" :
    "test";
  File symLinkFile = null;

  try {
    shellFile = Shell.appendScriptExtension(tmpDir, "hello");
    tempFile = Shell.appendScriptExtension(tmpDir, "temp");
    String timeoutCommand = Shell.WINDOWS ? "@echo \"hello\"" :
      "echo \"hello\"";
    PrintWriter writer = new PrintWriter(new FileOutputStream(shellFile));
    FileUtil.setExecutable(shellFile, true);
    writer.println(timeoutCommand);
    writer.close();

    Map<Path, List<String>> resources =
        new HashMap<Path, List<String>>();
    //This is an invalid path and should throw exception because of No such file.
    Path invalidPath = new Path(shellFile.getAbsolutePath()+"randomPath");
    resources.put(invalidPath, Arrays.asList(symLink));
    FileOutputStream fos = new FileOutputStream(tempFile);

    Map<String, String> env = new HashMap<String, String>();
    List<String> commands = new ArrayList<String>();
    if (Shell.WINDOWS) {
      commands.add("cmd");
      commands.add("/c");
      commands.add("\"" + symLink + "\"");
    } else {
      commands.add("/bin/sh ./\\\"" + symLink + "\\\"");
    }
    new DefaultContainerExecutor().writeLaunchEnv(fos, env, resources, commands);
    fos.flush();
    fos.close();
    FileUtil.setExecutable(tempFile, true);

    Shell.ShellCommandExecutor shexc
    = new Shell.ShellCommandExecutor(new String[]{tempFile.getAbsolutePath()}, tmpDir);
    String diagnostics = null;
    try {
      shexc.execute();
      Assert.fail("Should catch exception");
    } catch(ExitCodeException e){
      diagnostics = e.getMessage();
    }
    Assert.assertNotNull(diagnostics);
    Assert.assertTrue(shexc.getExitCode() != 0);
    symLinkFile = new File(tmpDir, symLink);
  }
  finally {
    // cleanup
    if (shellFile != null
        && shellFile.exists()) {
      shellFile.delete();
    }
    if (tempFile != null
        && tempFile.exists()) {
      tempFile.delete();
    }
    if (symLinkFile != null
        && symLinkFile.exists()) {
      symLinkFile.delete();
    }
  }
}
 
开发者ID:yncxcw,项目名称:big-c,代码行数:70,代码来源:TestContainerLaunch.java

示例8: createHardLinkMult

import org.apache.hadoop.util.Shell.ExitCodeException; //导入方法依赖的package包/类
protected static int createHardLinkMult(File parentDir, 
    String[] fileBaseNames, File linkDir, int maxLength) 
throws IOException {
  if (parentDir == null) {
    throw new IOException(
        "invalid arguments to createHardLinkMult: parent directory is null");
  }
  if (linkDir == null) {
    throw new IOException(
        "invalid arguments to createHardLinkMult: link directory is null");
  }
  if (fileBaseNames == null) {
    throw new IOException(
        "invalid arguments to createHardLinkMult: "
        + "filename list can be empty but not null");
  }
  if (fileBaseNames.length == 0) {
    //the OS cmds can't handle empty list of filenames, 
    //but it's legal, so just return.
    return 0; 
  }
  if (!linkDir.exists()) {
    throw new FileNotFoundException(linkDir + " not found.");
  }

  //if the list is too long, split into multiple invocations
  int callCount = 0;
  if (getLinkMultArgLength(parentDir, fileBaseNames, linkDir) > maxLength
        && fileBaseNames.length > 1) {
    String[] list1 = Arrays.copyOf(fileBaseNames, fileBaseNames.length/2);
    callCount += createHardLinkMult(parentDir, list1, linkDir, maxLength);
    String[] list2 = Arrays.copyOfRange(fileBaseNames, fileBaseNames.length/2,
        fileBaseNames.length);
    callCount += createHardLinkMult(parentDir, list2, linkDir, maxLength);  
    return callCount;
  } else {
    callCount = 1;
  }
  
  // construct and execute shell command
  String[] hardLinkCommand = getHardLinkCommand.linkMult(fileBaseNames, 
      linkDir);
  ShellCommandExecutor shexec = new ShellCommandExecutor(hardLinkCommand,
    parentDir, null, 0L);
  try {
    shexec.execute();
  } catch (ExitCodeException e) {
    throw new IOException(shexec.getOutput() + e.getMessage());
  }
  return callCount;
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:52,代码来源:HardLink.java

示例9: testInvalidSymlinkDiagnostics

import org.apache.hadoop.util.Shell.ExitCodeException; //导入方法依赖的package包/类
@Test (timeout = 20000)
public void testInvalidSymlinkDiagnostics() throws IOException  {

  File shellFile = null;
  File tempFile = null;
  String symLink = Shell.WINDOWS ? "test.cmd" :
    "test";
  File symLinkFile = null;

  try {
    shellFile = Shell.appendScriptExtension(tmpDir, "hello");
    tempFile = Shell.appendScriptExtension(tmpDir, "temp");
    String timeoutCommand = Shell.WINDOWS ? "@echo \"hello\"" :
      "echo \"hello\"";
    PrintWriter writer = new PrintWriter(new FileOutputStream(shellFile));
    FileUtil.setExecutable(shellFile, true);
    writer.println(timeoutCommand);
    writer.close();

    Map<Path, List<String>> resources =
        new HashMap<Path, List<String>>();
    //This is an invalid path and should throw exception because of No such file.
    Path invalidPath = new Path(shellFile.getAbsolutePath()+"randomPath");
    resources.put(invalidPath, Arrays.asList(symLink));
    FileOutputStream fos = new FileOutputStream(tempFile);

    Map<String, String> env = new HashMap<String, String>();
    List<String> commands = new ArrayList<String>();
    if (Shell.WINDOWS) {
      commands.add("cmd");
      commands.add("/c");
      commands.add("\"" + symLink + "\"");
    } else {
      commands.add("/bin/sh ./\\\"" + symLink + "\\\"");
    }
    ContainerLaunch.writeLaunchEnv(fos, env, resources, commands);
    fos.flush();
    fos.close();
    FileUtil.setExecutable(tempFile, true);

    Shell.ShellCommandExecutor shexc
    = new Shell.ShellCommandExecutor(new String[]{tempFile.getAbsolutePath()}, tmpDir);
    String diagnostics = null;
    try {
      shexc.execute();
      Assert.fail("Should catch exception");
    } catch(ExitCodeException e){
      diagnostics = e.getMessage();
    }
    Assert.assertNotNull(diagnostics);
    Assert.assertTrue(shexc.getExitCode() != 0);
    symLinkFile = new File(tmpDir, symLink);
  }
  finally {
    // cleanup
    if (shellFile != null
        && shellFile.exists()) {
      shellFile.delete();
    }
    if (tempFile != null
        && tempFile.exists()) {
      tempFile.delete();
    }
    if (symLinkFile != null
        && symLinkFile.exists()) {
      symLinkFile.delete();
    }
  }
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:70,代码来源:TestContainerLaunch.java

示例10: testInvalidEnvSyntaxDiagnostics

import org.apache.hadoop.util.Shell.ExitCodeException; //导入方法依赖的package包/类
@Test (timeout = 20000)
public void testInvalidEnvSyntaxDiagnostics() throws IOException  {

  File shellFile = null;
  try {
    shellFile = Shell.appendScriptExtension(tmpDir, "hello");
    String timeoutCommand = Shell.WINDOWS ? "@echo \"hello\"" :
      "echo \"hello\"";
    PrintWriter writer = new PrintWriter(new FileOutputStream(shellFile));
    FileUtil.setExecutable(shellFile, true);
    writer.println(timeoutCommand);
    writer.close();
    Map<Path, List<String>> resources =
        new HashMap<Path, List<String>>();
    FileOutputStream fos = new FileOutputStream(shellFile);

    Map<String, String> env = new HashMap<String, String>();
    // invalid env
    env.put(
        "APPLICATION_WORKFLOW_CONTEXT", "{\"workflowId\":\"609f91c5cd83\"," +
        "\"workflowName\":\"\n\ninsert table " +
        "\npartition (cd_education_status)\nselect cd_demo_sk, cd_gender, " );
    List<String> commands = new ArrayList<String>();
    ContainerLaunch.writeLaunchEnv(fos, env, resources, commands);
    fos.flush();
    fos.close();

    Shell.ShellCommandExecutor shexc
    = new Shell.ShellCommandExecutor(new String[]{shellFile.getAbsolutePath()}, tmpDir);
    String diagnostics = null;
    try {
      shexc.execute();
      Assert.fail("Should catch exception");
    } catch(ExitCodeException e){
      diagnostics = e.getMessage();
    }
    Assert.assertTrue(diagnostics.contains("command not found"));
    Assert.assertTrue(shexc.getExitCode() != 0);
  }
  finally {
    // cleanup
    if (shellFile != null
        && shellFile.exists()) {
      shellFile.delete();
    }
  }
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:48,代码来源:TestContainerLaunch.java

示例11: testContainerLaunchStdoutAndStderrDiagnostics

import org.apache.hadoop.util.Shell.ExitCodeException; //导入方法依赖的package包/类
@Test (timeout = 20000)
public void testContainerLaunchStdoutAndStderrDiagnostics() throws IOException {

  File shellFile = null;
  try {
    shellFile = Shell.appendScriptExtension(tmpDir, "hello");
    // echo "hello" to stdout and "error" to stderr and exit code with 2;
    String command = Shell.WINDOWS ? "@echo \"hello\"; @echo \"error\" 1>&2; exit 2;" :
      "echo \"hello\"; echo \"error\" 1>&2; exit 2;";
    PrintWriter writer = new PrintWriter(new FileOutputStream(shellFile));
    FileUtil.setExecutable(shellFile, true);
    writer.println(command);
    writer.close();
    Map<Path, List<String>> resources =
        new HashMap<Path, List<String>>();
    FileOutputStream fos = new FileOutputStream(shellFile);

    Map<String, String> env = new HashMap<String, String>();
    List<String> commands = new ArrayList<String>();
    commands.add(command);
    ContainerLaunch.writeLaunchEnv(fos, env, resources, commands);
    fos.flush();
    fos.close();

    Shell.ShellCommandExecutor shexc
    = new Shell.ShellCommandExecutor(new String[]{shellFile.getAbsolutePath()}, tmpDir);
    String diagnostics = null;
    try {
      shexc.execute();
      Assert.fail("Should catch exception");
    } catch(ExitCodeException e){
      diagnostics = e.getMessage();
    }
    // test stderr
    Assert.assertTrue(diagnostics.contains("error"));
    // test stdout
    Assert.assertTrue(shexc.getOutput().contains("hello"));
    Assert.assertTrue(shexc.getExitCode() == 2);
  }
  finally {
    // cleanup
    if (shellFile != null
        && shellFile.exists()) {
      shellFile.delete();
    }
  }
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:48,代码来源:TestContainerLaunch.java

示例12: testInvalidEnvSyntaxDiagnostics

import org.apache.hadoop.util.Shell.ExitCodeException; //导入方法依赖的package包/类
@Test (timeout = 20000)
public void testInvalidEnvSyntaxDiagnostics() throws IOException  {

  File shellFile = null;
  try {
    shellFile = Shell.appendScriptExtension(tmpDir, "hello");
    Map<Path, List<String>> resources =
        new HashMap<Path, List<String>>();
    FileOutputStream fos = new FileOutputStream(shellFile);
    FileUtil.setExecutable(shellFile, true);

    Map<String, String> env = new HashMap<String, String>();
    // invalid env
    env.put(
        "APPLICATION_WORKFLOW_CONTEXT", "{\"workflowId\":\"609f91c5cd83\"," +
        "\"workflowName\":\"\n\ninsert table " +
        "\npartition (cd_education_status)\nselect cd_demo_sk, cd_gender, " );
    List<String> commands = new ArrayList<String>();
    ContainerLaunch.writeLaunchEnv(fos, env, resources, commands);
    fos.flush();
    fos.close();

    Shell.ShellCommandExecutor shexc
    = new Shell.ShellCommandExecutor(new String[]{shellFile.getAbsolutePath()}, tmpDir);
    String diagnostics = null;
    try {
      shexc.execute();
      Assert.fail("Should catch exception");
    } catch(ExitCodeException e){
      diagnostics = e.getMessage();
    }
    Assert.assertTrue(diagnostics.contains(Shell.WINDOWS ?
        "is not recognized as an internal or external command" :
        "command not found"));
    Assert.assertTrue(shexc.getExitCode() != 0);
  }
  finally {
    // cleanup
    if (shellFile != null
        && shellFile.exists()) {
      shellFile.delete();
    }
  }
}
 
开发者ID:chendave,项目名称:hadoop-TCP,代码行数:45,代码来源:TestContainerLaunch.java

示例13: testContainerLaunchStdoutAndStderrDiagnostics

import org.apache.hadoop.util.Shell.ExitCodeException; //导入方法依赖的package包/类
@Test (timeout = 20000)
public void testContainerLaunchStdoutAndStderrDiagnostics() throws IOException {

  File shellFile = null;
  try {
    shellFile = Shell.appendScriptExtension(tmpDir, "hello");
    // echo "hello" to stdout and "error" to stderr and exit code with 2;
    String command = Shell.WINDOWS ?
        "@echo \"hello\" & @echo \"error\" 1>&2 & exit /b 2" :
        "echo \"hello\"; echo \"error\" 1>&2; exit 2;";
    PrintWriter writer = new PrintWriter(new FileOutputStream(shellFile));
    FileUtil.setExecutable(shellFile, true);
    writer.println(command);
    writer.close();
    Map<Path, List<String>> resources =
        new HashMap<Path, List<String>>();
    FileOutputStream fos = new FileOutputStream(shellFile, true);

    Map<String, String> env = new HashMap<String, String>();
    List<String> commands = new ArrayList<String>();
    commands.add(command);
    ContainerLaunch.writeLaunchEnv(fos, env, resources, commands);
    fos.flush();
    fos.close();

    Shell.ShellCommandExecutor shexc
    = new Shell.ShellCommandExecutor(new String[]{shellFile.getAbsolutePath()}, tmpDir);
    String diagnostics = null;
    try {
      shexc.execute();
      Assert.fail("Should catch exception");
    } catch(ExitCodeException e){
      diagnostics = e.getMessage();
    }
    // test stderr
    Assert.assertTrue(diagnostics.contains("error"));
    // test stdout
    Assert.assertTrue(shexc.getOutput().contains("hello"));
    Assert.assertTrue(shexc.getExitCode() == 2);
  }
  finally {
    // cleanup
    if (shellFile != null
        && shellFile.exists()) {
      shellFile.delete();
    }
  }
}
 
开发者ID:chendave,项目名称:hadoop-TCP,代码行数:49,代码来源:TestContainerLaunch.java

示例14: testInvalidEnvSyntaxDiagnostics

import org.apache.hadoop.util.Shell.ExitCodeException; //导入方法依赖的package包/类
@Test (timeout = 20000)
public void testInvalidEnvSyntaxDiagnostics() throws IOException  {

  File shellFile = null;
  try {
    shellFile = Shell.appendScriptExtension(tmpDir, "hello");
    Map<Path, List<String>> resources =
        new HashMap<Path, List<String>>();
    FileOutputStream fos = new FileOutputStream(shellFile);
    FileUtil.setExecutable(shellFile, true);

    Map<String, String> env = new HashMap<String, String>();
    // invalid env
    env.put(
        "APPLICATION_WORKFLOW_CONTEXT", "{\"workflowId\":\"609f91c5cd83\"," +
        "\"workflowName\":\"\n\ninsert table " +
        "\npartition (cd_education_status)\nselect cd_demo_sk, cd_gender, " );
    List<String> commands = new ArrayList<String>();
    ContainerLaunch.writeLaunchEnv(fos, env, resources, commands);
    fos.flush();
    fos.close();

    // It is supposed that LANG is set as C.
    Map<String, String> cmdEnv = new HashMap<String, String>();
    cmdEnv.put("LANG", "C");
    Shell.ShellCommandExecutor shexc
    = new Shell.ShellCommandExecutor(new String[]{shellFile.getAbsolutePath()},
      tmpDir, cmdEnv);
    String diagnostics = null;
    try {
      shexc.execute();
      Assert.fail("Should catch exception");
    } catch(ExitCodeException e){
      diagnostics = e.getMessage();
    }
    Assert.assertTrue(diagnostics.contains(Shell.WINDOWS ?
        "is not recognized as an internal or external command" :
        "command not found"));
    Assert.assertTrue(shexc.getExitCode() != 0);
  }
  finally {
    // cleanup
    if (shellFile != null
        && shellFile.exists()) {
      shellFile.delete();
    }
  }
}
 
开发者ID:Seagate,项目名称:hadoop-on-lustre2,代码行数:49,代码来源:TestContainerLaunch.java


注:本文中的org.apache.hadoop.util.Shell.ExitCodeException.getMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。