Example #1
0
        private async Task PerformUpgradeAsync(Domain domain, UpgradeStage stage, CancellationToken token)
        {
            context.Stage = stage;

            await OnBeforeStageAsync(token).ConfigureAwait(false);

            var session = await domain.OpenSessionAsync(SessionType.System, token).ConfigureAwait(false);

            await using (session.ConfigureAwait(false)) {
                using (session.Activate()) {
                    var transaction = session.OpenTransaction();
                    await using (transaction.ConfigureAwait(false)) {
                        var upgrader  = new SchemaUpgrader(context, session);
                        var extractor = new SchemaExtractor(context, session);
                        await SynchronizeSchemaAsync(domain, upgrader, extractor, GetUpgradeMode(stage), token).ConfigureAwait(false);

                        var storageNode = BuildStorageNode(domain, await extractor.GetSqlSchemaAsync(token).ConfigureAwait(false));
                        session.SetStorageNode(storageNode);
                        await OnStageAsync(session, token).ConfigureAwait(false);

                        transaction.Complete();
                    }
                }
            }
        }
        // Constructors

        public StageModelFilter(ReadOnlyDictionary <Assembly, IUpgradeHandler> handlers, UpgradeStage stage)
        {
            ArgumentValidator.EnsureArgumentNotNull(handlers, "handlers");

            this.handlers = handlers;
            this.stage    = stage;
        }
        private void SwitchStage(UpgradeStage stage)
        {
            this.stage = stage;
            scrollPos  = Vector2.zero;

            GUI.enabled = true;
            GUIUtility.ExitGUI();
        }
Example #4
0
        public override bool IsTypeAvailable(Type type, UpgradeStage upgradeStage)
        {
            string suffix            = ".Version" + runningVersion;
            var    originalNamespace = type.Namespace;
            var    nameSpace         = originalNamespace.TryCutSuffix(suffix);

            return(nameSpace != originalNamespace &&
                   base.IsTypeAvailable(type, upgradeStage));
        }
        public ModelMapping GetMappingForStage(UpgradeStage stage)
        {
            ModelMapping mapping;

            if (!mappings.TryGetValue(stage, out mapping))
            {
                throw new Exception(string.Format("There is no model mappings for the {0} stage ", stage));
            }
            return(mapping);
        }
Example #6
0
        private Func <Domain> CreateDomainBuilder(UpgradeStage stage)
        {
            if (stage == UpgradeStage.Final && context.ParentDomain != null)
            {
                return(() => context.ParentDomain);
            }

            var configuration = CreateDomainBuilderConfiguration(stage);

            return(((Func <DomainBuilderConfiguration, Domain>)DomainBuilder.Run).Bind(configuration));
        }
Example #7
0
        private SchemaUpgradeMode GetUpgradeMode(UpgradeStage stage)
        {
            switch (stage)
            {
            case UpgradeStage.Upgrading:
                return(upgradeMode.GetUpgradingStageUpgradeMode());

            case UpgradeStage.Final:
                return(upgradeMode.GetFinalStageUpgradeMode());

            default:
                throw new ArgumentOutOfRangeException("stage");
            }
        }
Example #8
0
        /// <exception cref="ArgumentOutOfRangeException"><c>UpgradeContext.Stage</c> is out of range.</exception>
        public virtual bool IsFieldAvailable(PropertyInfo field, UpgradeStage upgradeStage)
        {
            ArgumentValidator.EnsureArgumentNotNull(field, "field");
            var type = field.DeclaringType;

            if (type.Assembly != Assembly)
            {
                throw new ArgumentOutOfRangeException("field");
            }
            if (upgradeStage == UpgradeStage.Final)
            {
                return(field.GetAttribute <RecycledAttribute>() == null);
            }
            return(true);
        }
Example #9
0
        private DomainBuilderConfiguration CreateDomainBuilderConfiguration(UpgradeStage stage)
        {
            var configuration = new DomainBuilderConfiguration {
                DomainConfiguration = context.Configuration,
                Stage                = stage,
                Services             = context.Services,
                ModelFilter          = new StageModelFilter(context.UpgradeHandlers, stage),
                UpgradeContextCookie = context.Cookie,
                RecycledDefinitions  = context.RecycledDefinitions,
                DefaultSchemaInfo    = defaultSchemaInfo
            };

            configuration.Lock();
            return(configuration);
        }
Example #10
0
        /// <summary>
        /// Generate actions for specific <see cref="UpgradeStage"/>.
        /// </summary>
        /// <param name="stage">The stage.</param>
        /// <param name="action">The parent action.</param>
        protected void ProcessStage(UpgradeStage stage, GroupingNodeAction action)
        {
            Stage = stage;
            if (stage == UpgradeStage.Upgrade)
            {
                UpdateHints();
                Difference = Comparer.Compare(CurrentModel, TargetModel, Hints);
            }
            var stageActions = Visit(Difference);

            if (stageActions != null)
            {
                action.Add(stageActions);
            }
            CoreLog.Info(string.Format("Stage {0} complete.", stage));
        }
Example #11
0
        /// <exception cref="ArgumentOutOfRangeException"><c>context.Stage</c> is out of range.</exception>
        private void PerformUpgrade(Domain domain, UpgradeStage stage)
        {
            context.Stage = stage;

            OnBeforeStage();

            using (var session = domain.OpenSession(SessionType.System))
                using (session.Activate())
                    using (var transaction = session.OpenTransaction()) {
                        var upgrader  = new SchemaUpgrader(context, session);
                        var extractor = new SchemaExtractor(context, session);
                        SynchronizeSchema(domain, upgrader, extractor, GetUpgradeMode(stage));
                        var storageNode = BuildStorageNode(domain, extractor);
                        session.SetStorageNode(storageNode);
                        OnStage(session);
                        transaction.Complete();
                    }
        }
Example #12
0
        /// <exception cref="ArgumentOutOfRangeException"><c>UpgradeContext.Stage</c> is out of range.</exception>
        public virtual bool IsTypeAvailable(Type type, UpgradeStage upgradeStage)
        {
            ArgumentValidator.EnsureArgumentNotNull(type, "type");
            if (type.Assembly != Assembly)
            {
                throw new ArgumentOutOfRangeException("type");
            }
            switch (upgradeStage)
            {
            case UpgradeStage.Upgrading:
                return(true);

            case UpgradeStage.Final:
                return(type.GetAttribute <RecycledAttribute>() == null);

            default:
                throw new ArgumentOutOfRangeException("UpgradeContext.Stage");
            }
        }
Example #13
0
 private SchemaUpgradeMode GetUpgradeMode(UpgradeStage stage) =>
 stage switch
 {
        /// <summary>
        /// Compares <paramref name="sourceSchema"/> and <paramref name="targetSchema"/>.
        /// </summary>
        /// <param name="sourceSchema">The source schema.</param>
        /// <param name="targetSchema">The target schema.</param>
        /// <param name="schemaHints">The upgrade hints.</param>
        /// <param name="upgradeHints"><see cref="UpgradeHint"/>s to be applied.</param>
        /// <param name="schemaUpgradeMode">A <see cref="SchemaUpgradeMode"/> being used.</param>
        /// <param name="model">A <see cref="DomainModel"/> of a storage.</param>
        /// <param name="briefExceptionFormat">Indicates whether brief or full exception format should be used.</param>
        /// <param name="upgradeStage">A current <see cref="UpgradeStage"/>.</param>
        /// <returns>Comparison result.</returns>
        public static SchemaComparisonResult Compare(
            StorageModel sourceSchema, StorageModel targetSchema,
            HintSet schemaHints, SetSlim <UpgradeHint> upgradeHints,
            SchemaUpgradeMode schemaUpgradeMode, DomainModel model,
            bool briefExceptionFormat, UpgradeStage upgradeStage)
        {
            if (schemaHints == null)
            {
                schemaHints = new HintSet(sourceSchema, targetSchema);
            }

            var comparer                = new Comparer();
            var difference              = comparer.Compare(sourceSchema, targetSchema, schemaHints);
            var actions                 = GetUpgradeActions(comparer, difference, schemaHints);
            var actionList              = actions.Flatten().ToList();
            var comparisonStatus        = GetComparisonStatus(actionList, schemaUpgradeMode);
            var unsafeActions           = GetUnsafeActions(actionList, upgradeHints);
            var columnTypeChangeActions = actionList.OfType <PropertyChangeAction>().Where(IsTypeChangeAction).ToList();

            if (schemaUpgradeMode != SchemaUpgradeMode.ValidateLegacy)
            {
                return(new SchemaComparisonResult(
                           comparisonStatus, columnTypeChangeActions.Count > 0, null,
                           schemaHints, difference, actions, unsafeActions));
            }

            // Legacy comparison

            var systemTablesSequence = model.Types.Where(type => type.IsSystem).Select(type => type.MappingName);
            var systemTables         = new HashSet <string>(systemTablesSequence, Comparer);

            var createTableActions = actionList
                                     .OfType <CreateNodeAction>()
                                     .Where(
                action => {
                var table = action.Difference.Target as TableInfo;
                return(table != null && !systemTables.Contains(table.Name));
            })
                                     .ToList();

            var createColumnActions = actionList
                                      .OfType <CreateNodeAction>()
                                      .Where(
                action => {
                var column = action.Difference.Target as StorageColumnInfo;
                return(column != null && !systemTables.Contains(column.Parent.Name));
            })
                                      .ToList();

            columnTypeChangeActions = columnTypeChangeActions
                                      .Where(
                action => {
                var sourceType = action.Difference.Source as StorageTypeInfo;
                var targetType = action.Difference.Target as StorageTypeInfo;
                return(sourceType == null || targetType == null || sourceType.IsTypeUndefined ||
                       sourceType.Type.ToNullable() != targetType.Type.ToNullable());
            })
                                      .ToList();


            var isCompatibleInLegacyMode =
                createTableActions.Count == 0 &&
                createColumnActions.Count == 0 &&
                columnTypeChangeActions.Count == 0;

            if (briefExceptionFormat)
            {
                unsafeActions =
                    createTableActions.Cast <NodeAction>()
                    .Concat(createColumnActions.Cast <NodeAction>())
                    .Concat(columnTypeChangeActions.Cast <NodeAction>())
                    .ToList();
            }

            return(new SchemaComparisonResult(
                       comparisonStatus, columnTypeChangeActions.Count > 0, isCompatibleInLegacyMode,
                       schemaHints, difference, actions, unsafeActions));
        }
Example #15
0
 public override bool IsTypeAvailable(Type type, UpgradeStage upgradeStage)
 {
     return(true);
 }
Example #16
0
        private void CreateFilteredUpgradeBatches(UpgradeBatchCreatorScheduler.MailboxType mailboxType, ICacheEntry cacheEntryProxy)
        {
            UpgradeStage upgradeStage      = UpgradeBatchCreatorScheduler.MapMailboxTypeToUpgradeStage(mailboxType);
            QueryFilter  filterByBatchType = this.GetFilterByBatchType(mailboxType);

            base.Context.Logger.Log(MigrationEventType.Information, "CreateFilteredUpgradeBatches. upgrade stage is {0} mailboxType='{1}', filter='{2}'", new object[]
            {
                upgradeStage,
                mailboxType,
                filterByBatchType
            });
            ADObjectId rootId = (cacheEntryProxy is CacheEntryProxy && (mailboxType == UpgradeBatchCreatorScheduler.MailboxType.RegularSoftDeleted || mailboxType == UpgradeBatchCreatorScheduler.MailboxType.CloudOnlyArchiveSoftDeleted)) ? ((CacheEntryProxy)cacheEntryProxy).CacheEntryBase.OrganizationId.OrganizationalUnit.GetChildId("OU", "Soft Deleted Objects") : null;
            IEnumerable <RecipientWrapper> enumerable = cacheEntryProxy.ADSessionProxy.FindPagedMiniRecipient(mailboxType, rootId, QueryScope.OneLevel, filterByBatchType, null, 0, UpgradeBatchCreatorScheduler.AddlMiniRecipientProps);

            if (mailboxType != UpgradeBatchCreatorScheduler.MailboxType.Discovery && mailboxType != UpgradeBatchCreatorScheduler.MailboxType.RegularSoftDeleted && mailboxType != UpgradeBatchCreatorScheduler.MailboxType.CloudOnlyArchiveSoftDeleted)
            {
                this.e14MbxCount = 0;
                this.crossOrgMoveRequestCount             = 0;
                this.highPriorityMoveRequestCount         = 0;
                this.intraOrgMoveRequestCount             = 0;
                this.upgradeInProgressMoveRequestCount    = 0;
                this.upgradeNotInProgressMoveRequestCount = 0;
            }
            string       text         = null;
            StreamWriter streamWriter = null;
            int          config       = base.Context.Config.GetConfig <int>("MaxBatchSize");
            bool         config2      = base.Context.Config.GetConfig <bool>("RemoveNonUpgradeMoveRequests");
            string       config3      = base.Context.Config.GetConfig <string>((this.organization.UpgradeRequest == UpgradeRequestTypes.TenantUpgradeDryRun) ? "DryRunBatchFilenamePrefix" : "UpgradeBatchFilenamePrefix");
            int          num          = config;
            int          num2         = 0;

            try
            {
                foreach (RecipientWrapper recipientWrapper in enumerable)
                {
                    if (mailboxType == UpgradeBatchCreatorScheduler.MailboxType.Regular && (recipientWrapper.RecipientTypeDetails.HasFlag(RecipientTypeDetails.MailboxPlan) || recipientWrapper.RecipientTypeDetails.HasFlag(RecipientTypeDetails.DiscoveryMailbox)))
                    {
                        base.Context.Logger.Log(MigrationEventType.Information, "Skipping '{0}' with RecipientTypeDetails '{1}'", new object[]
                        {
                            recipientWrapper.Id,
                            recipientWrapper.RecipientTypeDetails
                        });
                    }
                    else
                    {
                        this.e14MbxCount++;
                        num2++;
                        if (recipientWrapper.MoveStatus != RequestStatus.None)
                        {
                            base.Context.Logger.Log(MigrationEventType.Information, "Move Request for '{0}' already exists. BatchName='{1}' Status='{2}' RequestFlags='{3}'", new object[]
                            {
                                recipientWrapper.Id.ObjectGuid,
                                recipientWrapper.MailboxMoveBatchName,
                                recipientWrapper.MoveStatus,
                                recipientWrapper.RequestFlags
                            });
                            bool flag = false;
                            if (recipientWrapper.MailboxMoveBatchName.StartsWith(config3, StringComparison.OrdinalIgnoreCase))
                            {
                                if (recipientWrapper.MoveStatus != RequestStatus.InProgress && recipientWrapper.MoveStatus != RequestStatus.Queued)
                                {
                                    this.upgradeInProgressMoveRequestCount++;
                                }
                                else
                                {
                                    this.upgradeNotInProgressMoveRequestCount++;
                                }
                            }
                            else
                            {
                                if (config2 && (recipientWrapper.MoveStatus == RequestStatus.Completed || recipientWrapper.MoveStatus == RequestStatus.CompletedWithWarning || (!recipientWrapper.RequestFlags.HasFlag(RequestFlags.CrossOrg) && !recipientWrapper.RequestFlags.HasFlag(RequestFlags.HighPriority))))
                                {
                                    flag = this.orgOperationProxy.TryRemoveMoveRequest(recipientWrapper.Id.ObjectGuid.ToString());
                                }
                                if (!flag)
                                {
                                    if (recipientWrapper.RequestFlags.HasFlag(RequestFlags.CrossOrg))
                                    {
                                        this.crossOrgMoveRequestCount++;
                                    }
                                    else if (recipientWrapper.RequestFlags.HasFlag(RequestFlags.HighPriority))
                                    {
                                        this.highPriorityMoveRequestCount++;
                                    }
                                    else
                                    {
                                        this.intraOrgMoveRequestCount++;
                                    }
                                }
                            }
                            if (!flag)
                            {
                                continue;
                            }
                        }
                        if (num == config)
                        {
                            if (streamWriter != null)
                            {
                                streamWriter.Close();
                                streamWriter.Dispose();
                                streamWriter = null;
                                File.Move(text, Path.ChangeExtension(text, ".csv"));
                                if (cacheEntryProxy is CacheEntryProxy && base.ShouldProcessEntry(((CacheEntryProxy)cacheEntryProxy).CacheEntryBase) != AnchorJobProcessorResult.Working)
                                {
                                    throw new AnchorServiceInstanceNotActiveException();
                                }
                            }
                            num = 0;
                            string path = string.Format("{0}{1:MMdd}{2}{3}{4}{5}{6}{7}", new object[]
                            {
                                config3,
                                DateTime.UtcNow,
                                '_',
                                this.organization.ExternalDirectoryOrganizationId,
                                '_',
                                mailboxType,
                                UpgradeBatchCreatorScheduler.random.Next(),
                                ".tmp"
                            });
                            text = Path.Combine(this.OrgBatchDirectoryPath, path);
                            base.Context.Logger.Log(MigrationEventType.Information, "Starting new batch file '{0}'.", new object[]
                            {
                                text
                            });
                            streamWriter = new StreamWriter(text, false);
                            streamWriter.WriteLine("Guid,TenantPartitionHint,SourceDatabase,TargetDatabase,ArchiveOnly,Priority,CompletedRequestAgeLimit,Protect,PreventCompletion,BlockFinalization,WorkloadType");
                        }
                        string text2 = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}", new object[]
                        {
                            recipientWrapper.Id.ObjectGuid,
                            this.organization.ExternalDirectoryOrganizationId,
                            string.Empty,
                            string.Empty,
                            mailboxType == UpgradeBatchCreatorScheduler.MailboxType.CloudOnlyArchive || mailboxType == UpgradeBatchCreatorScheduler.MailboxType.CloudOnlyArchivePilot,
                            (mailboxType == UpgradeBatchCreatorScheduler.MailboxType.Arbitration || mailboxType == UpgradeBatchCreatorScheduler.MailboxType.Discovery) ? RequestPriority.High : RequestPriority.Low,
                            0,
                            true,
                            this.organization.UpgradeRequest == UpgradeRequestTypes.TenantUpgradeDryRun,
                            this.organization.UpgradeRequest == UpgradeRequestTypes.TenantUpgradeDryRun,
                            RequestWorkloadType.TenantUpgrade
                        });
                        base.Context.Logger.Log(MigrationEventType.Information, "Adding Entry: {0}", new object[]
                        {
                            text2
                        });
                        streamWriter.WriteLine(text2);
                        num++;
                    }
                }
            }
            finally
            {
                if (num2 > 0 && this.organization.UpgradeRequest != UpgradeRequestTypes.TenantUpgradeDryRun)
                {
                    this.LogUpgradeStageWithE14Counts(new UpgradeStage?(upgradeStage));
                }
                if (streamWriter != null)
                {
                    streamWriter.Close();
                    streamWriter.Dispose();
                    File.Move(text, Path.ChangeExtension(text, ".csv"));
                }
            }
        }
 public void Register(UpgradeStage stage, ModelMapping mapping)
 {
     mappings.Add(stage, mapping);
 }
Example #18
0
 public override bool IsTypeAvailable(Type type, UpgradeStage upgradeStage) => true;
Example #19
0
 private void SetOrganization(TenantOrganizationPresentationObjectWrapper tenant, UpgradeStatusTypes workitemStatus, UpgradeRequestTypes requestType, UpgradeStage upgradeStage = UpgradeStage.None)
 {
     base.Context.Logger.Log(MigrationEventType.Information, "updating {0} organization with status {1} and type {2}", new object[]
     {
         tenant.ExternalDirectoryOrganizationId,
         workitemStatus,
         requestType
     });
     this.orgOperationProxy.SetOrganization(tenant, workitemStatus, requestType, string.Empty, string.Empty, new UpgradeStage?(upgradeStage), -1, -1);
     this.tenantUpdatedCount++;
 }