public ConfigurationLocationsParser(IFileSystem fileSystemInstance, IEnvironmentVariableProvider environmentVariableProvider) { AppName = CurrentApplicationInfo.Name; environmentVariableProvider.SetEnvironmentVariableForProcess("AppName", CurrentApplicationInfo.Name); ConfigRoot = environmentVariableProvider.GetEnvironmentVariable(HS_CONFIG_ROOT); if (string.IsNullOrEmpty(ConfigRoot)) { ConfigRoot = environmentVariableProvider.PlatformSpecificPathPrefix + HS_CONFIG_ROOT_DEFAULT; } LoadPathsFilePath = environmentVariableProvider.GetEnvironmentVariable(HS_CONFIG_PATHS_FILE); if (string.IsNullOrEmpty(LoadPathsFilePath)) { LoadPathsFilePath = Path.Combine(ConfigRoot, LOADPATHS_JSON); } //Normalize slashes LoadPathsFilePath = LoadPathsFilePath.Replace("\\", "/"); Trace.WriteLine("Started parsing configurations from location " + LoadPathsFilePath + "\n"); var configPathDeclarations = ParseAndValidateConfigLines(LoadPathsFilePath, fileSystemInstance); ConfigFileDeclarations = ExpandConfigPathDeclarations(environmentVariableProvider, configPathDeclarations, environmentVariableProvider.PlatformSpecificPathPrefix).ToArray(); }
public MetricsInitializer(ILog log, IMetricsSettings metricsSettings, HealthMonitor healthMonitor, IEnvironmentVariableProvider envProvider) { MetricsSettings = metricsSettings; HealthMonitor = healthMonitor; Log = log; EnvProvider = envProvider; }
public ConsulClient(string serviceName, Func <ConsulConfig> getConfig, ISourceBlock <ConsulConfig> configChanged, IEnvironmentVariableProvider environmentVariableProvider, ILog log, IDateTime dateTime, Func <string, AggregatingHealthStatus> getAggregatedHealthStatus) { _serviceName = serviceName; GetConfig = getConfig; _dateTime = dateTime; Log = log; DataCenter = environmentVariableProvider.DataCenter; _waitForConfigChange = new TaskCompletionSource <bool>(); configChanged.LinkTo(new ActionBlock <ConsulConfig>(ConfigChanged)); var address = environmentVariableProvider.ConsulAddress ?? $"{CurrentApplicationInfo.HostName}:8500"; ConsulAddress = new Uri($"http://{address}"); _httpClient = new HttpClient { BaseAddress = ConsulAddress, Timeout = getConfig().HttpTimeout }; _aggregatedHealthStatus = getAggregatedHealthStatus("ConsulClient"); _resultChanged = new BufferBlock <EndPointsResult>(); _initializedVersion = new TaskCompletionSource <bool>(); ShutdownToken = new CancellationTokenSource(); Task.Run(LoadVersionLoop); Task.Run(LoadEndpointsLoop); }
/// <summary> /// Constructor for the 'FileBasedConfigItemsSource' class /// </summary> /// <param name="configurationLocations">Encapsulates the retrieval of all configuration location behavior</param> /// <param name="environmentVariableProvider">Encapsulates the retrieval of all environment variables</param> /// <param name="fileSystem">Encapsulates the file system behavior</param> /// <param name="configDecryptor">Encapsulates the decryption behavior for a config item</param> public FileBasedConfigItemsSource(IConfigurationLocationsParser configurationLocations, IEnvironmentVariableProvider environmentVariableProvider, IFileSystem fileSystem, ConfigDecryptor configDecryptor) { _configurationLocations = configurationLocations; _environmentVariableProvider = environmentVariableProvider; _fileSystem = fileSystem; _configDecryptor = configDecryptor; }
public void SetUp() { _unitTestingKernel?.Dispose(); _serviceName = $"ServiceName{++id}"; _environmentVariableProvider = Substitute.For <IEnvironmentVariableProvider>(); _environmentVariableProvider.DataCenter.Returns("il3"); _environmentVariableProvider.DeploymentEnvironment.Returns(ORIGINATING_ENVIRONMENT); _configDic = new Dictionary <string, string> { { "Discovery.EnvironmentFallbackEnabled", "true" } }; _unitTestingKernel = new TestingKernel <ConsoleLog>(k => { k.Rebind <IEnvironmentVariableProvider>().ToConstant(_environmentVariableProvider); k.Rebind <IDiscoverySourceLoader>().To <DiscoverySourceLoader>().InSingletonScope(); SetupConsulClientMocks(); k.Rebind <Func <string, IConsulClient> >().ToMethod(_ => (s => _consulClients[s])); _dateTimeMock = Substitute.For <IDateTime>(); _dateTimeMock.Delay(Arg.Any <TimeSpan>()).Returns(c => Task.Delay(TimeSpan.FromMilliseconds(100))); k.Rebind <IDateTime>().ToConstant(_dateTimeMock); }, _configDic); _configRefresh = _unitTestingKernel.Get <ManualConfigurationEvents>(); var environmentVariableProvider = _unitTestingKernel.Get <IEnvironmentVariableProvider>(); Assert.AreEqual(_environmentVariableProvider, environmentVariableProvider); }
public void Setup() { _environmentVariableProvider = Substitute.For <IEnvironmentVariableProvider>(); _environmentVariableProvider.DataCenter.Returns("il3"); _environmentVariableProvider.DeploymentEnvironment.Returns(ORIGINATING_ENVIRONMENT); _configDic = new Dictionary <string, string> { { "Discovery.EnvironmentFallbackEnabled", "true" } }; _unitTestingKernel = new TestingKernel <ConsoleLog>(k => { k.Rebind <IEnvironmentVariableProvider>().ToConstant(_environmentVariableProvider); k.Rebind <IDiscoverySourceLoader>().To <DiscoverySourceLoader>().InSingletonScope(); _consulAdapterMock = Substitute.For <IConsulClient>(); _consulAdapterMock.GetEndPoints(Arg.Any <string>()).Returns(Task.FromResult(new EndPointsResult { EndPoints = new[] { new ConsulEndPoint { HostName = "dumy" } } })); k.Rebind <IConsulClient>().ToConstant(_consulAdapterMock); }, _configDic); _configRefresh = _unitTestingKernel.Get <ManualConfigurationEvents>(); var environmentVariableProvider = _unitTestingKernel.Get <IEnvironmentVariableProvider>(); Assert.AreEqual(_environmentVariableProvider, environmentVariableProvider); }
public EventSerializer(Func <EventConfiguration> loggingConfigFactory, IEnvironmentVariableProvider envProvider, IStackTraceEnhancer stackTraceEnhancer, Func <EventConfiguration> eventConfig) { LoggingConfigFactory = loggingConfigFactory; EnvProvider = envProvider; StackTraceEnhancer = stackTraceEnhancer; EventConfig = eventConfig; }
/// <summary> /// 注册一个环境变量提供程序 /// </summary> /// <param name="provider"></param> public static void RegisterProvider(IEnvironmentVariableProvider provider) { if (provider == null) { throw new ArgumentNullException("provider"); } _providers.Add(provider); }
public MetricsInitializer(ILog log, IConfiguration configuration, IMetricsSettings metricsSettings, HealthMonitor healthMonitor, IEnvironmentVariableProvider envProvider, CurrentApplicationInfo appInfo) { Configuration = configuration; MetricsSettings = metricsSettings; HealthMonitor = healthMonitor; Log = log; EnvProvider = envProvider; AppInfo = appInfo; }
public void SetUp() { _fileSystem = Substitute.For <IFileSystem>(); _fileSystem.ReadAllTextFromFile(Arg.Any <string>()).Returns(a => testData); _fileSystem.Exists(Arg.Any <string>()).Returns(a => true); environmentVariableProvider = Substitute.For <IEnvironmentVariableProvider>(); environmentVariableProvider.PlatformSpecificPathPrefix.Returns("c:"); }
private List <ConfigFileDeclaration> ExpandConfigPathDeclarations(IEnvironmentVariableProvider environmentVariableProvider, ConfigFileDeclaration[] configs, string prefix) { var configPathsSet = new SortedSet <ConfigFileDeclaration>(configs); var toSave = new List <ConfigFileDeclaration>(); var listOfErrors = new List <ErrorAggregator>(); foreach (var configPath in configPathsSet) { configPath.Pattern = configPath.Pattern.Replace("$(prefix)", prefix); var list = Regex.Matches(configPath.Pattern, "%([^%]+)%") .Cast <Match>() .Select(match => new { Placehodler = match.Groups[0].Value, Value = environmentVariableProvider.GetEnvironmentVariable(match.Groups[1].Value) }).ToList(); var missingEnvVariables = list.Where(a => string.IsNullOrEmpty(a.Value)).Select(a => a.Placehodler.Trim('%')).ToList(); if (missingEnvVariables.Any()) { listOfErrors.Add(new ErrorAggregator { Line = configPath.Pattern, EnvVariables = missingEnvVariables }); } else { foreach (var valToReplace in list) { configPath.Pattern = configPath.Pattern.Replace(valToReplace.Placehodler, valToReplace.Value); } configPath.Pattern = configPath.Pattern.Replace("\\", "/"); //Assumes $(appName) present only once. if (Regex.Match(configPath.Pattern, @"/?[^$/]*\$\(appName\)").Success) { configPath.Pattern = configPath.Pattern.Replace("$(appName)", AppName); } toSave.Add(configPath); Trace.WriteLine(configPath.Pattern + " priority=" + configPath.Priority + " " + SearchOption.TopDirectoryOnly); } } if (listOfErrors.Any()) { var errorMessage = PrepareErrorMessage(listOfErrors); throw new ConfigurationException(errorMessage); } return(toSave); }
/// <summary> /// Creates an instance of <see cref="ConfigManager"/>. /// </summary> /// <param name="configFilePath">Path to the config file.</param> /// <param name="dataStore">Provider of file system APIs.</param> /// <param name="environmentVariableProvider">Provider of environment variable APIs.</param> internal ConfigManager(string configFilePath, IDataStore dataStore, IEnvironmentVariableProvider environmentVariableProvider) { _ = dataStore ?? throw new AzPSArgumentNullException($"{nameof(dataStore)} cannot be null.", nameof(dataStore)); _ = configFilePath ?? throw new AzPSArgumentNullException($"{nameof(configFilePath)} cannot be null.", nameof(configFilePath)); _ = environmentVariableProvider ?? throw new AzPSArgumentNullException($"{nameof(environmentVariableProvider)} cannot be null.", nameof(environmentVariableProvider)); ConfigFilePath = configFilePath; _environmentVariableProvider = environmentVariableProvider; _dataStore = dataStore; _jsonConfigHelper = new JsonConfigHelper(ConfigFilePath, _dataStore); }
public ConfigurationResponseBuilder(ConfigCache configCache, IEnvironmentVariableProvider envs, IAssemblyProvider assemblyProvider, UsageTracking usageTracking) { UsageTracking = usageTracking; ConfigCache = configCache; Envs = envs; AssemblyProvider = assemblyProvider; }
public void MasterShouldNotFallBack() { _environmentVariableProvider = Substitute.For <IEnvironmentVariableProvider>(); _environmentVariableProvider.DataCenter.Returns("il3"); _environmentVariableProvider.DeploymentEnvironment.Returns(MASTER_ENVIRONMENT); _unitTestingKernel.Rebind <IEnvironmentVariableProvider>().ToConstant(_environmentVariableProvider); SetMockToReturnQueryNotFound(_masterService); Should.Throw <EnvironmentException>(() => GetServiceDiscovey.GetNextHost()); }
/// <summary> /// Parses the content of environment variables file content. /// </summary> public EnvironmentVariablesFileReader(IFileSystem fileSystem, IEnvironmentVariableProvider environmentVariableProvider) { locEnvFilePath = environmentVariableProvider.GetEnvironmentVariable(HS_ENV_VARS_FILE); if (string.IsNullOrEmpty(locEnvFilePath)) { locEnvFilePath = string.Format(ENV_FILEPATH, environmentVariableProvider.PlatformSpecificPathPrefix); } EnvironmentVariableProvider = environmentVariableProvider; FileSystem = fileSystem; }
public ConsulClient(IEnvironmentVariableProvider environmentVariableProvider, ILog log, HealthMonitor healthMonitor) { Log = log; DataCenter = environmentVariableProvider.DataCenter; var address = environmentVariableProvider.ConsulAddress ?? $"{CurrentApplicationInfo.HostName}:8500"; ConsulAddress = new Uri($"http://{address}"); _httpClient = new HttpClient { BaseAddress = ConsulAddress, Timeout = TimeSpan.FromSeconds(5) }; healthMonitor.SetHealthFunction("ConsulClient", HealthCheck); }
public EnvironmentInstance(IEnvironmentVariableProvider environmentVariableProvider, Func <DataCentersConfig> getDataCentersConfig) { _environmentVariableProvider = environmentVariableProvider; GetDataCentersConfig = getDataCentersConfig; Zone = environmentVariableProvider.GetEnvironmentVariable("ZONE") ?? environmentVariableProvider.GetEnvironmentVariable("DC"); _region = environmentVariableProvider.GetEnvironmentVariable("REGION"); DeploymentEnvironment = environmentVariableProvider.GetEnvironmentVariable("ENV"); ConsulAddress = environmentVariableProvider.GetEnvironmentVariable("CONSUL"); if (string.IsNullOrEmpty(Zone) || string.IsNullOrEmpty(DeploymentEnvironment)) { throw new EnvironmentException("One or more of the following environment variables, which are required, have not been set: %ZONE%, %ENV%"); } }
public EnvironmentInstance(IEnvironmentVariableProvider environmentVariableProvider, Func <DataCentersConfig> getDataCentersConfig, CurrentApplicationInfo applicationInfo) { _environmentVariableProvider = environmentVariableProvider; GetDataCentersConfig = getDataCentersConfig; Zone = environmentVariableProvider.GetEnvironmentVariable("ZONE") ?? environmentVariableProvider.GetEnvironmentVariable("DC"); _region = environmentVariableProvider.GetEnvironmentVariable("REGION"); DeploymentEnvironment = environmentVariableProvider.GetEnvironmentVariable("ENV"); ConsulAddress = environmentVariableProvider.GetEnvironmentVariable("CONSUL"); InstanceName = applicationInfo.InstanceName ?? environmentVariableProvider.GetEnvironmentVariable("GIGYA_SERVICE_INSTANCE_NAME") ?? DEFAULT_INSTANCE_NAME; if (string.IsNullOrEmpty(Zone) || string.IsNullOrEmpty(DeploymentEnvironment)) { throw new EnvironmentException("One or more of the following environment variables, which are required, have not been set: %ZONE%, %ENV%"); } }
public void SetupConsulListener() { _consulSimulator = new ConsulSimulator(ConsulPort); _testingKernel = new TestingKernel <ConsoleLog>(k => { _environmentVariableProvider = Substitute.For <IEnvironmentVariableProvider>(); _environmentVariableProvider.ConsulAddress.Returns($"{CurrentApplicationInfo.HostName}:{ConsulPort}"); _environmentVariableProvider.DataCenter.Returns(DataCenter); k.Rebind <IEnvironmentVariableProvider>().ToMethod(_ => _environmentVariableProvider); k.Rebind <IDateTime>().ToMethod(_ => _dateTimeFake); k.Rebind <Func <ConsulConfig> >().ToMethod(_ => () => _consulConfig); }); }
public HttpServiceListener(IActivator activator, IWorker worker, IServiceEndPointDefinition serviceEndPointDefinition, ICertificateLocator certificateLocator, ILog log, IEventPublisher <ServiceCallEvent> eventPublisher, IEnumerable <ICustomEndpoint> customEndpoints, IEnvironmentVariableProvider environmentVariableProvider, IServerRequestPublisher serverRequestPublisher, JsonExceptionSerializer exceptionSerializer, Func <LoadShedding> loadSheddingConfig) { _serverRequestPublisher = serverRequestPublisher; ServiceEndPointDefinition = serviceEndPointDefinition; Worker = worker; Activator = activator; Log = log; EventPublisher = eventPublisher; CustomEndpoints = customEndpoints.ToArray(); EnvironmentVariableProvider = environmentVariableProvider; ExceptionSerializer = exceptionSerializer; LoadSheddingConfig = loadSheddingConfig; if (serviceEndPointDefinition.UseSecureChannel) { ServerRootCertHash = certificateLocator.GetCertificate("Service").GetHashOfRootCertificate(); } var urlPrefixTemplate = ServiceEndPointDefinition.UseSecureChannel ? "https://+:{0}/" : "http://+:{0}/"; Prefix = string.Format(urlPrefixTemplate, ServiceEndPointDefinition.HttpPort); Listener = new HttpListener { IgnoreWriteExceptions = true, Prefixes = { Prefix } }; var context = Metric.Context("Service").Context(CurrentApplicationInfo.Name); _serializationTime = context.Timer("Serialization", Unit.Calls); _deserializationTime = context.Timer("Deserialization", Unit.Calls); _roundtripTime = context.Timer("Roundtrip", Unit.Calls); _metaEndpointsRoundtripTime = context.Timer("MetaRoundtrip", Unit.Calls); _successCounter = context.Counter("Success", Unit.Calls); _failureCounter = context.Counter("Failed", Unit.Calls); _activeRequestsCounter = context.Timer("ActiveRequests", Unit.Requests); _endpointContext = context.Context("Endpoints"); }
/// <summary> /// Performs discovery of services in the silo and populates the class' static members with information about them. /// </summary> public ClusterIdentity(ServiceArguments serviceArguments, ILog log, IEnvironmentVariableProvider environmentVariableProvider) { if (serviceArguments.SiloClusterMode != SiloClusterMode.ZooKeeper) { return; } string dc = environmentVariableProvider.DataCenter; string env = environmentVariableProvider.DeploymentEnvironment; var serviceIdSourceString = string.Join("_", dc, env, CurrentApplicationInfo.Name, CurrentApplicationInfo.InstanceName); ServiceId = Guid.Parse(serviceIdSourceString.GetHashCode().ToString("X32")); DeploymentId = serviceIdSourceString + "_" + CurrentApplicationInfo.Version; log.Info(_ => _("Orleans Cluster Identity Information (see tags)", unencryptedTags: new { OrleansDeploymentId = DeploymentId, OrleansServiceId = ServiceId, serviceIdSourceString })); }
public ServiceDiscovery(string serviceName, ReachabilityChecker reachabilityChecker, IRemoteHostPoolFactory remoteHostPoolFactory, IDiscoverySourceLoader discoverySourceLoader, IEnvironmentVariableProvider environmentVariableProvider, ISourceBlock <DiscoveryConfig> configListener, Func <DiscoveryConfig> discoveryConfigFactory) { _serviceName = serviceName; _originatingDeployment = new ServiceDeployment(serviceName, environmentVariableProvider.DeploymentEnvironment); _masterDeployment = new ServiceDeployment(serviceName, MASTER_ENVIRONMENT); _reachabilityChecker = reachabilityChecker; _remoteHostPoolFactory = remoteHostPoolFactory; _discoverySourceLoader = discoverySourceLoader; // Must be run in Task.Run() because of incorrect Orleans scheduling _initTask = Task.Run(() => ReloadRemoteHost(discoveryConfigFactory())); _configBlockLink = configListener.LinkTo(new ActionBlock <DiscoveryConfig>(ReloadRemoteHost)); }
/// <summary> /// Performs discovery of services in the silo and populates the class' static members with information about them. /// </summary> public ClusterIdentity(ServiceArguments serviceArguments, ILog log, IEnvironmentVariableProvider environmentVariableProvider) { if (serviceArguments.SiloClusterMode != SiloClusterMode.ZooKeeper) { return; } string dc = environmentVariableProvider.DataCenter; string env = environmentVariableProvider.DeploymentEnvironment; if (dc == null || env == null) { throw new EnvironmentException("One or more of the following environment variables, which are required when running with ZooKeeper, have not been set: %DC%, %ENV%"); } var serviceIdSourceString = string.Join("_", dc, env, CurrentApplicationInfo.Name, CurrentApplicationInfo.InstanceName); ServiceId = Guid.Parse(serviceIdSourceString.GetHashCode().ToString("X32")); DeploymentId = serviceIdSourceString + "_" + CurrentApplicationInfo.Version; log.Info(_ => _("Orleans Cluster Identity Information (see tags)", unencryptedTags: new { OrleansDeploymentId = DeploymentId, OrleansServiceId = ServiceId, serviceIdSourceString })); }
public VariableHelperBuilder() { _environmentVariableProvider = new StubEnvironmentVariableProvider(); }
public VariableHelperBuilder WithEnvironmentVariableProvider(IEnvironmentVariableProvider environmentVariableProvider) { _environmentVariableProvider = environmentVariableProvider; return(this); }
public StackTraceEnhancer(Func <StackTraceCleanerSettings> getConfig, IEnvironmentVariableProvider environmentVariableProvider) { GetConfig = getConfig; EnvironmentVariableProvider = environmentVariableProvider; }
/// <summary> /// Adds an environment variable provider /// </summary> /// <param name="provider"></param> public EnvironmentOptions AddProvider(IEnvironmentVariableProvider provider) { VariableProviders.Add(provider); return(this); }
public VariableHelper(IEnvironmentVariableProvider environmentVariableProvider) { _environmentVariableProvider = environmentVariableProvider; }
public EnvironmentVariablesConfigurationProvider(string id, EnvironmentVariablesConfigurationOptions options) : base(id) { _environmentVariableTarget = options.EnvironmentVariableTarget; _environmentVariableNameToKeyMapping = options.EnvironmentVariableToKeyMap ?? new Dictionary <string, string>(); _environmentVariableProvider = options.EnvironmentVariableProvider; }
public LogEventPublisher(ILog log, IEnvironmentVariableProvider envProvider) { Log = log; EnvProvider = envProvider; }