Search in sources :

Example 1 with HtcProxy

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);
    }
}
Also used : Cachetable(cbit.vcell.simdata.Cachetable) DataServerImpl(cbit.vcell.simdata.DataServerImpl) ServerMessagingDelegate(cbit.vcell.message.server.ServerMessagingDelegate) HtcProxy(cbit.vcell.message.server.htc.HtcProxy) CommandService(cbit.vcell.message.server.cmd.CommandService) VCMessagingService(cbit.vcell.message.VCMessagingService) ConnectionFactory(org.vcell.db.ConnectionFactory) SimulationDatabaseDirect(cbit.vcell.message.server.dispatcher.SimulationDatabaseDirect) CommandServiceLocal(cbit.vcell.message.server.cmd.CommandServiceLocal) ServiceInstanceStatus(cbit.vcell.message.server.ServiceInstanceStatus) DatabaseServerImpl(cbit.vcell.modeldb.DatabaseServerImpl) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) KeyFactory(org.vcell.db.KeyFactory) AdminDBTopLevel(cbit.vcell.modeldb.AdminDBTopLevel) SimulationDatabase(cbit.vcell.message.server.dispatcher.SimulationDatabase) LibraryLoaderThread(cbit.vcell.resource.LibraryLoaderThread) SlurmProxy(cbit.vcell.message.server.htc.slurm.SlurmProxy) VCMessagingException(cbit.vcell.message.VCMessagingException) Date(java.util.Date) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) BatchSystemType(cbit.vcell.server.HtcJobID.BatchSystemType) File(java.io.File) CommandServiceSshNative(cbit.vcell.message.server.cmd.CommandServiceSshNative)

Example 2 with HtcProxy

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);
}
Also used : QueueListener(cbit.vcell.message.VCQueueConsumer.QueueListener) SimulationTask(cbit.vcell.messaging.server.SimulationTask) HtcProxy(cbit.vcell.message.server.htc.HtcProxy) VCMessageSelector(cbit.vcell.message.VCMessageSelector) VCMessageSession(cbit.vcell.message.VCMessageSession) VCPooledQueueConsumer(cbit.vcell.message.VCPooledQueueConsumer) VCMessagingException(cbit.vcell.message.VCMessagingException) FileNotFoundException(java.io.FileNotFoundException) ConfigurationException(org.vcell.util.ConfigurationException) ExecutableException(org.vcell.util.exe.ExecutableException) RollbackException(cbit.vcell.message.RollbackException) XmlParseException(cbit.vcell.xml.XmlParseException) SolverException(cbit.vcell.solver.SolverException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) UnknownHostException(java.net.UnknownHostException) VCQueueConsumer(cbit.vcell.message.VCQueueConsumer) VCMessage(cbit.vcell.message.VCMessage) VCMessagingException(cbit.vcell.message.VCMessagingException) HtcJobID(cbit.vcell.server.HtcJobID) VCellQueue(cbit.vcell.message.VCellQueue) SimulationTaskMessage(cbit.vcell.message.messages.SimulationTaskMessage)

Example 3 with HtcProxy

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;
}
Also used : Solver(cbit.vcell.solver.server.Solver) AbstractSolver(cbit.vcell.solvers.AbstractSolver) AbstractCompiledSolver(cbit.vcell.solvers.AbstractCompiledSolver) HtcProxy(cbit.vcell.message.server.htc.HtcProxy) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) VtkMeshGenerator(cbit.vcell.simdata.VtkMeshGenerator) ArrayList(java.util.ArrayList) AbstractCompiledSolver(cbit.vcell.solvers.AbstractCompiledSolver) AbstractSolver(cbit.vcell.solvers.AbstractSolver) ExecutableCommand(cbit.vcell.solvers.ExecutableCommand) HtcJobID(cbit.vcell.server.HtcJobID) PortableCommand(cbit.vcell.simdata.PortableCommand) File(java.io.File)

Aggregations

HtcProxy (cbit.vcell.message.server.htc.HtcProxy)3 VCMessagingException (cbit.vcell.message.VCMessagingException)2 HtcJobID (cbit.vcell.server.HtcJobID)2 File (java.io.File)2 ExportServiceImpl (cbit.vcell.export.server.ExportServiceImpl)1 RollbackException (cbit.vcell.message.RollbackException)1 VCMessage (cbit.vcell.message.VCMessage)1 VCMessageSelector (cbit.vcell.message.VCMessageSelector)1 VCMessageSession (cbit.vcell.message.VCMessageSession)1 VCMessagingService (cbit.vcell.message.VCMessagingService)1 VCPooledQueueConsumer (cbit.vcell.message.VCPooledQueueConsumer)1 VCQueueConsumer (cbit.vcell.message.VCQueueConsumer)1 QueueListener (cbit.vcell.message.VCQueueConsumer.QueueListener)1 VCellQueue (cbit.vcell.message.VCellQueue)1 SimulationTaskMessage (cbit.vcell.message.messages.SimulationTaskMessage)1 ServerMessagingDelegate (cbit.vcell.message.server.ServerMessagingDelegate)1 ServiceInstanceStatus (cbit.vcell.message.server.ServiceInstanceStatus)1 CommandService (cbit.vcell.message.server.cmd.CommandService)1 CommandServiceLocal (cbit.vcell.message.server.cmd.CommandServiceLocal)1 CommandServiceSshNative (cbit.vcell.message.server.cmd.CommandServiceSshNative)1