internal static void FixIPAddress(AmServerName nodeName, DatabaseAvailabilityGroup dag, IEnumerable <AmServerName> startedMailboxServers, ITaskOutputHelper output) { output.WriteProgressSimple(Strings.DagTaskFixingUpIpResources); MultiValuedProperty <IPAddress> databaseAvailabilityGroupIpv4Addresses = 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>(); output.AppendLogMessage("Got the following IP addresses for the DAG (blank means DHCP):{0}", new object[] { string.Join(",", value) }); using (AmCluster amCluster = AmCluster.OpenByNames(startedMailboxServers)) { if (amCluster.CnoName != string.Empty) { using (IAmClusterGroup amClusterGroup = amCluster.FindCoreClusterGroup()) { using (IAmClusterResource amClusterResource = amClusterGroup.FindResourceByTypeName("Network Name")) { LocalizedString value2 = AmClusterResourceHelper.FixUpIpAddressesForNetName(output, amCluster, (AmClusterGroup)amClusterGroup, (AmClusterResource)amClusterResource, array); output.WriteProgressSimple(Strings.DagTaskFixedUpIpResources(value2)); DagTaskHelper.LogCnoState(output, dag.Name, amClusterResource); } } } } }
internal static bool IsClusterUp(DatabaseAvailabilityGroup dag, HaTaskOutputHelper output) { try { using (AmCluster amCluster = AmCluster.OpenDagClus(dag)) { using (IAmClusterGroup amClusterGroup = amCluster.FindCoreClusterGroup()) { IEnumerable <AmServerName> source = amCluster.EnumerateNodeNames(); output.AppendLogMessage("Cluster is up, there are {0} nodes in the cluster, group owner:{1}", new object[] { source.Count <AmServerName>(), amClusterGroup.OwnerNode.NetbiosName }); } } } catch (AmCoreGroupRegNotFound amCoreGroupRegNotFound) { output.AppendLogMessage("Cluster is down, got AmCoreGroupRegNotFound:{0} when trying to open the cluster", new object[] { amCoreGroupRegNotFound.ToString() }); return(false); } return(true); }
public static void MoveClusterGroupWithTimeout(AmServerName clusterNode, AmServerName destinationNode, TimeSpan timeout) { uint errorCode = 0U; bool flag = false; try { InvokeWithTimeout.Invoke(delegate() { using (IAmCluster amCluster = MockableCluster.Instance.OpenByName(clusterNode)) { using (IAmClusterGroup amClusterGroup = amCluster.FindCoreClusterGroup()) { if (!amClusterGroup.OwnerNode.Equals(destinationNode)) { amClusterGroup.MoveGroup(timeout, destinationNode); } } } }, timeout); } catch (TimeoutException) { errorCode = 258U; flag = true; } if (flag) { throw AmExceptionHelper.ConstructClusterApiException((int)errorCode, "MoveClusterGroup( dest={0}, timeout={1})", new object[] { destinationNode.NetbiosName, timeout }); } }
protected override void InternalValidate() { TaskLogger.LogEnter(); this.LogCommandLineParameters(); this.m_removeNode = false; this.m_destroyCluster = false; this.ResolveParameters(); DagTaskHelper.VerifyDagAndServersAreWithinScopes <DatabaseAvailabilityGroup>(this, this.m_dag, true); this.m_output.WriteProgress(Strings.ProgressStatusInProgress, Strings.DagTaskRemoveDagServerRunningChecks(this.m_mailboxServerName, this.m_dagName), 0); this.CheckDatabasesAreNotReplicated(); if (!this.m_configurationOnly) { DagTaskHelper.CheckServerDoesNotBelongToDifferentDag(new Task.TaskErrorLoggingDelegate(this.m_output.WriteError), base.DataSession, this.m_mailboxServer, this.m_dagName); this.CheckFswSettings(); this.CheckClusterStateForDagServerRemoval(); if (!this.m_configurationOnly) { using (IAmClusterGroup amClusterGroup = this.m_clusDag.FindCoreClusterGroup()) { AmServerName ownerNode = amClusterGroup.OwnerNode; this.m_output.AppendLogMessage("Checking if msexchangerepl is running on {0}.", new object[] { ownerNode.NetbiosName }); DatabaseTasksHelper.CheckReplayServiceRunningOnNode(ownerNode, new Task.TaskErrorLoggingDelegate(base.WriteError)); if (this.m_clusDag.CnoName != string.Empty) { using (IAmClusterResource amClusterResource = amClusterGroup.FindResourceByTypeName("Network Name")) { DagTaskHelper.LogCnoState(this.m_output, this.m_dagName, amClusterResource); } } } } } if (DagTaskHelper.FindServerAdObjectIdInDag(this.m_dag, this.m_mailboxAmServerName) == null) { StringBuilder stringBuilder = new StringBuilder(string.Format("{0}. srvToRemove={1} dagSvrs=(", this.m_dagName, this.m_mailboxAmServerName.NetbiosName)); bool flag = false; foreach (ADObjectId adobjectId in this.m_dag.Servers) { if (flag) { stringBuilder.Append(","); } else { flag = true; } stringBuilder.Append(adobjectId.Name); } stringBuilder.Append(")"); this.m_output.WriteErrorSimple(new DagTaskServerIsNotInDagException(this.m_mailboxServerName, stringBuilder.ToString())); } base.InternalValidate(); TaskLogger.LogExit(); }
protected override void RunCheck() { using (IAmClusterGroup amClusterGroup = base.Cluster.FindCoreClusterGroup()) { if (amClusterGroup.State != AmGroupState.Online) { base.Fail(Strings.QuorumGroupNotOnline(amClusterGroup.Name, amClusterGroup.OwnerNode.NetbiosName, base.Cluster.Name, QuorumGroupCheck.ReportResourcesNotOnline(amClusterGroup), Environment.NewLine)); } } }
public bool IsClusterGroup() { using (IAmClusterGroup amClusterGroup = this.OwningCluster.FindCoreClusterGroup()) { if (amClusterGroup != null && SharedHelper.StringIEquals(amClusterGroup.Name, this.Name)) { return(true); } } return(false); }
// Token: 0x060008AE RID: 2222 RVA: 0x00029798 File Offset: 0x00027998 internal static void RevertToMnsQuorum(ILogTraceHelper output, IAmCluster cluster) { using (IAmClusterGroup amClusterGroup = cluster.FindCoreClusterGroup()) { string text; uint maxLogSize; string quorumResourceInformation = cluster.GetQuorumResourceInformation(out text, out maxLogSize); if (string.IsNullOrEmpty(quorumResourceInformation)) { output.AppendLogMessage("RevertToMnsQuorum: It's already using MNS!", new object[0]); using (IAmClusterResource amClusterResource = amClusterGroup.FindResourceByTypeName("File Share Witness")) { if (amClusterResource != null) { output.AppendLogMessage("Even though the quorum is set to MNS, there is a FSW resource present named '{0}', which will be deleted shortly.", new object[] { amClusterResource.Name }); amClusterResource.DeleteResource(); output.AppendLogMessage("The resource has been deleted!", new object[0]); } goto IL_13D; } } using (AmClusterResource amClusterResource2 = cluster.OpenResource(quorumResourceInformation)) { output.AppendLogMessage("Setting cluster quorum to MNS", new object[0]); if (cluster.CnoName == string.Empty) { cluster.ClearQuorumResource(); } else { using (IAmClusterResource amClusterResource3 = amClusterGroup.FindResourceByTypeName("Network Name")) { output.AppendLogMessage("Setting cluster quorum resource to the netname resource (i.e. MNS quorum).", new object[0]); cluster.SetQuorumResource(amClusterResource3, null, maxLogSize); if (amClusterResource2 != null && amClusterResource2.GetTypeName() == "File Share Witness") { output.AppendLogMessage("Offlining and deleting the old FSW resource '{0}'.", new object[] { quorumResourceInformation }); amClusterResource2.OfflineResource(); amClusterResource2.DeleteResource(); } } } } IL_13D :; } }
// Token: 0x060008B4 RID: 2228 RVA: 0x00029BAC File Offset: 0x00027DAC internal static void FollowBestPractices(ITaskOutputHelper output, IAmCluster cluster) { if (string.Empty != cluster.CnoName) { using (IAmClusterGroup amClusterGroup = cluster.FindCoreClusterGroup()) { using (IAmClusterResource amClusterResource = amClusterGroup.FindResourceByTypeName("Network Name")) { output.AppendLogMessage("Setting the DNS TTL to 300", new object[0]); amClusterResource.SetPrivateProperty <int>("HostRecordTTL", 300); } } } }
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; } } }
public static bool MovePrimaryActiveManagerRole(string CurrentPrimaryName) { AmServerName serverName = new AmServerName(CurrentPrimaryName); bool result; using (IAmCluster amCluster = ClusterFactory.Instance.OpenByName(serverName)) { using (IAmClusterGroup amClusterGroup = amCluster.FindCoreClusterGroup()) { string text; result = amClusterGroup.MoveGroupToReplayEnabledNode((string targetNode) => AmHelper.IsReplayRunning(targetNode), "Network Name", new TimeSpan(0, 3, 0), out text); } } return(result); }
public static string ReportResourcesNotOnline(IAmClusterGroup resGroup) { if (resGroup == null) { throw new ArgumentNullException("resGroup cannot be null!"); } StringBuilder stringBuilder = new StringBuilder(); foreach (AmClusterResource amClusterResource in resGroup.EnumerateResources()) { using (amClusterResource) { AmResourceState state = amClusterResource.GetState(); if (state != AmResourceState.Online) { stringBuilder.AppendFormat("\t\t{0}: {1}{2}", amClusterResource.Name, state.ToString(), Environment.NewLine); } } } return(stringBuilder.ToString()); }
// Token: 0x060008AD RID: 2221 RVA: 0x000296B0 File Offset: 0x000278B0 private static void SetFswSharePath(ITaskOutputHelper output, IAmCluster cluster, IAmClusterResource fsw, string fswShare) { try { fsw.OfflineResource(); fsw.SetPrivateProperty <string>("SharePath", fswShare); fsw.OnlineResource(); } catch (ClusterException ex) { Win32Exception ex2 = null; if (ex.TryGetTypedInnerException(out ex2)) { output.AppendLogMessage("SetFswSharePath() caught an AmClusterApiException with errorcode={0} and NativeErrorCode={1}. ex = {2}", new object[] { ex2.ErrorCode, ex2.NativeErrorCode, ex2 }); if (ex2.NativeErrorCode == 5) { string text = cluster.CnoName; if (text == string.Empty) { using (IAmClusterGroup amClusterGroup = cluster.FindCoreClusterGroup()) { if (amClusterGroup != null && amClusterGroup.OwnerNode != null) { text = amClusterGroup.OwnerNode.NetbiosName; } } } output.WriteErrorSimple(new DagTaskFswNeedsCnoPermissionException(fswShare, text)); } } throw; } }
private void MovePamIfNeeded() { try { using (IAmClusterGroup amClusterGroup = this.m_clusDag.FindCoreClusterGroup()) { AmServerName ownerNode = amClusterGroup.OwnerNode; this.m_output.AppendLogMessage("The core cluster group '{0}' is currently on machine '{1}'.", new object[] { amClusterGroup.Name, ownerNode.NetbiosName }); if (ownerNode.Equals(this.m_mailboxAmServerName)) { this.m_output.WriteProgressSimple(ReplayStrings.DagTaskMovingPam(this.m_mailboxServerName)); string resourceType = (this.m_clusDag.CnoName == string.Empty) ? string.Empty : "Network Name"; string newPam; if (!amClusterGroup.MoveGroupToReplayEnabledNode((string targetNode) => AmHelper.IsReplayRunning(targetNode), resourceType, TimeSpan.FromMinutes(3.0), out newPam)) { this.m_output.WriteWarning(ReplayStrings.DagTaskPamNotMovedSubsequentOperationsMayBeSlowOrUnreliable); } else { this.m_output.WriteProgressSimple(ReplayStrings.DagTaskMovedPam(newPam)); } } } } catch (LocalizedException ex) { this.m_output.AppendLogMessage("MoveGroupToReplayEnabledNode encountered the following exception: {0}", new object[] { ex }); this.m_output.WriteWarning(ReplayStrings.DagTaskPamNotMovedSubsequentOperationsMayBeSlowOrUnreliable); } }
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)); } }
// Token: 0x060008AC RID: 2220 RVA: 0x00029304 File Offset: 0x00027504 internal static void CreateFileShareWitnessQuorum(ITaskOutputHelper output, IAmCluster cluster, string fswShare) { output = (output ?? NullTaskOutputHelper.GetNullLogger()); IAmClusterGroup amClusterGroup = cluster.FindCoreClusterGroup(); if (amClusterGroup == null) { Thread.Sleep(10000); amClusterGroup = cluster.FindCoreClusterGroup(); if (amClusterGroup == null) { throw new FailedToGetClusterCoreGroupException(); } } using (amClusterGroup) { IEnumerable <AmClusterResource> source = amClusterGroup.EnumerateResourcesOfType("File Share Witness"); IAmClusterResource amClusterResource = source.ElementAtOrDefault(0); try { bool flag = false; if (amClusterResource == null) { output.AppendLogMessage("CreateFileShareWitnessQuorum: Could not find an existing FSW resource. A new one will be created.", new object[0]); flag = true; } else if (amClusterResource.GetState() == AmResourceState.Failed) { output.AppendLogMessage("CreateFileShareWitnessQuorum: The existing FSW resource is in a Failed state. It should be deleted and recreated.", new object[0]); flag = true; } else { string privateProperty = amClusterResource.GetPrivateProperty <string>("SharePath"); if (!SharedHelper.StringIEquals(privateProperty, fswShare)) { output.AppendLogMessage("CreateFileShareWitnessQuorum: There is already a FSW, but the current share path ({0}) is not what's desired ({1}). Will try to fix it.", new object[] { privateProperty, fswShare }); List <string> list = new List <string>(4); foreach (IAmClusterNode amClusterNode in cluster.EnumerateNodes()) { using (amClusterNode) { if (!AmClusterNode.IsNodeUp(amClusterNode.State)) { list.Add(amClusterNode.Name.NetbiosName); } } } if (list.Count > 0) { output.WriteErrorSimple(new DagTaskSetDagNeedsAllNodesUpToChangeQuorumException(string.Join(",", list.ToArray()))); } DagHelper.SetFswSharePath(output, cluster, amClusterResource, fswShare); } } AmResourceState state; if (!flag && amClusterResource != null) { try { state = amClusterResource.GetState(); if (state != AmResourceState.Online) { output.AppendLogMessage("The FSW is not online (it is {0}). Attempting to bring online.", new object[] { state }); amClusterResource.OnlineResource(); } state = amClusterResource.GetState(); output.AppendLogMessage("The fsw resource is now in state {0}.", new object[] { state }); if (state != AmResourceState.Online) { flag = true; } } catch (ClusterException ex) { output.AppendLogMessage("Bringing the FSW resource online failed, so it will be deleted and recreated. For the record, the error was {0}", new object[] { ex }); flag = true; } } if (flag) { if (amClusterResource != null) { amClusterResource.Dispose(); amClusterResource = null; } output.AppendLogMessage("CreateFileShareWitnessQuorum: Calling RevertToMnsQuorum to clean everything up first.", new object[0]); DagHelper.RevertToMnsQuorum(output, cluster); string text = string.Format("File Share Witness ({0})", fswShare); output.AppendLogMessage("Creating a new file share witness resource named '{0}'.", new object[] { text }); amClusterResource = amClusterGroup.CreateResource(text, "File Share Witness"); DagHelper.SetFswSharePath(output, cluster, amClusterResource, fswShare); } output.AppendLogMessage("The FSW resource is now in state {0}.", new object[] { amClusterResource.GetState() }); string text2; uint maxLogSize; string quorumResourceInformation = cluster.GetQuorumResourceInformation(out text2, out maxLogSize); output.AppendLogMessage("The current quorum resource is '{0}'. About to set it to the FSW.", new object[] { quorumResourceInformation }); state = amClusterResource.GetState(); if (state != AmResourceState.Online) { output.WriteErrorSimple(new DagTaskFileShareWitnessResourceIsStillNotOnlineException(fswShare, state.ToString())); } cluster.SetQuorumResource(amClusterResource, null, maxLogSize); quorumResourceInformation = cluster.GetQuorumResourceInformation(out text2, out maxLogSize); output.AppendLogMessage("The quorum resource is now '{0}'.", new object[] { quorumResourceInformation }); output.AppendLogMessage("Bringing the quorum resource online...", new object[0]); amClusterResource.OnlineResource(); } finally { if (amClusterResource != null) { amClusterResource.Dispose(); amClusterResource = null; } } } }
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)); } } } }
protected override void InternalProcessRecord() { TaskLogger.LogEnter(); bool flag = false; if ((base.Fields["ReplicationPort"] != null || base.Fields["NetworkCompression"] != null || base.Fields["NetworkEncryption"] != null || base.Fields["ManualDagNetworkConfiguration"] != null || base.Fields["DiscoverNetworks"] != null) && !this.m_dag.IsDagEmpty()) { flag = true; this.m_IsObjectChanged = true; } if (this.DataObject.AllowCrossSiteRpcClientAccess != this.AllowCrossSiteRpcClientAccess) { if (base.Fields["AllowCrossSiteRpcClientAccess"] != null) { this.DataObject.AllowCrossSiteRpcClientAccess = this.AllowCrossSiteRpcClientAccess; this.m_IsObjectChanged = true; } else { this.AllowCrossSiteRpcClientAccess = this.DataObject.AllowCrossSiteRpcClientAccess; } } if (this.m_fsw != null) { this.m_dag.SetWitnessServer(this.m_fsw.FileShareWitnessShare, this.m_fsw.WitnessDirectory); this.m_IsObjectChanged = true; } if (this.m_afsw != null) { this.m_dag.SetAlternateWitnessServer(this.m_afsw.FileShareWitnessShare, this.m_afsw.WitnessDirectory); this.m_IsObjectChanged = true; } else if (this.AlternateWitnessServer == null && this.m_alternateWitnessServerParameterSpecified) { this.m_dag.SetAlternateWitnessServer(null, null); } base.InternalProcessRecord(); if (flag && !this.m_dag.IsDagEmpty()) { SetDagNetworkConfigRequest setDagNetworkConfigRequest = new SetDagNetworkConfigRequest(); if (base.Fields["ReplicationPort"] != null) { setDagNetworkConfigRequest.ReplicationPort = this.ReplicationPort; } setDagNetworkConfigRequest.NetworkCompression = this.m_dag.NetworkCompression; setDagNetworkConfigRequest.NetworkEncryption = this.m_dag.NetworkEncryption; setDagNetworkConfigRequest.ManualDagNetworkConfiguration = this.m_dag.ManualDagNetworkConfiguration; if (base.Fields["DiscoverNetworks"] != null) { setDagNetworkConfigRequest.DiscoverNetworks = true; } DagNetworkRpc.SetDagNetworkConfig(this.m_dag, setDagNetworkConfigRequest); } if (!this.m_dag.IsDagEmpty()) { using (AmCluster amCluster = AmCluster.OpenDagClus(this.m_dag)) { if (amCluster.CnoName != string.Empty) { using (IAmClusterGroup amClusterGroup = amCluster.FindCoreClusterGroup()) { using (IAmClusterResource amClusterResource = amClusterGroup.FindResourceByTypeName("Network Name")) { IPAddress[] dagIpAddressesFromAd = this.GetDagIpAddressesFromAd(this.m_output, this.m_dag); AmClusterResourceHelper.FixUpIpAddressesForNetName(this.m_output, amCluster, (AmClusterGroup)amClusterGroup, (AmClusterResource)amClusterResource, dagIpAddressesFromAd); DagTaskHelper.LogCnoState(this.m_output, this.m_dag.Name, amClusterResource); } } } } this.UpdateFileShareWitness(); DagTaskHelper.NotifyServersOfConfigChange(this.m_allServers.Keys); } TaskLogger.LogExit(); }
protected override void WriteResult(IConfigurable dataObject) { TaskLogger.LogEnter(new object[] { dataObject.Identity, dataObject }); DatabaseAvailabilityGroup databaseAvailabilityGroup = (DatabaseAvailabilityGroup)dataObject; if (this.Status && !databaseAvailabilityGroup.IsDagEmpty()) { List <ADObjectId> list = new List <ADObjectId>(8); List <ADObjectId> list2 = new List <ADObjectId>(8); AmCluster amCluster = null; try { amCluster = AmCluster.OpenDagClus(databaseAvailabilityGroup); } catch (ClusterException exception) { base.WriteError(exception, ErrorCategory.InvalidArgument, null); } if (amCluster != null) { using (amCluster) { foreach (IAmClusterNode amClusterNode in amCluster.EnumerateNodes()) { using (amClusterNode) { AmNodeState state = amClusterNode.GetState(false); if (AmClusterNode.IsNodeUp(state)) { ADObjectId adobjectId = DagTaskHelper.FindServerAdObjectIdInDag(databaseAvailabilityGroup, amClusterNode.Name); if (adobjectId != null) { list.Add(adobjectId); if (state == AmNodeState.Paused) { list2.Add(adobjectId); } } else { this.WriteWarning(Strings.WarningClusterNodeNotFoundInDag(amClusterNode.Name.Fqdn, databaseAvailabilityGroup.Name)); } } } } databaseAvailabilityGroup.OperationalServers = list.ToArray(); databaseAvailabilityGroup.ServersInMaintenance = list2.ToArray(); DagNetworkConfiguration dagNetworkConfig = DagNetworkRpc.GetDagNetworkConfig(databaseAvailabilityGroup); databaseAvailabilityGroup.ReplicationPort = dagNetworkConfig.ReplicationPort; foreach (DatabaseAvailabilityGroupNetwork databaseAvailabilityGroupNetwork in dagNetworkConfig.Networks) { databaseAvailabilityGroup.NetworkNames.Add(databaseAvailabilityGroupNetwork.Name); } if (DagHelper.IsQuorumTypeFileShareWitness(amCluster)) { IAmClusterGroup amClusterGroup = amCluster.FindCoreClusterGroup(); if (amClusterGroup == null) { databaseAvailabilityGroup.WitnessShareInUse = new WitnessShareUsage?(WitnessShareUsage.InvalidConfiguration); this.WriteWarning(Strings.WarningClusterGroupNotFormed(databaseAvailabilityGroup.Name)); goto IL_306; } using (amClusterGroup) { IEnumerable <AmClusterResource> enumerable = null; try { enumerable = amClusterGroup.EnumerateResourcesOfType("File Share Witness"); AmClusterResource amClusterResource = enumerable.ElementAtOrDefault(0); if (amClusterResource == null) { databaseAvailabilityGroup.WitnessShareInUse = new WitnessShareUsage?(WitnessShareUsage.InvalidConfiguration); this.WriteWarning(Strings.WarningFswNotFound(databaseAvailabilityGroup.Name)); } else if (amClusterResource.GetState() == AmResourceState.Failed) { databaseAvailabilityGroup.WitnessShareInUse = new WitnessShareUsage?(WitnessShareUsage.InvalidConfiguration); this.WriteWarning(Strings.WarningFswFailed(databaseAvailabilityGroup.Name)); } else { string privateProperty = amClusterResource.GetPrivateProperty <string>("SharePath"); UncFileSharePath a; if (UncFileSharePath.TryParse(privateProperty, out a)) { if (a == databaseAvailabilityGroup.FileShareWitness) { databaseAvailabilityGroup.WitnessShareInUse = new WitnessShareUsage?(WitnessShareUsage.Primary); } else if (a == databaseAvailabilityGroup.AlternateFileShareWitness) { databaseAvailabilityGroup.WitnessShareInUse = new WitnessShareUsage?(WitnessShareUsage.Alternate); } else { databaseAvailabilityGroup.WitnessShareInUse = new WitnessShareUsage?(WitnessShareUsage.InvalidConfiguration); this.WriteWarning(Strings.WarningFswNotPrimaryOrAlternate(databaseAvailabilityGroup.Name)); } } else { databaseAvailabilityGroup.WitnessShareInUse = new WitnessShareUsage?(WitnessShareUsage.InvalidConfiguration); this.WriteWarning(Strings.WarningFswNotValidPath(databaseAvailabilityGroup.Name, privateProperty)); } } } finally { if (enumerable != null) { foreach (AmClusterResource amClusterResource2 in enumerable) { using (amClusterResource2) { } } } } goto IL_306; } } databaseAvailabilityGroup.WitnessShareInUse = new WitnessShareUsage?(WitnessShareUsage.None); IL_306:; } this.UpdatePam(databaseAvailabilityGroup); try { DeferredFailoverEntry[] serversInDeferredRecovery = DagTaskHelper.GetServersInDeferredRecovery(databaseAvailabilityGroup); databaseAvailabilityGroup.ServersInDeferredRecovery = serversInDeferredRecovery; } catch (AmServerException ex) { this.WriteWarning(Strings.PAMOtherError(ex.Message)); } } } base.WriteResult(databaseAvailabilityGroup); TaskLogger.LogExit(); }
// Token: 0x060001A2 RID: 418 RVA: 0x0000A078 File Offset: 0x00008278 internal static bool AttemptServerSwitchoverOnShutdown() { AmTrace.Entering("ActiveManagerCore.AttemptServerSwitchoverOnShutdown", new object[0]); ExDateTime utcNow = ExDateTime.UtcNow; ReplayEventLogConstants.Tuple_PreShutdownStart.LogEvent(null, new object[0]); Exception ex = null; bool result = false; try { AmConfig config = AmSystemManager.Instance.Config; if (config.IsPamOrSam) { string fqdn = config.DagConfig.CurrentPAM.Fqdn; AmTrace.Debug("{0} Trying to mount all the databases on other servers", new object[] { ExDateTime.Now }); AmRpcClientHelper.ServerSwitchOver(fqdn, AmServerName.LocalComputerName.Fqdn); if (config.IsPAM) { AmTrace.Debug("{0} Trying to move PAM off this node", new object[] { ExDateTime.Now }); using (IAmCluster amCluster = ClusterFactory.Instance.Open()) { using (IAmClusterGroup amClusterGroup = amCluster.FindCoreClusterGroup()) { TimeSpan ts = ExDateTime.UtcNow.Subtract(utcNow); TimeSpan timeSpan = TimeSpan.FromSeconds(115.0).Subtract(ts); if (!(timeSpan <= TimeSpan.Zero)) { if (amClusterGroup.MoveGroupToReplayEnabledNode((string targetNode) => AmHelper.IsReplayRunning(targetNode), "Network Name", timeSpan, out fqdn)) { ReplayEventLogConstants.Tuple_SuccMovePAM.LogEvent(null, new object[] { Environment.MachineName, fqdn }); AmTrace.Debug("{0} Moved PAM to another node", new object[] { ExDateTime.Now }); goto IL_197; } } ReplayEventLogConstants.Tuple_FailedMovePAM.LogEvent(null, new object[] { Environment.MachineName }); IL_197 :; } } } result = true; ReplayEventLogConstants.Tuple_PreShutdownOK.LogEvent(null, new object[0]); } } catch (ClusterException ex2) { ex = ex2; } catch (AmRpcException ex3) { ex = ex3; } catch (AmServerTransientException ex4) { ex = ex4; } catch (AmServerException ex5) { ex = ex5; } finally { if (ex != null) { ReplayEventLogConstants.Tuple_PreShutdownFailed.LogEvent(null, new object[] { ex.Message }); } AmTrace.Leaving("ActiveManagerCore.AttemptServerSwitchoverOnShutdown", new object[0]); } return(result); }
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); }