コード例 #1
0
    /// <summary>
    /// Configures a scoped host that serves gRPC endpoints of the specified <see cref="EndpointVisibility"/> using Kestrel.
    /// </summary>
    /// <param name="builder">The host builder to add a scoped host to.</param>
    /// <param name="visibility">The endpoint visibility to serve endpoints for.</param>
    /// <returns>The builder for continuation.</returns>
    public static IHostBuilder AddGrpcHost(this IHostBuilder builder, EndpointVisibility visibility)
    => builder
    .AddGrpcEndpointHealthCheck(visibility)
    .AddScopedHost(_ => _.ConfigureWebHost(grpcHost =>
    {
        grpcHost.UseKestrel();

        grpcHost.ConfigureServices(services =>
        {
            services.AddKestrelConfigurationFor(visibility);
            services.AddGrpc();
            services.AddGrpcReflection();
        });

        grpcHost.Configure(app =>
        {
            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapDiscoveredGrpcServicesOf(visibility);
                endpoints.MapGrpcReflectionService();
                endpoints.MapGrpcService <HealthService>();
            });
        });
    }));
コード例 #2
0
        /// <inheritdoc/>
        public void Start(EndpointVisibility type, EndpointConfiguration configuration, IEnumerable <Service> services)
        {
            try
            {
                var keepAliveTime         = new grpc.ChannelOption("grpc.keepalive_time", 1000);
                var keepAliveTimeout      = new grpc.ChannelOption("grpc.keepalive_timeout_ms", 500);
                var keepAliveWithoutCalls = new grpc.ChannelOption("grpc.keepalive_permit_without_calls", 1);
                _server = new grpc::Server(new[] {
                    keepAliveTime,
                    keepAliveTimeout,
                    keepAliveWithoutCalls
                })
                {
                    Ports =
                    {
                        new grpc.ServerPort("0.0.0.0", configuration.Port, grpc::SslServerCredentials.Insecure)
                    }
                };

                _server
                .Ports
                .ForEach(_ =>
                         _logger.Information($"Starting {type} host on {_.Host}" + (_.Port > 0 ? $" for port {_.Port}" : string.Empty)));

                services.ForEach(_ => _server.Services.Add(_.ServerDefinition));

                _server.Start();
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"Couldn't start {type} host");
            }
        }
コード例 #3
0
 public static void AddKestrelConfigurationFor(this IServiceCollection services, EndpointVisibility visibility)
 {
     services.AddSingleton <IConfigureOptions <KestrelServerOptions> >(_ =>
                                                                       new KestrelConfiguration(
                                                                           _.GetRequiredService <IOptions <EndpointsConfiguration> >(),
                                                                           visibility));
 }
コード例 #4
0
 /// <inheritdoc />
 public void MapServicesForVisibility(IEndpointRouteBuilder endpoints, EndpointVisibility visibility)
 {
     foreach (var service in _services.Where(_ => _.Visibility == visibility))
     {
         _logger.MappingDiscoveredGrpcService(service.ImplementationType, visibility);
         MapDynamicGrpcService(endpoints, service.ImplementationType);
     }
 }
コード例 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Client"/> class.
        /// </summary>
        /// <param name="visibility">The <see cref="EndpointVisibility"/> of the hosted <see cref="Endpoint"/>.</param>
        /// <param name="type"><see cref="Type"/> of <see cref="ClientBase">client</see>.</param>
        /// <param name="serviceDescriptor"><see cref="ServiceDescriptor"/> for the service the <see cref="Client"/> is for.</param>
        public Client(EndpointVisibility visibility, Type type, ServiceDescriptor serviceDescriptor)
        {
            ThrowIfTypeDoesNotImplementClientBase(type);

            Visibility        = visibility;
            Type              = type;
            ServiceDescriptor = serviceDescriptor;
        }
コード例 #6
0
        IEndpoint GetEndpointFor(EndpointVisibility type)
        {
            if (_endpoints.ContainsKey(type))
            {
                return(_endpoints[type]);
            }
            var endpoint = _container.Get <IEndpoint>();

            _endpoints[type] = endpoint;
            return(endpoint);
        }
コード例 #7
0
 internal static partial void PreparingEndpoint(ILogger logger, EndpointVisibility visibilityType, int port);
コード例 #8
0
 public KestrelConfiguration(IOptions <EndpointsConfiguration> configuration, EndpointVisibility visibility)
 {
     _configuration = configuration.Value.GetConfigurationFor(visibility);
 }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of <see cref="EndpointInfo"/>
 /// </summary>
 /// <param name="visibility"><see cref="EndpointVisibility">Type</see> of endpoint</param>
 /// <param name="configuration"><see cref="EndpointConfiguration">Configuration</see> for the endoint</param>
 public EndpointInfo(EndpointVisibility visibility, EndpointConfiguration configuration)
 {
     Visibility    = visibility;
     Configuration = configuration;
 }
コード例 #10
0
        public void TestNodeCollapse(EndpointVisibility visibility, bool nonCollapsedNonConnectedVisible, bool nonCollapsedConnectedVisible, bool collapsedNonConnectedVisible, bool collapsedConnectedVisible)
        {
            NodeOutputViewModel nodeAOutput = new NodeOutputViewModel();
            NodeViewModel       nodeA       = new NodeViewModel
            {
                Outputs = { nodeAOutput }
            };

            NodeInputViewModel nodeBInput = new NodeInputViewModel {
                Visibility = visibility
            };
            NodeInputViewModel nodeBInput2 = new NodeInputViewModel {
                Visibility = visibility
            };
            NodeOutputViewModel nodeBOutput = new NodeOutputViewModel {
                Visibility = visibility
            };
            NodeOutputViewModel nodeBOutput2 = new NodeOutputViewModel {
                Visibility = visibility
            };
            NodeViewModel nodeB = new NodeViewModel
            {
                Inputs  = { nodeBInput, nodeBInput2 },
                Outputs = { nodeBOutput, nodeBOutput2 }
            };

            NodeInputViewModel nodeCInput = new NodeInputViewModel();
            NodeViewModel      nodeC      = new NodeViewModel
            {
                Inputs = { nodeCInput }
            };

            NetworkViewModel network = new NetworkViewModel
            {
                Nodes = { nodeA, nodeB, nodeC }
            };

            network.Connections.Add(network.ConnectionFactory(nodeBInput, nodeAOutput));
            network.Connections.Add(network.ConnectionFactory(nodeCInput, nodeBOutput));

            var expectedInputSeq  = Enumerable.Empty <Endpoint>();
            var expectedOutputSeq = Enumerable.Empty <Endpoint>();

            if (nonCollapsedConnectedVisible)
            {
                expectedInputSeq  = expectedInputSeq.Concat(new[] { nodeBInput });
                expectedOutputSeq = expectedOutputSeq.Concat(new[] { nodeBOutput });
            }
            if (nonCollapsedNonConnectedVisible)
            {
                expectedInputSeq  = expectedInputSeq.Concat(new[] { nodeBInput2 });
                expectedOutputSeq = expectedOutputSeq.Concat(new[] { nodeBOutput2 });
            }

            Assert.IsTrue(nodeB.VisibleInputs.SequenceEqual(expectedInputSeq));
            Assert.IsTrue(nodeB.VisibleOutputs.SequenceEqual(expectedOutputSeq));

            nodeB.IsCollapsed = true;

            expectedInputSeq  = Enumerable.Empty <Endpoint>();
            expectedOutputSeq = Enumerable.Empty <Endpoint>();

            if (collapsedConnectedVisible)
            {
                expectedInputSeq  = expectedInputSeq.Concat(new[] { nodeBInput });
                expectedOutputSeq = expectedOutputSeq.Concat(new[] { nodeBOutput });
            }
            if (collapsedNonConnectedVisible)
            {
                expectedInputSeq  = expectedInputSeq.Concat(new[] { nodeBInput2 });
                expectedOutputSeq = expectedOutputSeq.Concat(new[] { nodeBOutput2 });
            }

            Assert.IsTrue(nodeB.VisibleInputs.SequenceEqual(expectedInputSeq));
            Assert.IsTrue(nodeB.VisibleOutputs.SequenceEqual(expectedOutputSeq));
        }
コード例 #11
0
ファイル: ServiceDefinition.cs プロジェクト: dolittle/Runtime
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceDefinition"/> class.
 /// </summary>
 /// <param name="visibility">The visibility of the implemented service.</param>
 /// <param name="implementationType">The type that implements the service.</param>
 public ServiceDefinition(EndpointVisibility visibility, Type implementationType)
 {
     Visibility         = visibility;
     ImplementationType = implementationType;
 }
コード例 #12
0
 internal static void CouldNotStartHost(this ILogger logger, Exception ex, EndpointVisibility endpointVisibility)
 => _couldNotStartHost(logger, endpointVisibility.ToString(), ex);
コード例 #13
0
ファイル: ServiceAttribute.cs プロジェクト: dolittle/Runtime
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceAttribute"/> class.
 /// </summary>
 /// <param name="visibility">The visibility of the service with this attribute defined.</param>
 protected ServiceAttribute(EndpointVisibility visibility)
 {
     Visibility = visibility;
 }
コード例 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UnknownEndpointVisibility"/> class.
 /// </summary>
 /// <param name="visibility">The visibility that is unknown.</param>
 public UnknownEndpointVisibility(EndpointVisibility visibility)
     : base($"The {nameof(EndpointVisibility)} {visibility} is unknown")
 {
 }
コード例 #15
0
ファイル: Log.cs プロジェクト: dolittle/Runtime
 internal static partial void AddingHealthCheckFor(this ILogger logger, EndpointVisibility visibility);
コード例 #16
0
 /// <summary>
 /// Maps discovered gRPC service implementations for the specified <see cref="EndpointVisibility"/>.
 /// </summary>
 /// <param name="endpoints">The endpoint route builder to map services to.</param>
 /// <param name="visibility">The endpoint visibility to map services for.</param>
 public static void MapDiscoveredGrpcServicesOf(this IEndpointRouteBuilder endpoints, EndpointVisibility visibility)
 => endpoints
 .ServiceProvider.GetRequiredService <ICanConfigureGrpcServicesForEndpoint>()
 .MapServicesForVisibility(endpoints, visibility);
コード例 #17
0
 internal static partial void EndpointDisabled(ILogger logger, EndpointVisibility visibilityType);
コード例 #18
0
 internal static partial void MappingDiscoveredGrpcService(this ILogger logger, Type implementation, EndpointVisibility visibility);
コード例 #19
0
 internal static void StartingHost(this ILogger logger, EndpointVisibility visibility, string host, int port)
 => _startingHost(logger, visibility.ToString(), host, port, null);
コード例 #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HealthCheckConfiguration"/> class.
 /// </summary>
 /// <param name="visibility">The endpoint visibility to add a health check for.</param>
 /// <param name="getConfiguration">The factory to use to get the endpoint configuration.</param>
 /// <param name="logger">The logger to use for logging.</param>
 public HealthCheckConfiguration(EndpointVisibility visibility, Func<IOptions<EndpointsConfiguration>> getConfiguration, ILogger logger)
 {
     _visibility = visibility;
     _getConfiguration = getConfiguration;
     _logger = logger;
 }
コード例 #21
0
 /// <summary>
 /// Configures a <see cref="HealthCheckRegistration"/> that performs a gRPC <see cref="HealthCheckRequest"/> on the specified <see cref="EndpointVisibility"/>.
 /// </summary>
 /// <param name="builder">The host builder to configure.</param>
 /// <param name="visibility">The endpoint visibility to add a health check for.</param>
 /// <returns>The builder for continuation.</returns>
 public static IHostBuilder AddGrpcEndpointHealthCheck(this IHostBuilder builder, EndpointVisibility visibility)
 => builder.ConfigureServices(services =>
                              services.AddTransient <IConfigureOptions <HealthCheckServiceOptions> >(_ => new HealthCheckConfiguration(
                                                                                                         visibility,
                                                                                                         _.GetRequiredService <Func <IOptions <EndpointsConfiguration> > >(),
                                                                                                         _.GetRequiredService <ILogger <HealthCheckConfiguration> >())));
コード例 #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EndpointHealthCheck"/> class.
 /// </summary>
 /// <param name="visibility">The endpoint visibility to attempt to connect to.</param>
 /// <param name="getConfiguration">The factory to use to resolve the endpoint configuration.</param>
 public EndpointHealthCheck(EndpointVisibility visibility, Func <IOptions <EndpointsConfiguration> > getConfiguration)
 {
     _visibility       = visibility;
     _getConfiguration = getConfiguration;
 }