Esempio n. 1
0
        public bool ParserConstant(string value)
        {
            var a = FeatureFlagEvaluatorUtils.Parse(value);

            Assert.IsInstanceOf <ConstantFeatureFlagStateEvaluator>(a);
            return(a.Evaluate(null) == FeatureFlagState.Active);
        }
        private void OnZookeeperEntryChanged(string path, string data)
        {
            var featureKey = GetKeyForPath(path);

            if (featureKey != null)
            {
                localView[featureKey] = new LocalViewItem {
                    Definition = data, Evaluator = FeatureFlagEvaluatorUtils.Parse(featureKey, data)
                };
            }
        }
Esempio n. 3
0
        public void SetRule(string store, string key, string rule)
        {
            var featureStore     = FeatureStoreFactory.GetFeatureStore(store);
            var def              = featureStore.GetFeatureFlagDefinition(key);
            var p                = FeatureFlagEvaluatorUtils.Parse(key, def.Definition);
            var dynamicEvaluator = p as DynamicFeatureFlagStateEvaluator ?? new DynamicFeatureFlagStateEvaluator(key, new FeatureRulesDefinition());

            dynamicEvaluator.Rules.ActiveExpression = rule;
            featureStore.SetFeatureFlagDefinition(new FeatureFlagDefinition {
                Name = key, Definition = FeatureFlagEvaluatorUtils.SerializeRules(dynamicEvaluator.Rules)
            });
        }
Esempio n. 4
0
        public void ComplexValue()
        {
            var value = @"
{
    'contextualRules': [
        { 
            'rule': 'Or',
            'rules': [ 
                {
                    'rule': 'Schedule',
                    'from': '2016-11-28T12:00:00', 
                    'to': '2016-11-28T14:00:00'
                },
                {
                    'rule': 'Schedule',
                    'from': '2016-11-28T18:00:00', 
                    'to': '2016-11-28T20:00:00'
                },
            ]
        },
        {
            'rule': 'Or',
            'rules': [ 
                {
                    'rule': 'UserSelection',
                    'uid': 'DF767C54-AB7F-4158-ADBC-56C38B4E7831',
                },
                {
                    'rule': 'UserSelection',
                    'ratio': '0.05'
                },
            ]
        }
    ]
}
";
            var a     = FeatureFlagEvaluatorUtils.Parse(value);

            Assert.IsInstanceOf <DynamicFeatureFlagStateEvaluator>(a);

            var ev = (DynamicFeatureFlagStateEvaluator)a;

            Assert.AreEqual(2, ev.Rules.ContextualRules.Length);
            Assert.IsInstanceOf <OrRule>(ev.Rules.ContextualRules[0]);
            Assert.AreEqual(2, ((OrRule)ev.Rules.ContextualRules[0]).Rules.Length);
            Assert.IsInstanceOf <ScheduleRule>(((OrRule)ev.Rules.ContextualRules[0]).Rules[0]);
            Assert.IsInstanceOf <ScheduleRule>(((OrRule)ev.Rules.ContextualRules[0]).Rules[1]);
            Assert.IsInstanceOf <OrRule>(ev.Rules.ContextualRules[1]);
            Assert.AreEqual(2, ((OrRule)ev.Rules.ContextualRules[1]).Rules.Length);
            Assert.IsInstanceOf <UserSelectionRule>(((OrRule)ev.Rules.ContextualRules[1]).Rules[0]);
            Assert.IsInstanceOf <UserSelectionRule>(((OrRule)ev.Rules.ContextualRules[1]).Rules[1]);
        }
 public void SetFeatureFlagDefinition(FeatureFlagDefinition featureFlagDefinition)
 {
     if (zooKeeper.getState() == Z.ZooKeeper.States.CONNECTED || zooKeeper.getState() == Z.ZooKeeper.States.CONNECTING)
     {
         WriteKey(featureFlagDefinition.Name, featureFlagDefinition.Definition).Wait();
     }
     else
     {
         localView[featureFlagDefinition.Name] = new LocalViewItem
         {
             Definition = featureFlagDefinition.Definition,
             Evaluator  = FeatureFlagEvaluatorUtils.Parse(featureFlagDefinition.Name, featureFlagDefinition.Definition)
         }
     };
 }
Esempio n. 6
0
        public void Dectivate(string store, string key)
        {
            var featureStore     = FeatureStoreFactory.GetFeatureStore(store);
            var def              = featureStore.GetFeatureFlagDefinition(key);
            var p                = FeatureFlagEvaluatorUtils.Parse(key, def.Definition);
            var dynamicEvaluator = p as DynamicFeatureFlagStateEvaluator;

            if (dynamicEvaluator != null)
            {
                dynamicEvaluator.Rules.OverrideValue = false;
                featureStore.SetFeatureFlagDefinition(new FeatureFlagDefinition {
                    Name = key, Definition = FeatureFlagEvaluatorUtils.SerializeRules(dynamicEvaluator.Rules)
                });
            }
            else
            {
                featureStore.SetFeatureFlagDefinition(new FeatureFlagDefinition {
                    Name = key, Definition = "false"
                });
            }
        }
Esempio n. 7
0
        public async Task <IActionResult> StoreIndex(string store)
        {
            var featureStore = FeatureStoreFactory.GetFeatureStore(store);
            var model        = new IndexViewModel
            {
                Features = featureStore.GetAllFeatures()
                           .Select(
                    x =>
                {
                    var definition       = featureStore.GetFeatureFlagDefinition(x.Name);
                    var p                = FeatureFlagEvaluatorUtils.Parse(x.Name, definition.Definition);
                    var dynamicEvaluator = p as DynamicFeatureFlagStateEvaluator;
                    if (dynamicEvaluator != null)
                    {
                        return(new FeatureFlagsViewModel
                        {
                            Key = x.Name,
                            IsDynamic = true,
                            IsActive = dynamicEvaluator.Rules.OverrideValue.GetValueOrDefault(true),
                            Definition = dynamicEvaluator.Rules.ActiveExpression
                        });
                    }
                    else
                    {
                        return new FeatureFlagsViewModel
                        {
                            Key       = x.Name,
                            IsDynamic = false,
                            IsActive  = x.GetState(null) == FeatureFlagState.Active
                        }
                    };
                }
                    ).OrderBy(x => x.Key).ToList(),
                ActiveNodes = await(featureStore as IWatchdog)?.GetActiveNodes(),
                AllStores   = await FeatureStoreFactory.GetStores()
            };

            return(View(model));
        }
Esempio n. 8
0
        public FeatureFlagState GetFeatureState(string featureKey, FeatureContext featureContext)
        {
            var v = GetFeatureFlagDefinition(featureKey)?.Definition;

            return(FeatureFlagEvaluatorUtils.Parse(featureKey, v).Evaluate(featureContext));
        }