Esempio n. 1
0
        public static void MoveClusterGroupWithTimeout(AmServerName clusterNode, AmServerName destinationNode, TimeSpan timeout)
        {
            uint errorCode = 0U;
            bool flag      = false;

            try
            {
                InvokeWithTimeout.Invoke(delegate()
                {
                    using (IAmCluster amCluster = MockableCluster.Instance.OpenByName(clusterNode))
                    {
                        using (IAmClusterGroup amClusterGroup = amCluster.FindCoreClusterGroup())
                        {
                            if (!amClusterGroup.OwnerNode.Equals(destinationNode))
                            {
                                amClusterGroup.MoveGroup(timeout, destinationNode);
                            }
                        }
                    }
                }, timeout);
            }
            catch (TimeoutException)
            {
                errorCode = 258U;
                flag      = true;
            }
            if (flag)
            {
                throw AmExceptionHelper.ConstructClusterApiException((int)errorCode, "MoveClusterGroup( dest={0}, timeout={1})", new object[]
                {
                    destinationNode.NetbiosName,
                    timeout
                });
            }
        }
Esempio n. 2
0
 // Token: 0x060008AE RID: 2222 RVA: 0x00029798 File Offset: 0x00027998
 internal static void RevertToMnsQuorum(ILogTraceHelper output, IAmCluster cluster)
 {
     using (IAmClusterGroup amClusterGroup = cluster.FindCoreClusterGroup())
     {
         string text;
         uint   maxLogSize;
         string quorumResourceInformation = cluster.GetQuorumResourceInformation(out text, out maxLogSize);
         if (string.IsNullOrEmpty(quorumResourceInformation))
         {
             output.AppendLogMessage("RevertToMnsQuorum: It's already using MNS!", new object[0]);
             using (IAmClusterResource amClusterResource = amClusterGroup.FindResourceByTypeName("File Share Witness"))
             {
                 if (amClusterResource != null)
                 {
                     output.AppendLogMessage("Even though the quorum is set to MNS, there is a FSW resource present named '{0}', which will be deleted shortly.", new object[]
                     {
                         amClusterResource.Name
                     });
                     amClusterResource.DeleteResource();
                     output.AppendLogMessage("The resource has been deleted!", new object[0]);
                 }
                 goto IL_13D;
             }
         }
         using (AmClusterResource amClusterResource2 = cluster.OpenResource(quorumResourceInformation))
         {
             output.AppendLogMessage("Setting cluster quorum to MNS", new object[0]);
             if (cluster.CnoName == string.Empty)
             {
                 cluster.ClearQuorumResource();
             }
             else
             {
                 using (IAmClusterResource amClusterResource3 = amClusterGroup.FindResourceByTypeName("Network Name"))
                 {
                     output.AppendLogMessage("Setting cluster quorum resource to the netname resource (i.e. MNS quorum).", new object[0]);
                     cluster.SetQuorumResource(amClusterResource3, null, maxLogSize);
                     if (amClusterResource2 != null && amClusterResource2.GetTypeName() == "File Share Witness")
                     {
                         output.AppendLogMessage("Offlining and deleting the old FSW resource '{0}'.", new object[]
                         {
                             quorumResourceInformation
                         });
                         amClusterResource2.OfflineResource();
                         amClusterResource2.DeleteResource();
                     }
                 }
             }
         }
         IL_13D :;
     }
 }
Esempio n. 3
0
 // Token: 0x060008B4 RID: 2228 RVA: 0x00029BAC File Offset: 0x00027DAC
 internal static void FollowBestPractices(ITaskOutputHelper output, IAmCluster cluster)
 {
     if (string.Empty != cluster.CnoName)
     {
         using (IAmClusterGroup amClusterGroup = cluster.FindCoreClusterGroup())
         {
             using (IAmClusterResource amClusterResource = amClusterGroup.FindResourceByTypeName("Network Name"))
             {
                 output.AppendLogMessage("Setting the DNS TTL to 300", new object[0]);
                 amClusterResource.SetPrivateProperty <int>("HostRecordTTL", 300);
             }
         }
     }
 }
Esempio n. 4
0
        public static bool MovePrimaryActiveManagerRole(string CurrentPrimaryName)
        {
            AmServerName serverName = new AmServerName(CurrentPrimaryName);
            bool         result;

            using (IAmCluster amCluster = ClusterFactory.Instance.OpenByName(serverName))
            {
                using (IAmClusterGroup amClusterGroup = amCluster.FindCoreClusterGroup())
                {
                    string text;
                    result = amClusterGroup.MoveGroupToReplayEnabledNode((string targetNode) => AmHelper.IsReplayRunning(targetNode), "Network Name", new TimeSpan(0, 3, 0), out text);
                }
            }
            return(result);
        }
Esempio n. 5
0
 // Token: 0x060008AD RID: 2221 RVA: 0x000296B0 File Offset: 0x000278B0
 private static void SetFswSharePath(ITaskOutputHelper output, IAmCluster cluster, IAmClusterResource fsw, string fswShare)
 {
     try
     {
         fsw.OfflineResource();
         fsw.SetPrivateProperty <string>("SharePath", fswShare);
         fsw.OnlineResource();
     }
     catch (ClusterException ex)
     {
         Win32Exception ex2 = null;
         if (ex.TryGetTypedInnerException(out ex2))
         {
             output.AppendLogMessage("SetFswSharePath() caught an AmClusterApiException with errorcode={0} and NativeErrorCode={1}. ex = {2}", new object[]
             {
                 ex2.ErrorCode,
                 ex2.NativeErrorCode,
                 ex2
             });
             if (ex2.NativeErrorCode == 5)
             {
                 string text = cluster.CnoName;
                 if (text == string.Empty)
                 {
                     using (IAmClusterGroup amClusterGroup = cluster.FindCoreClusterGroup())
                     {
                         if (amClusterGroup != null && amClusterGroup.OwnerNode != null)
                         {
                             text = amClusterGroup.OwnerNode.NetbiosName;
                         }
                     }
                 }
                 output.WriteErrorSimple(new DagTaskFswNeedsCnoPermissionException(fswShare, text));
             }
         }
         throw;
     }
 }
Esempio n. 6
0
        // Token: 0x060001A2 RID: 418 RVA: 0x0000A078 File Offset: 0x00008278
        internal static bool AttemptServerSwitchoverOnShutdown()
        {
            AmTrace.Entering("ActiveManagerCore.AttemptServerSwitchoverOnShutdown", new object[0]);
            ExDateTime utcNow = ExDateTime.UtcNow;

            ReplayEventLogConstants.Tuple_PreShutdownStart.LogEvent(null, new object[0]);
            Exception ex     = null;
            bool      result = false;

            try
            {
                AmConfig config = AmSystemManager.Instance.Config;
                if (config.IsPamOrSam)
                {
                    string fqdn = config.DagConfig.CurrentPAM.Fqdn;
                    AmTrace.Debug("{0} Trying to mount all the databases on other servers", new object[]
                    {
                        ExDateTime.Now
                    });
                    AmRpcClientHelper.ServerSwitchOver(fqdn, AmServerName.LocalComputerName.Fqdn);
                    if (config.IsPAM)
                    {
                        AmTrace.Debug("{0} Trying to move PAM off this node", new object[]
                        {
                            ExDateTime.Now
                        });
                        using (IAmCluster amCluster = ClusterFactory.Instance.Open())
                        {
                            using (IAmClusterGroup amClusterGroup = amCluster.FindCoreClusterGroup())
                            {
                                TimeSpan ts       = ExDateTime.UtcNow.Subtract(utcNow);
                                TimeSpan timeSpan = TimeSpan.FromSeconds(115.0).Subtract(ts);
                                if (!(timeSpan <= TimeSpan.Zero))
                                {
                                    if (amClusterGroup.MoveGroupToReplayEnabledNode((string targetNode) => AmHelper.IsReplayRunning(targetNode), "Network Name", timeSpan, out fqdn))
                                    {
                                        ReplayEventLogConstants.Tuple_SuccMovePAM.LogEvent(null, new object[]
                                        {
                                            Environment.MachineName,
                                            fqdn
                                        });
                                        AmTrace.Debug("{0} Moved PAM to another node", new object[]
                                        {
                                            ExDateTime.Now
                                        });
                                        goto IL_197;
                                    }
                                }
                                ReplayEventLogConstants.Tuple_FailedMovePAM.LogEvent(null, new object[]
                                {
                                    Environment.MachineName
                                });
                                IL_197 :;
                            }
                        }
                    }
                    result = true;
                    ReplayEventLogConstants.Tuple_PreShutdownOK.LogEvent(null, new object[0]);
                }
            }
            catch (ClusterException ex2)
            {
                ex = ex2;
            }
            catch (AmRpcException ex3)
            {
                ex = ex3;
            }
            catch (AmServerTransientException ex4)
            {
                ex = ex4;
            }
            catch (AmServerException ex5)
            {
                ex = ex5;
            }
            finally
            {
                if (ex != null)
                {
                    ReplayEventLogConstants.Tuple_PreShutdownFailed.LogEvent(null, new object[]
                    {
                        ex.Message
                    });
                }
                AmTrace.Leaving("ActiveManagerCore.AttemptServerSwitchoverOnShutdown", new object[0]);
            }
            return(result);
        }
Esempio n. 7
0
        // Token: 0x060008AC RID: 2220 RVA: 0x00029304 File Offset: 0x00027504
        internal static void CreateFileShareWitnessQuorum(ITaskOutputHelper output, IAmCluster cluster, string fswShare)
        {
            output = (output ?? NullTaskOutputHelper.GetNullLogger());
            IAmClusterGroup amClusterGroup = cluster.FindCoreClusterGroup();

            if (amClusterGroup == null)
            {
                Thread.Sleep(10000);
                amClusterGroup = cluster.FindCoreClusterGroup();
                if (amClusterGroup == null)
                {
                    throw new FailedToGetClusterCoreGroupException();
                }
            }
            using (amClusterGroup)
            {
                IEnumerable <AmClusterResource> source = amClusterGroup.EnumerateResourcesOfType("File Share Witness");
                IAmClusterResource amClusterResource   = source.ElementAtOrDefault(0);
                try
                {
                    bool flag = false;
                    if (amClusterResource == null)
                    {
                        output.AppendLogMessage("CreateFileShareWitnessQuorum: Could not find an existing FSW resource. A new one will be created.", new object[0]);
                        flag = true;
                    }
                    else if (amClusterResource.GetState() == AmResourceState.Failed)
                    {
                        output.AppendLogMessage("CreateFileShareWitnessQuorum: The existing FSW resource is in a Failed state. It should be deleted and recreated.", new object[0]);
                        flag = true;
                    }
                    else
                    {
                        string privateProperty = amClusterResource.GetPrivateProperty <string>("SharePath");
                        if (!SharedHelper.StringIEquals(privateProperty, fswShare))
                        {
                            output.AppendLogMessage("CreateFileShareWitnessQuorum: There is already a FSW, but the current share path ({0}) is not what's desired ({1}). Will try to fix it.", new object[]
                            {
                                privateProperty,
                                fswShare
                            });
                            List <string> list = new List <string>(4);
                            foreach (IAmClusterNode amClusterNode in cluster.EnumerateNodes())
                            {
                                using (amClusterNode)
                                {
                                    if (!AmClusterNode.IsNodeUp(amClusterNode.State))
                                    {
                                        list.Add(amClusterNode.Name.NetbiosName);
                                    }
                                }
                            }
                            if (list.Count > 0)
                            {
                                output.WriteErrorSimple(new DagTaskSetDagNeedsAllNodesUpToChangeQuorumException(string.Join(",", list.ToArray())));
                            }
                            DagHelper.SetFswSharePath(output, cluster, amClusterResource, fswShare);
                        }
                    }
                    AmResourceState state;
                    if (!flag && amClusterResource != null)
                    {
                        try
                        {
                            state = amClusterResource.GetState();
                            if (state != AmResourceState.Online)
                            {
                                output.AppendLogMessage("The FSW is not online (it is {0}). Attempting to bring online.", new object[]
                                {
                                    state
                                });
                                amClusterResource.OnlineResource();
                            }
                            state = amClusterResource.GetState();
                            output.AppendLogMessage("The fsw resource is now in state {0}.", new object[]
                            {
                                state
                            });
                            if (state != AmResourceState.Online)
                            {
                                flag = true;
                            }
                        }
                        catch (ClusterException ex)
                        {
                            output.AppendLogMessage("Bringing the FSW resource online failed, so it will be deleted and recreated. For the record, the error was {0}", new object[]
                            {
                                ex
                            });
                            flag = true;
                        }
                    }
                    if (flag)
                    {
                        if (amClusterResource != null)
                        {
                            amClusterResource.Dispose();
                            amClusterResource = null;
                        }
                        output.AppendLogMessage("CreateFileShareWitnessQuorum: Calling RevertToMnsQuorum to clean everything up first.", new object[0]);
                        DagHelper.RevertToMnsQuorum(output, cluster);
                        string text = string.Format("File Share Witness ({0})", fswShare);
                        output.AppendLogMessage("Creating a new file share witness resource named '{0}'.", new object[]
                        {
                            text
                        });
                        amClusterResource = amClusterGroup.CreateResource(text, "File Share Witness");
                        DagHelper.SetFswSharePath(output, cluster, amClusterResource, fswShare);
                    }
                    output.AppendLogMessage("The FSW resource is now in state {0}.", new object[]
                    {
                        amClusterResource.GetState()
                    });
                    string text2;
                    uint   maxLogSize;
                    string quorumResourceInformation = cluster.GetQuorumResourceInformation(out text2, out maxLogSize);
                    output.AppendLogMessage("The current quorum resource is '{0}'. About to set it to the FSW.", new object[]
                    {
                        quorumResourceInformation
                    });
                    state = amClusterResource.GetState();
                    if (state != AmResourceState.Online)
                    {
                        output.WriteErrorSimple(new DagTaskFileShareWitnessResourceIsStillNotOnlineException(fswShare, state.ToString()));
                    }
                    cluster.SetQuorumResource(amClusterResource, null, maxLogSize);
                    quorumResourceInformation = cluster.GetQuorumResourceInformation(out text2, out maxLogSize);
                    output.AppendLogMessage("The quorum resource is now '{0}'.", new object[]
                    {
                        quorumResourceInformation
                    });
                    output.AppendLogMessage("Bringing the quorum resource online...", new object[0]);
                    amClusterResource.OnlineResource();
                }
                finally
                {
                    if (amClusterResource != null)
                    {
                        amClusterResource.Dispose();
                        amClusterResource = null;
                    }
                }
            }
        }