use of org.vcell.util.document.KeyValue in project vcell by virtualcell.
the class FieldDataDBOperationDriver method getFunctionFileNamesAndSimKeys.
public static synchronized HashMap<String, KeyValue> getFunctionFileNamesAndSimKeys(User user) throws DataAccessException {
String sql = "SELECT " + SimulationJobTable.table.simRef.getQualifiedColName() + "," + SimulationJobTable.table.jobIndex.getQualifiedColName() + " FROM " + SimulationJobTable.table.getTableName() + "," + SimulationTable.table.getTableName() + " WHERE " + SimulationTable.table.ownerRef.getQualifiedColName() + " = " + user.getID() + " AND " + SimulationTable.table.id.getQualifiedColName() + " = " + SimulationJobTable.table.simRef.getQualifiedColName() + " UNION " + " SELECT " + SimulationTable.table.id.getQualifiedColName() + "," + // SimulationJobTable.table.jobIndex.getUnqualifiedColName()+
"TO_NUMBER(NULL) " + " FROM " + SimulationTable.table.getTableName() + " WHERE " + SimulationTable.table.ownerRef.getQualifiedColName() + "=" + user.getID() + " AND " + SimulationTable.table.id.getQualifiedColName() + " NOT IN (SELECT " + SimulationJobTable.table.simRef.getQualifiedColName() + " FROM " + SimulationJobTable.table.getTableName() + " )" + " UNION " + " SELECT " + ExternalDataTable.table.id.getQualifiedColName() + "," + "TO_NUMBER(0) " + " FROM " + ExternalDataTable.table.getTableName() + " WHERE " + ExternalDataTable.table.ownerRef.getQualifiedColName() + "=" + user.getID();
Statement stmt = null;
HashMap<String, KeyValue> functionNamesH = new HashMap<String, KeyValue>();
try {
stmt = getConnection().createStatement();
ResultSet rset = stmt.executeQuery(sql);
while (rset.next()) {
KeyValue simKey = new KeyValue(rset.getBigDecimal(1));
BigDecimal jobIndex = rset.getBigDecimal(2);
boolean isOldStyle = rset.wasNull();
functionNamesH.put(SimulationData.createCanonicalFunctionsFileName(simKey, (isOldStyle ? 0 : jobIndex.intValue()), isOldStyle), simKey);
}
} catch (Exception e) {
e.printStackTrace();
throw new DataAccessException("Error: getFunctionFileNamesAndSimKeys", e);
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return functionNamesH;
}
use of org.vcell.util.document.KeyValue in project vcell by virtualcell.
the class SimulationControllerImpl method onSimJobQueue_SimulationTask.
private void onSimJobQueue_SimulationTask(VCMessage vcMessage) {
SimulationTask simTask = null;
try {
SimulationTaskMessage simTaskMessage = new SimulationTaskMessage(vcMessage);
simTask = simTaskMessage.getSimulationTask();
LocalSolverController solverController = getOrCreateSolverController(simTask);
// can only start after updating the database is done
solverController.startSimulationJob();
} catch (Exception e) {
lg.error(e.getMessage(), e);
KeyValue simKey = simTask.getSimKey();
VCSimulationIdentifier vcSimID = simTask.getSimulationJob().getVCDataIdentifier().getVcSimID();
int jobIndex = simTask.getSimulationJob().getJobIndex();
int taskID = simTask.getTaskID();
SimulationJobStatus newJobStatus = new SimulationJobStatus(VCellServerID.getSystemServerID(), vcSimID, jobIndex, null, SchedulerStatus.FAILED, taskID, SimulationMessage.jobFailed(e.getMessage()), null, null);
SimulationJobStatusEvent event = new SimulationJobStatusEvent(this, Simulation.createSimulationID(simKey), newJobStatus, null, null, vcSimID.getOwner().getName());
fireSimulationJobStatusEvent(event);
}
}
use of org.vcell.util.document.KeyValue 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 org.vcell.util.document.KeyValue in project vcell by virtualcell.
the class SimulationDatabaseDirect method getFieldDataIdentifierSpecs.
@Override
public FieldDataIdentifierSpec[] getFieldDataIdentifierSpecs(Simulation sim) throws DataAccessException {
try {
KeyValue simKey = sim.getKey();
if (lg.isTraceEnabled())
lg.trace("Get FieldDataIdentifierSpec for [" + simKey + "]");
FieldDataIdentifierSpec[] fieldDataIDSs = (FieldDataIdentifierSpec[]) simFieldDataIDMap.get(simKey);
if (fieldDataIDSs != null) {
return fieldDataIDSs;
}
FieldFunctionArguments[] fieldFuncArgs = FieldUtilities.getFieldFunctionArguments(sim.getMathDescription());
if (fieldFuncArgs == null || fieldFuncArgs.length == 0) {
fieldDataIDSs = new FieldDataIdentifierSpec[0];
simFieldDataIDMap.put(simKey, fieldDataIDSs);
return fieldDataIDSs;
}
fieldDataIDSs = new FieldDataIdentifierSpec[0];
User owner = sim.getVersion().getOwner();
FieldDataDBOperationSpec fieldDataDbOperationSpec = FieldDataDBOperationSpec.createGetExtDataIDsSpec(owner);
FieldDataDBOperationResults fieldDataDBOperationResults = databaseServerImpl.fieldDataDBOperation(owner, fieldDataDbOperationSpec);
ExternalDataIdentifier[] externalDataIDs = fieldDataDBOperationResults.extDataIDArr;
if (externalDataIDs != null && externalDataIDs.length != 0 && fieldFuncArgs != null && fieldFuncArgs.length > 0) {
Vector<FieldDataIdentifierSpec> fieldDataIdV = new Vector<FieldDataIdentifierSpec>();
for (int j = 0; fieldFuncArgs != null && j < fieldFuncArgs.length; j += 1) {
for (int i = 0; i < externalDataIDs.length; i += 1) {
if (externalDataIDs[i].getName().equals(fieldFuncArgs[j].getFieldName())) {
fieldDataIdV.add(new FieldDataIdentifierSpec(fieldFuncArgs[j], externalDataIDs[i]));
break;
}
}
}
if (fieldDataIdV.size() > 0) {
fieldDataIDSs = new FieldDataIdentifierSpec[fieldDataIdV.size()];
fieldDataIdV.copyInto(fieldDataIDSs);
}
}
simFieldDataIDMap.put(simKey, fieldDataIDSs);
return fieldDataIDSs;
} catch (Exception ex) {
lg.error(ex.getMessage(), ex);
throw new DataAccessException(ex.getMessage());
}
}
use of org.vcell.util.document.KeyValue in project vcell by virtualcell.
the class SimulationDispatcherEngine method onSystemAbort.
public void onSystemAbort(SimulationJobStatus jobStatus, String failureMessage, SimulationDatabase simulationDatabase, VCMessageSession session) {
try {
KeyValue simKey = jobStatus.getVCSimulationIdentifier().getSimulationKey();
int jobIndex = jobStatus.getJobIndex();
SimulationStateMachine simStateMachine = getSimulationStateMachine(simKey, jobIndex);
simStateMachine.onSystemAbort(jobStatus, failureMessage, simulationDatabase, session);
} catch (Exception ex) {
lg.error(ex.getMessage(), ex);
}
}
Aggregations