예제 #1
0
        protected override void RunCheck()
        {
            ExTraceGlobals.HealthChecksTracer.TraceDebug <string>((long)this.GetHashCode(), "CheckNetworksOnNode(): Checking the networks on node '{0}'.", base.ServerName);
            if (SharedHelper.StringIEquals(base.ServerName, Environment.MachineName) && !this.m_dag.ManualDagNetworkConfiguration && this.LoadNetworkDescription())
            {
                this.m_serverToCheck = this.m_networkConfig.FindNode(Environment.MachineName);
                if (this.m_serverToCheck == null)
                {
                    this.m_errors.Add(Strings.DagNetworkEnumerationFailed(Strings.DagNodeNotFound(Environment.MachineName)));
                }
                else
                {
                    this.CheckForSingleDnsNic();
                    this.CheckForUniformNetworks();
                }
            }
            Exception ex = null;

            try
            {
                DagNetworkConfiguration dagNetworkConfig = DagNetworkRpc.GetDagNetworkConfig(base.ServerName);
                int num = 0;
                foreach (DatabaseAvailabilityGroupNetwork databaseAvailabilityGroupNetwork in dagNetworkConfig.Networks)
                {
                    if (!databaseAvailabilityGroupNetwork.IgnoreNetwork)
                    {
                        if (databaseAvailabilityGroupNetwork.ReplicationEnabled)
                        {
                            num++;
                        }
                        foreach (DatabaseAvailabilityGroupNetworkSubnet databaseAvailabilityGroupNetworkSubnet in databaseAvailabilityGroupNetwork.Subnets)
                        {
                            if (databaseAvailabilityGroupNetworkSubnet.State != DatabaseAvailabilityGroupNetworkSubnet.SubnetState.Up)
                            {
                                foreach (DatabaseAvailabilityGroupNetworkInterface databaseAvailabilityGroupNetworkInterface in databaseAvailabilityGroupNetwork.Interfaces)
                                {
                                    if (!base.IsNodeStopped(new AmServerName(databaseAvailabilityGroupNetworkInterface.NodeName)))
                                    {
                                        this.m_errors.Add(Strings.DagSubnetDown(databaseAvailabilityGroupNetworkSubnet.SubnetId.ToString(), databaseAvailabilityGroupNetwork.Name, databaseAvailabilityGroupNetworkSubnet.State.ToString()));
                                    }
                                }
                            }
                        }
                        foreach (DatabaseAvailabilityGroupNetworkInterface databaseAvailabilityGroupNetworkInterface2 in databaseAvailabilityGroupNetwork.Interfaces)
                        {
                            if (databaseAvailabilityGroupNetworkInterface2.State != DatabaseAvailabilityGroupNetworkInterface.InterfaceState.Up && !base.IsNodeStopped(new AmServerName(databaseAvailabilityGroupNetworkInterface2.NodeName)))
                            {
                                this.m_errors.Add(Strings.DagNicDown(databaseAvailabilityGroupNetworkInterface2.NodeName, databaseAvailabilityGroupNetworkInterface2.IPAddress.ToString(), databaseAvailabilityGroupNetworkInterface2.State.ToString()));
                            }
                        }
                    }
                }
                if (num == 0)
                {
                    this.m_errors.Add(Strings.DagNetworkAllDisabledWarning);
                }
            }
            catch (DagNetworkManagementException ex2)
            {
                ex = ex2;
            }
            catch (HaRpcServerBaseException ex3)
            {
                ex = ex3;
            }
            catch (HaRpcServerTransientBaseException ex4)
            {
                ex = ex4;
            }
            if (ex != null)
            {
                this.m_errors.Add(ServerStrings.DagNetworkManagementError(ex.Message));
            }
            if (this.m_errors.Count > 0)
            {
                string value = string.Join("\n", this.m_errors.ToArray());
                base.FailContinue(new LocalizedString(value));
            }
        }
        private List <DatabaseAvailabilityGroupNetwork> Find(QueryFilter queryFilter, ObjectId rootId, bool deepSearch, SortBy sortBy)
        {
            List <DatabaseAvailabilityGroupNetwork> list = new List <DatabaseAvailabilityGroupNetwork>();
            DagNetworkQueryFilter dagNetworkQueryFilter  = null;

            if (queryFilter != null)
            {
                dagNetworkQueryFilter = (queryFilter as DagNetworkQueryFilter);
            }
            IEnumerable <DatabaseAvailabilityGroup> enumerable;

            if (this.TargetDag != null)
            {
                enumerable = new DatabaseAvailabilityGroup[]
                {
                    this.TargetDag
                };
            }
            else
            {
                string identity = "*";
                if (dagNetworkQueryFilter != null && dagNetworkQueryFilter.NamesToMatch != null && dagNetworkQueryFilter.NamesToMatch.DagName != null)
                {
                    identity = dagNetworkQueryFilter.NamesToMatch.DagName;
                }
                DatabaseAvailabilityGroupIdParameter databaseAvailabilityGroupIdParameter = DatabaseAvailabilityGroupIdParameter.Parse(identity);
                enumerable = databaseAvailabilityGroupIdParameter.GetObjects <DatabaseAvailabilityGroup>(null, this.m_adSession);
            }
            if (enumerable != null)
            {
                Regex regex = null;
                if (dagNetworkQueryFilter != null && dagNetworkQueryFilter.NamesToMatch != null && dagNetworkQueryFilter.NamesToMatch.NetName != null)
                {
                    string pattern = Wildcard.ConvertToRegexPattern(dagNetworkQueryFilter.NamesToMatch.NetName);
                    regex = new Regex(pattern, RegexOptions.IgnoreCase);
                }
                foreach (DatabaseAvailabilityGroup databaseAvailabilityGroup in enumerable)
                {
                    DagNetworkConfiguration dagNetworkConfiguration = (this.m_targetServer == null) ? DagNetworkRpc.GetDagNetworkConfig(databaseAvailabilityGroup) : DagNetworkRpc.GetDagNetworkConfig(this.m_targetServer);
                    if (dagNetworkConfiguration != null && dagNetworkConfiguration.Networks != null)
                    {
                        this.m_netConfig = dagNetworkConfiguration;
                        foreach (DatabaseAvailabilityGroupNetwork databaseAvailabilityGroupNetwork in dagNetworkConfiguration.Networks)
                        {
                            if (regex == null || regex.IsMatch(databaseAvailabilityGroupNetwork.Name))
                            {
                                DagNetworkObjectId identity2 = new DagNetworkObjectId(databaseAvailabilityGroup.Name, databaseAvailabilityGroupNetwork.Name);
                                databaseAvailabilityGroupNetwork.SetIdentity(identity2);
                                databaseAvailabilityGroupNetwork.ResetChangeTracking();
                                list.Add(databaseAvailabilityGroupNetwork);
                            }
                        }
                    }
                }
            }
            return(list);
        }
        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();
        }
 public DagNetworkConfiguration ReadNetConfig(DatabaseAvailabilityGroup dag)
 {
     this.m_netConfig = DagNetworkRpc.GetDagNetworkConfig(dag);
     return(this.m_netConfig);
 }