RecipientWrapper IOrganizationOperation.GetUser(string organizationId, string userId)
        {
            RecipientWrapper result;

            using (AnchorRunspaceProxy anchorRunspaceProxy = AnchorRunspaceProxy.CreateRunspaceForDatacenterAdmin(this.Context, "upgradehandlers"))
            {
                PSCommand pscommand = new PSCommand();
                pscommand.AddCommand("Get-User");
                pscommand.AddParameter("Organization", organizationId);
                pscommand.AddParameter("Identity", userId);
                User user;
                try
                {
                    user = anchorRunspaceProxy.RunPSCommandSingleOrDefault <User>(pscommand);
                }
                catch (Exception ex)
                {
                    this.Context.Logger.Log(MigrationEventType.Error, "MigrationPermanentException from GetUser '{0}'.{1}", new object[]
                    {
                        userId,
                        ex
                    });
                    if (ex.InnerException is ManagementObjectNotFoundException)
                    {
                        throw new UserNotFoundException(userId, ex.InnerException);
                    }
                    throw;
                }
                result = new RecipientWrapper(user);
            }
            return(result);
        }
Beispiel #2
0
 public void Write(TenantOrganizationPresentationObjectWrapper tenant, RecipientWrapper user, string errorType, string errorDetails)
 {
     base.LogObject(new TenantUpgradeData
     {
         Tenant       = tenant,
         PilotUser    = user,
         ErrorType    = errorType,
         ErrorDetails = errorDetails
     });
 }
Beispiel #3
0
        public IEnumerable <RecipientWrapper> FindPilotUsersADRawEntry(ADObjectId rootId, QueryScope scope, QueryFilter filter, SortBy sortBy, int pageSize, IEnumerable <PropertyDefinition> properties)
        {
            ADPagedReader <ADRawEntry> pagedReader = this.anchorAdProvider.FindPagedADRawEntry(rootId, scope, filter, sortBy, pageSize, properties);

            foreach (ADRawEntry adRawEntry in pagedReader)
            {
                RecipientWrapper wrappedRecipient = new RecipientWrapper(adRawEntry.Id, RequestStatus.None, null, RequestFlags.None, RecipientType.UserMailbox, RecipientTypeDetails.None);
                yield return(wrappedRecipient);
            }
            yield break;
        }
Beispiel #4
0
        public IEnumerable <RecipientWrapper> FindPagedMiniRecipient(UpgradeBatchCreatorScheduler.MailboxType mailboxType, ADObjectId rootId, QueryScope scope, QueryFilter filter, SortBy sortBy, int pageSize, IEnumerable <PropertyDefinition> properties)
        {
            ADPagedReader <MiniRecipient> pagedReader = this.anchorAdProvider.FindPagedMiniRecipient <MiniRecipient>(rootId, scope, filter, sortBy, pageSize, properties);

            foreach (MiniRecipient recipient in pagedReader)
            {
                RequestStatus    moveStatus       = (RequestStatus)recipient[SharedPropertyDefinitions.MailboxMoveStatus];
                string           moveBatchName    = (string)recipient[SharedPropertyDefinitions.MailboxMoveBatchName];
                RequestFlags     requestFlags     = (RequestFlags)recipient[SharedPropertyDefinitions.MailboxMoveFlags];
                RecipientWrapper wrappedRecipient = new RecipientWrapper(recipient.Id, moveStatus, moveBatchName, requestFlags, recipient.RecipientType, recipient.RecipientTypeDetails);
                yield return(wrappedRecipient);
            }
            yield break;
        }
        bool IOrganizationOperation.TryGetAnchorMailbox(string tenantId, out RecipientWrapper anchorMailbox)
        {
            anchorMailbox = null;
            bool result;

            using (AnchorRunspaceProxy anchorRunspaceProxy = AnchorRunspaceProxy.CreateRunspaceForDatacenterAdmin(this.Context, "upgradehandlers"))
            {
                PSCommand pscommand = new PSCommand();
                pscommand.AddCommand("Get-Mailbox");
                pscommand.AddParameter("Arbitration");
                pscommand.AddParameter("Organization", tenantId);
                pscommand.AddParameter("Identity", "Migration.8f3e7716-2011-43e4-96b1-aba62d229136");
                Mailbox mailbox;
                try
                {
                    mailbox = anchorRunspaceProxy.RunPSCommandSingleOrDefault <Mailbox>(pscommand);
                    if (mailbox == null)
                    {
                        this.Context.Logger.Log(MigrationEventType.Error, "Get-AnchorMailbox for '{0}' returned null", new object[0]);
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null && ex.InnerException is ManagementObjectNotFoundException)
                    {
                        this.Context.Logger.Log(MigrationEventType.Information, "Get-AnchorMailbox for '{0}' failed due to: {1}", new object[]
                        {
                            tenantId,
                            ex.InnerException
                        });
                        return(false);
                    }
                    this.Context.Logger.Log(MigrationEventType.Error, "Get-AnchorMailbox for '{0}' failed due to: {1}", new object[]
                    {
                        tenantId,
                        ex
                    });
                    throw;
                }
                anchorMailbox = new RecipientWrapper(mailbox);
                result        = true;
            }
            return(result);
        }
        void IOrganizationOperation.SetUser(RecipientWrapper user, UpgradeStatusTypes status, UpgradeRequestTypes request, string message, string details, UpgradeStage?stage)
        {
            PSCommand pscommand = new PSCommand();

            pscommand.AddCommand("Set-User");
            pscommand.AddParameter("Identity", user.Id.ToDNString());
            if (user.UpgradeStatus != status)
            {
                pscommand.AddParameter("UpgradeStatus", status);
                user.UpgradeStatus = status;
            }
            if (user.UpgradeRequest != request)
            {
                pscommand.AddParameter("UpgradeRequest", request);
                user.UpgradeRequest = request;
            }
            if (user.UpgradeMessage != message)
            {
                pscommand.AddParameter("UpgradeMessage", message);
                user.UpgradeMessage = message;
            }
            if (user.UpgradeDetails != details)
            {
                pscommand.AddParameter("UpgradeDetails", details);
                user.UpgradeDetails = details;
            }
            if (user.UpgradeStage != stage)
            {
                pscommand.AddParameter("UpgradeStage", stage);
                user.UpgradeStage          = stage;
                user.UpgradeStageTimeStamp = ((stage != null) ? new DateTime?(DateTime.UtcNow) : null);
                pscommand.AddParameter("UpgradeStageTimeStamp", user.UpgradeStageTimeStamp);
            }
            if (pscommand.Commands[0].Parameters.Count > 1)
            {
                this.RunPSCommandForOrgOrUser(pscommand);
                return;
            }
            this.Context.Logger.Log(MigrationEventType.Information, "Set-User will not be invoked because no property values have been changed", new object[0]);
        }
Beispiel #7
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);
 }