Ejemplo n.º 1
0
        protected Dictionary <ContainersGroupState, List <(ICommand Command, string Output)> > ExecuteActions(IEnumerable <ContainersGroupState> states, Dictionary <ContainersGroupState, List <ICommand> > actions)
        {
            using (logger.BeginScope())
            {
                var output = new Dictionary <ContainersGroupState, List <(ICommand Command, string Output)> >();

                logger.LogDebug(LogEventId.MONITORING_SERVICE_ACTIONS_DETAILS, "Group is in following states: {States}", string.Join(", ", states));

                foreach (var state in states)
                {
                    foreach (var kvp in actions)
                    {
                        if (kvp.Key.HasFlag(state))
                        {
                            logger.LogInformation(LogEventId.MONITORING_SERVICE_ACTIONS_MATCH_DETAILS, "Found matching actions group {ActionsGroupFlags} with {ActionsCount} actions to execute for state {State}", kvp.Key, kvp.Value.Count, state);

                            if (!output.ContainsKey(state))
                            {
                                output.Add(state, new List <(ICommand Command, string Output)>());
                            }

                            foreach (var command in kvp.Value)
                            {
                                var actionOutput = commandsExecutorFactory.Execute(command);
                                output[state].Add((Command: command, Output: actionOutput));
                            }
                        }
                    }
                }

                return(output);
            }
        }