Пример #1
0
 private bool Equals(LocalProcess other)
 {
     return(string.Equals(AgentType, other.AgentType,
                          StringComparison.InvariantCultureIgnoreCase) &&
            string.Equals(ExecutablePath, other.ExecutablePath,
                          StringComparison.InvariantCultureIgnoreCase) &&
            string.Equals(CommandLineArguments, other.CommandLineArguments,
                          StringComparison.InvariantCultureIgnoreCase) &&
            string.Equals(HostName, other.HostName,
                          StringComparison.InvariantCultureIgnoreCase) &&
            Port == other.Port && Equals(ServiceNames, other.ServiceNames));
 }
        private IEnumerable <LocalProcess> GetManagedProcesses(
            AgentConfiguration agentConfiguration)
        {
            if (agentConfiguration.Ports == null || agentConfiguration.Ports.Count == 0)
            {
                // No ports specified, use ephemeral ports
                agentConfiguration.Ports =
                    new List <int>(Enumerable.Repeat(-1, agentConfiguration.ProcessCount));
            }

            if (agentConfiguration.Ports.Count != agentConfiguration.ProcessCount)
            {
                throw new ArgumentException(
                          "Number of ports must correspond to process count or be zero for ephemeral port usage");
            }

            for (int i = 0; i < agentConfiguration.ProcessCount; i++)
            {
                string hostName = agentConfiguration.HostName;
                int    port     = agentConfiguration.Ports[i];

                ChannelCredentials credentials =
                    GrpcUtils.CreateChannelCredentials(agentConfiguration.UseTls,
                                                       agentConfiguration.ClientCertificate);

                var managedProcess = new LocalProcess(agentConfiguration.AgentType,
                                                      agentConfiguration.ExecutablePath, agentConfiguration.CommandLineArguments,
                                                      hostName, port, credentials)
                {
                    EnvironmentVariables   = agentConfiguration.EnvironmentVariables,
                    ClusterShutdownAction  = agentConfiguration.ClusterShutdownAction,
                    RecyclingIntervalHours = GetRandomizedRecyclingInterval(agentConfiguration),
                    StartupWaitSeconds     = agentConfiguration.StartupWaitSeconds
                };

                if (agentConfiguration.ServiceNames != null)
                {
                    foreach (string serviceName in agentConfiguration.ServiceNames)
                    {
                        managedProcess.ServiceNames.Add(serviceName);
                    }
                }

                _logger.LogInformation(
                    "Agent has been configured with recycling interval {recyclingHours:F3}h. Process details: {process}",
                    managedProcess.RecyclingIntervalHours, managedProcess);

                yield return(managedProcess);
            }
        }