private RemoteHostPool CreatePool(
            DeploymentIdentifier deploymentIdentifier,
            List <IDisposable> blockLinks,
            IServiceDiscoverySource discoverySource)
        {
            var result = _remoteHostPoolFactory.Create(deploymentIdentifier, 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);
        }
 public ConfigDiscoverySource(DeploymentIdentifier deployment, Func <DiscoveryConfig> getConfig, ILog log) : base(deployment.ServiceName)
 {
     _serviceDiscoveryConfig = getConfig().Services[deployment.ServiceName];
     Log    = log;
     Result = new EndPointsResult {
         EndPoints = GetEndPointsInitialValue()
     };
 }
示例#3
0
 public LocalDiscoverySource(DeploymentIdentifier deploymentIdentifier) : base($"{CurrentApplicationInfo.HostName}-{deploymentIdentifier.ServiceName}")
 {
     Result = new EndPointsResult {
         EndPoints = new[] { new EndPoint {
                                 HostName = CurrentApplicationInfo.HostName
                             } }
     };
 }
        private async Task <IServiceDiscoverySource> GetDiscoverySource(DeploymentIdentifier deploymentIdentifier, ServiceDiscoveryConfig config)
        {
            var source = _serviceDiscoveryLoader.GetDiscoverySource(deploymentIdentifier, config);

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

            return(source);
        }
        public static string GetDeploymentName(DeploymentIdentifier deploymentIdentifier, ServiceDiscoveryConfig serviceDiscoverySettings)
        {
            if (serviceDiscoverySettings.Scope == ServiceScope.Zone)
            {
                return(deploymentIdentifier.ServiceName);
            }

            return(deploymentIdentifier.GetConsulServiceName());
        }
示例#6
0
        public IServiceDiscoverySource GetDiscoverySource(DeploymentIdentifier deploymentIdentifier, ServiceDiscoveryConfig serviceDiscoveryConfig)
        {
            var source = _getSources(deploymentIdentifier).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(DeploymentIdentifier deploymentIdentifier,
                                     IDateTime dateTime,
                                     Func <DiscoveryConfig> getConfig,
                                     Func <string, IConsulClient> getConsulClient, ILog log)
            : base(GetDeploymentName(deploymentIdentifier, getConfig().Services[deploymentIdentifier.ServiceName]))

        {
            DateTime         = dateTime;
            _getConsulClient = getConsulClient;
            _log             = log;

            _firstResultInitialized = new TaskCompletionSource <bool>();
        }
        public ServiceDiscovery(string serviceName,
                                ReachabilityChecker reachabilityChecker,
                                IRemoteHostPoolFactory remoteHostPoolFactory,
                                IDiscoverySourceLoader serviceDiscoveryLoader,
                                IEnvironment environment,
                                ISourceBlock <DiscoveryConfig> configListener,
                                Func <DiscoveryConfig> discoveryConfigFactory,
                                ILog log)
        {
            Log                    = log;
            _serviceName           = serviceName;
            _originatingDeployment = new DeploymentIdentifier(serviceName, environment.DeploymentEnvironment, environment);
            _masterDeployment      = new DeploymentIdentifier(serviceName, MASTER_ENVIRONMENT, environment);

            _reachabilityChecker    = reachabilityChecker;
            _remoteHostPoolFactory  = remoteHostPoolFactory;
            _serviceDiscoveryLoader = serviceDiscoveryLoader;

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