Search in sources :

Example 6 with HtcJobID

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

the class SimulationStateMachine method onStartRequest.

public synchronized void onStartRequest(User user, VCSimulationIdentifier vcSimID, SimulationDatabase simulationDatabase, VCMessageSession session) throws VCMessagingException, DataAccessException, SQLException {
    if (!user.equals(vcSimID.getOwner())) {
        lg.error(user + " is not authorized to start simulation (key=" + simKey + ")");
        StatusMessage message = new StatusMessage(new SimulationJobStatus(VCellServerID.getSystemServerID(), vcSimID, 0, null, SchedulerStatus.FAILED, 0, SimulationMessage.workerFailure("You are not authorized to start this simulation!"), null, null), user.getName(), null, null);
        message.sendToClient(session);
        VCMongoMessage.sendInfo("onStartRequest(" + vcSimID.getID() + ") ignoring start simulation request - wrong user): simID=" + vcSimID);
        return;
    }
    // 
    // get latest simulation job task (if any).
    // 
    SimulationJobStatus oldSimulationJobStatus = simulationDatabase.getLatestSimulationJobStatus(simKey, jobIndex);
    int oldTaskID = -1;
    if (oldSimulationJobStatus != null) {
        oldTaskID = oldSimulationJobStatus.getTaskID();
    }
    // if already started by another thread
    if (oldSimulationJobStatus != null && !oldSimulationJobStatus.getSchedulerStatus().isDone()) {
        VCMongoMessage.sendInfo("onStartRequest(" + vcSimID.getID() + ") ignoring start simulation request - (currentSimJobStatus:" + oldSimulationJobStatus.getSchedulerStatus().getDescription() + "): simID=" + vcSimID);
        throw new RuntimeException("Can't start, simulation[" + vcSimID + "] job [" + jobIndex + "] task [" + oldTaskID + "] is running already (" + oldSimulationJobStatus.getSchedulerStatus().getDescription() + ")");
    }
    int newTaskID;
    if (oldTaskID > -1) {
        // calculate new task
        newTaskID = (oldTaskID & SimulationStatus.TASKID_USERCOUNTER_MASK) + SimulationStatus.TASKID_USERINCREMENT;
    } else {
        // first task, start with 0
        newTaskID = 0;
    }
    Date currentDate = new Date();
    // new queue status
    SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(currentDate, PRIORITY_DEFAULT, SimulationJobStatus.SimulationQueueID.QUEUE_ID_WAITING);
    // new exe status
    Date lastUpdateDate = new Date();
    String computeHost = null;
    Date startDate = null;
    Date endDate = null;
    HtcJobID htcJobID = null;
    boolean hasData = false;
    SimulationExecutionStatus newExeStatus = new SimulationExecutionStatus(startDate, computeHost, lastUpdateDate, endDate, hasData, htcJobID);
    VCellServerID vcServerID = VCellServerID.getSystemServerID();
    Date submitDate = currentDate;
    SimulationJobStatus newJobStatus = new SimulationJobStatus(vcServerID, vcSimID, jobIndex, submitDate, SchedulerStatus.WAITING, newTaskID, SimulationMessage.MESSAGE_JOB_WAITING, newQueueStatus, newExeStatus);
    simulationDatabase.insertSimulationJobStatus(newJobStatus);
    // addStateMachineTransition(new StateMachineTransition(new StartStateMachineEvent(newTaskID), oldSimulationJobStatus, newJobStatus));
    StatusMessage message = new StatusMessage(newJobStatus, user.getName(), null, null);
    message.sendToClient(session);
}
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 7 with HtcJobID

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

the class HtcSimulationWorker method initQueueConsumer.

private void initQueueConsumer() {
    this.sharedMessageProducer = vcMessagingService.createProducerSession();
    QueueListener queueListener = new QueueListener() {

        @Override
        public void onQueueMessage(VCMessage vcMessage, VCMessageSession session) throws RollbackException {
            SimulationTask simTask = null;
            try {
                SimulationTaskMessage simTaskMessage = new SimulationTaskMessage(vcMessage);
                simTask = simTaskMessage.getSimulationTask();
                if (lg.isInfoEnabled()) {
                    lg.info("onQueueMessage() run simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName());
                }
                PostProcessingChores rd = choresFor(simTask);
                HtcProxy clonedHtcProxy = htcProxy.cloneThreadsafe();
                if (lg.isInfoEnabled()) {
                    lg.info("onQueueMessage() submit job: simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName());
                }
                HtcJobID pbsId = submit2PBS(simTask, clonedHtcProxy, rd);
                if (lg.isInfoEnabled()) {
                    lg.info("onQueueMessage() sending 'accepted' message for job: simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName());
                }
                synchronized (sharedMessageProducer) {
                    WorkerEventMessage.sendAccepted(sharedMessageProducer, HtcSimulationWorker.class.getName(), simTask, ManageUtils.getHostName(), pbsId);
                }
                if (lg.isInfoEnabled()) {
                    lg.info("onQueueMessage() sent 'accepted' message for job: simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName());
                }
            } catch (Exception e) {
                lg.error(e.getMessage(), e);
                if (simTask != null) {
                    try {
                        lg.error("failed to process simTask request: " + e.getMessage() + " for simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName(), e);
                        synchronized (sharedMessageProducer) {
                            WorkerEventMessage.sendFailed(sharedMessageProducer, HtcSimulationWorker.class.getName(), simTask, ManageUtils.getHostName(), SimulationMessage.jobFailed(e.getMessage()));
                        }
                        lg.error("sent 'failed' message for simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName(), e);
                    } catch (VCMessagingException e1) {
                        lg.error(e1.getMessage(), e);
                    }
                } else {
                    lg.error("failed to process simTask request: " + e.getMessage(), e);
                }
            }
        }
    };
    int numHtcworkerThreads = Integer.parseInt(PropertyLoader.getProperty(PropertyLoader.htcworkerThreadsProperty, "5"));
    this.pooledQueueConsumer = new VCPooledQueueConsumer(queueListener, numHtcworkerThreads, sharedMessageProducer);
    this.pooledQueueConsumer.initThreadPool();
    VCellQueue queue = VCellQueue.SimJobQueue;
    VCMessageSelector selector = vcMessagingService.createSelector(getJobSelector());
    String threadName = "SimJob Queue Consumer";
    queueConsumer = new VCQueueConsumer(queue, pooledQueueConsumer, selector, threadName, MessageConstants.PREFETCH_LIMIT_SIM_JOB_HTC);
    vcMessagingService.addMessageConsumer(queueConsumer);
}
Also used : QueueListener(cbit.vcell.message.VCQueueConsumer.QueueListener) SimulationTask(cbit.vcell.messaging.server.SimulationTask) HtcProxy(cbit.vcell.message.server.htc.HtcProxy) VCMessageSelector(cbit.vcell.message.VCMessageSelector) VCMessageSession(cbit.vcell.message.VCMessageSession) VCPooledQueueConsumer(cbit.vcell.message.VCPooledQueueConsumer) VCMessagingException(cbit.vcell.message.VCMessagingException) FileNotFoundException(java.io.FileNotFoundException) ConfigurationException(org.vcell.util.ConfigurationException) ExecutableException(org.vcell.util.exe.ExecutableException) RollbackException(cbit.vcell.message.RollbackException) XmlParseException(cbit.vcell.xml.XmlParseException) SolverException(cbit.vcell.solver.SolverException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) UnknownHostException(java.net.UnknownHostException) VCQueueConsumer(cbit.vcell.message.VCQueueConsumer) VCMessage(cbit.vcell.message.VCMessage) VCMessagingException(cbit.vcell.message.VCMessagingException) HtcJobID(cbit.vcell.server.HtcJobID) VCellQueue(cbit.vcell.message.VCellQueue) SimulationTaskMessage(cbit.vcell.message.messages.SimulationTaskMessage)

Example 8 with HtcJobID

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

the class SlurmProxy method getJobStatus.

@Override
public Map<HtcJobID, JobInfoAndStatus> getJobStatus(List<HtcJobID> htcJobIDs) throws ExecutableException, IOException {
    ArrayList<String> jobNumbers = new ArrayList<String>();
    for (HtcJobID job : htcJobIDs) {
        jobNumbers.add(Long.toString(job.getJobNumber()));
    }
    String jobList = String.join(",", jobNumbers);
    String[] cmds = { Slurm_HOME + JOB_CMD_STATUS, "-u", "vcell", "-P", "-j", jobList, "-o", "jobid%25,jobname%25,partition,user,alloccpus,ncpus,ntasks,state%13,exitcode" };
    CommandOutput commandOutput = commandService.command(cmds);
    String output = commandOutput.getStandardOutput();
    Map<HtcJobID, JobInfoAndStatus> statusMap = extractJobIds(output);
    return statusMap;
}
Also used : CommandOutput(cbit.vcell.message.server.cmd.CommandService.CommandOutput) ArrayList(java.util.ArrayList) HtcJobID(cbit.vcell.server.HtcJobID)

Example 9 with HtcJobID

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

the class ServiceTable method getServiceStatus.

/**
 * This method was created in VisualAge.
 * @return VCImage
 * @param rset ResultSet
 * @param log SessionLog
 */
public ServiceStatus getServiceStatus(ResultSet rset) throws SQLException {
    // serverID
    String parsedServerIDString = rset.getString(serverID.toString());
    VCellServerID parsedServerID = VCellServerID.getServerID(parsedServerIDString);
    // type
    String parsedType = rset.getString(type.toString());
    // ordinal
    int parsedOrdinal = rset.getInt(ordinal.toString());
    // startupType
    int parsedStartupType = rset.getInt(startupType.toString());
    // memoryMB
    int parsedMemoryMB = rset.getInt(memoryMB.toString());
    // date
    java.util.Date parsedDate = rset.getTimestamp(date.toString());
    if (rset.wasNull()) {
        parsedDate = null;
    }
    // status
    int parsedStatus = rset.getInt(status.toString());
    // statusMsg
    String parsedStatusMsg = rset.getString(statusMsg.toString());
    if (rset.wasNull()) {
        parsedStatusMsg = null;
    }
    // host
    HtcJobID parsedHtcJobId = null;
    String parsedHtcJobDatabaseString = rset.getString(pbsjobid.toString());
    if (!rset.wasNull() && parsedHtcJobDatabaseString != null && parsedHtcJobDatabaseString.length() > 0) {
        parsedHtcJobId = SimulationJobTable.fromDatabase(parsedHtcJobDatabaseString);
    }
    ServiceStatus serviceStatus = new ServiceStatus(new ServiceSpec(parsedServerID, ServiceType.fromName(parsedType), parsedOrdinal, ServiceStartupType.fromDatabaseNumber(parsedStartupType), parsedMemoryMB), parsedDate, ServiceStatusType.fromDatabaseNumber(parsedStatus), parsedStatusMsg, parsedHtcJobId);
    return serviceStatus;
}
Also used : VCellServerID(org.vcell.util.document.VCellServerID) ServiceStatus(cbit.vcell.message.server.ServiceStatus) ServiceSpec(cbit.vcell.message.server.ServiceSpec) HtcJobID(cbit.vcell.server.HtcJobID)

Example 10 with HtcJobID

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

the class SimulationJobTable method fromDatabase.

public static HtcJobID fromDatabase(String databaseString) {
    String PBS_Prefix = HtcJobID.BatchSystemType.PBS.name() + ":";
    String SGE_Prefix = HtcJobID.BatchSystemType.SGE.name() + ":";
    String SLURM_Prefix = HtcJobID.BatchSystemType.SLURM.name() + ":";
    if (databaseString.startsWith(PBS_Prefix)) {
        return new HtcJobID(databaseString.substring(PBS_Prefix.length()), BatchSystemType.PBS);
    } else if (databaseString.startsWith(SLURM_Prefix)) {
        return new HtcJobID(databaseString.substring(SLURM_Prefix.length()), BatchSystemType.SLURM);
    } else if (databaseString.startsWith(SGE_Prefix)) {
        return new HtcJobID(databaseString.substring(SGE_Prefix.length()), BatchSystemType.SGE);
    } else {
        return new HtcJobID(databaseString, BatchSystemType.PBS);
    }
}
Also used : HtcJobID(cbit.vcell.server.HtcJobID)

Aggregations

HtcJobID (cbit.vcell.server.HtcJobID)19 SimulationExecutionStatus (cbit.vcell.server.SimulationExecutionStatus)5 SimulationQueueEntryStatus (cbit.vcell.server.SimulationQueueEntryStatus)5 Date (java.util.Date)5 VCellServerID (org.vcell.util.document.VCellServerID)5 SimulationJobStatus (cbit.vcell.server.SimulationJobStatus)4 KeyValue (org.vcell.util.document.KeyValue)4 StatusMessage (cbit.vcell.message.messages.StatusMessage)3 CommandOutput (cbit.vcell.message.server.cmd.CommandService.CommandOutput)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 ExecutableException (org.vcell.util.exe.ExecutableException)3 HtcJobStatus (cbit.vcell.message.server.htc.HtcJobStatus)2 HtcProxy (cbit.vcell.message.server.htc.HtcProxy)2 SchedulerStatus (cbit.vcell.server.SimulationJobStatus.SchedulerStatus)2 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)2 File (java.io.File)2 User (org.vcell.util.document.User)2 RollbackException (cbit.vcell.message.RollbackException)1 VCMessage (cbit.vcell.message.VCMessage)1