Search in sources :

Example 1 with VCMessagingService

use of cbit.vcell.message.VCMessagingService in project vcell by virtualcell.

the class TestBlobRpcMessages method main.

public static void main(String[] args) throws Exception {
    try {
        PropertyLoader.loadProperties();
        // System.getProperties().setProperty(PropertyLoader.jmsURL,"tcp://nrcamdev5.cam.uchc.edu:61616");
        VCMessagingService messagingService = new VCMessagingServiceActiveMQ();
        messagingService.setDelegate(new SimpleMessagingDelegate());
        // reading message and computing sum
        // create N comsumers
        MyRpcServer myRpcServer = new MyRpcServer();
        for (int i = 0; i < NUM_COMSUMERS; i++) {
            VCRpcMessageHandler rpcMessageHandler = new VCRpcMessageHandler(myRpcServer, VCellTestQueue.JimQueue);
            VCQueueConsumer rpcConsumer = new VCQueueConsumer(VCellTestQueue.JimQueue, rpcMessageHandler, null, "Queue[" + VCellTestQueue.JimQueue.getName() + "] ==== RPC Consumer Thread " + i, 1);
            messagingService.addMessageConsumer(rpcConsumer);
        }
        // creating one messageProducer session
        ArrayList<VCMessageSession> sessions = new ArrayList<VCMessageSession>();
        for (int i = 0; i < NUM_PRODUCERS; i++) {
            sessions.add(messagingService.createProducerSession());
        }
        for (int i = 0; i < NUM_MESSAGES; i++) {
            for (int s = 0; s < NUM_PRODUCERS; s++) {
                VCMessageSession session = sessions.get(s);
                try {
                    // 
                    // create simple RPC request for service "Testing_Service"
                    // 
                    User user = new User("schaff", new KeyValue("17"));
                    byte[] array1 = new byte[20000000];
                    byte[] array2 = new byte[20000000];
                    VCRpcRequest rpcRequest = new VCRpcRequest(user, RpcServiceType.TESTING_SERVICE, "concat", new Object[] { array1, array2 });
                    // 
                    // send request and block for response (or timeout).
                    // RPC invocations don't need commits.
                    // 
                    Object returnValue = session.sendRpcMessage(VCellTestQueue.JimQueue, rpcRequest, true, 20000, null, null, null);
                    // 
                    if (returnValue instanceof byte[]) {
                        System.out.println("concat(byte[" + array1.length + "], byte[" + array2.length + "]) ===> byte[" + (((byte[]) returnValue).length) + "]");
                    } else {
                        System.out.println("unexpected return value of " + returnValue);
                    }
                } catch (VCMessagingInvocationTargetException e) {
                    e.printStackTrace(System.out);
                    System.out.println("the rpc service threw an exception");
                    e.getTargetException().printStackTrace(System.out);
                }
            }
        }
        System.out.println("main program calling closeAll()");
        messagingService.close();
        System.out.println("main program exiting");
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
}
Also used : SimpleMessagingDelegate(cbit.vcell.message.SimpleMessagingDelegate) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) VCMessagingInvocationTargetException(cbit.vcell.message.VCMessagingInvocationTargetException) VCMessageSession(cbit.vcell.message.VCMessageSession) ArrayList(java.util.ArrayList) VCMessagingService(cbit.vcell.message.VCMessagingService) VCRpcRequest(cbit.vcell.message.VCRpcRequest) VCMessagingInvocationTargetException(cbit.vcell.message.VCMessagingInvocationTargetException) VCQueueConsumer(cbit.vcell.message.VCQueueConsumer) VCMessagingServiceActiveMQ(cbit.vcell.message.jms.activeMQ.VCMessagingServiceActiveMQ) VCRpcMessageHandler(cbit.vcell.message.VCRpcMessageHandler)

Example 2 with VCMessagingService

use of cbit.vcell.message.VCMessagingService 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 3 with VCMessagingService

use of cbit.vcell.message.VCMessagingService in project vcell by virtualcell.

the class DatabaseServer 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: " + DatabaseServer.class.getName() + " serviceOrdinal [logdir]");
        System.exit(1);
    }
    try {
        PropertyLoader.loadProperties();
        DatabasePolicySQL.lg.setLevel(Level.ALL);
        int serviceOrdinal = Integer.parseInt(args[0]);
        String logdir = null;
        if (args.length > 1) {
            logdir = args[1];
        }
        ServiceInstanceStatus serviceInstanceStatus = new ServiceInstanceStatus(VCellServerID.getSystemServerID(), ServiceType.DB, serviceOrdinal, ManageUtils.getHostName(), new Date(), true);
        VCMongoMessage.serviceStartup(ServiceName.database, new Integer(serviceOrdinal), args);
        // 
        // JMX registration
        // 
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        mbs.registerMBean(new VCellServiceMXBeanImpl(), new ObjectName(VCellServiceMXBean.jmxObjectName));
        ConnectionFactory conFactory = DatabaseService.getInstance().createConnectionFactory();
        KeyFactory keyFactory = conFactory.getKeyFactory();
        DatabaseServerImpl databaseServerImpl = new DatabaseServerImpl(conFactory, keyFactory);
        VCMessagingService vcMessagingService = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
        vcMessagingService.setDelegate(new ServerMessagingDelegate());
        DatabaseServer databaseServer = new DatabaseServer(serviceInstanceStatus, databaseServerImpl, vcMessagingService, false);
        databaseServer.init();
    } catch (Throwable e) {
        e.printStackTrace(System.out);
    }
}
Also used : ServerMessagingDelegate(cbit.vcell.message.server.ServerMessagingDelegate) VCMessagingService(cbit.vcell.message.VCMessagingService) Date(java.util.Date) ObjectName(javax.management.ObjectName) ConnectionFactory(org.vcell.db.ConnectionFactory) VCellServiceMXBeanImpl(cbit.vcell.message.server.jmx.VCellServiceMXBeanImpl) ServiceInstanceStatus(cbit.vcell.message.server.ServiceInstanceStatus) DatabaseServerImpl(cbit.vcell.modeldb.DatabaseServerImpl) KeyFactory(org.vcell.db.KeyFactory) MBeanServer(javax.management.MBeanServer)

Example 4 with VCMessagingService

use of cbit.vcell.message.VCMessagingService 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);
    }
}
Also used : Cachetable(cbit.vcell.simdata.Cachetable) DataServerImpl(cbit.vcell.simdata.DataServerImpl) ServerMessagingDelegate(cbit.vcell.message.server.ServerMessagingDelegate) VCMessagingService(cbit.vcell.message.VCMessagingService) Date(java.util.Date) ObjectName(javax.management.ObjectName) ServiceName(cbit.vcell.mongodb.VCMongoMessage.ServiceName) VCellServiceMXBeanImpl(cbit.vcell.message.server.jmx.VCellServiceMXBeanImpl) ServiceInstanceStatus(cbit.vcell.message.server.ServiceInstanceStatus) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) File(java.io.File) MBeanServer(javax.management.MBeanServer)

Example 5 with VCMessagingService

use of cbit.vcell.message.VCMessagingService in project vcell by virtualcell.

the class SolverPostprocessor method main.

public static void main(java.lang.String[] args) {
    if (args.length < NUM_STD_ARGS) {
        System.out.println("Usage: " + SolverPostprocessor.class.getName() + " simKey username userKey jobindex taskid solverExitCode [postProcessorCommandFile]");
        System.exit(1);
    }
    Logging.init();
    Log4jSessionLog log = new Log4jSessionLog(LOG_NAME);
    Logger lg = log.getLogger();
    VCMessagingService vcMessagingService = null;
    try {
        PropertyLoader.loadProperties(POST_PROCESSOR_PROPERTIES);
        ResourceUtil.setNativeLibraryDirectory();
        NativeLoader.setOsType(OsType.LINUX);
        KeyValue simKey = new KeyValue(args[0]);
        String userName = args[1];
        KeyValue userKey = new KeyValue(args[2]);
        int jobIndex = Integer.parseInt(args[3]);
        int taskID = Integer.parseInt(args[4]);
        int solverExitCode = Integer.parseInt(args[5]);
        User owner = new User(userName, userKey);
        VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simKey, owner);
        String hostName = ManageUtils.getHostName();
        VCMongoMessage.serviceStartup(ServiceName.solverPostprocessor, Integer.valueOf(simKey.toString()), args);
        // 
        // JMX registration
        // 
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        mbs.registerMBean(new VCellServiceMXBeanImpl(), new ObjectName(VCellServiceMXBean.jmxObjectName));
        vcMessagingService = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
        vcMessagingService.setDelegate(new ServerMessagingDelegate());
        VCMessageSession session = vcMessagingService.createProducerSession();
        WorkerEventMessage workerEventMessage;
        if (solverExitCode == 0) {
            Exception postProcessingException = null;
            if (args.length > NUM_STD_ARGS) {
                String fname = args[NUM_STD_ARGS];
                if (lg.isDebugEnabled()) {
                    lg.debug("processing " + fname);
                }
                postProcessingException = runPostprocessingCommands(fname, lg);
            }
            if (lg.isDebugEnabled()) {
                lg.debug("postProcessingException is " + postProcessingException);
            }
            if (postProcessingException == null) {
                lg.debug("sendWorkerExitNormal");
                workerEventMessage = WorkerEventMessage.sendWorkerExitNormal(session, SolverPostprocessor.class.getName(), hostName, vcSimID, jobIndex, taskID, solverExitCode);
            } else {
                lg.debug("sendWorkerExitError postprocessing");
                workerEventMessage = WorkerEventMessage.sendWorkerExitError(session, postProcessingException, hostName, vcSimID, jobIndex, taskID, SimulationMessage.WorkerExited(postProcessingException));
            }
        } else {
            // solverExitCode != 0
            lg.debug("sendWorkerExitError solverExitCode");
            workerEventMessage = WorkerEventMessage.sendWorkerExitError(session, SolverPostprocessor.class.getName(), hostName, vcSimID, jobIndex, taskID, solverExitCode);
        }
        lg.debug(workerEventMessage);
        VCMongoMessage.sendWorkerEvent(workerEventMessage);
    } catch (Throwable e) {
        log.exception(e);
    } finally {
        if (vcMessagingService != null) {
            try {
                vcMessagingService.close();
            } catch (VCMessagingException e) {
                e.printStackTrace();
            }
        }
        ApplicationTerminator.beginCountdown(TimeUnit.SECONDS, 10, 0);
        VCMongoMessage.shutdown();
        System.exit(0);
    }
}
Also used : ServerMessagingDelegate(cbit.vcell.message.server.ServerMessagingDelegate) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) Log4jSessionLog(org.vcell.util.logging.Log4jSessionLog) VCMessageSession(cbit.vcell.message.VCMessageSession) VCMessagingService(cbit.vcell.message.VCMessagingService) Logger(org.apache.log4j.Logger) VCMessagingException(cbit.vcell.message.VCMessagingException) ObjectName(javax.management.ObjectName) VCellServiceMXBeanImpl(cbit.vcell.message.server.jmx.VCellServiceMXBeanImpl) VCMessagingException(cbit.vcell.message.VCMessagingException) WorkerEventMessage(cbit.vcell.message.messages.WorkerEventMessage) MBeanServer(javax.management.MBeanServer)

Aggregations

VCMessagingService (cbit.vcell.message.VCMessagingService)10 ServerMessagingDelegate (cbit.vcell.message.server.ServerMessagingDelegate)6 VCMessageSession (cbit.vcell.message.VCMessageSession)5 VCMessagingException (cbit.vcell.message.VCMessagingException)5 User (org.vcell.util.document.User)4 SimpleMessagingDelegate (cbit.vcell.message.SimpleMessagingDelegate)3 VCQueueConsumer (cbit.vcell.message.VCQueueConsumer)3 VCRpcRequest (cbit.vcell.message.VCRpcRequest)3 ServiceInstanceStatus (cbit.vcell.message.server.ServiceInstanceStatus)3 VCellServiceMXBeanImpl (cbit.vcell.message.server.jmx.VCellServiceMXBeanImpl)3 DatabaseServerImpl (cbit.vcell.modeldb.DatabaseServerImpl)3 File (java.io.File)3 Date (java.util.Date)3 MBeanServer (javax.management.MBeanServer)3 ObjectName (javax.management.ObjectName)3 ConnectionFactory (org.vcell.db.ConnectionFactory)3 KeyFactory (org.vcell.db.KeyFactory)3 ExportServiceImpl (cbit.vcell.export.server.ExportServiceImpl)2 VCMessage (cbit.vcell.message.VCMessage)2 VCMessagingInvocationTargetException (cbit.vcell.message.VCMessagingInvocationTargetException)2