Search in sources :

Example 11 with VCellConnection

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

the class HealthService method loginLoop.

private void loginLoop() {
    try {
        Thread.sleep(LOGIN_LOOP_START_DELAY);
    } catch (InterruptedException e1) {
    }
    while (true) {
        long id = loginStartEvent();
        try {
            UserLoginInfo userLoginInfo = new UserLoginInfo(testUserid, testPassword);
            RemoteProxyVCellConnectionFactory vcellConnectionFactory = new RemoteProxyVCellConnectionFactory(host, port, userLoginInfo);
            VCellConnection vcellConnection = vcellConnectionFactory.createVCellConnection();
            VCInfoContainer vcInfoContainer = vcellConnection.getUserMetaDbServer().getVCInfoContainer();
            loginSuccess(id);
        } catch (Throwable e) {
            loginFailed(id, e.getMessage());
        }
        try {
            Thread.sleep(LOGIN_LOOP_SLEEP);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
Also used : VCellConnection(cbit.vcell.server.VCellConnection) RemoteProxyVCellConnectionFactory(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory) VCInfoContainer(org.vcell.util.document.VCInfoContainer) UserLoginInfo(org.vcell.util.document.UserLoginInfo)

Example 12 with VCellConnection

use of cbit.vcell.server.VCellConnection 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 13 with VCellConnection

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

the class NagiosVCellCheck method checkVCell.

private static String checkVCell(VCELL_CHECK_LEVEL checkLevel, String rmiHostName, int rmiPort, String rmiBootstrapStubName, String vcellNagiosPassword, int warningTimeout, int criticalTimeout) throws Exception {
    long startTime = System.currentTimeMillis();
    SimulationStatusPersistent lastSimStatus = null;
    if (rmiHostName == null || rmiPort == -1) {
        throw new UnexpectedTestStateException("Host name/ip and rmiPort required for testing, rmihostname=" + rmiHostName + " rmiport=" + rmiPort);
    }
    String rmiUrl = "//" + rmiHostName + ":" + rmiPort + "/" + rmiBootstrapStubName;
    VCellBootstrap vcellBootstrap = null;
    try {
        vcellBootstrap = (VCellBootstrap) Naming.lookup(rmiUrl);
    } catch (Exception e) {
        throw new UnexpectedTestStateException("Error during bootstrap lookup, " + e.getClass().getSimpleName() + " " + e.getMessage());
    }
    if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.CONNECT_1.ordinal()) {
        if (vcellNagiosPassword == null) {
            throw new UnexpectedTestStateException("vcellNagios Password required for " + VCELL_CHECK_LEVEL.CONNECT_1.toString() + " and above");
        }
        VCellConnection vcellConnection = vcellBootstrap.getVCellConnection(new UserLoginInfo("vcellNagios", new DigestedPassword(vcellNagiosPassword)));
        if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.INFOS_2.ordinal()) {
            VCInfoContainer vcInfoContainer = vcellConnection.getUserMetaDbServer().getVCInfoContainer();
            if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.LOAD_3.ordinal()) {
                KeyValue bioModelKey = null;
                final String testModelName = "Solver Suite 5.1 (BETA only ode)";
                for (BioModelInfo bioModelInfo : vcInfoContainer.getBioModelInfos()) {
                    if (bioModelInfo.getVersion().getName().equals(testModelName)) {
                        bioModelKey = bioModelInfo.getVersion().getVersionKey();
                        break;
                    }
                }
                BigString bioModelXML = vcellConnection.getUserMetaDbServer().getBioModelXML(bioModelKey);
                BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
                bioModel.refreshDependencies();
                if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.DATA_4.ordinal()) {
                    final String testSimContextName = "non-spatial ODE";
                    SimulationContext simulationContext = bioModel.getSimulationContext(testSimContextName);
                    final String testSimName = "Copy of combined ida/cvode";
                    Simulation simulation = simulationContext.getSimulation(testSimName);
                    if (simulation == null) {
                        throw new UnexpectedTestStateException("Couldn't find sim '" + testSimName + "' for " + checkLevel.toString());
                    }
                    VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(simulation.getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), 0);
                    ArrayList<AnnotatedFunction> outputFunctionsList = simulationContext.getOutputFunctionContext().getOutputFunctionsList();
                    OutputContext outputContext = new OutputContext(outputFunctionsList.toArray(new AnnotatedFunction[outputFunctionsList.size()]));
                    double[] times = vcellConnection.getDataSetController().getDataSetTimes(vcSimulationDataIdentifier);
                    ODESimData odeSimData = vcellConnection.getDataSetController().getODEData(vcSimulationDataIdentifier);
                    // SimDataBlock simDataBlock = vcellConnection.getDataSetController().getSimDataBlock(outputContext, vcSimulationDataIdentifier, "RanC_cyt",times[times.length-1]);
                    if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.RUN_5.ordinal()) {
                        KeyValue copy1Key = null;
                        KeyValue copy2Key = null;
                        try {
                            if (simulationContext.getSimulations().length != 1) {
                                throw new UnexpectedTestStateException("Expecting only 1 sim to be copied for " + checkLevel.toString());
                            }
                            SimulationStatusPersistent simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(simulation.getVersion().getVersionKey());
                            if (!simulationStatus.isCompleted()) {
                                throw new UnexpectedTestStateException("Expecting completed sim to copy for " + checkLevel.toString());
                            }
                            String copyModelName = testModelName + "_" + rmiHostName + "_" + rmiPort;
                            for (BioModelInfo bioModelInfo : vcInfoContainer.getBioModelInfos()) {
                                if (bioModelInfo.getVersion().getName().equals(copyModelName)) {
                                    throw new UnexpectedTestStateException("Messy test environment, not expecting " + copyModelName + " to exist at this point");
                                }
                            }
                            BigString copyBioModelXMLStr = vcellConnection.getUserMetaDbServer().saveBioModelAs(bioModelXML, copyModelName, null);
                            BioModel copyBioModel = XmlHelper.XMLToBioModel(new XMLSource(copyBioModelXMLStr.toString()));
                            copy1Key = copyBioModel.getVersion().getVersionKey();
                            copyBioModel.refreshDependencies();
                            Simulation copySim = copyBioModel.getSimulationContext(testSimContextName).copySimulation(copyBioModel.getSimulationContext(testSimContextName).getSimulation(testSimName));
                            final String copyTestSimName = "test";
                            copySim.setName(copyTestSimName);
                            copyBioModel.refreshDependencies();
                            copyBioModelXMLStr = new BigString(XmlHelper.bioModelToXML(copyBioModel));
                            copyBioModelXMLStr = vcellConnection.getUserMetaDbServer().saveBioModel(copyBioModelXMLStr, null);
                            copyBioModel = XmlHelper.XMLToBioModel(new XMLSource(copyBioModelXMLStr.toString()));
                            copy2Key = copyBioModel.getVersion().getVersionKey();
                            copyBioModel.refreshDependencies();
                            Simulation newSimulation = copyBioModel.getSimulationContext(testSimContextName).getSimulation(copyTestSimName);
                            simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(newSimulation.getVersion().getVersionKey());
                            if (simulationStatus != null && !simulationStatus.isNeverRan()) {
                                throw new UnexpectedTestStateException("Expecting new sim to have 'never ran' status for " + checkLevel.toString());
                            }
                            VCSimulationIdentifier newSimID = new VCSimulationIdentifier(newSimulation.getVersion().getVersionKey(), copyBioModel.getVersion().getOwner());
                            vcellConnection.getSimulationController().startSimulation(newSimID, 1);
                            lastSimStatus = simulationStatus;
                            MessageEvent[] messageEvents = null;
                            while (simulationStatus == null || (!simulationStatus.isStopped() && !simulationStatus.isCompleted() && !simulationStatus.isFailed())) {
                                Thread.sleep(200);
                                if (((System.currentTimeMillis() - startTime) / 1000) > criticalTimeout) {
                                    vcellConnection.getSimulationController().stopSimulation(newSimID);
                                    vcellConnection.getMessageEvents();
                                    break;
                                }
                                simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(newSimulation.getVersion().getVersionKey());
                                if (simulationStatus != null && !simulationStatus.toString().equals((lastSimStatus == null ? null : lastSimStatus.toString()))) {
                                    lastSimStatus = simulationStatus;
                                }
                                messageEvents = vcellConnection.getMessageEvents();
                            }
                        } finally {
                            try {
                                if (copy1Key != null) {
                                    vcellConnection.getUserMetaDbServer().deleteBioModel(copy1Key);
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            try {
                                if (copy2Key != null) {
                                    vcellConnection.getUserMetaDbServer().deleteBioModel(copy2Key);
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }
        }
    }
    long endTime = System.currentTimeMillis();
    if (criticalTimeout != -1 && ((endTime - startTime) / 1000) > criticalTimeout) {
        throw new Exception(checkLevel.toString() + " test exceeded criticalTimeout=" + criticalTimeout + " seconds lastSimStatus=" + lastSimStatus);
    }
    if (warningTimeout != -1 && ((endTime - startTime) / 1000) > warningTimeout) {
        throw new WarningTestConditionException(checkLevel.toString() + " test exceeded warningTimeout=" + warningTimeout + " seconds lastSimStatus=" + lastSimStatus);
    }
    return vcellBootstrap.getVCellSoftwareVersion();
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) MessageEvent(cbit.rmi.event.MessageEvent) VCellBootstrap(cbit.vcell.server.VCellBootstrap) BigString(org.vcell.util.BigString) ODESimData(cbit.vcell.solver.ode.ODESimData) DigestedPassword(org.vcell.util.document.UserLoginInfo.DigestedPassword) BigString(org.vcell.util.BigString) VCInfoContainer(org.vcell.util.document.VCInfoContainer) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) VCellConnection(cbit.vcell.server.VCellConnection) BioModelInfo(org.vcell.util.document.BioModelInfo) SimulationStatusPersistent(cbit.vcell.server.SimulationStatusPersistent) SimulationContext(cbit.vcell.mapping.SimulationContext) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) OutputContext(cbit.vcell.simdata.OutputContext) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) UserLoginInfo(org.vcell.util.document.UserLoginInfo) XMLSource(cbit.vcell.xml.XMLSource)

Aggregations

VCellConnection (cbit.vcell.server.VCellConnection)13 UserLoginInfo (org.vcell.util.document.UserLoginInfo)8 BigString (org.vcell.util.BigString)6 VCellBootstrap (cbit.vcell.server.VCellBootstrap)5 Simulation (cbit.vcell.solver.Simulation)5 DigestedPassword (org.vcell.util.document.UserLoginInfo.DigestedPassword)5 MessageEvent (cbit.rmi.event.MessageEvent)4 BioModel (cbit.vcell.biomodel.BioModel)4 RemoteProxyVCellConnectionFactory (cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory)4 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)4 IOException (java.io.IOException)4 DataAccessException (org.vcell.util.DataAccessException)4 SimulationContext (cbit.vcell.mapping.SimulationContext)3 RemoteProxyException (cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException)3 SimulationStatusPersistent (cbit.vcell.server.SimulationStatusPersistent)3 XMLSource (cbit.vcell.xml.XMLSource)3 BioModelInfo (org.vcell.util.document.BioModelInfo)3 KeyValue (org.vcell.util.document.KeyValue)3 VCInfoContainer (org.vcell.util.document.VCInfoContainer)3 OutputContext (cbit.vcell.simdata.OutputContext)2