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

            try
            {
                output.AppendLogMessage("joining {0}", new object[]
                {
                    serverName.NetbiosName
                });
                ReplayRpcClientWrapper.RunAddNodeToCluster(pamServer, serverName, out verboseLog);
            }
            catch (DagTaskServerException ex)
            {
                Exception ex2;
                if (!ex.TryGetInnerExceptionOfType(out ex2) && !ex.TryGetInnerExceptionOfType(out ex2))
                {
                    throw;
                }
                DagTaskHelper.LogRemoteVerboseLog(output, pamServer.Fqdn, verboseLog);
                output.AppendLogMessage("{0} is probably just starting up, retry add after 1 minute", new object[]
                {
                    serverName.NetbiosName
                });
                Thread.Sleep(DatabaseAvailabilityGroupAction.WaitBetweenOps);
                ReplayRpcClientWrapper.RunAddNodeToCluster(pamServer, serverName, out verboseLog);
            }
            finally
            {
                DagTaskHelper.LogRemoteVerboseLog(output, pamServer.Fqdn, verboseLog);
            }
        }
Example #2
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 #3
0
        internal static bool ForceCleanupOneNodeLocally(string dagName, Server nodeToForceCleanup, TimeSpan maxTimeToWait, HaTaskOutputHelper output)
        {
            if (dagName == null)
            {
                throw new ArgumentNullException("dagName");
            }
            if (nodeToForceCleanup == null)
            {
                throw new ArgumentNullException("nodeToForceCleanup");
            }
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            bool         result     = false;
            string       verboseLog = string.Empty;
            AmServerName serverName = new AmServerName(nodeToForceCleanup);

            output.AppendLogMessage("Attempting to run cluster node <LocalNodeName> /forcecleanup on {0}...", new object[]
            {
                serverName.NetbiosName
            });
            string error = null;

            System.Threading.Tasks.Task task = System.Threading.Tasks.Task.Factory.StartNew(delegate()
            {
                try
                {
                    ReplayRpcClientWrapper.RunForceCleanupNode(serverName, out verboseLog);
                }
                catch (LocalizedException ex)
                {
                    error = ex.Message;
                }
            });
            if (!task.Wait(maxTimeToWait))
            {
                error = string.Format("The operation didn't complete in {0} seconds", maxTimeToWait.TotalSeconds);
                output.WriteWarning(Strings.FailedToForceCleanupNode(nodeToForceCleanup.Name, dagName, error));
            }
            else
            {
                DagTaskHelper.LogRemoteVerboseLog(output, serverName.Fqdn, verboseLog);
                if (!string.IsNullOrEmpty(error))
                {
                    output.WriteWarning(Strings.FailedToForceCleanupNode(nodeToForceCleanup.Name, dagName, error));
                }
                else
                {
                    result = true;
                }
            }
            return(result);
        }
Example #4
0
        private void DestroyCluster()
        {
            bool   flag        = false;
            string verboseData = null;
            string serverName  = "<unknown>";

            try
            {
                this.m_output.WriteProgressSimple(Strings.RemoveDagDestroyingCluster(this.m_dagName, this.m_mailboxServerName, this.m_dagName));
                try
                {
                    using (IAmClusterGroup amClusterGroup = this.m_clusDag.FindCoreClusterGroup())
                    {
                        AmServerName ownerNode = amClusterGroup.OwnerNode;
                        serverName = ownerNode.Fqdn;
                        ReplayRpcClientWrapper.RunDestroyCluster(ownerNode, this.m_dagName, out verboseData);
                    }
                }
                catch (LocalizedException error)
                {
                    this.m_output.AppendLogMessage(ReplayStrings.DagTaskRemoteOperationLogBegin(serverName));
                    this.m_output.AppendLogMessage(ReplayStrings.DagTaskRemoteOperationLogData(verboseData));
                    this.m_output.WriteErrorSimple(error);
                }
                this.m_output.AppendLogMessage(ReplayStrings.DagTaskRemoteOperationLogBegin(serverName));
                this.m_output.AppendLogMessage(ReplayStrings.DagTaskRemoteOperationLogData(verboseData));
                this.m_output.AppendLogMessage(ReplayStrings.DagTaskRemoteOperationLogEnd(serverName));
                flag = true;
                this.m_output.WriteProgressSimple(Strings.RemoveDagDestroyedCluster(this.m_dagName, this.m_mailboxServerName, this.m_dagName));
            }
            catch (ClusCommonTransientException ex)
            {
                uint           status = 0U;
                Win32Exception ex2    = ex.InnerException as Win32Exception;
                if (ex2 != null)
                {
                    status = (uint)ex2.NativeErrorCode;
                }
                this.m_output.WriteErrorSimple(new RemoveDagFailedToDestroyClusterException(this.m_dagName, this.m_dagName, status));
            }
            finally
            {
                if (flag)
                {
                    this.m_clusDag.Dispose();
                    this.m_clusDag = null;
                }
            }
        }
        protected override void RpcOperation()
        {
            Database database = this.DataObject.GetDatabase <Database>();

            if (base.IsActivationRpcSupported)
            {
                DatabaseCopyActionFlags flags = DatabaseCopyActionFlags.Replication | DatabaseCopyActionFlags.Activation;
                if (this.ReplicationOnly)
                {
                    flags = DatabaseCopyActionFlags.Replication;
                }
                ReplayRpcClientHelper.RequestResume2(base.GetServerFqdn(), database.Guid, (uint)flags);
                return;
            }
            ReplayRpcClientWrapper.RequestResume(base.GetServerFqdn(), database.Guid);
        }
        internal void SuspendDatabaseCopyIfNecessary(ReplayConfiguration config)
        {
            string text = string.Empty;

            text = config.TargetMachine;
            if (!this.m_fConfigOnly && !WmiWrapper.IsFileExisting(text, config.DestinationEdbPath))
            {
                string fileName = string.Empty;
                fileName = Path.Combine(config.DestinationLogPath, EseHelper.MakeLogfileName(config.LogFilePrefix, "." + config.LogExtension, 1L));
                if (!WmiWrapper.IsFileExisting(SharedHelper.GetFqdnNameFromNode(config.SourceMachine), fileName))
                {
                    try
                    {
                        this.WriteWarning(Strings.EnableDBCSuspendReplayNoDbComment(config.Name));
                        ReplayRpcClientWrapper.RequestSuspend(text, config.IdentityGuid, Strings.EnableDBCSuspendReplayNoDbComment(config.Name));
                        ReplayEventLogConstants.Tuple_DbSeedingRequired.LogEvent(null, new object[]
                        {
                            config.Name,
                            text
                        });
                    }
                    catch (TaskServerTransientException ex)
                    {
                        ExTraceGlobals.CmdletsTracer.TraceDebug <TaskServerTransientException>((long)this.GetHashCode(), "SeedDatabase: Caught exception in RPC: {0}", ex);
                        base.WriteError(new InvalidOperationException(Strings.SgcFailedToSuspendRpc(config.Name, ex.Message)), ErrorCategory.InvalidOperation, this.Identity);
                    }
                    catch (TaskServerException ex2)
                    {
                        ExTraceGlobals.CmdletsTracer.TraceDebug <TaskServerException>((long)this.GetHashCode(), "SeedDatabase: Caught exception in RPC: {0}", ex2);
                        if (!(ex2 is ReplayServiceSuspendWantedSetException))
                        {
                            if (ex2 is ReplayServiceSuspendRpcPartialSuccessCatalogFailedException)
                            {
                                base.WriteWarning(ex2.Message);
                            }
                            else
                            {
                                base.WriteError(new InvalidOperationException(Strings.SgcFailedToSuspendRpc(config.Name, ex2.Message)), ErrorCategory.InvalidOperation, this.Identity);
                            }
                        }
                    }
                }
            }
        }
Example #7
0
        protected override void RpcOperation()
        {
            Database database = this.DataObject.GetDatabase <Database>();

            if (!base.IsActivationRpcSupported)
            {
                ReplayRpcClientWrapper.RequestSuspend(base.GetServerFqdn(), database.Guid, this.SuspendComment);
                return;
            }
            DatabaseCopyActionFlags flags = DatabaseCopyActionFlags.Replication | DatabaseCopyActionFlags.Activation;

            if (this.ActivationOnly)
            {
                flags = DatabaseCopyActionFlags.Activation;
            }
            if (base.IsRequestSuspend3RpcSupported)
            {
                ReplayRpcClientHelper.RequestSuspend3(base.GetServerFqdn(), database.Guid, this.SuspendComment, (uint)flags, 2U);
                return;
            }
            ReplayRpcClientWrapper.RequestSuspend2(base.GetServerFqdn(), database.Guid, this.SuspendComment, (uint)flags);
        }
Example #8
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 #9
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));
            }
        }