Exemplo n.º 1
0
        private RavenAzureClient(AzureSettings azureSettings, BackupConfiguration configuration, Progress progress = null, CancellationToken cancellationToken = default)
        {
            if (azureSettings == null)
            {
                throw new ArgumentNullException(nameof(azureSettings));
            }
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var hasAccountKey = string.IsNullOrWhiteSpace(azureSettings.AccountKey) == false;
            var hasSasToken   = string.IsNullOrWhiteSpace(azureSettings.SasToken) == false;

            if (hasAccountKey == false && hasSasToken == false)
            {
                throw new ArgumentException($"{nameof(AzureSettings.AccountKey)} and {nameof(AzureSettings.SasToken)} cannot be both null or empty");
            }

            if (hasAccountKey && hasSasToken)
            {
                throw new ArgumentException($"{nameof(AzureSettings.AccountKey)} and {nameof(AzureSettings.SasToken)} cannot be used simultaneously");
            }

            if (string.IsNullOrWhiteSpace(azureSettings.AccountName))
            {
                throw new ArgumentException($"{nameof(AzureSettings.AccountName)} cannot be null or empty");
            }

            if (string.IsNullOrWhiteSpace(azureSettings.StorageContainer))
            {
                throw new ArgumentException($"{nameof(AzureSettings.StorageContainer)} cannot be null or empty");
            }

            var serverUrlForContainer = new Uri($"https://{azureSettings.AccountName}.blob.core.windows.net/{azureSettings.StorageContainer.ToLower()}", UriKind.Absolute);

            var options = new BlobClientOptions
            {
                Retry =
                {
                    NetworkTimeout = configuration.CloudStorageOperationTimeout.AsTimeSpan
                }
            };

            if (hasAccountKey)
            {
                _client = new BlobContainerClient(serverUrlForContainer, new StorageSharedKeyCredential(azureSettings.AccountName, azureSettings.AccountKey), options);
            }

            if (hasSasToken)
            {
                VerifySasToken(azureSettings.SasToken);
                _client = new BlobContainerClient(serverUrlForContainer, new AzureSasCredential(azureSettings.SasToken), options);
            }

            _progress          = progress;
            _cancellationToken = cancellationToken;
            _storageContainer  = azureSettings.StorageContainer;
            RemoteFolderName   = azureSettings.RemoteFolderName;
        }
Exemplo n.º 2
0
        public static IRavenAzureClient Create(AzureSettings settings, BackupConfiguration configuration, Progress progress = null, CancellationToken cancellationToken = default)
        {
            if (configuration.AzureLegacy)
            {
                return(new LegacyRavenAzureClient(settings, progress, cancellationToken: cancellationToken));
            }

            return(new RavenAzureClient(settings, configuration, progress, cancellationToken));
        }
Exemplo n.º 3
0
        public ConcurrentBackupsCounter(BackupConfiguration backupConfiguration, LicenseManager licenseManager)
        {
            _licenseManager = licenseManager;

            int numberOfCoresToUse;
            var skipModifications = backupConfiguration.MaxNumberOfConcurrentBackups != null;

            if (skipModifications)
            {
                numberOfCoresToUse = backupConfiguration.MaxNumberOfConcurrentBackups.Value;
            }
            else
            {
                var utilizedCores = _licenseManager.GetCoresLimitForNode(out _);
                numberOfCoresToUse = GetNumberOfCoresToUseForBackup(utilizedCores);
            }

            _concurrentBackups      = numberOfCoresToUse;
            _maxConcurrentBackups   = numberOfCoresToUse;
            _concurrentBackupsDelay = backupConfiguration.ConcurrentBackupsDelay.AsTimeSpan;
            _skipModifications      = skipModifications;
        }