use of org.vcell.util.document.User in project vcell by virtualcell.
the class StochtestRunService method runOne.
public void runOne() throws IllegalArgumentException, SQLException, DataAccessException, XmlParseException, PropertyVetoException, ExpressionException, MappingException, GeometryException, ImageException, IOException {
StochtestRun stochtestRun = StochtestDbUtils.acceptNextWaitingStochtestRun(conFactory);
String biomodelXML = null;
if (stochtestRun != null) {
String networkGenProbs = null;
try {
User user = new User(PropertyLoader.ADMINISTRATOR_ACCOUNT, new KeyValue(PropertyLoader.ADMINISTRATOR_ID));
ServerDocumentManager serverDocumentManager = new ServerDocumentManager(this.dbServerImpl);
biomodelXML = serverDocumentManager.getBioModelXML(new QueryHashtable(), user, stochtestRun.stochtest.biomodelRef, true);
BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(biomodelXML));
bioModel.refreshDependencies();
SimulationContext srcSimContext = null;
for (SimulationContext sc : bioModel.getSimulationContexts()) {
if (sc.getKey().equals(stochtestRun.stochtest.simContextRef)) {
srcSimContext = sc;
}
}
if (srcSimContext == null) {
throw new RuntimeException("cannot find simcontext with key=" + stochtestRun.stochtest.simContextRef);
}
//
for (SpeciesContextSpec scs : srcSimContext.getReactionContext().getSpeciesContextSpecs()) {
scs.setConstant(false);
}
SimulationContext simContext = srcSimContext;
StochtestMathType parentMathType = stochtestRun.parentMathType;
StochtestMathType mathType = stochtestRun.mathType;
if (parentMathType != mathType) {
if (parentMathType == StochtestMathType.nonspatialstochastic && mathType == StochtestMathType.rules) {
simContext = SimulationContext.copySimulationContext(srcSimContext, "generatedRules", false, Application.RULE_BASED_STOCHASTIC);
} else if (parentMathType == StochtestMathType.rules && mathType == StochtestMathType.nonspatialstochastic) {
simContext = SimulationContext.copySimulationContext(srcSimContext, "generatedSSA", false, Application.NETWORK_STOCHASTIC);
} else {
throw new RuntimeException("unexpected copy of simcontext from " + parentMathType + " to " + mathType);
}
bioModel.addSimulationContext(simContext);
}
MathMappingCallback mathMappingCallback = new MathMappingCallback() {
@Override
public void setProgressFraction(float fractionDone) {
}
@Override
public void setMessage(String message) {
}
@Override
public boolean isInterrupted() {
return false;
}
};
MathMapping mathMapping = simContext.createNewMathMapping(mathMappingCallback, NetworkGenerationRequirements.ComputeFullStandardTimeout);
MathDescription mathDesc = mathMapping.getMathDescription(mathMappingCallback);
simContext.setMathDescription(mathDesc);
if (simContext.isInsufficientIterations()) {
networkGenProbs = "insufficientIterations";
} else if (simContext.isInsufficientMaxMolecules()) {
networkGenProbs = "insufficientMaxMolecules";
}
File baseDirectory = StochtestFileUtils.createDirFile(baseDir, stochtestRun);
try {
OutputTimeSpec outputTimeSpec = new UniformOutputTimeSpec(0.5);
double endTime = 10.0;
computeTrials(simContext, stochtestRun, baseDirectory, outputTimeSpec, endTime, numTrials);
StochtestDbUtils.finalizeAcceptedStochtestRun(conFactory, stochtestRun, StochtestRun.StochtestRunStatus.complete, null, networkGenProbs);
} finally {
StochtestFileUtils.clearDir(baseDirectory);
}
} catch (Exception e) {
StochtestDbUtils.finalizeAcceptedStochtestRun(conFactory, stochtestRun, StochtestRun.StochtestRunStatus.failed, e.getMessage(), networkGenProbs);
//
if (biomodelXML != null) {
XmlUtil.writeXMLStringToFile(biomodelXML, new File(baseDir, "stochtestrun_" + stochtestRun.stochtest.key + ".vcml").getPath(), false);
}
//
// write exception trace to .txt file
//
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
e.printStackTrace(printWriter);
printWriter.flush();
System.out.println(stringWriter.getBuffer().toString());
XmlUtil.writeXMLStringToFile(stringWriter.getBuffer().toString(), new File(baseDir, "stochtestrun_" + stochtestRun.stochtest.key + "_error.txt").getPath(), false);
}
} else {
System.out.println("no jobs waiting");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
use of org.vcell.util.document.User in project vcell by virtualcell.
the class TestMissingSimData method createArrayList.
private static HashMap<String, ArrayList<SimIDAndJobID>> createArrayList(ResultSet rset) throws Exception {
int lastTaskid = -1;
long lastSimID = -1;
HashMap<String, ArrayList<SimIDAndJobID>> mapUserToSimJobs = new HashMap<String, ArrayList<SimIDAndJobID>>();
while (rset.next()) {
int jobID = rset.getInt(2);
if (rset.wasNull()) {
jobID = 0;
}
int dimension = rset.getInt(7);
User user = new User(rset.getString(4), new KeyValue(rset.getBigDecimal(3)));
// ;
ArrayList<SimIDAndJobID> simIDAndJobIDs = mapUserToSimJobs.get(user.getName());
if (simIDAndJobIDs == null) {
simIDAndJobIDs = new ArrayList<SimIDAndJobID>();
mapUserToSimJobs.put(user.getName(), simIDAndJobIDs);
}
String modelName = rset.getString("modelName");
String appName = rset.getString("appname");
String simName = rset.getString("simName");
int schedulerStatus = rset.getInt("schedulerStatus");
int taskid = rset.getInt("taskid");
BigDecimal simID = rset.getBigDecimal(1);
if (lastSimID != simID.longValue()) {
lastTaskid = -1;
}
String hasData = rset.getString("hasdata");
Boolean bHasData = (hasData == null ? null : hasData.toLowerCase().equals("y"));
BigDecimal privacy = rset.getBigDecimal("privacy");
String softwareVersion = rset.getString("softwareversion");
Timestamp timestamp = rset.getTimestamp("versiondate");
SimIDAndJobID simIDAndJobID = new SimIDAndJobID(new KeyValue(simID), jobID, user, dimension, modelName, appName, simName, SimulationJobStatus.SchedulerStatus.values()[schedulerStatus], bHasData, privacy, softwareVersion, timestamp);
if (lastTaskid == taskid) {
simIDAndJobIDs.remove(simIDAndJobIDs.size() - 1);
}
lastTaskid = taskid;
simIDAndJobIDs.add(simIDAndJobID);
}
return mapUserToSimJobs;
}
use of org.vcell.util.document.User in project vcell by virtualcell.
the class ServerManageConsole method resubmitSimulation.
/**
* Insert the method's description here.
* Creation date: (7/19/2004 3:32:52 PM)
* @param simKey cbit.sql.KeyValue
*/
public void resubmitSimulation(String userid, KeyValue simKey) {
try {
User user = adminDbTop.getUser(userid, true);
UserLoginInfo userLoginInfo = new UserLoginInfo(user.getName(), null);
userLoginInfo.setUser(user);
String apihost = "vcellapi.cam.uchc.edu";
Integer apiport = 8080;
RemoteProxyVCellConnectionFactory remoteProxyVCellConnectionFactory = new RemoteProxyVCellConnectionFactory(apihost, apiport, userLoginInfo);
VCellConnection vcConn = remoteProxyVCellConnectionFactory.createVCellConnection();
BigString simxml = vcConn.getUserMetaDbServer().getSimulationXML(simKey);
if (simxml == null) {
javax.swing.JOptionPane.showMessageDialog(this, "Simulation [" + simKey + "] doesn't exit, might have been deleted.", "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
return;
}
Simulation sim = XmlHelper.XMLToSim(simxml.toString());
if (sim == null) {
javax.swing.JOptionPane.showMessageDialog(this, "Simulation [" + simKey + "] doesn't exit, might have been deleted.", "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
return;
}
vcConn.getSimulationController().startSimulation(sim.getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), sim.getScanCount());
} catch (Exception ex) {
javax.swing.JOptionPane.showMessageDialog(this, "Resubmitting simulation failed:" + ex.getMessage(), "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
}
}
use of org.vcell.util.document.User in project vcell by virtualcell.
the class MathModelDbTreeModel method databaseInsert.
/**
* @param event cbit.vcell.clientdb.DatabaseEvent
*/
public void databaseInsert(DatabaseEvent databaseEvent) {
if (databaseEvent.getNewVersionInfo() instanceof MathModelInfo) {
try {
MathModelInfo insertedMathModelInfo = (MathModelInfo) databaseEvent.getNewVersionInfo();
//
// get parent of updated version
//
// model1 (VCDocumentInfoNode)
// Fri Sept 2, 2001 12:00:00 (MathModelInfo)
// Fri Sept 1, 2001 10:00:00 (MathModelInfo)
//
//
BioModelNode newVersionNode = createVersionSubTree(insertedMathModelInfo);
//
// find owner node (if it is displayed)
//
User owner = insertedMathModelInfo.getVersion().getOwner();
BioModelNode ownerRoot = ((BioModelNode) getRoot()).findNodeByUserObject(owner);
BioModelNode parentNode = null;
if (ownerRoot != null) {
parentNode = ownerRoot.findNodeByUserObject(new VCDocumentInfoNode(insertedMathModelInfo));
}
if (parentNode == null) {
//
// fresh insert
// Have to create parent node, for all versions of this mathModel,
// and stick it in the correct order in the tree.
//
parentNode = new BioModelNode(new VCDocumentInfoNode(insertedMathModelInfo), true);
parentNode.insert(newVersionNode, 0);
//
if (ownerRoot != null) {
// !!!!!!!!!!!!!! new insert on top (index=0) .... should do insertion sort !!!!
ownerRoot.insert(parentNode, 0);
insertNodeInto(parentNode, ownerRoot, 0);
}
} else {
//
// already versions there (just add child in the correct position within parent)
//
// !!!!!!!!!! right now ignore order !!!!!!!!!!
parentNode.insert(newVersionNode, 0);
insertNodeInto(newVersionNode, parentNode, 0);
}
} catch (DataAccessException e) {
e.printStackTrace(System.out);
System.out.println("exception responding to databaseInsert(), refreshing whole tree");
refreshTree();
}
}
}
use of org.vcell.util.document.User in project vcell by virtualcell.
the class MathModelDbTreeModel method createBaseTree.
/**
* Insert the method's description here.
* Creation date: (11/28/00 1:06:51 PM)
* @return cbit.vcell.desktop.BioModelNode
* @param docManager cbit.vcell.clientdb.DocumentManager
*/
protected void createBaseTree() throws DataAccessException {
VCDocumentDbTreeModel.initBaseTree(rootNode, new BioModelNode[] { myModelsNode, sharedModelsNode, publicModelsNode, educationModelsNode }, "Math Models", sharedModelsNode, SHARED_MATH_MODELS);
MathModelInfo[] mathModelInfos = getDocumentManager().getMathModelInfos();
User loginUser = getDocumentManager().getUser();
TreeMap<String, BioModelNode> treeMap = null;
try {
treeMap = VCDocumentDbTreeModel.initOwners(mathModelInfos, loginUser, this, this.getClass().getMethod("createOwnerSubTree", new Class[] { User.class, MathModelInfo[].class }));
} catch (Exception e) {
e.printStackTrace();
treeMap = new TreeMap<String, BioModelNode>();
treeMap.put(loginUser.getName(), new BioModelNode("Error:" + e.getMessage()));
}
initFinalTree(this, treeMap, loginUser);
}
Aggregations