internal static void ForceCleanupStoppedNodes(DatabaseAvailabilityGroup dag, IEnumerable <Server> shouldStopServers, TimeSpan maxTimeToWaitForOneNode, HaTaskOutputHelper output) { if (dag == null) { throw new ArgumentNullException("dag"); } if (shouldStopServers == null) { throw new ArgumentNullException("shouldStopServers"); } if (output == null) { throw new ArgumentNullException("output"); } string empty = string.Empty; List <string> list = new List <string>(1); int num = shouldStopServers.Count <Server>(); foreach (Server server in shouldStopServers) { new AmServerName(server); output.WriteProgressIncrementalSimple(Strings.ProgressEvictNode(server.Name), 20 / num); if (!DatabaseAvailabilityGroupAction.ForceCleanupOneNodeLocally(dag.Name, server, maxTimeToWaitForOneNode, output)) { list.Add(server.Name); } } if (list.Count != 0) { output.WriteErrorSimple(new StopDagFailedException(string.Join(",", list.ToArray <string>()), dag.Name)); } }
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)); } }