コード例 #1
0
 public ResourcesService(
     ILogger <ResourcesService> logger,
     IOptions <BackendConfig> config,
     IResourcesRepo resourcesRepo,
     IStorageRepo storageRepo)
 {
     _logger        = logger;
     _config        = config.Value;
     _resourcesRepo = resourcesRepo;
     _storageRepo   = storageRepo;
 }
コード例 #2
0
 public BackendProberTests()
 {
     // set up all the parameter needed for prober class
     _backendId     = "example service";
     _backendConfig = new BackendConfig(
         healthCheckOptions: new BackendConfig.BackendHealthCheckOptions(
             enabled: true,
             interval: TimeSpan.FromMilliseconds(100),
             timeout: TimeSpan.FromSeconds(60),
             port: 8000,
             path: "/example"),
         loadBalancingOptions: default);
コード例 #3
0
ファイル: WebServerConfig.cs プロジェクト: zacons/CoiniumServ
 public WebServerConfig(dynamic config)
 {
     try
     {
         // load the config data.
         Enabled       = config.enabled;
         BindInterface = string.IsNullOrEmpty(config.bind) ? "127.0.0.1" : config.bind;
         Port          = config.port == 0 ? 80 : config.port;
         Backend       = new BackendConfig(config.backend);
         Valid         = true;
     }
     catch (Exception e)
     {
         Valid = false;
         Log.Logger.ForContext <WebServerConfig>().Error(e, "Error loading web-server configuration");
     }
 }
コード例 #4
0
        public HealthProbeWorkerTests()
        {
            // Set up all the parameter needed for healthProberWorker.
            Provide <IMonotonicTimer, MonotonicTimer>();
            Provide <ILogger, Logger <HealthProbeWorker> >();
            Mock <IProxyHttpClientFactoryFactory>()
            .Setup(f => f.CreateFactory())
            .Returns(new Mock <IProxyHttpClientFactory>().Object);

            // Set up backends. We are going to fake multiple service for us to probe.
            _backendManager = Provide <IBackendManager, BackendManager>();
            _backendConfig  = new BackendConfig(
                healthCheckOptions: new BackendConfig.BackendHealthCheckOptions(
                    enabled: true,
                    interval: TimeSpan.FromSeconds(1),
                    timeout: TimeSpan.FromSeconds(1),
                    port: 8000,
                    path: "/example"),
                loadBalancingOptions: default);
コード例 #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            var configSection = Configuration.GetSection(nameof(BackendConfig));

            if (configSection != null)
            {
                services.Configure <BackendConfig>(configSection);
                BackendConfig = configSection.Get <BackendConfig>();
            }
            else
            {
                throw new System.Exception("Missing configuration for Backend service!");
            }

            // Loading and initializing the resouces repositories
            var repoFactory = new ResourcesRepository.RepositoryFactory(
                BackendConfig.ResourcesConfig.SubscriptionId,
                BackendConfig.ResourcesConfig.ResourceGroupName
                );

            if (!BackendConfig.SecurityConfig.UseMSI)
            {
                repoFactory.ConfigureEnvironment(
                    BackendConfig.SecurityConfig.ClientId,
                    BackendConfig.SecurityConfig.ClientSecret,
                    BackendConfig.SecurityConfig.TenantId);
            }
            else
            {
                repoFactory.ConfigureEnvironment(BackendConfig.SecurityConfig.TenantId);
            }
            services.AddSingleton <ResourcesRepository.Interfaces.IResourcesRepo>(f => {
                var logFac = f.GetService <Microsoft.Extensions.Logging.ILoggerFactory>();
                return(repoFactory.CreateResourcesRepo(logFac));
            });
            services.AddSingleton <ResourcesRepository.Interfaces.IStorageRepo>(f => {
                var logFac = f.GetService <Microsoft.Extensions.Logging.ILoggerFactory>();
                return(repoFactory.CreateStorageRepo(logFac, false));
            });

            // GRPC Stuff
            services.AddGrpc();
        }
コード例 #6
0
        public long Register <T>(BackendConfig <T> backendConfig)
        {
            if (backendConfig == null)
            {
                throw new ArgumentNullException(nameof(backendConfig));
            }

            long maxTag = -1;

            foreach (long existingTag in _registeredBackendConfigs.Keys)
            {
                if (existingTag > maxTag)
                {
                    maxTag = existingTag;
                }
            }

            long tag = maxTag + 1;

            _registeredBackendConfigs.Add(tag, backendConfig);

            return(tag);
        }
コード例 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BackendProber"/> class.
        /// HealthProber is the unit that checks the health state for all destinations(replica) of a backend(service)
        /// HealthProbe would query the health controller of the destination and update the health state for every destination
        /// periodically base on the time interval user specified in backend.
        /// </summary>
        public BackendProber(string backendId, BackendConfig config, IDestinationManager destinationManager, IMonotonicTimer timer, ILogger <BackendProber> logger, IOperationLogger <BackendProber> operationLogger, HttpClient httpClient, IRandomFactory randomFactory)
        {
            Contracts.CheckValue(backendId, nameof(backendId));
            Contracts.CheckValue(config, nameof(config));
            Contracts.CheckValue(destinationManager, nameof(destinationManager));
            Contracts.CheckValue(timer, nameof(timer));
            Contracts.CheckValue(logger, nameof(logger));
            Contracts.CheckValue(operationLogger, nameof(operationLogger));
            Contracts.CheckValue(httpClient, nameof(httpClient));
            Contracts.CheckValue(randomFactory, nameof(randomFactory));

            BackendId           = backendId;
            Config              = config;
            _destinationManager = destinationManager;
            _timer              = timer;
            _logger             = logger;
            _operationLogger    = operationLogger;
            _randomFactory      = randomFactory;

            _healthControllerUrl = new Uri(Config.HealthCheckOptions.Path, UriKind.Relative);
            _healthCheckInterval = Config.HealthCheckOptions.Interval;

            _backendProbeHttpClient = httpClient;
        }
コード例 #8
0
 /// <inheritdoc/>
 public IBackendProber CreateBackendProber(string backendId, BackendConfig config, IEndpointManager endpointManager)
 {
     return(new BackendProber(backendId, config, endpointManager, _timer, _loggerFactory.CreateLogger <BackendProber>(), _operationLogger, _httpClientFactory.CreateHttpClient(), _randomFactory));
 }
コード例 #9
0
ファイル: EmployeesProxy.cs プロジェクト: cTorres1982/MAS
 public EmployeesProxy(HttpClient httpClient, ILogger <EmployeesProxy> logger, IOptions <BackendConfig> options)
 {
     _httpClient    = httpClient;
     _logger        = logger;
     _backendConfig = options.Value;
 }
コード例 #10
0
 public async Task ConfigureSecretBackendAsync(string path, BackendConfig backendConfig)
 {
     var resourcePath = string.Format(CultureInfo.InvariantCulture, "v1/sys/mounts/{0}/tune", path.Trim('/'));
     await _polymath.MakeVaultApiRequest(resourcePath, HttpMethod.Post, backendConfig).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext);
 }
コード例 #11
0
 /// <inheritdoc/>
 public IBackendProber CreateBackendProber(string backendId, BackendConfig config, IDestinationManager destinationManager)
 {
     return(new BackendProber(backendId, config, destinationManager, _timer, _logger, _operationLogger, _httpClientFactory.CreateHttpClient(), _randomFactory));
 }
コード例 #12
0
 public GreeterService(ILogger <GreeterService> logger, IOptions <BackendConfig> config)
 {
     _logger = logger;
     _config = config.Value;
 }
コード例 #13
0
        private void UpdateRuntimeBackends(DynamicConfigRoot config)
        {
            var desiredBackends = new HashSet <string>(StringComparer.Ordinal);

            foreach (var configBackendPair in config.Backends)
            {
                var configBackend = configBackendPair.Value;
                desiredBackends.Add(configBackendPair.Key);

                _backendManager.GetOrCreateItem(
                    itemId: configBackendPair.Key,
                    setupAction: backend =>
                {
                    UpdateRuntimeEndpoints(configBackend.Endpoints, backend.EndpointManager);

                    var newConfig = new BackendConfig(
                        new BackendConfig.BackendHealthCheckOptions(
                            enabled: configBackend.HealthCheckOptions?.Enabled ?? false,
                            interval: configBackend.HealthCheckOptions?.Interval ?? TimeSpan.FromSeconds(0),
                            timeout: configBackend.HealthCheckOptions?.Timeout ?? TimeSpan.FromSeconds(0),
                            port: configBackend.HealthCheckOptions?.Port ?? 0,
                            path: configBackend.HealthCheckOptions?.Path ?? string.Empty),
                        new BackendConfig.BackendLoadBalancingOptions(
                            mode: BackendConfig.BackendLoadBalancingOptions.LoadBalancingMode.First));

                    var currentBackendConfig = backend.Config.Value;
                    if (currentBackendConfig == null ||
                        currentBackendConfig.HealthCheckOptions.Enabled != newConfig.HealthCheckOptions.Enabled ||
                        currentBackendConfig.HealthCheckOptions.Interval != newConfig.HealthCheckOptions.Interval ||
                        currentBackendConfig.HealthCheckOptions.Timeout != newConfig.HealthCheckOptions.Timeout ||
                        currentBackendConfig.HealthCheckOptions.Port != newConfig.HealthCheckOptions.Port ||
                        currentBackendConfig.HealthCheckOptions.Path != newConfig.HealthCheckOptions.Path)
                    {
                        if (currentBackendConfig == null)
                        {
                            _logger.LogDebug("Backend {backendId} has been added.", configBackendPair.Key);
                        }
                        else
                        {
                            _logger.LogDebug("Backend {backendId} has changed.", configBackendPair.Key);
                        }

                        // Config changed, so update runtime backend
                        backend.Config.Value = newConfig;
                    }
                });
            }

            foreach (var existingBackend in _backendManager.GetItems())
            {
                if (!desiredBackends.Contains(existingBackend.BackendId))
                {
                    // NOTE 1: This is safe to do within the `foreach` loop
                    // because `IBackendManager.GetItems` returns a copy of the list of backends.
                    //
                    // NOTE 2: Removing the backend from `IBackendManager` is safe and existing
                    // ASP .NET Core endpoints will continue to work with their existing behavior (until those endpoints are updated)
                    // and the Garbage Collector won't destroy this backend object while it's referenced elsewhere.
                    _logger.LogDebug("Backend {backendId} has been removed.", existingBackend.BackendId);
                    _backendManager.TryRemoveItem(existingBackend.BackendId);
                }
            }
        }