Example #1
0
        internal static void JoinForceCleanupNode(AmServerName pamServer, AmServerName serverName, HaTaskOutputHelper output)
        {
            string verboseLog = null;

            output.AppendLogMessage("{0} is probably cleaned up, try to evict it and join it back", new object[]
            {
                serverName.NetbiosName
            });
            try
            {
                ReplayRpcClientWrapper.RunEvictNodeFromCluster(pamServer, serverName, out verboseLog);
                DagTaskHelper.LogRemoteVerboseLog(output, pamServer.Fqdn, verboseLog);
                output.AppendLogMessage("Sleep one minute before we issue add", new object[0]);
                Thread.Sleep(DatabaseAvailabilityGroupAction.WaitBetweenOps);
                output.AppendLogMessage("joining {0}", new object[]
                {
                    serverName.NetbiosName
                });
                ReplayRpcClientWrapper.RunAddNodeToCluster(pamServer, serverName, out verboseLog);
            }
            finally
            {
                DagTaskHelper.LogRemoteVerboseLog(output, pamServer.Fqdn, verboseLog);
            }
        }
Example #2
0
 private void RemoveNodeFromCluster()
 {
     this.m_output.WriteProgressSimple(Strings.DagTaskRemovedNodeToCluster(this.m_mailboxServerName));
     using (IAmClusterNode amClusterNode = this.m_clusDag.OpenNode(this.m_mailboxAmServerName))
     {
         bool   flag             = false;
         string empty            = string.Empty;
         string remoteServerName = "<unknown>";
         try
         {
             using (IAmClusterGroup amClusterGroup = this.m_clusDag.FindCoreClusterGroup())
             {
                 AmServerName ownerNode = amClusterGroup.OwnerNode;
                 remoteServerName = ownerNode.Fqdn;
                 ReplayRpcClientWrapper.RunEvictNodeFromCluster(ownerNode, this.m_mailboxAmServerName, out empty);
             }
         }
         catch (DagTaskOperationFailedException ex)
         {
             AmClusterEvictWithoutCleanupException ex2;
             if (ex.TryGetTypedInnerException(out ex2))
             {
                 this.m_output.WriteWarning(ex2.LocalizedString);
             }
             else
             {
                 DagTaskHelper.LogRemoteVerboseLog(this.m_output, remoteServerName, empty);
                 this.m_output.WriteErrorSimple(ex);
             }
         }
         catch (LocalizedException error)
         {
             DagTaskHelper.LogRemoteVerboseLog(this.m_output, remoteServerName, empty);
             this.m_output.WriteErrorSimple(error);
         }
         DagTaskHelper.LogRemoteVerboseLog(this.m_output, remoteServerName, empty);
         if (flag)
         {
             this.m_output.WriteWarning(Strings.DagTaskRemoveNodeCleanupFailed(amClusterNode.Name.Fqdn));
         }
     }
     this.m_output.WriteProgressSimple(Strings.DagTaskRemovedNodeToCluster(this.m_mailboxServerName));
     if (this.m_clusDag.CnoName != string.Empty)
     {
         this.m_output.WriteProgressSimple(Strings.DagTaskFixingUpIpResources);
         List <AmServerName>        source     = this.m_clusDag.EnumerateNodeNames().ToList <AmServerName>();
         IEnumerable <AmServerName> enumerable = from name in source
                                                 where name != this.m_mailboxAmServerName
                                                 select name;
         IEnumerable <string> source2 = from serverName in enumerable
                                        select serverName.NetbiosName;
         this.m_output.AppendLogMessage("Refreshing the cluster using the names [{0}].", new object[]
         {
             string.Join(", ", source2.ToArray <string>())
         });
         this.m_clusDag.Dispose();
         MultiValuedProperty <IPAddress> databaseAvailabilityGroupIpv4Addresses = this.m_dag.DatabaseAvailabilityGroupIpv4Addresses;
         IPAddress[] array = new IPAddress[0];
         if (databaseAvailabilityGroupIpv4Addresses.Count > 0)
         {
             array = databaseAvailabilityGroupIpv4Addresses.ToArray();
         }
         string[] value = (from addr in array
                           select addr.ToString()).ToArray <string>();
         this.m_output.AppendLogMessage("Got the following IP addresses for the DAG (blank means DHCP): {0}", new object[]
         {
             string.Join(",", value)
         });
         this.m_clusDag = AmCluster.OpenByNames(enumerable);
         using (IAmClusterGroup amClusterGroup2 = this.m_clusDag.FindCoreClusterGroup())
         {
             using (IAmClusterResource amClusterResource = amClusterGroup2.FindResourceByTypeName("Network Name"))
             {
                 this.m_output.AppendLogMessage("Cluster group net name = '{0}'.", new object[]
                 {
                     amClusterResource.Name
                 });
                 LocalizedString value2 = AmClusterResourceHelper.FixUpIpAddressesForNetName(this.m_output, this.m_clusDag, (AmClusterGroup)amClusterGroup2, (AmClusterResource)amClusterResource, array);
                 this.m_output.WriteProgressSimple(Strings.DagTaskFixedUpIpResources(value2));
             }
         }
     }
 }
Example #3
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));
            }
        }