/// <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); }
/// <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)); } }