use of org.vcell.util.exe.ExecutableException in project vcell by virtualcell.
the class BNGExecutorServiceNative method executeBNG.
/**
* Insert the method's description here.
* Creation date: (6/23/2005 3:57:30 PM)
*/
@Override
public BNGOutput executeBNG() throws BNGException {
if (executable != null) {
throw new BNGException("You can only run BNG one at a time!");
}
BNGOutput bngOutput = null;
startTime = System.currentTimeMillis();
File workingDir = null;
try {
workingDir = Files.createTempDirectory("Bng_working_").toFile();
File bngInputFile = null;
FileOutputStream fos = null;
String tempFilePrefix = workingDir.getName();
try {
bngInputFile = new File(workingDir, tempFilePrefix + suffix_input);
fos = new java.io.FileOutputStream(bngInputFile);
} catch (java.io.IOException e) {
if (LG.isWarnEnabled()) {
LG.warn("error opening input file '" + bngInputFile, e);
}
e.printStackTrace(System.out);
throw new RuntimeException("error opening input file '" + bngInputFile.getName() + ": " + e.getMessage());
}
PrintWriter inputFile = new PrintWriter(fos);
System.out.println("Input file is: " + bngInputFile.getPath());
inputFile.print(bngInput.getInputString());
inputFile.close();
// System.out.println("BNGExecutorService.executeBNG(): input = \n"+bngInput.getInputString());
String[] cmd = null;
OperatingSystemInfo osi = OperatingSystemInfo.getInstance();
if (osi.isWindows()) {
System.out.println("BNGExecutorService.executeBNG() " + (osi.is64bit() ? "64bit" : "32bit") + " as standalone executable\n");
cmd = new String[] { ResourceUtil.getBNG2StandaloneWin(osi.is64bit()), bngInputFile.getAbsolutePath() };
} else {
// Execute as perl script
System.out.println("BNGExecutorService.executeBNG() as perl script\n");
String bngPerlFilePath = ResourceUtil.getBNG2_perl_file();
cmd = new String[] { ResourceUtil.getPerlExe().getAbsolutePath(), bngPerlFilePath, bngInputFile.getAbsolutePath() };
}
// run BNG
long timeoutMS = 0;
if (timeoutDurationMS != null) {
timeoutMS = timeoutDurationMS.longValue();
}
executable = new BioNetGenExecutable(cmd, timeoutMS, workingDir);
executable.addEnvironmentVariable("LD_LIBRARY_PATH", "");
executable.inheritCallbacks(getCallbacks());
int[] expectedReturnCodes = new int[] { 0 };
executable.start(expectedReturnCodes);
String stdoutString;
if (executable.getStatus() != org.vcell.util.exe.ExecutableStatus.STOPPED) {
stdoutString = executable.getStdoutString();
} else {
stdoutString = "Stopped by user. Output from BioNetGen may be truncated";
}
if (executable.getExitValue() == 1) {
String stderrString = executable.getStderrString();
if (stderrString.contains("run_network")) {
stdoutString = "run_network not supported on this operating system; partial data may be available\n" + executable.getStdoutString();
}
}
File[] files = workingDir.listFiles();
ArrayList<String> filenames = new ArrayList<String>();
ArrayList<String> filecontents = new ArrayList<String>();
for (File file : files) {
String filename = file.getName();
if (LG.isDebugEnabled()) {
LG.debug("BNG executor trying to read " + filename);
}
filenames.add(filename);
filecontents.add(FileUtils.readFileToString(file));
}
bngOutput = new BNGOutput(stdoutString, filenames.toArray(new String[0]), filecontents.toArray(new String[0]));
} catch (ExecutableException | IOException ex) {
if (LG.isWarnEnabled()) {
LG.warn("error executable BNG", ex);
}
if (executable == null || executable.getStderrString().trim().length() == 0) {
throw new BNGException("Error executing BNG", ex);
}
throw new BNGException(executable.getStderrString(), ex);
} finally {
if (workingDir != null) {
File[] files = workingDir.listFiles();
for (File file : files) {
file.delete();
}
workingDir.delete();
}
}
return bngOutput;
}
use of org.vcell.util.exe.ExecutableException in project vcell by virtualcell.
the class CopasiServicePython method runCopasiPython.
public static void runCopasiPython(File copasiOptProblemFile, File copasiResultsFile) throws IOException {
// It's 2015 -- forward slash works for all operating systems
File PYTHON = PythonSupport.getPythonExe();
InstallStatus copasiInstallStatus = PythonSupport.getPythonPackageStatus(PythonPackage.COPASI);
if (copasiInstallStatus == InstallStatus.FAILED) {
throw new RuntimeException("failed to install COPASI python package, consider re-installing VCell-managed python\n ...see Preferences->Python->Re-install");
}
if (copasiInstallStatus == InstallStatus.INITIALIZING) {
throw new RuntimeException("VCell is currently installing or verifying the COPASI python package ... please try again in a minute");
}
File vcellOptDir = ResourceUtil.getVCellOptPythonDir();
File optServicePythonFile = new File(vcellOptDir, "optService.py");
if (PYTHON == null || !PYTHON.exists()) {
throw new RuntimeException("python executable not specified, set python location in VCell menu File->Preferences...->Python Properties");
}
String[] cmd = new String[] { PYTHON.getAbsolutePath(), optServicePythonFile.getAbsolutePath(), copasiOptProblemFile.getAbsolutePath(), copasiResultsFile.getAbsolutePath() };
IExecutable exe = prepareExecutable(cmd);
try {
exe.start(new int[] { 0 });
if (exe.getExitValue() != 0) {
throw new RuntimeException("copasi python solver (optService.py) failed with return code " + exe.getExitValue() + ": " + exe.getStderrString());
}
} catch (ExecutableException e) {
e.printStackTrace();
throw new RuntimeException("optService.py invocation failed: " + e.getMessage(), e);
}
}
use of org.vcell.util.exe.ExecutableException 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;
}
use of org.vcell.util.exe.ExecutableException 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);
}
}
}
use of org.vcell.util.exe.ExecutableException in project vcell by virtualcell.
the class SlurmProxyTest method testSLURM.
@Test
public void testSLURM() throws IOException, ExecutableException {
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[0]);
CommandServiceSshNative cmd = null;
try {
cmd = new CommandServiceSshNative(new String[] { "vcell-service.cam.uchc.edu" }, "vcell", new File("/Users/schaff/.ssh/schaff_rsa"));
SlurmProxy slurmProxy = new SlurmProxy(cmd, "vcell");
Map<HtcJobInfo, HtcJobStatus> runningJobs = slurmProxy.getRunningJobs();
for (HtcJobInfo jobInfo : runningJobs.keySet()) {
HtcJobStatus jobStatus = runningJobs.get(jobInfo);
System.out.println("job " + jobInfo.getHtcJobID() + " " + jobInfo.getJobName() + ", status=" + jobStatus.toString());
}
for (String partition : partitions) {
System.setProperty(PropertyLoader.slurm_partition, partition);
PartitionStatistics partitionStatistics = slurmProxy.getPartitionStatistics();
System.out.println("partition statistics for partition " + partition + ": " + partitionStatistics);
System.out.println("number of cpus allocated = " + partitionStatistics.numCpusAllocated);
System.out.println("load = " + partitionStatistics.load);
System.out.println("number of cpus total = " + partitionStatistics.numCpusTotal);
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
} finally {
if (cmd != null) {
cmd.close();
}
}
}
Aggregations