static Result <CacheServiceWrapperConfiguration> tryCreateConfiguration(DistributedCacheServiceArguments configuration) { var outOfProcSettings = configuration.Configuration.DistributedContentSettings.OutOfProcCacheSettings; if (outOfProcSettings is null) { return(Result.FromErrorMessage <CacheServiceWrapperConfiguration>($"{nameof(configuration.Configuration.DistributedContentSettings.OutOfProcCacheSettings)} should not be null.")); } if (outOfProcSettings.Executable is null) { return(Result.FromErrorMessage <CacheServiceWrapperConfiguration>($"{nameof(outOfProcSettings.Executable)} is null.")); } if (!File.Exists(outOfProcSettings.Executable)) { // This is not a bullet proof check, but if the executable is not found we should not even trying to create an out of proc cache service. return(Result.FromErrorMessage <CacheServiceWrapperConfiguration>($"the executable is not found at '{outOfProcSettings.Executable}'.")); } if (outOfProcSettings.CacheConfigPath is null) { return(Result.FromErrorMessage <CacheServiceWrapperConfiguration>($"{nameof(outOfProcSettings.CacheConfigPath)} is null.")); } if (!File.Exists(outOfProcSettings.CacheConfigPath)) { // This is not a bullet proof check, but if the executable is not found we should not even trying to create an out of proc cache service. return(Result.FromErrorMessage <CacheServiceWrapperConfiguration>($"the cache configuration is not found at '{outOfProcSettings.CacheConfigPath}'.")); } // The next layout should be in sync with CloudBuild. AbsolutePath executable = getExecutingPath() / outOfProcSettings.Executable; var workingDirectory = getRootPath(configuration.Configuration); var hostParameters = HostParameters.FromTelemetryProvider(configuration.TelemetryFieldsProvider); var resultingConfiguration = new CacheServiceWrapperConfiguration( serviceId: "OutOfProcCache", executable: executable, workingDirectory: workingDirectory, hostParameters: hostParameters, cacheConfigPath: new AbsolutePath(outOfProcSettings.CacheConfigPath), // DataRootPath is set in CloudBuild and we need to propagate this configuration to the launched process. dataRootPath: new AbsolutePath(configuration.Configuration.DataRootPath), useInterProcSecretsCommunication: outOfProcSettings.UseInterProcSecretsCommunication); outOfProcSettings.ServiceLifetimePollingIntervalSeconds.ApplyIfNotNull(v => resultingConfiguration.ServiceLifetimePollingInterval = TimeSpan.FromSeconds(v)); outOfProcSettings.ShutdownTimeoutSeconds.ApplyIfNotNull(v => resultingConfiguration.ShutdownTimeout = TimeSpan.FromSeconds(v)); return(resultingConfiguration); }
public CacheServiceWrapper(CacheServiceWrapperConfiguration configuration, ServiceLifetimeManager serviceLifetimeManager, RetrievedSecrets secrets) { _configuration = configuration; _serviceLifetimeManager = serviceLifetimeManager; _secrets = secrets; }