Example #1
0
 /// <summary>
 /// Starts the grpc server at the address specified in the microserver arguments parameter
 /// with the specified services.
 /// </summary>
 /// <param name="services">The list of service definitions to be hosted by the server.</param>
 /// <param name="arguments">The microserver arguments containing the connection details.</param>
 /// <returns></returns>
 public static Grpc.Core.Server StartGrpcServer(
     [NotNull] ICollection <ServerServiceDefinition> services,
     [NotNull] MicroserverArguments arguments)
 {
     return(StartGrpcServer(services, arguments.HostName, arguments.Port,
                            arguments.Certificate, arguments.PrivateKeyFile,
                            arguments.EnforceMutualTls));
 }
Example #2
0
        public static MicroserverArguments GetStartParameters([NotNull] string[] args,
                                                              [CanBeNull] string configFilePath,
                                                              int defaultPort = 5151)
        {
            MicroserverArguments result = null;

            if (args.Length == 0)
            {
                // Still parse the args, in case of --help or --version
                Parser.Default.ParseArguments <MicroserverArguments>(args);

                _msg.InfoFormat("No arguments provided. For help, start with --help");

                if (configFilePath != null && File.Exists(configFilePath))
                {
                    _msg.InfoFormat("Getting server parameters from {0}", configFilePath);

                    XmlSerializationHelper <MicroserverArguments> helper =
                        new XmlSerializationHelper <MicroserverArguments>();

                    result = helper.ReadFromFile(configFilePath);
                }
                else
                {
                    _msg.InfoFormat("No configuration file found at {0}. Using default parameters.",
                                    configFilePath);

                    result = new MicroserverArguments
                    {
                        HostName = "localhost",
                        Port     = defaultPort
                    };
                }
            }
            else
            {
                _msg.InfoFormat(
                    "Using arguments from command line (config file is ignored if it exists).");

                var parsedArgs = Parser.Default.ParseArguments <MicroserverArguments>(args);

                parsedArgs.WithParsed(arguments => { result = arguments; });

                bool helpArg = args.Any(
                    a => a != null &&
                    a.Equals("--help", StringComparison.InvariantCultureIgnoreCase));

                if (helpArg)
                {
                    // Lets exit after printing the help:
                    return(null);
                }
            }

            return(result);
        }
Example #3
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 #4
0
        private static Grpc.Core.Server StartGrpcServer(
            MicroserverArguments arguments,
            [NotNull] QualityVerificationGrpcImpl verificationServiceImpl,
            [NotNull] HealthServiceImpl healthService,
            [NotNull] LoadReportingGrpcImpl loadReporting)
        {
            var services = new List <ServerServiceDefinition>(
                new[]
            {
                QualityVerificationGrpc.BindService(verificationServiceImpl),
                Health.BindService(healthService),
                LoadReportingGrpc.BindService(loadReporting)
            });

            return(StartGrpcServer(services, arguments));
        }
Example #5
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="inputsFactory">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="markUnhealthyOnExceptions"></param>
        /// <returns></returns>
        public static StartedGrpcServer <QualityVerificationGrpcImpl> StartVerificationServer(
            [NotNull] MicroserverArguments arguments,
            [CanBeNull] Func <VerificationRequest, IBackgroundVerificationInputs> inputsFactory,
            bool markUnhealthyOnExceptions)
        {
            var healthService = new HealthServiceImpl();

            IServiceHealth health = new ServiceHealth(healthService);

            LoadReportingGrpcImpl loadReporting = new LoadReportingGrpcImpl();

            ServiceLoad serviceLoad = new ServiceLoad(arguments.MaxParallel);

            loadReporting.AllowMonitoring(nameof(QualityVerificationGrpc), serviceLoad);

            var verificationServiceImpl =
                new QualityVerificationGrpcImpl(inputsFactory,
                                                arguments.MaxParallel)
            {
                CurrentLoad = serviceLoad
            };

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

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

            Grpc.Core.Server server =
                StartGrpcServer(arguments, verificationServiceImpl, healthService, loadReporting);

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

            return(new StartedGrpcServer <QualityVerificationGrpcImpl>(
                       server, verificationServiceImpl, health));
        }