use of cbit.vcell.server.SimulationJobStatus in project vcell by virtualcell.
the class SimulationStateMachine method onStopRequest.
public synchronized void onStopRequest(User user, SimulationJobStatus simJobStatus, SimulationDatabase simulationDatabase, VCMessageSession session) throws VCMessagingException, DataAccessException, SQLException {
updateSolverProcessTimestamp();
if (!user.equals(simJobStatus.getVCSimulationIdentifier().getOwner())) {
lg.error(user + " is not authorized to stop simulation (key=" + simKey + ")");
StatusMessage message = new StatusMessage(new SimulationJobStatus(VCellServerID.getSystemServerID(), simJobStatus.getVCSimulationIdentifier(), 0, null, SchedulerStatus.FAILED, 0, SimulationMessage.workerFailure("You are not authorized to stop this simulation!"), null, null), user.getName(), null, null);
message.sendToClient(session);
VCMongoMessage.sendInfo("onStopRequest(" + simJobStatus.getVCSimulationIdentifier() + ") ignoring stop simulation request - wrong user)");
return;
}
// stop latest task if active
SchedulerStatus schedulerStatus = simJobStatus.getSchedulerStatus();
int taskID = simJobStatus.getTaskID();
if (schedulerStatus.isActive()) {
SimulationQueueEntryStatus simQueueEntryStatus = simJobStatus.getSimulationQueueEntryStatus();
SimulationExecutionStatus simExeStatus = simJobStatus.getSimulationExecutionStatus();
SimulationJobStatus newJobStatus = new SimulationJobStatus(simJobStatus.getServerID(), simJobStatus.getVCSimulationIdentifier(), jobIndex, simJobStatus.getSubmitDate(), SchedulerStatus.STOPPED, taskID, SimulationMessage.solverStopped("simulation stopped by user"), simQueueEntryStatus, simExeStatus);
//
if (lg.isTraceEnabled())
lg.trace("send " + MessageConstants.MESSAGE_TYPE_STOPSIMULATION_VALUE + " to " + VCellTopic.ServiceControlTopic.getName() + " topic");
VCMessage msg = session.createMessage();
msg.setStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY, MessageConstants.MESSAGE_TYPE_STOPSIMULATION_VALUE);
msg.setLongProperty(MessageConstants.SIMKEY_PROPERTY, Long.parseLong(simKey + ""));
msg.setIntProperty(MessageConstants.JOBINDEX_PROPERTY, jobIndex);
msg.setIntProperty(MessageConstants.TASKID_PROPERTY, taskID);
msg.setStringProperty(VCMessagingConstants.USERNAME_PROPERTY, user.getName());
if (simExeStatus.getHtcJobID() != null) {
msg.setStringProperty(MessageConstants.HTCJOBID_PROPERTY, simExeStatus.getHtcJobID().toDatabase());
}
session.sendTopicMessage(VCellTopic.ServiceControlTopic, msg);
simulationDatabase.updateSimulationJobStatus(newJobStatus);
// addStateMachineTransition(new StateMachineTransition(new StopStateMachineEvent(taskID), simJobStatus, newJobStatus));
// update client
StatusMessage message = new StatusMessage(newJobStatus, user.getName(), null, null);
message.sendToClient(session);
}
}
use of cbit.vcell.server.SimulationJobStatus in project vcell by virtualcell.
the class SimulationDispatcherEngine method onStopRequest.
public void onStopRequest(VCSimulationIdentifier vcSimID, User user, SimulationDatabase simulationDatabase, VCMessageSession session) throws DataAccessException, VCMessagingException, SQLException {
KeyValue simKey = vcSimID.getSimulationKey();
SimulationJobStatus[] allActiveSimJobStatusArray = simulationDatabase.getActiveJobs(VCellServerID.getSystemServerID());
ArrayList<SimulationJobStatus> simJobStatusArray = new ArrayList<SimulationJobStatus>();
for (SimulationJobStatus activeSimJobStatus : allActiveSimJobStatusArray) {
if (activeSimJobStatus.getVCSimulationIdentifier().getSimulationKey().equals(vcSimID.getSimulationKey())) {
simJobStatusArray.add(activeSimJobStatus);
}
}
for (SimulationJobStatus simJobStatus : simJobStatusArray) {
SimulationStateMachine simStateMachine = getSimulationStateMachine(simKey, simJobStatus.getJobIndex());
try {
simStateMachine.onStopRequest(user, simJobStatus, simulationDatabase, session);
} catch (UpdateSynchronizationException e) {
simStateMachine.onStopRequest(user, simJobStatus, simulationDatabase, session);
}
}
}
use of cbit.vcell.server.SimulationJobStatus in project vcell by virtualcell.
the class SimulationDatabaseDirect method translateToSimulationJobStatusTransient.
private SimulationJobStatus translateToSimulationJobStatusTransient(SimulationJobStatusPersistent simJobStatus) {
VCellServerID serverID = simJobStatus.getServerID();
VCSimulationIdentifier vcSimID = simJobStatus.getVCSimulationIdentifier();
int jobIndex = simJobStatus.getJobIndex();
Date submitDate = simJobStatus.getSubmitDate();
SchedulerStatus schedulerStatus = SimulationJobStatus.SchedulerStatus.valueOf(simJobStatus.getSchedulerStatus().name());
int taskID = simJobStatus.getTaskID();
SimulationMessage simMessage = SimulationMessage.fromSerializedMessage(simJobStatus.getSimulationMessage().toSerialization());
Date queueDate = simJobStatus.getSimulationQueueEntryStatus().getQueueDate();
int queuePriority = simJobStatus.getSimulationQueueEntryStatus().getQueuePriority();
SimulationQueueID queueId = SimulationJobStatus.SimulationQueueID.valueOf(simJobStatus.getSimulationQueueEntryStatus().getQueueID().name());
SimulationQueueEntryStatus simQueueStatus = new SimulationQueueEntryStatus(queueDate, queuePriority, queueId);
SimulationExecutionStatus simExecStatus = new SimulationExecutionStatus(simJobStatus.getSimulationExecutionStatus().getStartDate(), simJobStatus.getSimulationExecutionStatus().getComputeHost(), simJobStatus.getSimulationExecutionStatus().getLatestUpdateDate(), simJobStatus.getSimulationExecutionStatus().getEndDate(), simJobStatus.getSimulationExecutionStatus().hasData(), simJobStatus.getSimulationExecutionStatus().getHtcJobID());
SimulationJobStatus simJobStatusTransient = new SimulationJobStatus(serverID, vcSimID, jobIndex, submitDate, schedulerStatus, taskID, simMessage, simQueueStatus, simExecStatus);
return simJobStatusTransient;
}
use of cbit.vcell.server.SimulationJobStatus in project vcell by virtualcell.
the class SimulationDatabaseDirect method translateToSimpleJobStatusTransient.
private SimpleJobStatus translateToSimpleJobStatusTransient(SimpleJobStatusPersistent simpleJobStatusPersistent, SimulationJobStatus cachedSimulationJobStatus, StateInfo cachedStateInfo) {
SimulationJobStatus simJobStatus = null;
if (cachedSimulationJobStatus != null) {
simJobStatus = cachedSimulationJobStatus;
} else {
simJobStatus = translateToSimulationJobStatusTransient(simpleJobStatusPersistent.jobStatus);
}
SimpleJobStatus simpleJobStatus = new SimpleJobStatus(simpleJobStatusPersistent.simulationMetadata, simpleJobStatusPersistent.simulationDocumentLink, simJobStatus, cachedStateInfo);
return simpleJobStatus;
}
use of cbit.vcell.server.SimulationJobStatus in project vcell by virtualcell.
the class SimulationDatabaseDirect method queryJobs.
@Override
public SimulationJobStatus[] queryJobs(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<SimulationJobStatusPersistent> simpleJobStatusPersistentList = databaseServerImpl.getSimulationJobStatus(simStatusQuerySpec);
ArrayList<SimulationJobStatus> simulationJobStatusList = new ArrayList<SimulationJobStatus>();
for (SimulationJobStatusPersistent simJobStatusDb : simpleJobStatusPersistentList) {
SimJobStatusKey key = new SimJobStatusKey(simJobStatusDb.getVCSimulationIdentifier().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));
}
SimulationJobStatus simulationJobStatus = translateToSimulationJobStatusTransient(simJobStatusDb);
// uses latest SimulationJobStatus and StateInfo.
simulationJobStatusList.add(simulationJobStatus);
}
return simulationJobStatusList.toArray(new SimulationJobStatus[simulationJobStatusList.size()]);
}
Aggregations