Пример #1
0
        private static OperatorConfiguration GetOperatorConfiguration()
        {
            var configuration = new OperatorConfiguration();

            var retryPolicy = new RetryPolicy();

            if (int.TryParse(Environment.GetEnvironmentVariable("RETRY_MAX_ATTEMPTS"), out int maxAttempts))
            {
                retryPolicy.MaxAttempts = Math.Max(1, maxAttempts);
            }
            if (int.TryParse(Environment.GetEnvironmentVariable("RETRY_INITIAL_DELAY"), out int initialDelay))
            {
                retryPolicy.InitialDelay = Math.Max(0, initialDelay);
            }
            if (int.TryParse(Environment.GetEnvironmentVariable("RETRY_DELAY_MULTIPLIER"), out int delayMultiplier))
            {
                retryPolicy.DelayMultiplier = delayMultiplier;
            }
            configuration.RetryPolicy = retryPolicy;

            configuration.WatchNamespace = Environment.GetEnvironmentVariable("WATCH_NAMESPACE");

            configuration.WatchLabelSelector = Environment.GetEnvironmentVariable("WATCH_LABEL_SELECTOR");

            return(configuration);
        }
Пример #2
0
        /// <summary>
        /// Takes an operator and fills the right hand side parameters recurively to form an valid expression.
        /// </summary>
        /// <param name="item">An operator to fill.</param>
        private void FillParameters(ExpressionItem item)
        {
            //If the item is already valid, return.
            if (item.IsValid())
            {
                return;
            }
            //Find the NextItem item
            ExpressionItem next = NextItem();

            //If the next item is an operator,
            //check if the operator accepts the only valid config and check whether the
            //supplied parameters are accepted.
            if (next is OperatorItem)
            {
                OperatorConfiguration[] configs = ((OperatorItem)next).AcceptedConfigurations;
                OperatorConfiguration   config  = new OperatorConfiguration(Associativity.left, 1);
                bool result = false;
                for (int i = 0; i < configs.Length; i++)
                {
                    ExpressionItem   rightParam = Peek();
                    ExpressionItem[] param      = new ExpressionItem[1];
                    param[0] = rightParam;
                    OperatorConfiguration oc;
                    if (config.Equals(configs[i]) && ((OperatorItem)next).SuggestParameters(param, out oc))
                    {
                        //The operator accepts the parameters and config which it is given
                        result = true;
                        ((OperatorItem)next).Configuration = configs[i];
                        break;
                    }
                }
                if (!result)
                {
                    //The operator can't be used in the way supplied
                    throw new Exception("Interpreter.FillParameters: Malformed expression");
                }
                //Fill the parameters of the new operator recursively
                FillParameters(next);
            }

            //Add the next item as a parameter to the operator.
            ((FunctionItem)item).AddParameter(next);
        }
Пример #3
0
        /// <summary>
        /// Parses the expression string. If the expression is well-formed
        /// a tree will be constructed and the top node of the tree is returned.
        /// </summary>
        /// <returns>The top node of the tree.</returns>
        public ExpressionItem Interpret()
        {
            ExpressionItem topNode = NextItem();

            //Inserts the first node into the tree.
            //This has to be managed separatly.
            if (topNode is OperatorItem)
            {
                //Find out the accepted configurations of the item to add.
                OperatorConfiguration[] configs = ((OperatorItem)topNode).AcceptedConfigurations;
                //The only valid config is a unary operator with the data on the right.
                OperatorConfiguration config = new OperatorConfiguration(Associativity.left, 1);

                //Find out whether the operator may have the only possible config
                bool result = false;
                for (int i = 0; i < configs.Length; i++)
                {
                    if (config.Equals(configs[i]))
                    {
                        //A valid configuration is found.
                        //Indicate success and tell the operator which configuration it is in.
                        result = true;
                        ((OperatorItem)topNode).Configuration = configs[i];
                        break;
                    }
                }
                if (!result)
                {
                    throw new Exception("Interpreter.Interpret(): Malformed expression");
                }
                //Fill all the parameter places of the top node to acquire a valid expression.
                FillParameters(topNode);
            }

            //As long as there exists more items in the expression,
            //add the next item to the tree.
            while (HasNext())
            {
                AddNextToTree(ref topNode);
            }

            return(topNode);
        }
Пример #4
0
 public MyResourceController(OperatorConfiguration configuration, IKubernetes client, ILoggerFactory loggerFactory = null) : base(configuration, client, loggerFactory)
 {
 }
Пример #5
0
        /// <summary>
        /// Add the next item to the expression tree.
        /// </summary>
        /// <param name="topNode">The top node of the tree.</param>
        private void AddNextToTree(ref ExpressionItem topNode)
        {
            //Get the next item. If the next item is an operator,
            //find the possible configurations and try to add it to the tree.
            ExpressionItem next = NextItem();

            if (next is OperatorItem && HasNext())
            {
                int nrOfParameters = 2;
                OperatorConfiguration[] configs = ((OperatorItem)next).AcceptedConfigurations;
                OperatorConfiguration   oc;
                ExpressionItem          rightParam = Peek();
                ExpressionItem          leftParam  = scannedItems[scannedItems.Count - 2];
                ExpressionItem[]        param      = new ExpressionItem[nrOfParameters];
                param[0] = leftParam;
                param[1] = rightParam;
                bool result = false;
                //Find the correct configuration.
                for (int i = 0; i < configs.Length; i++)
                {
                    if (configs[i].NrOfParameters == nrOfParameters && ((OperatorItem)next).SuggestParameters(param, out oc))
                    {
                        ((OperatorItem)next).Configuration = configs[i];
                        result = true;
                        break;
                    }
                }
                if (result)
                {
                    //The parameters were accepted as is and the item can be addd to the tree.
                    AddToTree(ref topNode, next);
                }
                else
                {
                    //The parameters were not accepted, negotiate config.
                    Negotiate(ref topNode, next, param);
                }
            }
            //The current item is an operator, but no items to the right of it.
            //Try to add it as unary operator.
            else if (next is OperatorItem)
            {
                int nrOfParameters = 1;
                OperatorConfiguration[] configs = ((OperatorItem)next).AcceptedConfigurations;
                OperatorConfiguration   config  = new OperatorConfiguration(Associativity.right, 1);
                OperatorConfiguration   oc;
                ExpressionItem          leftParam = scannedItems[scannedItems.Count - 2];
                ExpressionItem[]        param     = new ExpressionItem[nrOfParameters];
                param[0] = leftParam;
                bool result = false;
                for (int i = 0; i < configs.Length; i++)
                {
                    if (configs[i].Equals(config) && ((OperatorItem)next).SuggestParameters(param, out oc))
                    {
                        //The configuration were accepted
                        ((OperatorItem)next).Configuration = configs[i];
                        result = true;
                        break;
                    }
                }
                if (result)
                {
                    //Add the opeartor to the tree
                    AddToTree(ref topNode, next);
                }
                else
                {
                    //The operator wouldn't accept to be unary, throw exception
                    throw new Exception("Interpreter.AddNextToTree()1: Cannot form expression");
                }
            }
            else
            {
                //The next item is not an operator,
                //the tree is valid, but the next item can't be linked to the tree.
                throw new Exception("Interpreter.AddNextToTree()2: Cannot form expression");
            }
        }
Пример #6
0
 public TestableOperator(OperatorConfiguration configuration, IKubernetes client, ILoggerFactory loggerFactory = null) : base(configuration, client, loggerFactory)
 {
 }