Search in sources :

Example 71 with KeyValue

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;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) HashMap(java.util.HashMap) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) BigDecimal(java.math.BigDecimal) SQLException(java.sql.SQLException) DataAccessException(org.vcell.util.DataAccessException) DataAccessException(org.vcell.util.DataAccessException)

Example 72 with KeyValue

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);
    }
}
Also used : LocalSolverController(cbit.vcell.solvers.LocalSolverController) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) SimulationTask(cbit.vcell.messaging.server.SimulationTask) KeyValue(org.vcell.util.document.KeyValue) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) SimulationJobStatusEvent(cbit.rmi.event.SimulationJobStatusEvent) SimulationTaskMessage(cbit.vcell.message.messages.SimulationTaskMessage) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) SQLException(java.sql.SQLException) VCMessagingException(cbit.vcell.message.VCMessagingException) SolverException(cbit.vcell.solver.SolverException) AuthenticationException(org.vcell.util.AuthenticationException) DataAccessException(org.vcell.util.DataAccessException) JMSException(javax.jms.JMSException) FileNotFoundException(java.io.FileNotFoundException) RemoteException(java.rmi.RemoteException) ConfigurationException(org.vcell.util.ConfigurationException)

Example 73 with KeyValue

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]);
    }
}
Also used : User(org.vcell.util.document.User) SimulationRequirements(cbit.vcell.messaging.db.SimulationRequirements) KeyValue(org.vcell.util.document.KeyValue) Hashtable(java.util.Hashtable) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 74 with KeyValue

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());
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) UpdateSynchronizationException(cbit.vcell.server.UpdateSynchronizationException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) FieldDataDBOperationResults(cbit.vcell.field.FieldDataDBOperationResults) FieldDataDBOperationSpec(cbit.vcell.field.FieldDataDBOperationSpec) Vector(java.util.Vector) DataAccessException(org.vcell.util.DataAccessException)

Example 75 with KeyValue

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);
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) DataAccessException(org.vcell.util.DataAccessException) UpdateSynchronizationException(cbit.vcell.server.UpdateSynchronizationException) SQLException(java.sql.SQLException) VCMessagingException(cbit.vcell.message.VCMessagingException)

Aggregations

KeyValue (org.vcell.util.document.KeyValue)325 DataAccessException (org.vcell.util.DataAccessException)92 User (org.vcell.util.document.User)68 ResultSet (java.sql.ResultSet)57 Statement (java.sql.Statement)52 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)44 SQLException (java.sql.SQLException)43 BigString (org.vcell.util.BigString)40 BigDecimal (java.math.BigDecimal)38 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)37 BioModel (cbit.vcell.biomodel.BioModel)36 Simulation (cbit.vcell.solver.Simulation)33 XmlParseException (cbit.vcell.xml.XmlParseException)33 PropertyVetoException (java.beans.PropertyVetoException)33 Vector (java.util.Vector)33 Connection (java.sql.Connection)32 ArrayList (java.util.ArrayList)31 File (java.io.File)29 SimulationContext (cbit.vcell.mapping.SimulationContext)28 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)24