コード例 #1
0
 public static bool IsTenantLockedDown(ADObjectId identity)
 {
     return(TenantRelocationStateCache.IsSourceTenantStateInRange(identity, new TenantRelocationStatus[]
     {
         TenantRelocationStatus.Lockdown
     }));
 }
コード例 #2
0
        public static bool IsTenantArriving(ADObjectId identity)
        {
            TenantRelocationState tenantRelocationState;
            bool flag;

            return(TenantRelocationStateCache.TryGetTenantRelocationStateByObjectId(identity, out tenantRelocationState, out flag) && !flag && tenantRelocationState.TargetForestState <= RelocationStatusDetailsDestination.Arriving && tenantRelocationState.SourceForestState != TenantRelocationStatus.Retired);
        }
コード例 #3
0
 public static bool IsTenantRetired(ADObjectId identity)
 {
     return(TenantRelocationStateCache.IsSourceTenantStateInRange(identity, new TenantRelocationStatus[]
     {
         TenantRelocationStatus.Retired
     }));
 }
コード例 #4
0
 public static bool IsTenantVolatile(ADObjectId identity)
 {
     return(TenantRelocationStateCache.IsSourceTenantStateInRange(identity, new TenantRelocationStatus[]
     {
         TenantRelocationStatus.Synchronization,
         TenantRelocationStatus.Lockdown,
         TenantRelocationStatus.Retired
     }));
 }
コード例 #5
0
        internal static bool IgnoreRelocationTimeConstraints()
        {
            DateTime utcNow = DateTime.UtcNow;

            if (utcNow > TenantRelocationStateCache.nextRegistryCheckTimestamp)
            {
                TenantRelocationStateCache.ignoreRelocationTimeConstraints = TenantRelocationStateCache.ReadIgnoreRelocationTimeConstraintsValue();
                TenantRelocationStateCache.nextRegistryCheckTimestamp      = utcNow.AddMinutes(5.0);
            }
            return(TenantRelocationStateCache.ignoreRelocationTimeConstraints);
        }
コード例 #6
0
        public static bool TryGetTenantRelocationStateByObjectId(ADObjectId identity, out TenantRelocationState state, out bool isSourceTenant)
        {
            ArgumentValidator.ThrowIfNull("identity", identity);
            state          = null;
            isSourceTenant = true;
            PartitionId partitionId = identity.GetPartitionId();

            if (!ForestTenantRelocationsCache.IsTenantRelocationAllowed(partitionId.ForestFQDN))
            {
                return(false);
            }
            ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 595, "TryGetTenantRelocationStateByObjectId", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\RelocationCache\\TenantRelocationStateCache.cs");
            ADObjectId configurationUnitsRoot = tenantConfigurationSession.GetConfigurationUnitsRoot();

            if (configurationUnitsRoot.Equals(identity))
            {
                return(false);
            }
            ADObjectId adobjectId = null;

            if (identity.IsDescendantOf(configurationUnitsRoot))
            {
                adobjectId = identity.GetFirstGenerationDecendantOf(configurationUnitsRoot);
            }
            else
            {
                ADObjectId hostedOrganizationsRoot = tenantConfigurationSession.GetHostedOrganizationsRoot();
                if (hostedOrganizationsRoot.Equals(identity))
                {
                    return(false);
                }
                if (identity.IsDescendantOf(hostedOrganizationsRoot))
                {
                    adobjectId = identity.GetFirstGenerationDecendantOf(hostedOrganizationsRoot);
                }
            }
            if (adobjectId == null)
            {
                return(false);
            }
            try
            {
                state = TenantRelocationStateCache.GetTenantRelocationState(adobjectId.Name, partitionId, out isSourceTenant, false);
            }
            catch (CannotResolveTenantNameException)
            {
                return(false);
            }
            return(true);
        }
コード例 #7
0
        public static TenantRelocationState GetTenantRelocationState(string tenantName, PartitionId partitionId, out bool isSourceTenant, bool readThrough = false)
        {
            if (string.IsNullOrEmpty(tenantName))
            {
                throw new ArgumentNullException("tenantName");
            }
            if (!ForestTenantRelocationsCache.IsTenantRelocationAllowed(partitionId.ForestFQDN))
            {
                isSourceTenant = true;
                return(new TenantRelocationState(partitionId.ForestFQDN, TenantRelocationStatus.NotStarted));
            }
            TenantRelocationStateCache         tenantRelocationStateCache = TenantRelocationStateCache.GetInstance();
            ExpiringTenantRelocationStateValue expiringTenantRelocationStateValue;

            if (!tenantRelocationStateCache.tenantRelocationStates.TryGetValue(tenantName, out expiringTenantRelocationStateValue) || expiringTenantRelocationStateValue.Expired || readThrough || TenantRelocationStateCache.IgnoreRelocationTimeConstraints())
            {
                TenantRelocationState tenantRelocationState = TenantRelocationStateCache.LoadTenantRelocationState(tenantName, partitionId);
                ExTraceGlobals.TenantRelocationTracer.TraceDebug(0L, "TenantRelocationStateCache::GetTenantRelocationState(): Inserting new TenantRelocationState value for tenant {0} to the cache: SourceForestFQDN={1}, SourceForestState={2}, TargetForestFQDN={3}, TargetForestState={4}, TargetOrganizationId={5}", new object[]
                {
                    tenantName,
                    tenantRelocationState.SourceForestFQDN,
                    tenantRelocationState.SourceForestState,
                    tenantRelocationState.TargetForestFQDN,
                    tenantRelocationState.TargetForestState,
                    (tenantRelocationState.TargetOrganizationId != null) ? tenantRelocationState.TargetOrganizationId.ToString() : "<null>"
                });
                expiringTenantRelocationStateValue = new ExpiringTenantRelocationStateValue(tenantRelocationState);
                tenantRelocationStateCache.AddOrUpdate(tenantName, expiringTenantRelocationStateValue);
            }
            if (expiringTenantRelocationStateValue.Value.TargetOrganizationId == null || expiringTenantRelocationStateValue.Value.TargetOrganizationId.OrganizationalUnit == null)
            {
                isSourceTenant = true;
            }
            else if (expiringTenantRelocationStateValue.Value.TargetOrganizationId.PartitionId != partitionId)
            {
                isSourceTenant = true;
            }
            else if (expiringTenantRelocationStateValue.Value.SourceForestFQDN == expiringTenantRelocationStateValue.Value.TargetForestFQDN)
            {
                isSourceTenant = (tenantName != expiringTenantRelocationStateValue.Value.TargetOrganizationId.OrganizationalUnit.Name);
            }
            else
            {
                isSourceTenant = false;
            }
            return(expiringTenantRelocationStateValue.Value);
        }
コード例 #8
0
        private static bool IsTargetTenantStateInRange(ADObjectId identity, params RelocationStatusDetailsDestination[] states)
        {
            TenantRelocationState tenantRelocationState;
            bool flag;

            if (TenantRelocationStateCache.TryGetTenantRelocationStateByObjectId(identity, out tenantRelocationState, out flag) && !flag)
            {
                foreach (RelocationStatusDetailsDestination relocationStatusDetailsDestination in states)
                {
                    if (tenantRelocationState.TargetForestState == relocationStatusDetailsDestination)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #9
0
        private static bool IsSourceTenantStateInRange(ADObjectId identity, params TenantRelocationStatus[] states)
        {
            TenantRelocationState tenantRelocationState;
            bool flag;

            if (TenantRelocationStateCache.TryGetTenantRelocationStateByObjectId(identity, out tenantRelocationState, out flag) && flag)
            {
                foreach (TenantRelocationStatus tenantRelocationStatus in states)
                {
                    if (tenantRelocationState.SourceForestState == tenantRelocationStatus)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #10
0
        public static TimeSpan GetTenantCacheExpirationWindow(string tenantName, PartitionId partitionId)
        {
            TenantRelocationState tenantRelocationState = null;

            try
            {
                bool flag;
                tenantRelocationState = TenantRelocationStateCache.GetTenantRelocationState(tenantName, partitionId, out flag, false);
            }
            catch (CannotResolveTenantNameException)
            {
            }
            if (tenantRelocationState != null)
            {
                return(ExpiringTenantRelocationStateValue.TenantRelocationStateExpirationWindowProvider.GetExpirationWindow(tenantRelocationState));
            }
            return(ExpiringTenantRelocationStateValue.TenantRelocationStateExpirationWindowProvider.DefaultExpirationWindow);
        }
コード例 #11
0
 protected override OrganizationId RehomeScopingOrganizationIdIfNeeded(OrganizationId currentOrganizationId)
 {
     if (currentOrganizationId != null && ADSessionSettings.SessionSettingsFactory.IsTenantScopedOrganization(currentOrganizationId))
     {
         try
         {
             bool flag;
             TenantRelocationState tenantRelocationState = TenantRelocationStateCache.GetTenantRelocationState(currentOrganizationId.OrganizationalUnit.Name, currentOrganizationId.PartitionId, out flag, false);
             if (flag && tenantRelocationState != null && tenantRelocationState.SourceForestState == TenantRelocationStatus.Retired && tenantRelocationState.TargetOrganizationId != null)
             {
                 currentOrganizationId = tenantRelocationState.TargetOrganizationId;
             }
             else if (!flag && tenantRelocationState != null && tenantRelocationState.SourceForestState != TenantRelocationStatus.Retired && tenantRelocationState.OrganizationId != null)
             {
                 currentOrganizationId = tenantRelocationState.OrganizationId;
             }
         }
         catch (CannotResolveTenantNameException)
         {
         }
     }
     return(currentOrganizationId);
 }
コード例 #12
0
        private static TimeSpan CalculateCacheItemExpirationWindow(bool dataFromOfflineService, string tenantName, Guid externalOrgId, PartitionId accountPartitionId)
        {
            if (dataFromOfflineService)
            {
                return(TimeSpan.FromMinutes((double)ConfigBase <AdDriverConfigSchema> .GetConfig <int>("OfflineDataCacheExpirationTimeInMinutes")));
            }
            if (!ForestTenantRelocationsCache.IsTenantRelocationAllowed(accountPartitionId.ForestFQDN))
            {
                return(ExpiringTenantRelocationStateValue.TenantRelocationStateExpirationWindowProvider.DefaultExpirationWindow);
            }
            if (!string.IsNullOrEmpty(tenantName))
            {
                return(TenantRelocationStateCache.GetTenantCacheExpirationWindow(tenantName, accountPartitionId));
            }
            ITenantConfigurationSession tenantConfigurationSession            = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromAllTenantsPartitionId(accountPartitionId), 110, "CalculateCacheItemExpirationWindow", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\TenantPartitionCacheItem.cs");
            ExchangeConfigurationUnit   exchangeConfigurationUnitByExternalId = tenantConfigurationSession.GetExchangeConfigurationUnitByExternalId(externalOrgId);

            if (exchangeConfigurationUnitByExternalId != null)
            {
                tenantName = ((ADObjectId)exchangeConfigurationUnitByExternalId.Identity).Parent.Name;
                return(TenantRelocationStateCache.GetTenantCacheExpirationWindow(tenantName, accountPartitionId));
            }
            return(ExpiringTenantRelocationStateValue.TenantRelocationStateExpirationWindowProvider.DefaultExpirationWindow);
        }
コード例 #13
0
        private void CacheInsert <TResult>(TResult instance, Func <TResult, List <Tuple <string, KeyType> > > getAdditionalKeys = null, IEnumerable <PropertyDefinition> objectProperties = null) where TResult : IConfigurable, new()
        {
            ArgumentValidator.ThrowIfNull("query", instance);
            Stopwatch stopwatch = Stopwatch.StartNew();

            CachePerformanceTracker.StartLogging();
            bool   isNewProxyObject = false;
            int    retryCount       = 0;
            Guid   activityId       = Guid.Empty;
            string callerInfo       = null;
            string error            = null;

            try
            {
                List <Tuple <string, KeyType> > keys = null;
                TSession session = this.GetSession();
                if (session.ActivityScope != null)
                {
                    TSession session2 = this.GetSession();
                    if (session2.ActivityScope.Status == ActivityContextStatus.ActivityStarted)
                    {
                        TSession session3 = this.GetSession();
                        activityId = session3.ActivityScope.ActivityId;
                    }
                }
                TSession session4 = this.GetSession();
                callerInfo = session4.CallerInfo;
                if (getAdditionalKeys != null)
                {
                    keys = getAdditionalKeys(instance);
                }
                ICacheDirectorySession cacheDirectorySession = this.GetCacheSession() as ICacheDirectorySession;
                bool flag = false;
                if (((IDirectorySession)this).SessionSettings.TenantConsistencyMode == TenantConsistencyMode.IgnoreRetiredTenants && (TenantRelocationStateCache.IsTenantRetired((ADObjectId)instance.Identity) || TenantRelocationStateCache.IsTenantArriving((ADObjectId)instance.Identity)))
                {
                    ExTraceGlobals.SessionTracer.TraceWarning <ObjectId>((long)this.GetHashCode(), "CacheInsert. DN {0}. Tenant Is Retired or Arriving, skipping.", instance.Identity);
                }
                else
                {
                    if (!instance.GetType().Equals(CompositeDirectorySession <TSession> .ExchangeConfigUnitCUType) && (TenantRelocationStateCache.IsTenantLockedDown((ADObjectId)instance.Identity) || TenantRelocationStateCache.IsTenantRetired((ADObjectId)instance.Identity)))
                    {
                        flag = true;
                    }
                    int num = flag ? 30 : Configuration.GetCacheExpirationForObject(instance as ADRawEntry);
                    CacheItemPriority cacheItemPriority = flag ? CacheItemPriority.Default : Configuration.GetCachePriorityForObject(instance as ADRawEntry);
                    if (cacheDirectorySession != null)
                    {
                        cacheDirectorySession.Insert(instance, objectProperties, keys, num, cacheItemPriority);
                    }
                    else
                    {
                        TSession tsession = this.GetCacheSession();
                        tsession.Save(instance);
                    }
                    CacheDirectorySession cacheDirectorySession2 = this.GetCacheSession() as CacheDirectorySession;
                    if (cacheDirectorySession2 != null)
                    {
                        isNewProxyObject = cacheDirectorySession2.IsNewProxyObject;
                        retryCount       = cacheDirectorySession2.RetryCount;
                    }
                    ExTraceGlobals.SessionTracer.TraceDebug((long)this.GetHashCode(), "CacheInsert. DN={0}, IsTenantLockedDownOrRetired={1}, CacheExpiration={2}, Priority={3}", new object[]
                    {
                        instance.Identity,
                        flag,
                        num,
                        cacheItemPriority
                    });
                }
            }
            catch (TransientException ex)
            {
                ExTraceGlobals.SessionTracer.TraceError <ObjectId, TransientException>((long)this.GetHashCode(), "CacheInsert. DN {0}. Exception {1}", instance.Identity, ex);
                error = ex.ToString();
            }
            catch (Exception ex2)
            {
                error = ex2.ToString();
                throw;
            }
            finally
            {
                stopwatch.Stop();
                string     cachePerformanceTracker = CachePerformanceTracker.StopLogging();
                ADRawEntry adrawEntry = instance as ADRawEntry;
                CacheProtocolLog.BeginAppend("Save", (adrawEntry != null) ? adrawEntry.GetDistinguishedNameOrName() : "<NULL>", DateTime.MinValue, stopwatch.ElapsedMilliseconds, -1L, -1L, stopwatch.ElapsedMilliseconds, -1L, isNewProxyObject, retryCount, instance.GetType().Name, cachePerformanceTracker, activityId, callerInfo, error);
            }
        }
コード例 #14
0
        private static TenantRelocationState LoadTenantRelocationState(string tenantName, PartitionId partitionId)
        {
            ITenantConfigurationSession session = DirectorySessionFactory.NonCacheSessionFactory.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 185, "LoadTenantRelocationState", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\RelocationCache\\TenantRelocationStateCache.cs");
            ExchangeConfigurationUnit   exchangeCUAndThrowIfNotFound = TenantRelocationStateCache.GetExchangeCUAndThrowIfNotFound(tenantName, session);

            if (exchangeCUAndThrowIfNotFound.IsCached)
            {
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <string>(0L, "TenantRelocationStateCache::LoadTenantRelocationState(): Tenant {0} found in cache.", tenantName);
                if ((DateTime.UtcNow - exchangeCUAndThrowIfNotFound.WhenReadUTC).Value.TotalSeconds >= 30.0)
                {
                    ITenantConfigurationSession session2 = DirectorySessionFactory.NonCacheSessionFactory.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 203, "LoadTenantRelocationState", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\RelocationCache\\TenantRelocationStateCache.cs");
                    exchangeCUAndThrowIfNotFound = TenantRelocationStateCache.GetExchangeCUAndThrowIfNotFound(tenantName, session2);
                    ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.CacheSessionFactory.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 206, "LoadTenantRelocationState", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\RelocationCache\\TenantRelocationStateCache.cs");
                    tenantConfigurationSession.Delete(exchangeCUAndThrowIfNotFound);
                    tenantConfigurationSession.Save(exchangeCUAndThrowIfNotFound);
                }
            }
            if ((string.IsNullOrEmpty(exchangeCUAndThrowIfNotFound.TargetForest) && string.IsNullOrEmpty(exchangeCUAndThrowIfNotFound.RelocationSourceForestRaw)) || (!string.IsNullOrEmpty(exchangeCUAndThrowIfNotFound.RelocationSourceForestRaw) && exchangeCUAndThrowIfNotFound.RelocationStateRequested == RelocationStateRequested.Cleanup))
            {
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <string, string, bool>(0L, "TenantRelocationStateCache::LoadTenantRelocationState(): Found tenant {0} on DC {1} Cached {2} - not being relocated.", tenantName, exchangeCUAndThrowIfNotFound.OriginatingServer, exchangeCUAndThrowIfNotFound.IsCached);
                return(new TenantRelocationState(partitionId.ForestFQDN, TenantRelocationStatus.NotStarted));
            }
            if (string.IsNullOrEmpty(exchangeCUAndThrowIfNotFound.ExternalDirectoryOrganizationId))
            {
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <string, string, bool>(0L, "TenantRelocationStateCache::LoadTenantRelocationState(): Found tenant {0} on DC {1} Cached {2} - prepared for deletion.", tenantName, exchangeCUAndThrowIfNotFound.OriginatingServer, exchangeCUAndThrowIfNotFound.IsCached);
                TenantRelocationStatus sourceForestState;
                if (!string.IsNullOrEmpty(exchangeCUAndThrowIfNotFound.TargetForest))
                {
                    sourceForestState = exchangeCUAndThrowIfNotFound.RelocationStatus;
                }
                else
                {
                    sourceForestState = TenantRelocationStatus.NotStarted;
                }
                return(new TenantRelocationState(partitionId.ForestFQDN, sourceForestState));
            }
            if (!string.IsNullOrEmpty(exchangeCUAndThrowIfNotFound.TargetForest))
            {
                TenantRelocationRequest tenantRelocationRequest;
                Exception ex;
                TenantRelocationRequest.LoadOtherForestObjectInternal(null, exchangeCUAndThrowIfNotFound.TargetForest, exchangeCUAndThrowIfNotFound.DistinguishedName, exchangeCUAndThrowIfNotFound.ExternalDirectoryOrganizationId, true, out tenantRelocationRequest, out ex);
                if (ex != null && !(ex is CannotFindTargetTenantException))
                {
                    throw ex;
                }
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <string, string>(0L, "TenantRelocationStateCache::LoadTenantRelocationState(): Found tenant {0} on DC {1} - this is relocation source.", tenantName, (tenantRelocationRequest != null) ? tenantRelocationRequest.OriginatingServer : "<unknown>");
                return(new TenantRelocationState(partitionId.ForestFQDN, exchangeCUAndThrowIfNotFound.RelocationStatus, exchangeCUAndThrowIfNotFound.TargetForest, (RelocationStatusDetailsDestination)((tenantRelocationRequest != null) ? tenantRelocationRequest.RelocationStatusDetailsRaw : RelocationStatusDetails.NotStarted), exchangeCUAndThrowIfNotFound.OrganizationId, (tenantRelocationRequest != null) ? tenantRelocationRequest.OrganizationId : null));
            }
            else
            {
                Exception ex;
                TenantRelocationRequest tenantRelocationRequest2;
                TenantRelocationRequest.LoadOtherForestObjectInternal(null, exchangeCUAndThrowIfNotFound.RelocationSourceForestRaw, exchangeCUAndThrowIfNotFound.DistinguishedName, exchangeCUAndThrowIfNotFound.ExternalDirectoryOrganizationId, false, out tenantRelocationRequest2, out ex);
                if (ex == null)
                {
                    ExTraceGlobals.TenantRelocationTracer.TraceDebug(0L, string.Format("TenantRelocationStateCache::LoadTenantRelocationState(): Found tenant {0} on DC {1} - this is relocation target.", tenantName, (tenantRelocationRequest2 != null) ? tenantRelocationRequest2.OriginatingServer : "<unknown>"));
                    return(new TenantRelocationState(exchangeCUAndThrowIfNotFound.RelocationSourceForestRaw, (tenantRelocationRequest2 != null) ? tenantRelocationRequest2.RelocationStatus : TenantRelocationStatus.NotStarted, partitionId.ForestFQDN, (RelocationStatusDetailsDestination)exchangeCUAndThrowIfNotFound.RelocationStatusDetailsSource, (tenantRelocationRequest2 != null) ? tenantRelocationRequest2.OrganizationId : null, exchangeCUAndThrowIfNotFound.OrganizationId));
                }
                if (ex is CannotFindTargetTenantException)
                {
                    return(new TenantRelocationState(partitionId.ForestFQDN, TenantRelocationStatus.NotStarted));
                }
                throw ex;
            }
        }
コード例 #15
0
        private static bool ReadIgnoreRelocationTimeConstraintsValue()
        {
            int intValueFromRegistry = Globals.GetIntValueFromRegistry("SOFTWARE\\Microsoft\\ExchangeLabs", "TenantRelocationIgnoreTimeConstraints", 0, TenantRelocationStateCache.GetInstance().GetHashCode());

            return(intValueFromRegistry > 0);
        }