/// <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)); } }
public UnitProcess(string clientId, int clientNum, string sshPath, string sshArgs, string hostName, string sharePath, string shareName, string startDir, Dictionary <string, string> envs) { 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 = sshArgs + ' ' + hostName + " '" + clientProcPath + "' --id=" + clientId + " --num=" + clientNum + envStr + " '--startdir=" + (startDir == null ? runDir : startDir) + "' '--driver=tcp://" + Util.IPAddressString + ':' + Util.DriverPort + '/' + CommConstants.DriverService + "' '--bbServer=" + bbServer + "' " + clientPort; try { lock (((ICollection)ProcessIDMap).SyncRoot) { ProcessIDMap[clientId] = m_clientEvent; } if (!Util.StartProcess(sshPath, remoteArgs, Util.LogFile == null, null, false, false, false, out m_process)) { throw new AssertionException("Failed to start the client."); } 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_sshPath = sshPath; m_sshArgs = sshArgs; 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 remote shell: {3}{0}" + "\tException: {4}", Environment.NewLine, clientProcPath, hostName, sshPath, ex)); } }