/// <nodoc /> public DeploymentProxyService( ProxyServiceConfiguration configuration, HostParameters hostParameters, IAbsFileSystem fileSystem = null, IClock clock = null, IDeploymentServiceClient client = null) { clock ??= SystemClock.Instance; Configuration = configuration; Root = new AbsolutePath(configuration.RootPath); Clock = clock; ContentCacheRequests = new VolatileMap <(string, string), AsyncLazy <BoolResult> >(Clock); ProxyAddress = new VolatileMap <UnitValue, AsyncLazy <string> >(Clock); Client = client ?? DeploymentLauncherHost.Instance.CreateServiceClient(); HostParameters = hostParameters; DownloadQueue = new ActionQueue(configuration.DownloadConcurrency ?? Environment.ProcessorCount); Store = new FileSystemContentStoreInternal( fileSystem ?? new PassThroughFileSystem(), Clock, DeploymentUtilities.GetCasRootPath(Root), new ConfigurationModel(new ContentStoreConfiguration(new MaxSizeQuota($"{Configuration.RetentionSizeGb}GB"))), settings: new ContentStoreSettings() { TraceFileSystemContentStoreDiagnosticMessages = true, }); }
/// <summary> /// Loads a configuration object from preprocessed json /// </summary> public static TConfig LoadPreprocessedConfig <TConfig>(string configurationPath, out string configHash, HostParameters hostParameters = null) { hostParameters ??= HostParameters.FromEnvironment(); var configJson = File.ReadAllText(configurationPath); configHash = HashInfoLookup.GetContentHasher(HashType.Murmur).GetContentHash(Encoding.UTF8.GetBytes(configJson)).ToHex(); var preprocessor = DeploymentUtilities.GetHostJsonPreprocessor(hostParameters); var preprocessedConfigJson = preprocessor.Preprocess(configJson); var config = JsonSerializer.Deserialize <TConfig>(preprocessedConfigJson, DeploymentUtilities.ConfigurationSerializationOptions); return(config); }
/// <summary> /// Loads a configuration object from preprocessed json and watches files for changes. /// When result config value changes, teardown will be requested. /// </summary> public static TResultConfig LoadAndWatchPreprocessedConfig <TConfig, TResultConfig>( OperationContext context, string configurationPath, HostParameters hostParameters, out string configHash, Func <TConfig, TResultConfig> extractConfig, Action <Context, string> requestTeardown = null, TimeSpan?pollingInterval = null) { requestTeardown ??= (context, reason) => LifetimeManager.RequestTeardown(context, reason); pollingInterval ??= TimeSpan.FromSeconds(5); var config = LoadPreprocessedConfig <TConfig>(configurationPath, out configHash, hostParameters); var resultConfig = extractConfig(config); var resultConfigString = JsonSerializer.Serialize(resultConfig); DeploymentUtilities.WatchFileAsync( configurationPath, context.Token, pollingInterval.Value, onChanged: () => { var newConfig = LoadPreprocessedConfig <TConfig>(configurationPath, out _, hostParameters); var newResultConfig = extractConfig(newConfig); var newResultConfigString = JsonSerializer.Serialize(resultConfig); if (newResultConfigString != resultConfigString) { resultConfigString = newResultConfigString; requestTeardown(context, "Configuration changed: " + configurationPath); } }, onError: ex => { requestTeardown(context, "Error: " + ex.ToString()); }); return(resultConfig); }