private RemoteHostPool GetRelevantPool()
        {
            lock (_locker)
            {
                bool shouldFallBack = MasterEnvironmentPool != null &&
                                      !OriginatingEnvironmentPool.IsServiceDeploymentDefined;

                RemoteHostPool newActivePool = shouldFallBack ? MasterEnvironmentPool : OriginatingEnvironmentPool;

                if (newActivePool != _activePool)
                {
                    Log.Info(x => x("Discovery host pool has changed", unencryptedTags: new { serviceName = _serviceName, previousPool = _activePool.ServiceDeployment.ToString(), newPool = newActivePool.ServiceDeployment.ToString() }));
                    _activePool = newActivePool;
                    FireEndPointChange();

                    if (shouldFallBack)
                    {
                        OriginatingEnvironmentPool.DeactivateMetrics();
                    }
                    else
                    {
                        MasterEnvironmentPool?.DeactivateMetrics();
                    }
                }

                return(_activePool);
            }
        }
Example #2
0
        private RemoteHostPool GetRelevantPool()
        {
            lock (_locker)
            {
                bool shouldFallBack = MasterEnvironmentPool != null &&
                                      !OriginatingEnvironmentPool.IsServiceDeploymentDefined;

                RemoteHostPool newActivePool = shouldFallBack ? MasterEnvironmentPool : OriginatingEnvironmentPool;

                if (newActivePool != _activePool)
                {
                    _activePool = newActivePool;

                    FireEndPointChange();

                    if (shouldFallBack)
                    {
                        OriginatingEnvironmentPool.DeactivateMetrics();
                    }
                    else
                    {
                        MasterEnvironmentPool?.DeactivateMetrics();
                    }
                }

                return(_activePool);
            }
        }
        private void RemoveMasterPool()
        {
            if (_activePool == MasterEnvironmentPool)
            {
                _activePool = null;
            }

            MasterEnvironmentPool?.Dispose();
            MasterEnvironmentPool = null;
            _masterEnvironmentLinks.ForEach(x => x?.Dispose());
            _masterEnvironmentLinks = new List <IDisposable>();
        }
        private void RemoveOriginatingPool()
        {
            if (_activePool == OriginatingEnvironmentPool)
            {
                _activePool = null;
            }

            OriginatingEnvironmentPool?.Dispose();
            OriginatingEnvironmentPool = null;
            _originatingEnvironmentLinks.ForEach(x => x?.Dispose());
            _originatingEnvironmentLinks = new List <IDisposable>();
        }
Example #5
0
        private async Task ReloadRemoteHost(DiscoveryConfig newConfig)
        {
            var newServiceConfig = newConfig.Services[_serviceName];

            lock (_locker)
            {
                if (newServiceConfig.Equals(LastServiceConfig) &&
                    newConfig.EnvironmentFallbackEnabled == LastConfig.EnvironmentFallbackEnabled)
                {
                    return;
                }
            }

            var shouldCreateMasterPool = newConfig.EnvironmentFallbackEnabled &&
                                         newServiceConfig.SupportsFallback &&
                                         _originatingDeployment.Equals(_masterDeployment) == false;

            ServiceDiscoverySourceBase masterSource = null;

            var originatingSource = await GetServiceDiscoverySource(_originatingDeployment, newServiceConfig).ConfigureAwait(false);

            if (shouldCreateMasterPool)
            {
                masterSource = await GetServiceDiscoverySource(_masterDeployment, newServiceConfig).ConfigureAwait(false);
            }

            lock (_locker)
            {
                _suppressNotifications = true;

                LastConfig        = newConfig;
                LastServiceConfig = newServiceConfig;

                RemoveOriginatingPool();
                OriginatingEnvironmentPool = CreatePool(_originatingDeployment, _originatingEnvironmentLinks, originatingSource);

                RemoveMasterPool();

                if (masterSource != null)
                {
                    MasterEnvironmentPool = CreatePool(_masterDeployment, _masterEnvironmentLinks, masterSource);
                }

                _suppressNotifications = false;

                GetRelevantPool();
            }
        }