Search in sources :

Example 6 with VCMessageSession

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

use of cbit.vcell.message.VCMessageSession 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)

Example 8 with VCMessageSession

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

the class JavaSimulationExecutable method init.

protected void init() throws JMSException {
    // 
    // session used for sending worker events.
    // 
    this.workerEventSession = vcMessagingService.createProducerSession();
    // 
    // message consumer for Service Control topic message (to stop simulation).
    // 
    VCellTopic topic = VCellTopic.ServiceControlTopic;
    TopicListener listener = new TopicListener() {

        public void onTopicMessage(VCMessage vcMessage, VCMessageSession session) {
            if (lg.isTraceEnabled())
                lg.trace("JavaSimulationExecutable::onControlTopicMessage(): " + vcMessage.show());
            try {
                String msgType = vcMessage.getStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY);
                if (msgType != null && msgType.equals(MessageConstants.MESSAGE_TYPE_STOPSIMULATION_VALUE)) {
                    Long longkey = vcMessage.getLongProperty(MessageConstants.SIMKEY_PROPERTY);
                    KeyValue simKey = new KeyValue(longkey + "");
                    int jobIndex = vcMessage.getIntProperty(MessageConstants.JOBINDEX_PROPERTY);
                    if (simKey.equals(simulationTask.getSimKey()) && jobIndex == simulationTask.getSimulationJob().getJobIndex()) {
                        solver.stopSolver();
                    }
                }
            } catch (MessagePropertyNotFoundException ex) {
                lg.error(ex.getMessage(), ex);
                return;
            }
        }
    };
    VCMessageSelector selector = null;
    String threadName = "Service Control Topic Consumer";
    VCTopicConsumer serviceControlConsumer = new VCTopicConsumer(topic, listener, selector, threadName, MessageConstants.PREFETCH_LIMIT_SERVICE_CONTROL);
    vcMessagingService.addMessageConsumer(serviceControlConsumer);
}
Also used : TopicListener(cbit.vcell.message.VCTopicConsumer.TopicListener) KeyValue(org.vcell.util.document.KeyValue) MessagePropertyNotFoundException(cbit.vcell.message.MessagePropertyNotFoundException) VCMessageSelector(cbit.vcell.message.VCMessageSelector) VCMessage(cbit.vcell.message.VCMessage) VCTopicConsumer(cbit.vcell.message.VCTopicConsumer) VCMessageSession(cbit.vcell.message.VCMessageSession) VCellTopic(cbit.vcell.message.VCellTopic)

Example 9 with VCMessageSession

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

the class RestDatabaseService method getDataSetTimeSeries.

public DataSetTimeSeries getDataSetTimeSeries(SimDataValuesServerResource resource, User vcellUser) throws DataAccessException, ObjectNotFoundException, SQLException {
    if (vcellUser == null) {
        vcellUser = VCellApiApplication.DUMMY_USER;
    }
    UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName(), null);
    // resource.getRequestAttributes().get(VCellApiApplication.SIMDATAID);
    String simId = resource.getAttribute(VCellApiApplication.SIMDATAID);
    // resource.getRequestAttributes().get(VCellApiApplication.SIMDATAID);
    String jobIndexString = resource.getAttribute(VCellApiApplication.JOBINDEX);
    KeyValue simKey = new KeyValue(simId);
    SimulationRep simRep = getSimulationRep(simKey);
    if (simRep == null) {
        throw new ObjectNotFoundException("Simulation with key " + simKey + " not found");
    }
    int jobIndex = Integer.parseInt(jobIndexString);
    // TODO: pass in variables names from the query parameters.
    String[] variableNames = null;
    User owner = simRep.getOwner();
    VCMessageSession rpcSession = vcMessagingService.createProducerSession();
    try {
        RpcDataServerProxy rpcDataServerProxy = new RpcDataServerProxy(userLoginInfo, rpcSession);
        VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simKey, owner);
        VCDataIdentifier vcdID = new VCSimulationDataIdentifier(vcSimID, jobIndex);
        DataSetTimeSeries dataSetTimeSeries = rpcDataServerProxy.getDataSetTimeSeries(vcdID, variableNames);
        return dataSetTimeSeries;
    } finally {
        rpcSession.close();
    }
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) VCMessageSession(cbit.vcell.message.VCMessageSession) BigString(org.vcell.util.BigString) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) RpcDataServerProxy(org.vcell.rest.rpc.RpcDataServerProxy) DataSetTimeSeries(cbit.vcell.simdata.DataSetTimeSeries) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) UserLoginInfo(org.vcell.util.document.UserLoginInfo) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) SimulationRep(cbit.vcell.modeldb.SimulationRep)

Example 10 with VCMessageSession

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

the class RestDatabaseService method startSimulation.

public SimulationRep startSimulation(BiomodelSimulationStartServerResource resource, User vcellUser) throws PermissionException, ObjectNotFoundException, DataAccessException, SQLException {
    // resource.getRequestAttributes().get(VCellApiApplication.SIMDATAID);
    String simId = resource.getAttribute(VCellApiApplication.SIMULATIONID);
    KeyValue simKey = new KeyValue(simId);
    SimulationRep simRep = getSimulationRep(simKey);
    if (simRep == null) {
        throw new ObjectNotFoundException("Simulation with key " + simKey + " not found");
    }
    User owner = simRep.getOwner();
    if (!owner.compareEqual(vcellUser)) {
        throw new PermissionException("not authorized to start simulation");
    }
    VCMessageSession rpcSession = vcMessagingService.createProducerSession();
    try {
        UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName(), null);
        try {
            userLoginInfo.setUser(vcellUser);
        } catch (Exception e) {
            e.printStackTrace();
            throw new DataAccessException(e.getMessage());
        }
        RpcSimServerProxy rpcSimServerProxy = new RpcSimServerProxy(userLoginInfo, rpcSession);
        VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simKey, owner);
        rpcSimServerProxy.startSimulation(vcellUser, vcSimID, simRep.getScanCount());
        return simRep;
    } finally {
        rpcSession.close();
    }
}
Also used : PermissionException(org.vcell.util.PermissionException) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) RpcSimServerProxy(org.vcell.rest.rpc.RpcSimServerProxy) VCMessageSession(cbit.vcell.message.VCMessageSession) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) BigString(org.vcell.util.BigString) UserLoginInfo(org.vcell.util.document.UserLoginInfo) SimulationRep(cbit.vcell.modeldb.SimulationRep) PropertyVetoException(java.beans.PropertyVetoException) MatrixException(cbit.vcell.matrix.MatrixException) ModelException(cbit.vcell.model.ModelException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) UseridIDExistsException(org.vcell.util.UseridIDExistsException) MappingException(cbit.vcell.mapping.MappingException) MathException(cbit.vcell.math.MathException) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

VCMessageSession (cbit.vcell.message.VCMessageSession)18 KeyValue (org.vcell.util.document.KeyValue)9 VCMessage (cbit.vcell.message.VCMessage)8 VCMessagingException (cbit.vcell.message.VCMessagingException)7 User (org.vcell.util.document.User)7 VCQueueConsumer (cbit.vcell.message.VCQueueConsumer)6 BigString (org.vcell.util.BigString)6 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)6 UserLoginInfo (org.vcell.util.document.UserLoginInfo)6 VCMessagingService (cbit.vcell.message.VCMessagingService)5 SimulationRep (cbit.vcell.modeldb.SimulationRep)5 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)5 XmlParseException (cbit.vcell.xml.XmlParseException)5 DataAccessException (org.vcell.util.DataAccessException)5 MappingException (cbit.vcell.mapping.MappingException)4 MathException (cbit.vcell.math.MathException)4 MatrixException (cbit.vcell.matrix.MatrixException)4 VCMessageSelector (cbit.vcell.message.VCMessageSelector)4 QueueListener (cbit.vcell.message.VCQueueConsumer.QueueListener)4 ModelException (cbit.vcell.model.ModelException)4