/// <summary>
        /// Configures TLS.
        /// </summary>
        /// <param name="builder">The builder to configure.</param>
        /// <param name="configureOptions">An Action to configure the <see cref="TlsOptions"/>.</param>
        /// <returns>The builder.</returns>
        public static IClientBuilder UseTls(
            this IClientBuilder builder,
            Action <TlsOptions> configureOptions)
        {
            if (configureOptions is null)
            {
                throw new ArgumentNullException(nameof(configureOptions));
            }

            var options = new TlsOptions();

            configureOptions(options);
            if (options.LocalCertificate is null && options.ClientCertificateMode == RemoteCertificateMode.RequireCertificate)
            {
                throw new InvalidOperationException("No certificate specified");
            }

            if (options.LocalCertificate is X509Certificate2 certificate && !certificate.HasPrivateKey)
            {
                TlsConnectionBuilderExtensions.ThrowNoPrivateKey(certificate, $"{nameof(TlsOptions)}.{nameof(TlsOptions.LocalCertificate)}");
            }

            return(builder.Configure <ClientConnectionOptions>(connectionOptions =>
            {
                connectionOptions.ConfigureConnection(connectionBuilder =>
                {
                    connectionBuilder.UseClientTls(options);
                });
            }));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Configures the Cluster.
        /// </summary>
        /// <param name="builder">The <see cref="IClientBuilder"/>.</param>
        /// <param name="clusterName">The Name of the Cluster being Configured.</param>
        /// <param name="configuration">The <see cref="IConfiguration"/> which binds to <see cref="ClusterOptions"/>.</param>
        /// <returns>Returns the <see cref="IClientBuilder"/> so that more methods can be chained.</returns>
        public static IClientBuilder ConfigureCluster([NotNull] this IClientBuilder builder, [NotNull] string clusterName, [NotNull] IConfiguration configuration)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            if (string.IsNullOrWhiteSpace(clusterName))
            {
                throw new ArgumentException($"'{nameof(clusterName)}' must not be null, empty or whitespace.", nameof(clusterName));
            }

            var configurationSection = configuration.GetSection($"{Constants.ClusterOptionsDefaultSectionName}:{clusterName}");

            if (configurationSection?.Exists() != true)
            {
                throw new ConfigurationErrorsException($"Configuration section '{Constants.ClusterOptionsDefaultSectionName}' is incorrect.");
            }

            builder.Configure <ClusterOptions>(configurationSection);
            return(builder);
        }
Ejemplo n.º 3
0
        private static void TryConfigureClientMembership(IConfiguration configuration, IClientBuilder clientBuilder)
        {
            bool.TryParse(configuration[nameof(TestClusterOptions.UseTestClusterMembership)], out bool useTestClusterMembership);

            if (useTestClusterMembership)
            {
                Action <StaticGatewayListProviderOptions> configureOptions = options =>
                {
                    int  baseGatewayPort   = int.Parse(configuration[nameof(TestClusterOptions.BaseGatewayPort)]);
                    int  initialSilosCount = int.Parse(configuration[nameof(TestClusterOptions.InitialSilosCount)]);
                    bool gatewayPerSilo    = bool.Parse(configuration[nameof(TestClusterOptions.GatewayPerSilo)]);

                    if (gatewayPerSilo)
                    {
                        options.Gateways = Enumerable.Range(baseGatewayPort, initialSilosCount)
                                           .Select(port => new IPEndPoint(IPAddress.Loopback, port).ToGatewayUri())
                                           .ToList();
                    }
                    else
                    {
                        options.Gateways = new List <Uri> {
                            new IPEndPoint(IPAddress.Loopback, baseGatewayPort).ToGatewayUri()
                        };
                    }
                };

                clientBuilder.Configure(configureOptions);

                clientBuilder.ConfigureServices(services =>
                {
                    services.AddSingleton <IGatewayListProvider, StaticGatewayListProvider>()
                    .ConfigureFormatter <StaticGatewayListProviderOptions>();
                });
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Configures TLS.
        /// </summary>
        /// <param name="builder">The builder to configure.</param>
        /// <param name="configureOptions">An Action to configure the <see cref="TlsOptions"/>.</param>
        /// <returns>The builder.</returns>
        public static IClientBuilder UseTls(
            this IClientBuilder builder,
            Action <TlsOptions> configureOptions)
        {
            if (configureOptions == null)
            {
                throw new ArgumentNullException(nameof(configureOptions));
            }

            var options = new TlsOptions();

            configureOptions(options);
            if (options.LocalCertificate is null && options.LocalServerCertificateSelector is null)
            {
                throw new InvalidOperationException("No certificate specified");
            }

            return(builder.Configure <ClientConnectionOptions>(connectionOptions =>
            {
                connectionOptions.ConfigureConnection(connectionBuilder =>
                {
                    connectionBuilder.UseClientTls(options);
                });
            }));
        }
Ejemplo n.º 5
0
 public static IClientBuilder Configure_ClusterOptions(this IClientBuilder builder)
 {
     return(builder.Configure <ClusterOptions>(options =>
     {
         options.ClusterId = AppConst.ClusterId;
         options.ServiceId = AppConst.ServiceId;
     }));
 }
Ejemplo n.º 6
0
 public void Configure(IConfiguration configuration, IClientBuilder clientBuilder)
 {
     clientBuilder.Configure <GatewayOptions>(options => options.PreferedGatewayIndex = 0);
     clientBuilder.ConfigureApplicationParts(parts =>
     {
         parts.AddApplicationPart(typeof(IVersionUpgradeTestGrain).Assembly);
     });
 }
Ejemplo n.º 7
0
 public void Configure(IConfiguration configuration, IClientBuilder clientBuilder)
 {
     clientBuilder
     .Configure <ClientMessagingOptions>(options =>
     {
         options.ResponseTimeout             = TimeSpan.FromSeconds(5);
         options.ResponseTimeoutWithDebugger = TimeSpan.FromSeconds(5);
     });
 }
Ejemplo n.º 8
0
 public void Configure(IConfiguration configuration, IClientBuilder clientBuilder)
 {
     clientBuilder
     .Configure <ClusterOptions>(op => op.ServiceId = serviceId)
     .AddAzureQueueStreams(AQStreamProviderName, ob => ob.Configure <IOptions <ClusterOptions> >(
                               (options, dep) =>
     {
         options.ConnectionString = TestDefaultConfiguration.DataConnectionString;
     }));
 }
Ejemplo n.º 9
0
            public void Configure(IConfiguration configuration, IClientBuilder clientBuilder)
            {
                var clusterConnectionLostNotifier  = new EventNotifier <EventArgs>();
                var gatewayConnectionCountNotifier = new EventNotifier <GatewayCountChangedEventArgs>();

                clientBuilder.ConfigureServices(s => s.AddSingleton(clusterConnectionLostNotifier));
                clientBuilder.ConfigureServices(s => s.AddSingleton(gatewayConnectionCountNotifier));
                clientBuilder.Configure <GatewayOptions>(options => options.GatewayListRefreshPeriod = TimeSpan.FromSeconds(1));
                clientBuilder.AddClusterConnectionLostHandler((s, e) => clusterConnectionLostNotifier.Notify(e));
                clientBuilder.AddGatewayCountChangedHandler((s, e) => gatewayConnectionCountNotifier.Notify(e));
            }
Ejemplo n.º 10
0
        private static IClientBuilder AddOrleansClusterClient(this IClientBuilder builder, OrleansConfig config)
        {
            builder.ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IPiSystem).Assembly));

#if DEBUG
            builder.UseLocalhostClustering();
#else
            builder.Configure <ClusterOptions>(options =>
            {
                options.ClusterId = config.ClusterId;
                options.ServiceId = config.ServiceId;
            });

            if (config.DataConnectionString.Contains("6379") || config.DataConnectionString.Contains("6380"))
            {
                builder.UseRedisGatewayListProvider(options => options.ConnectionString = config.DataConnectionString);
            }
            else
            {
                builder.UseAzureStorageClustering(options => options.ConnectionString = config.DataConnectionString);
            }
#endif

            LoggerType loggers = config.GetLoggerTypes();

            if (loggers.HasFlag(LoggerType.AppInsights))
            {
                builder.AddApplicationInsightsTelemetryConsumer(config.InstrumentationKey);
            }

            builder.ConfigureLogging(op =>
            {
                if (loggers.HasFlag(LoggerType.AppInsights))
                {
                    op.AddApplicationInsights(config.InstrumentationKey);
                    op.SetMinimumLevel(Enum.Parse <LogLevel>(config.LogLevel, true));
                }

                if (loggers.HasFlag(LoggerType.Console))
                {
                    op.AddConsole();
                    op.SetMinimumLevel(Enum.Parse <LogLevel>(config.LogLevel, true));
                }

                if (loggers.HasFlag(LoggerType.Debug))
                {
                    op.AddDebug();
                    op.SetMinimumLevel(Enum.Parse <LogLevel>(config.LogLevel, true));
                }
            });

            return(builder);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Configures the Cluster.
        /// </summary>
        /// <param name="builder">The <see cref="IClientBuilder"/>.</param>
        /// <param name="configurationSection">An <see cref="IConfigurationSection"/> to configure the provided <see cref="IClientBuilder"/>.</param>
        /// <returns>Returns the <see cref="IClientBuilder"/> so that more methods can be chained.</returns>
        public static IClientBuilder ConfigureCluster([NotNull] this IClientBuilder builder, [NotNull] IConfigurationSection configurationSection)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (configurationSection?.Exists() != true)
            {
                throw new ConfigurationErrorsException($"Configuration section '{configurationSection?.Path}' is incorrect.");
            }

            return(builder.Configure <ClusterOptions>(configurationSection));
        }
Ejemplo n.º 12
0
 public static IClientBuilder UseRedisMembership(this IClientBuilder builder, string redisConnectionString, int db = 0)
 {
     builder.Configure <ClusterMembershipOptions>(x => x.ValidateInitialConnectivity = true);
     return(builder.ConfigureServices(services => services
                                      .Configure <RedisOptions>(opt =>
     {
         opt.ConnectionString = redisConnectionString;
         opt.Database = db;
     })
                                      .AddSingleton(new GatewayOptions()
     {
         GatewayListRefreshPeriod = GatewayOptions.DEFAULT_GATEWAY_LIST_REFRESH_PERIOD
     })
                                      .AddRedis()
                                      .AddSingleton <IGatewayListProvider, RedisGatewayListProvider>()));
 }
Ejemplo n.º 13
0
 public static IClientBuilder UseConfiguration(
     this IClientBuilder clientBuilder,
     ClientBuilderContext context
     )
 {
     return(clientBuilder
            .Configure <ClusterOptions>(config =>
     {
         config.ClusterId = "dev";
         config.ServiceId = "Heroes";
     })
            .UseConsulClustering(options => {
         options.Address = new Uri(context.ConsulEndPoint);
     })
            .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IHeroGrain).Assembly).WithReferences())
            .ConfigureLogging(logging => logging.AddConsole()));
 }
Ejemplo n.º 14
0
        public static IClientBuilder UseRedisMembership(this IClientBuilder builder, Action <RedisOptions> configuration)
        {
            builder.Configure <ClusterMembershipOptions>(x => x.ValidateInitialConnectivity = true);
            return(builder.ConfigureServices(services =>
            {
                var options = new RedisOptions();
                configuration?.Invoke(options);

                services
                .AddSingleton(options)
                .AddSingleton(new GatewayOptions()
                {
                    GatewayListRefreshPeriod = GatewayOptions.DEFAULT_GATEWAY_LIST_REFRESH_PERIOD
                })
                .AddRedis()
                .AddSingleton <IGatewayListProvider, RedisGatewayListProvider>();
            }));
        }
        public static IClientBuilder UseConfiguration(
            this IClientBuilder clientBuilder,
            ClientBuilderContext context
            )
        {
            if (!context.AppInfo.IsDockerized)
            {
                var       siloAddress = IPAddress.Loopback;
                const int gatewayPort = 30000;                 // 10400
                clientBuilder.UseStaticClustering(new IPEndPoint(siloAddress, gatewayPort));
            }

            return(clientBuilder.Configure <ClusterOptions>(config =>
            {
                config.ClusterId = context.ClusterId;
                config.ServiceId = context.ServiceId;
            }));
        }
Ejemplo n.º 16
0
 private void ConfigureOrleansBase(IClientBuilder builder)
 {
     builder
     .Configure <ClusterOptions>(options =>
     {
         options.ClusterId = "serverlessorleans";
         options.ServiceId = "serverlessorleans";
     })
     .ConfigureLogging(builder => builder.AddConsole())
     .ConfigureApplicationParts(parts =>
     {
         foreach (var assembly in ExternalAssemblies)
         {
             System.Console.WriteLine("Loading orleans app parts: " + assembly.FullName);
             parts.AddApplicationPart(assembly);
         }
     })
     .UseDashboard();
 }
Ejemplo n.º 17
0
            public void Configure(IConfiguration configuration, IClientBuilder clientBuilder)
            {
                var basePort  = int.Parse(configuration[nameof(TestClusterOptions.BaseGatewayPort)]);
                var primaryGw = new IPEndPoint(IPAddress.Loopback, basePort).ToGatewayUri();

                clientBuilder.Configure <GatewayOptions>(options =>
                {
                    options.GatewayListRefreshPeriod = TimeSpan.FromMilliseconds(100);
                });
                clientBuilder.ConfigureServices(services =>
                {
                    services.AddSingleton(sp =>
                    {
                        var gateway = new TestGatewayManager();
                        gateway.Gateways.Add(primaryGw);
                        return(gateway);
                    });
                    services.AddFromExisting <IGatewayListProvider, TestGatewayManager>();
                });
            }
 public static IClientBuilder UseConfiguration(
     this IClientBuilder clientBuilder,
     ClientBuilderContext context
     )
 {
     //if (!context.AppInfo.IsDockerized)
     //{
     //	var siloAddress = IPAddress.Loopback;
     //	const int gatewayPort = 30000; // 10400
     //	clientBuilder.UseStaticClustering(new IPEndPoint(siloAddress, gatewayPort));
     //}
     clientBuilder.UseConsulClustering(options =>
     {
         options.Address = new Uri("http://127.0.0.1:8500");
     });
     return(clientBuilder.Configure <ClusterOptions>(config =>
     {
         config.ClusterId = context.ClusterId;
         config.ServiceId = context.ServiceId;
     }));
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Configures the Cluster.
        /// </summary>
        /// <param name="builder">The <see cref="IClientBuilder"/>.</param>
        /// <param name="configuration">The <see cref="IConfiguration"/> which binds to <see cref="ClusterOptions"/>.</param>
        /// <returns>Returns the <see cref="IClientBuilder"/> so that more methods can be chained.</returns>
        public static IClientBuilder ConfigureCluster([NotNull] this IClientBuilder builder, [NotNull] IConfiguration configuration)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var configurationSection = configuration.GetSection(Constants.ClusterOptionsDefaultSectionName);

            if (configurationSection?.Exists() != true)
            {
                throw new ConfigurationErrorsException($"Configuration section '{Constants.ClusterOptionsDefaultSectionName}' is incorrect.");
            }

            builder.Configure <ClusterOptions>(configurationSection);

            return(builder);
        }
Ejemplo n.º 20
0
 static IClientBuilder ConfigureDemoClustering(this IClientBuilder builder) => builder
 .Configure <ClusterOptions>(options =>
 {
     options.ServiceId = DemoClusterId;
     options.ClusterId = DemoClusterId;
 })
 .UseStaticClustering(options => options.Gateways.Add(new IPEndPoint(LocalhostSiloAddress, LocalhostGatewayPort).ToGatewayUri()));
 public void Configure(IConfiguration configuration, IClientBuilder clientBuilder)
 {
     clientBuilder.Configure <GatewayOptions>(options => options.PreferedGatewayIndex = 0);
 }
Ejemplo n.º 22
0
 public void Configure(IConfiguration configuration, IClientBuilder clientBuilder)
 {
     clientBuilder.Configure <StaticGatewayListProviderOptions>(options => options.Gateways = options.Gateways.Take(1).ToList());
 }
Ejemplo n.º 23
0
 public void Configure(IConfiguration configuration, IClientBuilder clientBuilder)
 {
     clientBuilder.Configure <GatewayOptions>(
         options => options.GatewayListRefreshPeriod = TimeSpan.FromMilliseconds(100));
 }
Ejemplo n.º 24
0
 public void Configure(IConfiguration configuration, IClientBuilder clientBuilder)
 {
     clientBuilder.Configure <ClientMessagingOptions>(options => options.ResponseTimeout = Timeout);
 }
Ejemplo n.º 25
0
 public void Configure(IConfiguration configuration, IClientBuilder clientBuilder)
 {
     clientBuilder.Configure <TypeManagementOptions>(options => options.TypeMapRefreshInterval = ClientRefreshDelay);
 }
Ejemplo n.º 26
0
 public void Configure(IConfiguration configuration, IClientBuilder clientBuilder)
 {
     clientBuilder.Configure <SiloMessagingOptions>(options => options.PropagateActivityId = true);
 }