Search in sources :

Example 16 with SimulationJobStatusPersistent

use of cbit.vcell.server.SimulationJobStatusPersistent in project vcell by virtualcell.

the class SimulationDatabaseDirect method getSimpleJobStatus.

@Override
public SimpleJobStatus[] getSimpleJobStatus(User user, 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<SimpleJobStatusPersistent> simpleJobStatusPersistentList = databaseServerImpl.getSimpleJobStatus(simStatusQuerySpec);
    ArrayList<SimpleJobStatus> simpleJobStatusList = new ArrayList<SimpleJobStatus>();
    for (SimpleJobStatusPersistent simpleJobStatusPersistent : simpleJobStatusPersistentList) {
        SimulationJobStatusPersistent simJobStatusDb = simpleJobStatusPersistent.jobStatus;
        SimJobStatusKey key = new SimJobStatusKey(simpleJobStatusPersistent.simulationMetadata.vcSimID.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));
        }
        SimpleJobStatus bestSimpleJobStatus = translateToSimpleJobStatusTransient(simpleJobStatusPersistent, latestSimulationJobStatus, cachedStateInfo);
        // uses latest SimulationJobStatus and StateInfo.
        simpleJobStatusList.add(bestSimpleJobStatus);
    }
    return simpleJobStatusList.toArray(new SimpleJobStatus[simpleJobStatusList.size()]);
}
Also used : StateInfo(cbit.vcell.server.StateInfo) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) ArrayList(java.util.ArrayList) SimpleJobStatusPersistent(cbit.vcell.server.SimpleJobStatusPersistent) SimulationJobStatusPersistent(cbit.vcell.server.SimulationJobStatusPersistent) SimpleJobStatus(cbit.vcell.server.SimpleJobStatus)

Example 17 with SimulationJobStatusPersistent

use of cbit.vcell.server.SimulationJobStatusPersistent in project vcell by virtualcell.

the class SimulationJobDbDriver method getSimulationJobStatus.

/**
 * This method was created in VisualAge.
 * @return int
 * @param user java.lang.String
 * @param imageName java.lang.String
 */
public SimulationJobStatusPersistent[] getSimulationJobStatus(Connection con, KeyValue simKey) throws SQLException {
    // log.print("SchedulerDbDriver.getSimulationJobStatus(SimKey="+simKey+")");
    String sql = new String(standardJobStatusSQL);
    sql += " AND " + simTable.id.getQualifiedColName() + " = " + simKey;
    // log.print(sql);
    Statement stmt = con.createStatement();
    List<SimulationJobStatusPersistent> simJobStatuses = new java.util.ArrayList<SimulationJobStatusPersistent>();
    try {
        ResultSet rset = stmt.executeQuery(sql);
        while (rset.next()) {
            simJobStatuses.add(jobTable.getSimulationJobStatus(rset));
        }
    } finally {
        stmt.close();
    }
    return (SimulationJobStatusPersistent[]) simJobStatuses.toArray(new SimulationJobStatusPersistent[0]);
}
Also used : Statement(java.sql.Statement) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) SimulationJobStatusPersistent(cbit.vcell.server.SimulationJobStatusPersistent)

Example 18 with SimulationJobStatusPersistent

use of cbit.vcell.server.SimulationJobStatusPersistent in project vcell by virtualcell.

the class SimulationJobDbDriver method getSimpleJobStatus.

/**
 * Insert the method's description here.
 * Creation date: (9/3/2003 8:59:46 AM)
 * @return java.util.List of SimpleJobStatus for managementGUI
 * @param conditions java.lang.String
 *
 * for the subqueries, here is a prototype query which returns the
 *
 * select
 *vc_simulation_1.id as simid,
 *(select max('{"bmid":"' || lpad(vc_biomodel.id,14,0) || '","scid":"' || lpad(vc_simcontext.id,14,0) || '","bmbranch":"' || lpad(vc_biomodel.versionbranchid,14,0) || '","scbranch":"' || lpad(vc_simcontext.versionbranchid,14,0) || '","bmname":"' || vc_biomodel.name || '","scname":"' || vc_simcontext.name || '"}')
 *from vc_biomodel, vc_biomodelsimcontext, VC_BIOMODELSIM, vc_simcontext
 *where vc_simulation_1.mathref = vc_simcontext.mathref
 *and VC_BIOMODELSIMCONTEXT.SIMCONTEXTREF = VC_SIMCONTEXT.id
 *and VC_BIOMODELSIMCONTEXT.BIOMODELREF = vc_biomodel.id
 *and VC_BIOMODELSIM.SIMREF = VC_SIMULATION_1.id
 *and VC_BIOMODELSIM.BIOMODELREF = vc_biomodel.id
 *) as bmLink,
 *(select max('{"mmid":"' || lpad(vc_mathmodel.id,14,0) || '","mmbranch":"' || lpad(vc_mathmodel.versionbranchid,14,0) || '","mmname":"' || vc_mathmodel.name || '"}')
 *from vc_mathmodel, VC_MATHMODELSIM
 *where vc_simulation_1.id = vc_mathmodelsim.SIMREF
 *and vc_mathmodelsim.MATHMODELREF = vc_mathmodel.id
 *) as mmLink
 *from vc_simulation vc_simulation_1
 *where rownum <= 10;
 *
 *which returns the biomodel link (bmlink) and the math model link (mmlink) as JSON strings to be interpreted as needed.
 *
 *simid		bmlink																																								mmlink
 *2,006,065	<null>																																								{"mmid":"00000002001619","mmbranch":"00000001008286","mmname":"Terasaki1"}
 *2,006,075	<null>																																								{"mmid":"00000002001626","mmbranch":"00000001008286","mmname":"Terasaki1"}
 *2,006,085	<null>																																								{"mmid":"00000002001636","mmbranch":"00000001008286","mmname":"Terasaki1"}
 *2,637,970	{"bmid":"00000002669821","scid":"00000002637934","bmbranch":"00000002622407","scbranch":"00000002637935","bmname":"aggregation","scname":"diagonal gradient"}		<null>
 *2,006,427	<null>																																								{"mmid":"00000002002108","mmbranch":"00000001002871","mmname":"DiffusionfromChannel"}
 *2,006,437	<null>																																								{"mmid":"00000002002110","mmbranch":"00000001002871","mmname":"DiffusionfromChannel"}
 *2,006,646	<null>																																								{"mmid":"00000002002254","mmbranch":"00000001118506","mmname":"AliciaProblem1"}
 *10,067,537	{"bmid":"00000010067543","scid":"00000010067469","bmbranch":"00000010033822","scbranch":"00000010067470","bmname":"BMTest_biphasicStatModule1","scname":"figure5"}	<null>
 *10,369,972	{"bmid":"00000010369990","scid":"00000010369900","bmbranch":"00000010009521","scbranch":"00000010369901","bmname":"MemBinding_1","scname":"comp"}					<null>
 *2,007,278	<null>																																								{"mmid":"00000002001884","mmbranch":"00000001036088","mmname":"Wave_no_nucl5"}
 */
public List<SimpleJobStatusPersistent> getSimpleJobStatus(Connection con, String conditions, int startRow, int maxNumRows) throws java.sql.SQLException, DataAccessException {
    BioModelSimulationLinkTable bioSimLinkTable = BioModelSimulationLinkTable.table;
    MathModelSimulationLinkTable mathSimLinkTable = MathModelSimulationLinkTable.table;
    final String BMLINK = "bmlink";
    final String MMLINK = "mmlink";
    String subquery = "SELECT " + "current_timestamp as " + DatabaseConstants.SYSDATE_COLUMN_NAME + "," + jobTable.getTableName() + ".*," + userTable.userid.getQualifiedColName() + "," + userTable.id.getQualifiedColName() + " as ownerkey" + "," + "vc_sim_1." + simTable.ownerRef.getUnqualifiedColName() + "," + "vc_sim_1." + simTable.name.getUnqualifiedColName() + "," + "vc_sim_1." + simTable.taskDescription.getUnqualifiedColName() + "," + "vc_sim_1." + simTable.meshSpecX.getUnqualifiedColName() + "," + "vc_sim_1." + simTable.meshSpecY.getUnqualifiedColName() + "," + "vc_sim_1." + simTable.meshSpecZ.getUnqualifiedColName() + "," + "vc_sim_1." + simTable.mathOverridesLarge.getUnqualifiedColName() + " as " + simTable.mathOverridesLarge.getUnqualifiedColName() + "," + "vc_sim_1." + simTable.mathOverridesSmall.getUnqualifiedColName() + " as " + simTable.mathOverridesSmall.getUnqualifiedColName() + "," + "(SELECT max('{\"" + BioModelLink.bmid + "\":\"' || lpad(vc_biomodel.id,14,0)" + " || '\",\"" + BioModelLink.scid + "\":\"' || lpad(vc_simcontext.id,14,0)" + " || '\",\"" + BioModelLink.bmbranch + "\":\"' || lpad(vc_biomodel.versionbranchid,14,0)" + " || '\",\"" + BioModelLink.scbranch + "\":\"' || lpad(vc_simcontext.versionbranchid,14,0)" + " || '\",\"" + BioModelLink.bmname + "\":\"' || vc_biomodel.name" + " || '\",\"" + BioModelLink.scname + "\":\"' || vc_simcontext.name || '\"}')" + " FROM vc_biomodel" + ", vc_biomodelsimcontext" + ", VC_BIOMODELSIM" + ", vc_simcontext" + " WHERE vc_sim_1.mathref = vc_simcontext.mathref" + " AND VC_BIOMODELSIMCONTEXT.SIMCONTEXTREF = VC_SIMCONTEXT.id" + " AND VC_BIOMODELSIMCONTEXT.BIOMODELREF = vc_biomodel.id" + " AND VC_BIOMODELSIM.SIMREF = vc_sim_1.id" + " AND VC_BIOMODELSIM.BIOMODELREF = vc_biomodel.id" + ") as " + BMLINK + "," + "(SELECT max('{\"" + MathModelLink.mmid + "\":\"' || lpad(vc_mathmodel.id,14,0)" + " || '\",\"" + MathModelLink.mmbranch + "\":\"' || lpad(vc_mathmodel.versionbranchid,14,0)" + " || '\",\"" + MathModelLink.mmname + "\":\"' || vc_mathmodel.name || '\"}')" + " FROM vc_mathmodel" + ", vc_mathmodelsim" + " WHERE vc_sim_1.id = vc_mathmodelsim.SIMREF" + " AND vc_mathmodelsim.MATHMODELREF = vc_mathmodel.id" + ") as " + MMLINK + " FROM " + jobTable.getTableName() + "," + simTable.getTableName() + " vc_sim_1" + "," + userTable.getTableName() + "," + bioSimLinkTable.getTableName() + "," + mathSimLinkTable.getTableName() + " WHERE " + "vc_sim_1." + simTable.id.getUnqualifiedColName() + "=" + jobTable.simRef.getQualifiedColName() + " AND " + "vc_sim_1." + simTable.ownerRef.getUnqualifiedColName() + "=" + userTable.id.getQualifiedColName() + " AND " + bioSimLinkTable.simRef.getQualifiedColName() + " (+) " + "=" + "vc_sim_1." + simTable.id.getUnqualifiedColName() + " AND " + mathSimLinkTable.simRef.getQualifiedColName() + " (+) " + "=" + "vc_sim_1." + simTable.id.getUnqualifiedColName();
    String additionalConditionsClause = "";
    if (conditions != null && conditions.length() > 0) {
        additionalConditionsClause = " AND (" + conditions + ")";
    }
    // most recent records first
    String orderByClause = " order by " + jobTable.submitDate.getQualifiedColName() + " DESC ";
    String sql = null;
    if (maxNumRows > 0) {
        if (startRow <= 1) {
            // simpler query, only limit rows, not starting row
            sql = "select * from " + "(" + subquery + " " + additionalConditionsClause + " " + orderByClause + ") " + "where rownum <= " + maxNumRows;
        } else {
            // full query, limit start and limit
            sql = "select * from " + "(select a.*, ROWNUM rnum from " + "(" + subquery + " " + additionalConditionsClause + " " + orderByClause + ") a " + " where rownum <= " + (startRow + maxNumRows - 1) + ") " + "where rnum >= " + startRow;
        }
    } else {
        sql = subquery + " " + additionalConditionsClause + " " + orderByClause;
    }
    if (lg.isTraceEnabled()) {
        lg.trace(sql);
    }
    List<SimpleJobStatusPersistent> resultList = new ArrayList<SimpleJobStatusPersistent>();
    Statement stmt = con.createStatement();
    SimulationJobStatusPersistent simJobStatus = null;
    cbit.vcell.solver.SolverTaskDescription std = null;
    String username = null;
    try {
        ResultSet rset = stmt.executeQuery(sql.toString());
        while (rset.next()) {
            simJobStatus = jobTable.getSimulationJobStatus(rset);
            username = rset.getString(userTable.userid.getUnqualifiedColName());
            BigDecimal ownerKeyDecimal = rset.getBigDecimal("ownerkey");
            User owner = new User(username, new KeyValue(ownerKeyDecimal));
            std = null;
            try {
                String taskDesc = rset.getString(SimulationTable.table.taskDescription.getUnqualifiedColName());
                if (taskDesc != null) {
                    std = new cbit.vcell.solver.SolverTaskDescription(new org.vcell.util.CommentStringTokenizer(org.vcell.util.TokenMangler.getSQLRestoredString(taskDesc)));
                }
            } catch (DataAccessException ex) {
                ex.printStackTrace();
                lg.error("failed to parse SolverTaskDescription", ex);
            }
            Integer meshSizeX = rset.getInt(SimulationTable.table.meshSpecX.getUnqualifiedColName());
            if (rset.wasNull()) {
                meshSizeX = null;
            }
            Integer meshSizeY = rset.getInt(SimulationTable.table.meshSpecY.getUnqualifiedColName());
            if (rset.wasNull()) {
                meshSizeY = null;
            }
            Integer meshSizeZ = rset.getInt(SimulationTable.table.meshSpecZ.getUnqualifiedColName());
            if (rset.wasNull()) {
                meshSizeZ = null;
            }
            String simname = rset.getString(SimulationTable.table.name.getUnqualifiedColName());
            SimulationDocumentLink simulationDocumentLink = null;
            String latestBioModelLinkJSON = rset.getString(BMLINK);
            if (latestBioModelLinkJSON != null) {
                try {
                    Gson gson = new Gson();
                    BioModelLink bioModelLink = gson.fromJson(latestBioModelLinkJSON, BioModelLink.class);
                    bioModelLink.clearZeroPadding();
                    simulationDocumentLink = bioModelLink;
                } catch (Exception e) {
                    e.printStackTrace();
                    lg.error("failed to parse BioModelLink", e);
                }
            }
            String latestMathModelLinkJSON = rset.getString(MMLINK);
            if (latestMathModelLinkJSON != null) {
                Gson gson = new Gson();
                try {
                    MathModelLink mathModelLink = gson.fromJson(latestMathModelLinkJSON, MathModelLink.class);
                    mathModelLink.clearZeroPadding();
                    simulationDocumentLink = mathModelLink;
                } catch (Exception e) {
                    e.printStackTrace();
                    lg.error("failed to parse MathModelLink", e);
                }
            }
            CommentStringTokenizer mathOverridesTokens = SimulationTable.getMathOverridesTokenizer(rset, dbSyntax);
            List<MathOverrides.Element> mathOverrideElements = MathOverrides.parseOverrideElementsFromVCML(mathOverridesTokens);
            int scanCount = 1;
            for (MathOverrides.Element element : mathOverrideElements) {
                if (element.getSpec() != null) {
                    scanCount *= element.getSpec().getNumValues();
                }
            }
            SimulationMetadata simulationMetadata = new SimulationMetadata(simJobStatus.getVCSimulationIdentifier(), simname, owner, std, meshSizeX, meshSizeY, meshSizeZ, new Integer(scanCount));
            resultList.add(new SimpleJobStatusPersistent(simulationMetadata, simulationDocumentLink, simJobStatus));
        }
    } finally {
        stmt.close();
    }
    return resultList;
}
Also used : User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) SimulationJobStatusPersistent(cbit.vcell.server.SimulationJobStatusPersistent) SimulationMetadata(cbit.vcell.solver.SimulationMetadata) ResultSet(java.sql.ResultSet) DataAccessException(org.vcell.util.DataAccessException) BioModelSimulationLinkTable(cbit.vcell.modeldb.BioModelSimulationLinkTable) Statement(java.sql.Statement) SimpleJobStatusPersistent(cbit.vcell.server.SimpleJobStatusPersistent) MathModelSimulationLinkTable(cbit.vcell.modeldb.MathModelSimulationLinkTable) BigDecimal(java.math.BigDecimal) SQLException(java.sql.SQLException) DataAccessException(org.vcell.util.DataAccessException) MathOverrides(cbit.vcell.solver.MathOverrides) SimulationDocumentLink(cbit.vcell.server.SimulationDocumentLink) BioModelLink(cbit.vcell.server.BioModelLink) CommentStringTokenizer(org.vcell.util.CommentStringTokenizer) MathModelLink(cbit.vcell.server.MathModelLink)

Example 19 with SimulationJobStatusPersistent

use of cbit.vcell.server.SimulationJobStatusPersistent in project vcell by virtualcell.

the class SimulationJobDbDriver method getActiveJobs.

/**
 * This method was created in VisualAge.
 * @return int
 * @param user java.lang.String
 * @param imageName java.lang.String
 */
public SimulationJobStatusPersistent[] getActiveJobs(Connection con, VCellServerID serverID) throws SQLException {
    String sql = "SELECT current_timestamp as " + DatabaseConstants.SYSDATE_COLUMN_NAME + "," + jobTable.getTableName() + ".*," + simTable.ownerRef.getQualifiedColName() + "," + userTable.userid.getQualifiedColName() + " FROM " + jobTable.getTableName() + "," + simTable.getTableName() + "," + userTable.getTableName() + " WHERE " + simTable.ownerRef.getQualifiedColName() + "=" + userTable.id.getQualifiedColName() + " AND " + simTable.id.getQualifiedColName() + "=" + jobTable.simRef.getQualifiedColName();
    sql += " AND " + jobTable.schedulerStatus + " in (" + // in job queue
    SchedulerStatus.QUEUED.getDatabaseNumber() + "," + // worker just accepted it
    SchedulerStatus.DISPATCHED.getDatabaseNumber() + "," + // worker running it
    SchedulerStatus.RUNNING.getDatabaseNumber() + "," + // waiting
    SchedulerStatus.WAITING.getDatabaseNumber() + ")";
    // AND upper(serverID) = 'serverid1';
    if (serverID != null) {
        // all in uppercase
        sql += " AND upper(" + jobTable.serverID.getQualifiedColName() + ") = " + "'" + serverID.toString().toUpperCase() + "'";
    }
    // order by submit date
    sql += " order by " + jobTable.submitDate.getQualifiedColName();
    // log.print(sql);
    Statement stmt = con.createStatement();
    java.util.List<SimulationJobStatusPersistent> simJobStatusList = new java.util.ArrayList<SimulationJobStatusPersistent>();
    try {
        ResultSet rset = stmt.executeQuery(sql);
        while (rset.next()) {
            SimulationJobStatusPersistent simJobStatus = jobTable.getSimulationJobStatus(rset);
            simJobStatusList.add(simJobStatus);
        }
    } finally {
        stmt.close();
    }
    return (SimulationJobStatusPersistent[]) simJobStatusList.toArray(new SimulationJobStatusPersistent[0]);
}
Also used : Statement(java.sql.Statement) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) SimulationJobStatusPersistent(cbit.vcell.server.SimulationJobStatusPersistent)

Example 20 with SimulationJobStatusPersistent

use of cbit.vcell.server.SimulationJobStatusPersistent in project vcell by virtualcell.

the class SimulationJobDbDriver method getSimulationJobStatus.

/**
 * This method was created in VisualAge.
 * @return int
 * @param user java.lang.String
 * @param imageName java.lang.String
 */
public SimulationJobStatusPersistent getSimulationJobStatus(Connection con, KeyValue simKey, int jobIndex, int taskID, boolean lockRowForUpdate) throws SQLException {
    // log.print("SchedulerDbDriver.getSimulationJobStatus(SimKey="+simKey+")");
    String sql = new String(standardJobStatusSQL);
    sql += " AND " + simTable.id.getQualifiedColName() + " = " + simKey;
    sql += " AND " + jobTable.jobIndex.getQualifiedColName() + " = " + jobIndex;
    sql += " AND " + jobTable.taskID.getQualifiedColName() + " = " + taskID;
    if (lockRowForUpdate) {
        sql += " FOR UPDATE OF " + jobTable.getTableName() + ".id";
    }
    // log.print(sql);
    Statement stmt = con.createStatement();
    SimulationJobStatusPersistent simJobStatus = null;
    try {
        ResultSet rset = stmt.executeQuery(sql);
        if (rset.next()) {
            simJobStatus = jobTable.getSimulationJobStatus(rset);
        }
    } finally {
        stmt.close();
    }
    // log.print("retrieved simJobStatus = "+simJobStatus);
    return simJobStatus;
}
Also used : Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) SimulationJobStatusPersistent(cbit.vcell.server.SimulationJobStatusPersistent)

Aggregations

SimulationJobStatusPersistent (cbit.vcell.server.SimulationJobStatusPersistent)23 ResultSet (java.sql.ResultSet)8 Statement (java.sql.Statement)8 ArrayList (java.util.ArrayList)8 Connection (java.sql.Connection)5 SimulationStatusPersistent (cbit.vcell.server.SimulationStatusPersistent)4 SimulationExecutionStatusPersistent (cbit.vcell.server.SimulationExecutionStatusPersistent)3 SimulationQueueEntryStatusPersistent (cbit.vcell.server.SimulationQueueEntryStatusPersistent)3 SQLException (java.sql.SQLException)3 Date (java.util.Date)3 DataAccessException (org.vcell.util.DataAccessException)3 User (org.vcell.util.document.User)3 SimpleJobStatusPersistent (cbit.vcell.server.SimpleJobStatusPersistent)2 SimulationJobStatus (cbit.vcell.server.SimulationJobStatus)2 Simulation (cbit.vcell.solver.Simulation)2 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)2 SimulationMessagePersistent (cbit.vcell.solver.server.SimulationMessagePersistent)2 FileNotFoundException (java.io.FileNotFoundException)2 BigString (org.vcell.util.BigString)2 KeyValue (org.vcell.util.document.KeyValue)2