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);
}
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);
}
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;
}
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;
}
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);
}
}
Aggregations