Search in sources :

Example 6 with SimulationJobStatusEvent

use of cbit.rmi.event.SimulationJobStatusEvent in project vcell by virtualcell.

the class HealthService method runsimLoop.

private void runsimLoop() {
    try {
        Thread.sleep(SIMULATION_LOOP_START_DELAY);
    } catch (InterruptedException e1) {
    }
    UserLoginInfo userLoginInfo = new UserLoginInfo(testUserid, testPassword);
    while (true) {
        long id = simStartEvent();
        KeyValue savedBioModelKey = null;
        VCSimulationIdentifier runningSimId = null;
        try {
            RemoteProxyVCellConnectionFactory vcellConnectionFactory = new RemoteProxyVCellConnectionFactory(host, port, userLoginInfo);
            VCellConnection vcellConnection = vcellConnectionFactory.createVCellConnection();
            String vcmlString = IOUtils.toString(getClass().getResourceAsStream("/TestTemplate.vcml"));
            BioModel templateBioModel = XmlHelper.XMLToBioModel(new XMLSource(vcmlString));
            templateBioModel.clearVersion();
            String newBiomodelName = "test_" + System.currentTimeMillis();
            templateBioModel.setName(newBiomodelName);
            // remove all existing simulations from stored template model, and add new one
            while (templateBioModel.getNumSimulations() > 0) {
                templateBioModel.removeSimulation(templateBioModel.getSimulation(0));
            }
            MathMappingCallback callback = new MathMappingCallback() {

                @Override
                public void setProgressFraction(float fractionDone) {
                }

                @Override
                public void setMessage(String message) {
                }

                @Override
                public boolean isInterrupted() {
                    return false;
                }
            };
            templateBioModel.getSimulationContext(0).addNewSimulation("sim", callback, NetworkGenerationRequirements.ComputeFullStandardTimeout);
            BigString vcml = new BigString(XmlHelper.bioModelToXML(templateBioModel));
            String[] independentSims = new String[0];
            BigString savedBioModelVCML = vcellConnection.getUserMetaDbServer().saveBioModelAs(vcml, newBiomodelName, independentSims);
            BioModel savedBioModel = XmlHelper.XMLToBioModel(new XMLSource(savedBioModelVCML.toString()));
            savedBioModelKey = savedBioModel.getVersion().getVersionKey();
            Simulation sim = savedBioModel.getSimulation(0);
            VCSimulationIdentifier vcSimId = new VCSimulationIdentifier(sim.getKey(), sim.getVersion().getOwner());
            long eventTimestamp = System.currentTimeMillis();
            SimulationStatus simStatus = vcellConnection.getSimulationController().startSimulation(vcSimId, 1);
            simSubmitEvent(id, vcSimId);
            runningSimId = vcSimId;
            long startTime_MS = System.currentTimeMillis();
            while (simStatus.isActive()) {
                if ((System.currentTimeMillis() - startTime_MS) > SIMULATION_TIMEOUT) {
                    throw new RuntimeException("simulation took longer than " + SIMULATION_TIMEOUT + " to complete");
                }
                Thread.sleep(1000);
                MessageEvent[] messageEvents = vcellConnection.getMessageEvents();
                if (messageEvents != null) {
                    for (MessageEvent event : messageEvents) {
                        if (event instanceof SimulationJobStatusEvent) {
                            SimulationJobStatusEvent jobEvent = (SimulationJobStatusEvent) event;
                            SimulationJobStatus jobStatus = jobEvent.getJobStatus();
                            VCSimulationIdentifier eventSimId = jobStatus.getVCSimulationIdentifier();
                            if (eventSimId.getOwner().equals(userLoginInfo.getUser()) && eventSimId.getSimulationKey().equals(sim.getKey())) {
                                simStatus = SimulationStatus.updateFromJobEvent(simStatus, jobEvent);
                            }
                        }
                    }
                }
            }
            runningSimId = null;
            if (!simStatus.isCompleted()) {
                throw new RuntimeException("failed: " + simStatus.getDetails());
            }
            simSuccess(id);
        } catch (Throwable e) {
            simFailed(id, e.getMessage());
        } finally {
            // cleanup
            try {
                RemoteProxyVCellConnectionFactory vcellConnectionFactory = new RemoteProxyVCellConnectionFactory(host, port, userLoginInfo);
                VCellConnection vcellConnection = vcellConnectionFactory.createVCellConnection();
                if (runningSimId != null) {
                    try {
                        vcellConnection.getSimulationController().stopSimulation(runningSimId);
                    } catch (Exception e) {
                        e.printStackTrace(System.out);
                    }
                }
                if (savedBioModelKey != null) {
                    vcellConnection.getUserMetaDbServer().deleteBioModel(savedBioModelKey);
                }
            } catch (Exception e) {
                e.printStackTrace(System.out);
            }
        }
        try {
            Thread.sleep(SIMULATION_LOOP_SLEEP);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
Also used : VCellConnection(cbit.vcell.server.VCellConnection) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) RemoteProxyVCellConnectionFactory(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory) KeyValue(org.vcell.util.document.KeyValue) MathMappingCallback(cbit.vcell.mapping.SimulationContext.MathMappingCallback) MessageEvent(cbit.rmi.event.MessageEvent) BigString(org.vcell.util.BigString) BigString(org.vcell.util.BigString) SimulationJobStatusEvent(cbit.rmi.event.SimulationJobStatusEvent) Simulation(cbit.vcell.solver.Simulation) SimulationStatus(cbit.vcell.server.SimulationStatus) BioModel(cbit.vcell.biomodel.BioModel) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) UserLoginInfo(org.vcell.util.document.UserLoginInfo) XMLSource(cbit.vcell.xml.XMLSource)

Example 7 with SimulationJobStatusEvent

use of cbit.rmi.event.SimulationJobStatusEvent in project vcell by virtualcell.

the class VCMongoMessage method sendClientMessageEventsDelivered.

public static void sendClientMessageEventsDelivered(MessageEvent[] messageEvents, UserLoginInfo userLoginInfo) {
    if (!enabled || messageEvents == null) {
        return;
    }
    for (MessageEvent messageEvent : messageEvents) {
        if (messageEvent instanceof SimulationJobStatusEvent) {
            try {
                Document dbObject = new Document();
                addHeader(dbObject, MongoMessage_msgtype_clientSimStatusDelivered);
                addObject(dbObject, (SimulationJobStatusEvent) messageEvent);
                addObject(dbObject, userLoginInfo);
                VCMongoDbDriver.getInstance().addMessage(new VCMongoMessage(dbObject));
            } catch (Exception e) {
                lg.error(e.getMessage(), e);
            }
        }
    }
}
Also used : MessageEvent(cbit.rmi.event.MessageEvent) Document(org.bson.Document) SimulationJobStatusEvent(cbit.rmi.event.SimulationJobStatusEvent) UnknownHostException(java.net.UnknownHostException)

Example 8 with SimulationJobStatusEvent

use of cbit.rmi.event.SimulationJobStatusEvent in project vcell by virtualcell.

the class SimulationControllerImpl method onServiceControlTopic_StopSimulation.

private void onServiceControlTopic_StopSimulation(VCMessage message) {
    KeyValue simKey = new KeyValue(String.valueOf(message.getLongProperty(MessageConstants.SIMKEY_PROPERTY)));
    int jobIndex = message.getIntProperty(MessageConstants.JOBINDEX_PROPERTY);
    int taskID = message.getIntProperty(MessageConstants.TASKID_PROPERTY);
    try {
        SimulationTaskID simTaskInfo = new SimulationTaskID(simKey, jobIndex, taskID);
        LocalSolverController solverController = solverControllerHash.get(simTaskInfo);
        if (solverController != null) {
            // can only start after updating the database is done
            solverController.stopSimulationJob();
        }
    } catch (Exception e) {
        lg.error(e.getMessage(), e);
        VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simKey, localVCellConnection.getUserLoginInfo().getUser());
        SimulationJobStatus newJobStatus = new SimulationJobStatus(VCellServerID.getSystemServerID(), vcSimID, jobIndex, null, SchedulerStatus.FAILED, taskID, SimulationMessage.jobFailed(e.getMessage()), null, null);
        SimulationJobStatusEvent event = new SimulationJobStatusEvent(this, Simulation.createSimulationID(simKey), newJobStatus, null, null, vcSimID.getOwner().getName());
        fireSimulationJobStatusEvent(event);
    }
}
Also used : LocalSolverController(cbit.vcell.solvers.LocalSolverController) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) SimulationTaskID(cbit.vcell.server.SimulationTaskID) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) SimulationJobStatusEvent(cbit.rmi.event.SimulationJobStatusEvent) 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)

Aggregations

SimulationJobStatusEvent (cbit.rmi.event.SimulationJobStatusEvent)8 SimulationJobStatus (cbit.vcell.server.SimulationJobStatus)5 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)4 VCMessagingException (cbit.vcell.message.VCMessagingException)3 KeyValue (org.vcell.util.document.KeyValue)3 DataJobEvent (cbit.rmi.event.DataJobEvent)2 ExportEvent (cbit.rmi.event.ExportEvent)2 MessageEvent (cbit.rmi.event.MessageEvent)2 VCellMessageEvent (cbit.rmi.event.VCellMessageEvent)2 SolverException (cbit.vcell.solver.SolverException)2 LocalSolverController (cbit.vcell.solvers.LocalSolverController)2 FileNotFoundException (java.io.FileNotFoundException)2 UnknownHostException (java.net.UnknownHostException)2 RemoteException (java.rmi.RemoteException)2 SQLException (java.sql.SQLException)2 JMSException (javax.jms.JMSException)2 Document (org.bson.Document)2 AuthenticationException (org.vcell.util.AuthenticationException)2 BigString (org.vcell.util.BigString)2 ConfigurationException (org.vcell.util.ConfigurationException)2