Exemplo n.º 1
0
        protected virtual AnchorJobProcessorResult ProcessEntry(CacheEntryBase cacheEntry)
        {
            AnchorUtil.ThrowOnNullArgument(cacheEntry, "cacheEntry");
            AnchorJobProcessorResult anchorJobProcessorResult = this.ShouldProcessEntry(cacheEntry);

            if (anchorJobProcessorResult != AnchorJobProcessorResult.Working)
            {
                return(anchorJobProcessorResult);
            }
            return(AnchorJobProcessorResult.Waiting);
        }
Exemplo n.º 2
0
        internal override bool Process(JobCache data)
        {
            AnchorUtil.ThrowOnNullArgument(data, "data");
            bool result = false;
            int  num    = 0;
            int  num2   = 0;

            foreach (CacheEntryBase cacheEntryBase in data.Get())
            {
                if (base.StopEvent.WaitOne(0, false))
                {
                    break;
                }
                int config = base.Context.Config.GetConfig <int>("MaximumCacheEntrySchedulerRun");
                if (config >= 0 && num++ >= config)
                {
                    base.Context.Logger.Log(MigrationEventType.Error, "Skipping run of {0} because too many cache entries {1} expected {2}", new object[]
                    {
                        cacheEntryBase,
                        num,
                        config
                    });
                }
                else
                {
                    AnchorLogContext.Current.OrganizationId = cacheEntryBase.OrganizationId;
                    try
                    {
                        AnchorJobProcessorResult anchorJobProcessorResult = AnchorJobProcessorResult.Working;
                        try
                        {
                            cacheEntryBase.ServiceException = null;
                            anchorJobProcessorResult        = this.ProcessEntry(cacheEntryBase);
                            num2 = 0;
                        }
                        catch (TransientException ex)
                        {
                            base.Context.Logger.Log(MigrationEventType.Error, "entry {0} encountered a transient error {1}", new object[]
                            {
                                cacheEntryBase,
                                ex
                            });
                            anchorJobProcessorResult = AnchorJobProcessorResult.Waiting;
                            num2 = 0;
                        }
                        catch (StoragePermanentException ex2)
                        {
                            base.Context.Logger.Log(MigrationEventType.Error, "entry {0} encountered a permanent error {1}", new object[]
                            {
                                cacheEntryBase,
                                ex2
                            });
                            anchorJobProcessorResult = AnchorJobProcessorResult.Waiting;
                            num2 = 0;
                        }
                        catch (MigrationPermanentException ex3)
                        {
                            base.Context.Logger.Log(MigrationEventType.Error, "entry {0} encountered a permanent error {1}", new object[]
                            {
                                cacheEntryBase,
                                ex3
                            });
                            anchorJobProcessorResult = AnchorJobProcessorResult.Waiting;
                            num2 = 0;
                        }
                        catch (Exception ex4)
                        {
                            if (base.Context.Config.GetConfig <bool>("UseWatson"))
                            {
                                ExWatson.SendReport(ex4);
                            }
                            cacheEntryBase.ServiceException = ex4;
                            anchorJobProcessorResult        = AnchorJobProcessorResult.Waiting;
                            num2++;
                            base.Context.Logger.Log(MigrationEventType.Error, "entry {0} encountered an unhandled error {1}, poison count {2} triggering alert notification", new object[]
                            {
                                cacheEntryBase,
                                ex4,
                                num2
                            });
                            if (!AnchorIssueCache.TrySendEventNotification(base.Context, base.Context.Config.GetConfig <string>("CacheEntryPoisonNotificationReason"), cacheEntryBase.ToString(), ResultSeverityLevel.Error))
                            {
                                throw;
                            }
                            if (num2 >= base.Context.Config.GetConfig <int>("CacheEntryPoisonThreshold"))
                            {
                                throw;
                            }
                        }
                        switch (anchorJobProcessorResult)
                        {
                        case AnchorJobProcessorResult.Working:
                            result = true;
                            continue;

                        case AnchorJobProcessorResult.Waiting:
                            continue;

                        case AnchorJobProcessorResult.Failed:
                            base.Context.Logger.Log(MigrationEventType.Error, "marking job cache entry failed.. {0}", new object[]
                            {
                                cacheEntryBase
                            });
                            data.Remove(cacheEntryBase);
                            continue;

                        case AnchorJobProcessorResult.Deleted:
                            base.Context.Logger.Log(MigrationEventType.Information, "Removing deleted job cache entry {0}", new object[]
                            {
                                cacheEntryBase
                            });
                            data.Remove(cacheEntryBase);
                            result = true;
                            continue;
                        }
                        throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Invalid AnchorJobProcessorResult {0}", new object[]
                        {
                            anchorJobProcessorResult
                        }));
                    }
                    finally
                    {
                        AnchorLogContext.Current.OrganizationId = null;
                    }
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        protected override AnchorJobProcessorResult ProcessEntry(CacheEntryBase cacheEntry)
        {
            AuthAdminContext authAdminContext = base.Context as AuthAdminContext;

            AnchorUtil.AssertOrThrow(authAdminContext != null, "expect to have a valid AuthAdminContext", new object[0]);
            authAdminContext.Logger.Log(MigrationEventType.Information, "Checking if mailbox {0} active on current server", new object[]
            {
                cacheEntry
            });
            AnchorJobProcessorResult anchorJobProcessorResult = base.ProcessEntry(cacheEntry);

            if (anchorJobProcessorResult == AnchorJobProcessorResult.Deleted)
            {
                authAdminContext.Logger.Log(MigrationEventType.Information, "Mailbox {0} is not active on current server, skipping Auth Admin tasks", new object[]
                {
                    cacheEntry
                });
                return(anchorJobProcessorResult);
            }
            authAdminContext.Logger.Log(MigrationEventType.Information, "Mailbox {0} is active on current server", new object[]
            {
                cacheEntry
            });
            try
            {
                authAdminContext.Logger.Log(MigrationEventType.Information, "Starting Auth Admin tasks", new object[0]);
                ITopologyConfigurationSession session = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(false, ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromRootOrgScopeSet(), 81, "ProcessEntry", "f:\\15.00.1497\\sources\\dev\\Management\\src\\ServiceHost\\Servicelets\\AuthAdmin\\Program\\AuthAdminScheduler.cs");
                this.authAdminAuthConfig.DoScheduledWork(session);
                this.authAdminCertificates.DoScheduledWork(session);
            }
            catch (ADTransientException ex)
            {
                authAdminContext.Logger.LogTerseEvent(MigrationEventType.Error, MSExchangeAuthAdminEventLogConstants.Tuple_TransientException, new string[]
                {
                    AnchorLogger.GetDiagnosticInfo(ex, null)
                });
                throw;
            }
            catch (DataSourceTransientException ex2)
            {
                authAdminContext.Logger.LogTerseEvent(MigrationEventType.Error, MSExchangeAuthAdminEventLogConstants.Tuple_TransientException, new string[]
                {
                    AnchorLogger.GetDiagnosticInfo(ex2, null)
                });
                throw;
            }
            catch (Exception ex3)
            {
                authAdminContext.Logger.LogTerseEvent(MigrationEventType.Error, MSExchangeAuthAdminEventLogConstants.Tuple_PermanentException, new string[]
                {
                    AnchorLogger.GetDiagnosticInfo(ex3, null)
                });
            }
            finally
            {
                authAdminContext.Logger.LogTerseEvent(MigrationEventType.Information, MSExchangeAuthAdminEventLogConstants.Tuple_AuthAdminCompleted, new string[]
                {
                    cacheEntry.ToString()
                });
            }
            return(AnchorJobProcessorResult.Waiting);
        }
Exemplo n.º 4
0
 internal AnchorJobProcessorResult InternalProcessEntry(ICacheEntry cacheEntryProxy)
 {
     this.queriedCount         = 0;
     this.tenantUpdatedCount   = 0;
     this.workItemUpdatedCount = 0;
     using (UpgradeHandlerSyncLog upgradeHandlerSyncLog = new UpgradeHandlerSyncLog("UpgradeHandlerSync"))
     {
         foreach (UpgradeRequestTypes upgradeRequestTypes in UpgradeHandlerScheduler.RequestTypes)
         {
             foreach (WorkItemStatus workItemStatus in UpgradeHandlerScheduler.WorkItemStatuses)
             {
                 base.Context.Logger.Log(MigrationEventType.Information, "Querying UpgradeRequestType '{0}' and WorkItemStatus '{1}'", new object[]
                 {
                     upgradeRequestTypes,
                     workItemStatus
                 });
                 WorkItemInfo[] array;
                 try
                 {
                     array = this.QueryWorkItems(workItemStatus, upgradeRequestTypes.ToString());
                 }
                 catch (ErrorQueryingWorkItemException ex)
                 {
                     base.Context.Logger.Log(MigrationEventType.Error, "Error Querying WorkItems of Status: {0} Type: {1} Error: {2}", new object[]
                     {
                         workItemStatus,
                         upgradeRequestTypes,
                         ex.Message
                     });
                     return(AnchorJobProcessorResult.Deleted);
                 }
                 foreach (WorkItemInfo workItemInfo in array)
                 {
                     TenantOrganizationPresentationObjectWrapper tenantOrganizationPresentationObjectWrapper = null;
                     RecipientWrapper recipientWrapper = null;
                     try
                     {
                         if (cacheEntryProxy is CacheEntryProxy)
                         {
                             AnchorJobProcessorResult anchorJobProcessorResult = base.ShouldProcessEntry(((CacheEntryProxy)cacheEntryProxy).CacheEntryBase);
                             if (anchorJobProcessorResult != AnchorJobProcessorResult.Working)
                             {
                                 base.Context.Logger.Log(MigrationEventType.Information, "Returning to anchor service because cacheEntry is '{0}'.", new object[]
                                 {
                                     anchorJobProcessorResult
                                 });
                                 return(anchorJobProcessorResult);
                             }
                         }
                         UpgradeRequestTypes upgradeRequestTypes2 = (UpgradeRequestTypes)Enum.Parse(typeof(UpgradeRequestTypes), workItemInfo.WorkItemType, true);
                         string text  = workItemInfo.Tenant.TenantId.ToString();
                         string text2 = (upgradeRequestTypes2 == UpgradeRequestTypes.PilotUpgrade) ? workItemInfo.PilotUser.PilotUserId.ToString() : null;
                         base.Context.Logger.Log(MigrationEventType.Information, "Processing workitemId '{0}' Type '{1}' Status '{2}' for TenantId '{3}'{4}", new object[]
                         {
                             workItemInfo.WorkItemId,
                             workItemInfo.WorkItemType,
                             workItemInfo.WorkItemStatus.Status,
                             text,
                             (text2 != null) ? (" PilotUserId '" + text2 + "'") : string.Empty
                         });
                         tenantOrganizationPresentationObjectWrapper = this.orgOperationProxy.GetOrganization(text);
                         base.Context.Logger.Log(MigrationEventType.Information, "Found organization '{0}' ('{1}') with UpgradeRequest '{2}' UpgradeStatus '{3}'", new object[]
                         {
                             text,
                             tenantOrganizationPresentationObjectWrapper.Name,
                             tenantOrganizationPresentationObjectWrapper.UpgradeRequest,
                             tenantOrganizationPresentationObjectWrapper.UpgradeStatus
                         });
                         if (tenantOrganizationPresentationObjectWrapper.UpgradeStatus == UpgradeStatusTypes.Error)
                         {
                             this.UpdateWIStatus(workItemInfo, WorkItemStatus.Error, tenantOrganizationPresentationObjectWrapper.UpgradeMessage);
                         }
                         else
                         {
                             if (tenantOrganizationPresentationObjectWrapper.AdminDisplayVersion.ExchangeBuild.Major != ExchangeObjectVersion.Exchange2012.ExchangeBuild.Major && (tenantOrganizationPresentationObjectWrapper.AdminDisplayVersion.ExchangeBuild.Major != ExchangeObjectVersion.Exchange2010.ExchangeBuild.Major || tenantOrganizationPresentationObjectWrapper.AdminDisplayVersion.ExchangeBuild.Minor < 16))
                             {
                                 throw new InvalidOrganizationVersionException(text, tenantOrganizationPresentationObjectWrapper.AdminDisplayVersion);
                             }
                             if (tenantOrganizationPresentationObjectWrapper.UpgradeRequest == UpgradeRequestTypes.TenantUpgradeDryRun)
                             {
                                 throw new OrganizationInDryRunModeException(text, workItemInfo.WorkItemType);
                             }
                             if (upgradeRequestTypes2 != UpgradeRequestTypes.CancelPrestageUpgrade)
                             {
                                 TenantData tenantData = new TenantData(text);
                                 tenantData.UpdateFromTenant(tenantOrganizationPresentationObjectWrapper);
                                 if (tenantData.Constraints != null && tenantData.Constraints.Length > 0)
                                 {
                                     throw new OrganizationHasConstraintsException(upgradeRequestTypes2, text, tenantOrganizationPresentationObjectWrapper.Name, string.Join(",", tenantData.Constraints));
                                 }
                             }
                             RecipientWrapper recipientWrapper2 = null;
                             if (!this.orgOperationProxy.TryGetAnchorMailbox(text, out recipientWrapper2))
                             {
                                 base.Context.Logger.Log(MigrationEventType.Information, "AnchorMailbox for '{0}' not found. Need to create it.", new object[]
                                 {
                                     tenantOrganizationPresentationObjectWrapper.Name
                                 });
                                 this.orgOperationProxy.CreateAnchorMailbox(tenantOrganizationPresentationObjectWrapper.Name);
                             }
                             else if (!recipientWrapper2.PersistedCapabilities.Contains(Capability.OrganizationCapabilityTenantUpgrade))
                             {
                                 base.Context.Logger.Log(MigrationEventType.Information, "Anchor mbx for organization '{0}' exists, but need to set TenantUpgrade capability", new object[]
                                 {
                                     text
                                 });
                                 this.orgOperationProxy.SetTenantUpgradeCapability(recipientWrapper2.Identity, true);
                             }
                             WorkItemStatus newStatus = WorkItemStatus.InProgress;
                             string         comment   = string.Empty;
                             if (upgradeRequestTypes2 == UpgradeRequestTypes.PilotUpgrade && tenantOrganizationPresentationObjectWrapper.UpgradeRequest != UpgradeRequestTypes.TenantUpgrade)
                             {
                                 recipientWrapper = this.orgOperationProxy.GetUser(text, text2);
                                 if (recipientWrapper.RecipientType != RecipientType.UserMailbox)
                                 {
                                     string text3 = string.Format("Pilot user '{0}' cannot be piloted because it is of type '{1}' instead of 'UserMailbox', completing WI", text2, recipientWrapper.RecipientType.ToString());
                                     base.Context.Logger.Log(MigrationEventType.Information, text3, new object[0]);
                                     this.orgOperationProxy.SetUser(recipientWrapper, UpgradeStatusTypes.Complete, UpgradeRequestTypes.PilotUpgrade, text3, string.Empty, new UpgradeStage?(UpgradeStage.SyncedWorkItem));
                                 }
                                 if (recipientWrapper.UpgradeRequest != UpgradeRequestTypes.PilotUpgrade)
                                 {
                                     base.Context.Logger.Log(MigrationEventType.Information, "PilotUpgrade. initializing user '{0}' to PilotUpgrade InProgress", new object[]
                                     {
                                         text2
                                     });
                                     this.orgOperationProxy.SetUser(recipientWrapper, UpgradeStatusTypes.InProgress, UpgradeRequestTypes.PilotUpgrade, string.Empty, string.Empty, new UpgradeStage?(UpgradeStage.SyncedWorkItem));
                                     upgradeHandlerSyncLog.Write(tenantOrganizationPresentationObjectWrapper, recipientWrapper, string.Empty, string.Empty);
                                 }
                                 else
                                 {
                                     if (!Enum.TryParse <WorkItemStatus>(recipientWrapper.UpgradeStatus.ToString(), out newStatus))
                                     {
                                         throw new InvalidUpgradeStatusException(recipientWrapper.Id.ToString(), recipientWrapper.UpgradeStatus);
                                     }
                                     comment = recipientWrapper.UpgradeMessage;
                                 }
                                 this.UpdateWIStatus(workItemInfo, newStatus, comment);
                             }
                             else
                             {
                                 if (upgradeRequestTypes2 != UpgradeRequestTypes.TenantUpgrade && ((upgradeRequestTypes2 != UpgradeRequestTypes.PrestageUpgrade && upgradeRequestTypes2 != UpgradeRequestTypes.CancelPrestageUpgrade) || tenantOrganizationPresentationObjectWrapper.UpgradeRequest == UpgradeRequestTypes.TenantUpgrade))
                                 {
                                     throw new InvalidRequestedTypeException(text, tenantOrganizationPresentationObjectWrapper.UpgradeRequest, workItemInfo.WorkItemType);
                                 }
                                 if (upgradeRequestTypes2 != tenantOrganizationPresentationObjectWrapper.UpgradeRequest)
                                 {
                                     base.Context.Logger.Log(MigrationEventType.Information, "Changing organization '{0}' from '{1}','{2}' to '{3}','InProgress'", new object[]
                                     {
                                         text,
                                         tenantOrganizationPresentationObjectWrapper.UpgradeRequest,
                                         tenantOrganizationPresentationObjectWrapper.UpgradeStatus,
                                         upgradeRequestTypes2
                                     });
                                     this.SetOrganization(tenantOrganizationPresentationObjectWrapper, UpgradeStatusTypes.InProgress, upgradeRequestTypes2, UpgradeStage.SyncedWorkItem);
                                     upgradeHandlerSyncLog.Write(tenantOrganizationPresentationObjectWrapper, null, string.Empty, string.Empty);
                                 }
                                 else
                                 {
                                     if (tenantOrganizationPresentationObjectWrapper.UpgradeStatus == UpgradeStatusTypes.Complete || tenantOrganizationPresentationObjectWrapper.UpgradeStatus == UpgradeStatusTypes.ForceComplete)
                                     {
                                         base.Context.Logger.Log(MigrationEventType.Information, "organization '{0}' has UpgradeStatus '{1}'. Removing Upgrade capability", new object[]
                                         {
                                             text,
                                             tenantOrganizationPresentationObjectWrapper.UpgradeStatus
                                         });
                                         this.orgOperationProxy.SetTenantUpgradeCapability(recipientWrapper2.Identity, false);
                                     }
                                     if (!Enum.TryParse <WorkItemStatus>(tenantOrganizationPresentationObjectWrapper.UpgradeStatus.ToString(), out newStatus))
                                     {
                                         throw new InvalidUpgradeStatusException(text, tenantOrganizationPresentationObjectWrapper.UpgradeStatus);
                                     }
                                     comment = tenantOrganizationPresentationObjectWrapper.UpgradeMessage;
                                 }
                                 this.UpdateWIStatus(workItemInfo, newStatus, comment);
                             }
                         }
                     }
                     catch (Exception ex2)
                     {
                         base.Context.Logger.Log(MigrationEventType.Error, "Processing workitem id '{0}' failed due to: {1}", new object[]
                         {
                             workItemInfo.WorkItemId,
                             ex2.ToString()
                         });
                         upgradeHandlerSyncLog.Write(tenantOrganizationPresentationObjectWrapper, recipientWrapper, ex2.GetType().ToString(), ex2.Message);
                         try
                         {
                             this.UpdateWIStatus(workItemInfo, (ex2 is MigrationTransientException) ? WorkItemStatus.Warning : WorkItemStatus.Error, ex2.Message);
                         }
                         catch (Exception ex3)
                         {
                             base.Context.Logger.Log(MigrationEventType.Error, "Could not report exception for workitemId '{0}' due to: {1}", new object[]
                             {
                                 workItemInfo.WorkItemId,
                                 ex3
                             });
                             upgradeHandlerSyncLog.Write(tenantOrganizationPresentationObjectWrapper, recipientWrapper, ex3.GetType().ToString(), ex3.Message);
                         }
                         try
                         {
                             if (recipientWrapper != null && recipientWrapper.UpgradeStatus != UpgradeStatusTypes.Warning && recipientWrapper.UpgradeStatus != UpgradeStatusTypes.Error)
                             {
                                 this.orgOperationProxy.SetUser(recipientWrapper, UpgradeStatusTypes.Warning, recipientWrapper.UpgradeRequest, ex2.Message, ex2.ToString(), recipientWrapper.UpgradeStage);
                             }
                             else if (tenantOrganizationPresentationObjectWrapper != null && tenantOrganizationPresentationObjectWrapper.UpgradeStatus != UpgradeStatusTypes.Warning && tenantOrganizationPresentationObjectWrapper.UpgradeStatus != UpgradeStatusTypes.Error)
                             {
                                 this.orgOperationProxy.SetOrganization(tenantOrganizationPresentationObjectWrapper, UpgradeStatusTypes.Warning, tenantOrganizationPresentationObjectWrapper.UpgradeRequest, ex2.Message, ex2.ToString(), tenantOrganizationPresentationObjectWrapper.UpgradeStage, -1, -1);
                             }
                         }
                         catch (Exception ex4)
                         {
                             base.Context.Logger.Log(MigrationEventType.Error, "Could not report exception for workitemId '{0}' for '{1}' due to: {2}", new object[]
                             {
                                 workItemInfo.WorkItemId,
                                 (recipientWrapper != null) ? recipientWrapper.ToString() : tenantOrganizationPresentationObjectWrapper.ToString(),
                                 ex4
                             });
                             upgradeHandlerSyncLog.Write(tenantOrganizationPresentationObjectWrapper, recipientWrapper, ex4.GetType().ToString(), ex4.Message);
                         }
                         if (!(ex2 is LocalizedException))
                         {
                             throw;
                         }
                     }
                 }
             }
         }
     }
     base.Context.Logger.Log(MigrationEventType.Information, "Total WorkItems Queried: {0} Total Tenants Updated: {1} Total WorkItems Updated: {2}", new object[]
     {
         this.queriedCount,
         this.tenantUpdatedCount,
         this.workItemUpdatedCount
     });
     return(AnchorJobProcessorResult.Deleted);
 }