private IEnumerable <ComplianceMessage> ResolveServers(IEnumerable <ComplianceMessage> sources)
        {
            MemoryCache     cache;
            FaultDefinition faultDefinition;

            if (Registry.Instance.TryGetInstance <MemoryCache>(RegistryComponent.Common, CommonComponent.BestEffortCache, out cache, out faultDefinition, "ResolveServers", "f:\\15.00.1497\\sources\\dev\\EDiscovery\\src\\TaskDistributionSystem\\TaskDistributionCommon\\Resolver\\ActiveDirectoryTargetResolver.cs", 84))
            {
                faultDefinition = null;
                cache           = null;
            }
            using (IEnumerator <ComplianceMessage> enumerator = sources.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    ComplianceMessage source = enumerator.Current;
                    if (source.MessageTarget.Database != Guid.Empty && !ExceptionHandler.IsFaulted(source))
                    {
                        string text        = null;
                        string databaseKey = string.Format("DATABASELOCATION:{0}", source.MessageTarget.Database);
                        if (cache != null)
                        {
                            text = (cache.Get(databaseKey, null) as string);
                            if (!string.IsNullOrEmpty(text))
                            {
                                string key = string.Format("BADSERVER:{0}", text);
                                if (cache.Get(key, null) == null)
                                {
                                    source.MessageTarget.Server = text;
                                }
                                else
                                {
                                    text = null;
                                }
                            }
                        }
                        if (string.IsNullOrEmpty(text))
                        {
                            if (!ExceptionHandler.DataSource.TryRun(delegate
                            {
                                using (MailboxServerLocator mailboxServerLocator = MailboxServerLocator.CreateWithResourceForestFqdn(source.MessageTarget.Database, null))
                                {
                                    BackEndServer server = mailboxServerLocator.GetServer();
                                    source.MessageTarget.Server = server.Fqdn;
                                    if (cache != null)
                                    {
                                        cache.Set(databaseKey, server.Fqdn, DateTimeOffset.Now.AddMinutes(5.0), null);
                                    }
                                }
                            }, ActiveDirectoryTargetResolver.DataLookupTime, out faultDefinition, source, null, default(CancellationToken), null, "ResolveServers", "f:\\15.00.1497\\sources\\dev\\EDiscovery\\src\\TaskDistributionSystem\\TaskDistributionCommon\\Resolver\\ActiveDirectoryTargetResolver.cs", 115))
                            {
                                ExceptionHandler.FaultMessage(source, faultDefinition, true);
                            }
                        }
                    }
                    yield return(source);
                }
            }
            yield break;
        }
Пример #2
0
        private void RefreshDatabase(DatabaseWithForest database)
        {
            ExTraceGlobals.VerboseTracer.TraceDebug <string>((long)this.GetHashCode(), "[MailboxServerCache::RefreshDatabase]: Refreshing cache for database {0}.", database.Database.ToString());
            Diagnostics.Logger.LogEvent(FrontEndHttpProxyEventLogConstants.Tuple_RefreshingDatabaseBackEndServer, null, new object[]
            {
                HttpProxyGlobals.ProtocolType,
                database.Database,
                database.ResourceForest
            });
            Dictionary <Guid, BackEndServer> dictionary = null;
            bool flag = true;

            try
            {
                using (MailboxServerLocator mailboxServerLocator = MailboxServerLocator.CreateWithResourceForestFqdn(database.Database, string.IsNullOrEmpty(database.ResourceForest) ? null : new Fqdn(database.ResourceForest)))
                {
                    PerfCounters.HttpProxyCountersInstance.MailboxServerLocatorCalls.Increment();
                    mailboxServerLocator.GetServer();
                    dictionary = mailboxServerLocator.AvailabilityGroupServers;
                    flag       = mailboxServerLocator.IsSourceCachedData;
                    PerfCounters.HttpProxyCountersInstance.MailboxServerLocatorLatency.RawValue = mailboxServerLocator.Latency;
                    PerfCounters.HttpProxyCountersInstance.MailboxServerLocatorAverageLatency.IncrementBy(mailboxServerLocator.Latency);
                    PerfCounters.HttpProxyCountersInstance.MailboxServerLocatorAverageLatencyBase.Increment();
                    PerfCounters.UpdateMovingAveragePerformanceCounter(PerfCounters.HttpProxyCountersInstance.MovingAverageMailboxServerLocatorLatency, mailboxServerLocator.Latency);
                    PerfCounters.IncrementMovingPercentagePerformanceCounterBase(PerfCounters.HttpProxyCountersInstance.MovingPercentageMailboxServerLocatorRetriedCalls);
                    if (mailboxServerLocator.LocatorServiceHosts.Length > 1)
                    {
                        PerfCounters.HttpProxyCountersInstance.MailboxServerLocatorRetriedCalls.Increment();
                        PerfCounters.UpdateMovingPercentagePerformanceCounter(PerfCounters.HttpProxyCountersInstance.MovingPercentageMailboxServerLocatorRetriedCalls);
                    }
                }
            }
            catch (Exception ex)
            {
                ExTraceGlobals.VerboseTracer.TraceError <Guid, string, Exception>((long)this.GetHashCode(), "[MailboxServerCache::CacheRefreshEntry]: MailboxServerLocator throws exception when locating database {0} in forest {1}. Error: {2}", database.Database, database.ResourceForest, ex);
                Diagnostics.Logger.LogEvent(FrontEndHttpProxyEventLogConstants.Tuple_ErrorRefreshingDatabaseBackEndServer, database.Database.ToString(), new object[]
                {
                    HttpProxyGlobals.ProtocolType,
                    database.Database,
                    database.ResourceForest,
                    ex.ToString()
                });
                if (ex is ServerLocatorClientException || ex is ServerLocatorClientTransientException || ex is MailboxServerLocatorException || ex is AmServerTransientException || ex is AmServerException)
                {
                    PerfCounters.HttpProxyCountersInstance.MailboxServerLocatorFailedCalls.Increment();
                    PerfCounters.UpdateMovingPercentagePerformanceCounter(PerfCounters.HttpProxyCountersInstance.MovingPercentageMailboxServerLocatorFailedCalls);
                }
                else if (!(ex is DatabaseNotFoundException) && !(ex is ADTransientException) && !(ex is DataValidationException) && !(ex is DataSourceOperationException))
                {
                    throw;
                }
            }
            if (dictionary != null)
            {
                this.PopulateCache(dictionary, database.ResourceForest, database.InitiatingRequestId, flag, this.AlwaysRefresh || !flag);
            }
        }
Пример #3
0
        public BackEndServer ServerLocatorEndGetServer(MailboxServerLocator locator, IAsyncResult asyncResult, Guid initiatingRequestId)
        {
            if (locator == null)
            {
                throw new ArgumentNullException("locator");
            }
            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }
            BackEndServer result = locator.EndGetServer(asyncResult);

            this.PopulateCache(locator.AvailabilityGroupServers, locator.ResourceForestFqdn, initiatingRequestId, locator.IsSourceCachedData, this.AlwaysRefresh || !locator.IsSourceCachedData);
            return(result);
        }
Пример #4
0
        // Token: 0x06000236 RID: 566 RVA: 0x0000B057 File Offset: 0x00009257
        public BackEndServer ServerLocatorEndGetServer(MailboxServerLocator locator, IAsyncResult asyncResult, Guid initiatingRequestId)
        {
            if (locator == null)
            {
                throw new ArgumentNullException("locator");
            }
            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }
            BackEndServer result = locator.EndGetServer(asyncResult);

            this.PopulateCache(locator.AvailabilityGroupDatabaseToServerMappings, locator.ResourceForestFqdn);
            return(result);
        }
Пример #5
0
        public Uri Locate(ADUser target)
        {
            ArgumentValidator.ThrowIfNull("target", target);
            ArgumentValidator.ThrowIfNull("target.Database", target.Database);
            if (this.lastLocatedTarget != null && this.lastLocatedTarget.Equals(target))
            {
                return(this.lastLocatedUri);
            }
            Uri result;

            try
            {
                using (MailboxServerLocator mailboxServerLocator = MailboxServerLocator.CreateWithResourceForestFqdn(target.Database.ObjectGuid, new Fqdn(TopologyProvider.LocalForestFqdn)))
                {
                    Uri photoServiceUri = this.GetPhotoServiceUri(this.LocateServer(mailboxServerLocator));
                    this.lastLocatedUri    = photoServiceUri;
                    this.lastLocatedTarget = target;
                    result = photoServiceUri;
                }
            }
            catch (BackEndLocatorException arg)
            {
                this.tracer.TraceError <BackEndLocatorException>((long)this.GetHashCode(), "SERVICE LOCATOR[MAILBOXSERVERLOCATOR]: failed to locate service because MailboxServerLocator failed.  Exception: {0}", arg);
                throw;
            }
            catch (ServerLocatorClientTransientException arg2)
            {
                this.tracer.TraceError <ServerLocatorClientTransientException>((long)this.GetHashCode(), "SERVICE LOCATOR[MAILBOXSERVERLOCATOR]: hit a transient error in ServerLocator trying to locate photo service.  Exception: {0}", arg2);
                throw;
            }
            catch (ServiceDiscoveryTransientException arg3)
            {
                this.tracer.TraceError <ServiceDiscoveryTransientException>((long)this.GetHashCode(), "SERVICE LOCATOR[MAILBOXSERVERLOCATOR]: hit a transient error in service discovery trying to locate photo service.  Exception: {0}", arg3);
                throw;
            }
            catch (TransientException arg4)
            {
                this.tracer.TraceError <TransientException>((long)this.GetHashCode(), "SERVICE LOCATOR[MAILBOXSERVERLOCATOR]: hit a transient error trying to locate photo service.  Exception: {0}", arg4);
                throw;
            }
            catch (Exception arg5)
            {
                this.tracer.TraceError <Exception>((long)this.GetHashCode(), "SERVICE LOCATOR[MAILBOXSERVERLOCATOR]: failed to locate photo service.  Exception: {0}", arg5);
                throw;
            }
            return(result);
        }
Пример #6
0
        private BackEndServer LocateServer(MailboxServerLocator locator)
        {
            BackEndServer result;

            using (new StopwatchPerformanceTracker("LocalForestPhotoServiceLocatorLocateServer", this.perfLogger))
            {
                using (new ADPerformanceTracker("LocalForestPhotoServiceLocatorLocateServer", this.perfLogger))
                {
                    IAsyncResult asyncResult = locator.BeginGetServer(null, null);
                    if (!asyncResult.AsyncWaitHandle.WaitOne(LocalForestPhotoServiceLocatorUsingMailboxServerLocator.LocateServerTimeout))
                    {
                        this.tracer.TraceError((long)this.GetHashCode(), "SERVICE LOCATOR[MAILBOXSERVERLOCATOR]: timed out waiting for a response from locator.");
                        throw new TimeoutException();
                    }
                    result = locator.EndGetServer(asyncResult);
                }
            }
            return(result);
        }
Пример #7
0
        public BackEndServer GetBackEndServerForDatabase(Guid databaseGuid, string domainName, string resourceForest, IRoutingDiagnostics diagnostics)
        {
            Exception     ex = null;
            BackEndServer result;

            using (MailboxServerLocator mailboxServerLocator = MailboxServerLocator.Create(databaseGuid, domainName, resourceForest))
            {
                BackEndServer backEndServer = null;
                try
                {
                    backEndServer = mailboxServerLocator.GetServer();
                }
                catch (ServerLocatorClientException ex2)
                {
                    ex = ex2;
                }
                catch (ServerLocatorClientTransientException ex3)
                {
                    ex = ex3;
                }
                catch (MailboxServerLocatorException ex4)
                {
                    ex = ex4;
                }
                catch (AmServerTransientException ex5)
                {
                    ex = ex5;
                }
                catch (AmServerException ex6)
                {
                    ex = ex6;
                }
                catch (DatabaseNotFoundException ex7)
                {
                    ex = ex7;
                }
                catch (ADTransientException ex8)
                {
                    ex = ex8;
                }
                catch (DataValidationException ex9)
                {
                    ex = ex9;
                }
                catch (DataSourceOperationException ex10)
                {
                    ex = ex10;
                }
                foreach (long num in mailboxServerLocator.DirectoryLatencies)
                {
                    diagnostics.AddResourceForestLatency(TimeSpan.FromMilliseconds((double)num));
                }
                foreach (long num2 in mailboxServerLocator.GlsLatencies)
                {
                    diagnostics.AddGlobalLocatorLatency(TimeSpan.FromMilliseconds((double)num2));
                }
                if (ex != null)
                {
                    throw new DatabaseLocationProviderException("MailboxServerLocator.GetServer failed", ex);
                }
                result = backEndServer;
            }
            return(result);
        }
Пример #8
0
 public BackEndServer ServerLocatorEndGetServer(MailboxServerLocator locator, IAsyncResult asyncResult, IRequestContext requestContext)
 {
     return(this.ServerLocatorEndGetServer(locator, asyncResult, requestContext.ActivityId));
 }
Пример #9
0
        protected virtual void CreateGroupsForLocalMailboxes(List <MailboxInfo> localMailboxes)
        {
            Dictionary <Guid, BackEndServer> dictionary = new Dictionary <Guid, BackEndServer>(localMailboxes.Count);

            for (int i = 0; i < localMailboxes.Count; i++)
            {
                Guid key = (localMailboxes[i].Type == MailboxType.Primary) ? localMailboxes[i].MdbGuid : localMailboxes[i].ArchiveDatabase;
                if (!dictionary.ContainsKey(key))
                {
                    dictionary.Add(key, null);
                }
            }
            for (int j = 0; j < localMailboxes.Count; j++)
            {
                Guid guid = (localMailboxes[j].Type == MailboxType.Primary) ? localMailboxes[j].MdbGuid : localMailboxes[j].ArchiveDatabase;
                try
                {
                    BackEndServer backEndServer = null;
                    dictionary.TryGetValue(guid, out backEndServer);
                    if (backEndServer == null)
                    {
                        Factory.Current.MailboxGroupGeneratorTracer.TraceDebug <Guid, Guid>((long)this.GetHashCode(), "Correlation Id:{0}. Retrieving backend servers for database {1} and all the databases in the DAG", this.callerInfo.QueryCorrelationId, guid);
                        int k = EwsEndpointDiscovery.MailboxServerLocatorRetryCount;
                        while (k > 0)
                        {
                            using (MailboxServerLocator mailboxServerLocator = MailboxServerLocator.CreateWithResourceForestFqdn(guid, null))
                            {
                                Stopwatch stopwatch = new Stopwatch();
                                stopwatch.Start();
                                IAsyncResult asyncResult = mailboxServerLocator.BeginGetServer(null, null);
                                bool         flag        = asyncResult.AsyncWaitHandle.WaitOne(EwsEndpointDiscovery.MailboxServerLocatorTimeout);
                                if (flag)
                                {
                                    BackEndServer value = mailboxServerLocator.EndGetServer(asyncResult);
                                    stopwatch.Stop();
                                    Factory.Current.EventLog.LogEvent(InfoWorkerEventLogConstants.Tuple_DiscoveryMailboxServerLocatorTime, null, new object[]
                                    {
                                        this.callerInfo.QueryCorrelationId.ToString(),
                                        guid.ToString(),
                                        stopwatch.ElapsedMilliseconds
                                    });
                                    dictionary[guid] = value;
                                    foreach (KeyValuePair <Guid, BackEndServer> keyValuePair in mailboxServerLocator.AvailabilityGroupServers)
                                    {
                                        if (dictionary.ContainsKey(keyValuePair.Key))
                                        {
                                            Factory.Current.MailboxGroupGeneratorTracer.TraceDebug <Guid, Guid, Guid>((long)this.GetHashCode(), "Correlation Id:{0}. While queried backend for {1}, also retrieved backend for {2}", this.callerInfo.QueryCorrelationId, guid, keyValuePair.Key);
                                            dictionary[keyValuePair.Key] = keyValuePair.Value;
                                        }
                                    }
                                    break;
                                }
                                stopwatch.Stop();
                                Factory.Current.EventLog.LogEvent(InfoWorkerEventLogConstants.Tuple_DiscoveryServerLocatorTimeout, null, new object[]
                                {
                                    guid.ToString(),
                                    this.callerInfo.QueryCorrelationId.ToString(),
                                    EwsEndpointDiscovery.MailboxServerLocatorRetryCount - k + 1
                                });
                                k--;
                            }
                        }
                    }
                    if (dictionary[guid] != null)
                    {
                        this.AddMailboxToGroup(localMailboxes[j], dictionary[guid]);
                    }
                    else
                    {
                        Factory.Current.MailboxGroupGeneratorTracer.TraceDebug <Guid, Guid, SmtpAddress>((long)this.GetHashCode(), "Correlation Id:{0}. Couldn't find the backend for database {1}. So adding an error group for mailbox {2}", this.callerInfo.QueryCorrelationId, guid, localMailboxes[j].PrimarySmtpAddress);
                        this.AddMailboxToGroup(localMailboxes[j], new GroupId(new DatabaseLocationUnavailableException(Strings.DatabaseLocationUnavailable(localMailboxes[j].PrimarySmtpAddress.ToString()))));
                    }
                }
                catch (MailboxServerLocatorException error)
                {
                    Factory.Current.MailboxGroupGeneratorTracer.TraceDebug <Guid, Guid>((long)this.GetHashCode(), "Correlation Id:{0}. Encountered an Exception while querying backend for database {1}", this.callerInfo.QueryCorrelationId, guid);
                    this.AddMailboxToGroup(localMailboxes[j], new GroupId(error));
                }
            }
        }
Пример #10
0
        // Token: 0x06000246 RID: 582 RVA: 0x0000B4CC File Offset: 0x000096CC
        private void RefreshDatabase(DatabaseWithForest database)
        {
            if (ExTraceGlobals.VerboseTracer.IsTraceEnabled(1))
            {
                ExTraceGlobals.VerboseTracer.TraceDebug <string>((long)this.GetHashCode(), "[MailboxServerCache::RefreshDatabase]: Refreshing cache for database {0}.", database.Database.ToString());
            }
            Diagnostics.Logger.LogEvent(FrontEndHttpProxyEventLogConstants.Tuple_RefreshingDatabaseBackEndServer, null, new object[]
            {
                HttpProxyGlobals.ProtocolType,
                database.Database,
                database.ResourceForest
            });
            Dictionary <Guid, DatabaseToServerMappingInfo> dictionary = null;

            try
            {
                using (MailboxServerLocator mailboxServerLocator = MailboxServerLocator.Create(database.Database, null, database.ResourceForest, true, GuardedSlsExecution.MailboxServerLocatorCallbacks, null))
                {
                    PerfCounters.HttpProxyCountersInstance.MailboxServerLocatorCalls.Increment();
                    mailboxServerLocator.GetServer();
                    dictionary = mailboxServerLocator.AvailabilityGroupDatabaseToServerMappings;
                    bool isSourceCachedData = mailboxServerLocator.IsSourceCachedData;
                    PerfCounters.HttpProxyCountersInstance.MailboxServerLocatorLatency.RawValue = mailboxServerLocator.Latency;
                    PerfCounters.HttpProxyCountersInstance.MailboxServerLocatorAverageLatency.IncrementBy(mailboxServerLocator.Latency);
                    PerfCounters.HttpProxyCountersInstance.MailboxServerLocatorAverageLatencyBase.Increment();
                    PerfCounters.UpdateMovingAveragePerformanceCounter(PerfCounters.HttpProxyCountersInstance.MovingAverageMailboxServerLocatorLatency, mailboxServerLocator.Latency);
                    PerfCounters.IncrementMovingPercentagePerformanceCounterBase(PerfCounters.HttpProxyCountersInstance.MovingPercentageMailboxServerLocatorRetriedCalls);
                    if (mailboxServerLocator.LocatorServiceHosts.Length > 1)
                    {
                        PerfCounters.HttpProxyCountersInstance.MailboxServerLocatorRetriedCalls.Increment();
                        PerfCounters.UpdateMovingPercentagePerformanceCounter(PerfCounters.HttpProxyCountersInstance.MovingPercentageMailboxServerLocatorRetriedCalls);
                    }
                }
            }
            catch (Exception ex)
            {
                if (ExTraceGlobals.VerboseTracer.IsTraceEnabled(3))
                {
                    ExTraceGlobals.VerboseTracer.TraceError <Guid, string, Exception>((long)this.GetHashCode(), "[MailboxServerCache::RefreshDatabase]: MailboxServerLocator threw exception when locating database {0} in forest {1}. Error: {2}", database.Database, database.ResourceForest, ex);
                }
                Diagnostics.Logger.LogEvent(FrontEndHttpProxyEventLogConstants.Tuple_ErrorRefreshingDatabaseBackEndServer, database.Database.ToString(), new object[]
                {
                    HttpProxyGlobals.ProtocolType,
                    database.Database,
                    database.ResourceForest,
                    ex.ToString()
                });
                if (ex is ServerLocatorClientException || ex is ServerLocatorClientTransientException || ex is MailboxServerLocatorException || ex is AmServerTransientException || ex is AmServerException)
                {
                    PerfCounters.HttpProxyCountersInstance.MailboxServerLocatorFailedCalls.Increment();
                    PerfCounters.UpdateMovingPercentagePerformanceCounter(PerfCounters.HttpProxyCountersInstance.MovingPercentageMailboxServerLocatorFailedCalls);
                }
                else if (!(ex is DatabaseNotFoundException) && !(ex is ADTransientException) && !(ex is DataValidationException) && !(ex is DataSourceOperationException) && !(ex is DagDecomException))
                {
                    throw;
                }
            }
            if (dictionary != null)
            {
                this.PopulateCache(dictionary, database.ResourceForest);
            }
        }