public static void CleanADOrphanAndInconsistency() { PartitionId[] allAccountPartitionIds = ADAccountPartitionLocator.GetAllAccountPartitionIds(); for (int i = 0; i < allAccountPartitionIds.Length; i++) { PartitionId partitionId = allAccountPartitionIds[i]; CommonUtils.CheckForServiceStopping(); ADSessionSettings adsessionSettings = ADSessionSettings.FromAllTenantsPartitionId(partitionId); adsessionSettings.IncludeSoftDeletedObjects = true; adsessionSettings.IncludeInactiveMailbox = true; IRecipientSession recipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(null, false, ConsistencyMode.PartiallyConsistent, null, adsessionSettings, 45, "CleanADOrphanAndInconsistency", "f:\\15.00.1497\\sources\\dev\\mrs\\src\\Service\\ADInconsistencyCheck.cs"); IConfigurationSession configSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(null, false, ConsistencyMode.PartiallyConsistent, null, adsessionSettings, 52, "CleanADOrphanAndInconsistency", "f:\\15.00.1497\\sources\\dev\\mrs\\src\\Service\\ADInconsistencyCheck.cs"); using (List <Guid> .Enumerator enumerator = MapiUtils.GetDatabasesOnThisServer().GetEnumerator()) { while (enumerator.MoveNext()) { Guid dbGuid = enumerator.Current; CommonUtils.CheckForServiceStopping(); DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(dbGuid, null, null, FindServerFlags.AllowMissing); if (databaseInformation.IsMissing) { MrsTracer.Service.Debug("CleanADOrphanAndInconsistency Database {0} in Forest {1} is missing, skip it", new object[] { dbGuid, databaseInformation.ForestFqdn }); } else { CommonUtils.CatchKnownExceptions(delegate { ADInconsistencyCheck.CleanADOrphanAndInconsistencyForRequests(recipientSession, configSession, dbGuid); }, delegate(Exception f) { MrsTracer.Service.Error("CleanADOrphanAndInconsistency() failed for DB {0}. Error: {1}", new object[] { dbGuid, CommonUtils.FullExceptionMessage(f, true) }); MRSService.LogEvent(MRSEventLogConstants.Tuple_ScanADInconsistencyRequestFailEvent, new object[] { dbGuid, string.Empty, string.Empty, CommonUtils.FullExceptionMessage(f, true) }); }); } } } } }
private IEnumerable <string> GetForests() { Dictionary <string, bool> dictionary = new Dictionary <string, bool>(StringComparer.InvariantCultureIgnoreCase); if (ADResourceHealthMonitor.isMultiTenancyEnabled) { foreach (PartitionId partitionId in ADAccountPartitionLocator.GetAllAccountPartitionIds()) { dictionary[partitionId.ForestFQDN] = true; } } dictionary[TopologyProvider.LocalForestFqdn] = true; return(dictionary.Keys); }
// Token: 0x06000C79 RID: 3193 RVA: 0x000272A4 File Offset: 0x000254A4 internal OrganizationId ResolveOrganizationId() { if (string.IsNullOrEmpty(base.RawIdentity) || string.IsNullOrEmpty(base.RawIdentity.Trim())) { throw new ArgumentException("Cannot resolve tenant name - RawIdentity is null or empty"); } ExchangeConfigurationUnit exchangeConfigurationUnit = null; try { PartitionId partitionId = ADAccountPartitionLocator.GetPartitionIdByAcceptedDomainName(base.RawIdentity); ADSessionSettings adsessionSettings = ADSessionSettings.FromAllTenantsPartitionId(partitionId); adsessionSettings.TenantConsistencyMode = TenantConsistencyMode.IncludeRetiredTenants; ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, adsessionSettings, 142, "ResolveOrganizationId", "f:\\15.00.1497\\sources\\dev\\Configuration\\src\\ObjectModel\\IdentityParameter\\TenantRelocationRequestIdParameter.cs"); exchangeConfigurationUnit = tenantConfigurationSession.GetExchangeConfigurationUnitByName(base.RawIdentity); } catch (CannotResolveTenantNameException) { } if (exchangeConfigurationUnit == null) { foreach (PartitionId partitionId2 in ADAccountPartitionLocator.GetAllAccountPartitionIds()) { ADSessionSettings adsessionSettings2 = ADSessionSettings.FromAllTenantsPartitionId(partitionId2); adsessionSettings2.TenantConsistencyMode = TenantConsistencyMode.IncludeRetiredTenants; ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, adsessionSettings2, 160, "ResolveOrganizationId", "f:\\15.00.1497\\sources\\dev\\Configuration\\src\\ObjectModel\\IdentityParameter\\TenantRelocationRequestIdParameter.cs"); exchangeConfigurationUnit = tenantConfigurationSession.GetExchangeConfigurationUnitByName(base.RawIdentity); if (exchangeConfigurationUnit != null) { break; } } } if (exchangeConfigurationUnit != null && !string.IsNullOrEmpty(exchangeConfigurationUnit.RelocationSourceForestRaw)) { PartitionId partitionId = new PartitionId(exchangeConfigurationUnit.RelocationSourceForestRaw); ADSessionSettings adsessionSettings = ADSessionSettings.FromAllTenantsPartitionId(partitionId); adsessionSettings.TenantConsistencyMode = TenantConsistencyMode.IncludeRetiredTenants; ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, adsessionSettings, 175, "ResolveOrganizationId", "f:\\15.00.1497\\sources\\dev\\Configuration\\src\\ObjectModel\\IdentityParameter\\TenantRelocationRequestIdParameter.cs"); exchangeConfigurationUnit = tenantConfigurationSession.GetExchangeConfigurationUnitByName(base.RawIdentity); } if (exchangeConfigurationUnit != null) { return(exchangeConfigurationUnit.OrganizationId); } throw new CannotResolveTenantNameException(DirectoryStrings.CannotResolveTenantRelocationRequestIdentity(base.RawIdentity)); }
protected override void InternalValidate() { TaskLogger.LogEnter(); try { base.InternalValidate(); if (!base.HasErrors) { this.ServerObject = TestTopologyServiceTask.EnsureSingleObject <Server>(() => this.Server.GetObjects <Server>(null, this.SystemConfigurationSession)); if (this.ServerObject == null) { throw new CasHealthMailboxServerNotFoundException(this.Server.ToString()); } if (this.PartitionFqdn == null) { PartitionId[] array = Globals.IsDatacenter ? ADAccountPartitionLocator.GetAllAccountPartitionIds() : new PartitionId[] { PartitionId.LocalForest }; this.PartitionFqdn = array[new Random().Next(0, array.Length)].ForestFQDN; } if (this.TargetDomainController == null && (this.OperationType == TopologyServiceOperationTypeEnum.ReportServerDown || this.OperationType == TopologyServiceOperationTypeEnum.SetConfigDC)) { throw new TopologyServiceMissingDC(this.OperationType.ToString()); } } } catch (LocalizedException exception) { this.WriteError(exception, ErrorCategory.OperationStopped, this, true); } finally { TaskLogger.LogExit(); } }
private IList <ExchangePrincipal> GetSyncMailboxPrincipals(Guid mailboxDatabaseGuid, IDirectorySession configSession) { List <ExchangePrincipal> list = new List <ExchangePrincipal>(); ADObjectId id = new ADObjectId(mailboxDatabaseGuid); Result <MailboxDatabase>[] dataBases = null; ADOperationResult adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate() { dataBases = configSession.FindByADObjectIds <MailboxDatabase>(new ADObjectId[] { id }); }, 3); if (!adoperationResult.Succeeded) { this.logger.LogOneEntry("NotificationLoader", string.Empty, ExecutionLog.EventType.Error, string.Format("GetSyncMailboxPrincipals: failed to find database {0} in active directory because of {1}", mailboxDatabaseGuid, adoperationResult.Exception), adoperationResult.Exception); } if (dataBases != null && dataBases.Length > 0) { PartitionId[] allAccountPartitionIds = ADAccountPartitionLocator.GetAllAccountPartitionIds(); for (int i = 0; i < allAccountPartitionIds.Length; i++) { PartitionId partitionId = allAccountPartitionIds[i]; IRecipientSession recipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 238, "GetSyncMailboxPrincipals", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\UnifiedPolicy\\NotificationLoader.cs"); ADUser[] arbMbxs = null; adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate() { arbMbxs = recipientSession.FindPaged <ADUser>(RecipientFilterHelper.DiscoveryMailboxFilterUnifiedPolicy(dataBases[0].Data.Id), null, true, null, 0).ToArray <ADUser>(); }, 3); if (!adoperationResult.Succeeded) { this.logger.LogOneEntry("NotificationLoader", string.Empty, ExecutionLog.EventType.Error, string.Format("GetSyncMailboxPrincipals: failed to find sync mailboxes in database {0} in active directory because of {1}", mailboxDatabaseGuid, adoperationResult.Exception), adoperationResult.Exception); } if (arbMbxs != null && arbMbxs.Length > 0) { ADUser[] arbMbxs2 = arbMbxs; int j = 0; while (j < arbMbxs2.Length) { ADUser aduser = arbMbxs2[j]; this.logger.LogOneEntry("NotificationLoader", string.Empty, ExecutionLog.EventType.Verbose, string.Format("GetSyncMailboxPrincipals: found sync mailbox {0} in database {1} in partition {2}", aduser.UserPrincipalName, mailboxDatabaseGuid, partitionId), null); ExchangePrincipal item = null; try { item = ExchangePrincipal.FromADUser(ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(aduser.OrganizationId), aduser, RemotingOptions.LocalConnectionsOnly); } catch (StoragePermanentException exception) { this.logger.LogOneEntry("NotificationLoader", string.Empty, ExecutionLog.EventType.Error, string.Format("GetSyncMailboxPrincipals: sync mailbox {0} is skipped because of StoragePermanentException in ExchangePrincipal construction", aduser.UserPrincipalName), exception); goto IL_20F; } catch (StorageTransientException exception2) { this.logger.LogOneEntry("NotificationLoader", string.Empty, ExecutionLog.EventType.Error, string.Format("GetSyncMailboxPrincipals: sync mailbox {0} is skipped because of StorageTransientException in ExchangePrincipal construction", aduser.UserPrincipalName), exception2); goto IL_20F; } goto IL_207; IL_20F: j++; continue; IL_207: list.Add(item); goto IL_20F; } } else { this.logger.LogOneEntry("NotificationLoader", string.Empty, ExecutionLog.EventType.Verbose, string.Format("GetSyncMailboxPrincipals: there is no sync mailboxes in database {0} in active directory", mailboxDatabaseGuid), null); } } } return(list); }