예제 #1
0
        public override void Init(IDictionary <string, string> jobArgsDictionary)
        {
            var retrievedMaxManifestSize = JobConfigurationManager.TryGetIntArgument(jobArgsDictionary, JobArgumentNames.MaxManifestSize);

            MaxManifestSize = retrievedMaxManifestSize == null
                ? DefaultMaxAllowedManifestBytes
                : Convert.ToInt64(retrievedMaxManifestSize);

            PackageDatabase = new SqlConnectionStringBuilder(
                JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.PackageDatabase));

            Source = CloudStorageAccount.Parse(
                JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.SourceStorage));
            Backups = CloudStorageAccount.Parse(
                JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.BackupStorage));
            SourceContainerName  = JobConfigurationManager.TryGetArgument(jobArgsDictionary, JobArgumentNames.SourceContainerName) ?? DefaultSourceContainerName;
            BackupsContainerName = JobConfigurationManager.TryGetArgument(jobArgsDictionary, JobArgumentNames.BackupContainerName) ?? DefaultBackupContainerName;
            ReadMeContainerName  = JobConfigurationManager.TryGetArgument(jobArgsDictionary, JobArgumentNames.ReadMeContainerName) ?? DefaultReadMeContainerName;

            SourceContainer  = Source.CreateCloudBlobClient().GetContainerReference(SourceContainerName);
            BackupsContainer = Backups.CreateCloudBlobClient().GetContainerReference(BackupsContainerName);
            ReadMeContainer  = Source.CreateCloudBlobClient().GetContainerReference(ReadMeContainerName);

            MaxTryCount = DefaultMaxRetryCount;
        }
        public override bool Init(IDictionary <string, string> jobArgsDictionary)
        {
            string maxManifestSizeString = JobConfigurationManager.TryGetArgument(jobArgsDictionary, JobArgumentNames.MaxManifestSize);

            if (string.IsNullOrEmpty(maxManifestSizeString))
            {
                MaxManifestSize = DefaultMaxAllowedManifestBytes;
            }
            else
            {
                MaxManifestSize = Convert.ToInt64(maxManifestSizeString);
            }

            PackageDatabase = new SqlConnectionStringBuilder(
                JobConfigurationManager.GetArgument(jobArgsDictionary,
                                                    JobArgumentNames.PackageDatabase,
                                                    EnvironmentVariableKeys.SqlGallery));

            Source = CloudStorageAccount.Parse(
                JobConfigurationManager.GetArgument(jobArgsDictionary,
                                                    JobArgumentNames.SourceStorage, EnvironmentVariableKeys.StorageGallery));
            Backups = CloudStorageAccount.Parse(
                JobConfigurationManager.GetArgument(jobArgsDictionary,
                                                    JobArgumentNames.BackupStorage, EnvironmentVariableKeys.StorageGallery));

            SourceContainerName  = JobConfigurationManager.TryGetArgument(jobArgsDictionary, JobArgumentNames.SourceContainerName) ?? DefaultSourceContainerName;
            BackupsContainerName = JobConfigurationManager.TryGetArgument(jobArgsDictionary, JobArgumentNames.BackupContainerName) ?? DefaultBackupContainerName;

            SourceContainer  = Source.CreateCloudBlobClient().GetContainerReference(SourceContainerName);
            BackupsContainer = Backups.CreateCloudBlobClient().GetContainerReference(BackupsContainerName);
            return(true);
        }
예제 #3
0
 public AzureStorage(IDictionary <string, string> jobArgsDictionary)
 {
     Source = CloudStorageAccount.Parse(JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.SourceStorage));
     SourceContainerName  = JobConfigurationManager.TryGetArgument(jobArgsDictionary, JobArgumentNames.SourceContainerName) ?? DefaultSourceContainerName;
     SourceContainer      = Source.CreateCloudBlobClient().GetContainerReference(SourceContainerName);
     Backups              = CloudStorageAccount.Parse(JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.BackupStorage));
     BackupsContainerName = JobConfigurationManager.TryGetArgument(jobArgsDictionary, JobArgumentNames.BackupContainerName) ?? DefaultBackupContainerName;
     BackupsContainer     = Backups.CreateCloudBlobClient().GetContainerReference(BackupsContainerName);
     SnapshotService      = new AzureSnapshotService();
 }
        protected internal override async Task Execute()
        {
            // Load defaults
            MaxManifestSize = MaxAllowedManifestBytes ?? DefaultMaxAllowedManifestBytes;
            PackageDatabase = PackageDatabase ?? Config.Sql.GetConnectionString(KnownSqlConnection.Legacy);
            Source          = Source ?? Config.Storage.Legacy;
            Backups         = Backups ?? Config.Storage.Backup;
            SourceContainer = Source.CreateCloudBlobClient().GetContainerReference(
                String.IsNullOrEmpty(SourceContainerName) ? BlobContainerNames.LegacyPackages : SourceContainerName);
            BackupsContainer = Backups.CreateCloudBlobClient().GetContainerReference(
                String.IsNullOrEmpty(BackupsContainerName) ? BlobContainerNames.Backups : BackupsContainerName);

            // Grab package edits
            IList <PackageEdit> edits;

            Log.FetchingQueuedEdits(PackageDatabase.DataSource, PackageDatabase.InitialCatalog);
            using (var connection = await PackageDatabase.ConnectTo())
            {
                if (MaxTryCount.HasValue)
                {
                    edits = (await connection.QueryAsync <PackageEdit>(
                                 GetEditsBaseSql + @"
                        WHERE [TriedCount] < @MaxTryCount",
                                 new
                    {
                        MaxTryCount = MaxTryCount.Value
                    })).ToList();
                }
                else
                {
                    edits = (await connection.QueryAsync <PackageEdit>(GetEditsBaseSql))
                            .ToList();
                }
            }
            Log.FetchedQueuedEdits(PackageDatabase.DataSource, PackageDatabase.InitialCatalog, edits.Count);

            // Group by package and take just the most recent edit for each package
            edits = edits
                    .GroupBy(e => e.PackageKey)
                    .Select(g => g.OrderByDescending(e => e.Timestamp).FirstOrDefault())
                    .Where(e => e != null)
                    .ToList();

            // Process packages
            foreach (var edit in edits)
            {
                Log.EditingPackage(edit.Id, edit.Version);
                Exception thrown = null;
                try
                {
                    await ApplyEdit(edit);
                }
                catch (Exception ex)
                {
                    thrown = ex;
                }
                if (thrown != null)
                {
                    Log.ErrorEditingPackage(edit.Id, edit.Version, thrown.ToString());
                    if (!WhatIf)
                    {
                        using (var connection = await PackageDatabase.ConnectTo())
                        {
                            await connection.QueryAsync <int>(@"
                            UPDATE  PackageEdits
                            SET
                                    TriedCount = TriedCount + 1,
                                    LastError = @error
                            WHERE   [Key] = @key", new
                            {
                                error = thrown.ToString(),
                                key   = edit.Key
                            });
                        }
                    }
                }
                Log.EditedPackage(edit.Id, edit.Version);
            }
        }