Search in sources :

Example 26 with SimulationJobStatus

use of cbit.vcell.server.SimulationJobStatus in project vcell by virtualcell.

the class SimulationDispatcherEngine method onStartRequest.

/**
 * @param vcMessage
 * @param session
 * @throws VCMessagingException
 * @throws SQLException
 * @throws DataAccessException
 */
public void onStartRequest(VCSimulationIdentifier vcSimID, User user, int simulationScanCount, SimulationDatabase simulationDatabase, VCMessageSession session, VCMessageSession dispatcherQueueSession) throws VCMessagingException, DataAccessException, SQLException {
    KeyValue simKey = vcSimID.getSimulationKey();
    boolean isAdmin = false;
    User myUser = simulationDatabase.getUser(user.getName());
    if (myUser instanceof User.SpecialUser) {
        // 'special0' assigned to users who are VCell project admins
        isAdmin = Arrays.asList(((User.SpecialUser) myUser).getMySpecials()).contains(User.SPECIALS.special1);
    }
    SimulationInfo simulationInfo = null;
    try {
        simulationInfo = simulationDatabase.getSimulationInfo(user, simKey);
    } catch (DataAccessException ex) {
        if (lg.isWarnEnabled())
            lg.warn("Bad simulation " + vcSimID);
        StatusMessage message = new StatusMessage(new SimulationJobStatus(VCellServerID.getSystemServerID(), vcSimID, -1, null, SchedulerStatus.FAILED, 0, SimulationMessage.workerFailure("Failed to dispatch simulation: " + ex.getMessage()), null, null), user.getName(), null, null);
        message.sendToClient(session);
        return;
    }
    if (simulationInfo == null) {
        if (lg.isWarnEnabled())
            lg.warn("Can't start, simulation [" + vcSimID + "] doesn't exist in database");
        StatusMessage message = new StatusMessage(new SimulationJobStatus(VCellServerID.getSystemServerID(), vcSimID, -1, null, SchedulerStatus.FAILED, 0, SimulationMessage.workerFailure("Can't start, simulation [" + vcSimID + "] doesn't exist"), null, null), user.getName(), null, null);
        message.sendToClient(session);
        return;
    }
    if (!isAdmin && simulationScanCount > Integer.parseInt(cbit.vcell.resource.PropertyLoader.getRequiredProperty(cbit.vcell.resource.PropertyLoader.maxJobsPerScan))) {
        if (lg.isWarnEnabled())
            lg.warn("Too many simulations (" + simulationScanCount + ") for parameter scan." + vcSimID);
        StatusMessage message = new StatusMessage(new SimulationJobStatus(VCellServerID.getSystemServerID(), vcSimID, -1, null, SchedulerStatus.FAILED, 0, SimulationMessage.workerFailure("Too many simulations (" + simulationScanCount + ") for parameter scan."), null, null), user.getName(), null, null);
        message.sendToClient(session);
        return;
    }
    for (int jobIndex = 0; jobIndex < simulationScanCount; jobIndex++) {
        SimulationStateMachine simStateMachine = getSimulationStateMachine(simKey, jobIndex);
        try {
            simStateMachine.onStartRequest(user, vcSimID, simulationDatabase, session);
        } catch (UpdateSynchronizationException e) {
            simStateMachine.onStartRequest(user, vcSimID, simulationDatabase, session);
        }
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) UpdateSynchronizationException(cbit.vcell.server.UpdateSynchronizationException) DataAccessException(org.vcell.util.DataAccessException) SimulationInfo(cbit.vcell.solver.SimulationInfo) StatusMessage(cbit.vcell.message.messages.StatusMessage)

Example 27 with SimulationJobStatus

use of cbit.vcell.server.SimulationJobStatus in project vcell by virtualcell.

the class SimulationDatabaseDirect method getSimpleJobStatus.

@Override
public SimpleJobStatus[] getSimpleJobStatus(User user, SimpleJobStatusQuerySpec simStatusQuerySpec) throws ObjectNotFoundException, DataAccessException {
    // 
    // create corresponding SimpleJobStatus[] from SimpleJobStatusPersistent[]
    // 1) get SimpleJobStatusPersistent from database (with stored status, metadata, and documentLinks - but no stateInfo)
    // 2) if already in cache, use SimulationJobStatus and stateInfo from cache.
    // 3) if not in cache, use SimulationJobStatus from database and no stateInfo, populate cache.
    // 
    List<SimpleJobStatusPersistent> simpleJobStatusPersistentList = databaseServerImpl.getSimpleJobStatus(simStatusQuerySpec);
    ArrayList<SimpleJobStatus> simpleJobStatusList = new ArrayList<SimpleJobStatus>();
    for (SimpleJobStatusPersistent simpleJobStatusPersistent : simpleJobStatusPersistentList) {
        SimulationJobStatusPersistent simJobStatusDb = simpleJobStatusPersistent.jobStatus;
        SimJobStatusKey key = new SimJobStatusKey(simpleJobStatusPersistent.simulationMetadata.vcSimID.getSimulationKey(), simJobStatusDb.getJobIndex(), simJobStatusDb.getTaskID());
        SimStatusCacheEntry simStatusCacheEntry = cache.get(key);
        // TODO need to get this from memory cache.
        StateInfo cachedStateInfo = null;
        SimulationJobStatus latestSimulationJobStatus = null;
        if (simStatusCacheEntry != null) {
            cachedStateInfo = simStatusCacheEntry.stateInfo;
            latestSimulationJobStatus = simStatusCacheEntry.jobStatus;
        } else {
            latestSimulationJobStatus = translateToSimulationJobStatusTransient(simJobStatusDb);
            cache.put(key, new SimStatusCacheEntry(latestSimulationJobStatus, null));
        }
        SimpleJobStatus bestSimpleJobStatus = translateToSimpleJobStatusTransient(simpleJobStatusPersistent, latestSimulationJobStatus, cachedStateInfo);
        // uses latest SimulationJobStatus and StateInfo.
        simpleJobStatusList.add(bestSimpleJobStatus);
    }
    return simpleJobStatusList.toArray(new SimpleJobStatus[simpleJobStatusList.size()]);
}
Also used : StateInfo(cbit.vcell.server.StateInfo) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) ArrayList(java.util.ArrayList) SimpleJobStatusPersistent(cbit.vcell.server.SimpleJobStatusPersistent) SimulationJobStatusPersistent(cbit.vcell.server.SimulationJobStatusPersistent) SimpleJobStatus(cbit.vcell.server.SimpleJobStatus)

Example 28 with SimulationJobStatus

use of cbit.vcell.server.SimulationJobStatus 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);
}
Also used : SimulationExecutionStatus(cbit.vcell.server.SimulationExecutionStatus) VCellServerID(org.vcell.util.document.VCellServerID) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) HtcJobID(cbit.vcell.server.HtcJobID) SimulationQueueEntryStatus(cbit.vcell.server.SimulationQueueEntryStatus) Date(java.util.Date) StatusMessage(cbit.vcell.message.messages.StatusMessage)

Example 29 with SimulationJobStatus

use of cbit.vcell.server.SimulationJobStatus 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

SimulationJobStatus (cbit.vcell.server.SimulationJobStatus)29 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)9 KeyValue (org.vcell.util.document.KeyValue)9 StatusMessage (cbit.vcell.message.messages.StatusMessage)7 SimulationExecutionStatus (cbit.vcell.server.SimulationExecutionStatus)7 SimulationQueueEntryStatus (cbit.vcell.server.SimulationQueueEntryStatus)7 Date (java.util.Date)6 SimulationJobStatusEvent (cbit.rmi.event.SimulationJobStatusEvent)5 ArrayList (java.util.ArrayList)5 VCellServerID (org.vcell.util.document.VCellServerID)5 VCMessage (cbit.vcell.message.VCMessage)4 VCMessagingException (cbit.vcell.message.VCMessagingException)4 HtcJobID (cbit.vcell.server.HtcJobID)4 SimulationStatus (cbit.vcell.server.SimulationStatus)4 VCDestination (cbit.vcell.message.VCDestination)3 LocalVCMessageAdapter (cbit.vcell.message.local.LocalVCMessageAdapter)3 LocalVCMessageListener (cbit.vcell.message.local.LocalVCMessageAdapter.LocalVCMessageListener)3 SchedulerStatus (cbit.vcell.server.SimulationJobStatus.SchedulerStatus)3 SimulationJobStatusPersistent (cbit.vcell.server.SimulationJobStatusPersistent)3 SolverException (cbit.vcell.solver.SolverException)3