Search in sources :

Example 1 with VCellConnection

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

the class ClientServerManager method connect.

/**
 * Insert the method's description here.
 * Creation date: (5/17/2004 6:26:14 PM)
 */
public void connect(InteractiveContext requester) {
    asynchMessageManager.stopPolling();
    reconnectStat = ReconnectStatus.NOT;
    checkClientServerSoftwareVersion(requester, clientServerInfo);
    // get new server connection
    VCellConnection newVCellConnection = connectToServer(requester);
    // update managers, status, etc.
    changeConnection(requester, newVCellConnection);
    if (fieldConnectionStatus.getStatus() == ConnectionStatus.CONNECTED) {
        // start polling if haven't already
        asynchMessageManager.startPolling();
    }
}
Also used : VCellConnection(cbit.vcell.server.VCellConnection)

Example 2 with VCellConnection

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

the class ClientServerManager method connectToServer.

/**
 * Insert the method's description here.
 * Creation date: (5/12/2004 4:48:13 PM)
 */
private VCellConnection connectToServer(InteractiveContext requester) {
    VCellThreadChecker.checkRemoteInvocation();
    VCellConnection newVCellConnection = null;
    VCellConnectionFactory vcConnFactory = null;
    String badConnStr = "";
    try {
        switch(getClientServerInfo().getServerType()) {
            case SERVER_REMOTE:
                {
                    String apihost = getClientServerInfo().getApihost();
                    Integer apiport = getClientServerInfo().getApiport();
                    try {
                        badConnStr += apihost + ":" + apiport;
                        vcConnFactory = new RemoteProxyVCellConnectionFactory(apihost, apiport, getClientServerInfo().getUserLoginInfo());
                        setConnectionStatus(new ClientConnectionStatus(getClientServerInfo().getUsername(), apihost, apiport, ConnectionStatus.INITIALIZING));
                        newVCellConnection = vcConnFactory.createVCellConnection();
                    } catch (AuthenticationException ex) {
                        throw ex;
                    }
                    break;
                }
            case SERVER_LOCAL:
                {
                    new PropertyLoader();
                    LocalVCellConnectionService localVCellConnectionService = VCellServiceHelper.getInstance().loadService(LocalVCellConnectionService.class);
                    vcConnFactory = localVCellConnectionService.getLocalVCellConnectionFactory(getClientServerInfo().getUserLoginInfo());
                    setConnectionStatus(new ClientConnectionStatus(getClientServerInfo().getUsername(), null, null, ConnectionStatus.INITIALIZING));
                    newVCellConnection = vcConnFactory.createVCellConnection();
                    break;
                }
        }
        requester.clearConnectWarning();
        reconnectStat = ReconnectStatus.NOT;
    } catch (AuthenticationException aexc) {
        aexc.printStackTrace(System.out);
        requester.showErrorDialog(aexc.getMessage());
    } catch (ConnectionException cexc) {
        String msg = badConnectMessage(badConnStr) + "\n" + cexc.getMessage();
        cexc.printStackTrace(System.out);
        ErrorUtils.sendRemoteLogMessage(getClientServerInfo().getUserLoginInfo(), msg);
        if (reconnectStat != ReconnectStatus.SUBSEQUENT) {
            requester.showConnectWarning(msg);
        }
    } catch (Exception exc) {
        exc.printStackTrace(System.out);
        String msg = badConnectMessage(badConnStr) + "\nException:\n" + exc.getMessage();
        ErrorUtils.sendRemoteLogMessage(getClientServerInfo().getUserLoginInfo(), msg);
        requester.showErrorDialog(msg);
    }
    return newVCellConnection;
}
Also used : VCellConnection(cbit.vcell.server.VCellConnection) RemoteProxyVCellConnectionFactory(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory) AuthenticationException(org.vcell.util.AuthenticationException) LocalVCellConnectionService(cbit.vcell.server.LocalVCellConnectionService) PropertyLoader(cbit.vcell.resource.PropertyLoader) VCellConnectionFactory(cbit.vcell.server.VCellConnectionFactory) RemoteProxyVCellConnectionFactory(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory) ConnectionException(cbit.vcell.server.ConnectionException) ConnectionException(cbit.vcell.server.ConnectionException) AuthenticationException(org.vcell.util.AuthenticationException) RemoteProxyException(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException)

Example 3 with VCellConnection

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

the class ClientServerManager method reconnect.

/**
 * attempt reconnect now
 */
void reconnect() {
    Reconnector rc = getReconnector();
    rc.notificationPause(true);
    try {
        switch(reconnectStat) {
            case NOT:
                reconnectStat = ReconnectStatus.FIRST;
                break;
            case FIRST:
                reconnectStat = ReconnectStatus.SUBSEQUENT;
                break;
            default:
        }
        InteractiveContext requester = defaultInteractiveContextProvider.getInteractiveContext();
        VCellConnection connection = connectToServer(requester);
        if (connection != null) {
            // success
            changeConnection(requester, connection);
            rc.stop();
            asynchMessageManager.startPolling();
            return;
        }
        setConnectionStatus(new ClientConnectionStatus(getClientServerInfo().getUsername(), getClientServerInfo().getApihost(), getClientServerInfo().getApiport(), ConnectionStatus.DISCONNECTED));
    } finally {
        rc.notificationPause(false);
    }
}
Also used : VCellConnection(cbit.vcell.server.VCellConnection)

Example 4 with VCellConnection

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

the class NagiosVCellMonitor method checkVCell.

private CheckResults checkVCell(VCELL_CHECK_LEVEL checkLevel, String rmiHostName, int rmiPort, String rmiBootstrapStubName, String vcellNagiosPassword, int criticalTimeout, int monitorPort) throws Exception {
    SimulationStatusPersistent lastSimStatus = null;
    String vcellVersion = null;
    TreeMap<VCELL_CHECK_LEVEL, Long> levelTimesMillisec = new TreeMap<NagiosVCellMonitor.VCELL_CHECK_LEVEL, Long>();
    long startTime = System.currentTimeMillis();
    VCellConnection vcellConnection = null;
    try {
        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());
        }
        vcellVersion = vcellBootstrap.getVCellSoftwareVersion();
        levelTimesMillisec.put(VCELL_CHECK_LEVEL.RMI_ONLY_0, System.currentTimeMillis() - startTime);
        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");
            }
            UserLoginInfo userLoginInfo = new UserLoginInfo(VCELL_NAGIOS_USER, new DigestedPassword(vcellNagiosPassword));
            vcellConnection = vcellBootstrap.getVCellConnection(userLoginInfo);
            levelTimesMillisec.put(VCELL_CHECK_LEVEL.CONNECT_1, System.currentTimeMillis() - startTime - levelTimesMillisec.get(VCELL_CHECK_LEVEL.RMI_ONLY_0));
            if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.INFOS_2.ordinal()) {
                VCInfoContainer vcInfoContainer = vcellConnection.getUserMetaDbServer().getVCInfoContainer();
                levelTimesMillisec.put(VCELL_CHECK_LEVEL.INFOS_2, System.currentTimeMillis() - startTime - levelTimesMillisec.get(VCELL_CHECK_LEVEL.CONNECT_1));
                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 (userLoginInfo.getUserName().equals(bioModelInfo.getVersion().getOwner().getName()) && 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();
                    levelTimesMillisec.put(VCELL_CHECK_LEVEL.LOAD_3, System.currentTimeMillis() - startTime - levelTimesMillisec.get(VCELL_CHECK_LEVEL.INFOS_2));
                    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);
                        levelTimesMillisec.put(VCELL_CHECK_LEVEL.DATA_4, System.currentTimeMillis() - startTime - levelTimesMillisec.get(VCELL_CHECK_LEVEL.LOAD_3));
                        if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.RUN_5.ordinal()) {
                            KeyValue copy1Key = null;
                            KeyValue copy2Key = null;
                            VCSimulationIdentifier testRunSimID = 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 + "_rmi" + rmiPort + "_siteprt" + monitorPort;
                                boolean bForceCleanup = true;
                                while (true) {
                                    boolean bMessy = false;
                                    for (BioModelInfo bioModelInfo : vcInfoContainer.getBioModelInfos()) {
                                        if (userLoginInfo.getUserName().equals(bioModelInfo.getVersion().getOwner().getName()) && bioModelInfo.getVersion().getName().equals(copyModelName)) {
                                            bMessy = true;
                                            if (bForceCleanup) {
                                                try {
                                                    vcellConnection.getUserMetaDbServer().deleteBioModel(bioModelInfo.getVersion().getVersionKey());
                                                } catch (Exception e) {
                                                    e.printStackTrace();
                                                }
                                            } else {
                                                throw new MessyTestEnvironmentException("Messy test environment, not expecting " + copyModelName + " and couldn't cleanup");
                                            }
                                        }
                                    }
                                    if (!bMessy) {
                                        break;
                                    }
                                    // get new vcInfoContainer without cleaned-up model
                                    vcInfoContainer = vcellConnection.getUserMetaDbServer().getVCInfoContainer();
                                    bForceCleanup = false;
                                }
                                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());
                                }
                                testRunSimID = new VCSimulationIdentifier(newSimulation.getVersion().getVersionKey(), copyBioModel.getVersion().getOwner());
                                vcellConnection.getSimulationController().startSimulation(testRunSimID, 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(testRunSimID);
                                        vcellConnection.getMessageEvents();
                                        break;
                                    }
                                    simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(newSimulation.getVersion().getVersionKey());
                                    if (simulationStatus != null && !simulationStatus.toString().equals((lastSimStatus == null ? null : lastSimStatus.toString()))) {
                                        lastSimStatus = simulationStatus;
                                    }
                                    if (simulationStatus != null && simulationStatus.isFailed()) {
                                        throw new Exception("time " + ((System.currentTimeMillis() - startTime) / 1000) + ", Sim execution failed key:" + testRunSimID.getSimulationKey() + " sim " + newSimulation.getName() + " model " + copyBioModel.getVersion().getName() + " messg " + simulationStatus.getFailedMessage());
                                    }
                                    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();
                                }
                                if (testRunSimID != null) {
                                    deleteSimData(testRunSimID);
                                }
                            }
                            levelTimesMillisec.put(VCELL_CHECK_LEVEL.RUN_5, System.currentTimeMillis() - startTime - levelTimesMillisec.get(VCELL_CHECK_LEVEL.DATA_4));
                        }
                    }
                }
            }
        }
        return new CheckResults(vcellVersion, levelTimesMillisec, lastSimStatus, System.currentTimeMillis() - startTime, null);
    } catch (Exception e) {
        return new CheckResults(vcellVersion, levelTimesMillisec, lastSimStatus, System.currentTimeMillis() - startTime, e);
    } finally {
        vcellConnection = null;
    }
}
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) TreeMap(java.util.TreeMap) SimulationContext(cbit.vcell.mapping.SimulationContext) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) IOException(java.io.IOException) 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)

Example 5 with VCellConnection

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

the class LoginChecker method attemptLogin.

private static boolean attemptLogin(SiteInfo si, String user, String password) {
    long start = 0;
    try {
        if (VERBOSE) {
            start = System.currentTimeMillis();
        }
        String url = si.bootStrapUrl();
        VCellBootstrap vcellBootstrap = (VCellBootstrap) java.rmi.Naming.lookup(url);
        DigestedPassword dp = new UserLoginInfo.DigestedPassword(password);
        UserLoginInfo uli = new UserLoginInfo(user, dp);
        VCellConnection vcellConnection = vcellBootstrap.getVCellConnection(uli);
        if (vcellConnection == null) {
            if (VERBOSE) {
                System.out.println("no connection on " + si + " in " + elapsed(start) + " seconds");
            }
            return false;
        }
        UserMetaDbServer dataServer = vcellConnection.getUserMetaDbServer();
        @SuppressWarnings("unused") BioModelInfo[] bmi = dataServer.getBioModelInfos(true);
        if (VERBOSE) {
            System.out.println("success on " + si + " in " + elapsed(start) + " seconds");
        }
        return true;
    } catch (MalformedURLException e) {
        e.printStackTrace();
        throw new Error("bad code");
    } catch (Exception e) {
        if (VERBOSE) {
            System.out.println("failed in " + elapsed(start) + " seconds");
        }
        e.printStackTrace();
        return false;
    }
}
Also used : VCellConnection(cbit.vcell.server.VCellConnection) UserMetaDbServer(cbit.vcell.server.UserMetaDbServer) MalformedURLException(java.net.MalformedURLException) VCellBootstrap(cbit.vcell.server.VCellBootstrap) BioModelInfo(org.vcell.util.document.BioModelInfo) DigestedPassword(org.vcell.util.document.UserLoginInfo.DigestedPassword) MalformedURLException(java.net.MalformedURLException) UserLoginInfo(org.vcell.util.document.UserLoginInfo)

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