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)); } }
private List <string> JoinStartedNodes(IEnumerable <Server> serversToStart) { if (serversToStart == null) { throw new ArgumentNullException("serversToStart"); } List <string> list = new List <string>(1); using (AmCluster amCluster = AmCluster.OpenDagClus(this.m_dag)) { using (IAmClusterGroup amClusterGroup = amCluster.FindCoreClusterGroup()) { try { using (DumpClusterTopology dumpClusterTopology = new DumpClusterTopology(amCluster, this.m_output)) { dumpClusterTopology.Dump(); } } catch (ClusterException ex) { this.m_output.AppendLogMessage("DumpClusterTopology( {0} ) failed with exception = {1}. This is OK.", new object[] { this.m_dag.Name, ex.Message }); this.m_output.AppendLogMessage("Ignoring previous error, as it is acceptable if the cluster does not exist yet.", new object[0]); } AmServerName ownerNode = amClusterGroup.OwnerNode; DatabaseTasksHelper.CheckReplayServiceRunningOnNode(ownerNode, new Task.TaskErrorLoggingDelegate(base.WriteError)); if (amCluster.CnoName != string.Empty) { using (IAmClusterResource amClusterResource = amClusterGroup.FindResourceByTypeName("Network Name")) { DagTaskHelper.LogCnoState(this.m_output, this.m_dag.Name, amClusterResource); } } foreach (Server server in serversToStart) { bool flag = false; AmServerName amServerName = new AmServerName(server); try { if (amCluster.IsEvictedBasedOnMemberShip(amServerName)) { this.m_output.WriteProgressSimple(Strings.ProgressJoinNode(amServerName.NetbiosName)); this.m_output.AppendLogMessage("ForceCleanup the Node {0}", new object[] { server.Name }); DatabaseAvailabilityGroupAction.ForceCleanupOneNodeLocally(this.m_dag.Name, server, TimeSpan.FromSeconds(15.0), this.m_output); this.m_output.AppendLogMessage("Join the node {0} to the cluster", new object[] { server.Name }); DatabaseAvailabilityGroupAction.JoinOneNode(ownerNode, amServerName, this.m_output); flag = true; } else { this.m_output.AppendLogMessage("{0} is not evicted", new object[] { amServerName }); } if (!AmCluster.IsRunning(amServerName)) { try { this.m_output.AppendLogMessage("{0} cluster service is not running, try to start the service", new object[] { server.Name }); this.m_output.WriteProgressSimple(Strings.ProgressStartClussvc(amServerName.NetbiosName)); DatabaseAvailabilityGroupAction.TryStartClussvcOnNode(amServerName, this.m_output); } catch (InvalidOperationException) { this.m_output.AppendLogMessage("Got an invalidOperationException, most likely the node {0} is force cleanedup", new object[] { amServerName }); if (flag) { this.m_output.AppendLogMessage("STRANGE! we joined {0} but cannot start the service!", new object[] { amServerName }); throw; } this.m_output.WriteProgressSimple(Strings.ProgressJoinNode(amServerName.NetbiosName)); DatabaseAvailabilityGroupAction.JoinForceCleanupNode(ownerNode, amServerName, this.m_output); flag = true; } } if (flag) { ICollection <AmServerName> startedMailboxServers = from server1 in this.m_dag.StartedMailboxServers select new AmServerName(server1); DatabaseAvailabilityGroupAction.FixIPAddress(new AmServerName(server.Fqdn), this.m_dag, startedMailboxServers, this.m_output); } } catch (LocalizedException ex2) { this.m_output.WriteWarning(Strings.FailedToJoinNode(server.Name, this.m_dag.Name, ex2.Message)); list.Add(server.Name); } catch (InvalidOperationException ex3) { this.m_output.WriteWarning(Strings.FailedToJoinNode(server.Name, this.m_dag.Name, ex3.Message)); list.Add(server.Name); } } } } return(list); }