/// <summary>
        /// Initializes a new instance of the <see cref="KinesisFirehoseSink"/> class.
        /// </summary>
        /// <param name="context">The <see cref="IPlugInContext"/> that contains configuration info, logger, metrics etc.</param>
        /// <param name="failoverSink">The <see cref="FailoverSink{AmazonKinesisFirehoseClient}"/> that defines failover sink class.</param>
        /// <param name="failoverSinkRegionStrategy">The <see cref="FailoverStrategy{AmazonKinesisFirehoseClient}"/> that defines failover sink region selection strategy.</param>
        public KinesisFirehoseSink(
            IPlugInContext context,
            FailoverSink <AmazonKinesisFirehoseClient> failoverSink,
            FailoverStrategy <AmazonKinesisFirehoseClient> failoverSinkRegionStrategy)
            : this(context, failoverSinkRegionStrategy.GetPrimaryRegionClient()) // Setup Kinesis Firehose Client with Primary Region
        {
            // Parse or default
            // Max wait interval between failback retry
            if (!int.TryParse(_config[ConfigConstants.MAX_FAILBACK_RETRY_INTERVAL_IN_MINUTES], out _maxFailbackRetryIntervalInMinutes))
            {
                _maxFailbackRetryIntervalInMinutes = ConfigConstants.DEFAULT_MIN_WAIT_BEFORE_REGION_FAILBACK_RETRY_IN_MINUTES;
            }
            else if (_maxFailbackRetryIntervalInMinutes < ConfigConstants.DEFAULT_MIN_WAIT_BEFORE_REGION_FAILBACK_RETRY_IN_MINUTES)
            {
                throw new ArgumentException(String.Format("Invalid \"{0}\" value, please provide positive integer greator than \"{1}\".",
                                                          ConfigConstants.MAX_FAILBACK_RETRY_INTERVAL_IN_MINUTES, ConfigConstants.DEFAULT_MIN_WAIT_BEFORE_REGION_FAILBACK_RETRY_IN_MINUTES));
            }

            // Failover Sink
            _failoverSink        = failoverSink;
            _failoverSinkEnabled = true;
            // Failover Sink Region Strategy
            _failoverSinkRegionStrategy = failoverSinkRegionStrategy;

            // Setup Primary Region Failback Timer
            _primaryRegionFailbackTimer           = new System.Timers.Timer(_maxFailbackRetryIntervalInMinutes * 60 * 1000);
            _primaryRegionFailbackTimer.Elapsed  += new ElapsedEventHandler(FailbackToPrimaryRegion);
            _primaryRegionFailbackTimer.AutoReset = true;
            _primaryRegionFailbackTimer.Start();
        }
Esempio n. 2
0
            public LoadService(ILoadService <T> service, ILoadServiceProvider failoverProvider, Action <Exception> logger, FailoverStrategy strategy)
            {
                _service         = service;
                _failoverService = failoverProvider != null?failoverProvider.Load <T>() : null;

                _logger   = logger;
                _strategy = strategy;
            }
Esempio n. 3
0
            public LoadService(ILoadService <T> service, ILoadServiceProvider failoverProvider, Action <Exception> logger, FailoverStrategy strategy, bool allowInconsistentReplication)
            {
                _service         = service;
                _failoverService = failoverProvider != null?failoverProvider.Load <T>() : null;

                _logger   = logger;
                _strategy = strategy;
                _allowInconsistentReplication = allowInconsistentReplication;
            }
Esempio n. 4
0
 public static Options Use(this Options options, FailoverStrategy strategy)
 {
     return(strategy switch
     {
         FailoverStrategy.ActiveActive => options.Use <ActiveActiveFailoverStrategy>(),
         FailoverStrategy.ActivePassive => options.Use <ActivePassiveFailoverStrategy>(),
         FailoverStrategy.None => options.Use <NoFailoverStrategy>(),
         _ => throw new NotSupportedException(
             $"Failover strategy {strategy} unknown."),
     });
Esempio n. 5
0
 public FailoverRepostiory(IRepository repository, IRepository otherRepository, Action <Exception> logger = null, FailoverStrategy strategy = FailoverStrategy.ReplicationOnly)
     : base(repository)
 {
     if (otherRepository == null)
     {
         throw new ArgumentNullException("otherRepository");
     }
     _other      = otherRepository;
     _current    = _repository;
     _logger     = logger;
     _strategy   = strategy;
     _failedOver = false;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="FailoverSink{TAWSClient}"/> class.
        /// </summary>
        /// <param name="context">The <see cref="IPlugInContext"/> that contains configuration info, logger, metrics etc.</param>
        /// <param name="failoverSinkRegionStrategy">The <see cref="FailoverStrategy{TAWSClient}"/> that defines sinks region selection strategy.</param>
        public FailoverSink(
            IPlugInContext context,
            FailoverStrategy <TAWSClient> failoverSinkRegionStrategy)
            : base(context)
        {
            // Parse or default
            // Max errors count before failover
            if (!int.TryParse(_config[ConfigConstants.MAX_ERRORS_COUNT_BEFORE_FAILOVER], out _maxErrorsCountBeforeFailover))
            {
                _maxErrorsCountBeforeFailover = ConfigConstants.DEFAULT_MAX_CONSECUTIVE_ERRORS_COUNT;
            }
            else if (_maxErrorsCountBeforeFailover < 1)
            {
                throw new ArgumentException(String.Format("Invalid \"{0}\" value, please provide positive integer.",
                                                          ConfigConstants.MAX_ERRORS_COUNT_BEFORE_FAILOVER));
            }

            // Max wait interval before failover
            if (!int.TryParse(_config[ConfigConstants.MAX_FAILOVER_INTERVAL_IN_MINUTES], out _maxWaitIntervalBeforeFailover))
            {
                _maxWaitIntervalBeforeFailover = ConfigConstants.DEFAULT_MAX_WAIT_BEFORE_REGION_FAILOVER_IN_MINUTES;
            }
            else if (_maxWaitIntervalBeforeFailover < 1)
            {
                throw new ArgumentException(String.Format("Invalid \"{0}\" value, please provide positive integer.",
                                                          ConfigConstants.MAX_FAILOVER_INTERVAL_IN_MINUTES));
            }

            // Setup Failover Strategy
            _failoverSinkRegionStrategy = failoverSinkRegionStrategy;

            // Setup Secondary Region Failover Timer
            _secondaryRegionFailoverTimer           = new Timer(_maxWaitIntervalBeforeFailover * 60 * 1000);
            _secondaryRegionFailoverTimer.Elapsed  += new ElapsedEventHandler(FailOverToSecondaryRegion);
            _secondaryRegionFailoverTimer.AutoReset = false;
        }
Esempio n. 7
0
 public static IRepository WithFailover(this IRepository repository, IRepository otherRepository, Action <Exception> logger = null, FailoverStrategy strategy = FailoverStrategy.ReplicationOnly)
 {
     return(new FailoverRepostiory(repository, otherRepository, logger, strategy));
 }
Esempio n. 8
0
 public FailoverPolicy(long retryCount, FailoverStrategy strategy)
 {
     this.retryCount = new Counter(retryCount);
     this.Strategy = strategy;
 }
Esempio n. 9
0
 public FailoverPolicy(long retryCount, FailoverStrategy strategy)
 {
     this.retryCount = new Counter(retryCount);
     this.Strategy   = strategy;
 }