Search in sources :

Example 16 with VCMessage

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

the class VCellApiMain method main.

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        if (args.length != 2) {
            System.out.println("usage: VCellApiMain javascriptDir port");
            System.exit(1);
        }
        File javascriptDir = new File(args[0]);
        if (!javascriptDir.isDirectory()) {
            throw new RuntimeException("javascriptDir '" + args[0] + "' is not a directory");
        }
        // don't validate
        PropertyLoader.loadProperties();
        lg.debug("properties loaded");
        String portString = args[1];
        // was hard-coded at 8080
        Integer port = null;
        try {
            port = Integer.parseInt(portString);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            throw new RuntimeException("failed to parse port argument '" + portString + "'", e);
        }
        lg.trace("connecting to database");
        lg.trace("oracle factory (next)");
        ConnectionFactory conFactory = DatabaseService.getInstance().createConnectionFactory();
        KeyFactory keyFactory = conFactory.getKeyFactory();
        lg.trace("database impl (next)");
        DatabaseServerImpl databaseServerImpl = new DatabaseServerImpl(conFactory, keyFactory);
        lg.trace("local db server (next)");
        LocalAdminDbServer localAdminDbServer = new LocalAdminDbServer(conFactory, keyFactory);
        lg.trace("admin db server (next)");
        AdminDBTopLevel adminDbTopLevel = new AdminDBTopLevel(conFactory);
        lg.trace("messaging service (next)");
        VCMessagingService vcMessagingService_int = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
        VCMessagingDelegate delegate = new VCMessagingDelegate() {

            @Override
            public void onTraceEvent(String string) {
                if (lg.isTraceEnabled())
                    lg.trace("onTraceEvent(): " + string);
            }

            @Override
            public void onRpcRequestSent(VCRpcRequest vcRpcRequest, UserLoginInfo userLoginInfo, VCMessage vcRpcRequestMessage) {
                if (lg.isTraceEnabled())
                    lg.trace("onRpcRequestSent(): " + vcRpcRequest.getMethodName());
            }

            @Override
            public void onRpcRequestProcessed(VCRpcRequest vcRpcRequest, VCMessage rpcVCMessage) {
                if (lg.isTraceEnabled())
                    lg.trace("onRpcRequestProcessed(): " + vcRpcRequest.getMethodName());
            }

            @Override
            public void onMessageSent(VCMessage message, VCDestination desintation) {
                if (lg.isTraceEnabled())
                    lg.trace("onMessageSent(): " + message);
            }

            @Override
            public void onMessageReceived(VCMessage vcMessage, VCDestination vcDestination) {
                if (lg.isTraceEnabled())
                    lg.trace("onMessageReceived(): " + vcMessage);
            }

            @Override
            public void onException(Exception e) {
                lg.error(e.getMessage(), e);
            }
        };
        String jmshost_int = PropertyLoader.getRequiredProperty(PropertyLoader.jmsIntHostInternal);
        int jmsport_int = Integer.parseInt(PropertyLoader.getRequiredProperty(PropertyLoader.jmsIntPortInternal));
        vcMessagingService_int.setConfiguration(delegate, jmshost_int, jmsport_int);
        lg.trace("rest database service (next)");
        RestDatabaseService restDatabaseService = new RestDatabaseService(databaseServerImpl, localAdminDbServer, vcMessagingService_int);
        lg.trace("rest event service (next)");
        RestEventService restEventService = new RestEventService(vcMessagingService_int);
        lg.trace("use verifier (next)");
        UserVerifier userVerifier = new UserVerifier(adminDbTopLevel);
        lg.trace("mongo (next)");
        VCMongoMessage.enabled = true;
        VCMongoMessage.serviceStartup(ServiceName.unknown, port, args);
        System.out.println("setting up server configuration");
        lg.trace("register engine (next)");
        Engine.register(true);
        WadlComponent component = new WadlComponent();
        // Server httpServer = component.getServers().add(Protocol.HTTP, 80);
        // Server httpsServer = component.getServers().add(Protocol.HTTPS, 443);
        // Client httpsClient = component.getClients().add(Protocol.HTTPS);
        // Client httpClient = component.getClients().add(Protocol.HTTP);
        lg.trace("adding FILE protcol");
        @SuppressWarnings("unused") Client httpClient = component.getClients().add(Protocol.FILE);
        lg.trace("adding CLAP protcol");
        @SuppressWarnings("unused") Client clapClient = component.getClients().add(Protocol.CLAP);
        lg.trace("adding CLAP https");
        File keystorePath = new File(PropertyLoader.getRequiredProperty(PropertyLoader.vcellapiKeystoreFile));
        String keystorePassword = PropertyLoader.getSecretValue(PropertyLoader.vcellapiKeystorePswd, PropertyLoader.vcellapiKeystorePswdFile);
        try {
            // 
            // keystorePassword may be encrypted with dbPassword, if it is decypt it.
            // 
            String dbPassword = PropertyLoader.getSecretValue(PropertyLoader.dbPasswordValue, PropertyLoader.dbPasswordFile);
            SecretKeyFactory kf = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
            SecretKey key = kf.generateSecret(new PBEKeySpec(dbPassword.toCharArray()));
            Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
            pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(new byte[] { 32, 11, 55, 121, 01, 42, 89, 11 }, 20));
            keystorePassword = new String(pbeCipher.doFinal(DatatypeConverter.parseBase64Binary(keystorePassword)));
        } catch (Exception e) {
            System.out.println("password unhashing didn't work - trying clear text password");
            e.printStackTrace();
        }
        Server httpsServer = component.getServers().add(Protocol.HTTPS, port);
        Series<Parameter> parameters = httpsServer.getContext().getParameters();
        parameters.add("keystorePath", keystorePath.toString());
        parameters.add("keystorePassword", keystorePassword);
        parameters.add("keystoreType", "JKS");
        parameters.add("keyPassword", keystorePassword);
        parameters.add("disabledCipherSuites", "SSL_RSA_WITH_3DES_EDE_CBC_SHA " + "SSL_DHE_RSA_WITH_DES_CBC_SHA " + "SSL_DHE_DSS_WITH_DES_CBC_SHA");
        parameters.add("enabledCipherSuites", "TLS_DHE_DSS_WITH_AES_128_CBC_SHA " + "TLS_DHE_RSA_WITH_AES_128_CBC_SHA " + "TLS_RSA_WITH_AES_128_CBC_SHA " + "TLS_DHE_DSS_WITH_AES_256_CBC_SHA " + "TLS_DHE_RSA_WITH_AES_256_CBC_SHA " + "TLS_RSA_WITH_AES_256_CBC_SHA");
        lg.trace("create config");
        Configuration templateConfiguration = new Configuration();
        templateConfiguration.setObjectWrapper(new DefaultObjectWrapper());
        // lg.trace("verify python installation");
        // PythonSupport.verifyInstallation(new PythonPackage[] { PythonPackage.COPASI, PythonPackage.LIBSBML, PythonPackage.THRIFT });
        // 
        // lg.trace("start Optimization Service");
        lg.trace("create app");
        boolean bIgnoreHostProblems = true;
        boolean bIgnoreCertProblems = true;
        User testUser = localAdminDbServer.getUser(TEST_USER);
        // lookup hashed auth credentials in database.
        UserInfo testUserInfo = localAdminDbServer.getUserInfo(testUser.getID());
        HealthService healthService = new HealthService(restEventService, "localhost", port, bIgnoreCertProblems, bIgnoreHostProblems, testUserInfo.userid, testUserInfo.digestedPassword0);
        AdminService adminService = new AdminService(adminDbTopLevel, databaseServerImpl);
        RpcService rpcService = new RpcService(vcMessagingService_int);
        WadlApplication app = new VCellApiApplication(restDatabaseService, userVerifier, rpcService, restEventService, adminService, templateConfiguration, healthService, javascriptDir);
        lg.trace("attach app");
        component.getDefaultHost().attach(app);
        System.out.println("component start()");
        lg.trace("start component");
        component.start();
        System.out.println("component ended.");
        lg.trace("component started");
        lg.trace("start VCell Health Monitoring service");
        healthService.start();
    } catch (Exception e) {
        lg.error(e.getMessage(), e);
    }
}
Also used : PBEKeySpec(javax.crypto.spec.PBEKeySpec) WadlComponent(org.restlet.ext.wadl.WadlComponent) User(org.vcell.util.document.User) AdminService(org.vcell.rest.admin.AdminService) Server(org.restlet.Server) LocalAdminDbServer(cbit.vcell.modeldb.LocalAdminDbServer) Configuration(freemarker.template.Configuration) VCMessagingDelegate(cbit.vcell.message.VCMessagingDelegate) UserInfo(org.vcell.util.document.UserInfo) VCMessagingService(cbit.vcell.message.VCMessagingService) ConnectionFactory(org.vcell.db.ConnectionFactory) VCDestination(cbit.vcell.message.VCDestination) VCMessage(cbit.vcell.message.VCMessage) HealthService(org.vcell.rest.health.HealthService) DatabaseServerImpl(cbit.vcell.modeldb.DatabaseServerImpl) RestDatabaseService(org.vcell.rest.server.RestDatabaseService) Client(org.restlet.Client) SecretKeyFactory(javax.crypto.SecretKeyFactory) SecretKeyFactory(javax.crypto.SecretKeyFactory) KeyFactory(org.vcell.db.KeyFactory) PBEParameterSpec(javax.crypto.spec.PBEParameterSpec) AdminDBTopLevel(cbit.vcell.modeldb.AdminDBTopLevel) DefaultObjectWrapper(freemarker.template.DefaultObjectWrapper) VCRpcRequest(cbit.vcell.message.VCRpcRequest) SecretKey(javax.crypto.SecretKey) RestEventService(org.vcell.rest.events.RestEventService) WadlApplication(org.restlet.ext.wadl.WadlApplication) RpcService(org.vcell.rest.rpc.RpcService) LocalAdminDbServer(cbit.vcell.modeldb.LocalAdminDbServer) Parameter(org.restlet.data.Parameter) Cipher(javax.crypto.Cipher) UserLoginInfo(org.vcell.util.document.UserLoginInfo) File(java.io.File)

Example 17 with VCMessage

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

the class WorkerEventMessage method toMessage.

/**
 * Insert the method's description here.
 * Creation date: (5/20/2003 1:36:36 PM)
 * @return javax.jms.Message
 */
private VCMessage toMessage(VCMessageSession session) {
    VCMessage message = session.createObjectMessage(workerEvent);
    message.setStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY, MessageConstants.MESSAGE_TYPE_WORKEREVENT_VALUE);
    return message;
}
Also used : VCMessage(cbit.vcell.message.VCMessage)

Example 18 with VCMessage

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

the class SimulationControllerImpl method onWorkerEvent.

/**
 * Insert the method's description here.
 * Creation date: (3/11/2004 10:44:18 AM)
 * @param newJobStatus cbit.vcell.messaging.db.SimulationJobStatus
 * @param progress java.lang.Double
 * @param timePoint java.lang.Double
 */
public void onWorkerEvent(WorkerEvent workerEvent) {
    try {
        LocalVCMessageListener localVCMessageListener = new LocalVCMessageListener() {

            public void onLocalVCMessage(VCDestination destination, VCMessage objectMessage) {
                if (destination == VCellTopic.ClientStatusTopic && objectMessage.getObjectContent() instanceof SimulationJobStatus) {
                    onClientStatusTopic_SimulationJobStatus(objectMessage);
                } else {
                    throw new RuntimeException("SimulationControllerImpl.onWorkerEvent().localMessageListener::  expecting object message with SimulationJobStatus to topic " + VCellTopic.ClientStatusTopic.getName() + ": received \"" + objectMessage.show() + "\"");
                }
            }
        };
        LocalVCMessageAdapter vcMessageSession = new LocalVCMessageAdapter(localVCMessageListener);
        simulationDispatcherEngine.onWorkerEvent(workerEvent, simulationDatabase, vcMessageSession);
        vcMessageSession.deliverAll();
    } catch (Exception e) {
        lg.error(e.getMessage(), e);
    }
}
Also used : VCDestination(cbit.vcell.message.VCDestination) LocalVCMessageListener(cbit.vcell.message.local.LocalVCMessageAdapter.LocalVCMessageListener) VCMessage(cbit.vcell.message.VCMessage) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) SQLException(java.sql.SQLException) VCMessagingException(cbit.vcell.message.VCMessagingException) SolverException(cbit.vcell.solver.SolverException) AuthenticationException(org.vcell.util.AuthenticationException) DataAccessException(org.vcell.util.DataAccessException) JMSException(javax.jms.JMSException) FileNotFoundException(java.io.FileNotFoundException) RemoteException(java.rmi.RemoteException) ConfigurationException(org.vcell.util.ConfigurationException) LocalVCMessageAdapter(cbit.vcell.message.local.LocalVCMessageAdapter)

Example 19 with VCMessage

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

the class SimDataServer method exportMessage.

/**
 * Insert the method's description here.
 * Creation date: (7/29/2003 10:34:11 AM)
 * @param event cbit.rmi.event.ExportEvent
 */
public void exportMessage(cbit.rmi.event.ExportEvent event) {
    try {
        VCMessageSession dataSession = vcMessagingService_int.createProducerSession();
        VCMessage exportEventMessage = dataSession.createObjectMessage(event);
        exportEventMessage.setStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY, MessageConstants.MESSAGE_TYPE_EXPORT_EVENT_VALUE);
        exportEventMessage.setStringProperty(VCMessagingConstants.USERNAME_PROPERTY, event.getUser().getName());
        dataSession.sendTopicMessage(VCellTopic.ClientStatusTopic, exportEventMessage);
        dataSession.close();
    } catch (VCMessagingException ex) {
        lg.error(ex.getMessage(), ex);
    }
}
Also used : VCMessage(cbit.vcell.message.VCMessage) VCMessageSession(cbit.vcell.message.VCMessageSession) VCMessagingException(cbit.vcell.message.VCMessagingException)

Example 20 with VCMessage

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

the class SimDataServer method dataJobMessage.

/**
 * Insert the method's description here.
 * Creation date: (3/31/2006 8:48:04 AM)
 * @param event cbit.rmi.event.ExportEvent
 */
public void dataJobMessage(cbit.rmi.event.DataJobEvent event) {
    try {
        VCMessageSession dataSession = vcMessagingService_int.createProducerSession();
        VCMessage dataEventMessage = dataSession.createObjectMessage(event);
        dataEventMessage.setStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY, MessageConstants.MESSAGE_TYPE_DATA_EVENT_VALUE);
        dataEventMessage.setStringProperty(VCMessagingConstants.USERNAME_PROPERTY, event.getUser().getName());
        dataSession.sendTopicMessage(VCellTopic.ClientStatusTopic, dataEventMessage);
        dataSession.close();
    } catch (VCMessagingException ex) {
        lg.error(ex.getMessage(), ex);
    }
}
Also used : VCMessage(cbit.vcell.message.VCMessage) VCMessageSession(cbit.vcell.message.VCMessageSession) VCMessagingException(cbit.vcell.message.VCMessagingException)

Aggregations

VCMessage (cbit.vcell.message.VCMessage)22 VCMessageSession (cbit.vcell.message.VCMessageSession)10 VCMessagingException (cbit.vcell.message.VCMessagingException)9 VCMessageSelector (cbit.vcell.message.VCMessageSelector)6 VCQueueConsumer (cbit.vcell.message.VCQueueConsumer)5 QueueListener (cbit.vcell.message.VCQueueConsumer.QueueListener)5 VCDestination (cbit.vcell.message.VCDestination)4 SimulationJobStatus (cbit.vcell.server.SimulationJobStatus)4 FileNotFoundException (java.io.FileNotFoundException)4 RollbackException (cbit.vcell.message.RollbackException)3 VCTopicConsumer (cbit.vcell.message.VCTopicConsumer)3 TopicListener (cbit.vcell.message.VCTopicConsumer.TopicListener)3 LocalVCMessageAdapter (cbit.vcell.message.local.LocalVCMessageAdapter)3 LocalVCMessageListener (cbit.vcell.message.local.LocalVCMessageAdapter.LocalVCMessageListener)3 SolverException (cbit.vcell.solver.SolverException)3 XmlParseException (cbit.vcell.xml.XmlParseException)3 DataAccessException (org.vcell.util.DataAccessException)3 MessagePropertyNotFoundException (cbit.vcell.message.MessagePropertyNotFoundException)2 VCMessagingService (cbit.vcell.message.VCMessagingService)2 VCPooledQueueConsumer (cbit.vcell.message.VCPooledQueueConsumer)2