Search in sources :

Example 1 with MemLimitResults

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));
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) SimulationExecutionStatus(cbit.vcell.server.SimulationExecutionStatus) User(org.vcell.util.document.User) SimulationTask(cbit.vcell.messaging.server.SimulationTask) KeyValue(org.vcell.util.document.KeyValue) SolverDescription(cbit.vcell.solver.SolverDescription) MemLimitResults(cbit.vcell.message.server.htc.HtcProxy.MemLimitResults) SimulationQueueEntryStatus(cbit.vcell.server.SimulationQueueEntryStatus) Date(java.util.Date) StatusMessage(cbit.vcell.message.messages.StatusMessage) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) SimulationJob(cbit.vcell.solver.SimulationJob) SimulationTaskMessage(cbit.vcell.message.messages.SimulationTaskMessage)

Aggregations

FieldDataIdentifierSpec (cbit.vcell.field.FieldDataIdentifierSpec)1 SimulationTaskMessage (cbit.vcell.message.messages.SimulationTaskMessage)1 StatusMessage (cbit.vcell.message.messages.StatusMessage)1 MemLimitResults (cbit.vcell.message.server.htc.HtcProxy.MemLimitResults)1 SimulationTask (cbit.vcell.messaging.server.SimulationTask)1 SimulationExecutionStatus (cbit.vcell.server.SimulationExecutionStatus)1 SimulationJobStatus (cbit.vcell.server.SimulationJobStatus)1 SimulationQueueEntryStatus (cbit.vcell.server.SimulationQueueEntryStatus)1 SimulationJob (cbit.vcell.solver.SimulationJob)1 SolverDescription (cbit.vcell.solver.SolverDescription)1 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)1 Date (java.util.Date)1 KeyValue (org.vcell.util.document.KeyValue)1 User (org.vcell.util.document.User)1