コード例 #1
0
		public override bool CanTakeOverLease(bool force, LeaseToken lease, DateTime now)
		{
			bool flag2;
			bool flag = this.leaseManager.CanTakeOverLease(force, lease, now, EdgeSyncSvc.EdgeSync.Topology.SiteBridgeheadDistinguishedNames, out flag2);
			if (flag && flag2)
			{
				this.ignoreCookieDomainController = true;
			}
			return flag;
		}
コード例 #2
0
        public void SetLease(LeaseToken leaseToken)
        {
            LeaseToken token = new LeaseToken(leaseToken.Path, leaseToken.Expiry, leaseToken.Type, leaseToken.LastSync, leaseToken.Expiry + this.interSiteLeaseExpiryInterval + FileLeaseManager.LeaseExpiryCriticalAlertPadding, leaseToken.Version);

            FileLeaseManager.LeaseOperationResult leaseOperationResult = FileLeaseManager.TryRunLeaseOperation(new FileLeaseManager.LeaseOperation(this.SetLeaseOperation), new FileLeaseManager.LeaseOperationRequest(token));
            if (!leaseOperationResult.Succeeded)
            {
                this.logSession.LogException(EdgeSyncLoggingLevel.Low, EdgeSyncEvent.TargetConnection, leaseOperationResult.Exception, "Sync failed because Edgesync failed to update lease file");
                throw new ExDirectoryException(leaseOperationResult.Exception);
            }
        }
コード例 #3
0
 public static FileLeaseManager.LeaseOperationResult GetLeaseOperation(FileLeaseManager.LeaseOperationRequest request)
 {
     FileLeaseManager.LeaseOperationResult result;
     using (FileStream fileStream = new FileStream(request.LeasePath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.None))
     {
         byte[] array   = new byte[fileStream.Length];
         int    count   = fileStream.Read(array, 0, array.Length);
         string @string = Encoding.ASCII.GetString(array, 0, count);
         result = new FileLeaseManager.LeaseOperationResult(LeaseToken.Parse(@string));
     }
     return(result);
 }
コード例 #4
0
        private void ExtractLeaseInfo()
        {
            string stringForm = this.edgeConnection.GetLease().StringForm;

            if (!string.IsNullOrEmpty(stringForm))
            {
                LeaseToken leaseToken = LeaseToken.Parse(stringForm);
                this.leaseType            = leaseToken.Type;
                this.leaseExpiry          = leaseToken.Expiry;
                this.leaseHolder          = leaseToken.Path;
                this.lastSynchronizedDate = leaseToken.LastSync;
            }
        }
コード例 #5
0
        public override void SetLease(LeaseToken newLeaseToken)
        {
            string        stringForm    = newLeaseToken.StringForm;
            ModifyRequest modifyRequest = new ModifyRequest();

            modifyRequest.DistinguishedName = this.serverDistinguishedName;
            DirectoryAttributeModification directoryAttributeModification = new DirectoryAttributeModification();

            directoryAttributeModification.Operation = DirectoryAttributeOperation.Replace;
            directoryAttributeModification.Name      = "msExchEdgeSyncLease";
            directoryAttributeModification.Add(stringForm);
            modifyRequest.Modifications.Add(directoryAttributeModification);
            this.SendRequest(modifyRequest);
        }
コード例 #6
0
        public bool CanTakeOverLease(bool force, LeaseToken lease, DateTime now, HashSet <string> localSiteHubs, out bool siteChanged)
        {
            siteChanged = !localSiteHubs.Contains(lease.Path);
            if (force)
            {
                return(true);
            }
            if (!siteChanged)
            {
                return(lease.Expiry < now);
            }
            bool flag = lease.Expiry + this.interSiteLeaseExpiryInterval < now;

            this.tracer.TraceDebug((long)this.GetHashCode(), "{0} over out of site lease {1}, Expiry {2}, TimeNow {3}", new object[]
            {
                flag ? "Took" : "Did not take",
                lease.Path,
                lease.Expiry,
                now
            });
            return(flag);
        }
コード例 #7
0
        public override bool CanTakeOverLease(bool force, LeaseToken lease, DateTime now)
        {
            if (force)
            {
                ExTraceGlobals.SynchronizationJobTracer.TraceDebug <string>((long)this.GetHashCode(), "Forcefully take over the lease from {0}", lease.StringForm);
                return(true);
            }
            if (lease.Expiry < now)
            {
                ExTraceGlobals.SynchronizationJobTracer.TraceDebug <string>((long)this.GetHashCode(), "Can take over expired lease {0}", lease.StringForm);
                return(true);
            }
            ServerVersion serverVersion  = new ServerVersion(base.LocalServerVersion);
            ServerVersion serverVersion2 = new ServerVersion(lease.Version);

            if ((serverVersion.Major == 14 || serverVersion.Major == 15) && serverVersion2.Major == 8 && serverVersion2.Minor == 2)
            {
                ExTraceGlobals.SynchronizationJobTracer.TraceDebug <string>((long)this.GetHashCode(), "Can take over E12 Sp2 lease {0}", lease.StringForm);
                return(true);
            }
            return(false);
        }
コード例 #8
0
 public override LeaseToken GetLease()
 {
     return(LeaseToken.Parse(this.ReadSingleStringAttribute(this.serverDistinguishedName, "msExchEdgeSyncLease")));
 }
コード例 #9
0
 public static EdgeSyncRecord GetFailedRecord(string service, string context, string detail, LeaseToken leaseToken, Cookie cookie, string additionalInfo)
 {
     return(EdgeSyncRecord.GetFailedRecord(service, context, detail, leaseToken, cookie, additionalInfo, false));
 }
コード例 #10
0
		public override void SetLease(LeaseToken leaseToken)
		{
			this.leaseManager.SetLease(leaseToken);
		}
コード例 #11
0
 public static EdgeSyncRecord GetFailedRecord(string service, string context, string detail, LeaseToken leaseToken, Cookie cookie, string additionalInfo, bool isUrgent)
 {
     return(new EdgeSyncRecord(service, context, isUrgent ? ValidationStatus.FailedUrgent : ValidationStatus.Failed, detail, leaseToken, cookie, additionalInfo));
 }
コード例 #12
0
 public static EdgeSyncRecord GetInconclusiveRecord(string service, string context, string detail, LeaseToken leaseToken, Cookie cookie, string additionalInfo)
 {
     return(new EdgeSyncRecord(service, context, ValidationStatus.Inconclusive, detail, leaseToken, cookie, additionalInfo));
 }
コード例 #13
0
 public abstract void SetLease(LeaseToken newLeaseToken);
コード例 #14
0
 public abstract bool CanTakeOverLease(bool force, LeaseToken lease, DateTime now);
コード例 #15
0
 public static EdgeSyncRecord GetNormalRecord(string service, string detail, LeaseToken leaseToken, Cookie cookie, string additionalInfo)
 {
     return(new EdgeSyncRecord(service, null, ValidationStatus.Normal, detail, leaseToken, cookie, additionalInfo));
 }
コード例 #16
0
 public LeaseOperationResult(LeaseToken resultToken)
 {
     this.resultToken = resultToken;
 }
コード例 #17
0
 public LeaseOperationRequest(LeaseToken token)
 {
     this.token = token;
 }
コード例 #18
0
 public static EdgeSyncRecord GetWarningRecord(string service, string context, string detail, LeaseToken leaseToken, Cookie cookie)
 {
     return(new EdgeSyncRecord(service, context, ValidationStatus.Warning, detail, leaseToken, cookie, null));
 }
コード例 #19
0
        private EdgeSyncRecord TestSyncHealth(string domainController)
        {
            ITopologyConfigurationSession session = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(domainController, true, ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromRootOrgScopeSet(), 383, "TestSyncHealth", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\transport\\EdgeSync\\TestEdgeSyncBase.cs");
            ADSite localSite             = null;
            EdgeSyncServiceConfig config = null;

            ADNotificationAdapter.RunADOperation(delegate()
            {
                localSite = session.GetLocalSite();
                if (localSite == null)
                {
                    throw new TransientException(Strings.CannotGetLocalSite);
                }
                config = session.Read <EdgeSyncServiceConfig>(localSite.Id.GetChildId("EdgeSyncService"));
            }, 3);
            if (config == null)
            {
                return(EdgeSyncRecord.GetEdgeSyncServiceNotConfiguredForCurrentSiteRecord(this.Service, localSite.Name));
            }
            bool   flag = false;
            string primaryLeaseFilePath;
            string backupLeaseFilePath;

            if (!this.ReadConnectorLeasePath(session, config.Id, out primaryLeaseFilePath, out backupLeaseFilePath, out flag))
            {
                if (!flag)
                {
                    return(EdgeSyncRecord.GetEdgeSyncConnectorNotConfiguredForEntireForestRecord(this.Service));
                }
                return(EdgeSyncRecord.GetEdgeSyncConnectorNotConfiguredForCurrentSiteRecord(this.Service, localSite.Name));
            }
            else
            {
                string     additionalInfo = null;
                LeaseToken lease          = TestEdgeSyncBase.GetLease(primaryLeaseFilePath, backupLeaseFilePath, out additionalInfo);
                if (lease.NotHeld)
                {
                    return(EdgeSyncRecord.GetFailedRecord(this.Service, base.MyInvocation.MyCommand.Name, "There is no lease file detected. It suggests synchronization has not started at all.", lease, null, additionalInfo));
                }
                Cookie cookie = null;
                string text   = null;
                if (!this.TryGetNewestCookieFromAllDomainControllers(out cookie, out text))
                {
                    throw new InvalidOperationException("Failed accessing all DCs: " + text);
                }
                if (cookie == null)
                {
                    return(EdgeSyncRecord.GetFailedRecord(this.Service, base.MyInvocation.MyCommand.Name, "There is no cookie detected. It suggests we haven't had a single successful synchronization.", lease, null, text));
                }
                EnhancedTimeSpan syncInterval = this.GetSyncInterval(config);
                switch (lease.Type)
                {
                case LeaseTokenType.Lock:
                    if (DateTime.UtcNow > lease.AlertTime)
                    {
                        return(EdgeSyncRecord.GetFailedRecord(this.Service, base.MyInvocation.MyCommand.Name, "Synchronization has completely stopped because lock has expired. It suggests the EdgeSync service died in the middle of the synchronization and no other service instance has taken over.", lease, cookie, text, true));
                    }
                    if (DateTime.UtcNow > cookie.LastUpdated + config.OptionDuration + 3L * syncInterval + TimeSpan.FromHours(1.0))
                    {
                        return(EdgeSyncRecord.GetFailedRecord(this.Service, base.MyInvocation.MyCommand.Name, "Cookie has not been updated as expected. It might be caused by failure to synchronize some items which means that the sychronization might still be running but not efficiently. It might also be caused by a long full sync. Check EdgeSync log for further troubleshooting.", lease, cookie, text));
                    }
                    return(EdgeSyncRecord.GetInconclusiveRecord(this.Service, base.MyInvocation.MyCommand.Name, "Synchronization status is inconclusive because EdgeSync is in the middle of synchronizing data. Try running this cmdlet again later.", lease, cookie, text));

                case LeaseTokenType.Option:
                    if (DateTime.UtcNow > lease.AlertTime)
                    {
                        return(EdgeSyncRecord.GetFailedRecord(this.Service, base.MyInvocation.MyCommand.Name, "Synchronization has completely stopped. We have failed to failover to another instance within the same AD site or to another AD site.", lease, cookie, text, true));
                    }
                    if (DateTime.UtcNow > cookie.LastUpdated + config.FailoverDCInterval + TimeSpan.FromMinutes(30.0))
                    {
                        return(EdgeSyncRecord.GetFailedRecord(this.Service, base.MyInvocation.MyCommand.Name, "Cookie has not been updated as expected. It might be caused by failure to synchronize some items which means that the sychronization might still be running but not efficiently. It might also be caused by a long full sync. Check EdgeSync log for further troubleshooting.", lease, cookie, text));
                    }
                    return(EdgeSyncRecord.GetNormalRecord(this.Service, "The synchronization is operating normally.", lease, cookie, text));

                default:
                    throw new ArgumentException("Unknown lease type: " + lease.Type);
                }
            }
        }
コード例 #20
0
 private EdgeSyncRecord(string service, string context, ValidationStatus status, string detail, LeaseToken leaseToken, Cookie cookie, string additionalInfo)
 {
     this.status           = status;
     this.detail           = detail;
     this.alertTime        = leaseToken.AlertTime;
     this.leaseHolder      = leaseToken.Path;
     this.leaseType        = leaseToken.Type;
     this.leaseExpiry      = leaseToken.Expiry;
     this.lastSynchronized = leaseToken.LastSync;
     this.cookie           = cookie;
     this.now            = DateTime.UtcNow;
     this.additionalInfo = (string.IsNullOrEmpty(additionalInfo) ? "N/A" : additionalInfo);
     this.service        = service;
     this.context        = context;
 }