/// <inheritdoc /> public override string GetCommandLineArgs(LocalServerConfiguration localContentServerConfiguration = null, string scenario = null, bool logAutoFlush = false, bool passMaxConnections = false) { var args = new StringBuilder(base.GetCommandLineArgs(localContentServerConfiguration, scenario, logAutoFlush, false)); if (!string.IsNullOrEmpty(StampId)) { args.AppendFormat(" /stampId:{0}", StampId); } if (!string.IsNullOrEmpty(RingId)) { args.AppendFormat(" /ringId:{0}", RingId); } if (!string.IsNullOrEmpty(CacheName)) { args.AppendFormat(" /cacheName:{0}", CacheName); } if (CachePath != null) { args.AppendFormat(" /cachePath:{0}", CachePath.Path); } return(args.ToString()); }
/// <inheritdoc /> public override string GetCommandLineArgs(LocalServerConfiguration localContentServerConfiguration = null, string scenario = null, bool logAutoFlush = false, bool passMaxConnections = false) { var args = new StringBuilder(base.GetCommandLineArgs(localContentServerConfiguration, scenario, logAutoFlush, false)); args.AppendFormat(" /hashType:{0}", HashType.ToString()); args.AppendFormat(" /path:{0}", SourcePath.Path); return(args.ToString()); }
/// <nodoc /> public LocalContentServer( IAbsFileSystem fileSystem, ILogger logger, string scenario, Func <AbsolutePath, IContentStore> contentStoreFactory, LocalServerConfiguration localContentServerConfiguration) : base(logger, fileSystem, scenario, contentStoreFactory, localContentServerConfiguration) { _grpcContentServer = new GrpcContentServer(logger, Capabilities.ContentOnly, this, StoresByName, localContentServerConfiguration); }
/// <nodoc /> public LocalContentServer( IAbsFileSystem fileSystem, ILogger logger, string scenario, Func <AbsolutePath, IContentStore> contentStoreFactory, LocalServerConfiguration localContentServerConfiguration, IGrpcServiceEndpoint[]?additionalEndpoints = null, IColdStorage?coldStorage = null) : base(logger, fileSystem, scenario, contentStoreFactory, localContentServerConfiguration, additionalEndpoints) { GrpcContentServer = new GrpcContentServer(logger, Capabilities.ContentOnly, this, StoresByName, localContentServerConfiguration, coldStorage); }
/// <nodoc /> protected LocalContentServerBase( ILogger logger, IAbsFileSystem fileSystem, string scenario, Func <AbsolutePath, TStore> contentStoreFactory, LocalServerConfiguration localContentServerConfiguration, IGrpcServiceEndpoint[]?additionalEndpoints) { Contract.Requires(logger != null); Contract.Requires(fileSystem != null); Contract.Requires(localContentServerConfiguration != null); Contract.Requires(localContentServerConfiguration.GrpcPort > 0, "GrpcPort must be provided"); logger.Debug($"{Name} process id {Process.GetCurrentProcess().Id}"); logger.Debug($"{Name} constructing {nameof(ServiceConfiguration)}: {localContentServerConfiguration}"); GrpcEnvironment.Initialize(logger, localContentServerConfiguration.GrpcEnvironmentOptions, overwriteSafeOptions: true); FileSystem = fileSystem; Logger = logger; Config = localContentServerConfiguration; _additionalEndpoints = additionalEndpoints ?? Array.Empty <IGrpcServiceEndpoint>(); _serviceReadinessChecker = new ServiceReadinessChecker(logger, scenario); _sessionHandles = new ConcurrentDictionary <int, ISessionHandle <TSession, TSessionData> >(); var storesByName = new Dictionary <string, TStore>(); foreach (var kvp in localContentServerConfiguration.NamedCacheRoots) { fileSystem.CreateDirectory(kvp.Value); var store = contentStoreFactory(kvp.Value); storesByName.Add(kvp.Key, store); } StoresByName = new ReadOnlyDictionary <string, TStore>(storesByName); foreach (var kvp in localContentServerConfiguration.NamedCacheRoots) { _tempFolderForStreamsByCacheName[kvp.Key] = kvp.Value / "TempFolder"; } if (!string.IsNullOrEmpty(localContentServerConfiguration.GrpcPortFileName)) { var portSharingFactory = new MemoryMappedFileGrpcPortSharingFactory(logger, localContentServerConfiguration.GrpcPortFileName); var portExposer = portSharingFactory.GetPortExposer(); _portDisposer = portExposer.Expose(localContentServerConfiguration.GrpcPort); } }
/// <nodoc /> public LocalContentServer( IAbsFileSystem fileSystem, ILogger logger, string scenario, Func <AbsolutePath, IContentStore> contentStoreFactory, LocalServerConfiguration localContentServerConfiguration) : base(logger, fileSystem, scenario, contentStoreFactory, localContentServerConfiguration) { var nameByDrive = new Dictionary <string, string>(); foreach (var kvp in localContentServerConfiguration.NamedCacheRoots) { nameByDrive.Add(kvp.Value.DriveLetter.ToString(), kvp.Key); } _grpcContentServer = new GrpcContentServer(logger, Capabilities.ContentOnly, this, nameByDrive, StoresByName); }
private void InitializeAndStartGrpcServer(Context context, LocalServerConfiguration config) { GrpcCoreServerOptions?grpcCoreServerOptions = config.GrpcCoreServerOptions; GrpcEnvironment.WaitUntilInitialized(); bool?encryptionEnabled = grpcCoreServerOptions?.EncryptionEnabled; Tracer.Info(context, $"Grpc Encryption Enabled = {encryptionEnabled == true}, Encrypted GRPC Port: {config.EncryptedGrpcPort}, Unencrypted GRPC Port: {config.GrpcPort}"); _grpcServer = new Server(GrpcEnvironment.GetServerOptions(grpcCoreServerOptions)) { Ports = { new ServerPort(IPAddress.Any.ToString(), config.GrpcPort, ServerCredentials.Insecure) }, RequestCallTokensPerCompletionQueue = config.RequestCallTokensPerCompletionQueue, }; if (encryptionEnabled == true) { try { ServerCredentials?serverSSLCreds = TryGetEncryptedCredentials(context, grpcCoreServerOptions); if (serverSSLCreds != null) { _grpcServer.Ports.Add(new ServerPort(IPAddress.Any.ToString(), config.EncryptedGrpcPort, serverSSLCreds)); Tracer.Debug(context, $"Server creating Encrypted Grpc channel on port {config.EncryptedGrpcPort}"); } else { Tracer.Error(context, message: $"Failed to get SSL Credentials. Not creating encrypted Grpc channel."); } } catch (Exception ex) { Tracer.Error(context, ex, $"Creating SSL Secured Grpc Channel Failed."); } } foreach (var endpoint in GrpcEndpoints) { endpoint.BindServices(_grpcServer.Services); } _grpcServer.Start(); }
/// <summary> /// Initializes a new instance of the <see cref="ServiceProcess"/> class. /// </summary> public ServiceProcess ( ServiceConfiguration configuration, LocalServerConfiguration localContentServerConfiguration, string scenario, int waitForServerReadyTimeoutMs, int waitForExitTimeoutMs, bool logAutoFlush = true ) { Contract.Requires(configuration != null); _configuration = configuration; _localContentServerConfiguration = localContentServerConfiguration; _scenario = scenario; _waitForServerReadyTimeoutMs = waitForServerReadyTimeoutMs; _waitForExitTimeoutMs = waitForExitTimeoutMs; _logAutoFlush = logAutoFlush; }
/// <nodoc /> protected LocalContentServerBase( ILogger logger, IAbsFileSystem fileSystem, string scenario, Func <AbsolutePath, TStore> contentStoreFactory, LocalServerConfiguration localContentServerConfiguration) { Contract.Requires(logger != null); Contract.Requires(fileSystem != null); Contract.Requires(localContentServerConfiguration != null); Contract.Requires(localContentServerConfiguration.GrpcPort > 0, "GrpcPort must be provided"); logger.Debug($"{Name} process id {Process.GetCurrentProcess().Id}"); logger.Debug($"{Name} constructing {nameof(ServiceConfiguration)}: {localContentServerConfiguration}"); FileSystem = fileSystem; Logger = logger; Config = localContentServerConfiguration; _serviceReadinessChecker = new ServiceReadinessChecker(Tracer, logger, scenario); _sessionHandles = new ConcurrentDictionary <int, SessionHandle <TSession> >(); foreach (var kvp in localContentServerConfiguration.NamedCacheRoots) { fileSystem.CreateDirectory(kvp.Value); var store = contentStoreFactory(kvp.Value); StoresByName.Add(kvp.Key, store); } foreach (var kvp in localContentServerConfiguration.NamedCacheRoots) { _tempFolderForStreamsByCacheName[kvp.Key] = kvp.Value / "TempFolder"; } if (!string.IsNullOrEmpty(localContentServerConfiguration.GrpcPortFileName)) { var portSharingFactory = new MemoryMappedFileGrpcPortSharingFactory(logger, localContentServerConfiguration.GrpcPortFileName); var portExposer = portSharingFactory.GetPortExposer(); _portDisposer = portExposer.Expose(localContentServerConfiguration.GrpcPort); } }
/// <summary> /// Create the command line arguments to match this configuration. /// </summary> public virtual string GetCommandLineArgs(LocalServerConfiguration localContentServerConfiguration = null, string scenario = null, bool logAutoFlush = false, bool passMaxConnections = true) { var args = new StringBuilder(GetVerb()); if (passMaxConnections) { args.AppendFormat(" /maxConnections={0}", MaxConnections); } if (GrpcPort != ServiceConfiguration.GrpcDisabledPort) { args.AppendFormat(" /grpcPort={0}", GrpcPort); } if (GrpcPortFileName != null) { args.AppendFormat(" /grpcPortFileName={0}", GrpcPortFileName); } if (localContentServerConfiguration?.UnusedSessionTimeout != null) { args.AppendFormat(" /unusedSessionTimeoutSeconds={0}", localContentServerConfiguration.UnusedSessionTimeout.TotalSeconds); } if (localContentServerConfiguration?.UnusedSessionHeartbeatTimeout != null) { args.AppendFormat(" /unusedSessionHeartbeatTimeoutSeconds={0}", localContentServerConfiguration.UnusedSessionHeartbeatTimeout.TotalSeconds); } var namedCacheRoots = NamedCacheRoots; if (namedCacheRoots.Any()) { var sbNames = new StringBuilder(); var sbRoots = new StringBuilder(); foreach (var kvp in namedCacheRoots) { sbNames.AppendFormat(",{0}", kvp.Key); sbRoots.AppendFormat(",{0}", kvp.Value); } args.AppendFormat(" /names={0}", sbNames.ToString().TrimStart(',')); args.AppendFormat(" /paths={0}", sbRoots.ToString().TrimStart(',')); } if (DataRootPath != null) { args.AppendFormat(" /dataRootPath={0}", DataRootPath.Path); } if (scenario != null) { args.AppendFormat(" /scenario={0}", scenario); } if (logAutoFlush) { args.Append(" /logautoflush"); } return(args.ToString()); }
/// <nodoc /> public static async Task HibernateSessionsAsync( Context context, IDictionary <int, ISessionHandle <IContentSession, LocalContentServerSessionData> > sessionHandles, LocalServerConfiguration config, Tracer tracer, IAbsFileSystem fileSystem) { var sessionInfoList = new List <HibernatedContentSessionInfo>(sessionHandles.Count); foreach (var(sessionId, handle) in sessionHandles) { IContentSession session = handle.Session; if (session is IHibernateContentSession hibernateSession) { if (config.ShutdownEvictionBeforeHibernation) { // Calling shutdown of eviction before hibernating sessions to prevent possible race condition of evicting pinned content await hibernateSession.ShutdownEvictionAsync(context).ThrowIfFailure(); } var pinnedContentHashes = hibernateSession.EnumeratePinnedContentHashes().Select(x => x.Serialize()).ToList(); tracer.Debug(context, $"Hibernating session {handle.ToString(sessionId)}."); sessionInfoList.Add(new HibernatedContentSessionInfo( sessionId, handle.SessionData.Name, handle.SessionData.ImplicitPin, handle.CacheName, pinnedContentHashes, handle.SessionExpirationUtcTicks, handle.SessionData.Capabilities)); } else { tracer.Warning(context, $"Shutdown of non-hibernating dangling session. {sessionId.AsTraceableSessionId()}"); } await session.ShutdownAsync(context).ThrowIfFailure(); session.Dispose(); } if (sessionInfoList.Any()) { var hibernatedSessions = new HibernatedSessions <HibernatedContentSessionInfo>(sessionInfoList); try { var sw = Stopwatch.StartNew(); hibernatedSessions.Write(fileSystem, config.DataRootPath, HibernatedSessionsFileName); sw.Stop(); tracer.Debug( context, $"Wrote hibernated sessions to root=[{config.DataRootPath}] in {sw.Elapsed.TotalMilliseconds}ms"); } catch (Exception exception) { tracer.Error(context, exception, $"Failed to write hibernated sessions root=[{config.DataRootPath}]"); } } }