protected virtual Dictionary <AmServerName, AmNodeState> GetAllClusterNodeStates(ITaskOutputHelper output) { Dictionary <AmServerName, AmNodeState> dictionary = new Dictionary <AmServerName, AmNodeState>(15); try { using (IAmCluster amCluster = ClusterFactory.Instance.Open()) { foreach (IAmClusterNode amClusterNode in amCluster.EnumerateNodes()) { using (amClusterNode) { AmNodeState state = amClusterNode.GetState(false); dictionary[amClusterNode.Name] = state; } } } } catch (ClusterException ex) { output.AppendLogMessage("GetAllClusterNodeStates() failed with error {0}", new object[] { ex.Message }); } return(dictionary); }
public void LoadClusterObjects(IAmCluster cluster) { IEnumerable <IAmClusterNode> enumerable = cluster.EnumerateNodes(); try { foreach (IAmClusterNode clusNode in enumerable) { ClusterNode item = new ClusterNode(clusNode); this.m_clusterNodes.Add(item); } } finally { foreach (IAmClusterNode amClusterNode in enumerable) { using (amClusterNode) { } } } IEnumerable <AmClusterNetwork> enumerable2 = cluster.EnumerateNetworks(); try { foreach (AmClusterNetwork clusNet in enumerable2) { ClusterNetwork item2 = new ClusterNetwork(clusNet); this.m_clusterNets.Add(item2); } } finally { foreach (AmClusterNetwork amClusterNetwork in enumerable2) { using (amClusterNetwork) { } } } int testWithFakeNetwork = RegistryParameters.GetTestWithFakeNetwork(); if (testWithFakeNetwork > 0) { this.AddFakeNetworkForTesting(testWithFakeNetwork); } this.LinkNicsToNodes(); }
// Token: 0x060008B2 RID: 2226 RVA: 0x00029A88 File Offset: 0x00027C88 public static IEnumerable <AmServerName> EnumeratePausedNodes(IAmCluster cluster) { IList <AmServerName> list = new List <AmServerName>(8); foreach (IAmClusterNode amClusterNode in cluster.EnumerateNodes()) { using (amClusterNode) { if (amClusterNode.State == AmNodeState.Paused) { list.Add(amClusterNode.Name); } } } return(list); }
// 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; } } } }
public void RefreshMapiNetwork() { Exception ex = null; try { Dictionary <AmServerName, AmNetworkMonitor.Node> dictionary = new Dictionary <AmServerName, AmNetworkMonitor.Node>(); Dictionary <string, AmNetworkMonitor.Nic> dictionary2 = new Dictionary <string, AmNetworkMonitor.Nic>(); using (IAmCluster amCluster = ClusterFactory.Instance.Open()) { lock (this) { ExTraceGlobals.AmNetworkMonitorTracer.TraceDebug((long)this.GetHashCode(), "RefreshMapiNetwork running"); foreach (IAmClusterNode amClusterNode in amCluster.EnumerateNodes()) { using (amClusterNode) { AmNetworkMonitor.Node node = new AmNetworkMonitor.Node(amClusterNode.Name); dictionary.Add(node.Name, node); IPAddress[] dnsAddresses = NetworkUtil.GetDnsAddresses(amClusterNode.Name.Fqdn, ref ex); foreach (AmClusterNetInterface amClusterNetInterface in amClusterNode.EnumerateNetInterfaces()) { using (amClusterNetInterface) { bool flag2 = false; IPAddress ipaddress = NetworkUtil.ConvertStringToIpAddress(amClusterNetInterface.GetAddress()); if (ipaddress != null && NetworkUtil.IsAddressPresent(dnsAddresses, ipaddress)) { flag2 = true; AmNetworkMonitor.Tracer.TraceDebug <string, IPAddress>((long)this.GetHashCode(), "NIC '{0}' on DNS at {1}", amClusterNetInterface.Name, ipaddress); } if (!flag2) { string[] ipv6Addresses = amClusterNetInterface.GetIPv6Addresses(); if (ipv6Addresses != null && ipv6Addresses.Length > 0) { foreach (string text in ipv6Addresses) { ipaddress = NetworkUtil.ConvertStringToIpAddress(text); if (ipaddress != null && NetworkUtil.IsAddressPresent(dnsAddresses, ipaddress)) { flag2 = true; AmNetworkMonitor.Tracer.TraceDebug <string, string>((long)this.GetHashCode(), "NIC '{0}' on DNS at {1}", amClusterNetInterface.Name, text); break; } } } } if (flag2) { AmNetworkMonitor.Nic nic = new AmNetworkMonitor.Nic(amClusterNetInterface.Name, node); node.MapiNics.Add(nic); dictionary2.Add(nic.Name, nic); } } } } } this.m_nodeTable = dictionary; this.m_nicTable = dictionary2; } } } catch (ClusterException ex2) { ex = ex2; } finally { this.m_firstRefreshCompleted.Set(); this.m_firstRefreshCompleted.Close(); } if (ex != null) { AmNetworkMonitor.Tracer.TraceError <Exception>(0L, "RefreshMapiNetwork fails:{0}", ex); } }
private void RecalculateAccessRules() { if (this.m_accessRules == null) { this.m_accessRules = new List <FileSystemAccessRule>(); } string text = NativeHelpers.GetDomainName(); int num = text.IndexOf('.'); if (num > -1) { text = text.Substring(0, num); } ComparisonFilter filter = new ComparisonFilter(ComparisonOperator.Equal, DatabaseAvailabilityGroupSchema.Name, this.m_dagName); DatabaseAvailabilityGroup[] array = this.m_adSession.Find <DatabaseAvailabilityGroup>(null, QueryScope.SubTree, filter, null, 1); if (array == null || array.Length == 0) { this.m_accessRules.Clear(); TaskLogger.Trace("Account {0}$ for witness share \\\\{1}\\{2} does not exist yet, assuming we are working with empty dag, fsw will be created with current user {3} permissions and removed.", new object[] { this.m_dagName, this.WitnessServer, this.ShareName, WindowsIdentity.GetCurrent().User }); FileSystemAccessRule item = new FileSystemAccessRule(WindowsIdentity.GetCurrent().User.Translate(typeof(NTAccount)) as NTAccount, FileSystemRights.FullControl, AccessControlType.Allow); this.m_accessRules.Add(item); return; } MultiValuedProperty <IPAddress> databaseAvailabilityGroupIpAddresses = array[0].DatabaseAvailabilityGroupIpAddresses; bool flag = databaseAvailabilityGroupIpAddresses == null || databaseAvailabilityGroupIpAddresses.Count != 1 || !IPAddress.None.Equals(databaseAvailabilityGroupIpAddresses[0]); if (flag) { bool flag2 = true; if (this.m_accessRules.Count == 1) { if (this.m_accessRules[0].IdentityReference.Value.Contains(this.m_dagName)) { flag2 = false; } else { this.m_accessRules.Clear(); } } if (flag2) { ITopologyConfigurationSession topologyConfigurationSession = this.CreateRootSession(); DateTime t = DateTime.UtcNow.AddMinutes(6.0); ADComputer adcomputer; for (adcomputer = topologyConfigurationSession.FindComputerByHostName(this.m_dagName); adcomputer == null; adcomputer = topologyConfigurationSession.FindComputerByHostName(this.m_dagName)) { if (DateTime.UtcNow > t) { throw new DagUnableToFindCnoException(this.m_dagName); } Thread.Sleep(TimeSpan.FromSeconds(20.0)); } IdentityReference identity = adcomputer.Sid.Translate(typeof(NTAccount)); FileSystemAccessRule item2 = new FileSystemAccessRule(identity, FileSystemRights.FullControl, AccessControlType.Allow); this.m_accessRules.Add(item2); return; } } else { bool flag3 = false; IAmCluster amCluster = null; DatabaseAvailabilityGroup databaseAvailabilityGroup = array[0]; List <AmServerName> list = new List <AmServerName>(); try { if (!this.m_clusterReference.TryGetTarget(out amCluster) || (amCluster is AmCluster && ((AmCluster)amCluster).IsDisposed)) { amCluster = null; foreach (ADObjectId adobjectId in databaseAvailabilityGroup.Servers) { AmServerName amServerName = new AmServerName(adobjectId); if (!databaseAvailabilityGroup.StoppedMailboxServers.Contains(amServerName.Fqdn) && (databaseAvailabilityGroup.ServersInMaintenance == null || !databaseAvailabilityGroup.ServersInMaintenance.Contains(adobjectId))) { amCluster = ClusterFactory.Instance.OpenByName(amServerName); if (amCluster != null) { flag3 = true; break; } } } } if (amCluster != null) { using (IEnumerator <IAmClusterNode> enumerator2 = amCluster.EnumerateNodes().GetEnumerator()) { while (enumerator2.MoveNext()) { IAmClusterNode amClusterNode = enumerator2.Current; list.Add(amClusterNode.Name); } goto IL_352; } } foreach (ADObjectId serverId in databaseAvailabilityGroup.Servers) { list.Add(new AmServerName(serverId)); } IL_352 :; } finally { if (flag3 && amCluster != null) { amCluster.Dispose(); } } this.m_accessRules.Clear(); ITopologyConfigurationSession topologyConfigurationSession2 = this.CreateRootSession(); foreach (AmServerName amServerName2 in list) { ADComputer adcomputer2 = topologyConfigurationSession2.FindComputerByHostName(amServerName2.NetbiosName); IdentityReference identity2 = adcomputer2.Sid.Translate(typeof(NTAccount)); FileSystemAccessRule item3 = new FileSystemAccessRule(identity2, FileSystemRights.FullControl, AccessControlType.Allow); this.m_accessRules.Add(item3); } } }