private static UpgradeStage MapMailboxTypeToUpgradeStage(UpgradeBatchCreatorScheduler.MailboxType mailboxType) { switch (mailboxType) { case UpgradeBatchCreatorScheduler.MailboxType.Regular: case UpgradeBatchCreatorScheduler.MailboxType.Discovery: case UpgradeBatchCreatorScheduler.MailboxType.RegularSoftDeleted: return(UpgradeStage.MoveRegularUser); case UpgradeBatchCreatorScheduler.MailboxType.RegularPilot: return(UpgradeStage.MoveRegularPilot); case UpgradeBatchCreatorScheduler.MailboxType.Arbitration: return(UpgradeStage.MoveArbitration); case UpgradeBatchCreatorScheduler.MailboxType.CloudOnlyArchive: case UpgradeBatchCreatorScheduler.MailboxType.CloudOnlyArchiveSoftDeleted: return(UpgradeStage.MoveCloudOnlyArchive); case UpgradeBatchCreatorScheduler.MailboxType.CloudOnlyArchivePilot: return(UpgradeStage.MoveCloudOnlyArchivePilot); default: throw new ArgumentException(string.Format("Not recognized mailbox type {0}", mailboxType)); } }
private QueryFilter GetFilterByBatchType(UpgradeBatchCreatorScheduler.MailboxType mailboxType) { QueryFilter queryFilter; switch (mailboxType) { case UpgradeBatchCreatorScheduler.MailboxType.Regular: case UpgradeBatchCreatorScheduler.MailboxType.RegularSoftDeleted: queryFilter = UpgradeBatchCreatorScheduler.e14MailboxQueryFilter; break; case UpgradeBatchCreatorScheduler.MailboxType.RegularPilot: queryFilter = new AndFilter(new QueryFilter[] { UpgradeBatchCreatorScheduler.e14MailboxQueryFilter, new ComparisonFilter(ComparisonOperator.Equal, ADRecipientSchema.UpgradeRequest, UpgradeRequestTypes.PilotUpgrade) }); break; case UpgradeBatchCreatorScheduler.MailboxType.Arbitration: queryFilter = new AndFilter(new QueryFilter[] { UpgradeBatchCreatorScheduler.e14MailboxQueryFilter, new ComparisonFilter(ComparisonOperator.Equal, ADRecipientSchema.RecipientTypeDetailsValue, RecipientTypeDetails.ArbitrationMailbox) }); break; case UpgradeBatchCreatorScheduler.MailboxType.Discovery: queryFilter = new AndFilter(new QueryFilter[] { UpgradeBatchCreatorScheduler.e14MailboxQueryFilter, new ComparisonFilter(ComparisonOperator.Equal, ADRecipientSchema.RecipientTypeDetailsValue, RecipientTypeDetails.DiscoveryMailbox) }); break; case UpgradeBatchCreatorScheduler.MailboxType.CloudOnlyArchive: case UpgradeBatchCreatorScheduler.MailboxType.CloudOnlyArchivePilot: case UpgradeBatchCreatorScheduler.MailboxType.CloudOnlyArchiveSoftDeleted: queryFilter = new AndFilter(new QueryFilter[] { new ComparisonFilter(ComparisonOperator.Equal, ADRecipientSchema.RecipientTypeDetailsValue, RecipientTypeDetails.MailUser), new ExistsFilter(IADMailStorageSchema.ArchiveDatabaseRaw), new ComparisonFilter(ComparisonOperator.NotEqual, ADUserSchema.ArchiveRelease, MailboxRelease.E15.ToString()) }); if (mailboxType == UpgradeBatchCreatorScheduler.MailboxType.CloudOnlyArchivePilot) { queryFilter = new AndFilter(new QueryFilter[] { queryFilter, new ComparisonFilter(ComparisonOperator.Equal, ADRecipientSchema.UpgradeRequest, UpgradeRequestTypes.PilotUpgrade) }); } break; default: throw new UnsupportedBatchTypeException(mailboxType.ToString()); } return(queryFilter); }
public IEnumerable <RecipientWrapper> FindPagedMiniRecipient(UpgradeBatchCreatorScheduler.MailboxType mailboxType, ADObjectId rootId, QueryScope scope, QueryFilter filter, SortBy sortBy, int pageSize, IEnumerable <PropertyDefinition> properties) { ADPagedReader <MiniRecipient> pagedReader = this.anchorAdProvider.FindPagedMiniRecipient <MiniRecipient>(rootId, scope, filter, sortBy, pageSize, properties); foreach (MiniRecipient recipient in pagedReader) { RequestStatus moveStatus = (RequestStatus)recipient[SharedPropertyDefinitions.MailboxMoveStatus]; string moveBatchName = (string)recipient[SharedPropertyDefinitions.MailboxMoveBatchName]; RequestFlags requestFlags = (RequestFlags)recipient[SharedPropertyDefinitions.MailboxMoveFlags]; RecipientWrapper wrappedRecipient = new RecipientWrapper(recipient.Id, moveStatus, moveBatchName, requestFlags, recipient.RecipientType, recipient.RecipientTypeDetails); yield return(wrappedRecipient); } yield break; }
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")); } } }