internal static void UpdateServerLegdnForDatabaseSite(Task.TaskErrorLoggingDelegate writeErrorDelegate, Task.TaskVerboseLoggingDelegate writeVerboseDelegate, ITopologyConfigurationSession adSession, DatabaseCopy dbCopy)
        {
            ADObjectId hostServer = dbCopy.HostServer;

            PropertyDefinition[] properties = new PropertyDefinition[]
            {
                ServerSchema.ServerSite
            };
            MiniServer miniServer = adSession.ReadMiniServer(hostServer, properties);

            if (miniServer == null)
            {
                writeErrorDelegate(new ADServerNotFoundException(hostServer.ToString()), ErrorCategory.InvalidArgument, null);
            }
            IADToplogyConfigurationSession adSession2 = ADSessionFactory.CreateWrapper(adSession);
            SimpleAdObjectLookup <IADClientAccessArray> findClientAccessArray      = new SimpleAdObjectLookup <IADClientAccessArray>(adSession2);
            SimpleMiniClientAccessServerOrArrayLookup   findMiniClientAccessServer = new SimpleMiniClientAccessServerOrArrayLookup(adSession);
            ADObjectId serverSite = miniServer.ServerSite;
            LegacyDN   legacyDN   = ActiveManagerImplementation.FindClientAccessArrayOrServerFromSite(serverSite, miniServer.Id, findClientAccessArray, findMiniClientAccessServer, AdObjectLookupFlags.ReadThrough);
            ADObjectId parent     = dbCopy.Id.Parent;
            Database   database   = adSession.Read <Database>(parent);

            if (legacyDN != null)
            {
                LegacyDN databaseLegacyDNFromRcaLegacyDN = Database.GetDatabaseLegacyDNFromRcaLegacyDN(legacyDN, database.IsPublicFolderDatabase);
                database.ExchangeLegacyDN = databaseLegacyDNFromRcaLegacyDN.ToString();
                writeVerboseDelegate(Strings.UpdatingLegDnForDatabaseToServer(database.Name, legacyDN.ToString(), legacyDN.ToString()));
                adSession.Save(database);
                return;
            }
            ExTraceGlobals.CmdletsTracer.TraceDebug <ADObjectId>(0L, "Could not find a new CAS machines for site '{0}'. Leaving the database's legdn unchanged.", serverSite);
        }
Ejemplo n.º 2
0
        internal static void CalculatePreferredHomeServerInternal(ActiveManager activeManager, IADDatabase database, ITopologyConfigurationSession adSession, IFindAdObject <IADDatabaseAvailabilityGroup> dagLookup, IFindAdObject <IADClientAccessArray> findClientAccessArray, IFindMiniClientAccessServerOrArray findMiniClientAccessServer, out LegacyDN preferredRpcClientAccessServerLegacyDN, out ADObjectId preferredServerSite)
        {
            Util.ThrowOnNullArgument(activeManager, "activeManager");
            preferredRpcClientAccessServerLegacyDN = LegacyDN.Parse(database.RpcClientAccessServerLegacyDN);
            ADObjectId masterServerOrAvailabilityGroup = database.MasterServerOrAvailabilityGroup;
            IADDatabaseAvailabilityGroup iaddatabaseAvailabilityGroup = (masterServerOrAvailabilityGroup != null) ? dagLookup.ReadAdObjectByObjectId(masterServerOrAvailabilityGroup) : null;

            if (iaddatabaseAvailabilityGroup == null || !iaddatabaseAvailabilityGroup.AllowCrossSiteRpcClientAccess)
            {
                ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <ADObjectId, ADObjectId>((long)activeManager.GetHashCode(), "CalculatePreferredHomeServerInternal: Cross-site is not allowed. Database = '{0}', DAG = '{1}'", database.Id, masterServerOrAvailabilityGroup);
                DatabaseLocationInfo databaseLocationInfo = null;
                preferredServerSite = null;
                try
                {
                    databaseLocationInfo = activeManager.GetServerForDatabase(database.Guid, GetServerForDatabaseFlags.IgnoreAdSiteBoundary, NullPerformanceDataLogger.Instance);
                    if (databaseLocationInfo != null)
                    {
                        preferredServerSite = databaseLocationInfo.ServerSite;
                    }
                }
                catch (DatabaseNotFoundException arg)
                {
                    ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <ADObjectId, DatabaseNotFoundException>((long)activeManager.GetHashCode(), "CalculatePreferredHomeServerInternal: The database '{0}' does not exist. Exception = {1}", database.Id, arg);
                    preferredServerSite = null;
                }
                catch (ObjectNotFoundException arg2)
                {
                    ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <ADObjectId, ObjectNotFoundException>((long)activeManager.GetHashCode(), "CalculatePreferredHomeServerInternal: Server hosting the database {0} cannot be found. Exception = {1}", database.Id, arg2);
                    preferredServerSite = null;
                }
                if (preferredServerSite == null)
                {
                    preferredRpcClientAccessServerLegacyDN = null;
                    return;
                }
                IADMiniClientAccessServerOrArray iadminiClientAccessServerOrArray = findMiniClientAccessServer.FindMiniClientAccessServerOrArrayByLegdn(databaseLocationInfo.RpcClientAccessServerLegacyDN);
                if (iadminiClientAccessServerOrArray != null && iadminiClientAccessServerOrArray.ServerSite != null && iadminiClientAccessServerOrArray.ServerSite.Equals(preferredServerSite))
                {
                    preferredRpcClientAccessServerLegacyDN = LegacyDN.Parse(databaseLocationInfo.RpcClientAccessServerLegacyDN);
                    return;
                }
                preferredRpcClientAccessServerLegacyDN = ActiveManagerImplementation.FindClientAccessArrayOrServerFromSite(preferredServerSite, database.HostServerForPreference1, findClientAccessArray, findMiniClientAccessServer, AdObjectLookupFlags.None);
                return;
            }
            else
            {
                IADMiniClientAccessServerOrArray iadminiClientAccessServerOrArray2 = findMiniClientAccessServer.FindMiniClientAccessServerOrArrayByLegdn(preferredRpcClientAccessServerLegacyDN.ToString());
                ExTraceGlobals.ActiveManagerClientTracer.TraceDebug <LegacyDN, string>((long)activeManager.GetHashCode(), "CalculatePreferredHomeServerInternal. preferredRpcClientAccessServerLegacyDN = {0}, preferredMiniServer = {1}.", preferredRpcClientAccessServerLegacyDN, (iadminiClientAccessServerOrArray2 == null) ? "<null>" : iadminiClientAccessServerOrArray2.Fqdn);
                if (iadminiClientAccessServerOrArray2 == null)
                {
                    preferredServerSite = null;
                    preferredRpcClientAccessServerLegacyDN = null;
                    return;
                }
                preferredRpcClientAccessServerLegacyDN = LegacyDN.Parse(iadminiClientAccessServerOrArray2.ExchangeLegacyDN);
                preferredServerSite = iadminiClientAccessServerOrArray2.ServerSite;
                return;
            }
        }