Пример #1
0
 internal static bool IsClusterUp(DatabaseAvailabilityGroup dag, HaTaskOutputHelper output)
 {
     try
     {
         using (AmCluster amCluster = AmCluster.OpenDagClus(dag))
         {
             using (IAmClusterGroup amClusterGroup = amCluster.FindCoreClusterGroup())
             {
                 IEnumerable <AmServerName> source = amCluster.EnumerateNodeNames();
                 output.AppendLogMessage("Cluster is up, there are {0} nodes in the cluster, group owner:{1}", new object[]
                 {
                     source.Count <AmServerName>(),
                     amClusterGroup.OwnerNode.NetbiosName
                 });
             }
         }
     }
     catch (AmCoreGroupRegNotFound amCoreGroupRegNotFound)
     {
         output.AppendLogMessage("Cluster is down, got AmCoreGroupRegNotFound:{0} when trying to open the cluster", new object[]
         {
             amCoreGroupRegNotFound.ToString()
         });
         return(false);
     }
     return(true);
 }
Пример #2
0
        internal static void EvictStoppedNodes(DatabaseAvailabilityGroup dag, IEnumerable <Server> stoppedServers, HaTaskOutputHelper output)
        {
            if (dag == null)
            {
                throw new ArgumentNullException("dag");
            }
            if (stoppedServers == null)
            {
                throw new ArgumentNullException("stoppedServers");
            }
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            string        error      = null;
            List <string> list       = new List <string>(1);
            string        verboseLog = null;

            using (AmCluster amCluster = AmCluster.OpenDagClus(dag))
            {
                using (IAmClusterGroup amClusterGroup = amCluster.FindCoreClusterGroup())
                {
                    output.AppendLogMessage("EvictStoppedNodes has been called. Dumping current cluster state.", new object[0]);
                    try
                    {
                        using (DumpClusterTopology dumpClusterTopology = new DumpClusterTopology(amCluster, output))
                        {
                            dumpClusterTopology.Dump();
                        }
                    }
                    catch (ClusterException ex)
                    {
                        output.AppendLogMessage("DumpClusterTopology( {0} ) failed with exception = {1}. This is OK.", new object[]
                        {
                            dag.Name,
                            ex.Message
                        });
                        output.AppendLogMessage("Ignoring previous error, as it is acceptable if the cluster does not exist yet.", new object[0]);
                    }
                    IEnumerable <AmServerName> source = amCluster.EnumerateNodeNames();
                    AmServerName ownerNode            = amClusterGroup.OwnerNode;
                    int          num = stoppedServers.Count <Server>();
                    foreach (Server server in stoppedServers)
                    {
                        AmServerName amServerName = new AmServerName(server);
                        if (source.Contains(amServerName))
                        {
                            output.AppendLogMessage("Server '{0}' is still a node in the cluster, and will have to be evicted.", new object[]
                            {
                                amServerName.NetbiosName
                            });
                            try
                            {
                                try
                                {
                                    output.WriteProgressIncrementalSimple(Strings.ProgressForceCleanupNode(server.Name), 20 / num);
                                    output.AppendLogMessage("Running the eviction operation by issuing an RPC to the replay service on '{0}'...", new object[]
                                    {
                                        ownerNode.Fqdn
                                    });
                                    ReplayRpcClientWrapper.RunEvictNodeFromCluster(ownerNode, amServerName, out verboseLog);
                                }
                                finally
                                {
                                    DagTaskHelper.LogRemoteVerboseLog(output, ownerNode.Fqdn, verboseLog);
                                }
                            }
                            catch (DagTaskOperationFailedException ex2)
                            {
                                output.AppendLogMessage("An exception was thrown! ex={0}", new object[]
                                {
                                    ex2.Message
                                });
                                Exception ex3;
                                if (ex2.TryGetInnerExceptionOfType(out ex3))
                                {
                                    output.AppendLogMessage("Ignore it. It was AmClusterEvictWithoutCleanupException, which is acceptable. It could be completed with cluster node /forcecleanp, but that isn't necessary.", new object[0]);
                                }
                                else if (ex2.TryGetInnerExceptionOfType(out ex3))
                                {
                                    output.AppendLogMessage("That exception is fine. It means that the server has already been evicted from the cluster.", new object[0]);
                                }
                                else
                                {
                                    error = ex2.Message;
                                    output.WriteWarning(Strings.FailedToEvictNode(server.Name, dag.Name, error));
                                    list.Add(server.Name);
                                }
                            }
                            catch (LocalizedException ex4)
                            {
                                error = ex4.Message;
                                output.WriteWarning(Strings.FailedToEvictNode(server.Name, dag.Name, error));
                                list.Add(server.Name);
                            }
                        }
                        else
                        {
                            output.AppendLogMessage("Server '{0}' is not in the cluster anymore. It must have already been evicted.", new object[]
                            {
                                amServerName.NetbiosName
                            });
                        }
                    }
                }
            }
            if (list.Count != 0)
            {
                output.WriteErrorSimple(new FailedToEvictNodeException(string.Join(",", list.ToArray <string>()), dag.Name, error));
            }
        }
        protected override void InternalValidate()
        {
            TaskLogger.LogEnter();
            base.InternalValidate();
            this.m_output            = new HaTaskOutputHelper("set-databaseavailabilitygroup", new Task.TaskErrorLoggingDelegate(base.WriteError), new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.TaskProgressLoggingDelegate(base.WriteProgress), this.GetHashCode());
            this.m_dag               = this.DataObject;
            this.m_skipDagValidation = this.SkipDagValidation;
            DagTaskHelper.VerifyDagAndServersAreWithinScopes <DatabaseAvailabilityGroup>(this, this.m_dag, true);
            if (this.DatabaseAvailabilityGroupIpAddresses != null)
            {
                if (!this.m_dag.IsDagEmpty())
                {
                    this.PrepareServersInDagIfRequired();
                    foreach (AmServerName amServerName in this.m_serverNamesInDag)
                    {
                        DagTaskHelper.ValidateIPAddressList(this.m_output, amServerName.NetbiosName, this.DatabaseAvailabilityGroupIpAddresses, this.m_dag.Name);
                        DagTaskHelper.ValidateIPAddressList(this.m_output, amServerName.Fqdn, this.DatabaseAvailabilityGroupIpAddresses, this.m_dag.Name);
                    }
                }
                foreach (IPAddress ipaddress in this.DatabaseAvailabilityGroupIpAddresses)
                {
                    if (ipaddress.AddressFamily == AddressFamily.InterNetworkV6)
                    {
                        this.m_output.WriteErrorSimple(new DagTaskDagIpAddressesMustBeIpv4Exception());
                    }
                }
            }
            this.m_useAlternateWitnessServer = (this.m_dag.AlternateWitnessServer != null && DagTaskHelper.IsDagFailedOverToOtherSite(this.m_output, this.m_dag));
            if (!this.m_useAlternateWitnessServer)
            {
                this.m_fsw = new FileShareWitness((ITopologyConfigurationSession)base.DataSession, this.m_dag.Name, this.WitnessServer ?? this.m_dag.WitnessServer, this.WitnessDirectory ?? this.m_dag.WitnessDirectory);
                try
                {
                    this.m_fsw.Initialize();
                }
                catch (LocalizedException error)
                {
                    this.m_output.WriteErrorSimple(error);
                }
                this.CheckFsw(this.m_fsw.WitnessServerFqdn);
            }
            if (this.AlternateWitnessServer != null || this.AlternateWitnessDirectory != null || (this.m_dag.AlternateWitnessServer != null && this.m_dag.AlternateWitnessDirectory != null && !this.m_alternateWitnessServerParameterSpecified) || this.m_useAlternateWitnessServer)
            {
                this.m_afsw = new FileShareWitness((ITopologyConfigurationSession)base.DataSession, this.m_dag.Name, this.AlternateWitnessServer ?? this.m_dag.AlternateWitnessServer, this.AlternateWitnessDirectory ?? this.m_dag.AlternateWitnessDirectory);
                try
                {
                    this.m_afsw.Initialize();
                }
                catch (LocalizedException error2)
                {
                    this.m_output.WriteErrorSimple(error2);
                }
                if (this.m_fsw != null && SharedHelper.StringIEquals(this.m_afsw.WitnessServerFqdn, this.m_fsw.WitnessServerFqdn) && this.m_fsw.WitnessDirectory != this.m_afsw.WitnessDirectory)
                {
                    this.m_output.WriteErrorSimple(new DagFswAndAlternateFswOnSameWitnessServerButPointToDifferentDirectoriesException(this.m_fsw.WitnessServer.ToString(), this.m_fsw.WitnessDirectory.ToString(), this.m_afsw.WitnessDirectory.ToString()));
                }
                this.CheckFsw(this.m_afsw.WitnessServerFqdn);
            }
            Dictionary <AmServerName, Server> startedServers = new Dictionary <AmServerName, Server>();

            DatabaseAvailabilityGroupAction.ResolveServers(this.m_output, this.m_dag, this.m_allServers, startedServers, this.m_stoppedServers);
            if (!this.m_dag.IsDagEmpty())
            {
                this.PrepareServersInDagIfRequired();
                List <AmServerName>        list             = new List <AmServerName>(this.m_stoppedServers.Count);
                IEnumerable <AmServerName> serversInCluster = null;
                foreach (Server server in this.m_stoppedServers.Values)
                {
                    list.Add(new AmServerName(server.Id));
                }
                using (AmCluster amCluster = AmCluster.OpenDagClus(this.m_dag))
                {
                    serversInCluster = amCluster.EnumerateNodeNames();
                }
                if (!this.m_skipDagValidation)
                {
                    DagTaskHelper.CompareDagClusterMembership(this.m_output, this.m_dag.Name, this.m_serverNamesInDag, serversInCluster, list);
                }
            }
            if (base.Fields["DatacenterActivationMode"] != null && this.DatacenterActivationMode != DatacenterActivationModeOption.Off)
            {
                DagTaskHelper.CheckDagCanBeActivatedInDatacenter(this.m_output, this.m_dag, null, (ITopologyConfigurationSession)base.DataSession);
            }
            if (base.Fields["DatacenterActivationMode"] != null && this.DatacenterActivationMode == DatacenterActivationModeOption.Off)
            {
                this.DataObject.StartedMailboxServers = null;
                this.DataObject.StoppedMailboxServers = null;
            }
            TaskLogger.LogExit();
        }