-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: introducing OmexExecSummary to unify reporting of errors
- Loading branch information
Showing
9 changed files
with
348 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.vcell.cli; | ||
|
||
import org.vcell.trace.Tracer; | ||
|
||
public class CliTracer implements CLIRecordable { | ||
|
||
@Override | ||
public void writeDetailedErrorList(Exception e, String message) { | ||
Tracer.failure(e, "writeDetailedErrorList(): "+message); | ||
} | ||
@Override | ||
public void writeFullSuccessList(String message) { | ||
Tracer.success("writeFullSuccessList(): " + message); | ||
} | ||
@Override | ||
public void writeErrorList(Exception e, String message) { | ||
Tracer.failure(e, "writeErrorList(): " + message); | ||
} | ||
@Override | ||
public void writeDetailedResultList(String message) { | ||
Tracer.log("writeDetailedResultList(): "+message); | ||
} | ||
@Override | ||
public void writeSpatialList(String message) { | ||
Tracer.log("writeSpatialList(): "+message); | ||
} | ||
@Override | ||
public void writeImportErrorList(Exception e, String message) { | ||
Tracer.failure(e, "writeImportErrorList(): " + message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
vcell-cli/src/main/java/org/vcell/cli/run/ExecuteOmexCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package org.vcell.cli.run; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.core.LoggerContext; | ||
import org.vcell.cli.CLIPythonManager; | ||
import org.vcell.cli.CLIRecordable; | ||
import org.vcell.cli.CliTracer; | ||
import org.vcell.cli.testsupport.OmexExecSummary; | ||
import org.vcell.cli.testsupport.OmexTestingDatabase; | ||
import org.vcell.trace.Tracer; | ||
import org.vcell.util.FileUtils; | ||
import org.vcell.util.exe.Executable; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Option; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.Date; | ||
import java.util.concurrent.Callable; | ||
|
||
@Command(name = "execute-omex", description = "run .vcml or .omex files via Python API") | ||
public class ExecuteOmexCommand implements Callable<Integer> { | ||
|
||
private final static Logger logger = LogManager.getLogger(ExecuteOmexCommand.class); | ||
|
||
@Option(names = { "-i", "--inputFilePath" }, required = true, description = "Path to a COMBINE/OMEX archive file") | ||
private File inputFilePath; | ||
|
||
@Option(names = { "-o", "--outputFilePath"}, required = true, description = "Directory to save outputs") | ||
private File outputFilePath; | ||
|
||
@Option(names = {"--keepTempFiles"}, defaultValue = "false") | ||
private boolean bKeepTempFiles = false; | ||
|
||
@Option(names = {"--exactMatchOnly"}, defaultValue = "false") | ||
private boolean bExactMatchOnly = false; | ||
|
||
@Option(names = "--small-mesh", defaultValue = "false", description = "force spatial simulations to have a very small mesh to make execution faster") | ||
private boolean bSmallMeshOverride = false; | ||
|
||
@Option(names = {"--encapsulateOutput"}, defaultValue = "true", description = | ||
"VCell will encapsulate output results in a sub directory when executing with a single input archive; has no effect when providing an input directory") | ||
private boolean bEncapsulateOutput = true; | ||
|
||
@Option(names = {"--timeout_ms"}, defaultValue = "600000", description = "executable wall clock timeout in milliseconds") | ||
// timeout for compiled solver running long jobs; default 10 minutes | ||
private long EXECUTABLE_MAX_WALLCLOCK_MILLIS = 10 * 60 * 1000; | ||
|
||
@Option(names = {"-h", "--help"}, description = "show this help message and exit", usageHelp = true) | ||
private boolean help = false; | ||
|
||
@Option(names = {"-d", "--debug"}, description = "full application debug mode") | ||
private boolean bDebug = false; | ||
|
||
@Option(names = {"-q", "--quiet"}, description = "suppress all console output") | ||
private boolean bQuiet = false; | ||
|
||
|
||
public Integer call() { | ||
|
||
CLIRecordable cliTracer = new CliTracer(); | ||
try { | ||
if (bDebug && bQuiet) { | ||
System.err.println("cannot specify both debug and quiet, try --help for usage"); | ||
return 1; | ||
} | ||
Level logLevel; | ||
if (!bQuiet && bDebug) { | ||
logLevel = Level.DEBUG; | ||
} else if (bQuiet) { | ||
logLevel = Level.OFF; | ||
} else { | ||
logLevel = logger.getLevel(); | ||
} | ||
|
||
if (this.inputFilePath.exists() && !this.inputFilePath.isFile()) { | ||
System.err.println("Input path must be a file"); | ||
return 1; | ||
} | ||
if (this.outputFilePath.exists() && !this.outputFilePath.isDirectory()) { | ||
System.err.println("Output path must be a directory"); | ||
return 1; | ||
} | ||
|
||
LoggerContext config = (LoggerContext)(LogManager.getContext(false)); | ||
config.getConfiguration().getLoggerConfig(LogManager.getLogger("org.vcell").getName()).setLevel(logLevel); | ||
config.getConfiguration().getLoggerConfig(LogManager.getLogger("cbit").getName()).setLevel(logLevel); | ||
config.updateLoggers(); | ||
|
||
|
||
CLIPythonManager.getInstance().instantiatePythonProcess(); | ||
|
||
Executable.setGlobalTimeoutMS(EXECUTABLE_MAX_WALLCLOCK_MILLIS); | ||
logger.info("Beginning execution"); | ||
File tmpDir = Files.createTempDirectory("VCell_CLI_" + Long.toHexString(new Date().getTime())).toFile(); | ||
|
||
Tracer.clearTraceEvents(); | ||
ExecuteImpl.singleMode(inputFilePath, tmpDir, cliTracer, bKeepTempFiles, bExactMatchOnly, | ||
bEncapsulateOutput, bSmallMeshOverride); | ||
CLIPythonManager.getInstance().closePythonProcess(); | ||
// WARNING: Python needs re-instantiation once the above line is called! | ||
FileUtils.copyDirectoryContents(tmpDir, outputFilePath, true, null); | ||
OmexExecSummary omexExecSummary = new OmexExecSummary(); | ||
omexExecSummary.file_path = String.valueOf(inputFilePath); | ||
omexExecSummary.status = OmexExecSummary.ActualStatus.PASSED; | ||
new ObjectMapper().writeValue(new File(outputFilePath, "exec_summary.json"), omexExecSummary); | ||
new ObjectMapper().writeValue(new File(outputFilePath, "logs.json"), Tracer.getTraceEvents()); | ||
return 0; | ||
} catch (Exception e) { ///TODO: Break apart into specific exceptions to maximize logging. | ||
LogManager.getLogger(this.getClass()).error(e.getMessage(), e); | ||
OmexExecSummary omexExecSummary = OmexTestingDatabase.summarize(inputFilePath,e,Tracer.getErrors()); | ||
try { | ||
new ObjectMapper().writeValue(new File(outputFilePath, "exec_summary.json"), omexExecSummary); | ||
new ObjectMapper().writeValue(new File(outputFilePath, "logs.json"), Tracer.getTraceEvents()); | ||
} catch (IOException ex) { | ||
logger.error("Failed to write exec summary and structured logs", ex); | ||
} | ||
return 1; | ||
} finally { | ||
logger.debug("Completed all execution"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
vcell-cli/src/main/java/org/vcell/cli/testsupport/OmexExecSummary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.vcell.cli.testsupport; | ||
|
||
public class OmexExecSummary { | ||
|
||
public enum ActualStatus { | ||
PASSED, | ||
FAILED | ||
} | ||
|
||
public String file_path; | ||
public ActualStatus status; | ||
public FailureType failure_type; | ||
public String failure_desc; | ||
|
||
@Override | ||
public String toString() { | ||
return "OmexExecSummary{" + | ||
", file_path='" + file_path + '\'' + | ||
", status=" + status + | ||
", failure_type=" + failure_type + | ||
", failure_desc="+((failure_desc!=null)?('\'' + failure_desc + '\''):null) + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.