Search in sources :

Example 11 with Executable

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

the class VisitSupport method launchVisTool.

public static void launchVisTool(File visitExecutable, SimulationDataSetRef simulationDataSetRef) throws IOException, ExecutableException, URISyntaxException, InterruptedException {
    if (OperatingSystemInfo.getInstance().isMac()) {
        launchVisToolMac(visitExecutable);
        return;
    } else if (OperatingSystemInfo.getInstance().isLinux()) {
        launchVisToolLinux(visitExecutable);
        return;
    }
    // MSWindows
    if (visitExecutable == null) {
        visitExecutable = ResourceUtil.getExecutable(VISIT_EXEC_NAME, false);
        if (visitExecutable == null || !visitExecutable.exists() || !visitExecutable.isFile()) {
            throw new IOException("visit executable not found, " + visitExecutable.getAbsolutePath());
        }
    }
    VCellConfiguration.setFileProperty(PropertyLoader.visitExe, visitExecutable);
    File visMainCLI = getVisToolPythonScript();
    if (!visMainCLI.exists() || !visMainCLI.isFile()) {
        throw new IOException("vcell/visit main python file not found, " + visMainCLI.getAbsolutePath());
    }
    if (lg.isInfoEnabled()) {
        lg.info("Starting VCellVisIt as a sub-process");
    }
    // 
    // 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);
        envVarList.add(varname + "=" + value);
    }
    String siteName = ResourceUtil.getSiteName();
    File vcellHomeVisFolder = new File(new File(ResourceUtil.getVcellHome(), "Vis"), siteName);
    if (!vcellHomeVisFolder.exists()) {
        if (!vcellHomeVisFolder.mkdirs()) {
            throw new IOException("Cannot create directory " + vcellHomeVisFolder.getCanonicalPath());
        }
    }
    // FileUtils.copyDirectoryShallow(visMainCLI.getParentFile(), vcellHomeVisFolder);
    FileUtils.copyDirectory(visMainCLI.getParentFile(), vcellHomeVisFolder, true, new VisitFolderFileFilter());
    File vcellHomeVisMainCLI = new File(vcellHomeVisFolder, visMainCLI.getName());
    vcellHomeVisMainCLI.setExecutable(true);
    envVarList.add("visitcmd=" + /*"\""+*/
    visitExecutable.getPath());
    envVarList.add("pythonscript=" + vcellHomeVisMainCLI.getPath().replace("\\", "/"));
    // envVarList.add("pythonscript="+visMainCLI.toURI().toASCIIString());
    final String[] cmdStringArray = new String[] { "cmd", "/K", "start", "\"\"", visitExecutable.getPath(), "-cli", "-uifile", vcellHomeVisMainCLI.getPath().replace("\\", "/") };
    if (simulationDataSetRef != null) {
        File simDataSetRefFile = new File(ResourceUtil.getLocalVisDataDir(), "SimID_" + simulationDataSetRef.getSimId() + "_" + simulationDataSetRef.getJobIndex() + "_.simref");
        VisMeshUtils.writeSimulationDataSetRef(simDataSetRefFile, simulationDataSetRef);
        envVarList.add("INITIALSIMDATAREFFILE=" + simDataSetRefFile.getPath().replace("\\", "/"));
    }
    // @SuppressWarnings("unused")
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Executable exec = new Executable(cmdStringArray);
                // Executable exec = new Executable(new String[] {st});
                for (String var : envVarList) {
                    StringTokenizer st2 = new StringTokenizer(var, "=");
                    exec.addEnvironmentVariable(st2.nextToken(), st2.nextToken());
                }
                exec.start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();
    if (lg.isInfoEnabled()) {
        lg.info("Started VCellVisIt");
    }
/*
			List<String> cmds = new ArrayList<String>();
			cmds.add(visitExecutable.getAbsolutePath());
			cmds.add("-cli");
			cmds.add("-ufile");
			cmds.add(script.getAbsolutePath());
			ProcessBuilder pb = new ProcessBuilder(cmds);
			final Process p = pb.start();
			Runnable mon = new Runnable() {
				
				@Override
				public void run() {
					try {
						System.err.println("waiting for visit");
						p.waitFor();
						int rcode = p.exitValue();
						System.err.println("visit exit code " + rcode);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			};
			new Thread(mon).start();
			*/
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ExecutableException(org.vcell.util.exe.ExecutableException) StringTokenizer(java.util.StringTokenizer) Executable(org.vcell.util.exe.Executable) File(java.io.File)

Example 12 with Executable

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

the class NagiosVCellMonitor method getPidOnPortLinuxLocal.

public static Integer getPidOnPortLinuxLocal(int port) throws Exception {
    // lsof -iTCP -sTCP:LISTEN -P -n
    Executable executable = new Executable(createLSOFPort_LinuxCmdParams(port));
    try {
        executable.start();
    } catch (Exception e) {
        // this can happen is there are no processes we have permission to list
        // assume the other monitor isn't running
        e.printStackTrace();
        return null;
    }
    String s = executable.getStdoutString();
    return parseLSOF_ReturnPID(s, port);
}
Also used : BigString(org.vcell.util.BigString) Executable(org.vcell.util.exe.Executable) IOException(java.io.IOException)

Aggregations

Executable (org.vcell.util.exe.Executable)12 ExecutableException (org.vcell.util.exe.ExecutableException)7 File (java.io.File)6 IOException (java.io.IOException)6 Variable (cbit.vcell.math.Variable)3 SimulationTask (cbit.vcell.messaging.server.SimulationTask)3 ODESolverResultSet (cbit.vcell.solver.ode.ODESolverResultSet)3 PrintWriter (java.io.PrintWriter)3 VCLogger (cbit.util.xml.VCLogger)2 BioModel (cbit.vcell.biomodel.BioModel)2 MathMapping (cbit.vcell.mapping.MathMapping)2 SimulationContext (cbit.vcell.mapping.SimulationContext)2 MathDescription (cbit.vcell.math.MathDescription)2 Model (cbit.vcell.model.Model)2 ReservedSymbol (cbit.vcell.model.Model.ReservedSymbol)2 ErrorTolerance (cbit.vcell.solver.ErrorTolerance)2 Simulation (cbit.vcell.solver.Simulation)2 SimulationJob (cbit.vcell.solver.SimulationJob)2 SolverException (cbit.vcell.solver.SolverException)2 TimeBounds (cbit.vcell.solver.TimeBounds)2