Ejemplo n.º 1
0
        public DatabaseSettingsContext(Guid mdbGuid, SettingsContextBase nextContext = null) : base(mdbGuid, nextContext)
        {
            DatabaseLocationInfo databaseLocationInfo = null;

            try
            {
                databaseLocationInfo = ActiveManager.GetCachingActiveManagerInstance().GetServerForDatabase(mdbGuid, GetServerForDatabaseFlags.IgnoreAdSiteBoundary | GetServerForDatabaseFlags.BasicQuery);
            }
            catch (ObjectNotFoundException)
            {
            }
            if (databaseLocationInfo != null)
            {
                this.databaseName    = databaseLocationInfo.DatabaseName;
                this.databaseVersion = databaseLocationInfo.AdminDisplayVersion;
                this.serverName      = databaseLocationInfo.ServerFqdn;
                this.serverVersion   = new ServerVersion(databaseLocationInfo.ServerVersion);
                this.serverGuid      = new Guid?(databaseLocationInfo.ServerGuid);
                return;
            }
            this.databaseName    = string.Empty;
            this.databaseVersion = new ServerVersion(0);
            this.serverName      = string.Empty;
            this.serverVersion   = new ServerVersion(0);
            this.serverGuid      = new Guid?(Guid.Empty);
        }
Ejemplo n.º 2
0
        // Token: 0x06001208 RID: 4616 RVA: 0x00037FB4 File Offset: 0x000361B4
        internal static MailboxDatabaseWithLocationInfo FindDatabaseAndLocationForEnterpriseSiteMailbox(string domainController, LogMessageDelegate logger, ScopeSet scopeSet)
        {
            PhysicalResourceLoadBalancing.LogVerbose(Strings.VerboseLbEnterSiteMailboxEnterprise, logger);
            ITopologyConfigurationSession configSession = PhysicalResourceLoadBalancing.CreateGlobalConfigSession(domainController);
            List <MailboxDatabase>        databasesForProvisioningCached = PhysicalResourceLoadBalancing.GetDatabasesForProvisioningCached(configSession, false, logger);

            if (databasesForProvisioningCached.Count == 0)
            {
                PhysicalResourceLoadBalancing.LogVerbose(Strings.VerboseLbNoAvailableDatabase, logger);
                return(null);
            }
            List <MailboxDatabase> list = new List <MailboxDatabase>();

            foreach (MailboxDatabase mailboxDatabase in databasesForProvisioningCached)
            {
                if (mailboxDatabase.AdminDisplayVersion == null)
                {
                    mailboxDatabase.AdminDisplayVersion = Server.GetServerVersion(mailboxDatabase.ServerName);
                }
                if (mailboxDatabase.AdminDisplayVersion.Major >= PhysicalResourceLoadBalancing.MajorVersionE15)
                {
                    list.Add(mailboxDatabase);
                }
            }
            if (list.Count == 0)
            {
                PhysicalResourceLoadBalancing.LogVerbose(Strings.VerboseLbNoAvailableE15Database(databasesForProvisioningCached.Count), logger);
                return(null);
            }
            ActiveManager cachingActiveManagerInstance = ActiveManager.GetCachingActiveManagerInstance();
            Random        random = new Random();

            while (list.Count != 0)
            {
                int             index            = random.Next(list.Count);
                MailboxDatabase mailboxDatabase2 = list[index];
                list.RemoveAt(index);
                PhysicalResourceLoadBalancing.LogVerbose(Strings.VerboseLbGetServerForActiveDatabaseCopy(mailboxDatabase2.Name), logger);
                DatabaseLocationInfo serverForActiveDatabaseCopy = PhysicalResourceLoadBalancing.GetServerForActiveDatabaseCopy(mailboxDatabase2, cachingActiveManagerInstance, logger);
                if (serverForActiveDatabaseCopy != null)
                {
                    MailboxDatabaseWithLocationInfo mailboxDatabaseWithLocationInfo = new MailboxDatabaseWithLocationInfo(mailboxDatabase2, serverForActiveDatabaseCopy);
                    if (mailboxDatabase2.MasterType == MasterType.DatabaseAvailabilityGroup)
                    {
                        PhysicalResourceLoadBalancing.LogVerbose(Strings.VerboseLbRemoteSiteDatabaseReturned(mailboxDatabaseWithLocationInfo.MailboxDatabase.Name, mailboxDatabaseWithLocationInfo.DatabaseLocationInfo.ServerFqdn), logger);
                        return(mailboxDatabaseWithLocationInfo);
                    }
                    mailboxDatabaseWithLocationInfo = PhysicalResourceLoadBalancing.VerifyStatusAndSelectDB(new List <MailboxDatabaseWithLocationInfo>
                    {
                        mailboxDatabaseWithLocationInfo
                    }, domainController, logger, scopeSet);
                    if (mailboxDatabaseWithLocationInfo != null)
                    {
                        return(mailboxDatabaseWithLocationInfo);
                    }
                }
            }
            return(null);
        }
        private bool IsFirstActiveMdbLocallyMounted()
        {
            IList <Database> list;

            if (!base.SourceMailboxServer.IsMailboxServer || !CrossPremiseTestMailFlowHelper.TryLoadAdObjects <Database>(base.Task.ConfigurationSession, this.adAdminGroups, out list))
            {
                return(false);
            }
            ActiveManager             cachingActiveManagerInstance = ActiveManager.GetCachingActiveManagerInstance();
            SortedList <Guid, string> sortedList = new SortedList <Guid, string>();

            try
            {
                foreach (Database database in list)
                {
                    DatabaseLocationInfo serverForDatabase = cachingActiveManagerInstance.GetServerForDatabase(database.Guid, GetServerForDatabaseFlags.None);
                    if (serverForDatabase != null && serverForDatabase.ServerSite != null && serverForDatabase.ServerSite.Equals(this.localSite) && !string.IsNullOrEmpty(serverForDatabase.ServerFqdn))
                    {
                        sortedList.Add(database.Guid, serverForDatabase.ServerFqdn);
                    }
                }
                using (IEnumerator <KeyValuePair <Guid, string> > enumerator2 = sortedList.GetEnumerator())
                {
                    while (enumerator2.MoveNext())
                    {
                        KeyValuePair <Guid, string> kvp = enumerator2.Current;
                        Database database2 = list.ToList <Database>().Find(delegate(Database db)
                        {
                            Guid guid = db.Guid;
                            KeyValuePair <Guid, string> kvp3 = kvp;
                            return(guid == kvp3.Key);
                        });
                        Database mdb = database2;
                        KeyValuePair <Guid, string> kvp4 = kvp;
                        if (base.IsMdbMounted(mdb, kvp4.Value))
                        {
                            KeyValuePair <Guid, string> kvp2 = kvp;
                            return(kvp2.Value.Equals(base.SourceMailboxServer.Fqdn, StringComparison.OrdinalIgnoreCase));
                        }
                    }
                }
                return(false);
            }
            catch (ObjectNotFoundException ex)
            {
                base.Task.WriteWarning(Strings.CrossPremiseMapMdbToServerFailure(ex.ToString()));
            }
            catch (StoragePermanentException ex2)
            {
                base.Task.WriteWarning(Strings.CrossPremiseMapMdbToServerFailure(ex2.ToString()));
            }
            catch (StorageTransientException ex3)
            {
                base.Task.WriteWarning(Strings.CrossPremiseMapMdbToServerFailure(ex3.ToString()));
            }
            return(false);
        }
Ejemplo n.º 4
0
        private static string GetServerFqdn(Guid databaseGuid)
        {
            DatabaseLocationInfo serverForDatabase = ActiveManager.GetCachingActiveManagerInstance().GetServerForDatabase(databaseGuid);

            if (serverForDatabase == null)
            {
                throw new MigrationMailboxDatabaseInfoNotAvailableException(databaseGuid.ToString());
            }
            return(serverForDatabase.ServerFqdn);
        }
        // Token: 0x0600003B RID: 59 RVA: 0x00002568 File Offset: 0x00000768
        public string GetDatabaseServerFqdn(Guid mdbGuid, bool forceRediscovery)
        {
            GetServerForDatabaseFlags gsfdFlags = forceRediscovery ? GetServerForDatabaseFlags.ReadThrough : GetServerForDatabaseFlags.None;
            string serverFqdn;

            try
            {
                DatabaseLocationInfo serverForDatabase = ActiveManager.GetCachingActiveManagerInstance().GetServerForDatabase(mdbGuid, gsfdFlags);
                if (serverForDatabase == null)
                {
                    throw new MigrationMailboxDatabaseInfoNotAvailableException(mdbGuid.ToString());
                }
                serverFqdn = serverForDatabase.ServerFqdn;
            }
            catch (ObjectNotFoundException ex)
            {
                string text = string.Format("Server for mailbox with Guid {0} not found in ActiveManager using forceDiscovery set to {1}", mdbGuid, forceRediscovery);
                this.Context.Logger.Log(MigrationEventType.Error, ex, text, new object[0]);
                throw new AnchorDatabaseNotFoundTransientException(mdbGuid.ToString(), ex)
                      {
                          InternalError = text
                      };
            }
            catch (StoragePermanentException exception)
            {
                this.Context.Logger.Log(MigrationEventType.Error, exception, "Server for mailbox with Guid {0} not found in ActiveManager using forceDiscovery set to {1}", new object[]
                {
                    mdbGuid,
                    forceRediscovery
                });
                throw;
            }
            catch (StorageTransientException exception2)
            {
                this.Context.Logger.Log(MigrationEventType.Error, exception2, "Server for mailbox with Guid {0} not found in ActiveManager using forceDiscovery set to {1}", new object[]
                {
                    mdbGuid,
                    forceRediscovery
                });
                throw;
            }
            catch (ServerForDatabaseNotFoundException ex2)
            {
                string text2 = string.Format("Server for mailbox with Guid {0} not found in ActiveManager using forceDiscovery set to {1}", mdbGuid, forceRediscovery);
                this.Context.Logger.Log(MigrationEventType.Error, ex2, text2, new object[0]);
                throw new AnchorServerNotFoundTransientException(mdbGuid.ToString(), ex2)
                      {
                          InternalError = text2
                      };
            }
            return(serverFqdn);
        }
        // Token: 0x06000818 RID: 2072 RVA: 0x00021380 File Offset: 0x0001F580
        private BackEndServer GetLegacyServerForDatabase(Guid databaseGuid)
        {
            this.Tracer.TraceDebug <Guid>((long)this.GetHashCode(), "[MailboxServerLocator.GetLegacyServerForDatabase] Resolving legacy server for database {0}.", databaseGuid);
            ActiveManager        cachingActiveManagerInstance = ActiveManager.GetCachingActiveManagerInstance();
            DatabaseLocationInfo serverForDatabase            = cachingActiveManagerInstance.GetServerForDatabase(databaseGuid);

            if (serverForDatabase != null)
            {
                this.Tracer.TraceDebug <Guid, string>((long)this.GetHashCode(), "[MailboxServerLocator.GetLegacyServerForDatabase] Active manager returns server {1} for database {0}.", databaseGuid, serverForDatabase.ServerFqdn);
                return(new BackEndServer(serverForDatabase.ServerFqdn, serverForDatabase.ServerVersion));
            }
            throw new MailboxServerLocatorException(this.DatabaseGuid.ToString());
        }
Ejemplo n.º 7
0
        private bool IsUserAllowedForUnifiedMessaging(ADUser user)
        {
            bool result = true;

            if (user != null && user.Database != null)
            {
                DatabaseLocationInfo serverForDatabase = ActiveManager.GetCachingActiveManagerInstance().GetServerForDatabase(user.Database.ObjectGuid);
                if (serverForDatabase != null && serverForDatabase.AdminDisplayVersion.Major > (int)ExchangeObjectVersion.Exchange2010.ExchangeBuild.Major && (serverForDatabase.AdminDisplayVersion.Major != 15 || serverForDatabase.AdminDisplayVersion.Minor > 1))
                {
                    result = false;
                }
            }
            return(result);
        }
Ejemplo n.º 8
0
        internal string GetClientAccessServerLegacyDN(string userLegacyDN)
        {
            Guid          guid = Guid.Empty;
            NspiPrincipal nspiPrincipal;

            if (string.IsNullOrEmpty(userLegacyDN) || LegacyDN.StringComparer.Equals(userLegacyDN, this.LegacyDistinguishedName))
            {
                this.protocolLogSession[ProtocolLog.Field.OperationSpecific] = "Self";
                nspiPrincipal = this.nspiPrincipal;
            }
            else
            {
                this.protocolLogSession[ProtocolLog.Field.OperationSpecific] = "Other";
                nspiPrincipal = this.NspiPrincipalFromLegacyDN(userLegacyDN);
                if (nspiPrincipal == null)
                {
                    return(null);
                }
            }
            if (nspiPrincipal.Database == null)
            {
                return(null);
            }
            guid = nspiPrincipal.Database.ObjectGuid;
            if (guid == Guid.Empty)
            {
                return(null);
            }
            LegacyDN legacyDN;

            try
            {
                ADObjectId adobjectId;
                ActiveManager.GetCachingActiveManagerInstance().CalculatePreferredHomeServer(guid, out legacyDN, out adobjectId);
            }
            catch (DatabaseNotFoundException)
            {
                legacyDN = null;
            }
            if (legacyDN == null)
            {
                return(null);
            }
            return(legacyDN.ToString());
        }
Ejemplo n.º 9
0
        // Token: 0x06001206 RID: 4614 RVA: 0x00037DC8 File Offset: 0x00035FC8
        internal static MailboxDatabaseWithLocationInfo FindDatabaseAndLocation(string domainController, LogMessageDelegate logger, ScopeSet scopeSet, bool isInitialProvisioning, bool localSiteDatabasesOnly, int?qualifiedMinServerVersion, IMailboxProvisioningConstraint mailboxProvisioningConstraint, IEnumerable <ADObjectId> excludedDatabaseIds, ref LoadBalancingReport loadBalancingReport)
        {
            ITopologyConfigurationSession configSession = PhysicalResourceLoadBalancing.CreateGlobalConfigSession(domainController);
            List <MailboxDatabase>        databasesForProvisioningCached = PhysicalResourceLoadBalancing.GetDatabasesForProvisioningCached(configSession, localSiteDatabasesOnly, logger);
            List <MailboxDatabase>        list;

            if (mailboxProvisioningConstraint != null || excludedDatabaseIds != null)
            {
                list = PhysicalResourceLoadBalancing.FilterEligibleDatabase(logger, databasesForProvisioningCached.GetRange(0, databasesForProvisioningCached.Count), mailboxProvisioningConstraint, excludedDatabaseIds);
            }
            else
            {
                list = databasesForProvisioningCached.GetRange(0, databasesForProvisioningCached.Count);
            }
            if (list.Count == 0)
            {
                PhysicalResourceLoadBalancing.LogVerbose(Strings.VerboseLbNoAvailableDatabase, logger);
                return(null);
            }
            LoadBalancingReport loadBalancingReport2 = loadBalancingReport ?? new LoadBalancingReport();

            loadBalancingReport2.enabledDatabasesWithLocalCopyCount = list.Count;
            ActiveManager cachingActiveManagerInstance = ActiveManager.GetCachingActiveManagerInstance();

            if (PhysicalResourceLoadBalancing.IsDatacenter)
            {
                return(PhysicalResourceLoadBalancing.FindDatabaseAndLocation(list, cachingActiveManagerInstance, isInitialProvisioning, localSiteDatabasesOnly, logger, ref loadBalancingReport2));
            }
            List <MailboxDatabaseWithLocationInfo> list2 = new List <MailboxDatabaseWithLocationInfo>(list.Count);

            foreach (MailboxDatabase mailboxDatabase in list)
            {
                DatabaseLocationInfo serverForActiveDatabaseCopy = PhysicalResourceLoadBalancing.GetServerForActiveDatabaseCopy(mailboxDatabase, cachingActiveManagerInstance, logger);
                if (serverForActiveDatabaseCopy != null && PhysicalResourceLoadBalancing.IsDatabaseInLocalSite(serverForActiveDatabaseCopy, logger) && (qualifiedMinServerVersion == null || serverForActiveDatabaseCopy.ServerVersion >= qualifiedMinServerVersion.Value))
                {
                    list2.Add(new MailboxDatabaseWithLocationInfo(mailboxDatabase, serverForActiveDatabaseCopy));
                }
            }
            return(PhysicalResourceLoadBalancing.VerifyStatusAndSelectDB(list2, domainController, logger, scopeSet));
        }
Ejemplo n.º 10
0
        private ExRpcAdmin GetExRpcAdminForDatabase(DirectoryDatabase database)
        {
            ActiveManager        activeManager     = LoadBalanceADSettings.Instance.Value.UseCachingActiveManager ? ActiveManager.GetCachingActiveManagerInstance() : ActiveManager.GetNoncachingActiveManagerInstance();
            DatabaseLocationInfo serverForDatabase = activeManager.GetServerForDatabase(database.Guid, true);

            return(ExRpcAdmin.Create("Client=MSExchangeMailboxLoadBalance", serverForDatabase.ServerFqdn, null, null, null));
        }
 public DatabaseLocationProvider() : this(ActiveManager.GetCachingActiveManagerInstance(), NullPerformanceDataLogger.Instance)
 {
 }
Ejemplo n.º 12
0
        public static DatabaseInformation FindServerForMdb(Guid mdbGuid, string dcName, NetworkCredential cred, FindServerFlags flags)
        {
            Guid systemMailboxGuid = Guid.Empty;

            if (flags.HasFlag(FindServerFlags.FindSystemMailbox))
            {
                systemMailboxGuid = MapiUtils.GetSystemMailboxGuid(mdbGuid, dcName, cred, flags);
            }
            if (cred == null)
            {
                try
                {
                    GetServerForDatabaseFlags getServerForDatabaseFlags = GetServerForDatabaseFlags.IgnoreAdSiteBoundary;
                    if (flags.HasFlag(FindServerFlags.ForceRediscovery))
                    {
                        MrsTracer.Common.Debug("Looking up MDB {0} with rediscovery", new object[]
                        {
                            mdbGuid
                        });
                        getServerForDatabaseFlags |= GetServerForDatabaseFlags.ReadThrough;
                    }
                    DatabaseLocationInfo serverForDatabase = ActiveManager.GetCachingActiveManagerInstance().GetServerForDatabase(mdbGuid, getServerForDatabaseFlags);
                    if (serverForDatabase != null)
                    {
                        return(DatabaseInformation.FromDatabaseLocationInfo(mdbGuid, serverForDatabase, systemMailboxGuid));
                    }
                }
                catch (ObjectNotFoundException)
                {
                }
                MrsTracer.Common.Debug("ActiveManager was unable to locate MDB {0}, will search AD instead.", new object[]
                {
                    mdbGuid
                });
            }
            ITopologyConfigurationSession topologyConfigurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(dcName, true, ConsistencyMode.PartiallyConsistent, cred, ADSessionSettings.FromRootOrgScopeSet(), 686, "FindServerForMdb", "f:\\15.00.1497\\sources\\dev\\mrs\\src\\Common\\MapiUtils.cs");
            Database database = topologyConfigurationSession.FindDatabaseByGuid <Database>(mdbGuid);

            if (database == null)
            {
                MrsTracer.Common.Error("Unable to locate MDB by guid {0}", new object[]
                {
                    mdbGuid
                });
                if (!flags.HasFlag(FindServerFlags.AllowMissing))
                {
                    throw new DatabaseNotFoundByGuidPermanentException(mdbGuid);
                }
                return(DatabaseInformation.Missing(mdbGuid, PartitionId.LocalForest.ForestFQDN));
            }
            else
            {
                PropertyDefinition[] properties = new PropertyDefinition[]
                {
                    ServerSchema.ExchangeLegacyDN,
                    ServerSchema.Fqdn,
                    ServerSchema.ServerSite,
                    ServerSchema.VersionNumber,
                    ActiveDirectoryServerSchema.MailboxRelease
                };
                MiniServer miniServer = topologyConfigurationSession.ReadMiniServer(database.Server, properties);
                if (miniServer != null)
                {
                    return(DatabaseInformation.FromAD(database, miniServer, systemMailboxGuid));
                }
                MrsTracer.Common.Error("Unable to locate DB server {0}", new object[]
                {
                    database.Server.DistinguishedName
                });
                if ((flags & FindServerFlags.AllowMissing) == FindServerFlags.None)
                {
                    throw new UnexpectedErrorPermanentException(-2147221233);
                }
                return(DatabaseInformation.Missing(mdbGuid, PartitionId.LocalForest.ForestFQDN));
            }
        }