Search in sources :

Example 16 with SimulationJobStatus

use of cbit.vcell.server.SimulationJobStatus in project vcell by virtualcell.

the class SimulationControllerImpl method stopSimulation.

/**
 * This method was created by a SmartGuide.
 * @throws JMSException
 * @throws AuthenticationException
 * @throws DataAccessException
 * @throws SQLException
 * @throws FileNotFoundException
 * @exception java.rmi.RemoteException The exception description.
 * @throws VCMessagingException
 */
public void stopSimulation(Simulation simulation) throws FileNotFoundException, SQLException, DataAccessException, AuthenticationException, JMSException, VCMessagingException {
    LocalVCMessageListener localVCMessageListener = new LocalVCMessageListener() {

        public void onLocalVCMessage(VCDestination destination, VCMessage objectMessage) {
            String messageTypeProperty = VCMessagingConstants.MESSAGE_TYPE_PROPERTY;
            String stopSimulationValue = MessageConstants.MESSAGE_TYPE_STOPSIMULATION_VALUE;
            if (destination == VCellTopic.ClientStatusTopic && objectMessage.getObjectContent() instanceof SimulationJobStatus) {
                onClientStatusTopic_SimulationJobStatus(objectMessage);
            } else if (destination == VCellTopic.ServiceControlTopic && objectMessage.getStringProperty(messageTypeProperty).equals(stopSimulationValue)) {
                lg.error("SimulationControllerImpl.stopSimulation() exercising serviceControl topic ... should be removed");
                onServiceControlTopic_StopSimulation(objectMessage);
            } else {
                throw new RuntimeException("SimulationControllerImpl.startSimulation().objectMessageListener:: expecting message with SimulationJobStatus to topic " + VCellTopic.ClientStatusTopic.getName() + ": received \"" + objectMessage.show() + "\" on destination \"" + destination + "\"");
            }
        }
    };
    LocalVCMessageAdapter vcMessageSession = new LocalVCMessageAdapter(localVCMessageListener);
    VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simulation.getKey(), simulation.getVersion().getOwner());
    simulationDispatcherEngine.onStopRequest(vcSimID, localVCellConnection.getUserLoginInfo().getUser(), simulationDatabase, vcMessageSession);
    vcMessageSession.deliverAll();
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) VCDestination(cbit.vcell.message.VCDestination) LocalVCMessageListener(cbit.vcell.message.local.LocalVCMessageAdapter.LocalVCMessageListener) VCMessage(cbit.vcell.message.VCMessage) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) LocalVCMessageAdapter(cbit.vcell.message.local.LocalVCMessageAdapter)

Example 17 with SimulationJobStatus

use of cbit.vcell.server.SimulationJobStatus in project vcell by virtualcell.

the class SimulationControllerImpl method onSimJobQueue_SimulationTask.

private void onSimJobQueue_SimulationTask(VCMessage vcMessage) {
    SimulationTask simTask = null;
    try {
        SimulationTaskMessage simTaskMessage = new SimulationTaskMessage(vcMessage);
        simTask = simTaskMessage.getSimulationTask();
        LocalSolverController solverController = getOrCreateSolverController(simTask);
        // can only start after updating the database is done
        solverController.startSimulationJob();
    } catch (Exception e) {
        lg.error(e.getMessage(), e);
        KeyValue simKey = simTask.getSimKey();
        VCSimulationIdentifier vcSimID = simTask.getSimulationJob().getVCDataIdentifier().getVcSimID();
        int jobIndex = simTask.getSimulationJob().getJobIndex();
        int taskID = simTask.getTaskID();
        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) SimulationTask(cbit.vcell.messaging.server.SimulationTask) KeyValue(org.vcell.util.document.KeyValue) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) SimulationJobStatusEvent(cbit.rmi.event.SimulationJobStatusEvent) SimulationTaskMessage(cbit.vcell.message.messages.SimulationTaskMessage) 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)

Example 18 with SimulationJobStatus

use of cbit.vcell.server.SimulationJobStatus in project vcell by virtualcell.

the class AdminService method query.

public SimulationJobStatus[] query(SimpleJobStatusQuerySpec querySpec) throws ObjectNotFoundException, DataAccessException {
    SimulationDatabase simDatabase = new SimulationDatabaseDirect(adminDbTop, dbServerImpl, false);
    SimulationJobStatus[] resultList = simDatabase.queryJobs(querySpec);
    return resultList;
}
Also used : SimulationDatabase(cbit.vcell.message.server.dispatcher.SimulationDatabase) SimulationDatabaseDirect(cbit.vcell.message.server.dispatcher.SimulationDatabaseDirect) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus)

Example 19 with SimulationJobStatus

use of cbit.vcell.server.SimulationJobStatus in project vcell by virtualcell.

the class SimulationDatabaseDirectTest method test.

@Test
public void test() {
    try (ConnectionFactory conFactory = DatabaseService.getInstance().createConnectionFactory()) {
        DatabaseServerImpl databaseServerImpl = new DatabaseServerImpl(conFactory, conFactory.getKeyFactory());
        AdminDBTopLevel adminDbTopLevel = new AdminDBTopLevel(conFactory);
        boolean bCache = false;
        SimulationDatabaseDirect simulationDatabaseDirect = new SimulationDatabaseDirect(adminDbTopLevel, databaseServerImpl, bCache);
        SimpleJobStatusQuerySpec querySpec = new SimpleJobStatusQuerySpec();
        querySpec.submitLowMS = null;
        querySpec.submitHighMS = null;
        querySpec.startLowMS = null;
        querySpec.startHighMS = null;
        querySpec.endLowMS = null;
        querySpec.endHighMS = null;
        querySpec.startRow = 0;
        querySpec.maxRows = 100;
        querySpec.serverId = null;
        querySpec.computeHost = null;
        querySpec.userid = null;
        querySpec.simId = null;
        querySpec.jobId = null;
        querySpec.taskId = null;
        querySpec.hasData = null;
        querySpec.waiting = true;
        querySpec.queued = true;
        querySpec.dispatched = true;
        querySpec.running = true;
        querySpec.completed = true;
        querySpec.failed = true;
        querySpec.stopped = true;
        SimulationJobStatus[] resultList = simulationDatabaseDirect.queryJobs(querySpec);
        Gson gson = new Gson();
        for (SimulationJobStatus status : resultList) {
            System.out.println(gson.toJson(status.toRep()));
        }
    // test that there are no repeated jobs
    } catch (Exception e) {
        e.printStackTrace();
        fail("exception: " + e.getMessage());
    }
}
Also used : SimpleJobStatusQuerySpec(cbit.vcell.server.SimpleJobStatusQuerySpec) ConnectionFactory(org.vcell.db.ConnectionFactory) AdminDBTopLevel(cbit.vcell.modeldb.AdminDBTopLevel) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) Gson(com.google.gson.Gson) DatabaseServerImpl(cbit.vcell.modeldb.DatabaseServerImpl) Test(org.junit.Test)

Example 20 with SimulationJobStatus

use of cbit.vcell.server.SimulationJobStatus 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)

Aggregations

SimulationJobStatus (cbit.vcell.server.SimulationJobStatus)29 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)9 KeyValue (org.vcell.util.document.KeyValue)9 StatusMessage (cbit.vcell.message.messages.StatusMessage)7 SimulationExecutionStatus (cbit.vcell.server.SimulationExecutionStatus)7 SimulationQueueEntryStatus (cbit.vcell.server.SimulationQueueEntryStatus)7 Date (java.util.Date)6 SimulationJobStatusEvent (cbit.rmi.event.SimulationJobStatusEvent)5 ArrayList (java.util.ArrayList)5 VCellServerID (org.vcell.util.document.VCellServerID)5 VCMessage (cbit.vcell.message.VCMessage)4 VCMessagingException (cbit.vcell.message.VCMessagingException)4 HtcJobID (cbit.vcell.server.HtcJobID)4 SimulationStatus (cbit.vcell.server.SimulationStatus)4 VCDestination (cbit.vcell.message.VCDestination)3 LocalVCMessageAdapter (cbit.vcell.message.local.LocalVCMessageAdapter)3 LocalVCMessageListener (cbit.vcell.message.local.LocalVCMessageAdapter.LocalVCMessageListener)3 SchedulerStatus (cbit.vcell.server.SimulationJobStatus.SchedulerStatus)3 SimulationJobStatusPersistent (cbit.vcell.server.SimulationJobStatusPersistent)3 SolverException (cbit.vcell.solver.SolverException)3