Exemplo n.º 1
0
        public LoadBalancingService(IConfiguration configuration)
        {
            KnownAgents.Configure(configuration);

            _loadBalancerConfig = new LoadBalancerConfig();
            configuration.GetSection(nameof(LoadBalancerConfig)).Bind(_loadBalancerConfig);

            if (string.IsNullOrEmpty(_loadBalancerConfig.HostName))
            {
                _logger.LogWarning("Invalid configuration: Hostname is null.");
            }
        }
Exemplo n.º 2
0
        private static async Task <IKeyValueStore> TryGetEtcdKeyValueStore()
        {
            foreach (var kvsAgent in KnownAgents.Get(WellKnownAgentType.KeyValueStore))
            {
                IKeyValueStore keyValueStore = await EtcdKeyValueStore.TryConnectAsync(kvsAgent);

                if (keyValueStore != null)
                {
                    return(keyValueStore);
                }
            }

            // Do not just try the default address - Etcd might be running with a different purpose

            return(null);
        }
        private void ConfigureEnvironment(IConfiguration configuration)
        {
            _logger.LogInformation("Configuring cluster agents...");

            KnownAgents.ConfigureAgents(configuration);

            if (_clusterConfig == null)
            {
                _clusterConfig = new ClusterConfig();
            }

            configuration.GetSection(nameof(ClusterConfig)).Bind(_clusterConfig);

            if (_cluster != null)
            {
                ConfigureClusterAgents();
            }
        }
Exemplo n.º 4
0
        private async Task <ServiceRegistry> CreateServiceRegistryAsync()
        {
            Stopwatch watch = Stopwatch.StartNew();

            IKeyValueStore keyValueStore = await TryGetEtcdKeyValueStore();

            List <AgentConfiguration> serviceAgents = new List <AgentConfiguration>();

            if (keyValueStore != null)
            {
                _logger.LogInformation("Connected to distributed key-value store in {millis}ms",
                                       watch.ElapsedMilliseconds);
            }
            else
            {
                _logger.LogWarning(
                    "Unable to connect to distributed key-value store. Using Worker agents from configuration:");

                keyValueStore = new LocalKeyValueStore();

                _keyValueStoreIsLocal = true;

                serviceAgents.AddRange(KnownAgents.Get(WellKnownAgentType.Worker));
            }

            ServiceRegistry serviceRegistry = new ServiceRegistry(keyValueStore, string.Empty);

            AddServices(serviceRegistry, serviceAgents);

            int endpointCount = serviceRegistry.GetTotalEndpointCount(out var serviceCount);

            _logger.LogInformation(
                "Service registry contains {serviceCount} service type(s) at {endpointCount} " +
                "different endpoints.", serviceCount, endpointCount);

            return(serviceRegistry);
        }