use of cbit.vcell.message.server.htc.HtcProxy.MemLimitResults in project vcell by virtualcell.
the class SimulationStateMachine method onDispatch.
public synchronized void onDispatch(Simulation simulation, SimulationJobStatus oldSimulationJobStatus, SimulationDatabase simulationDatabase, VCMessageSession session) throws VCMessagingException, DataAccessException, SQLException {
updateSolverProcessTimestamp();
VCSimulationIdentifier vcSimID = oldSimulationJobStatus.getVCSimulationIdentifier();
int taskID = oldSimulationJobStatus.getTaskID();
if (!oldSimulationJobStatus.getSchedulerStatus().isWaiting()) {
VCMongoMessage.sendInfo("onDispatch(" + vcSimID.getID() + ") Can't start, simulation[" + vcSimID + "] job [" + jobIndex + "] task [" + taskID + "] is already dispatched (" + oldSimulationJobStatus.getSchedulerStatus().getDescription() + ")");
throw new RuntimeException("Can't start, simulation[" + vcSimID + "] job [" + jobIndex + "] task [" + taskID + "] is already dispatched (" + oldSimulationJobStatus.getSchedulerStatus().getDescription() + ")");
}
FieldDataIdentifierSpec[] fieldDataIdentifierSpecs = simulationDatabase.getFieldDataIdentifierSpecs(simulation);
// Check if user wants long running sims activated in SlurmProxy.generateScript(...)
// only happens if user is allowed to be power user (entry in vc_specialusers table) and
// has checked the 'timeoutDisabledCheckBox' in SolverTaskDescriptionAdvancedPanel on the client-side GUI
// Set from GUI
boolean isPowerUser = simulation.getSolverTaskDescription().isTimeoutDisabled();
if (isPowerUser) {
// Check if user allowed to be power user for 'special1' long running sims (see User.SPECIALS and vc_specialusers table)
User myUser = simulationDatabase.getUser(simulation.getVersion().getOwner().getName());
if (myUser instanceof User.SpecialUser) {
// 'special1' assigned to users by request to allow long running sims
isPowerUser = isPowerUser && Arrays.asList(((User.SpecialUser) myUser).getMySpecials()).contains(User.SPECIALS.special1);
} else {
isPowerUser = false;
}
}
SimulationTask simulationTask = new SimulationTask(new SimulationJob(simulation, jobIndex, fieldDataIdentifierSpecs), taskID, null, isPowerUser);
double requiredMemMB = simulationTask.getEstimatedMemorySizeMB();
// SimulationStateMachine ultimately instantiated from {vcellroot}/docker/build/Dockerfile-sched-dev by way of cbit.vcell.message.server.dispatcher.SimulationDispatcher
String vcellUserid = simulationTask.getUser().getName();
KeyValue simID = simulationTask.getSimulationInfo().getSimulationVersion().getVersionKey();
SolverDescription solverDescription = simulationTask.getSimulation().getSolverTaskDescription().getSolverDescription();
MemLimitResults allowableMemMB = HtcProxy.getMemoryLimit(vcellUserid, simID, solverDescription, requiredMemMB);
final SimulationJobStatus newSimJobStatus;
if (requiredMemMB > allowableMemMB.getMemLimit()) {
//
// fail the simulation
//
Date currentDate = new Date();
// new queue status
SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(currentDate, PRIORITY_DEFAULT, SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL);
SimulationExecutionStatus newSimExeStatus = new SimulationExecutionStatus(null, null, new Date(), null, false, null);
newSimJobStatus = new SimulationJobStatus(VCellServerID.getSystemServerID(), vcSimID, jobIndex, oldSimulationJobStatus.getSubmitDate(), SchedulerStatus.FAILED, taskID, SimulationMessage.jobFailed("simulation required " + requiredMemMB + "MB of memory, only " + allowableMemMB.getMemLimit() + "MB allowed from " + allowableMemMB.getMemLimitSource()), newQueueStatus, newSimExeStatus);
simulationDatabase.updateSimulationJobStatus(newSimJobStatus);
StatusMessage message = new StatusMessage(newSimJobStatus, simulation.getVersion().getOwner().getName(), null, null);
message.sendToClient(session);
} else {
//
// dispatch the simulation, new queue status
//
Date currentDate = new Date();
SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(currentDate, PRIORITY_DEFAULT, SimulationJobStatus.SimulationQueueID.QUEUE_ID_SIMULATIONJOB);
SimulationExecutionStatus newSimExeStatus = new SimulationExecutionStatus(null, null, new Date(), null, false, null);
newSimJobStatus = new SimulationJobStatus(VCellServerID.getSystemServerID(), vcSimID, jobIndex, oldSimulationJobStatus.getSubmitDate(), SchedulerStatus.DISPATCHED, taskID, SimulationMessage.MESSAGE_JOB_DISPATCHED, newQueueStatus, newSimExeStatus);
SimulationTaskMessage simTaskMessage = new SimulationTaskMessage(simulationTask);
simTaskMessage.sendSimulationTask(session);
simulationDatabase.updateSimulationJobStatus(newSimJobStatus);
StatusMessage message = new StatusMessage(newSimJobStatus, simulation.getVersion().getOwner().getName(), null, null);
message.sendToClient(session);
}
// addStateMachineTransition(new StateMachineTransition(new DispatchStateMachineEvent(taskID), oldSimulationJobStatus, newSimJobStatus));
}
Aggregations