use of cbit.vcell.export.server.ExportServiceImpl in project vcell by virtualcell.
the class ClientSimManager method showSimulationResults0.
private AsynchClientTask[] showSimulationResults0(final boolean isLocal, final ViewerType viewerType) {
// Create the AsynchClientTasks
ArrayList<AsynchClientTask> taskList = new ArrayList<AsynchClientTask>();
taskList.add(new AsynchClientTaskFunction(h -> {
h.put(H_LOCAL_SIM, isLocal);
h.put(H_VIEWER_TYPE, viewerType);
}, "setLocal", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING));
final DocumentWindowManager documentWindowManager = getDocumentWindowManager();
AsynchClientTask retrieveResultsTask = new AsynchClientTask("Retrieving results", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@SuppressWarnings("unchecked")
public void run(Hashtable<String, Object> hashTable) throws Exception {
Simulation[] simsToShow = (Simulation[]) hashTable.get("simsArray");
for (int i = 0; i < simsToShow.length; i++) {
final Simulation sim = simsToShow[i];
final VCSimulationIdentifier vcSimulationIdentifier = sim.getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
final SimulationWindow simWindow = documentWindowManager.haveSimulationWindow(vcSimulationIdentifier);
OutputContext outputContext = (OutputContext) hashTable.get("outputContext");
if (simWindow == null && (viewerType == ViewerType.BothNativeAndPython || viewerType == ViewerType.NativeViewer_only)) {
try {
// make the manager and wire it up
DataViewerController dataViewerController = null;
if (!isLocal) {
dataViewerController = documentWindowManager.getRequestManager().getDataViewerController(outputContext, sim, 0);
// For changes in time or variable
documentWindowManager.addDataListener(dataViewerController);
} else {
// ---- preliminary : construct the localDatasetControllerProvider
File primaryDir = ResourceUtil.getLocalRootDir();
User usr = sim.getVersion().getOwner();
DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(null, primaryDir, null);
ExportServiceImpl localExportServiceImpl = new ExportServiceImpl();
LocalDataSetControllerProvider localDSCProvider = new LocalDataSetControllerProvider(usr, dataSetControllerImpl, localExportServiceImpl);
VCDataManager vcDataManager = new VCDataManager(localDSCProvider);
File localSimDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
LocalVCDataIdentifier vcDataId = new LocalVCSimulationDataIdentifier(vcSimulationIdentifier, 0, localSimDir);
DataManager dataManager = null;
if (sim.isSpatial()) {
dataManager = new PDEDataManager(outputContext, vcDataManager, vcDataId);
} else {
dataManager = new ODEDataManager(outputContext, vcDataManager, vcDataId);
}
dataViewerController = new SimResultsViewerController(dataManager, sim);
dataSetControllerImpl.addDataJobListener(documentWindowManager);
}
// make the viewer
Hashtable<VCSimulationIdentifier, DataViewerController> dataViewerControllers = (Hashtable<VCSimulationIdentifier, DataViewerController>) hashTable.get(H_DATA_VIEWER_CONTROLLERS);
if (dataViewerControllers == null) {
dataViewerControllers = new Hashtable<VCSimulationIdentifier, DataViewerController>();
hashTable.put(H_DATA_VIEWER_CONTROLLERS, dataViewerControllers);
}
dataViewerControllers.put(vcSimulationIdentifier, dataViewerController);
} catch (Throwable exc) {
exc.printStackTrace(System.out);
saveFailure(hashTable, sim, exc);
}
}
try {
if (viewerType == ViewerType.PythonViewer_only || viewerType == ViewerType.BothNativeAndPython) {
VtkManager vtkManager = null;
if (!isLocal) {
vtkManager = documentWindowManager.getRequestManager().getVtkManager(outputContext, new VCSimulationDataIdentifier(vcSimulationIdentifier, 0));
} else {
// ---- preliminary : construct the localDatasetControllerProvider
File primaryDir = ResourceUtil.getLocalRootDir();
User usr = sim.getVersion().getOwner();
DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(null, primaryDir, null);
ExportServiceImpl localExportServiceImpl = new ExportServiceImpl();
LocalDataSetControllerProvider localDSCProvider = new LocalDataSetControllerProvider(usr, dataSetControllerImpl, localExportServiceImpl);
VCDataManager vcDataManager = new VCDataManager(localDSCProvider);
File localSimDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
VCSimulationDataIdentifier simulationDataIdentifier = new LocalVCSimulationDataIdentifier(vcSimulationIdentifier, 0, localSimDir);
vtkManager = new VtkManager(outputContext, vcDataManager, simulationDataIdentifier);
}
//
// test ability to read data
//
VtuVarInfo[] vtuVarInfos = vtkManager.getVtuVarInfos();
double[] times = vtkManager.getDataSetTimes();
//
// create the SimulationDataSetRef
//
VCDocument modelDocument = null;
if (documentWindowManager instanceof BioModelWindowManager) {
modelDocument = ((BioModelWindowManager) documentWindowManager).getBioModel();
} else if (documentWindowManager instanceof MathModelWindowManager) {
modelDocument = ((MathModelWindowManager) documentWindowManager).getMathModel();
}
SimulationDataSetRef simulationDataSetRef = VCellClientDataServiceImpl.createSimulationDataSetRef(sim, modelDocument, 0, isLocal);
// Hashtable<VCSimulationIdentifier, SimulationDataSetRef> simDataSetRefs = (Hashtable<VCSimulationIdentifier, SimulationDataSetRef>)hashTable.get(H_SIM_DATASET_REFS);
// if (simDataSetRefs == null) {
// simDataSetRefs = new Hashtable<VCSimulationIdentifier, SimulationDataSetRef>();
// hashTable.put(H_SIM_DATASET_REFS, simDataSetRefs);
// }
// simDataSetRefs.put(vcSimulationIdentifier, simulationDataSetRef);
File visitExe = VCellConfiguration.getFileProperty(PropertyLoader.visitExe);
if (visitExe != null) {
VisitSupport.launchVisTool(visitExe, simulationDataSetRef);
}
}
} catch (Throwable exc) {
exc.printStackTrace(System.out);
saveFailure(hashTable, sim, exc);
}
}
}
};
taskList.add(retrieveResultsTask);
AsynchClientTask displayResultsTask = new AsynchClientTask("Showing results", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@SuppressWarnings("unchecked")
public void run(Hashtable<String, Object> hashTable) throws Exception {
boolean isLocal = fetch(hashTable, H_LOCAL_SIM, Boolean.class, true);
SimulationWindow.LocalState localState = isLocal ? LocalState.LOCAL : LocalState.SERVER;
Hashtable<Simulation, Throwable> failures = (Hashtable<Simulation, Throwable>) hashTable.get(H_FAILURES);
Simulation[] simsToShow = (Simulation[]) hashTable.get("simsArray");
for (int i = 0; i < simsToShow.length; i++) {
final Simulation sim = simsToShow[i];
if (failures != null && failures.containsKey(sim)) {
continue;
}
final VCSimulationIdentifier vcSimulationIdentifier = simsToShow[i].getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
final SimulationWindow simWindow = documentWindowManager.haveSimulationWindow(vcSimulationIdentifier);
if (simWindow != null) {
ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(documentWindowManager.getComponent());
ChildWindow childWindow = childWindowManager.getChildWindowFromContext(simWindow);
if (childWindow == null) {
childWindow = childWindowManager.addChildWindow(simWindow.getDataViewer(), simWindow);
childWindow.pack();
childWindow.setIsCenteredOnParent();
childWindow.show();
}
setFinalWindow(hashTable, childWindow);
simWindow.setLocalState(localState);
} else {
// wire it up the viewer
Hashtable<VCSimulationIdentifier, DataViewerController> dataViewerControllers = (Hashtable<VCSimulationIdentifier, DataViewerController>) hashTable.get(H_DATA_VIEWER_CONTROLLERS);
DataViewerController viewerController = dataViewerControllers.get(vcSimulationIdentifier);
Throwable ex = (failures == null ? null : failures.get(sim));
if (viewerController != null && ex == null) {
// no failure
DataViewer viewer = viewerController.createViewer();
getSimWorkspace().getSimulationOwner().getOutputFunctionContext().addPropertyChangeListener(viewerController);
documentWindowManager.addExportListener(viewer);
// For data related activities such as calculating statistics
documentWindowManager.addDataJobListener(viewer);
viewer.setSimulationModelInfo(new SimulationWorkspaceModelInfo(getSimWorkspace().getSimulationOwner(), sim.getName()));
viewer.setDataViewerManager(documentWindowManager);
SimulationWindow newWindow = new SimulationWindow(vcSimulationIdentifier, sim, getSimWorkspace().getSimulationOwner(), viewer);
BeanUtils.addCloseWindowKeyboardAction(newWindow.getDataViewer());
documentWindowManager.addResultsFrame(newWindow);
setFinalWindow(hashTable, viewer);
newWindow.setLocalState(localState);
}
}
}
StringBuffer failMessage = new StringBuffer();
if (failures != null) {
if (!failures.isEmpty()) {
failMessage.append("Error, " + failures.size() + " of " + simsToShow.length + " sim results failed to display:\n");
Enumeration<Simulation> en = failures.keys();
while (en.hasMoreElements()) {
Simulation sim = en.nextElement();
Throwable exc = (Throwable) failures.get(sim);
failMessage.append("'" + sim.getName() + "' - " + exc.getMessage());
}
}
}
if (failMessage.length() > 0) {
PopupGenerator.showErrorDialog(ClientSimManager.this.getDocumentWindowManager(), failMessage.toString());
}
}
};
if (viewerType == ViewerType.BothNativeAndPython || viewerType == ViewerType.NativeViewer_only) {
taskList.add(displayResultsTask);
}
// Dispatch the tasks using the ClientTaskDispatcher.
AsynchClientTask[] taskArray = new AsynchClientTask[taskList.size()];
taskList.toArray(taskArray);
return taskArray;
}
use of cbit.vcell.export.server.ExportServiceImpl in project vcell by virtualcell.
the class VirtualFrapWindowManager method startExport.
public void startExport(Component requester, OutputContext outContext, ExportSpecs exportSpecs) {
try {
ExportServiceImpl exportServiceImpl = new ExportServiceImpl();
DataServerImpl dataServerImpl = new DataServerImpl(localWorkSpace.getDataSetControllerImpl(), exportServiceImpl);
exportServiceImpl.addExportListener(new ExportListener() {
public void exportMessage(ExportEvent event) {
System.out.println(event.toString());
}
});
exportServiceImpl.makeRemoteFile(null, LocalWorkspace.getDefaultOwner(), dataServerImpl, exportSpecs);
} catch (DataAccessException e) {
e.printStackTrace(System.out);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of cbit.vcell.export.server.ExportServiceImpl in project vcell by virtualcell.
the class VCellClientDataServiceImpl method getVtkManager.
@Override
public VtkManager getVtkManager(SimulationDataSetRef simulationDataSetRef) throws FileNotFoundException, DataAccessException {
VCSimulationDataIdentifier vcSimulationDataIdentifier = getVCSimulationDataIdentifier(simulationDataSetRef);
VtkManager vtkManager = null;
if (!simulationDataSetRef.isLocal) {
vtkManager = vcellClient.getRequestManager().getVtkManager(null, vcSimulationDataIdentifier);
} else {
// ---- preliminary : construct the localDatasetControllerProvider
File primaryDir = ResourceUtil.getLocalRootDir();
User usr = User.tempUser;
DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(null, primaryDir, null);
ExportServiceImpl localExportServiceImpl = new ExportServiceImpl();
LocalDataSetControllerProvider localDSCProvider = new LocalDataSetControllerProvider(usr, dataSetControllerImpl, localExportServiceImpl);
VCDataManager vcDataManager = new VCDataManager(localDSCProvider);
vtkManager = new VtkManager(null, vcDataManager, vcSimulationDataIdentifier);
}
return vtkManager;
}
use of cbit.vcell.export.server.ExportServiceImpl in project vcell by virtualcell.
the class VCellServices method main.
/**
* Starts the application.
* @param args an array of command-line arguments
*/
public static void main(java.lang.String[] args) {
OperatingSystemInfo.getInstance();
if (args.length != 3 && args.length != 0) {
System.out.println("Missing arguments: " + VCellServices.class.getName() + " [sshHost sshUser sshKeyFile] ");
System.exit(1);
}
try {
PropertyLoader.loadProperties(REQUIRED_SERVICE_PROPERTIES);
ResourceUtil.setNativeLibraryDirectory();
new LibraryLoaderThread(false).start();
PythonSupport.verifyInstallation(new PythonPackage[] { PythonPackage.VTK, PythonPackage.THRIFT });
CommandService commandService = null;
if (args.length == 3) {
String sshHost = args[0];
String sshUser = args[1];
File sshKeyFile = new File(args[2]);
try {
commandService = new CommandServiceSshNative(sshHost, sshUser, sshKeyFile);
commandService.command(new String[] { "/usr/bin/env bash -c ls | head -5" });
lg.trace("SSH Connection test passed with installed keyfile, running ls as user " + sshUser + " on " + sshHost);
} catch (Exception e) {
e.printStackTrace();
try {
commandService = new CommandServiceSshNative(sshHost, sshUser, sshKeyFile, new File("/root"));
commandService.command(new String[] { "/usr/bin/env bash -c ls | head -5" });
lg.trace("SSH Connection test passed after installing keyfile, running ls as user " + sshUser + " on " + sshHost);
} catch (Exception e2) {
e.printStackTrace();
throw new RuntimeException("failed to establish an ssh command connection to " + sshHost + " as user '" + sshUser + "' using key '" + sshKeyFile + "'", e);
}
}
// can't make user directories, they are remote.
AbstractSolver.bMakeUserDirs = false;
} else {
commandService = new CommandServiceLocal();
}
BatchSystemType batchSystemType = BatchSystemType.SLURM;
HtcProxy htcProxy = null;
switch(batchSystemType) {
case SLURM:
{
htcProxy = new SlurmProxy(commandService, PropertyLoader.getRequiredProperty(PropertyLoader.htcUser));
break;
}
default:
{
throw new RuntimeException("unrecognized batch scheduling option :" + batchSystemType);
}
}
int serviceOrdinal = 0;
VCMongoMessage.serviceStartup(ServiceName.dispatch, new Integer(serviceOrdinal), args);
// //
// // JMX registration
// //
// MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
// mbs.registerMBean(new VCellServiceMXBeanImpl(), new ObjectName(VCellServiceMXBean.jmxObjectName));
ServiceInstanceStatus serviceInstanceStatus = new ServiceInstanceStatus(VCellServerID.getSystemServerID(), ServiceType.MASTER, serviceOrdinal, ManageUtils.getHostName(), new Date(), true);
ConnectionFactory conFactory = DatabaseService.getInstance().createConnectionFactory();
KeyFactory keyFactory = conFactory.getKeyFactory();
DatabaseServerImpl databaseServerImpl = new DatabaseServerImpl(conFactory, keyFactory);
AdminDBTopLevel adminDbTopLevel = new AdminDBTopLevel(conFactory);
SimulationDatabase simulationDatabase = new SimulationDatabaseDirect(adminDbTopLevel, databaseServerImpl, true);
Cachetable cacheTable = new Cachetable(MessageConstants.MINUTE_IN_MS * 20);
DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(cacheTable, new File(PropertyLoader.getRequiredProperty(PropertyLoader.primarySimDataDirInternalProperty)), new File(PropertyLoader.getProperty(PropertyLoader.secondarySimDataDirInternalProperty, PropertyLoader.getRequiredProperty(PropertyLoader.primarySimDataDirInternalProperty))));
ExportServiceImpl exportServiceImpl = new ExportServiceImpl();
// add dataJobListener
DataServerImpl dataServerImpl = new DataServerImpl(dataSetControllerImpl, exportServiceImpl);
VCMessagingService vcMessagingService = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
vcMessagingService.setDelegate(new ServerMessagingDelegate());
VCellServices vcellServices = new VCellServices(htcProxy, vcMessagingService, serviceInstanceStatus, databaseServerImpl, dataServerImpl, simulationDatabase);
dataSetControllerImpl.addDataJobListener(vcellServices);
exportServiceImpl.addExportListener(vcellServices);
vcellServices.init();
} catch (Throwable e) {
e.printStackTrace(System.out);
}
}
use of cbit.vcell.export.server.ExportServiceImpl in project vcell by virtualcell.
the class SimDataServer method main.
/**
* Starts the application.
* @param args an array of command-line arguments
*/
public static void main(java.lang.String[] args) {
if (args.length < 1) {
System.out.println("Missing arguments: " + SimDataServer.class.getName() + " serviceOrdinal [EXPORTONLY] [logdir]");
System.exit(1);
}
try {
PropertyLoader.loadProperties();
int serviceOrdinal = Integer.parseInt(args[0]);
String logdir = null;
boolean bExportOnly = false;
if (args.length > 1) {
if (args[1].equalsIgnoreCase("EXPORTONLY")) {
bExportOnly = true;
VCMongoMessage.serviceStartup(ServiceName.export, new Integer(serviceOrdinal), args);
if (args.length > 2) {
logdir = args[2];
}
} else {
VCMongoMessage.serviceStartup(ServiceName.simData, new Integer(serviceOrdinal), args);
logdir = args[1];
}
}
ServiceInstanceStatus serviceInstanceStatus = null;
ServiceName serviceName = null;
if (bExportOnly) {
serviceInstanceStatus = new ServiceInstanceStatus(VCellServerID.getSystemServerID(), ServiceType.DATAEXPORT, serviceOrdinal, ManageUtils.getHostName(), new Date(), true);
serviceName = ServiceName.export;
} else {
serviceInstanceStatus = new ServiceInstanceStatus(VCellServerID.getSystemServerID(), ServiceType.DATA, serviceOrdinal, ManageUtils.getHostName(), new Date(), true);
serviceName = ServiceName.simData;
}
VCMongoMessage.serviceStartup(serviceName, new Integer(serviceOrdinal), args);
//
// JMX registration
//
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
mbs.registerMBean(new VCellServiceMXBeanImpl(), new ObjectName(VCellServiceMXBean.jmxObjectName));
Cachetable cacheTable = new Cachetable(MessageConstants.MINUTE_IN_MS * 20);
DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(cacheTable, new File(PropertyLoader.getRequiredProperty(PropertyLoader.primarySimDataDirInternalProperty)), new File(PropertyLoader.getRequiredProperty(PropertyLoader.secondarySimDataDirInternalProperty)));
ExportServiceImpl exportServiceImpl = new ExportServiceImpl();
DataServerImpl dataServerImpl = new DataServerImpl(dataSetControllerImpl, exportServiceImpl);
VCMessagingService vcMessagingService = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
vcMessagingService.setDelegate(new ServerMessagingDelegate());
SimDataServer simDataServer = new SimDataServer(serviceInstanceStatus, dataServerImpl, vcMessagingService, false);
// add dataJobListener
dataSetControllerImpl.addDataJobListener(simDataServer);
// add export listener
exportServiceImpl.addExportListener(simDataServer);
simDataServer.init();
} catch (Throwable e) {
e.printStackTrace(System.out);
}
}
Aggregations