private static IRetryPolicy CreateSecretsRetrievalRetryPolicy(DistributedContentSettings settings)
 {
     return(RetryPolicyFactory.GetExponentialPolicy(
                IsTransient,
                retryCount: settings.SecretsRetrievalRetryCount,
                minBackoff: TimeSpan.FromSeconds(settings.SecretsRetrievalMinBackoffSeconds),
                maxBackoff: TimeSpan.FromSeconds(settings.SecretsRetrievalMaxBackoffSeconds),
                deltaBackoff: TimeSpan.FromSeconds(settings.SecretsRetrievalDeltaBackoffSeconds)));
 }
        public ClientContentMetadataStore(IGlobalLocationStore globalStore, IClientFactory <IContentMetadataService> metadataServiceClientFactory, ClientContentMetadataStoreConfiguration configuration)
        {
            _globalStore = globalStore;
            _metadataServiceClientFactory = metadataServiceClientFactory;
            _configuration = configuration;

            _retryPolicy = RetryPolicyFactory.GetExponentialPolicy(exception =>
            {
                return(true);
            });
        }
        public IRetryPolicy CreateRetryPolicy(Action <Exception> onRedisException)
        {
            var policy = new RedisDatabaseAdapter.RedisRetryPolicy(onRedisException, TreatObjectDisposedExceptionAsTransient);

            if (_retryCount != null)
            {
                return(RetryPolicyFactory.GetLinearPolicy(policy.IsTransient, _retryCount.Value));
            }
            else if (ExponentialBackoffConfiguration != null)
            {
                var config = ExponentialBackoffConfiguration;
                return(RetryPolicyFactory.GetExponentialPolicy(policy.IsTransient, config.RetryCount, config.MinBackoff, config.MaxBackoff, config.DeltaBackoff));
            }
            else
            {
                return(RetryPolicyFactory.GetExponentialPolicy(policy.IsTransient));
            }
        }
        public ClientGlobalCacheStore(
            IClientAccessor <IGlobalCacheService> metadataServiceClientFactory,
            ClientContentMetadataStoreConfiguration configuration)
        {
            _serviceClientFactory = metadataServiceClientFactory;
            _configuration        = configuration;
            _clock = SystemClock.Instance;

            _retryPolicy = RetryPolicyFactory.GetExponentialPolicy(
                _ => true,
                // We use an absurdly high retry count because the actual operation timeout is controlled through
                // PerformOperationAsync in ExecuteAsync.
                1_000_000,
                _configuration.RetryMinimumWaitTime,
                _configuration.RetryMaximumWaitTime,
                _configuration.RetryDelta);

            LinkLifetime(_serviceClientFactory);
        }
        /// <inheritdoc />
        public async Task <BoolResult> StartupAsync(Context context)
        {
            StartupStarted = true;
            IRetryPolicy retryPolicy = RetryPolicyFactory.GetExponentialPolicy(AuthorizationErrorDetectionStrategy.IsTransient);

            try
            {
                var creds = await retryPolicy.ExecuteAsync(() => _vssCredentialsFactory.GetOrCreateVssCredentialsAsync(_backingStoreBaseUri, _useAad, PatType.CacheReadWrite), CancellationToken.None).ConfigureAwait(false);

                _httpClientFactory = new ArtifactHttpClientFactory(
                    creds,
                    _httpSendTimeout,
                    tracer: new AppTraceSourceContextAdapter(context, nameof(BackingContentStoreHttpClientFactory), SourceLevels.All),
                    verifyConnectionCancellationToken: CancellationToken.None); // TODO: Pipe down cancellation support (bug 1365340)
                StartupCompleted = true;
                return(BoolResult.Success);
            }
            catch (Exception ex)
            {
                return(new BoolResult(ex));
            }
        }
Beispiel #6
0
        /// <summary>
        /// Creates an http client that can communicate with a VSTS Build Cache Service.
        /// </summary>
        public async Task <IBlobBuildCacheHttpClient> CreateBlobBuildCacheHttpClientAsync(Context context)
        {
            IRetryPolicy authRetryPolicy = RetryPolicyFactory.GetExponentialPolicy(AuthorizationErrorDetectionStrategy.IsTransient);
            var          creds           = await authRetryPolicy.ExecuteAsync(
                () => _vssCredentialsFactory.CreateVssCredentialsAsync(_buildCacheBaseUri, _useAad),
                CancellationToken.None).ConfigureAwait(false);

            var httpClientFactory = new ArtifactHttpClientFactory(
                creds,
                _httpSendTimeout,
                tracer: new AppTraceSourceContextAdapter(context, "BuildCacheHttpClientFactory", SourceLevels.All),
                verifyConnectionCancellationToken: CancellationToken.None); // TODO: Pipe down cancellation support (bug 1365340)
            IBlobBuildCacheHttpClient client =
                httpClientFactory.CreateVssHttpClient <IArtifactBlobBuildCacheHttpClient, BlobBuildCacheHttpClient>(_buildCacheBaseUri);
            await ArtifactHttpClientErrorDetectionStrategy.ExecuteAsync(
                context,
                "VerifyBlobBuildCacheHttpClientConnection",
                () => httpClientFactory.VerifyConnectionAsync(client as IArtifactHttpClient),
                CancellationToken.None).ConfigureAwait(false);

            _tracer.Debug(context, "Verified connection to {_buildCacheBaseUri} with SessionId=[{httpClientFactory.ClientSettings.SessionId}]");
            return(client);
        }