コード例 #1
0
        public override ClientBase CreateNew(string clientId)
        {
            UnitProcess newProc;

            if (clientId == null)
            {
                clientId = GetClientId().ToString();
            }
            if (m_sshPath != null)
            {
                int clientPort = GetClientPort();
                m_clientEvent.Reset();
                lock (((ICollection)ProcessIDMap).SyncRoot)
                {
                    ProcessIDMap[clientId] = m_clientEvent;
                }
                if (!m_clientComm.CreateNew(clientId, clientPort))
                {
                    throw new AssertionException("FATAL: Could not start client: " +
                                                 ClientProcName);
                }

                if (!m_clientEvent.WaitOne(MaxStartWaitMillis, false))
                {
                    throw new AssertionException("FATAL: Timed out waiting for client to start: " +
                                                 ClientProcName);
                }
                newProc              = new UnitProcess(clientId);
                newProc.m_sshPath    = m_sshPath;
                newProc.m_sshArgs    = m_sshArgs;
                newProc.m_hostName   = m_hostName;
                newProc.m_clientComm = ServerConnection <IClientComm> .Connect("tcp://" +
                                                                               m_hostName + ':' + clientPort + '/' + CommConstants.ClientService);

                newProc.m_process   = newProc.m_clientComm.GetClientProcess();
                newProc.m_timeout   = false;
                newProc.m_exiting   = false;
                newProc.m_sharePath = m_sharePath;
                newProc.m_shareName = m_shareName;
                newProc.m_startDir  = m_startDir;
                newProc.m_envs      = m_envs;
            }
            else
            {
                newProc = new UnitProcess(clientId, m_startDir);
            }
            return(newProc);
        }
コード例 #2
0
        /// <summary>
        /// If not already created, Create a launcher process on the remote host using
        /// psexec. This launcher is used to launch the FwkClients on the host.
        /// </summary>
        private static UnitProcess CreateLauncherUsingPsexec(string clientId,
                                                             string psexecPath, string psexecArgs, string hostName,
                                                             string sharePath, string shareName, string startDir,
                                                             int launcherPort, string logPath)
        {
            if (clientId != null)
            {
                string      clientProcPath = "FwkLauncher.exe";
                string      clientsCmd     = string.Empty;
                string      runDir         = null;
                bool        newProcCreated = false;
                UnitProcess unitProc;
                Process     proc = null;

                try
                {
                    lock (((ICollection)ProcessIDMap).SyncRoot)
                    {
                        unitProc = new UnitProcess(clientId);
                        ProcessIDMap[clientId] = unitProc.m_clientEvent;
                    }
                    if (launcherPort == 0) // i.e. launcher is not running
                    {
                        launcherPort = GetClientPort();

                        if (sharePath != null)
                        {
                            runDir         = Util.AssemblyDir.Replace(sharePath.ToLower(), shareName);
                            clientProcPath = runDir + Path.DirectorySeparatorChar + clientProcPath;
                            clientProcPath = clientProcPath.Replace('/', '\\');
                        }
                        clientsCmd = " cmd.exe /C \"\"" + clientProcPath + "\" --id=" + clientId +
                                     " --bg  --port=" + launcherPort + " --driver=\"tcp://" + Util.IPAddressString +
                                     ':' + Util.DriverPort + '/' + CommConstants.DriverService + "\"\"";



                        string psexecAllArgs = psexecArgs + "\\\\" + hostName +
                                               " " + clientsCmd;
                        Util.Log(string.Format("Running remote command: {0} {1}{2}",
                                               psexecPath, Util.HidePsexecPassword(psexecAllArgs), Environment.NewLine));
                        if (!Util.StartProcess(psexecPath, psexecAllArgs, Util.LogFile == null, null,
                                               false, false, false, out proc))
                        {
                            throw new AssertionException("Failed to start the launcher.");
                        }
                        if (!unitProc.m_clientEvent.WaitOne(90000, false))
                        {
                            throw new AssertionException("Timed out waiting for launcher: " +
                                                         clientId);
                        }
                        newProcCreated = true;
                    }

                    unitProc.m_clientComm = (IClientComm)ServerConnection <IClientCommV2> .Connect("tcp://" +
                                                                                                   hostName + ':' + launcherPort + '/' + CommConstants.ClientService);

                    unitProc.m_process = unitProc.m_clientComm.GetClientProcess();

                    unitProc.m_psexecPath = psexecPath;
                    unitProc.m_psexecArgs = psexecArgs;
                    unitProc.m_hostName   = hostName;
                    unitProc.m_timeout    = false;
                    unitProc.m_exiting    = false;
                    unitProc.m_sharePath  = sharePath;
                    unitProc.m_shareName  = shareName;
                    unitProc.m_startDir   = startDir;
                    if (newProcCreated)
                    {
                        logPath += "/" + "Launcher" + "_" + hostName + "_" + clientId + ".log";
                        Util.Log("Launcher log path {0}", logPath);

                        unitProc.SetLogLevel(Util.CurrentLogLevel);
                        unitProc.SetLogFile(logPath);
                    }
                }
                catch (Exception ex)
                {
                    throw new AssertionException(string.Format("FATAL: Could not start " +
                                                               "launcher: {1}{0}\ton host: {2}{0}" +
                                                               "\tException: {3}", Environment.NewLine, clientProcPath, hostName,
                                                               ex));
                }
                return(unitProc);
            }
            return(null);
        }
コード例 #3
0
        /// <summary>
        /// Create clients on the remote host using FwkLauncher.
        /// </summary>
        public static List <UnitProcess> CreateClientsUsingLauncher(List <string> clientIds,
                                                                    int startClientNum, string psexecPath, string psexecArgs, string hostName,
                                                                    string sharePath, string shareName, string startDir,
                                                                    Dictionary <string, string> envs, int launcherPort,
                                                                    Dictionary <string, UnitProcess> launcherProcesses, string logPath)
        {
            if (clientIds != null && clientIds.Count > 0)
            {
                UnitProcess launcherProcess = null;
                if (!launcherProcesses.ContainsKey(hostName))
                {
                    launcherProcess = CreateLauncherUsingPsexec(GetClientId().ToString(), psexecPath, psexecArgs,
                                                                hostName, sharePath, shareName, startDir, launcherPort, logPath);
                    launcherProcesses.Add(hostName, launcherProcess);
                }
                else
                {
                    launcherProcess = launcherProcesses[hostName];
                }


                string clientProcPath = ClientProcName;
                string runDir         = null;
                string clientId;

                List <UnitProcess> unitProcs = new List <UnitProcess>();

                if (sharePath != null)
                {
                    runDir         = Util.AssemblyDir.Replace(sharePath.ToLower(), shareName);
                    clientProcPath = runDir + Path.DirectorySeparatorChar + ClientProcName;
                    clientProcPath = clientProcPath.Replace('\\', '/');
                }

                string envStr = string.Empty;

                if (envs != null)
                {
                    foreach (KeyValuePair <string, string> envNameValue in envs)
                    {
                        string envValue = envNameValue.Value.Replace(sharePath, shareName);
                        envStr += " --env:" + envNameValue.Key + "=\"" + envValue + '\"';
                    }
                }
                List <int> clientPorts = new List <int>();


                try
                {
                    for (int i = 0; i < clientIds.Count; i++, startClientNum++)
                    {
                        string clientsCmd = string.Empty;
                        int    clientPort = GetClientPort();
                        clientId = clientIds[i];
                        if (clientId == null)
                        {
                            clientId     = GetClientId().ToString();
                            clientIds[i] = clientId;
                        }
                        string bbServer;
                        if (Util.ExternalBBServer != null)
                        {
                            bbServer = Util.ExternalBBServer;
                        }
                        else
                        {
                            bbServer = "tcp://" + Util.IPAddressString + ':' + Util.DriverPort +
                                       '/' + CommConstants.BBService;
                        }
                        clientsCmd = "  --id=" + clientId +
                                     " --num=" + startClientNum + envStr + " --startdir=\"" +
                                     (startDir == null ? runDir : startDir) + "\" --driver=\"tcp://" +
                                     Util.IPAddressString + ':' + Util.DriverPort + '/' +
                                     CommConstants.DriverService + "\" --bbServer=\"" + bbServer +
                                     "\" " + clientPort;
                        clientPorts.Add(clientPort);
                        IClientCommV2 clientComm = launcherProcess.m_clientComm as IClientCommV2;
                        Process       proc;
                        UnitProcess   unitProc;
                        unitProc = new UnitProcess(clientId);
                        lock (((ICollection)ProcessIDMap).SyncRoot)
                        {
                            ProcessIDMap[clientId] = unitProc.m_clientEvent;
                            unitProcs.Add(unitProc);
                        }
                        if (!clientComm.LaunchNewClient(clientProcPath, clientsCmd, out proc))
                        {
                            throw new AssertionException("Failed to start client: " +
                                                         clientId);
                        }
                        unitProc.m_process = proc;
                    }

                    for (int i = 0; i < clientIds.Count; i++)
                    {
                        clientId = clientIds[i];
                        UnitProcess unitProc = (UnitProcess)unitProcs[i];
                        if (!unitProc.m_clientEvent.WaitOne(MaxStartWaitMillis, false))
                        {
                            throw new AssertionException("Timed out waiting for client: " +
                                                         clientId);
                        }

                        unitProc.m_clientComm = ServerConnection <IClientComm> .Connect("tcp://" +
                                                                                        hostName + ':' + clientPorts[i] + '/' + CommConstants.ClientService);

                        unitProc.m_process    = unitProc.m_clientComm.GetClientProcess();
                        unitProc.m_psexecPath = psexecPath;
                        unitProc.m_psexecArgs = psexecArgs;
                        unitProc.m_hostName   = hostName;
                        unitProc.m_timeout    = false;
                        unitProc.m_exiting    = false;
                        unitProc.m_sharePath  = sharePath;
                        unitProc.m_shareName  = shareName;
                        unitProc.m_startDir   = startDir;
                        unitProc.m_envs       = envs;
                    }
                }
                catch (Exception ex)
                {
                    unitProcs.Clear();
                    unitProcs = null;
                    clientPorts.Clear();
                    clientPorts = null;
                    throw new AssertionException(string.Format("FATAL: Could not start " +
                                                               "client: {1}{0}\ton host: {2}{0}\tusing: FwkLauncher{0}" +
                                                               "\tException: {3}", Environment.NewLine, clientProcPath, hostName,
                                                               ex));
                }
                return(unitProcs);
            }

            return(null);
        }
コード例 #4
0
        public static List <UnitProcess> Create(List <string> clientIds,
                                                int startClientNum, string sshPath, string sshArgs, string hostName,
                                                string sharePath, string shareName, string startDir,
                                                Dictionary <string, string> envs)
        {
            if (clientIds != null && clientIds.Count > 0)
            {
                string clientProcPath = ClientProcName;
                string clientsCmd     = string.Empty;
                string runDir         = null;
                string clientId;

                List <UnitProcess> unitProcs = new List <UnitProcess>();
                UnitProcess        unitProc;

                if (sharePath != null)
                {
                    runDir         = Util.AssemblyDir.Replace(sharePath.ToLower(), shareName);
                    clientProcPath = runDir + Path.DirectorySeparatorChar + ClientProcName;
                    clientProcPath = clientProcPath.Replace('\\', '/');
                }

                string envStr = string.Empty;

                if (envs != null)
                {
                    foreach (KeyValuePair <string, string> envNameValue in envs)
                    {
                        string envValue = envNameValue.Value.Replace(sharePath, shareName);
                        envStr += " '--env:" + envNameValue.Key + '=' + envValue + '\'';
                    }
                }
                List <int> clientPorts = new List <int>();
                lock (((ICollection)ProcessIDMap).SyncRoot)
                {
                    for (int i = 0; i < clientIds.Count; i++, startClientNum++)
                    {
                        int clientPort = GetClientPort();
                        clientId = clientIds[i];
                        if (clientId == null)
                        {
                            clientId     = GetClientId().ToString();
                            clientIds[i] = clientId;
                        }
                        string bbServer;
                        if (Util.ExternalBBServer != null)
                        {
                            bbServer = Util.ExternalBBServer;
                        }
                        else
                        {
                            bbServer = "tcp://" + Util.IPAddressString + ':' + Util.DriverPort +
                                       '/' + CommConstants.BBService;
                        }
                        clientsCmd += '\'' + clientProcPath + "' --bg --id=" + clientId +
                                      " --num=" + startClientNum + envStr + " '--startdir=" +
                                      (startDir == null ? runDir : startDir) + "' '--driver=tcp://" +
                                      Util.IPAddressString + ':' + Util.DriverPort + '/' +
                                      CommConstants.DriverService + "' '--bbServer=" + bbServer +
                                      "' " + clientPort + " ; ";
                        clientPorts.Add(clientPort);

                        unitProc = new UnitProcess(clientId);
                        ProcessIDMap[clientId] = unitProc.m_clientEvent;
                        unitProcs.Add(unitProc);
                    }
                }
                try
                {
                    Process proc;
                    //string sshAllArgs = sshArgs + ' ' + hostName +
                    //  " \"" + " NCover.Console.exe //x Coverage.xml //at coverage.trend " + clientsCmd + '"';
                    string sshAllArgs = sshArgs + ' ' + hostName +
                                        " \"" + clientsCmd + '"';
                    Util.RawLog(string.Format("Running remote command: {0} {1}{2}",
                                              sshPath, Util.HideSshPassword(sshAllArgs), Environment.NewLine));
                    if (!Util.StartProcess(sshPath, sshAllArgs, Util.LogFile == null, null,
                                           false, false, false, out proc))
                    {
                        throw new AssertionException("Failed to start the clients.");
                    }

                    for (int i = 0; i < clientIds.Count; i++)
                    {
                        clientId = clientIds[i];
                        unitProc = (UnitProcess)unitProcs[i];
                        if (!unitProc.m_clientEvent.WaitOne(MaxStartWaitMillis, false))
                        {
                            throw new AssertionException("Timed out waiting for client: " +
                                                         clientId);
                        }

                        unitProc.m_clientComm = ServerConnection <IClientComm> .Connect("tcp://" +
                                                                                        hostName + ':' + clientPorts[i] + '/' + CommConstants.ClientService);

                        unitProc.m_process   = unitProc.m_clientComm.GetClientProcess();
                        unitProc.m_sshPath   = sshPath;
                        unitProc.m_sshArgs   = sshArgs;
                        unitProc.m_hostName  = hostName;
                        unitProc.m_timeout   = false;
                        unitProc.m_exiting   = false;
                        unitProc.m_sharePath = sharePath;
                        unitProc.m_shareName = shareName;
                        unitProc.m_startDir  = startDir;
                        unitProc.m_envs      = envs;
                    }
                }
                catch (Exception ex)
                {
                    unitProcs.Clear();
                    unitProcs = null;
                    clientPorts.Clear();
                    clientPorts = null;
                    throw new AssertionException(string.Format("FATAL: Could not start " +
                                                               "client: {1}{0}\ton host: {2}{0}\tusing remote shell: {3}{0}" +
                                                               "\tException: {4}", Environment.NewLine, clientProcPath, hostName,
                                                               sshPath, ex));
                }
                return(unitProcs);
            }
            return(null);
        }
コード例 #5
0
        /// <summary>
        /// Create a UnitProcess object by launching a client using a launcher. The
        /// launcher is launched on the remote host using psexec.
        /// </summary>
        public UnitProcess(string clientId, int clientNum, string psexecPath,
                           string psexecArgs, string hostName, string sharePath, string shareName,
                           string startDir, Dictionary <string, string> envs,
                           int launcherPort, Dictionary <string, UnitProcess> launcherProcesses, string logPath)
        {
            UnitProcess launcherProcess = null;

            if (!launcherProcesses.ContainsKey(hostName))
            {
                launcherProcess = CreateLauncherUsingPsexec(GetClientId().ToString(),
                                                            psexecPath, psexecArgs, hostName, sharePath, shareName, startDir,
                                                            launcherPort, logPath);
                launcherProcesses.Add(hostName, launcherProcess);
            }
            else
            {
                launcherProcess = launcherProcesses[hostName];
            }

            string clientProcPath = ClientProcName;
            string remoteArgs;
            string runDir = null;

            if (sharePath != null)
            {
                runDir         = Util.AssemblyDir.Replace(sharePath.ToLower(), shareName);
                clientProcPath = runDir + Path.DirectorySeparatorChar + ClientProcName;
                clientProcPath = clientProcPath.Replace('/', '\\');
            }

            int clientPort = GetClientPort();

            if (clientId == null)
            {
                clientId = GetClientId().ToString();
            }
            this.ID = clientId;
            string envStr = string.Empty;

            if (envs != null)
            {
                m_envs = envs;
                foreach (KeyValuePair <string, string> envNameValue in envs)
                {
                    string envValue = envNameValue.Value.Replace(sharePath, shareName);
                    envStr += " --env:" + envNameValue.Key + "=\"" + envValue + '\"';
                }
            }
            string bbServer;

            if (Util.ExternalBBServer != null)
            {
                bbServer = Util.ExternalBBServer;
            }
            else
            {
                bbServer = "tcp://" + Util.IPAddressString + ':' + Util.DriverPort +
                           '/' + CommConstants.BBService;
            }
            remoteArgs = " --id=" + clientId + " --num=" + clientNum + envStr +
                         " --startdir=\"" + (startDir == null ? runDir : startDir) +
                         "\" --driver=tcp://" + Util.IPAddressString + ':' + Util.DriverPort +
                         '/' + CommConstants.DriverService + " --bbServer=\"" + bbServer +
                         "\" " + clientPort;
            try
            {
                IClientCommV2 clientComm = launcherProcess.m_clientComm as IClientCommV2;
                Process       proc;
                if (!clientComm.LaunchNewClient(clientProcPath, remoteArgs, out proc))
                {
                    throw new AssertionException("Failed to start client: " +
                                                 clientId);
                }

                m_process = proc;
                lock (((ICollection)ProcessIDMap).SyncRoot)
                {
                    ProcessIDMap[clientId] = m_clientEvent;
                }

                if (!m_clientEvent.WaitOne(MaxStartWaitMillis, false))
                {
                    throw new AssertionException("Timed out waiting for client to start.");
                }

                m_clientComm = ServerConnection <IClientComm> .Connect("tcp://" +
                                                                       hostName + ':' + clientPort + '/' + CommConstants.ClientService);

                m_process = m_clientComm.GetClientProcess();

                m_psexecPath = psexecPath;
                m_psexecArgs = psexecArgs;
                m_hostName   = hostName;
                m_timeout    = false;
                m_exiting    = false;
                m_sharePath  = sharePath;
                m_shareName  = shareName;
                m_startDir   = startDir;
            }
            catch (Exception ex)
            {
                throw new AssertionException(string.Format("FATAL: Could not start " +
                                                           "client: {1}{0}\ton host: {2}{0}\tusing: FwkLauncher{0}" +
                                                           "\tException: {3}", Environment.NewLine, clientProcPath, hostName,
                                                           ex));
            }
        }