Ejemplo n.º 1
0
        private Dictionary <Guid, RpcDatabaseCopyStatus2> GetCopyStatusRpcResults()
        {
            Dictionary <Guid, RpcDatabaseCopyStatus2> result = null;
            ServerVersion adminDisplayVersion = ReplicationCheckGlobals.Server.AdminDisplayVersion;

            if (ReplicationCheckGlobals.WriteVerboseDelegate != null)
            {
                ReplicationCheckGlobals.WriteVerboseDelegate(Strings.TestRHUseCopyStatusRpc(adminDisplayVersion.ToString(), ReplayRpcVersionControl.GetCopyStatusEx2SupportVersion.ToString()));
            }
            RpcDatabaseCopyStatus2[] copyStatus = ReplayRpcClientHelper.GetCopyStatus(base.ServerName, ReplicationCheckGlobals.RunningInMonitoringContext ? RpcGetDatabaseCopyStatusFlags2.None : RpcGetDatabaseCopyStatusFlags2.ReadThrough, null);
            if (copyStatus != null && copyStatus.Length > 0)
            {
                result = ReplayRpcClientHelper.ParseStatusResults(copyStatus);
                if (ReplicationCheckGlobals.WriteVerboseDelegate != null)
                {
                    ReplicationCheckGlobals.WriteVerboseDelegate(Strings.TestRHRpcQueryAllDone(copyStatus.Length));
                }
            }
            return(result);
        }
        private void PreventMoveOfActiveSeedingSource(AmServerName server, Database[] databases)
        {
            if (this.SkipActiveCopyChecks)
            {
                TaskLogger.Trace("PreventMoveOfActiveSeedingSource: Check skipped because -SkipActiveCopyChecks flag is specified.", new object[0]);
                return;
            }
            Exception ex = null;

            RpcDatabaseCopyStatus2[] array = null;
            try
            {
                Guid[] array2 = null;
                if (databases != null && databases.Length > 0)
                {
                    array2 = new Guid[databases.Length];
                    for (int i = 0; i < databases.Length; i++)
                    {
                        array2[i] = databases[i].Guid;
                    }
                }
                array = ReplayRpcClientHelper.GetCopyStatus(server.Fqdn, RpcGetDatabaseCopyStatusFlags2.ReadThrough, array2);
            }
            catch (TaskServerTransientException ex2)
            {
                ex = ex2;
            }
            catch (TaskServerException ex3)
            {
                ex = ex3;
            }
            if (ex != null)
            {
                TaskLogger.Trace("PreventMoveOfActiveSeedingSource: Check failed because of exception: {2}", new object[]
                {
                    ex
                });
                base.WriteError(new ErrorMoveUnableToGetCopyStatusException(server.NetbiosName, ex.Message), ErrorCategory.InvalidOperation, server.Fqdn);
            }
            foreach (RpcDatabaseCopyStatus2 rpcDatabaseCopyStatus in array)
            {
                if (SharedHelper.StringIEquals(rpcDatabaseCopyStatus.ActiveDatabaseCopy, server.NetbiosName) && rpcDatabaseCopyStatus.SeedingSource)
                {
                    if (!rpcDatabaseCopyStatus.SeedingSourceForDB)
                    {
                        if (rpcDatabaseCopyStatus.SeedingSourceForDB || rpcDatabaseCopyStatus.SeedingSourceForCI)
                        {
                            goto IL_1B6;
                        }
                    }
                    try
                    {
                        IADDatabase iaddatabase = AmHelper.FindDatabaseByGuid(rpcDatabaseCopyStatus.DBGuid);
                        TaskLogger.Trace("PreventMoveOfActiveSeedingSource: Check failed for {0}\\{1} because it is seeding source.", new object[]
                        {
                            iaddatabase.Name,
                            rpcDatabaseCopyStatus.MailboxServer
                        });
                        base.WriteError(new ErrorMoveActiveCopyIsSeedingSourceException(iaddatabase.Name, rpcDatabaseCopyStatus.MailboxServer), ErrorCategory.InvalidOperation, iaddatabase.Identity);
                    }
                    catch (AmDatabaseNotFoundException ex4)
                    {
                        TaskLogger.Trace("PreventMoveOfActiveSeedingSource: Check failed for '{0}' because it is not found in AD. Error: {1}", new object[]
                        {
                            rpcDatabaseCopyStatus.DBGuid,
                            ex4.Message
                        });
                        base.WriteError(new ErrorMoveActiveCopyNotFoundException(rpcDatabaseCopyStatus.DBGuid, ex4.Message), ErrorCategory.InvalidOperation, rpcDatabaseCopyStatus.DBGuid);
                    }
                }
                IL_1B6 :;
            }
        }
        private DatabaseCopyStatusEntry[] PrepareStatusEntryFromRpc(Server server, Collection <DatabaseCopy> databaseCopies)
        {
            DatabaseCopyStatusEntry[] array = new DatabaseCopyStatusEntry[databaseCopies.Count];
            Guid[] array2 = new Guid[databaseCopies.Count];
            for (int i = 0; i < databaseCopies.Count; i++)
            {
                DatabaseCopy databaseCopy3 = databaseCopies[i];
                Database     database      = databaseCopy3.GetDatabase <Database>();
                array2[i] = database.Guid;
                array[i]  = this.ConstructNewSatusEntry(databaseCopy3);
            }
            RpcGetDatabaseCopyStatusFlags2 rpcGetDatabaseCopyStatusFlags = RpcGetDatabaseCopyStatusFlags2.None;

            if (!this.UseServerCache)
            {
                rpcGetDatabaseCopyStatusFlags |= RpcGetDatabaseCopyStatusFlags2.ReadThrough;
            }
            try
            {
                IEnumerable <string> source = from databaseCopy in databaseCopies
                                              select databaseCopy.DatabaseName;
                base.WriteVerbose(Strings.GetDbcsRpcQuery(server.Fqdn, string.Join(",", source.ToArray <string>())));
                RpcDatabaseCopyStatus2[] copyStatus = ReplayRpcClientHelper.GetCopyStatus(server.Fqdn, rpcGetDatabaseCopyStatusFlags, array2);
                if (copyStatus != null && copyStatus.Length > 0)
                {
                    base.WriteVerbose(Strings.GetDbcsRpcQueryAllDone(copyStatus.Length));
                    Dictionary <Guid, RpcDatabaseCopyStatus2> dictionary = new Dictionary <Guid, RpcDatabaseCopyStatus2>(copyStatus.Length);
                    for (int j = 0; j < copyStatus.Length; j++)
                    {
                        dictionary[copyStatus[j].DBGuid] = copyStatus[j];
                    }
                    for (int k = 0; k < array2.Length; k++)
                    {
                        RpcDatabaseCopyStatus2 copyStatus2;
                        if (dictionary.TryGetValue(array2[k], out copyStatus2))
                        {
                            GetMailboxDatabaseCopyStatus.GetEntryFromStatus(copyStatus2, array[k]);
                        }
                        else if (!databaseCopies[k].IsValid)
                        {
                            ExTraceGlobals.CmdletsTracer.TraceDebug <Guid, string>((long)this.GetHashCode(), "GetCopyStatus() didn't find replica instance for database {0} on server {1}. The DatabaseCopy is misconfigured in the Active Directory!", array2[k], server.Fqdn);
                            this.UpdateMisconfiguredCopyStatusEntry(array[k], databaseCopies[k]);
                        }
                        else
                        {
                            ExTraceGlobals.CmdletsTracer.TraceDebug <Guid, string>((long)this.GetHashCode(), "GetCopyStatus() didn't find replica instance for database {0} on server {1}.", array2[k], server.Fqdn);
                            this.UpdateCopyStatusNoReplicaInstance(array[k]);
                        }
                    }
                }
            }
            catch (ArgumentException ex)
            {
                ExTraceGlobals.CmdletsTracer.TraceError <ArgumentException>((long)this.GetHashCode(), "GetMailboxDatabaseCopyStatus: ArgumentException: {0}", ex);
                this.WriteError(ex, ErrorCategory.ReadError, null, false);
            }
            catch (TaskServerTransientException ex2)
            {
                ExTraceGlobals.CmdletsTracer.TraceError <TaskServerTransientException>((long)this.GetHashCode(), "GetMailboxDatabaseCopyStatus: ArgumentException: {0}", ex2);
                this.WriteError(ex2, ErrorCategory.ReadError, null, false);
            }
            catch (TaskServerException ex3)
            {
                ExTraceGlobals.CmdletsTracer.TraceError <TaskServerException>((long)this.GetHashCode(), "GetMailboxDatabaseCopyStatus: ReplayServiceRpcException: {0}", ex3);
                if (ex3 is ReplayServiceDownException)
                {
                    base.WriteVerbose(Strings.GetDbcsDetectReplayServiceDown(server.Fqdn, ex3.Message));
                    for (int l = 0; l < array.Length; l++)
                    {
                        DatabaseCopyStatusEntry databaseCopyStatusEntry = array[l];
                        DatabaseCopy            databaseCopy2           = databaseCopies[l];
                        if (!databaseCopy2.IsValid)
                        {
                            this.UpdateMisconfiguredCopyStatusEntry(databaseCopyStatusEntry, databaseCopy2);
                        }
                        else
                        {
                            databaseCopyStatusEntry.Status              = CopyStatus.ServiceDown;
                            databaseCopyStatusEntry.m_errorMessage      = ex3.Message;
                            databaseCopyStatusEntry.m_extendedErrorInfo = new ExtendedErrorInfo(ex3);
                        }
                    }
                }
                else if (ex3 is ReplayServiceRpcUnknownInstanceException)
                {
                    ExTraceGlobals.CmdletsTracer.TraceDebug <string>((long)this.GetHashCode(), "GetCopyStatus() was not able to find any replica instances on server {0}.", server.Fqdn);
                    for (int m = 0; m < array.Length; m++)
                    {
                        if (!databaseCopies[m].IsValid)
                        {
                            this.UpdateMisconfiguredCopyStatusEntry(array[m], databaseCopies[m]);
                        }
                        else
                        {
                            this.UpdateCopyStatusNoReplicaInstance(array[m]);
                        }
                    }
                }
                else
                {
                    this.WriteError(ex3, ErrorCategory.ReadError, null, false);
                }
            }
            return(array);
        }