Search in sources :

Example 1 with ServiceName

use of cbit.vcell.mongodb.VCMongoMessage.ServiceName 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 2 with ServiceName

use of cbit.vcell.mongodb.VCMongoMessage.ServiceName in project vcell by virtualcell.

the class WorkerEventMessage method parseMessage.

/**
 * Insert the method's description here.
 * Creation date: (2/5/2004 2:19:48 PM)
 * @param message javax.jms.Message
 * @throws DataAccessException
 * @throws SQLException
 */
private void parseMessage(UserResolver userResolver, VCMessage message) throws DataAccessException, SQLException {
    if (message == null) {
        throw new RuntimeException("Null message");
    }
    if (!message.propertyExists(VCMessagingConstants.MESSAGE_TYPE_PROPERTY)) {
        throw new RuntimeException("Wrong message: expecting property " + VCMessagingConstants.MESSAGE_TYPE_PROPERTY);
    }
    String msgType = message.getStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY);
    if (msgType != null && !msgType.equals(MessageConstants.MESSAGE_TYPE_WORKEREVENT_VALUE)) {
        throw new RuntimeException("Wrong message type: " + msgType + ", expecting: " + MessageConstants.MESSAGE_TYPE_WORKEREVENT_VALUE);
    }
    Object obj = message.getObjectContent();
    if (obj != null) {
        if (obj instanceof WorkerEvent) {
            // from Java executable or htcWorker
            workerEvent = (WorkerEvent) obj;
        } else if (obj instanceof String) {
            // from c++ executable (REST API where message stored as a single JSON object)
            String jsonContent = (String) obj;
            System.out.println("received JSON from message: " + jsonContent);
        } else {
            throw new IllegalArgumentException("Expecting object message with object " + WorkerEvent.class.getName() + ", found object :" + obj.getClass().getName());
        }
    } else {
        // from c++ executable (activemq-cpp native protocol communication library)
        int status = message.getIntProperty(MessageConstants.WORKEREVENT_STATUS);
        String hostname = message.getStringProperty(MessageConstants.HOSTNAME_PROPERTY);
        String username = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
        int taskID = message.getIntProperty(MessageConstants.TASKID_PROPERTY);
        int jobIndex = message.getIntProperty(MessageConstants.JOBINDEX_PROPERTY);
        Long longkey = message.getLongProperty(MessageConstants.SIMKEY_PROPERTY);
        KeyValue simKey = new KeyValue(longkey + "");
        // Simulation sim = null;
        User user = userResolver.getUser(username);
        VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simKey, user);
        String statusMessage = null;
        Double progress = null;
        Double timepoint = null;
        if (message.propertyExists(MessageConstants.WORKEREVENT_STATUSMSG)) {
            statusMessage = message.getStringProperty(MessageConstants.WORKEREVENT_STATUSMSG);
        }
        if (message.propertyExists(MessageConstants.WORKEREVENT_PROGRESS)) {
            progress = message.getDoubleProperty(MessageConstants.WORKEREVENT_PROGRESS);
        }
        if (message.propertyExists(MessageConstants.WORKEREVENT_TIMEPOINT)) {
            timepoint = message.getDoubleProperty(MessageConstants.WORKEREVENT_TIMEPOINT);
        }
        SimulationMessage simulationMessage = SimulationMessage.fromSerializedMessage(statusMessage);
        if (simulationMessage == null) {
            switch(status) {
                case WorkerEvent.JOB_ACCEPTED:
                    throw new RuntimeException("unexpected job_accepted status");
                case WorkerEvent.JOB_STARTING:
                    if (statusMessage == null) {
                        simulationMessage = SimulationMessage.MESSAGE_WORKEREVENT_STARTING;
                    } else {
                        simulationMessage = SimulationMessage.workerStarting(statusMessage);
                    }
                    break;
                case WorkerEvent.JOB_DATA:
                    simulationMessage = SimulationMessage.workerData(timepoint);
                    break;
                case WorkerEvent.JOB_PROGRESS:
                    simulationMessage = SimulationMessage.workerProgress(progress);
                    break;
                case WorkerEvent.JOB_FAILURE:
                    if (statusMessage == null) {
                        simulationMessage = SimulationMessage.MESSAGE_WORKEREVENT_FAILURE;
                    } else {
                        simulationMessage = SimulationMessage.workerFailure(statusMessage);
                    }
                    break;
                case WorkerEvent.JOB_COMPLETED:
                    if (statusMessage == null) {
                        simulationMessage = SimulationMessage.MESSAGE_WORKEREVENT_COMPLETED;
                    } else {
                        simulationMessage = SimulationMessage.workerCompleted(statusMessage);
                    }
                    break;
                case WorkerEvent.JOB_WORKER_ALIVE:
                    simulationMessage = SimulationMessage.MESSAGE_WORKEREVENT_WORKERALIVE;
                    break;
                default:
                    throw new RuntimeException("unexpected worker event status : " + status);
            }
        }
        ServiceName serviceName = VCMongoMessage.getServiceName();
        workerEvent = new WorkerEvent(status, serviceName, vcSimID, jobIndex, hostname, taskID, progress, timepoint, simulationMessage);
    }
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) WorkerEvent(cbit.rmi.event.WorkerEvent) ServiceName(cbit.vcell.mongodb.VCMongoMessage.ServiceName) SimulationMessage(cbit.vcell.solver.server.SimulationMessage)

Aggregations

ServiceName (cbit.vcell.mongodb.VCMongoMessage.ServiceName)2 WorkerEvent (cbit.rmi.event.WorkerEvent)1 ExportServiceImpl (cbit.vcell.export.server.ExportServiceImpl)1 VCMessagingService (cbit.vcell.message.VCMessagingService)1 ServerMessagingDelegate (cbit.vcell.message.server.ServerMessagingDelegate)1 ServiceInstanceStatus (cbit.vcell.message.server.ServiceInstanceStatus)1 VCellServiceMXBeanImpl (cbit.vcell.message.server.jmx.VCellServiceMXBeanImpl)1 Cachetable (cbit.vcell.simdata.Cachetable)1 DataServerImpl (cbit.vcell.simdata.DataServerImpl)1 DataSetControllerImpl (cbit.vcell.simdata.DataSetControllerImpl)1 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)1 SimulationMessage (cbit.vcell.solver.server.SimulationMessage)1 File (java.io.File)1 Date (java.util.Date)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 KeyValue (org.vcell.util.document.KeyValue)1 User (org.vcell.util.document.User)1