예제 #1
0
        public async Task <bool> IsActiveAsync(string featureName)
        {
            var active = false;

            var headerName = await _runtimeParameterAccessor
                             .GetValueAsync <string>(featureName, _descriptors[0]);

            var percentage = await _runtimeParameterAccessor
                             .GetValueAsync <double>(featureName, _descriptors[1]);

            if (headerName != null)
            {
                var headerValues = _httpContextAccessor.HttpContext.Request
                                   .Headers[headerName];

                var value = headerValues[0] ?? DEFAULT_HEADER_VALUE;

                var assignedPartition = JenkinsPartitioner.ResolveToLogicalPartition(value, NUMBER_OF_PARTITIONS);

                return(assignedPartition <= ((NUMBER_OF_PARTITIONS * percentage) / 100));
            }
            else
            {
                _logger.LogWarning($"The header name {_descriptors[0].Name} for feature {featureName} on RollupHeaderValueActivator is not configured correctly.");
            }

            return(active);
        }
예제 #2
0
        public async Task <bool> IsActiveAsync(string featureName)
        {
            var percentage = await _runtimeParameterAccessor
                             .GetValueAsync <double>(featureName, _descriptors[0]);

            var username = await _userProvider
                           .GetUserNameAsync() ?? ANONYMOUS_USER;

            var assignedPartition = JenkinsPartitioner.ResolveToLogicalPartition(username, NUMBER_OF_PARTITIONS);

            return(assignedPartition <= ((NUMBER_OF_PARTITIONS * percentage) / 100));
        }
예제 #3
0
        public static short ResolveToLogicalPartition(string value, short entityPartitionCount)
        {
            if (value == null)
            {
                return(0);
            }

            uint hash1;
            uint hash2;

            JenkinsPartitioner.ComputeHash(Encoding.ASCII.GetBytes(value.ToUpper()), 0U, 0U, out hash1, out hash2);

            return((short)Math.Abs((long)(hash1 ^ hash2) % (long)entityPartitionCount));
        }