use of cbit.vcell.server.HtcJobID in project vcell by virtualcell.
the class SimulationJobTable method getSimulationJobStatus.
/**
* This method was created in VisualAge.
* @return VCImage
* @param rset ResultSet
* @param log SessionLog
*/
public SimulationJobStatusPersistent getSimulationJobStatus(ResultSet rset) throws SQLException {
// serverid
String serID = rset.getString(this.serverID.toString());
if (rset.wasNull()) {
serID = null;
}
// simRef
KeyValue parsedSimKey = new KeyValue(rset.getBigDecimal(simRef.toString()));
// userKey
KeyValue userKey = new KeyValue(rset.getBigDecimal(SimulationTable.table.ownerRef.toString()));
// userKey
String userid = rset.getString(UserTable.table.userid.toString());
org.vcell.util.document.User owner = new org.vcell.util.document.User(userid, userKey);
// submitDate
java.util.Date parsedSubmitDate = rset.getTimestamp(submitDate.toString());
// taskID
int parsedTaskID = rset.getInt(taskID.toString());
// schedulerStatus
int parsedSchedulerStatusInt = rset.getInt(schedulerStatus.toString());
SchedulerStatus parsedSchedulerStatus = SchedulerStatus.fromDatabaseNumber(parsedSchedulerStatusInt);
// statusMsg
String parsedStatusMsg = TokenMangler.getSQLRestoredString(rset.getString(statusMsg.toString()));
SimulationMessagePersistent simulationMessage = SimulationMessagePersistent.fromSerialized(parsedSchedulerStatus, parsedStatusMsg);
//
// read queue stuff
//
// queueDate
java.util.Date parsedQueuedDate = rset.getTimestamp(queueDate.toString());
// queuePriority
int parsedQueuePriority = rset.getInt(queuePriority.toString());
if (rset.wasNull()) {
parsedQueuePriority = -1;
}
// queueID
int parsedQueueID = rset.getInt(queueID.toString());
if (rset.wasNull()) {
parsedQueueID = -1;
}
SimulationJobStatusPersistent.SimulationQueueID simulationQueueID = SimulationJobStatusPersistent.SimulationQueueID.fromDatabaseNumber(parsedQueueID);
SimulationQueueEntryStatusPersistent simQueueEntryStatus = new SimulationQueueEntryStatusPersistent(parsedQueuedDate, parsedQueuePriority, simulationQueueID);
//
// read solver stuff
//
// startDate
java.util.Date parsedStartDate = rset.getTimestamp(startDate.toString());
// computeHost
String parsedComputeHost = rset.getString(computeHost.toString());
// latestUpdateDate
java.util.Date parsedLatestUpdateDate = rset.getTimestamp(latestUpdateDate.toString());
// endDate
java.util.Date parsedEndDate = rset.getTimestamp(endDate.toString());
// hasData
String parsedHasData = rset.getString(hasData.toString());
HtcJobID parsedHtcJobID = null;
String htcJobIDString = rset.getString(pbsJobID.toString());
if (!rset.wasNull() && htcJobIDString != null && htcJobIDString.length() > 0) {
parsedHtcJobID = SimulationJobTable.fromDatabase(htcJobIDString);
}
SimulationExecutionStatusPersistent simExeStatus = new SimulationExecutionStatusPersistent(parsedStartDate, parsedComputeHost, parsedLatestUpdateDate, parsedEndDate, parsedHasData != null, parsedHtcJobID);
VCSimulationIdentifier parsedVCSimID = new VCSimulationIdentifier(parsedSimKey, owner);
// jobIndex
int parsedJobIndex = rset.getInt(jobIndex.toString());
SimulationJobStatusPersistent simulationJobStatus = new SimulationJobStatusPersistent(VCellServerID.getServerID(serID), parsedVCSimID, parsedJobIndex, parsedSubmitDate, parsedSchedulerStatus, parsedTaskID, simulationMessage, simQueueEntryStatus, simExeStatus);
// sysDate
java.util.Date parsedSysDate = rset.getTimestamp(DatabaseConstants.SYSDATE_COLUMN_NAME);
if (!rset.wasNull()) {
simulationJobStatus.setTimeDateStamp(parsedSysDate);
}
return simulationJobStatus;
}
use of cbit.vcell.server.HtcJobID in project vcell by virtualcell.
the class SimulationJobStatusEvent method fromJsonRep.
public static SimulationJobStatusEvent fromJsonRep(Object eventSource, SimulationJobStatusEventRepresentation eventRep) {
String simid = Simulation.createSimulationID(new KeyValue(eventRep.jobStatus.simulationKey));
int jobIndex = eventRep.jobStatus.jobIndex;
int taskID = eventRep.jobStatus.taskID;
VCellServerID serverID = VCellServerID.getServerID(eventRep.jobStatus.vcellServerID);
KeyValue simkey = new KeyValue(eventRep.jobStatus.simulationKey);
User owner = new User(eventRep.jobStatus.owner_userid, new KeyValue(eventRep.jobStatus.onwer_userkey));
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simkey, owner);
Date submitDate = eventRep.jobStatus.submitDate;
SchedulerStatus schedulerStatus = null;
if (eventRep.jobStatus.schedulerStatus != null) {
schedulerStatus = SchedulerStatus.valueOf(eventRep.jobStatus.schedulerStatus.name());
}
HtcJobID htcJobID = null;
Long htcJobNumber = eventRep.jobStatus.htcJobNumber;
SimulationJobStatusRepresentation.BatchSystemType htcBatchSystemType = eventRep.jobStatus.htcBatchSystemType;
if (htcJobNumber != null) {
htcJobID = new HtcJobID(htcJobNumber.toString(), BatchSystemType.valueOf(htcBatchSystemType.name()));
}
SimulationMessage simMessage = null;
DetailedState detailedState = DetailedState.valueOf(eventRep.jobStatus.detailedState.name());
String message = eventRep.jobStatus.detailedStateMessage;
if (detailedState != null) {
simMessage = SimulationMessage.create(detailedState, message, htcJobID);
}
SimulationQueueEntryStatus simQueueStatus = null;
Date queueDate = eventRep.jobStatus.queueDate;
Integer queuePriority = eventRep.jobStatus.queuePriority;
SimulationJobStatusRepresentation.SimulationQueueID queueId2 = eventRep.jobStatus.queueId;
if (queueDate != null && queuePriority != null) {
simQueueStatus = new SimulationQueueEntryStatus(queueDate, queuePriority, SimulationQueueID.valueOf(queueId2.name()));
}
SimulationExecutionStatus simExeStatus = null;
Date startDate = eventRep.jobStatus.simexe_startDate;
String computeHost = eventRep.jobStatus.computeHost;
Date latestUpdateDate = eventRep.jobStatus.simexe_latestUpdateDate;
Date endDate = eventRep.jobStatus.simexe_endDate;
Boolean hasData = eventRep.jobStatus.hasData;
if (latestUpdateDate != null) {
simExeStatus = new SimulationExecutionStatus(startDate, computeHost, latestUpdateDate, endDate, hasData, htcJobID);
}
SimulationJobStatus jobStatus = new SimulationJobStatus(serverID, vcSimID, jobIndex, submitDate, schedulerStatus, taskID, simMessage, simQueueStatus, simExeStatus);
Double progress = eventRep.progress;
Double timepoint = eventRep.timePoint;
String username = eventRep.username;
SimulationJobStatusEvent event = new SimulationJobStatusEvent(eventSource, simid, jobStatus, progress, timepoint, username);
return event;
}
use of cbit.vcell.server.HtcJobID in project vcell by virtualcell.
the class SimulationStateMachine method onSystemAbort.
public synchronized void onSystemAbort(SimulationJobStatus oldJobStatus, String failureMessage, SimulationDatabase simulationDatabase, VCMessageSession session) throws VCMessagingException, UpdateSynchronizationException, DataAccessException, SQLException {
updateSolverProcessTimestamp();
int taskID = oldJobStatus.getTaskID();
//
// status information (initialized as if new record)
//
Date startDate = null;
boolean hasData = false;
HtcJobID htcJobID = null;
String computeHost = null;
VCellServerID vcServerID = VCellServerID.getSystemServerID();
Date submitDate = null;
Date queueDate = null;
int queuePriority = PRIORITY_DEFAULT;
//
// update using previously stored status (if available).
//
SimulationExecutionStatus oldSimExeStatus = oldJobStatus.getSimulationExecutionStatus();
if (oldSimExeStatus != null && oldSimExeStatus.getStartDate() != null) {
startDate = oldSimExeStatus.getStartDate();
}
if (oldSimExeStatus != null && oldSimExeStatus.hasData()) {
hasData = true;
}
if (oldSimExeStatus != null && oldSimExeStatus.getComputeHost() != null) {
computeHost = oldSimExeStatus.getComputeHost();
}
if (oldSimExeStatus != null && oldSimExeStatus.getHtcJobID() != null) {
htcJobID = oldSimExeStatus.getHtcJobID();
}
vcServerID = oldJobStatus.getServerID();
submitDate = oldJobStatus.getSubmitDate();
SimulationQueueEntryStatus oldQueueStatus = oldJobStatus.getSimulationQueueEntryStatus();
if (oldQueueStatus != null && oldQueueStatus.getQueueDate() != null) {
queueDate = oldQueueStatus.getQueueDate();
}
if (oldQueueStatus != null) {
queuePriority = oldQueueStatus.getQueuePriority();
}
SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(queueDate, queuePriority, SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL);
Date endDate = new Date();
Date lastUpdateDate = new Date();
SimulationExecutionStatus newExeStatus = new SimulationExecutionStatus(startDate, computeHost, lastUpdateDate, endDate, hasData, htcJobID);
SimulationJobStatus newJobStatus = new SimulationJobStatus(vcServerID, oldJobStatus.getVCSimulationIdentifier(), jobIndex, submitDate, SchedulerStatus.FAILED, taskID, SimulationMessage.jobFailed(failureMessage), newQueueStatus, newExeStatus);
simulationDatabase.updateSimulationJobStatus(newJobStatus);
// addStateMachineTransition(new StateMachineTransition(new AbortStateMachineEvent(taskID, failureMessage), oldJobStatus, newJobStatus));
String userName = VCMessagingConstants.USERNAME_PROPERTY_VALUE_ALL;
StatusMessage msgForClient = new StatusMessage(newJobStatus, userName, null, null);
msgForClient.sendToClient(session);
if (lg.isTraceEnabled())
lg.trace("Send status to client: " + msgForClient);
}
use of cbit.vcell.server.HtcJobID in project vcell by virtualcell.
the class HtcSimulationWorker method submit2PBS.
private HtcJobID submit2PBS(SimulationTask simTask, HtcProxy clonedHtcProxy, PostProcessingChores chores) throws XmlParseException, IOException, SolverException, ExecutableException {
HtcJobID jobid = null;
String htcLogDirExternalString = new File(PropertyLoader.getRequiredProperty(PropertyLoader.htcLogDirExternal)).getAbsolutePath();
if (!htcLogDirExternalString.endsWith("/")) {
htcLogDirExternalString = htcLogDirExternalString + "/";
}
String htcLogDirInternalString = new File(PropertyLoader.getRequiredProperty(PropertyLoader.htcLogDirInternal)).getAbsolutePath();
if (!htcLogDirInternalString.endsWith("/")) {
htcLogDirInternalString = htcLogDirInternalString + "/";
}
// "S_" + simTask.getSimKey() + "_" + simTask.getSimulationJob().getJobIndex()+ "_" + simTask.getTaskID();
String jobname = HtcProxy.createHtcSimJobName(new HtcProxy.SimTaskInfo(simTask.getSimKey(), simTask.getSimulationJob().getJobIndex(), simTask.getTaskID()));
String subFileExternal = htcLogDirExternalString + jobname + clonedHtcProxy.getSubmissionFileExtension();
String subFileInternal = htcLogDirInternalString + jobname + clonedHtcProxy.getSubmissionFileExtension();
File parallelDirInternal = new File(chores.runDirectoryInternal);
File parallelDirExternal = new File(chores.runDirectoryExternal);
File primaryUserDirInternal = new File(chores.finalDataDirectoryInternal);
File primaryUserDirExternal = new File(chores.finalDataDirectoryExternal);
Solver realSolver = (AbstractSolver) SolverFactory.createSolver(primaryUserDirInternal, parallelDirInternal, simTask, true);
realSolver.setUnixMode();
String simTaskXmlText = XmlHelper.simTaskToXML(simTask);
String simTaskFilePathInternal = ResourceUtil.forceUnixPath(new File(primaryUserDirInternal, simTask.getSimulationJobID() + "_" + simTask.getTaskID() + ".simtask.xml").toString());
String simTaskFilePathExternal = ResourceUtil.forceUnixPath(new File(primaryUserDirExternal, simTask.getSimulationJobID() + "_" + simTask.getTaskID() + ".simtask.xml").toString());
if (!primaryUserDirInternal.exists()) {
FileUtils.forceMkdir(primaryUserDirInternal);
//
// directory create from container (possibly) as root, make this user directory accessible from user "vcell"
//
primaryUserDirInternal.setWritable(true, false);
primaryUserDirInternal.setExecutable(true, false);
primaryUserDirInternal.setReadable(true, false);
}
XmlUtil.writeXMLStringToFile(simTaskXmlText, simTaskFilePathInternal, true);
final String SOLVER_EXIT_CODE_REPLACE_STRING = "SOLVER_EXIT_CODE_REPLACE_STRING";
KeyValue simKey = simTask.getSimKey();
User simOwner = simTask.getSimulation().getVersion().getOwner();
final int jobId = simTask.getSimulationJob().getJobIndex();
ExecutableCommand.Container commandContainer = new ExecutableCommand.Container();
// the post processor command itself is neither messaging nor parallel; it's independent of the previous solver call
ExecutableCommand postprocessorCmd = new ExecutableCommand(null, false, false, PropertyLoader.getRequiredProperty(PropertyLoader.simulationPostprocessor), simKey.toString(), simOwner.getName(), simOwner.getID().toString(), Integer.toString(jobId), Integer.toString(simTask.getTaskID()), SOLVER_EXIT_CODE_REPLACE_STRING, subFileExternal);
postprocessorCmd.setExitCodeToken(SOLVER_EXIT_CODE_REPLACE_STRING);
commandContainer.add(postprocessorCmd);
// CBN?
int ncpus = simTask.getSimulation().getSolverTaskDescription().getNumProcessors();
Collection<PortableCommand> postProcessingCommands = new ArrayList<PortableCommand>();
if (realSolver instanceof AbstractCompiledSolver) {
AbstractCompiledSolver compiledSolver = (AbstractCompiledSolver) realSolver;
List<String> args = new ArrayList<>(4);
args.add(PropertyLoader.getRequiredProperty(PropertyLoader.simulationPreprocessor));
args.add(simTaskFilePathExternal);
args.add(primaryUserDirExternal.getAbsolutePath());
if (chores.isParallel()) {
args.add(chores.runDirectoryExternal);
}
// compiled solver ...used to be only single executable, now we pass 2 commands to PBSUtils.submitJob that invokes SolverPreprocessor.main() and then the native executable
// the pre-processor command itself is neither messaging nor parallel; it's independent of the subsequent solver call
ExecutableCommand preprocessorCmd = new ExecutableCommand(null, false, false, args);
commandContainer.add(preprocessorCmd);
for (ExecutableCommand ec : compiledSolver.getCommands()) {
if (ec.isMessaging()) {
ec.addArgument("-tid");
ec.addArgument(simTask.getTaskID());
}
commandContainer.add(ec);
}
if (chores.isCopyNeeded()) {
String logName = chores.finalDataDirectoryInternal + '/' + SimulationData.createCanonicalSimLogFileName(simKey, jobId, false);
CopySimFiles csf = new CopySimFiles(simTask.getSimulationJobID(), chores.runDirectoryInternal, chores.finalDataDirectoryInternal, logName);
postProcessingCommands.add(csf);
}
if (chores.isVtkUser()) {
VtkMeshGenerator vmg = new VtkMeshGenerator(simOwner, simKey, jobId);
postProcessingCommands.add(vmg);
}
} else {
ExecutableCommand ec = new ExecutableCommand(null, false, false, PropertyLoader.getRequiredProperty(PropertyLoader.javaSimulationExecutable), simTaskFilePathExternal, ResourceUtil.forceUnixPath(parallelDirExternal.getAbsolutePath()));
commandContainer.add(ec);
}
jobid = clonedHtcProxy.submitJob(jobname, subFileInternal, subFileExternal, commandContainer, ncpus, simTask.getEstimatedMemorySizeMB(), postProcessingCommands);
if (jobid == null) {
throw new RuntimeException("Failed. (error message: submitting to job scheduler failed).");
}
return jobid;
}
use of cbit.vcell.server.HtcJobID in project vcell by virtualcell.
the class SlurmProxy method submitJob.
@Override
public HtcJobID submitJob(String jobName, String sub_file_internal, String sub_file_external, ExecutableCommand.Container commandSet, int ncpus, double memSize, Collection<PortableCommand> postProcessingCommands) throws ExecutableException {
try {
if (LG.isDebugEnabled()) {
LG.debug("generating local SLURM submit script for jobName=" + jobName);
}
String text = generateScript(jobName, commandSet, ncpus, memSize, postProcessingCommands);
File tempFile = File.createTempFile("tempSubFile", ".sub");
writeUnixStyleTextFile(tempFile, text);
// move submission file to final location (either locally or remotely).
if (LG.isDebugEnabled()) {
LG.debug("moving local SLURM submit file '" + tempFile.getAbsolutePath() + "' to remote file '" + sub_file_external + "'");
}
FileUtils.copyFile(tempFile, new File(sub_file_internal));
tempFile.delete();
} catch (IOException ex) {
ex.printStackTrace(System.out);
return null;
}
/**
* > sbatch /share/apps/vcell2/deployed/test/htclogs/V_TEST_107643258_0_0.slurm.sub
* Submitted batch job 5174
*/
String[] completeCommand = new String[] { Slurm_HOME + JOB_CMD_SUBMIT, sub_file_external };
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_SUBMIT + "' 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;
}
Aggregations