Search in sources :

Example 6 with ExecutableException

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

the class SlurmProxyTest method testSLURM.

// @Before
// public void setEnv() {
// //System.setProperty(PropertyLoader.htcSlurmHome,"/opt/slurm/");
// System.setProperty( PropertyLoader.htcLogDirExternal,"/home/htcLogs");
// System.setProperty( PropertyLoader.MPI_HOME_EXTERNAL,"/opt/mpich/");
// }
// 
// private void write(String name, String text) {
// try {
// File f = new File(name);
// HtcProxy.writeUnixStyleTextFile(f, text);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// 
// private void addExit(Container ctn) {
// final String eToken = "yada-yada";
// ExecutableCommand exitC = new ExecutableCommand(null,"echo",eToken);
// exitC.setExitCodeToken(eToken);
// ctn.add(exitC);
// 
// }
// 
// @Test
// public void tryIt( ) {
// Container ctn = new ExecutableCommand.Container();
// ExecutableCommand listdog = new ExecutableCommand(null,"ls");
// listdog.addArgument("dog");
// ctn.add(listdog);
// ctn.add(new ExecutableCommand(null,"wc","dog"));
// SlurmProxy spProxy = new SlurmProxy(null, "gerard");
// String text = spProxy.generateScript("Q_3", ctn, 1, 10.0, null);
// write("out.sh",text);
// }
// 
// @Test
// public void tryItWithExit( ) {
// Container ctn = new ExecutableCommand.Container();
// ctn.add(new ExecutableCommand(null,"ls","dog"));
// ctn.add(new ExecutableCommand(null,"wc","dog"));
// addExit(ctn);
// 
// SlurmProxy spProxy = new SlurmProxy(null, "gerard");
// String text = spProxy.generateScript("Q_3", ctn, 1, 10.0, null);
// write("outexit.sh",text);
// }
// 
// @Test(expected=UnsupportedOperationException.class)
// public void tryParallelBad( ) {
// Container ctn = new ExecutableCommand.Container();
// ctn.add(new ExecutableCommand(null,true,true,"wc","dog"));
// SlurmProxy spProxy = new SlurmProxy(null, "gerard");
// spProxy.generateScript("Q_3", ctn, 1, 10.0, null);
// }
// 
// @Test
// public void tryParallel( ) {
// Container ctn = new ExecutableCommand.Container();
// ctn.add(new ExecutableCommand(null,"ls","dog"));
// ctn.add(new ExecutableCommand(null,true,true,"wc","dog"));
// SlurmProxy spProxy = new SlurmProxy(null, "gerard");
// String text = spProxy.generateScript("Q_3", ctn, 4, 10.0, null);
// write("par.sh",text);
// }
// @Test
// public void tryParallelExit( ) {
// Container ctn = new ExecutableCommand.Container();
// addExit(ctn);
// ctn.add(new ExecutableCommand(null,"ls","dog"));
// ctn.add(new ExecutableCommand(null,true,true,"wc","dog"));
// SlurmProxy spProxy = new SlurmProxy(null, "gerard");
// String text = spProxy.generateScript("Q_3", ctn, 4, 10.0, null);
// write("parexit.sh",text);
// }
@Test
public void testSLURM() throws IOException, ExecutableException {
    System.setProperty(PropertyLoader.vcellServerIDProperty, "Test2");
    System.setProperty(PropertyLoader.htcLogDirExternal, "/Volumes/vcell/htclogs");
    VCMongoMessage.enabled = false;
    CommandServiceSshNative cmd = null;
    try {
        // for (int i=0;i<10000;i++) {
        cmd = new CommandServiceSshNative("vcell-service.cam.uchc.edu", "vcell", new File("/Users/schaff/.ssh/schaff_rsa"));
        SlurmProxy slurmProxy = new SlurmProxy(cmd, "vcell");
        Map<HtcJobID, JobInfoAndStatus> runningJobs = slurmProxy.getRunningJobs();
        for (HtcJobID job : runningJobs.keySet()) {
            HtcJobStatus jobStatus = runningJobs.get(job).status;
            System.out.println("job " + job.toString() + ", status=" + jobStatus.toString());
        }
        System.out.println("\n\n\n");
        Thread.sleep(100);
    // }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (cmd != null) {
            cmd.close();
        }
    }
}
Also used : HtcJobStatus(cbit.vcell.message.server.htc.HtcJobStatus) HtcJobID(cbit.vcell.server.HtcJobID) File(java.io.File) CommandServiceSshNative(cbit.vcell.message.server.cmd.CommandServiceSshNative) JobInfoAndStatus(cbit.vcell.message.server.htc.HtcProxy.JobInfoAndStatus) IOException(java.io.IOException) ExecutableException(org.vcell.util.exe.ExecutableException) Test(org.junit.Test)

Example 7 with ExecutableException

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

the class BioformatsImageDatasetReader method launchServer.

private void launchServer(int port) {
    synchronized (BioformatsImageDatasetReader.class) {
        if (serverThread != null) {
            return;
        }
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                Executable executable = new Executable(new String[] { "java", "-jar", bioformatsExecutableJarFile.getAbsolutePath(), Integer.toString(port) });
                try {
                    executable.start();
                } catch (ExecutableException e) {
                    e.printStackTrace();
                    serverThread = null;
                }
            }
        };
        serverThread = new Thread(runnable, "bioformatsServerThread");
        serverThread.setDaemon(true);
        serverThread.start();
        try {
            // give some time for the service to start listening
            Thread.sleep(2000);
        } catch (InterruptedException e) {
        }
    }
}
Also used : ExecutableException(org.vcell.util.exe.ExecutableException) Executable(org.vcell.util.exe.Executable)

Example 8 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 9 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 10 with ExecutableException

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

the class VisitSupport method launchVisToolLinux.

public static void launchVisToolLinux(File visitExecutable) throws ExecutableException, IOException {
    File mpirun = null;
    if (visitExecutable == null) {
        File userDir = new File(System.getProperty("user.home"));
        System.out.println(userDir.getAbsolutePath() + " " + userDir.exists());
        // find -L ~/ -name 'visit' -executable -type f -print
        // 'find -L /home/frm -name 'visit' -executable -type f -print'
        Executable exec = new Executable(new String[] { "/bin/sh", "-c", "find -L " + userDir.getAbsolutePath() + " -maxdepth 4 -name 'visit' -executable -type f -print" });
        // exec.setWorkingDir(userDir);
        exec.start();
        System.out.println(exec.getExitValue());
        System.out.println(exec.getStdoutString());
        // System.out.println(exec.getStderrString());
        if (exec.getExitValue() == 0) {
            visitExecutable = new File(exec.getStdoutString().trim());
        }
        // look for mpirun starting 2 levels above visit executable dir location
        exec = new Executable(new String[] { "/bin/sh", "-c", "find -L " + visitExecutable.getParentFile().getParent() + " -maxdepth 6 -name 'mpirun' -executable -type f -print" });
        exec.start();
        System.out.println(exec.getExitValue());
        System.out.println(exec.getStdoutString());
        System.err.println(exec.getStderrString());
        // System.out.println(exec.getStderrString());
        if (exec.getExitValue() == 0) {
            String mpiStr = exec.getStdoutString();
            if (mpiStr != null) {
                mpiStr = mpiStr.trim();
            }
            if (mpiStr != null && mpiStr.length() != 0) {
                mpirun = new File(mpiStr);
            } else {
                mpirun = null;
            }
        }
        if (mpirun == null) {
            // See if any mpi run installed
            exec = new Executable(new String[] { "/bin/sh", "-c", "which mpirun" });
            exec.start();
            System.out.println(exec.getExitValue());
            System.out.println(exec.getStdoutString());
            System.out.println(exec.getStderrString());
            if (exec.getExitValue() == 0) {
                String mpiStr = exec.getStdoutString();
                if (mpiStr != null) {
                    mpiStr = mpiStr.trim();
                }
                if (mpiStr != null && mpiStr.length() != 0) {
                    mpirun = new File(mpiStr);
                } else {
                    mpirun = null;
                }
            }
        }
    }
    System.out.println(visitExecutable.getAbsolutePath());
    if (visitExecutable == null || !visitExecutable.exists() || !visitExecutable.isFile()) {
        throw new IOException("visit executable not found");
    }
    VCellConfiguration.setFileProperty(PropertyLoader.visitExe, visitExecutable);
    System.out.println(mpirun.getAbsolutePath());
    if (mpirun == null || !mpirun.exists() || !mpirun.isFile()) {
        throw new IOException("mpirun executable not found");
    }
    File visMainCLI = getVisToolPythonScript();
    if (!visMainCLI.exists() || !visMainCLI.isFile()) {
        throw new IOException("vcell/visit main python file not found, " + visMainCLI.getAbsolutePath());
    }
    File scriptFile = File.createTempFile("VCellVisitLaunch", ".command");
    System.out.println("Launch script location=" + scriptFile.getAbsolutePath());
    Executable exec = new Executable(new String[] { /*"/bin/sh","-c",*/
    scriptFile.getAbsolutePath() });
    // 
    // get existing environment variables and add visit command and python script to it.
    // 
    Map<String, String> envVariables = System.getenv();
    ArrayList<String> envVarList = new ArrayList<String>();
    for (String varname : envVariables.keySet()) {
        String value = envVariables.get(varname);
        if (varname.equals("PATH")) {
            value = value + ":" + visitExecutable.getParent();
        }
        // envVarList.add(varname+"="+value);
        exec.addEnvironmentVariable(varname, value);
        System.out.println(varname + "=" + value);
    }
    String visitCommandString = visitExecutable.getPath().replace("\"", "");
    System.out.println("Visit Command String = " + visitCommandString);
    // envVarList.add(visitCommandString);
    if (lg.isInfoEnabled()) {
        lg.info("visitcmd=" + visitExecutable.getPath().replace("\"", ""));
    }
    // envVarList.add("pythonscript="+visMainCLI.getPath());
    String pythonScriptString = visMainCLI.getPath();
    System.out.println("Python script = " + pythonScriptString);
    scriptFile.setExecutable(true);
    BufferedWriter writer = new BufferedWriter(new FileWriter(scriptFile));
    // export PATH="$HOME/opt/bin:$PATH"
    System.out.println("export PATH=\"$PATH:" + mpirun.getParent() + "\"\n");
    writer.append("export PATH=\"$PATH:" + mpirun.getParent() + "\"\n");
    System.out.println(visitCommandString + " -cli -uifile " + pythonScriptString + "\n");
    writer.append(visitCommandString + " -cli -uifile " + pythonScriptString + "\n");
    writer.close();
    // cli
    // mdserver
    // engine_ser
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                exec.start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();
    // envVarList.toArray(new String[0]));
    if (lg.isInfoEnabled()) {
        lg.info("Started VCellVisIt");
    }
}
Also used : FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Executable(org.vcell.util.exe.Executable) File(java.io.File) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ExecutableException(org.vcell.util.exe.ExecutableException) BufferedWriter(java.io.BufferedWriter)

Aggregations

ExecutableException (org.vcell.util.exe.ExecutableException)19 File (java.io.File)12 IOException (java.io.IOException)12 CommandOutput (cbit.vcell.message.server.cmd.CommandService.CommandOutput)6 Test (org.junit.Test)5 Executable (org.vcell.util.exe.Executable)5 ArrayList (java.util.ArrayList)4 IExecutable (org.vcell.util.exe.IExecutable)4 InstallStatus (cbit.vcell.resource.PythonSupport.InstallStatus)2 HtcJobID (cbit.vcell.server.HtcJobID)2 FileWriter (java.io.FileWriter)2 PrintWriter (java.io.PrintWriter)2 SocketTimeoutException (java.net.SocketTimeoutException)2 URISyntaxException (java.net.URISyntaxException)2 StringTokenizer (java.util.StringTokenizer)2 CommandServiceSshNative (cbit.vcell.message.server.cmd.CommandServiceSshNative)1 HtcJobNotFoundException (cbit.vcell.message.server.htc.HtcJobNotFoundException)1 HtcJobStatus (cbit.vcell.message.server.htc.HtcJobStatus)1 JobInfoAndStatus (cbit.vcell.message.server.htc.HtcProxy.JobInfoAndStatus)1 OperatingSystemInfo (cbit.vcell.resource.OperatingSystemInfo)1