private RemoteHostPool CreatePool(
            ServiceDeployment serviceDeployment,
            List <IDisposable> blockLinks,
            IServiceDiscoverySource discoverySource)
        {
            var result = _remoteHostPoolFactory.Create(serviceDeployment, discoverySource, _reachabilityChecker);

            var dispose = result.EndPointsChanged.LinkTo(new ActionBlock <EndPointsResult>(m =>
            {
                if (result == MasterEnvironmentPool || result == OriginatingEnvironmentPool)
                {
                    FireEndPointChange();
                }
            }));

            blockLinks.Add(dispose);

            dispose = result.ReachabilitySource.LinkTo(new ActionBlock <ServiceReachabilityStatus>(x =>
            {
                if (result == _activePool && !_suppressNotifications)
                {
                    _reachabilityChanged.Post(x);
                }
            }));
            blockLinks.Add(dispose);



            return(result);
        }
        private async Task <IServiceDiscoverySource> GetDiscoverySource(ServiceDeployment serviceDeployment, ServiceDiscoveryConfig config)
        {
            var source = _serviceDiscoveryLoader.GetDiscoverySource(serviceDeployment, config);

            await source.Init().ConfigureAwait(false);

            return(source);
        }
示例#3
0
 public static string GetDeploymentName(ServiceDeployment serviceDeployment, ServiceDiscoveryConfig serviceDiscoverySettings)
 {
     if (serviceDiscoverySettings.Scope == ServiceScope.DataCenter)
     {
         return(serviceDeployment.ServiceName);
     }
     return($"{serviceDeployment.ServiceName}-{serviceDeployment.DeploymentEnvironment}");
 }
示例#4
0
 public ConfigDiscoverySource(ServiceDeployment deployment, Func <DiscoveryConfig> getConfig, ILog log) : base(deployment.ServiceName)
 {
     _serviceDiscoveryConfig = getConfig().Services[deployment.ServiceName];
     Log    = log;
     Result = new EndPointsResult {
         EndPoints = GetEndPointsInitialValue()
     };
 }
 public LocalDiscoverySource(ServiceDeployment serviceDeployment) : base($"{CurrentApplicationInfo.HostName}-{serviceDeployment.ServiceName}")
 {
     Result = new EndPointsResult {
         EndPoints = new[] { new EndPoint {
                                 HostName = CurrentApplicationInfo.HostName
                             } }
     };
 }
示例#6
0
        private async Task <ServiceDiscoverySourceBase> GetServiceDiscoverySource(ServiceDeployment serviceDeployment, ServiceDiscoveryConfig config)
        {
            var discoverySource = _discoverySourceLoader.GetDiscoverySource(serviceDeployment, config);

            // TODO: RemoteHostPool should either deal with uninitialized source or request different class which represents initialized source
            await discoverySource.InitCompleted.ConfigureAwait(false);

            return(discoverySource);
        }
示例#7
0
        public ConsulDiscoverySource(ServiceDeployment serviceDeployment,
                                     Func <DiscoveryConfig> getConfig,
                                     Func <string, IConsulClient> getConsulClient, ILog log)
            : base(GetDeploymentName(serviceDeployment, getConfig().Services[serviceDeployment.ServiceName]))

        {
            _getConsulClient = getConsulClient;
            _log             = log;

            _initialized = new TaskCompletionSource <bool>();
        }
示例#8
0
        public IServiceDiscoverySource GetDiscoverySource(ServiceDeployment serviceDeployment, ServiceDiscoveryConfig serviceDiscoveryConfig)
        {
            var source = _getSources(serviceDeployment).FirstOrDefault(f => f.SourceName.Equals(serviceDiscoveryConfig.Source, StringComparison.InvariantCultureIgnoreCase));

            if (source == null)
            {
                throw new ConfigurationException($"Discovery Source '{serviceDiscoveryConfig.Source}' is not supported.");
            }

            return(source);
        }
        public ConsulDiscoverySource(ServiceDeployment serviceDeployment,
                                     ServiceDiscoveryConfig serviceDiscoveryConfig,
                                     IConsulClient consulClient,
                                     IDateTime dateTime, ILog log)
            : base(GetDeploymentName(serviceDeployment, serviceDiscoveryConfig))

        {
            ConsulClient  = consulClient;
            _config       = serviceDiscoveryConfig;
            _dateTime     = dateTime;
            _log          = log;
            ShutdownToken = new CancellationTokenSource();
            Task.Run(() => RefreshHostForever(ShutdownToken.Token));
            _initialized = Task.Run(Load); // Must be run in Task.Run() because of incorrect Orleans scheduling
        }
        public ServiceDiscoverySourceBase GetDiscoverySource(ServiceDeployment serviceDeployment, ServiceDiscoveryConfig serviceDiscoverySettings)
        {
            switch (serviceDiscoverySettings.Source)
            {
            case DiscoverySource.Config:
                return(_getConfigDiscoverySource(serviceDeployment.ServiceName, serviceDiscoverySettings));

            case DiscoverySource.Consul:
                return(_getConsulDiscoverySource(serviceDeployment, serviceDiscoverySettings));

            case DiscoverySource.Local:
                return(new LocalDiscoverySource(serviceDeployment.ServiceName));
            }

            throw new ConfigurationException($"Source '{serviceDiscoverySettings.Source}' is not supported by any configuration.");
        }
示例#11
0
        public ServiceDiscovery(string serviceName,
                                ReachabilityChecker reachabilityChecker,
                                IRemoteHostPoolFactory remoteHostPoolFactory,
                                IDiscoverySourceLoader discoverySourceLoader,
                                IEnvironmentVariableProvider environmentVariableProvider,
                                ISourceBlock <DiscoveryConfig> configListener,
                                Func <DiscoveryConfig> discoveryConfigFactory)
        {
            _serviceName           = serviceName;
            _originatingDeployment = new ServiceDeployment(serviceName, environmentVariableProvider.DeploymentEnvironment);
            _masterDeployment      = new ServiceDeployment(serviceName, MASTER_ENVIRONMENT);

            _reachabilityChecker   = reachabilityChecker;
            _remoteHostPoolFactory = remoteHostPoolFactory;
            _discoverySourceLoader = discoverySourceLoader;

            // Must be run in Task.Run() because of incorrect Orleans scheduling
            _initTask        = Task.Run(() => ReloadRemoteHost(discoveryConfigFactory()));
            _configBlockLink = configListener.LinkTo(new ActionBlock <DiscoveryConfig>(ReloadRemoteHost));
        }