use of cbit.vcell.message.server.htc.HtcProxy 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.message.server.htc.HtcProxy in project vcell by virtualcell.
the class HtcSimulationWorker method initQueueConsumer.
private void initQueueConsumer() {
this.sharedMessageProducer = vcMessagingService.createProducerSession();
QueueListener queueListener = new QueueListener() {
@Override
public void onQueueMessage(VCMessage vcMessage, VCMessageSession session) throws RollbackException {
SimulationTask simTask = null;
try {
SimulationTaskMessage simTaskMessage = new SimulationTaskMessage(vcMessage);
simTask = simTaskMessage.getSimulationTask();
if (lg.isInfoEnabled()) {
lg.info("onQueueMessage() run simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName());
}
PostProcessingChores rd = choresFor(simTask);
HtcProxy clonedHtcProxy = htcProxy.cloneThreadsafe();
if (lg.isInfoEnabled()) {
lg.info("onQueueMessage() submit job: simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName());
}
HtcJobID pbsId = submit2PBS(simTask, clonedHtcProxy, rd);
if (lg.isInfoEnabled()) {
lg.info("onQueueMessage() sending 'accepted' message for job: simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName());
}
synchronized (sharedMessageProducer) {
WorkerEventMessage.sendAccepted(sharedMessageProducer, HtcSimulationWorker.class.getName(), simTask, ManageUtils.getHostName(), pbsId);
}
if (lg.isInfoEnabled()) {
lg.info("onQueueMessage() sent 'accepted' message for job: simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName());
}
} catch (Exception e) {
lg.error(e.getMessage(), e);
if (simTask != null) {
try {
lg.error("failed to process simTask request: " + e.getMessage() + " for simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName(), e);
synchronized (sharedMessageProducer) {
WorkerEventMessage.sendFailed(sharedMessageProducer, HtcSimulationWorker.class.getName(), simTask, ManageUtils.getHostName(), SimulationMessage.jobFailed(e.getMessage()));
}
lg.error("sent 'failed' message for simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName(), e);
} catch (VCMessagingException e1) {
lg.error(e1.getMessage(), e);
}
} else {
lg.error("failed to process simTask request: " + e.getMessage(), e);
}
}
}
};
int numHtcworkerThreads = Integer.parseInt(PropertyLoader.getProperty(PropertyLoader.htcworkerThreadsProperty, "5"));
this.pooledQueueConsumer = new VCPooledQueueConsumer(queueListener, numHtcworkerThreads, sharedMessageProducer);
this.pooledQueueConsumer.initThreadPool();
VCellQueue queue = VCellQueue.SimJobQueue;
VCMessageSelector selector = vcMessagingService.createSelector(getJobSelector());
String threadName = "SimJob Queue Consumer";
queueConsumer = new VCQueueConsumer(queue, pooledQueueConsumer, selector, threadName, MessageConstants.PREFETCH_LIMIT_SIM_JOB_HTC);
vcMessagingService.addMessageConsumer(queueConsumer);
}
use of cbit.vcell.message.server.htc.HtcProxy in project vcell by virtualcell.
the class HtcSimulationWorker method submit2PBS.
private HtcJobID submit2PBS(SimulationTask simTask, HtcProxy clonedHtcProxy, PostProcessingChores chores) throws XmlParseException, IOException, SolverException, ExecutableException {
HtcJobID jobid = null;
String htcLogDirExternalString = new File(PropertyLoader.getRequiredProperty(PropertyLoader.htcLogDirExternal)).getAbsolutePath();
if (!htcLogDirExternalString.endsWith("/")) {
htcLogDirExternalString = htcLogDirExternalString + "/";
}
String htcLogDirInternalString = new File(PropertyLoader.getRequiredProperty(PropertyLoader.htcLogDirInternal)).getAbsolutePath();
if (!htcLogDirInternalString.endsWith("/")) {
htcLogDirInternalString = htcLogDirInternalString + "/";
}
// "S_" + simTask.getSimKey() + "_" + simTask.getSimulationJob().getJobIndex()+ "_" + simTask.getTaskID();
String jobname = HtcProxy.createHtcSimJobName(new HtcProxy.SimTaskInfo(simTask.getSimKey(), simTask.getSimulationJob().getJobIndex(), simTask.getTaskID()));
String subFileExternal = htcLogDirExternalString + jobname + clonedHtcProxy.getSubmissionFileExtension();
String subFileInternal = htcLogDirInternalString + jobname + clonedHtcProxy.getSubmissionFileExtension();
File parallelDirInternal = new File(chores.runDirectoryInternal);
File parallelDirExternal = new File(chores.runDirectoryExternal);
File primaryUserDirInternal = new File(chores.finalDataDirectoryInternal);
File primaryUserDirExternal = new File(chores.finalDataDirectoryExternal);
Solver realSolver = (AbstractSolver) SolverFactory.createSolver(primaryUserDirInternal, parallelDirInternal, simTask, true);
realSolver.setUnixMode();
String simTaskXmlText = XmlHelper.simTaskToXML(simTask);
String simTaskFilePathInternal = ResourceUtil.forceUnixPath(new File(primaryUserDirInternal, simTask.getSimulationJobID() + "_" + simTask.getTaskID() + ".simtask.xml").toString());
String simTaskFilePathExternal = ResourceUtil.forceUnixPath(new File(primaryUserDirExternal, simTask.getSimulationJobID() + "_" + simTask.getTaskID() + ".simtask.xml").toString());
if (!primaryUserDirInternal.exists()) {
FileUtils.forceMkdir(primaryUserDirInternal);
//
// directory create from container (possibly) as root, make this user directory accessible from user "vcell"
//
primaryUserDirInternal.setWritable(true, false);
primaryUserDirInternal.setExecutable(true, false);
primaryUserDirInternal.setReadable(true, false);
}
XmlUtil.writeXMLStringToFile(simTaskXmlText, simTaskFilePathInternal, true);
final String SOLVER_EXIT_CODE_REPLACE_STRING = "SOLVER_EXIT_CODE_REPLACE_STRING";
KeyValue simKey = simTask.getSimKey();
User simOwner = simTask.getSimulation().getVersion().getOwner();
final int jobId = simTask.getSimulationJob().getJobIndex();
ExecutableCommand.Container commandContainer = new ExecutableCommand.Container();
// the post processor command itself is neither messaging nor parallel; it's independent of the previous solver call
ExecutableCommand postprocessorCmd = new ExecutableCommand(null, false, false, PropertyLoader.getRequiredProperty(PropertyLoader.simulationPostprocessor), simKey.toString(), simOwner.getName(), simOwner.getID().toString(), Integer.toString(jobId), Integer.toString(simTask.getTaskID()), SOLVER_EXIT_CODE_REPLACE_STRING, subFileExternal);
postprocessorCmd.setExitCodeToken(SOLVER_EXIT_CODE_REPLACE_STRING);
commandContainer.add(postprocessorCmd);
// CBN?
int ncpus = simTask.getSimulation().getSolverTaskDescription().getNumProcessors();
Collection<PortableCommand> postProcessingCommands = new ArrayList<PortableCommand>();
if (realSolver instanceof AbstractCompiledSolver) {
AbstractCompiledSolver compiledSolver = (AbstractCompiledSolver) realSolver;
List<String> args = new ArrayList<>(4);
args.add(PropertyLoader.getRequiredProperty(PropertyLoader.simulationPreprocessor));
args.add(simTaskFilePathExternal);
args.add(primaryUserDirExternal.getAbsolutePath());
if (chores.isParallel()) {
args.add(chores.runDirectoryExternal);
}
// compiled solver ...used to be only single executable, now we pass 2 commands to PBSUtils.submitJob that invokes SolverPreprocessor.main() and then the native executable
// the pre-processor command itself is neither messaging nor parallel; it's independent of the subsequent solver call
ExecutableCommand preprocessorCmd = new ExecutableCommand(null, false, false, args);
commandContainer.add(preprocessorCmd);
for (ExecutableCommand ec : compiledSolver.getCommands()) {
if (ec.isMessaging()) {
ec.addArgument("-tid");
ec.addArgument(simTask.getTaskID());
}
commandContainer.add(ec);
}
if (chores.isCopyNeeded()) {
String logName = chores.finalDataDirectoryInternal + '/' + SimulationData.createCanonicalSimLogFileName(simKey, jobId, false);
CopySimFiles csf = new CopySimFiles(simTask.getSimulationJobID(), chores.runDirectoryInternal, chores.finalDataDirectoryInternal, logName);
postProcessingCommands.add(csf);
}
if (chores.isVtkUser()) {
VtkMeshGenerator vmg = new VtkMeshGenerator(simOwner, simKey, jobId);
postProcessingCommands.add(vmg);
}
} else {
ExecutableCommand ec = new ExecutableCommand(null, false, false, PropertyLoader.getRequiredProperty(PropertyLoader.javaSimulationExecutable), simTaskFilePathExternal, ResourceUtil.forceUnixPath(parallelDirExternal.getAbsolutePath()));
commandContainer.add(ec);
}
jobid = clonedHtcProxy.submitJob(jobname, subFileInternal, subFileExternal, commandContainer, ncpus, simTask.getEstimatedMemorySizeMB(), postProcessingCommands);
if (jobid == null) {
throw new RuntimeException("Failed. (error message: submitting to job scheduler failed).");
}
return jobid;
}
Aggregations