Example #1
0
 internal static string GetFqdnNameFromNode(string nodeName)
 {
     if (string.IsNullOrEmpty(nodeName) || SharedHelper.StringIEquals(nodeName, "localhost"))
     {
         nodeName = Environment.MachineName;
     }
     if (!nodeName.Contains("."))
     {
         return(AmServerNameCache.Instance.GetFqdn(nodeName));
     }
     return(nodeName);
 }
Example #2
0
        public static bool RunADOperation(EventHandler ev)
        {
            Exception ex = SharedHelper.RunADOperationEx(ev);

            if (ex != null)
            {
                AmTrace.Error("RunADOperation(): ADException occurred : {0}", new object[]
                {
                    ex
                });
                return(false);
            }
            return(true);
        }
Example #3
0
        // Token: 0x0600002F RID: 47 RVA: 0x00002724 File Offset: 0x00000924
        public void RemoveEntry(string serverName)
        {
            string nodeNameFromFqdn = SharedHelper.GetNodeNameFromFqdn(serverName);

            try
            {
                this.m_rwLock.EnterWriteLock();
                this.m_cache.Remove(nodeNameFromFqdn);
            }
            finally
            {
                try
                {
                    this.m_rwLock.ExitWriteLock();
                }
                catch (SynchronizationLockException)
                {
                }
            }
        }
Example #4
0
        // Token: 0x0600002B RID: 43 RVA: 0x000024F0 File Offset: 0x000006F0
        public static string ResolveFqdn(string shortNodeName, bool throwException)
        {
            string    fqdn = null;
            Exception ex   = SharedHelper.RunADOperationEx(delegate(object param0, EventArgs param1)
            {
                IADToplogyConfigurationSession iadtoplogyConfigurationSession = ADSessionFactory.CreateIgnoreInvalidRootOrgSession(true);
                iadtoplogyConfigurationSession.UseConfigNC      = false;
                iadtoplogyConfigurationSession.UseGlobalCatalog = true;
                IADComputer iadcomputer = iadtoplogyConfigurationSession.FindComputerByHostName(shortNodeName);
                if (iadcomputer != null && !string.IsNullOrEmpty(iadcomputer.DnsHostName))
                {
                    fqdn = iadcomputer.DnsHostName;
                    return;
                }
                if (throwException)
                {
                    throw new AmGetFqdnFailedNotFoundException(shortNodeName);
                }
                AmTrace.Error("FQDN resolution of the short name {0} failed. Could not find valid DNS hostname from ADComputer query.", new object[]
                {
                    shortNodeName
                });
                fqdn = AmServerNameCache.GetFqdnWithLocalDomainSuffix(shortNodeName);
            });

            if (ex != null)
            {
                if (throwException)
                {
                    throw new AmGetFqdnFailedADErrorException(shortNodeName, ex.Message, ex);
                }
                AmTrace.Error("FQDN resolution of the short name {0} failed. Error: {1}", new object[]
                {
                    shortNodeName,
                    ex.Message
                });
                fqdn = AmServerNameCache.GetFqdnWithLocalDomainSuffix(shortNodeName);
            }
            return(fqdn);
        }
Example #5
0
        public static IADDatabaseAvailabilityGroup GetLocalServerDatabaseAvailabilityGroup(IADToplogyConfigurationSession adSession, out Exception exception)
        {
            IADDatabaseAvailabilityGroup dag = null;
            Exception objNotFoundEx          = null;

            exception = null;
            exception = SharedHelper.RunADOperationEx(delegate(object param0, EventArgs param1)
            {
                if (adSession == null)
                {
                    adSession = ADSessionFactory.CreateIgnoreInvalidRootOrgSession(true);
                }
                if (adSession != null)
                {
                    IADServer iadserver = adSession.FindServerByName(SharedDependencies.ManagementClassHelper.LocalMachineName);
                    if (iadserver != null)
                    {
                        ADObjectId databaseAvailabilityGroup = iadserver.DatabaseAvailabilityGroup;
                        if (databaseAvailabilityGroup != null)
                        {
                            dag = adSession.ReadADObject <IADDatabaseAvailabilityGroup>(databaseAvailabilityGroup);
                            return;
                        }
                    }
                    else
                    {
                        objNotFoundEx = new CouldNotFindServerObject(Environment.MachineName);
                    }
                }
            });
            if (objNotFoundEx != null)
            {
                exception = objNotFoundEx;
            }
            return(dag);
        }
Example #6
0
        // Token: 0x06000030 RID: 48 RVA: 0x00002874 File Offset: 0x00000A74
        public void PopulateForDag()
        {
            Dictionary <string, AmServerNameCache.CacheEntry> dictionary = new Dictionary <string, AmServerNameCache.CacheEntry>(16, MachineName.Comparer);
            Exception ex = SharedHelper.RunADOperationEx(delegate(object param0, EventArgs param1)
            {
                IADToplogyConfigurationSession iadtoplogyConfigurationSession = ADSessionFactory.CreateIgnoreInvalidRootOrgSession(true);
                Exception ex2;
                IADDatabaseAvailabilityGroup localServerDatabaseAvailabilityGroup = DirectoryHelper.GetLocalServerDatabaseAvailabilityGroup(iadtoplogyConfigurationSession, out ex2);
                if (ex2 != null)
                {
                    AmServerNameCache.Tracer.TraceError <Exception>(0L, "PopulateForDag failed to get DAG: {0}", ex2);
                    return;
                }
                if (localServerDatabaseAvailabilityGroup != null)
                {
                    iadtoplogyConfigurationSession.UseConfigNC      = false;
                    iadtoplogyConfigurationSession.UseGlobalCatalog = true;
                    MultiValuedProperty <ADObjectId> servers        = localServerDatabaseAvailabilityGroup.Servers;
                    if (servers != null)
                    {
                        foreach (ADObjectId adobjectId in servers)
                        {
                            IADComputer iadcomputer = iadtoplogyConfigurationSession.FindComputerByHostName(adobjectId.Name);
                            if (iadcomputer != null && !string.IsNullOrEmpty(iadcomputer.DnsHostName))
                            {
                                AmServerNameCache.CacheEntry cacheEntry = new AmServerNameCache.CacheEntry();
                                cacheEntry.ExpiryTime = ExDateTime.Now + this.TimeToLive;
                                cacheEntry.Fqdn       = iadcomputer.DnsHostName;
                            }
                            else
                            {
                                AmServerNameCache.Tracer.TraceError <ADObjectId>(0L, "PopulateForDag could not map server {0}", adobjectId);
                            }
                        }
                    }
                }
            });

            if (ex != null)
            {
                AmServerNameCache.Tracer.TraceError <Exception>(0L, "PopulateForDag did not replace cache because: {0}", ex);
                return;
            }
            if (dictionary != null)
            {
                AmServerNameCache.Tracer.TraceDebug(0L, "PopulateForDag replaced the cache");
                try
                {
                    this.m_rwLock.EnterWriteLock();
                    this.m_cache = dictionary;
                }
                finally
                {
                    try
                    {
                        this.m_rwLock.ExitWriteLock();
                    }
                    catch (SynchronizationLockException)
                    {
                    }
                }
            }
        }
Example #7
0
 internal static bool IsEqual(AmServerName src, AmServerName dst)
 {
     return(object.ReferenceEquals(src, dst) || (src != null && dst != null && SharedHelper.StringIEquals(src.Fqdn, dst.Fqdn)));
 }
Example #8
0
 public override int GetHashCode()
 {
     return(SharedHelper.GetStringIHashCode(this.Fqdn));
 }
Example #9
0
        // Token: 0x06000677 RID: 1655 RVA: 0x00018120 File Offset: 0x00016320
        private static void SaveDatabasePropertiesOnMultipleServerSites(ITopologyConfigurationSession rwSession, Database database, MiniServer sourceServer, MiniServer targetServer, bool isBestEffort)
        {
            Server     server          = rwSession.FindServerByName(Environment.MachineName);
            ADObjectId localServerSite = server.ServerSite;
            Exception  ex = SharedHelper.RunADOperationEx(delegate(object param0, EventArgs param1)
            {
                rwSession.Save(database);
            });

            if (ex != null)
            {
                AmTrace.Error("Failed to update properties on the default local site (error={0})", new object[]
                {
                    ex
                });
                ReplayCrimsonEvents.DatabasePropertyLocalSiteUpdateFailed.Log <string, Guid, string, string, string>(database.Name, database.Guid, targetServer.Name, localServerSite.DistinguishedName, ex.Message);
                if (!isBestEffort)
                {
                    throw ex;
                }
            }
            ADObjectId adobjectId  = (sourceServer != null) ? sourceServer.ServerSite : null;
            ADObjectId adobjectId2 = (targetServer != null) ? targetServer.ServerSite : null;

            ADObjectId[] source = new ADObjectId[]
            {
                adobjectId,
                adobjectId2
            };
            ADObjectId[] sites = (from s in source
                                  where s != null && !s.Equals(localServerSite)
                                  select s).Distinct <ADObjectId>().ToArray <ADObjectId>();
            if (sites.Length > 0)
            {
                string[] array = (from s in sites
                                  select s.DistinguishedName).ToArray <string>();
                string[] dcsContacted = null;
                ex = SharedHelper.RunADOperationEx(delegate(object param0, EventArgs param1)
                {
                    dcsContacted = rwSession.ReplicateSingleObject(database, sites);
                });
                if (ex != null)
                {
                    AmTrace.Error("Failed to initiate replication for remote sites (error={0})", new object[]
                    {
                        ex
                    });
                }
                for (int i = 0; i < sites.Length; i++)
                {
                    if (dcsContacted == null || string.IsNullOrEmpty(dcsContacted[i]))
                    {
                        AmTrace.Error("Replication request for site '{0}' was not submitted to any DC", new object[]
                        {
                            array[i]
                        });
                    }
                    else
                    {
                        AmTrace.Debug("Replication request for site '{0}' was submitted to DC '{1}'", new object[]
                        {
                            array[i],
                            dcsContacted[i]
                        });
                    }
                }
                if (ex != null)
                {
                    ReplayCrimsonEvents.DatabasePropertyRemoteSiteReplicationFailed.Log <string, Guid, string, string, string, string>(database.Name, database.Guid, targetServer.Name, string.Join(",", array), (dcsContacted != null) ? string.Join(",", dcsContacted) : string.Empty, ex.Message);
                    if (!isBestEffort)
                    {
                        throw ex;
                    }
                }
                else
                {
                    ReplayCrimsonEvents.DatabasePropertyRemoteSiteReplicationSucceeded.Log <string, Guid, string, string, string>(database.Name, database.Guid, targetServer.Name, string.Join(",", array), (dcsContacted != null) ? string.Join(",", dcsContacted) : string.Empty);
                }
            }
        }