public ConfigurationSetupContext(ILog log, IDatacenters datacenters, Func <IVostokApplicationIdentity> identityProvider) { Log = log.ForContext <VostokHostingEnvironment>(); Datacenters = datacenters; this.identityProvider = identityProvider; }
public BoostLocalDatacentersModifier( [NotNull] IDatacenters datacenters, double boostMultiplier = Constants.DefaultBoostMultiplier, double minimumWeightForBoosting = Constants.DefaultMinimumWeightForBoosting) : this(datacenters, () => boostMultiplier, () => minimumWeightForBoosting) { }
/// <summary> /// Adds a <see cref="BoostLocalDatacentersModifier"/> that will increase weight of replicas in local datacenter. /// </summary> public static void SetupBoostLocalDatacentersWeightModifier( [NotNull] this IWeighedReplicaOrderingBuilder self, [NotNull] IDatacenters datacenters, double boostMultiplier = Constants.DefaultBoostMultiplier, double minimumWeightForBoosting = Constants.DefaultMinimumWeightForBoosting) { self.AddModifier(new BoostLocalDatacentersModifier(datacenters, boostMultiplier, minimumWeightForBoosting)); }
/// <summary> /// Adds a <see cref="BoostLocalDatacentersModifier"/> that will increase weight of replicas in local datacenter. /// </summary> public static void SetupBoostLocalDatacentersWeightModifier( [NotNull] this IWeighedReplicaOrderingBuilder self, [NotNull] IDatacenters datacenters, [NotNull] Func <double> boostMultiplierProvider, [NotNull] Func <double> minimumWeightForBoostingProvider) { self.AddModifier(new BoostLocalDatacentersModifier(datacenters, boostMultiplierProvider, minimumWeightForBoostingProvider)); }
/// <summary> /// <para>Configures the global default <see cref="IDatacenters"/> with given instance, which will be returned by all subsequent <see cref="Get"/> calls.</para> /// <para>By default, this method fails when trying to overwrite a previously configured instance. This behaviour can be changed with <paramref name="canOverwrite"/> parameter.</para> /// </summary> /// <exception cref="ArgumentNullException">Provided instance was <c>null</c>.</exception> /// <exception cref="InvalidOperationException">Attempted to overwrite previously configured instance.</exception> public static void Configure([NotNull] IDatacenters datacenters, bool canOverwrite = false) { if (!canOverwrite && instance != null) { throw new InvalidOperationException($"Can't overwrite existing configured implementation of type '{instance.GetType().Name}'."); } instance = datacenters ?? throw new ArgumentNullException(nameof(datacenters)); }
public BoostLocalDatacentersModifier( [NotNull] IDatacenters datacenters, [NotNull] Func <double> boostMultiplierProvider, [NotNull] Func <double> minimumWeightForBoostingProvider) { this.datacenters = datacenters ?? throw new ArgumentNullException(nameof(datacenters)); this.boostMultiplierProvider = boostMultiplierProvider ?? throw new ArgumentNullException(nameof(boostMultiplierProvider)); this.minimumWeightForBoostingProvider = minimumWeightForBoostingProvider ?? throw new ArgumentNullException(nameof(minimumWeightForBoostingProvider)); }
private Func <bool> LocalDatacenterIsActive(IDatacenters datacenters) { if (datacenters == null) { return(null); } return(datacenters.LocalDatacenterIsActive); }
public DatacenterAwarenessMiddleware( [NotNull] RequestDelegate next, [NotNull] IOptions <DatacenterAwarenessSettings> options, [NotNull] IDatacenters datacenters, [NotNull] ILog log) { this.next = next ?? throw new ArgumentNullException(nameof(next)); this.options = (options ?? throw new ArgumentNullException(nameof(options))).Value; this.datacenters = datacenters ?? throw new ArgumentNullException(nameof(datacenters)); this.log = (log ?? throw new ArgumentNullException(nameof(log))).ForContext <DatacenterAwarenessMiddleware>(); }
internal VostokHostingEnvironment( [NotNull] HostingShutdown hostingShutdown, [NotNull] ApplicationShutdown applicationShutdown, [NotNull] IVostokApplicationIdentity applicationIdentity, [NotNull] IVostokApplicationLimits applicationLimits, [NotNull] Func <IVostokApplicationReplicationInfo> replicationInfoProvider, [NotNull] IVostokApplicationMetrics metrics, [NotNull] IVostokApplicationDiagnostics diagnostics, [NotNull] ILog log, [NotNull] ITracer tracer, [NotNull] IHerculesSink herculesSink, [NotNull] IConfigurationSource configurationSource, [NotNull] IConfigurationSource secretConfigurationSource, [NotNull] IConfigurationProvider configurationProvider, [NotNull] IConfigurationProvider secretConfigurationProvider, [NotNull] IClusterConfigClient clusterConfigClient, [NotNull] IServiceBeacon serviceBeacon, [CanBeNull] int?port, [NotNull] IServiceLocator serviceLocator, [NotNull] IContextGlobals contextGlobals, [NotNull] IContextProperties contextProperties, [NotNull] IContextConfiguration contextConfiguration, [NotNull] IDatacenters datacenters, [NotNull] IVostokHostExtensions hostExtensions, [NotNull] Action onDispose) { this.hostingShutdown = hostingShutdown ?? throw new ArgumentNullException(nameof(hostingShutdown)); this.applicationShutdown = applicationShutdown ?? throw new ArgumentNullException(nameof(applicationShutdown)); this.replicationInfoProvider = replicationInfoProvider ?? throw new ArgumentNullException(nameof(replicationInfoProvider)); this.onDispose = onDispose ?? throw new ArgumentNullException(nameof(onDispose)); ApplicationIdentity = applicationIdentity ?? throw new ArgumentNullException(nameof(applicationIdentity)); ApplicationLimits = applicationLimits ?? throw new ArgumentNullException(nameof(applicationLimits)); Metrics = metrics ?? throw new ArgumentNullException(nameof(metrics)); Diagnostics = diagnostics ?? throw new ArgumentNullException(nameof(diagnostics)); Log = log ?? throw new ArgumentNullException(nameof(log)); Tracer = tracer ?? throw new ArgumentNullException(nameof(tracer)); HerculesSink = herculesSink ?? throw new ArgumentNullException(nameof(herculesSink)); ConfigurationSource = configurationSource ?? throw new ArgumentNullException(nameof(configurationSource)); ConfigurationProvider = configurationProvider ?? throw new ArgumentNullException(nameof(configurationProvider)); SecretConfigurationSource = secretConfigurationSource ?? throw new ArgumentNullException(nameof(secretConfigurationSource)); SecretConfigurationProvider = secretConfigurationProvider ?? throw new ArgumentNullException(nameof(secretConfigurationProvider)); ClusterConfigClient = clusterConfigClient ?? throw new ArgumentNullException(nameof(clusterConfigClient)); ServiceBeacon = serviceBeacon ?? throw new ArgumentNullException(nameof(serviceBeacon)); Port = port; ServiceLocator = serviceLocator ?? throw new ArgumentNullException(nameof(serviceLocator)); ContextGlobals = contextGlobals ?? throw new ArgumentNullException(nameof(contextGlobals)); ContextProperties = contextProperties ?? throw new ArgumentNullException(nameof(contextProperties)); ContextConfiguration = contextConfiguration ?? throw new ArgumentNullException(nameof(contextConfiguration)); Datacenters = datacenters ?? throw new ArgumentNullException(nameof(datacenters)); HostExtensions = hostExtensions ?? throw new ArgumentNullException(nameof(hostExtensions)); }
public EnvironmentSetupContext( ILog log, IConfigurationSource configurationSource, IConfigurationSource secretConfigurationSource, IConfigurationSource mergedConfigurationSource, IConfigurationProvider configurationProvider, IConfigurationProvider secretConfigurationProvider, IClusterConfigClient clusterConfigClient, IDatacenters datacenters) { Log = log.ForContext <VostokHostingEnvironment>(); ConfigurationSource = configurationSource; SecretConfigurationSource = secretConfigurationSource; MergedConfigurationSource = mergedConfigurationSource; ConfigurationProvider = configurationProvider; SecretConfigurationProvider = secretConfigurationProvider; ClusterConfigClient = clusterConfigClient; Datacenters = datacenters; }
public static IEnumerable <Substitution> Provide( IVostokApplicationIdentity identity, IClusterConfigClient clusterConfig, IServiceBeacon beacon, IDatacenters datacenters) { if (identity != null) { yield return(new Substitution(VostokConfigurationPlaceholders.IdentityProject, () => identity.Project)); yield return(new Substitution(VostokConfigurationPlaceholders.IdentitySubproject, () => identity.Subproject)); yield return(new Substitution(VostokConfigurationPlaceholders.IdentityEnvironment, () => identity.Environment)); yield return(new Substitution(VostokConfigurationPlaceholders.IdentityApplication, () => identity.Application)); yield return(new Substitution(VostokConfigurationPlaceholders.IdentityInstance, () => identity.Instance)); } if (beacon != null) { yield return(new Substitution(VostokConfigurationPlaceholders.ServiceDiscoveryEnvironment, () => beacon.ReplicaInfo.Environment)); yield return(new Substitution(VostokConfigurationPlaceholders.ServiceDiscoveryApplication, () => beacon.ReplicaInfo.Application)); } if (datacenters != null) { yield return(new Substitution(VostokConfigurationPlaceholders.LocalDatacenter, datacenters.GetLocalDatacenter)); } if (clusterConfig != null) { yield return(new Substitution(VostokConfigurationPlaceholders.ClusterConfigZone, () => (clusterConfig as ClusterConfigClient)?.Zone ?? "default")); } }
public DatacenterWhitelistCheck(IDatacenters datacenters) => this.datacenters = datacenters;
public EnvironmentInfoProvider(IDatacenters datacenters) => this.datacenters = datacenters;
public void SetUp() { datacenters = Substitute.For <IDatacenters>(); modifier = new AvoidInactiveDatacentersModifier(datacenters); }
public AvoidInactiveDatacentersModifier([NotNull] IDatacenters datacenters) { this.datacenters = datacenters ?? throw new ArgumentNullException(nameof(datacenters)); }
public void SetUp() { weight = 1.0; datacenters = Substitute.For <IDatacenters>(); modifier = new BoostLocalDatacentersModifier(datacenters, boostMultiplier, minimumWeightForBoosting); }
public void SubstituteWith(IDatacenters newDatacenters) => baseDatacenters = newDatacenters;
/// <summary> /// <para>Returns <c>true</c> if current local datacenter is among ones listed in result of <see cref="IDatacenters.GetActiveDatacenters"/>.</para> /// <para>Also returns <c>true</c> if local datacenter cannot be determined.</para> /// </summary> public static bool LocalDatacenterIsActive([NotNull] this IDatacenters datacenters) { var localDatacenter = datacenters.GetLocalDatacenter(); return(localDatacenter == null || datacenters.GetActiveDatacenters().Contains(localDatacenter)); }
private void LogLocalDatacenter(IDatacenters datacenters) => log.Info("Application datacenter: {DatacenterName}.", datacenters.GetLocalDatacenter() ?? "unknown");
/// <summary> /// Adds a <see cref="AvoidInactiveDatacentersModifier"/> that will apply zero weights for non-active datacenters. /// </summary> public static void SetupAvoidInactiveDatacentersWeightModifier( [NotNull] this IWeighedReplicaOrderingBuilder self, [NotNull] IDatacenters datacenters) { self.AddModifier(new AvoidInactiveDatacentersModifier(datacenters)); }