Пример #1
0
        public static ICommandConfigSet CreateCustomConfigSet(IsolationModeEnum isolationMode = IsolationModeEnum.SemaphoreIsolation)
        {
            ICommandConfigSet configSet = ComponentFactory.CreateCommandConfigSet(isolationMode);

            configSet.ToConcrete().CircuitBreakerEnabled = false;
            configSet.CircuitBreakerErrorThresholdPercentage = 99;
            configSet.CircuitBreakerForceClosed           = true;
            configSet.CircuitBreakerForceOpen             = true;
            configSet.CircuitBreakerRequestCountThreshold = 99;
            configSet.ToConcrete().CircuitBreakerSleepWindowInMilliseconds = 4999;
            configSet.CommandMaxConcurrentCount    = 99;
            configSet.CommandTimeoutInMilliseconds = 4999;
            configSet.DegradeLogLevel                 = true;
            configSet.FallbackMaxConcurrentCount      = 4999;
            configSet.LogExecutionError               = true;
            configSet.MaxAsyncCommandExceedPercentage = 99;
            configSet.ToConcrete().MetricsHealthSnapshotIntervalInMilliseconds   = 10;
            configSet.ToConcrete().MetricsRollingPercentileBucketSize            = 50;
            configSet.ToConcrete().MetricsRollingPercentileEnabled               = false;
            configSet.ToConcrete().MetricsRollingPercentileWindowBuckets         = 20;
            configSet.ToConcrete().MetricsRollingPercentileWindowInMilliseconds  = 80 * 1000;
            configSet.ToConcrete().MetricsRollingStatisticalWindowBuckets        = 20;
            configSet.ToConcrete().MetricsRollingStatisticalWindowInMilliseconds = 200 * 1000;

            return(configSet);
        }
        public CrmPluginRegistrationAttribute(
            string message,
            string entityLogicalName,
            StageEnum stage,
            ExecutionModeEnum executionMode,
            string filteringAttributes,
            string stepName,
            int executionOrder,
            IsolationModeEnum isolationModel

            )
        {
            Message = message;
            EntityLogicalName = entityLogicalName;
            FilteringAttributes = filteringAttributes;
            Name = stepName;
            ExecutionOrder = executionOrder;
            Stage = stage;
            ExecutionMode = executionMode;
            IsolationMode = isolationModel;
            Offline = false;
            Server = true;


        }
Пример #3
0
 public CrmPluginRegistrationAttribute(string name, string friendlyName, string description, string groupName, IsolationModeEnum isolationModel)
 {
     Name          = name;
     FriendlyName  = friendlyName;
     Description   = description;
     GroupName     = groupName;
     IsolationMode = isolationModel;
 }
Пример #4
0
        public static ICommandConfigSet CreateCommandConfigSet(IsolationModeEnum isolationMode)
        {
            CommandConfigSet configSet = new CommandConfigSet()
            {
                IsolationMode           = isolationMode,
                CircuitBreakerEnabled   = true,
                CircuitBreakerForceOpen = false,
                CircuitBreakerSleepWindowInMilliseconds = 5000,

                MetricsRollingStatisticalWindowBuckets        = 10,
                MetricsRollingStatisticalWindowInMilliseconds = 10000,
                MetricsRollingPercentileEnabled = true,
                MetricsRollingPercentileWindowInMilliseconds = 60000,
                MetricsRollingPercentileWindowBuckets        = 6,
                MetricsRollingPercentileBucketSize           = 100,
                MetricsHealthSnapshotIntervalInMilliseconds  = 100,

                MaxAsyncCommandExceedPercentage = DefaultMaxAsyncCommandExceedPercentage,
                DegradeLogLevel   = FrameworkDefaultDegradeLogLevel,
                LogExecutionError = DefaultLogExecutionError
            };

            if (DefaultCircuitBreakerErrorThresholdPercentage.HasValue)
            {
                configSet.CircuitBreakerErrorThresholdPercentage = DefaultCircuitBreakerErrorThresholdPercentage.Value;
            }

            if (DefaultCircuitBreakerForceClosed.HasValue)
            {
                configSet.CircuitBreakerForceClosed = DefaultCircuitBreakerForceClosed.Value;
            }

            if (DefaultCircuitBreakerRequestCountThreshold.HasValue)
            {
                configSet.CircuitBreakerRequestCountThreshold = DefaultCircuitBreakerRequestCountThreshold.Value;
            }

            if (DefaultCommandTimeoutInMilliseconds.HasValue)
            {
                configSet.CommandTimeoutInMilliseconds = DefaultCommandTimeoutInMilliseconds.Value;
            }

            if (isolationMode == IsolationModeEnum.SemaphoreIsolation && DefaultSemaphoreIsolationMaxConcurrentCount.HasValue)
            {
                configSet.CommandMaxConcurrentCount  = DefaultSemaphoreIsolationMaxConcurrentCount.Value;
                configSet.FallbackMaxConcurrentCount = configSet.CommandMaxConcurrentCount;
            }
            else if (isolationMode == IsolationModeEnum.ThreadIsolation && DefaultThreadIsolationMaxConcurrentCount.HasValue)
            {
                configSet.CommandMaxConcurrentCount  = DefaultThreadIsolationMaxConcurrentCount.Value;
                configSet.FallbackMaxConcurrentCount = configSet.CommandMaxConcurrentCount;
            }

            return(configSet);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="message">Message Name</param>
 /// <param name="entityLogicalName"></param>
 /// <param name="stage"></param>
 /// <param name="executionMode"></param>
 /// <param name="filteringAttributes">Comma separated list of attributes that will trigger this step. Leave null for all attributes.</param>
 /// <param name="stepName"></param>
 /// <param name="executionOrder"></param>
 /// <param name="isolationModel"></param>
 public CrmPluginRegistrationAttribute(
     MessageNameEnum message,
     string entityLogicalName,
     StageEnum stage,
     ExecutionModeEnum executionMode,
     string filteringAttributes,
     string stepName,
     int executionOrder,
     IsolationModeEnum isolationModel
     ) : this(message.ToString(), entityLogicalName, stage, executionMode, filteringAttributes, stepName, executionOrder, isolationModel)
 {
 }
Пример #6
0
 public static ICommandMetrics CreateCommandMetrics(ICommandConfigSet configSet, string key, IsolationModeEnum isolationMode)
 {
     if (isolationMode == IsolationModeEnum.SemaphoreIsolation)
     {
         return(new SemaphoreIsolationCommandMetrics(configSet, key));
     }
     return(new ThreadIsolationCommandMetrics(configSet, key));
 }
Пример #7
0
        internal static CommandComponents CreateCommandComponents(string key, string instanceKey, string commandKey, string groupKey, string domain, IsolationModeEnum isolationMode, Action <ICommandConfigSet> config, Type type)
        {
            if (!key.IsValidHystrixName())
            {
                string message = "Hystrix command key has invalid char: " + key + @". Name pattern is: ^[a-zA-Z0-9][a-zA-Z0-9\-_.]*[a-zA-Z0-9]$";
                CommonUtils.Log.Log(LogLevelEnum.Fatal, message, new Dictionary <string, string>().AddLogTagData("FXD303004"));
                throw new ArgumentException(message);
            }
            if (!string.IsNullOrWhiteSpace(instanceKey) && !instanceKey.IsValidHystrixName())
            {
                string str2 = "Hystrix command instanceKey has invalid char: " + instanceKey + @". Name pattern is: ^[a-zA-Z0-9][a-zA-Z0-9\-_.]*[a-zA-Z0-9]$";
                CommonUtils.Log.Log(LogLevelEnum.Fatal, str2, new Dictionary <string, string>().AddLogTagData("FXD303004"));
                throw new ArgumentException(str2);
            }
            if (!commandKey.IsValidHystrixName())
            {
                string str3 = "Hystrix command commandKey has invalid char: " + commandKey + @". Name pattern is: ^[a-zA-Z0-9][a-zA-Z0-9\-_.]*[a-zA-Z0-9]$";
                CommonUtils.Log.Log(LogLevelEnum.Fatal, str3, new Dictionary <string, string>().AddLogTagData("FXD303004"));
                throw new ArgumentException(str3);
            }
            if (!groupKey.IsValidHystrixName())
            {
                string str4 = "Hystrix command group commandKey has invalid char: " + groupKey + @". Name pattern is: ^[a-zA-Z0-9][a-zA-Z0-9\-_.]*[a-zA-Z0-9]$";
                CommonUtils.Log.Log(LogLevelEnum.Fatal, str4, new Dictionary <string, string>().AddLogTagData("FXD303005"));
                throw new ArgumentException(str4);
            }
            if (!domain.IsValidHystrixName())
            {
                string str5 = "Hystrix domain has invalid char: " + domain + @". Name pattern is: ^[a-zA-Z0-9][a-zA-Z0-9\-_.]*[a-zA-Z0-9]$";
                CommonUtils.Log.Log(LogLevelEnum.Fatal, str5, new Dictionary <string, string>().AddLogTagData("FXD303006"));
                throw new ArgumentException(str5);
            }
            if (CommandCount >= MaxCommandCount)
            {
                string str6 = "Hystrix command count has reached the limit: " + MaxCommandCount;
                CommonUtils.Log.Log(LogLevelEnum.Fatal, str6, new Dictionary <string, string>().AddLogTagData("FXD303007"));
                throw new ArgumentException(str6);
            }
            CommandCount.IncrementAndGet();
            ICommandConfigSet configSet = ComponentFactory.CreateCommandConfigSet(isolationMode);

            configSet.SubcribeConfigChangeEvent(delegate(ICommandConfigSet c) {
                OnConfigChanged(key, c);
            });
            try
            {
                if (config != null)
                {
                    config(configSet);
                }
            }
            catch (Exception exception)
            {
                CommonUtils.Log.Log(LogLevelEnum.Fatal, "Failed to config command: " + key, exception, new Dictionary <string, string>().AddLogTagData("FXD303008"));
            }
            ICommandMetrics   metrics    = ComponentFactory.CreateCommandMetrics(configSet, key, isolationMode);
            CommandComponents components = new CommandComponents {
                ConfigSet      = configSet,
                Metrics        = metrics,
                CircuitBreaker = ComponentFactory.CreateCircuitBreaker(configSet, metrics)
            };
            CommandInfo info = new CommandInfo {
                Domain      = domain.ToLower(),
                GroupKey    = groupKey.ToLower(),
                CommandKey  = commandKey.ToLower(),
                InstanceKey = (instanceKey == null) ? null : instanceKey.ToLower(),
                Key         = key.ToLower(),
                Type        = isolationMode.ToString()
            };

            components.CommandInfo   = info;
            components.Log           = ComponentFactory.CreateLog(configSet, type);
            components.IsolationMode = isolationMode;
            return(components);
        }