Beispiel #1
0
        internal MRSRequestWrapper(IConfigurationSession session, MRSRequestType type, string commonName)
        {
            base.RequestType = type;
            ADObjectId relativeContainerId = ADHandler.GetRelativeContainerId(type);

            base.SetId(session, relativeContainerId, commonName);
        }
 public RequestIndexEntryObjectId(Guid requestGuid, MRSRequestType requestType, OrganizationId organizationId, RequestIndexId indexId, RequestBase owner = null)
 {
     this.RequestGuid    = requestGuid;
     this.RequestType    = requestType;
     this.OrganizationId = organizationId;
     this.IndexId        = indexId;
     this.RequestObject  = owner;
 }
Beispiel #3
0
        internal static ADObjectId GetRootId(IConfigurationSession configSession, MRSRequestType type)
        {
            if (!configSession.SessionSettings.IsTenantScoped && CommonUtils.IsMultiTenantEnabled())
            {
                return(null);
            }
            ADObjectId descendantId = configSession.GetOrgContainerId().GetDescendantId(ADHandler.RelativeMRSContainer);

            return(descendantId.GetDescendantId(ADHandler.GetRelativeContainerId(type)));
        }
Beispiel #4
0
        protected bool CheckRequestOfTypeExists(MRSRequestType requestType)
        {
            RequestIndexEntryQueryFilter filter = new RequestIndexEntryQueryFilter(null, null, requestType, this.DefaultRequestIndexId, false);
            ObjectId rootId = ADHandler.GetRootId(this.CurrentOrgConfigSession, requestType);
            IEnumerable <TRequest> enumerable = ((RequestJobProvider)base.DataSession).IndexProvider.FindPaged <TRequest>(filter, rootId, rootId == null, null, 10);

            foreach (TRequest trequest in enumerable)
            {
                if (trequest.Type == requestType)
                {
                    return(true);
                }
            }
            return(false);
        }
 private static void CleanADOrphanAndInconsistencyForRequests(IRecipientSession recipientSession, IConfigurationSession configSession, Guid dbGuid)
 {
     MrsTracer.Service.Debug("Try to CleanADOrphanAndInconsistencyForRequests for Database {0} name is {1}", new object[]
     {
         dbGuid,
         dbGuid
     });
     using (RequestJobProvider rjProvider = new RequestJobProvider(dbGuid))
     {
         rjProvider.LoadReport   = false;
         rjProvider.AllowInvalid = true;
         foreach (object obj in Enum.GetValues(typeof(MRSRequestType)))
         {
             MRSRequestType requestType = (MRSRequestType)obj;
             MrsTracer.Service.Debug("Try to CleanADOrphanAndInconsistencyForRequests for request type {0}", new object[]
             {
                 requestType
             });
             CommonUtils.CatchKnownExceptions(delegate
             {
                 if (requestType == MRSRequestType.Move)
                 {
                     ADInconsistencyCheck.CleanADOrphanAndInconsistencyForMoves(recipientSession, rjProvider, dbGuid);
                     return;
                 }
                 ADInconsistencyCheck.CleanADOrphanAndInconsistencyForNonMoves(configSession, requestType, rjProvider, dbGuid);
             }, delegate(Exception f)
             {
                 MrsTracer.Service.Error("CleanADOrphanAndInconsistencyForRequests() failed for DB {0}. Request type {1} Error: {2}", new object[]
                 {
                     dbGuid,
                     requestType.ToString(),
                     CommonUtils.FullExceptionMessage(f, true)
                 });
                 MRSService.LogEvent(MRSEventLogConstants.Tuple_ScanADInconsistencyRequestFailEvent, new object[]
                 {
                     dbGuid,
                     requestType.ToString(),
                     string.Empty,
                     CommonUtils.FullExceptionMessage(f, true)
                 });
             });
         }
     }
 }
Beispiel #6
0
 public RequestIndexEntryQueryFilter(string name, ADObjectId id, MRSRequestType type, RequestIndexId idx, bool mbxSearch)
 {
     this.requestName          = name;
     this.mailboxId            = (mbxSearch ? id : null);
     this.dbId                 = (mbxSearch ? null : id);
     this.looseMailboxSearch   = false;
     this.wildcardedNameSearch = false;
     this.requestType          = type;
     this.indexId              = idx;
     this.requestGuid          = Guid.Empty;
     this.requestQueueId       = null;
     this.batchName            = null;
     this.sourceMailbox        = null;
     this.targetMailbox        = null;
     this.sourceDatabase       = null;
     this.status               = RequestStatus.None;
     this.flags                = RequestFlags.None;
     this.notFlags             = RequestFlags.None;
 }
Beispiel #7
0
 internal static bool IsKnownRequestType(MRSRequestType requestType)
 {
     switch (requestType)
     {
     case MRSRequestType.Move:
     case MRSRequestType.Merge:
     case MRSRequestType.MailboxImport:
     case MRSRequestType.MailboxExport:
     case MRSRequestType.MailboxRestore:
     case MRSRequestType.PublicFolderMove:
     case MRSRequestType.PublicFolderMigration:
     case MRSRequestType.Sync:
     case MRSRequestType.MailboxRelocation:
     case MRSRequestType.FolderMove:
     case MRSRequestType.PublicFolderMailboxMigration:
         return(true);
     }
     return(false);
 }
Beispiel #8
0
        internal static ADObjectId GetRelativeContainerId(MRSRequestType type)
        {
            ADObjectId result = null;

            if (type == MRSRequestType.Merge)
            {
                result = ADHandler.RelativeMergeContainer;
            }
            else if (type == MRSRequestType.MailboxImport)
            {
                result = ADHandler.RelativeMailboxImportContainer;
            }
            else if (type == MRSRequestType.MailboxExport)
            {
                result = ADHandler.RelativeMailboxExportContainer;
            }
            else if (type == MRSRequestType.MailboxRestore)
            {
                result = ADHandler.RelativeMailboxRestoreContainer;
            }
            else if (type == MRSRequestType.PublicFolderMove)
            {
                result = ADHandler.RelativePublicFolderMoveContainer;
            }
            else if (type == MRSRequestType.PublicFolderMigration)
            {
                result = ADHandler.RelativePublicFolderMigrationContainer;
            }
            else if (type == MRSRequestType.PublicFolderMailboxMigration)
            {
                result = ADHandler.RelativePublicFolderMailboxMigrationContainer;
            }
            else if (type == MRSRequestType.Sync)
            {
                result = ADHandler.RelativeSyncContainer;
            }
            else if (type == MRSRequestType.FolderMove)
            {
                result = ADHandler.RelativeFolderMoveContainer;
            }
            return(result);
        }
        protected override string CheckRequestNameAvailability(string name, ADObjectId identifyingObjectId, bool objectIsMailbox, MRSRequestType requestType, object errorObject, bool wildcardedSearch)
        {
            string text = string.Format("{0}*", name);
            RequestIndexEntryQueryFilter requestIndexEntryQueryFilter = new RequestIndexEntryQueryFilter(wildcardedSearch ? text : name, identifyingObjectId, requestType, new RequestIndexId(RequestIndexLocation.AD), objectIsMailbox);

            requestIndexEntryQueryFilter.WildcardedNameSearch = wildcardedSearch;
            ObjectId rootId = ADHandler.GetRootId(base.CurrentOrgConfigSession, requestType);
            IEnumerable <FolderMoveRequest> enumerable = ((RequestJobProvider)base.DataSession).IndexProvider.FindPaged <FolderMoveRequest>(requestIndexEntryQueryFilter, rootId, rootId == null, null, 10);
            string result;

            using (IEnumerator <FolderMoveRequest> enumerator = enumerable.GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    bool flag = true;
                    while (this.IsNewRequestAllowed(enumerator.Current))
                    {
                        if (!enumerator.MoveNext())
                        {
IL_93:
                            if (!flag)
                            {
                                base.WriteError(new NameMustBeUniquePermanentException(name, (identifyingObjectId == null) ? string.Empty : identifyingObjectId.ToString()), ErrorCategory.InvalidArgument, errorObject);
                                return(null);
                            }
                            return(name);
                        }
                    }
                    flag = false;
                    goto IL_93;
                }
                result = name;
            }
            return(result);
        }
 void IRequestIndexEntry.set_Type(MRSRequestType A_1)
 {
     base.Type = A_1;
 }
 public RequestIndexEntryObjectId(Guid requestGuid, Guid targetExchangeGuid, MRSRequestType requestType, OrganizationId organizationId, RequestIndexId indexId, RequestBase owner = null) : this(requestGuid, requestType, organizationId, indexId, owner)
 {
     this.TargetExchangeGuid = targetExchangeGuid;
 }
Beispiel #12
0
        protected virtual string CheckRequestNameAvailability(string name, ADObjectId identifyingObjectId, bool objectIsMailbox, MRSRequestType requestType, object errorObject, bool wildcardedSearch)
        {
            string text = string.Format("{0}*", name);
            RequestIndexEntryQueryFilter requestIndexEntryQueryFilter = new RequestIndexEntryQueryFilter(wildcardedSearch ? text : name, identifyingObjectId, requestType, this.DefaultRequestIndexId, objectIsMailbox);

            requestIndexEntryQueryFilter.WildcardedNameSearch = wildcardedSearch;
            ObjectId rootId = ADHandler.GetRootId(this.CurrentOrgConfigSession, requestType);
            IEnumerable <TRequest> enumerable = ((RequestJobProvider)base.DataSession).IndexProvider.FindPaged <TRequest>(requestIndexEntryQueryFilter, rootId, rootId == null, null, 10);
            string result;

            using (IEnumerator <TRequest> enumerator = enumerable.GetEnumerator())
            {
                if (!enumerator.MoveNext())
                {
                    result = name;
                }
                else if (!wildcardedSearch)
                {
                    if (requestType.Equals(MRSRequestType.PublicFolderMigration) || requestType.Equals(MRSRequestType.PublicFolderMove))
                    {
                        base.WriteError(new MultipleSamePublicFolderMRSJobInstancesNotAllowedException(requestType.ToString()), ErrorCategory.InvalidArgument, errorObject);
                    }
                    else
                    {
                        base.WriteError(new NameMustBeUniquePermanentException(name, (identifyingObjectId == null) ? string.Empty : identifyingObjectId.ToString()), ErrorCategory.InvalidArgument, errorObject);
                    }
                    result = null;
                }
                else
                {
                    Regex       regex = new Regex(string.Format("^{0}(\\d)?$", name));
                    List <uint> list  = new List <uint>(10);
                    for (uint num = 0U; num < 10U; num += 1U)
                    {
                        list.Add(num);
                    }
                    do
                    {
                        TRequest trequest = enumerator.Current;
                        Match    match    = regex.Match(trequest.Name);
                        if (match.Success)
                        {
                            string value = match.Groups[1].Value;
                            uint   num2;
                            if (string.IsNullOrEmpty(value))
                            {
                                list.Remove(0U);
                            }
                            else if (uint.TryParse(value, out num2) && list.Contains(num2) && num2 != 0U)
                            {
                                list.Remove(num2);
                            }
                        }
                    }while (enumerator.MoveNext() && list.Count > 0);
                    if (list.Count == 0)
                    {
                        base.WriteError(new NoAvailableDefaultNamePermanentException(identifyingObjectId.ToString()), ErrorCategory.InvalidArgument, errorObject);
                        result = null;
                    }
                    else if (list.Contains(0U))
                    {
                        result = name;
                    }
                    else
                    {
                        result = string.Format("{0}{1}", name, list[0]);
                    }
                }
            }
            return(result);
        }
Beispiel #13
0
 public static bool IsInteractive(MRSRequestType requestType, RequestWorkloadType workloadType)
 {
     return(ConfigBase <MRSConfigSchema> .GetConfig <bool>("AllAggregationSyncJobsInteractive") && requestType == MRSRequestType.Sync && workloadType == RequestWorkloadType.SyncAggregation);
 }
Beispiel #14
0
        public static void ReserveLocalForestResources(ReservationContext reservation, WorkloadType workloadType, MRSRequestType requestType, RequestFlags requestFlags, Guid archiveGuid, Guid exchangeGuid, Guid sourceExchangeGuid, Guid targetExchangeGuid, TenantPartitionHint partitionHint, ADObjectId sourceDatabase, ADObjectId sourceArchiveDatabase, ADObjectId targetDatabase, ADObjectId targetArchiveDatabase, Guid sourceDatabaseGuid, Guid sourceArchiveDatabaseGuid, Guid targetDatabaseGuid, Guid targetArchiveDatabaseGuid)
        {
            ReservationFlags reservationFlags;
            Guid             guid;
            Guid             guid2;

            if (requestType == MRSRequestType.Move || requestType == MRSRequestType.MailboxRelocation)
            {
                reservationFlags = ReservationFlags.Move;
                if (requestFlags.HasFlag(RequestFlags.MoveOnlyArchiveMailbox) && archiveGuid != Guid.Empty)
                {
                    guid = archiveGuid;
                }
                else
                {
                    guid = exchangeGuid;
                }
                guid2 = guid;
            }
            else
            {
                reservationFlags = ReservationFlags.Merge;
                guid             = sourceExchangeGuid;
                guid2            = targetExchangeGuid;
            }
            if (workloadType != Microsoft.Exchange.WorkloadManagement.WorkloadType.MailboxReplicationServiceHighPriority)
            {
                switch (workloadType)
                {
                case Microsoft.Exchange.WorkloadManagement.WorkloadType.MailboxReplicationServiceInternalMaintenance:
                    reservationFlags |= ReservationFlags.InternalMaintenance;
                    break;

                case Microsoft.Exchange.WorkloadManagement.WorkloadType.MailboxReplicationServiceInteractive:
                    reservationFlags |= ReservationFlags.Interactive;
                    break;
                }
            }
            else
            {
                reservationFlags |= ReservationFlags.HighPriority;
            }
            reservation.ReserveResource((guid2 == Guid.Empty) ? guid : guid2, partitionHint, MRSResource.Id, reservationFlags);
            if (targetDatabaseGuid != Guid.Empty)
            {
                reservation.ReserveResource(guid2, partitionHint, targetDatabase, reservationFlags | ReservationFlags.Write);
            }
            if (targetArchiveDatabaseGuid != Guid.Empty && targetArchiveDatabaseGuid != targetDatabaseGuid && archiveGuid != Guid.Empty)
            {
                reservation.ReserveResource(archiveGuid, partitionHint, targetArchiveDatabase, reservationFlags | ReservationFlags.Write | ReservationFlags.Archive);
            }
            if (sourceDatabaseGuid != Guid.Empty)
            {
                reservation.ReserveResource(guid, partitionHint, sourceDatabase, reservationFlags | ReservationFlags.Read);
            }
            if (sourceArchiveDatabaseGuid != Guid.Empty && sourceArchiveDatabaseGuid != sourceDatabaseGuid && archiveGuid != Guid.Empty)
            {
                reservation.ReserveResource(archiveGuid, partitionHint, sourceArchiveDatabase, reservationFlags | ReservationFlags.Read | ReservationFlags.Archive);
            }
        }
Beispiel #15
0
 public RequestJobQueryFilter(Guid req, Guid mdb, MRSRequestType type)
 {
     this.RequestGuid = req;
     this.MdbGuid     = mdb;
     this.RequestType = new MRSRequestType?(type);
 }
Beispiel #16
0
        internal static MRSRequestWrapper Read(IConfigurationSession configSession, Guid requestGuid, MRSRequestType type)
        {
            QueryFilter filter = new ComparisonFilter(ComparisonOperator.Equal, MRSRequestSchema.MailboxMoveRequestGuid, requestGuid);
            ADObjectId  rootId = ADHandler.GetRootId(configSession, type);
            IEnumerable <MRSRequestWrapper> enumerable = configSession.FindPaged <MRSRequestWrapper>(filter, rootId, !configSession.SessionSettings.IsTenantScoped, null, 2);
            MRSRequestWrapper result = null;

            using (IEnumerator <MRSRequestWrapper> enumerator = enumerable.GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    result = enumerator.Current;
                    if (enumerator.MoveNext())
                    {
                        throw new RequestGuidNotUniquePermanentException(requestGuid.ToString(), type.ToString());
                    }
                }
            }
            return(result);
        }
        private static void CleanADOrphanAndInconsistencyForNonMoves(IConfigurationSession configSession, MRSRequestType requestType, RequestJobProvider rjProvider, Guid dbGuid)
        {
            ADObjectId requestQueueId = new ADObjectId(dbGuid);
            RequestIndexEntryQueryFilter requestIndexEntryQueryFilter = new RequestIndexEntryQueryFilter();

            requestIndexEntryQueryFilter.IndexId        = new RequestIndexId(RequestIndexLocation.AD);
            requestIndexEntryQueryFilter.RequestType    = requestType;
            requestIndexEntryQueryFilter.RequestQueueId = requestQueueId;
            MRSRequestWrapper[] array = ADHandler.Find(configSession, requestIndexEntryQueryFilter, null, true, null);
            if (array != null && array.Length > 0)
            {
                bool needUpdateAD          = false;
                MRSRequestWrapper[] array2 = array;
                for (int i = 0; i < array2.Length; i++)
                {
                    MRSRequestWrapper request = array2[i];
                    CommonUtils.CatchKnownExceptions(delegate
                    {
                        needUpdateAD = false;
                        if (request.Status != RequestStatus.None)
                        {
                            RequestStatisticsBase requestStatisticsBase = (RequestStatisticsBase)rjProvider.Read <RequestStatisticsBase>(new RequestJobObjectId(request.RequestGuid, dbGuid, null));
                            if (requestStatisticsBase == null || (!requestStatisticsBase.IsFake && requestStatisticsBase.Status == RequestStatus.None))
                            {
                                MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForRequests():AD orphan {0} found for DB {1}", new object[]
                                {
                                    request.RequestGuid,
                                    dbGuid
                                });
                                ADHandler.Delete(configSession, request);
                                return;
                            }
                            if (requestStatisticsBase.IsFake)
                            {
                                MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForRequests():request {0} is uplevel/Fake, ignoring it", new object[]
                                {
                                    request.RequestGuid
                                });
                                return;
                            }
                            if (requestStatisticsBase.IndexEntries == null || requestStatisticsBase.IndexEntries.Count == 0)
                            {
                                MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForRequests():request {0} has been removed from AD, ignoring it", new object[]
                                {
                                    request.RequestGuid
                                });
                                return;
                            }
                            if (requestStatisticsBase.TimeTracker.GetCurrentDurationChunk() > ADInconsistencyCheck.updateLatencyThreshhold)
                            {
                                if (requestStatisticsBase.Status != requestStatisticsBase.IndexEntries[0].Status)
                                {
                                    MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForRequests():AD inconsistency {0} found for DB {1}, AD status is {2} but store status is {3}", new object[]
                                    {
                                        request.RequestGuid,
                                        dbGuid,
                                        request.Status,
                                        requestStatisticsBase.Status
                                    });
                                    request.Status = requestStatisticsBase.Status;
                                    needUpdateAD   = true;
                                }
                                if (requestStatisticsBase.Flags != requestStatisticsBase.IndexEntries[0].Flags)
                                {
                                    MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForRequests():AD inconsistency {0} found for DB {1}, AD flags is {2} but store flags is {3}", new object[]
                                    {
                                        request.RequestGuid,
                                        dbGuid,
                                        request.Flags,
                                        requestStatisticsBase.Flags
                                    });
                                    request.Flags = requestStatisticsBase.Flags;
                                    needUpdateAD  = true;
                                }
                                if (needUpdateAD)
                                {
                                    ADHandler.Save(configSession, request);
                                    return;
                                }
                            }
                        }
                        else
                        {
                            MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForRequests():request {0} for {1} has been removed from AD, store orphan will be handled by MRS pick up job logic", new object[]
                            {
                                request.RequestGuid,
                                dbGuid
                            });
                        }
                    }, delegate(Exception f)
                    {
                        MrsTracer.Service.Error("CleanADOrphanAndInconsistencyForRequests() failed for DB {0}. Request type {1} Request guid {2} Error: {3}", new object[]
                        {
                            dbGuid,
                            requestType.ToString(),
                            request.RequestGuid,
                            CommonUtils.FullExceptionMessage(f, true)
                        });
                        MRSService.LogEvent(MRSEventLogConstants.Tuple_ScanADInconsistencyRequestFailEvent, new object[]
                        {
                            dbGuid,
                            requestType.ToString(),
                            request.RequestGuid,
                            CommonUtils.FullExceptionMessage(f, true)
                        });
                    });
                }
                return;
            }
            MrsTracer.Service.Debug("CleanADOrphanAndInconsistencyForRequests(): No {0} requests found for DB {1}", new object[]
            {
                requestType,
                dbGuid
            });
        }