use of cbit.vcell.server.SimulationJobStatus in project vcell by virtualcell.
the class BatchScheduler method schedule.
/**
* Insert the method's description here.
* Creation date: (5/11/2006 9:32:58 AM)
*/
public static WaitingJob[] schedule(SimulationJobStatus[] activeJobsThisSite, Map<KeyValue, SimulationRequirements> simulationRequirementsMap, int siteJobQuota, int userQuotaOde, int userQuotaPde, VCellServerID systemID) {
Hashtable<User, Integer> userPdeRunningJobsThisSite = new Hashtable<User, Integer>();
Hashtable<User, Integer> userOdeRunningJobsThisSite = new Hashtable<User, Integer>();
cbit.vcell.server.SimulationJobStatus jobStatus = null;
int numRunningJobsThisSite = 0;
for (int i = 0; i < activeJobsThisSite.length; i++) {
jobStatus = activeJobsThisSite[i];
if (!jobStatus.getSchedulerStatus().isActive()) {
continue;
}
if (jobStatus.getSchedulerStatus().isWaiting()) {
// we only do statistics on running jobs;
continue;
}
numRunningJobsThisSite++;
if (jobStatus.getServerID().equals(systemID)) {
// the number of running jobs on this site
User user = activeJobsThisSite[i].getVCSimulationIdentifier().getOwner();
SimulationRequirements simRequirements = simulationRequirementsMap.get(jobStatus.getVCSimulationIdentifier().getSimulationKey());
if (simRequirements != null && simRequirements.isPDE()) {
Integer numUserPdeJobs = userPdeRunningJobsThisSite.get(user);
if (numUserPdeJobs == null) {
userPdeRunningJobsThisSite.put(user, 1);
} else {
userPdeRunningJobsThisSite.put(user, numUserPdeJobs.intValue() + 1);
}
} else {
Integer numUserOdeJobs = userOdeRunningJobsThisSite.get(user);
if (numUserOdeJobs == null) {
userOdeRunningJobsThisSite.put(user, 1);
} else {
userOdeRunningJobsThisSite.put(user, numUserOdeJobs.intValue() + 1);
}
}
}
}
ArrayList<WaitingJob> waitingJobs = new ArrayList<WaitingJob>();
for (int i = 0; i < activeJobsThisSite.length; i++) {
jobStatus = activeJobsThisSite[i];
if (!jobStatus.getSchedulerStatus().isWaiting()) {
// ignore non-waiting job
continue;
}
if (!jobStatus.getServerID().equals(systemID)) {
// doesn't belong
continue;
}
User user = activeJobsThisSite[i].getVCSimulationIdentifier().getOwner();
Integer numRunningPDEsThisSite = userPdeRunningJobsThisSite.get(user);
if (numRunningPDEsThisSite == null) {
numRunningPDEsThisSite = new Integer(0);
}
Integer numRunningODEsThisSite = userOdeRunningJobsThisSite.get(user);
if (numRunningODEsThisSite == null) {
numRunningODEsThisSite = new Integer(0);
}
long waitingTimeStamp = jobStatus.getSimulationQueueEntryStatus().getQueueDate().getTime();
KeyValue simKey = jobStatus.getVCSimulationIdentifier().getSimulationKey();
waitingJobs.add(new WaitingJob(user, numRunningPDEsThisSite, numRunningODEsThisSite, waitingTimeStamp, jobStatus, simulationRequirementsMap.get(simKey)));
}
Collections.sort(waitingJobs, new Comparator<WaitingJob>() {
@Override
public int compare(WaitingJob o1, WaitingJob o2) {
//
if (!o1.getNumRunningJobs().equals(o2.getNumRunningJobs())) {
return o1.getNumRunningJobs().compareTo(o2.getNumRunningJobs());
}
//
if (o1.simRequirements.isPDE() != o2.simRequirements.isPDE()) {
if (o1.simRequirements.isPDE()) {
return 1;
} else {
return -1;
}
}
//
return o1.waitingTimeStamp.compareTo(o2.waitingTimeStamp);
}
});
//
// enforce quota for each user
//
HashSet<User> users = new HashSet<User>();
users.addAll(userPdeRunningJobsThisSite.keySet());
users.addAll(userOdeRunningJobsThisSite.keySet());
for (User user : users) {
Integer numRunningPDEsThisSite = userPdeRunningJobsThisSite.get(user);
int numRunningPDEs = 0;
if (numRunningPDEsThisSite != null) {
numRunningPDEs = numRunningPDEsThisSite;
}
Integer numRunningODEsThisSite = userOdeRunningJobsThisSite.get(user);
int numRunningODEs = 0;
if (numRunningODEsThisSite != null) {
numRunningODEs = numRunningODEsThisSite;
}
//
// go full list and remove any jobs that would exceed this users quota
//
Iterator<WaitingJob> waitingJobIter = waitingJobs.iterator();
while (waitingJobIter.hasNext()) {
WaitingJob waitingJob = waitingJobIter.next();
if (waitingJob.user.equals(user)) {
if (waitingJob.simRequirements.isPDE()) {
if (numRunningPDEs < userQuotaPde) {
numRunningPDEs++;
} else {
waitingJobIter.remove();
}
} else {
if (numRunningODEs < userQuotaOde) {
numRunningODEs++;
} else {
waitingJobIter.remove();
}
}
}
}
}
//
// enforce site quota (keep only first N jobs) where currentRunning + N <= quota
//
int numJobsSlotsAvailable = Math.max(0, siteJobQuota - numRunningJobsThisSite);
int numJobsEligible = waitingJobs.size();
int numJobsToDispatch = Math.min(numJobsSlotsAvailable, numJobsEligible);
if (numJobsToDispatch == 0) {
return new WaitingJob[0];
} else {
return waitingJobs.subList(0, numJobsToDispatch).toArray(new WaitingJob[0]);
}
}
use of cbit.vcell.server.SimulationJobStatus in project vcell by virtualcell.
the class ClientTopicMessageCollector method onTopicMessage.
/**
* Insert the method's description here.
* Creation date: (10/23/2001 3:58:52 PM)
* @param message javax.jms.Message
* @throws VCMessagingException
*/
public void onTopicMessage(VCMessage message, VCMessageSession session) {
if (message == null) {
return;
}
try {
// Check if it's a broadcast message
if (message instanceof VCMessageJms) {
VCMessageJms vcMessageJms = (VCMessageJms) message;
javax.jms.Message myMessage = vcMessageJms.getJmsMessage();
if (myMessage instanceof ActiveMQTextMessage) {
ActiveMQTextMessage myAMQ = (ActiveMQTextMessage) myMessage;
if (myAMQ.getType().equalsIgnoreCase(MessageConstants.MESSAGE_TYPE_BROADCASTMESSAGE_VALUE)) {
fireMessageEvent(new VCellMessageEvent(this, System.currentTimeMillis() + "", new MessageData(myAMQ.getText()), VCellMessageEvent.VCELL_MESSAGEEVENT_TYPE_BROADCAST, null));
return;
}
}
}
if (message.getObjectContent() == null) {
throw new Exception(this.getClass().getName() + ".onTopicMessage: unimplemented message class " + message.show());
}
setTimeSinceLastMessage(System.currentTimeMillis());
String msgType = message.getStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY);
if (msgType == null) {
throw new Exception(this.getClass().getName() + ".onTopicMessage: message type NULL for message " + message);
}
if (msgType.equals(MessageConstants.MESSAGE_TYPE_SIMSTATUS_VALUE)) {
String messageUserName = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
StatusMessage statusMessage = new StatusMessage(message);
String userName = VCMessagingConstants.USERNAME_PROPERTY_VALUE_ALL;
if (message.propertyExists(VCMessagingConstants.USERNAME_PROPERTY)) {
userName = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
}
SimulationJobStatus newJobStatus = statusMessage.getJobStatus();
if (newJobStatus == null) {
return;
}
VCSimulationIdentifier vcSimID = newJobStatus.getVCSimulationIdentifier();
Double progress = statusMessage.getProgress();
Double timePoint = statusMessage.getTimePoint();
fireSimulationJobStatusEvent(new SimulationJobStatusEvent(this, vcSimID.getID(), newJobStatus, progress, timePoint, messageUserName));
} else if (msgType.equals(MessageConstants.MESSAGE_TYPE_EXPORT_EVENT_VALUE)) {
String messageUserName = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
ExportEvent event = (ExportEvent) message.getObjectContent();
fireExportEvent(event);
} else if (msgType.equals(MessageConstants.MESSAGE_TYPE_DATA_EVENT_VALUE)) {
String messageUserName = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
DataJobEvent event = (DataJobEvent) message.getObjectContent();
fireMessageEvent(event);
} else if (msgType.equals(MessageConstants.MESSAGE_TYPE_BROADCASTMESSAGE_VALUE)) {
String messageUserName = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
fireMessageEvent(new VCellMessageEvent(this, System.currentTimeMillis() + "", new MessageData((BigString) message.getObjectContent()), VCellMessageEvent.VCELL_MESSAGEEVENT_TYPE_BROADCAST, messageUserName));
} else {
throw new Exception(this.getClass().getName() + ".onControlTopicMessage: Unimplemented message " + message.show());
}
} catch (Exception e) {
e.printStackTrace();
lg.error(e.getMessage(), e);
}
}
use of cbit.vcell.server.SimulationJobStatus in project vcell by virtualcell.
the class SimulationJobStatusEvent method isSupercededBy.
@Override
public boolean isSupercededBy(MessageEvent messageEvent) {
if (messageEvent instanceof SimulationJobStatusEvent) {
SimulationJobStatusEvent simulationJobStatusEvent = (SimulationJobStatusEvent) messageEvent;
SimulationJobStatus jobStatus2 = simulationJobStatusEvent.jobStatus;
if (jobStatus != null && jobStatus2 != null && jobStatus.getVCSimulationIdentifier().equals(jobStatus2.getVCSimulationIdentifier()) && jobStatus.getJobIndex() == jobStatus2.getJobIndex()) {
if (jobStatus.getSchedulerStatus().isRunning() && getProgress() != null && jobStatus2.getSchedulerStatus().isRunning() && simulationJobStatusEvent.getProgress() != null) {
if (getProgress() < simulationJobStatusEvent.getProgress()) {
return true;
}
}
}
}
return false;
}
use of cbit.vcell.server.SimulationJobStatus in project vcell by virtualcell.
the class SimulationStateMachine method onWorkerEvent.
public synchronized void onWorkerEvent(WorkerEvent workerEvent, SimulationDatabase simulationDatabase, VCMessageSession session) throws DataAccessException, VCMessagingException, SQLException {
updateSolverProcessTimestamp();
WorkerEventMessage workerEventMessage = new WorkerEventMessage(workerEvent);
VCMongoMessage.sendWorkerEvent(workerEventMessage);
// as the filter of the client
String userName = workerEvent.getUserName();
int workerEventTaskID = workerEvent.getTaskID();
if (lg.isTraceEnabled())
lg.trace("onWorkerEventMessage[" + workerEvent.getEventTypeID() + "," + workerEvent.getSimulationMessage() + "][simid=" + workerEvent.getVCSimulationDataIdentifier() + ",job=" + jobIndex + ",task=" + workerEventTaskID + "]");
VCSimulationDataIdentifier vcSimDataID = workerEvent.getVCSimulationDataIdentifier();
if (vcSimDataID == null) {
VCMongoMessage.sendInfo("onWorkerEvent() ignoring WorkerEvent - no SimID in message): " + workerEvent.show());
return;
}
KeyValue simKey = vcSimDataID.getSimulationKey();
SimulationJobStatus oldSimulationJobStatus = simulationDatabase.getLatestSimulationJobStatus(simKey, jobIndex);
if (oldSimulationJobStatus == null) {
VCMongoMessage.sendInfo("onWorkerEvent() ignoring WorkerEvent, no current SimulationJobStatus: " + workerEvent.show());
return;
}
if (oldSimulationJobStatus == null || oldSimulationJobStatus.getSchedulerStatus().isDone() || oldSimulationJobStatus.getTaskID() > workerEventTaskID) {
VCMongoMessage.sendInfo("onWorkerEvent() ignoring outdated WorkerEvent, (currState=" + oldSimulationJobStatus.getSchedulerStatus().getDescription() + "): " + workerEvent.show());
return;
}
int taskID = oldSimulationJobStatus.getTaskID();
SchedulerStatus oldSchedulerStatus = oldSimulationJobStatus.getSchedulerStatus();
//
// status information (initialized as if new record)
//
Date startDate = null;
Date lastUpdateDate = null;
Date endDate = null;
boolean hasData = false;
HtcJobID htcJobID = null;
String computeHost = null;
VCellServerID vcServerID = VCellServerID.getSystemServerID();
Date submitDate = null;
Date queueDate = null;
int queuePriority = PRIORITY_DEFAULT;
SimulationJobStatus.SimulationQueueID simQueueID = SimulationJobStatus.SimulationQueueID.QUEUE_ID_WAITING;
//
// update using previously stored status (if available).
//
SimulationExecutionStatus oldSimExeStatus = oldSimulationJobStatus.getSimulationExecutionStatus();
if (oldSimExeStatus != null && oldSimExeStatus.getStartDate() != null) {
startDate = oldSimExeStatus.getStartDate();
}
if (oldSimExeStatus != null && oldSimExeStatus.getLatestUpdateDate() != null) {
lastUpdateDate = oldSimExeStatus.getLatestUpdateDate();
}
if (oldSimExeStatus != null && oldSimExeStatus.getEndDate() != null) {
endDate = oldSimExeStatus.getEndDate();
}
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 = oldSimulationJobStatus.getServerID();
submitDate = oldSimulationJobStatus.getSubmitDate();
SimulationQueueEntryStatus oldQueueStatus = oldSimulationJobStatus.getSimulationQueueEntryStatus();
if (oldQueueStatus != null && oldQueueStatus.getQueueDate() != null) {
queueDate = oldQueueStatus.getQueueDate();
}
if (oldQueueStatus != null) {
queuePriority = oldQueueStatus.getQueuePriority();
}
if (oldQueueStatus != null && oldQueueStatus.getQueueID() != null) {
simQueueID = oldQueueStatus.getQueueID();
}
//
if (workerEvent.getHtcJobID() != null) {
htcJobID = workerEvent.getHtcJobID();
}
if (workerEvent.getHostName() != null) {
computeHost = workerEvent.getHostName();
}
SimulationMessage workerEventSimulationMessage = workerEvent.getSimulationMessage();
if (workerEventSimulationMessage.getHtcJobId() != null) {
htcJobID = workerEventSimulationMessage.getHtcJobId();
}
SimulationJobStatus newJobStatus = null;
if (workerEvent.isAcceptedEvent()) {
//
if (oldSchedulerStatus.isWaiting() || oldSchedulerStatus.isQueued()) {
// new queue status
SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(queueDate, queuePriority, SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL);
// new exe status
lastUpdateDate = new Date();
startDate = lastUpdateDate;
endDate = null;
SimulationExecutionStatus newExeStatus = new SimulationExecutionStatus(startDate, computeHost, lastUpdateDate, endDate, hasData, htcJobID);
newJobStatus = new SimulationJobStatus(vcServerID, vcSimDataID.getVcSimID(), jobIndex, submitDate, SchedulerStatus.DISPATCHED, taskID, workerEventSimulationMessage, newQueueStatus, newExeStatus);
}
} else if (workerEvent.isStartingEvent()) {
// only update database when the job event changes from started to running. The later progress event will not be recorded.
if (oldSchedulerStatus.isWaiting() || oldSchedulerStatus.isQueued() || oldSchedulerStatus.isDispatched() || oldSchedulerStatus.isRunning()) {
// new queue status
SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(queueDate, queuePriority, SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL);
// new exe status
lastUpdateDate = new Date();
if (startDate == null) {
startDate = lastUpdateDate;
}
SimulationExecutionStatus newExeStatus = new SimulationExecutionStatus(startDate, computeHost, lastUpdateDate, endDate, hasData, htcJobID);
newJobStatus = new SimulationJobStatus(vcServerID, vcSimDataID.getVcSimID(), jobIndex, submitDate, SchedulerStatus.RUNNING, taskID, workerEventSimulationMessage, newQueueStatus, newExeStatus);
}
} else if (workerEvent.isNewDataEvent()) {
if (oldSchedulerStatus.isWaiting() || oldSchedulerStatus.isQueued() || oldSchedulerStatus.isDispatched() || oldSchedulerStatus.isRunning()) {
if (!oldSchedulerStatus.isRunning() || simQueueID != SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL || hasData == false) {
// new queue status
SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(queueDate, queuePriority, SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL);
// new exe status
if (startDate == null) {
startDate = lastUpdateDate;
}
hasData = true;
SimulationExecutionStatus newExeStatus = new SimulationExecutionStatus(startDate, computeHost, lastUpdateDate, endDate, hasData, htcJobID);
newJobStatus = new SimulationJobStatus(vcServerID, vcSimDataID.getVcSimID(), jobIndex, submitDate, SchedulerStatus.RUNNING, taskID, workerEventSimulationMessage, newQueueStatus, newExeStatus);
}
}
} else if (workerEvent.isProgressEvent() || workerEvent.isWorkerAliveEvent()) {
if (oldSchedulerStatus.isWaiting() || oldSchedulerStatus.isQueued() || oldSchedulerStatus.isDispatched() || oldSchedulerStatus.isRunning()) {
if (!oldSchedulerStatus.isRunning() || simQueueID != SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL) {
// new queue status
SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(queueDate, queuePriority, SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL);
// new exe status
if (startDate == null) {
startDate = lastUpdateDate;
}
SimulationExecutionStatus newExeStatus = new SimulationExecutionStatus(startDate, computeHost, lastUpdateDate, endDate, hasData, htcJobID);
newJobStatus = new SimulationJobStatus(vcServerID, vcSimDataID.getVcSimID(), jobIndex, submitDate, SchedulerStatus.RUNNING, taskID, workerEventSimulationMessage, newQueueStatus, newExeStatus);
} else if (oldSchedulerStatus.isRunning()) {
if (oldSimExeStatus != null) {
// Date latestUpdate = oldSimExeStatus.getLatestUpdateDate();
// if (System.currentTimeMillis() - latestUpdate.getTime() >= MessageConstants.INTERVAL_PING_SERVER_MS * 3 / 5) {
// new queue status
SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(queueDate, queuePriority, SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL);
SimulationExecutionStatus newExeStatus = new SimulationExecutionStatus(startDate, computeHost, lastUpdateDate, endDate, hasData, htcJobID);
newJobStatus = new SimulationJobStatus(vcServerID, vcSimDataID.getVcSimID(), jobIndex, submitDate, SchedulerStatus.RUNNING, taskID, workerEventSimulationMessage, newQueueStatus, newExeStatus);
}
// }
}
}
} else if (workerEvent.isCompletedEvent()) {
if (oldSchedulerStatus.isWaiting() || oldSchedulerStatus.isQueued() || oldSchedulerStatus.isDispatched() || oldSchedulerStatus.isRunning()) {
// new queue status
SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(queueDate, queuePriority, SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL);
// new exe status
endDate = new Date();
hasData = true;
SimulationExecutionStatus newExeStatus = new SimulationExecutionStatus(startDate, computeHost, lastUpdateDate, endDate, hasData, htcJobID);
newJobStatus = new SimulationJobStatus(vcServerID, vcSimDataID.getVcSimID(), jobIndex, submitDate, SchedulerStatus.COMPLETED, taskID, workerEventSimulationMessage, newQueueStatus, newExeStatus);
}
} else if (workerEvent.isFailedEvent()) {
if (oldSchedulerStatus.isWaiting() || oldSchedulerStatus.isQueued() || oldSchedulerStatus.isDispatched() || oldSchedulerStatus.isRunning()) {
// new queue status
SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(queueDate, queuePriority, SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL);
// new exe status
endDate = new Date();
SimulationExecutionStatus newExeStatus = new SimulationExecutionStatus(startDate, computeHost, lastUpdateDate, endDate, hasData, htcJobID);
newJobStatus = new SimulationJobStatus(vcServerID, vcSimDataID.getVcSimID(), jobIndex, submitDate, SchedulerStatus.FAILED, taskID, workerEventSimulationMessage, newQueueStatus, newExeStatus);
}
} else if (workerEvent.isWorkerExitErrorEvent()) {
if (oldSchedulerStatus.isWaiting() || oldSchedulerStatus.isQueued() || oldSchedulerStatus.isDispatched() || oldSchedulerStatus.isRunning()) {
// new queue status
SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(queueDate, queuePriority, SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL);
// new exe status
endDate = new Date();
SimulationExecutionStatus newExeStatus = new SimulationExecutionStatus(startDate, computeHost, lastUpdateDate, endDate, hasData, htcJobID);
SimulationMessage simulationMessage = SimulationMessage.workerFailure("solver stopped unexpectedly, " + workerEventSimulationMessage.getDisplayMessage());
newJobStatus = new SimulationJobStatus(vcServerID, vcSimDataID.getVcSimID(), jobIndex, submitDate, SchedulerStatus.FAILED, taskID, simulationMessage, newQueueStatus, newExeStatus);
}
}
if (newJobStatus != null) {
if (!newJobStatus.compareEqual(oldSimulationJobStatus) || workerEvent.isProgressEvent() || workerEvent.isNewDataEvent()) {
Double progress = workerEvent.getProgress();
Double timepoint = workerEvent.getTimePoint();
RunningStateInfo runningStateInfo = null;
if (progress != null && timepoint != null) {
runningStateInfo = new RunningStateInfo(progress, timepoint);
}
simulationDatabase.updateSimulationJobStatus(newJobStatus, runningStateInfo);
StatusMessage msgForClient = new StatusMessage(newJobStatus, userName, progress, timepoint);
msgForClient.sendToClient(session);
if (lg.isTraceEnabled())
lg.trace("Send status to client: " + msgForClient);
} else {
simulationDatabase.updateSimulationJobStatus(newJobStatus);
StatusMessage msgForClient = new StatusMessage(newJobStatus, userName, null, null);
msgForClient.sendToClient(session);
if (lg.isTraceEnabled())
lg.trace("Send status to client: " + msgForClient);
}
} else if (workerEvent.isProgressEvent() || workerEvent.isNewDataEvent()) {
Double progress = workerEvent.getProgress();
Double timepoint = workerEvent.getTimePoint();
RunningStateInfo runningStateInfo = null;
if (progress != null && timepoint != null) {
runningStateInfo = new RunningStateInfo(progress, timepoint);
}
simulationDatabase.updateSimulationJobStatus(oldSimulationJobStatus, runningStateInfo);
StatusMessage msgForClient = new StatusMessage(oldSimulationJobStatus, userName, progress, timepoint);
msgForClient.sendToClient(session);
if (lg.isTraceEnabled())
lg.trace("Send status to client: " + msgForClient);
} else {
VCMongoMessage.sendInfo("onWorkerEvent() ignoring WorkerEvent (currState=" + oldSchedulerStatus.getDescription() + "): " + workerEvent.show());
}
// addStateMachineTransition(new StateMachineTransition(new WorkerStateMachineEvent(taskID, workerEvent), oldSimulationJobStatus, newJobStatus));
}
use of cbit.vcell.server.SimulationJobStatus 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);
}
Aggregations