Example usage for org.apache.commons.exec ExecuteException getMessage

List of usage examples for org.apache.commons.exec ExecuteException getMessage

Introduction

In this page you can find the example usage for org.apache.commons.exec ExecuteException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.tupilabs.pbs.PBS.java

/**
 * PBS tracejob command./*w w w.j  ava  2 s. c om*/
 * <p>
 * Equivalent to tracejob -n [numberOfDays] [jobId]
 *
 * @param jobId job id
 * @param numberOfDays number of days to look for the job
 * @param quiet quiet mode flag
 * @return tracejob output
 */
public static CommandOutput traceJob(String jobId, int numberOfDays, boolean quiet) {
    final CommandLine cmdLine = new CommandLine(COMMAND_TRACEJOB);
    cmdLine.addArgument(PARAMETER_NUMBER_OF_DAYS);
    cmdLine.addArgument(Integer.toString(numberOfDays));
    if (quiet) {
        cmdLine.addArgument(PARAMETER_QUIET_MODE);
    }
    cmdLine.addArgument(jobId);

    final OutputStream out = new ByteArrayOutputStream();
    final OutputStream err = new ByteArrayOutputStream();

    DefaultExecuteResultHandler resultHandler;
    try {
        resultHandler = execute(cmdLine, null, out, err);
        resultHandler.waitFor(DEFAULT_TIMEOUT);
    } catch (ExecuteException e) {
        throw new PBSException("Failed to execute tracejob command: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new PBSException("Failed to execute tracejob command: " + e.getMessage(), e);
    } catch (InterruptedException e) {
        throw new PBSException("Failed to execute tracejob command: " + e.getMessage(), e);
    }

    final int exitValue = resultHandler.getExitValue();
    LOGGER.info("tracejob exit value: " + exitValue);
    LOGGER.fine("tracejob output: " + out.toString());

    return new CommandOutput(out.toString(), err.toString());
}

From source file:com.tupilabs.pbs.PBS.java

/**
 * PBS qstat command.//from   w w w  .j ava  2s  . co m
 * <p>
 * Equivalent to qstat -f [param]
 *
 * @param name job name
 * @return list of jobs
 */
public static List<Job> qstat(String name) {
    final CommandLine cmdLine = new CommandLine(COMMAND_QSTAT);
    cmdLine.addArgument(PARAMETER_FULL_STATUS);
    if (StringUtils.isNotBlank(name)) {
        cmdLine.addArgument(name);
    }

    final OutputStream out = new ByteArrayOutputStream();
    final OutputStream err = new ByteArrayOutputStream();

    DefaultExecuteResultHandler resultHandler;
    try {
        resultHandler = execute(cmdLine, null, out, err);
        resultHandler.waitFor(DEFAULT_TIMEOUT);
    } catch (ExecuteException e) {
        throw new PBSException("Failed to execute qstat command: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new PBSException("Failed to execute qstat command: " + e.getMessage(), e);
    } catch (InterruptedException e) {
        throw new PBSException("Failed to execute qstat command: " + e.getMessage(), e);
    }

    final int exitValue = resultHandler.getExitValue();
    LOGGER.info("qstat exit value: " + exitValue);

    final List<Job> jobs;
    try {
        jobs = QSTAT_JOBS_PARSER.parse(out.toString());
    } catch (ParseException pe) {
        throw new PBSException("Failed to parse qstat jobs output: " + pe.getMessage(), pe);
    }

    return (jobs == null ? new ArrayList<Job>(0) : jobs);
}

From source file:com.tupilabs.pbs.PBS.java

/**
 * PBS qsub command for an Array Job with Specific PBS_ARRAY_IDs to submit, and resource overrides
 * <p>// w  ww  .  ja  va2  s  .co m
 * Equivalent to qsub -t 1,2,3 -l [resource_name=value,resource_name=value] [param]
 *
 * @param input job input file
 * @param pbsArrayIDs of specified PBS indices
 * @param resourceOverrides list of resource overrides
 * @return job id of array job
 */
public static String qsubArrayJob(String input, List<Integer> pbsArrayIDs, String... resourceOverrides) {
    final CommandLine cmdLine = new CommandLine(COMMAND_QSUB);
    cmdLine.addArgument(PARAMETER_ARRAY_JOB_STATUS);
    String listArgument = StringUtils.join(pbsArrayIDs, ",");
    cmdLine.addArgument(listArgument);
    cmdLine.addArgument(PARAMETER_RESOURCE_OVERRIDE_STATUS);
    String resourceOverrideArgument = StringUtils.join(resourceOverrides, ",");
    cmdLine.addArgument(resourceOverrideArgument);
    cmdLine.addArgument(input);

    final OutputStream out = new ByteArrayOutputStream();
    final OutputStream err = new ByteArrayOutputStream();

    DefaultExecuteResultHandler resultHandler;
    try {
        resultHandler = execute(cmdLine, out, err);
        resultHandler.waitFor(DEFAULT_TIMEOUT);
    } catch (ExecuteException e) {
        throw new PBSException("Failed to execute qsub command: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new PBSException("Failed to execute qsub command: " + e.getMessage(), e);
    } catch (InterruptedException e) {
        throw new PBSException("Failed to execute qsub command: " + e.getMessage(), e);
    }

    final int exitValue = resultHandler.getExitValue();
    LOGGER.info("qsub exit value: " + exitValue);
    LOGGER.fine("qsub output: " + out.toString());

    if (exitValue != 0)
        throw new PBSException("Failed to submit job script " + input + ". Error output: " + err.toString());

    String jobId = out.toString();
    return jobId.trim();
}

From source file:com.tupilabs.pbs.PBS.java

/**
 * PBS qstat command./*from   ww  w .  j  a  v  a  2s . c  o  m*/
 * <p>
 * Equivalent to qstat -Q -f [name]
 *
 * @param name queue name
 * @return list of queues
 */
public static List<Queue> qstatQueues(String name) {
    final CommandLine cmdLine = new CommandLine(COMMAND_QSTAT);
    cmdLine.addArgument(PARAMETER_FULL_STATUS);
    cmdLine.addArgument(PARAMETER_QUEUE);
    if (StringUtils.isNotBlank(name)) {
        cmdLine.addArgument(name);
    }

    final OutputStream out = new ByteArrayOutputStream();
    final OutputStream err = new ByteArrayOutputStream();

    DefaultExecuteResultHandler resultHandler;
    try {
        resultHandler = execute(cmdLine, null, out, err);
        resultHandler.waitFor(DEFAULT_TIMEOUT);
    } catch (ExecuteException e) {
        throw new PBSException("Failed to execute qstat command: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new PBSException("Failed to execute qstat command: " + e.getMessage(), e);
    } catch (InterruptedException e) {
        throw new PBSException("Failed to execute qstat command: " + e.getMessage(), e);
    }

    final int exitValue = resultHandler.getExitValue();
    LOGGER.info("qstat exit value: " + exitValue);

    final List<Queue> queues;
    try {
        queues = QSTAT_QUEUES_PARSER.parse(out.toString());
    } catch (ParseException pe) {
        throw new PBSException("Failed to parse qstat queues output: " + pe.getMessage(), pe);
    }

    return (queues == null ? new ArrayList<Queue>(0) : queues);
}

From source file:com.tupilabs.pbs.PBS.java

/**
 * PBS qstat command for Array Jobs/*from  ww w. jav a 2 s. c o m*/
 * <p>
 * Equivalent to qstat -f -t [param]
 *
 * @param name job name
 * @return list of jobs
 */
public static List<Job> qstatArrayJob(String name) {
    final CommandLine cmdLine = new CommandLine(COMMAND_QSTAT);
    cmdLine.addArgument(PARAMETER_FULL_STATUS);
    cmdLine.addArgument(PARAMETER_ARRAY_JOB_STATUS);
    if (StringUtils.isNotBlank(name)) {
        cmdLine.addArgument(name);
    }

    final OutputStream out = new ByteArrayOutputStream();
    final OutputStream err = new ByteArrayOutputStream();

    DefaultExecuteResultHandler resultHandler;
    try {
        resultHandler = execute(cmdLine, out, err);
        resultHandler.waitFor(DEFAULT_TIMEOUT);
    } catch (ExecuteException e) {
        throw new PBSException("Failed to execute qstat command: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new PBSException("Failed to execute qstat command: " + e.getMessage(), e);
    } catch (InterruptedException e) {
        throw new PBSException("Failed to execute qstat command: " + e.getMessage(), e);
    }

    final int exitValue = resultHandler.getExitValue();
    LOGGER.info("qstat exit value: " + exitValue);

    final List<Job> jobs;
    try {
        jobs = QSTAT_JOBS_PARSER.parse(out.toString());
    } catch (ParseException pe) {
        throw new PBSException("Failed to parse qstat jobs output: " + pe.getMessage(), pe);
    }

    return (jobs == null ? new ArrayList<Job>(0) : jobs);
}

From source file:com.tupilabs.pbs.PBS.java

/**
 * PBS qnodes command./*from  w  w w .j a  v  a2s.c o m*/
 * <p>
 * Get information about the cluster nodes.
 *
 * @param name node name
 * @return list of nodes
 * @throws PBSException if an error communicating with the PBS occurs
 */
public static List<Node> qnodes(String name) {
    final List<Node> nodes;

    final CommandLine cmdLine = new CommandLine(COMMAND_QNODES);
    cmdLine.addArgument(PARAMETER_XML);
    if (StringUtils.isNotBlank(name)) {
        cmdLine.addArgument(name);
    }

    final OutputStream out = new ByteArrayOutputStream();
    final OutputStream err = new ByteArrayOutputStream();

    DefaultExecuteResultHandler resultHandler;
    try {
        resultHandler = execute(cmdLine, null, out, err);
        resultHandler.waitFor(DEFAULT_TIMEOUT);
    } catch (ExecuteException e) {
        throw new PBSException("Failed to execute qnodes command: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new PBSException("Failed to execute qnodes command: " + e.getMessage(), e);
    } catch (InterruptedException e) {
        throw new PBSException("Failed to execute qnodes command: " + e.getMessage(), e);
    }

    final int exitValue = resultHandler.getExitValue();
    LOGGER.info("qnodes exit value: " + exitValue);

    try {
        nodes = NODE_XML_PARSER.parse(out.toString());
    } catch (ParseException pe) {
        throw new PBSException("Failed to parse node XML: " + pe.getMessage(), pe);
    }

    return nodes;
}

From source file:com.creactiviti.piper.plugin.ffmpeg.Ffmpeg.java

@Override
public Object handle(Task aTask) throws Exception {
    List<String> options = aTask.getList("options", String.class);
    CommandLine cmd = new CommandLine("ffmpeg");
    options.forEach(o -> cmd.addArgument(o));
    log.debug("{}", cmd);
    DefaultExecutor exec = new DefaultExecutor();
    File tempFile = File.createTempFile("log", null);
    try (PrintStream stream = new PrintStream(tempFile);) {
        exec.setStreamHandler(new PumpStreamHandler(stream));
        int exitValue = exec.execute(cmd);
        return exitValue != 0 ? FileUtils.readFileToString(tempFile) : cmd.toString();
    } catch (ExecuteException e) {
        throw new ExecuteException(e.getMessage(), e.getExitValue(),
                new RuntimeException(FileUtils.readFileToString(tempFile)));
    } finally {//from  w  w w .  j av a 2 s.  com
        FileUtils.deleteQuietly(tempFile);
    }
}

From source file:com.creactiviti.piper.core.taskhandler.script.Bash.java

@Override
public String handle(Task aTask) throws Exception {
    File scriptFile = File.createTempFile("_script", ".sh");
    File logFile = File.createTempFile("log", null);
    FileUtils.writeStringToFile(scriptFile, aTask.getRequiredString("script"));
    try (PrintStream stream = new PrintStream(logFile);) {
        Process chmod = Runtime.getRuntime().exec(String.format("chmod u+x %s", scriptFile.getAbsolutePath()));
        int chmodRetCode = chmod.waitFor();
        if (chmodRetCode != 0) {
            throw new ExecuteException("Failed to chmod", chmodRetCode);
        }/*  ww  w .j  a v  a 2s.  com*/
        CommandLine cmd = new CommandLine(scriptFile.getAbsolutePath());
        logger.debug("{}", cmd);
        DefaultExecutor exec = new DefaultExecutor();
        exec.setStreamHandler(new PumpStreamHandler(stream));
        exec.execute(cmd);
        return FileUtils.readFileToString(logFile);
    } catch (ExecuteException e) {
        throw new ExecuteException(e.getMessage(), e.getExitValue(),
                new RuntimeException(FileUtils.readFileToString(logFile)));
    } finally {
        FileUtils.deleteQuietly(logFile);
        FileUtils.deleteQuietly(scriptFile);
    }
}

From source file:com.creactiviti.piper.plugin.ffmpeg.Mediainfo.java

@Override
public Map<String, Object> handle(Task aTask) throws Exception {
    CommandLine cmd = new CommandLine("mediainfo");
    cmd.addArgument(aTask.getRequiredString("input"));
    log.debug("{}", cmd);
    DefaultExecutor exec = new DefaultExecutor();
    File tempFile = File.createTempFile("log", null);
    try (PrintStream stream = new PrintStream(tempFile);) {
        exec.setStreamHandler(new PumpStreamHandler(stream));
        exec.execute(cmd);//www .  j  a  va  2s . co m
        return parse(FileUtils.readFileToString(tempFile));
    } catch (ExecuteException e) {
        throw new ExecuteException(e.getMessage(), e.getExitValue(),
                new RuntimeException(FileUtils.readFileToString(tempFile)));
    } finally {
        FileUtils.deleteQuietly(tempFile);
    }
}

From source file:com.creactiviti.piper.plugin.ffmpeg.Ffprobe.java

@Override
public Map<String, Object> handle(Task aTask) throws Exception {
    CommandLine cmd = new CommandLine("ffprobe");
    cmd.addArgument("-v").addArgument("quiet").addArgument("-print_format").addArgument("json")
            .addArgument("-show_error").addArgument("-show_format").addArgument("-show_streams")
            .addArgument(aTask.getRequiredString("input"));
    log.debug("{}", cmd);
    DefaultExecutor exec = new DefaultExecutor();
    File tempFile = File.createTempFile("log", null);
    try (PrintStream stream = new PrintStream(tempFile);) {
        exec.setStreamHandler(new PumpStreamHandler(stream));
        exec.execute(cmd);//from w w  w . j  av  a  2 s  .c o  m
        return parse(FileUtils.readFileToString(tempFile));
    } catch (ExecuteException e) {
        throw new ExecuteException(e.getMessage(), e.getExitValue(),
                new RuntimeException(FileUtils.readFileToString(tempFile)));
    } finally {
        FileUtils.deleteQuietly(tempFile);
    }
}