示例#1
0
        /// <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);
            }
        }
        private void InitializeAndStartGrpcServer(int grpcPort, ServerServiceDefinition[] definitions, int requestCallTokensPerCompletionQueue, GrpcCoreServerOptions?grpcCoreServerOptions)
        {
            Contract.Requires(definitions.Length != 0);

            GrpcEnvironment.WaitUntilInitialized();
            _grpcServer = new Server(GrpcEnvironment.GetServerOptions(grpcCoreServerOptions))
            {
                Ports = { new ServerPort(IPAddress.Any.ToString(), grpcPort, ServerCredentials.Insecure) },
                RequestCallTokensPerCompletionQueue = requestCallTokensPerCompletionQueue,
            };

            foreach (var definition in definitions)
            {
                _grpcServer.Services.Add(definition);
            }

            _grpcServer.Start();
        }
示例#3
0
        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();
        }
        private void InitializeAndStartGrpcServer(int grpcPort, ServerServiceDefinition[] definitions, int requestCallTokensPerCompletionQueue)
        {
            Contract.Requires(definitions.Length != 0);
            GrpcEnvironment.InitializeIfNeeded();
            _grpcServer = new Server(GrpcEnvironment.DefaultConfiguration)
            {
                Ports = { new ServerPort(IPAddress.Any.ToString(), grpcPort, ServerCredentials.Insecure) },

                // need a higher number here to avoid throttling: 7000 worked for initial experiments.
                RequestCallTokensPerCompletionQueue = requestCallTokensPerCompletionQueue,
            };

            foreach (var definition in definitions)
            {
                _grpcServer.Services.Add(definition);
            }

            _grpcServer.Start();
        }
示例#5
0
        internal GrpcCopyClient(Context context, GrpcCopyClientKey key, GrpcCopyClientConfiguration configuration, IClock?clock = null, ByteArrayPool?sharedBufferPool = null)
        {
            Key            = key;
            _configuration = configuration;
            _clock         = clock ?? SystemClock.Instance;

            GrpcEnvironment.WaitUntilInitialized();
            var  channelCreds      = ChannelCredentials.Insecure;
            bool?encryptionEnabled = _configuration.GrpcCoreClientOptions?.EncryptionEnabled;

            Tracer.Info(context, $"Grpc Encryption Enabled = {encryptionEnabled == true}, GRPC Port: {key.GrpcPort}");

            List <ChannelOption> options = new List <ChannelOption>(GrpcEnvironment.GetClientOptions(_configuration.GrpcCoreClientOptions));

            if (encryptionEnabled == true)
            {
                try
                {
                    channelCreds = TryGetSecureChannelCredentials(context, _configuration, out var hostName) ?? ChannelCredentials.Insecure;
                    if (channelCreds != ChannelCredentials.Insecure)
                    {
                        options.Add(new ChannelOption(ChannelOptions.SslTargetNameOverride, hostName));
                    }
                }
                catch (Exception ex)
                {
                    Tracer.Error(context, ex, $"Creating Encrypted Grpc Channel Failed.");
                }
            }

            Tracer.Debug(context, $"Client connecting to {key.Host}:{key.GrpcPort}. Channel Encrypted = {channelCreds != ChannelCredentials.Insecure}");

            _channel = new Channel(key.Host, key.GrpcPort, channelCreds, options: options);
            _client  = new ContentServer.ContentServerClient(_channel);

            _bandwidthChecker = new BandwidthChecker(_configuration.BandwidthCheckerConfiguration);
            _pool             = sharedBufferPool ?? new ByteArrayPool(_configuration.ClientBufferSizeBytes);
        }
示例#6
0
        protected GrpcClientBase(
            IAbsFileSystem fileSystem,
            ServiceClientContentSessionTracer tracer,
            ServiceClientRpcConfiguration configuration,
            string?scenario,
            Capabilities clientCapabilities)
        {
            FileSystem          = fileSystem;
            ServiceClientTracer = tracer;
            Configuration       = configuration;
            Scenario            = scenario;
            _clientCapabilities = clientCapabilities;

            GrpcEnvironment.WaitUntilInitialized();
            Channel = new Channel(configuration.GrpcHost, configuration.GrpcPort, ChannelCredentials.Insecure, GrpcEnvironment.GetClientOptions(configuration.GrpcCoreClientOptions));
        }
示例#7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GrpcRepairClient" /> class.
 /// </summary>
 public GrpcRepairClient(uint grpcPort)
 {
     GrpcEnvironment.InitializeIfNeeded();
     _channel = new Channel(GrpcEnvironment.Localhost, (int)grpcPort, ChannelCredentials.Insecure);
     _client  = new ContentServer.ContentServerClient(_channel);
 }
示例#8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GrpcCopyClient" /> class.
 /// </summary>
 private GrpcCopyClient(Channel channel)
 {
     GrpcEnvironment.InitializeIfNeeded();
     _client = new ContentServer.ContentServerClient(channel);
 }
示例#9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GrpcCopyClient" /> class.
 /// </summary>
 public GrpcCopyClient(string host, int grpcPort)
 {
     GrpcEnvironment.InitializeIfNeeded();
     _channel = new Channel(host, grpcPort, ChannelCredentials.Insecure);
     _client  = new ContentServer.ContentServerClient(_channel);
 }
示例#10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GrpcCopyClient" /> class.
 /// </summary>
 private GrpcCopyClient(Channel channel, bool useCompression)
 {
     GrpcEnvironment.InitializeIfNeeded();
     _client         = new ContentServer.ContentServerClient(channel);
     _useCompression = useCompression;
 }
示例#11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GrpcRepairClient" /> class.
 /// </summary>
 public GrpcRepairClient(uint grpcPort)
 {
     GrpcEnvironment.WaitUntilInitialized();
     _channel = new Channel(GrpcEnvironment.LocalHost, (int)grpcPort, ChannelCredentials.Insecure, GrpcEnvironment.GetClientOptions());
     _client  = new ContentServer.ContentServerClient(_channel);
 }