Search in sources :

Example 1 with CommandOutput

use of cbit.vcell.message.server.cmd.CommandService.CommandOutput in project vcell by virtualcell.

the class SlurmProxy method getJobStatus.

@Override
public Map<HtcJobID, JobInfoAndStatus> getJobStatus(List<HtcJobID> htcJobIDs) throws ExecutableException, IOException {
    ArrayList<String> jobNumbers = new ArrayList<String>();
    for (HtcJobID job : htcJobIDs) {
        jobNumbers.add(Long.toString(job.getJobNumber()));
    }
    String jobList = String.join(",", jobNumbers);
    String[] cmds = { Slurm_HOME + JOB_CMD_STATUS, "-u", "vcell", "-P", "-j", jobList, "-o", "jobid%25,jobname%25,partition,user,alloccpus,ncpus,ntasks,state%13,exitcode" };
    CommandOutput commandOutput = commandService.command(cmds);
    String output = commandOutput.getStandardOutput();
    Map<HtcJobID, JobInfoAndStatus> statusMap = extractJobIds(output);
    return statusMap;
}
Also used : CommandOutput(cbit.vcell.message.server.cmd.CommandService.CommandOutput) ArrayList(java.util.ArrayList) HtcJobID(cbit.vcell.server.HtcJobID)

Example 2 with CommandOutput

use of cbit.vcell.message.server.cmd.CommandService.CommandOutput in project vcell by virtualcell.

the class SlurmProxy method submitJobFile.

HtcJobID submitJobFile(File sub_file_external) throws ExecutableException {
    final String JOB_CMD_SBATCH = PropertyLoader.getProperty(PropertyLoader.slurm_cmd_sbatch, "sbatch");
    String[] completeCommand = new String[] { JOB_CMD_SBATCH, sub_file_external.getAbsolutePath() };
    if (LG.isDebugEnabled()) {
        LG.debug("submitting SLURM job: '" + CommandOutput.concatCommandStrings(completeCommand) + "'");
    }
    CommandOutput commandOutput = commandService.command(completeCommand);
    String jobid = commandOutput.getStandardOutput().trim();
    final String EXPECTED_STDOUT_PREFIX = "Submitted batch job ";
    if (jobid.startsWith(EXPECTED_STDOUT_PREFIX)) {
        jobid = jobid.replace(EXPECTED_STDOUT_PREFIX, "");
    } else {
        LG.error("failed to submit SLURM job '" + sub_file_external + "', stdout='" + commandOutput.getStandardOutput() + "', stderr='" + commandOutput.getStandardError() + "'");
        throw new ExecutableException("unexpected response from '" + JOB_CMD_SBATCH + "' while submitting simulation: '" + jobid + "'");
    }
    HtcJobID htcJobID = new HtcJobID(jobid, BatchSystemType.SLURM);
    if (LG.isDebugEnabled()) {
        LG.debug("SLURM job '" + CommandOutput.concatCommandStrings(completeCommand) + "' started as htcJobId '" + htcJobID + "'");
    }
    return htcJobID;
}
Also used : ExecutableException(org.vcell.util.exe.ExecutableException) CommandOutput(cbit.vcell.message.server.cmd.CommandService.CommandOutput) HtcJobID(cbit.vcell.server.HtcJobID)

Example 3 with CommandOutput

use of cbit.vcell.message.server.cmd.CommandService.CommandOutput in project vcell by virtualcell.

the class SlurmProxy method killJobSafe.

@Override
public void killJobSafe(HtcJobInfo htcJobInfo) throws ExecutableException, HtcException {
    final String JOB_CMD_DELETE = PropertyLoader.getProperty(PropertyLoader.slurm_cmd_scancel, "scancel");
    String[] cmd = new String[] { JOB_CMD_DELETE, "--jobname", htcJobInfo.getJobName(), Long.toString(htcJobInfo.getHtcJobID().getJobNumber()) };
    try {
        // CommandOutput commandOutput = commandService.command(cmd, new int[] { 0, QDEL_JOB_NOT_FOUND_RETURN_CODE });
        if (LG.isDebugEnabled()) {
            LG.debug("killing SLURM job htcJobId=" + htcJobInfo + ": '" + CommandOutput.concatCommandStrings(cmd) + "'");
        }
        CommandOutput commandOutput = commandService.command(cmd, new int[] { 0, SCANCEL_JOB_NOT_FOUND_RETURN_CODE });
        Integer exitStatus = commandOutput.getExitStatus();
        String standardOut = commandOutput.getStandardOutput();
        if (exitStatus != null && exitStatus.intValue() == SCANCEL_JOB_NOT_FOUND_RETURN_CODE && standardOut != null && standardOut.toLowerCase().contains(SCANCEL_UNKNOWN_JOB_RESPONSE.toLowerCase())) {
            LG.error("failed to cancel SLURM htcJobId=" + htcJobInfo + ", job not found");
            throw new HtcJobNotFoundException(standardOut, htcJobInfo);
        }
    } catch (ExecutableException e) {
        LG.error("failed to cancel SLURM htcJobId=" + htcJobInfo, e);
        if (!e.getMessage().toLowerCase().contains(SCANCEL_UNKNOWN_JOB_RESPONSE.toLowerCase())) {
            throw e;
        } else {
            throw new HtcJobNotFoundException(e.getMessage(), htcJobInfo);
        }
    }
}
Also used : ExecutableException(org.vcell.util.exe.ExecutableException) HtcJobNotFoundException(cbit.vcell.message.server.htc.HtcJobNotFoundException) CommandOutput(cbit.vcell.message.server.cmd.CommandService.CommandOutput)

Example 4 with CommandOutput

use of cbit.vcell.message.server.cmd.CommandService.CommandOutput in project vcell by virtualcell.

the class CommandServiceSshNativeTest method test.

@Test
public void test() throws IOException, ExecutableException {
    CommandServiceSshNative cmd = null;
    try {
        cmd = new CommandServiceSshNative(new String[] { "vcell-service.cam.uchc.edu" }, "vcell", new File("/Users/schaff/.ssh/schaff_rsa"));
        System.out.println("after created cmdService");
        CommandOutput output = cmd.command(new String[] { "ls -al | head -4" });
        System.out.println("ls output is: " + output.getStandardOutput());
        output = cmd.command(new String[] { "ls -al | head -9" });
        System.out.println("ls output is: " + output.getStandardOutput());
        output = cmd.command(new String[] { "ls -al | head -4" });
        System.out.println("ls output is: " + output.getStandardOutput());
    } catch (Exception e) {
        e.printStackTrace();
        fail("exception thrown: " + e.getMessage());
    } finally {
        if (cmd != null) {
            cmd.close();
        }
    }
}
Also used : CommandOutput(cbit.vcell.message.server.cmd.CommandService.CommandOutput) File(java.io.File) IOException(java.io.IOException) ExecutableException(org.vcell.util.exe.ExecutableException) Test(org.junit.Test)

Example 5 with CommandOutput

use of cbit.vcell.message.server.cmd.CommandService.CommandOutput in project vcell by virtualcell.

the class CommandServiceSsh_sshjTest method test.

@Test
public void test() throws IOException, ExecutableException {
    CommandServiceSsh_sshj cmd = null;
    try {
        cmd = new CommandServiceSsh_sshj("vcell-service.cam.uchc.edu", "vcell", new File("/Users/schaff/.ssh/schaff_rsa"));
        System.out.println("after created cmdService");
        CommandOutput output = cmd.command(new String[] { "ls -al | head -4" });
        System.out.println("ls output is: " + output.getStandardOutput());
        output = cmd.command(new String[] { "ls -al | head -9" });
        System.out.println("ls output is: " + output.getStandardOutput());
        output = cmd.command(new String[] { "ls -al | head -4" });
        System.out.println("ls output is: " + output.getStandardOutput());
    } catch (Exception e) {
        e.printStackTrace();
        fail("exception thrown: " + e.getMessage());
    } finally {
        if (cmd != null) {
            cmd.close();
        }
    }
}
Also used : CommandOutput(cbit.vcell.message.server.cmd.CommandService.CommandOutput) File(java.io.File) IOException(java.io.IOException) ExecutableException(org.vcell.util.exe.ExecutableException) Test(org.junit.Test)

Aggregations

CommandOutput (cbit.vcell.message.server.cmd.CommandService.CommandOutput)16 ExecutableException (org.vcell.util.exe.ExecutableException)11 IOException (java.io.IOException)7 File (java.io.File)6 HtcJobNotFoundException (cbit.vcell.message.server.htc.HtcJobNotFoundException)4 Test (org.junit.Test)4 HtcJobID (cbit.vcell.server.HtcJobID)3 ArrayList (java.util.ArrayList)3 HtcJobStatus (cbit.vcell.message.server.htc.HtcJobStatus)2 StringTokenizer (java.util.StringTokenizer)2 RollbackException (cbit.vcell.message.RollbackException)1 VCMessagingException (cbit.vcell.message.VCMessagingException)1 CommandService (cbit.vcell.message.server.cmd.CommandService)1 CommandServiceLocal (cbit.vcell.message.server.cmd.CommandServiceLocal)1 CommandServiceSshNative (cbit.vcell.message.server.cmd.CommandServiceSshNative)1 HtcException (cbit.vcell.message.server.htc.HtcException)1 HtcProxy (cbit.vcell.message.server.htc.HtcProxy)1 BatchSystemType (cbit.vcell.server.HtcJobID.BatchSystemType)1 SolverException (cbit.vcell.solver.SolverException)1 XmlParseException (cbit.vcell.xml.XmlParseException)1