Example #1
0
        public bool TryUpdate(
            ReliabilityLevel reliabilityLevel,
            IEnumerable <NodeDescription> existingSeedNodes,
            IEnumerable <NodeDescription> enabledNodes, /*list of nodes which are enabled*/
            int faultDomainCount,
            int upgradeDomainCount,
            out List <NodeDescription> seedNodesToAdd,
            out List <NodeDescription> seedNodesToRemove)
        {
            existingSeedNodes.ThrowIfNull("existingSeedNodes");
            enabledNodes.ThrowIfNull("nodes");

            seedNodesToAdd    = new List <NodeDescription>();
            seedNodesToRemove = new List <NodeDescription>();

            var targetSeedNodeCount = reliabilityLevel.GetSeedNodeCount();

            if (targetSeedNodeCount == existingSeedNodes.Count())
            {
                return(true);
            }
            else if (targetSeedNodeCount < existingSeedNodes.Count())
            {
                var seedNodesToRemoveCount = existingSeedNodes.Count() - targetSeedNodeCount;
                seedNodesToRemove = this.RemoveSeedNodes(
                    seedNodesToRemoveCount,
                    existingSeedNodes);
            }
            else
            {
                var seedNodesToAddCount = targetSeedNodeCount - existingSeedNodes.Count();
                seedNodesToAdd = this.AddSeedNodes(
                    seedNodesToAddCount,
                    enabledNodes,
                    existingSeedNodes,
                    faultDomainCount,
                    upgradeDomainCount);
                if (seedNodesToAdd == null)
                {
                    // not enough nodes available to reach target seed nodes
                    return(false);
                }
            }

            return(true);
        }
Example #2
0
        public IEnumerable <NodeDescription> Select(
            ReliabilityLevel reliabilityLevel,
            int totalExpectedPrimaryNodeCount,
            IEnumerable <NodeDescription> primaryNodeTypeNodes,
            int faultDomainCount,
            int upgradeDomainCount,
            bool isVmss)
        {
            this.traceLogger.WriteInfo(
                SeedNodeSelector.TraceType,
                "SeedNodeSelector.Select: Entering. reliabilityLevel: {0}, primaryNodeCount: {1}, primaryNodeTypeNodes.Count: {2}, faultDomainCount: {3}, upgradeDomainCount: {4}, primaryNodeTypeNodes: {5}",
                reliabilityLevel,
                totalExpectedPrimaryNodeCount,
                primaryNodeTypeNodes.Count(),
                faultDomainCount,
                upgradeDomainCount,
                this.DumpSeedNodes(primaryNodeTypeNodes));

            bool foundNewNode = this.UpdateNodeInfo(primaryNodeTypeNodes, faultDomainCount, upgradeDomainCount);

            this.traceLogger.WriteInfo(SeedNodeSelector.TraceType, "SeedNodeSelector.Select: foundNewNode is {0}", foundNewNode);

            var targetSeedNodeCount = reliabilityLevel.GetSeedNodeCount();

            this.traceLogger.WriteInfo(SeedNodeSelector.TraceType, "SeedNodeSelector.Select: nodes.Count: {0}, targetSeedNodeCount: {1}, totalExpectedNode: {2}", primaryNodeTypeNodes.Count(), targetSeedNodeCount, totalExpectedPrimaryNodeCount);

            if (primaryNodeTypeNodes.Count() < targetSeedNodeCount)
            {
                return(null);
            }

            if (targetSeedNodeCount == totalExpectedPrimaryNodeCount && primaryNodeTypeNodes.Count() == targetSeedNodeCount)
            {
                return(primaryNodeTypeNodes);
            }

            if (!foundNewNode && !TimeoutHelper.HasExpired(this.timeoutHelper))
            {
                // During optimal seed node selection, run the logic when
                // more nodes are available than the last attempt
                return(null);
            }

            if (isVmss)
            {
                var selectedSeedNodes =
                    primaryNodeTypeNodes.OrderBy(item => item.NodeInstance)
                    .Take(targetSeedNodeCount)
                    .TakeWhile((nodeDescription, index) => index == nodeDescription.NodeInstance);

                if (selectedSeedNodes.Count() == targetSeedNodeCount)
                {
                    return(selectedSeedNodes);
                }

                if (!TimeoutHelper.HasExpired(this.timeoutHelper))
                {
                    return(null);
                }

                return(this.AddSeedNodes(
                           targetSeedNodeCount - selectedSeedNodes.Count(),
                           primaryNodeTypeNodes,
                           selectedSeedNodes,
                           faultDomainCount,
                           upgradeDomainCount));
            }
            else
            {
                return(this.SelectInternal(targetSeedNodeCount, primaryNodeTypeNodes, TimeoutHelper.HasExpired(this.timeoutHelper) || primaryNodeTypeNodes.Count() == totalExpectedPrimaryNodeCount));
            }
        }