Search in sources :

Example 21 with ExecutableException

use of org.vcell.util.exe.ExecutableException in project vcell by virtualcell.

the class CommandServiceSsh_sshjTest method testSLURM.

@Test
public void testSLURM() 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[] { "sacctls -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 22 with ExecutableException

use of org.vcell.util.exe.ExecutableException in project vcell by virtualcell.

the class PythonSupport method checkPython.

private static boolean checkPython(File pythonExe) {
    String[] cmd;
    if (OperatingSystemInfo.getInstance().isWindows()) {
        // cmd = new String[] {"cmd", "/C", managedMiniconda.pythonExe.getAbsolutePath(), "--version"};
        cmd = new String[] { pythonExe.getAbsolutePath(), "--version" };
    } else {
        cmd = new String[] { pythonExe.getAbsolutePath(), "--version" };
    }
    IExecutable exe = new Executable(cmd);
    try {
        exe.start(new int[] { 0 });
        System.out.println("Exit value: " + exe.getExitValue());
        System.out.println("stdout=\"" + exe.getStdoutString() + "\"");
        System.out.println("stderr=\"" + exe.getStderrString() + "\"");
        if (exe.getExitValue() != 0) {
            throw new RuntimeException("Python test failed with return code " + exe.getExitValue() + ": " + exe.getStderrString());
        }
        // }
        return true;
    } catch (ExecutableException e) {
        e.printStackTrace();
        throw new RuntimeException("Python test invocation failed: " + e.getMessage(), e);
    }
}
Also used : ExecutableException(org.vcell.util.exe.ExecutableException) IExecutable(org.vcell.util.exe.IExecutable) Executable(org.vcell.util.exe.Executable) IExecutable(org.vcell.util.exe.IExecutable)

Example 23 with ExecutableException

use of org.vcell.util.exe.ExecutableException in project vcell by virtualcell.

the class PythonSupport method checkPackage.

private static boolean checkPackage(File pythonExe, PythonPackage pythonPackage) {
    String[] cmd;
    if (OperatingSystemInfo.getInstance().isWindows()) {
        // cmd = new String[] { "cmd", "/C", condaExe.getAbsolutePath(), "-c", "'import "+pythonPackage.pythonModuleName+"'"};
        cmd = new String[] { pythonExe.getAbsolutePath(), "-c", "\"import " + pythonPackage.pythonModuleName + "\"" };
    } else {
        cmd = new String[] { "bash", "-c", pythonExe.getAbsolutePath() + " -c  'import " + pythonPackage.pythonModuleName + "'" };
    }
    System.out.println(Arrays.asList(cmd).toString());
    IExecutable exe = new Executable(cmd);
    try {
        System.out.println("checking package " + pythonPackage.condaName);
        exe.start(new int[] { 0 });
        System.out.println("Exit value: " + exe.getExitValue());
        System.out.println(exe.getStdoutString());
        System.out.println(exe.getStderrString());
        return true;
    } catch (ExecutableException e) {
        // e.printStackTrace();
        System.out.println("Exit value: " + exe.getExitValue());
        System.out.println(exe.getStdoutString());
        System.out.println(exe.getStderrString());
        return false;
    }
}
Also used : ExecutableException(org.vcell.util.exe.ExecutableException) IExecutable(org.vcell.util.exe.IExecutable) Executable(org.vcell.util.exe.Executable) IExecutable(org.vcell.util.exe.IExecutable)

Example 24 with ExecutableException

use of org.vcell.util.exe.ExecutableException in project vcell by virtualcell.

the class SlurmProxyTest method testSingularitySupport.

@Test
public void testSingularitySupport() throws IOException, ExecutableException {
    CommandServiceSshNative cmd = null;
    try {
        Random r = new Random();
        System.setProperty("log4j2.trace", "true");
        System.setProperty(PropertyLoader.vcellServerIDProperty, "Test2");
        System.setProperty(PropertyLoader.htcLogDirExternal, "/Volumes/vcell/htclogs");
        VCMongoMessage.enabled = false;
        String[] partitions = new String[] { "vcell", "vcell2" };
        System.setProperty(PropertyLoader.slurm_partition, partitions[1]);
        cmd = new CommandServiceSshNative(new String[] { "vcell-service.cam.uchc.edu" }, "vcell", new File("/Users/schaff/.ssh/schaff_rsa"));
        SlurmProxy slurmProxy = new SlurmProxy(cmd, "vcell");
        String jobName = "V_TEST2_999999999_0_" + r.nextInt(10000);
        System.out.println("job name is " + jobName);
        File sub_file_localpath = new File("/Volumes/vcell/htclogs/" + jobName + ".slurm.sub");
        File sub_file_remotepath = new File("/share/apps/vcell3/htclogs/" + jobName + ".slurm.sub");
        StringBuffer subfileContent = new StringBuffer();
        subfileContent.append("#!/usr/bin/bash\n");
        String partition = PropertyLoader.getRequiredProperty(PropertyLoader.slurm_partition);
        subfileContent.append("#SBATCH --partition=" + partition + "\n");
        subfileContent.append("#SBATCH -J " + jobName + "\n");
        subfileContent.append("#SBATCH -o /share/apps/vcell3/htclogs/" + jobName + ".slurm.log\n");
        subfileContent.append("#SBATCH -e /share/apps/vcell3/htclogs/" + jobName + ".slurm.log\n");
        subfileContent.append("#SBATCH --mem=1000M\n");
        subfileContent.append("#SBATCH --no-kill\n");
        subfileContent.append("#SBATCH --no-requeue\n");
        subfileContent.append("env\n");
        subfileContent.append("echo `hostname`\n");
        subfileContent.append("python -c \"some_str = ' ' * 51200000\"\n");
        subfileContent.append("retcode=$?\n");
        subfileContent.append("echo \"return code was $retcode\"\n");
        subfileContent.append("if [[ $retcode == 137 ]]; then\n");
        subfileContent.append("   echo \"job was killed via kill -9 (probably out of memory)\"\n");
        subfileContent.append("fi\n");
        subfileContent.append("sleep 20\n");
        subfileContent.append("exit $retcode\n");
        // subfileContent.append("export MODULEPATH=/isg/shared/modulefiles:/tgcapps/modulefiles\n");
        // subfileContent.append("source /usr/share/Modules/init/bash\n");
        // subfileContent.append("module load singularity\n");
        // subfileContent.append("if command -v singularity >/dev/null 2>&1; then\n");
        // subfileContent.append("   echo 'singularity command exists'\n");
        // subfileContent.append("   exit 0\n");
        // subfileContent.append("else\n");
        // subfileContent.append("   echo 'singularity command not found'\n");
        // subfileContent.append("   exit 1\n");
        // subfileContent.append("fi\n");
        FileUtils.writeStringToFile(sub_file_localpath, subfileContent.toString());
        HtcJobID htcJobId = slurmProxy.submitJobFile(sub_file_remotepath);
        System.out.println("running job " + htcJobId);
        HtcJobInfo htcJobInfo = new HtcJobInfo(htcJobId, jobName);
        ArrayList<HtcJobInfo> jobInfos = new ArrayList<HtcJobInfo>();
        jobInfos.add(htcJobInfo);
        Map<HtcJobInfo, HtcJobStatus> jobStatusMap = slurmProxy.getJobStatus(jobInfos);
        int attempts = 0;
        while (attempts < 80 && (jobStatusMap.get(htcJobInfo) == null || !jobStatusMap.get(htcJobInfo).isDone())) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
            jobStatusMap = slurmProxy.getJobStatus(jobInfos);
            System.out.println(jobStatusMap.get(htcJobInfo));
            if (attempts == 5) {
                slurmProxy.killJobs(jobName);
            }
            attempts++;
        }
        System.out.println(jobStatusMap.get(htcJobInfo));
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    } finally {
        if (cmd != null) {
            cmd.close();
        }
    }
}
Also used : HtcJobStatus(cbit.vcell.message.server.htc.HtcJobStatus) ArrayList(java.util.ArrayList) HtcJobInfo(cbit.vcell.message.server.htc.HtcProxy.HtcJobInfo) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ExecutableException(org.vcell.util.exe.ExecutableException) Random(java.util.Random) HtcJobID(cbit.vcell.server.HtcJobID) File(java.io.File) CommandServiceSshNative(cbit.vcell.message.server.cmd.CommandServiceSshNative) Test(org.junit.Test)

Aggregations

ExecutableException (org.vcell.util.exe.ExecutableException)24 IOException (java.io.IOException)14 File (java.io.File)13 CommandOutput (cbit.vcell.message.server.cmd.CommandService.CommandOutput)9 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Executable (org.vcell.util.exe.Executable)5 IExecutable (org.vcell.util.exe.IExecutable)4 HtcJobNotFoundException (cbit.vcell.message.server.htc.HtcJobNotFoundException)3 HtcJobID (cbit.vcell.server.HtcJobID)3 PrintWriter (java.io.PrintWriter)3 CommandServiceSshNative (cbit.vcell.message.server.cmd.CommandServiceSshNative)2 HtcJobStatus (cbit.vcell.message.server.htc.HtcJobStatus)2 HtcJobInfo (cbit.vcell.message.server.htc.HtcProxy.HtcJobInfo)2 InstallStatus (cbit.vcell.resource.PythonSupport.InstallStatus)2 FileWriter (java.io.FileWriter)2 MalformedURLException (java.net.MalformedURLException)2 SocketTimeoutException (java.net.SocketTimeoutException)2 URISyntaxException (java.net.URISyntaxException)2 StringTokenizer (java.util.StringTokenizer)2