private void CheckClusterStateForDagServerRemoval() { this.m_output.AppendLogMessage("CheckClusterStateForDagServerRemoval entered. m_removeNode={0}, m_destroyCluster={1}", new object[] { this.m_removeNode, this.m_destroyCluster }); try { this.m_clusDag = AmCluster.OpenDagClus(this.m_dag); } catch (AmClusterException ex) { this.m_output.AppendLogMessage("Trying to open the cluster on the servers in the DAG '{0}' failed with exception {1}", new object[] { this.m_dagName, ex }); this.m_output.WriteErrorSimple(new DagTaskRemoveDagServerMustHaveQuorumException(this.m_dagName)); } using (DumpClusterTopology dumpClusterTopology = new DumpClusterTopology(this.m_clusDag, this.m_output)) { dumpClusterTopology.Dump(); } this.m_output.AppendLogMessage("Trying to open the node on the cluster.", new object[0]); IAmClusterNode amClusterNode = null; try { amClusterNode = this.m_clusDag.OpenNode(this.m_mailboxAmServerName); } catch (ClusterException ex2) { this.m_output.AppendLogMessage("OpenNode threw an exception. It's probably because the server is no longer clustered. Proceeding with -configurationonly.", new object[0]); this.m_output.AppendLogMessage("For the records, the exception was {0}.", new object[] { ex2 }); this.m_configurationOnly = true; this.m_mailboxServerIsDown = true; return; } using (amClusterNode) { AmNodeState state = amClusterNode.GetState(false); this.m_output.AppendLogMessage("Node.GetState( {0} ) reports that it is {1}.", new object[] { this.m_mailboxAmServerName, state }); if (!AmClusterNode.IsNodeUp(state)) { this.m_mailboxServerIsDown = true; } } if (!this.m_skipDagValidation) { try { DagTaskHelper.ValidateDagClusterMembership(this.m_output, this.m_dag, this.m_clusDag, this.m_mailboxAmServerName); } catch (ClusterException ex3) { this.DagTrace("ValidateDagClusterMembership() for the mailbox server failed possibly with error {0}, ex = {1}. This is OK.", new object[] { LocalizedException.GenerateErrorCode(ex3.InnerException).ToString(), ex3.Message }); } } int num = this.m_clusDag.EnumerateNodeNames().Count <AmServerName>(); this.DagTrace(string.Format("There are {0} nodes in the cluster.", num), new object[0]); if (num == 1) { this.m_destroyCluster = true; } else { this.m_removeNode = true; } bool destroyCluster = this.m_destroyCluster; this.ReopenClusterIfNecessary(); if ((this.m_removeNode || this.m_destroyCluster) && this.m_dag.DatacenterActivationMode != DatacenterActivationModeOption.Off) { DagTaskHelper.CheckDagCanBeActivatedInDatacenter(this.m_output, this.m_dag, (ADObjectId)this.m_mailboxServer.Identity, (ITopologyConfigurationSession)base.DataSession); } this.DagTrace("CheckClusterStateForDagServerRemoval left. m_removeNode={0}, m_destroyCluster={1}.", new object[] { this.m_removeNode, this.m_destroyCluster }); }
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(); }