Example #1
0
        /// <summary>
        /// Starts the grpc server, binds the <see cref="QualityVerificationGrpcImpl"/> together
        /// with the <see cref="IServiceHealth"/> implementation and returns a handle for both.
        /// </summary>
        /// <param name="arguments">The microserver command line / config arguments.</param>
        /// <param name="inputsFactoryMethod">The factory method that creates the
        /// <see cref="IBackgroundVerificationInputs"/> instance. If no factory is proveded, only
        /// stand-alone verification (such as XML) can be used.</param>
        /// <param name="checkout3dAnalyst"></param>
        /// <param name="markUnhealthyOnExceptions"></param>
        /// <returns></returns>
        public static StartedGrpcServer StartVerificationServer(
            [NotNull] MicroserverArguments arguments,
            [CanBeNull]
            Func <VerificationRequest, IBackgroundVerificationInputs> inputsFactoryMethod,
            bool checkout3dAnalyst,
            bool markUnhealthyOnExceptions)
        {
            var healthService = new HealthServiceImpl();

            IServiceHealth health = new ServiceHealth(healthService);

            var wuVerificationServiceImpl =
                new QualityVerificationGrpcImpl(inputsFactoryMethod,
                                                arguments.MaxParallel)
            {
                Checkout3DAnalyst = checkout3dAnalyst
            };

            if (markUnhealthyOnExceptions)
            {
                wuVerificationServiceImpl.Health = health;
            }

            health.SetStatus(wuVerificationServiceImpl.GetType(), true);

            ServerCredentials serverCredentials =
                GrpcServerUtils.GetServerCredentials(arguments.Certificate,
                                                     arguments.PrivateKeyFile,
                                                     arguments.EnforceMutualTls);

            var oneGb = (int)Math.Pow(1024, 3);

            IList <ChannelOption> channelOptions = GrpcServerUtils.CreateChannelOptions(oneGb);

            var server =
                new Grpc.Core.Server(channelOptions)
            {
                Services =
                {
                    QualityVerificationGrpc.BindService(wuVerificationServiceImpl),
                    Health.BindService(healthService)
                },
                Ports =
                {
                    new ServerPort(arguments.HostName, arguments.Port, serverCredentials)
                }
            };

            server.Start();

            _msg.InfoFormat("Service is listening on host {0}, port {1}.", arguments.HostName,
                            arguments.Port);

            return(new StartedGrpcServer(server, health));
        }
Example #2
0
        /// <summary>
        /// Starts the grpc server at the specified address with the specified services.
        /// </summary>
        /// <param name="services">The list of service definitions to be hosted by the server.</param>
        /// <param name="hostName">The host name.</param>
        /// <param name="port">The port.</param>
        /// <param name="certificate">The certificate store's certificate (subject or thumbprint)
        /// or the PEM file containing the certificate chain.</param>
        /// <param name="privateKeyFilePath">The PEM file containing the private key (only if the
        /// certificate was provided by a PEM file.</param>
        /// <param name="enforceMutualTls">Enforce client authentication.</param>
        /// <returns></returns>
        public static Grpc.Core.Server StartGrpcServer(
            [NotNull] ICollection <ServerServiceDefinition> services,
            [NotNull] string hostName,
            int port,
            string certificate,
            string privateKeyFilePath,
            bool enforceMutualTls = false)
        {
            ServerCredentials serverCredentials =
                GrpcServerUtils.GetServerCredentials(certificate,
                                                     privateKeyFilePath,
                                                     enforceMutualTls);

            // Enough for large geometries
            var oneGb = (int)Math.Pow(1024, 3);

            IList <ChannelOption> channelOptions = GrpcServerUtils.CreateChannelOptions(oneGb);

            var server =
                new Grpc.Core.Server(channelOptions)
            {
                Ports =
                {
                    new ServerPort(hostName, port, serverCredentials)
                }
            };

            foreach (ServerServiceDefinition serviceDefinition in services)
            {
                server.Services.Add(serviceDefinition);
            }

            _msg.DebugFormat("Starting grpc server on {0} with the following services: {1}",
                             ToHttpUrl(hostName, port, certificate != null),
                             StringUtils.Concatenate(services, ", "));

            server.Start();

            return(server);
        }