Esempio n. 1
0
        /// <summary>
        /// Adds a named Npgsql Grain Storage Provider.
        /// </summary>
        /// <param name="builder">The <see cref="ISiloBuilder"/>.</param>
        /// <param name="storageName">The Grain Storage name.</param>
        /// <param name="configurationSection">The <see cref="IConfigurationSection"/> which binds to <see cref="NpgsqlOptions"/>.</param>
        /// <returns>The <see cref="ISiloBuilder"/>.</returns>
        public static ISiloBuilder AddNpgsqlGrainStorage([NotNull] this ISiloBuilder builder, [NotNull] string storageName, [NotNull] IConfigurationSection configurationSection)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (configurationSection?.Exists() != true)
            {
                throw new ConfigurationErrorsException($"Configuration section '{configurationSection?.Path}' is incorrect.");
            }
            if (string.IsNullOrWhiteSpace(storageName))
            {
                throw new ArgumentException($"'{nameof(storageName)}' must not be null, empty or whitespace.", nameof(storageName));
            }

            var npgsqlOptions = configurationSection.Get <NpgsqlOptions>();

            if (npgsqlOptions == null)
            {
                throw new ConfigurationErrorsException($"Configuration section '{configurationSection.Path}' is not valid.");
            }

            builder.AddAdoNetGrainStorage(storageName, x =>
            {
                x.ConnectionString = npgsqlOptions.ConnectionString;
                x.Invariant        = InvariantNamePostgreSQL;
                x.UseJsonFormat    = true;
            });

            return(builder);
        }
        /// <summary>
        /// Configure silo to use  AdoNet grain storage for grain storage. Instructions on configuring your database are available at <see href="http://aka.ms/orleans-sql-scripts" />.
        /// </summary>
        /// <remarks>
        /// Instructions on configuring your database are available at <see href="http://aka.ms/orleans-sql-scripts" />.
        /// </remarks>
        public static ISiloBuilder AddOrleansAdoNetGrainStorage <T>(
            this ISiloBuilder builder,
            string name,
            Action <T> configureOptions)
            where T : AdoNetGrainStorageOptions, new()
        {
            var newAction = new Action <AdoNetGrainStorageOptions>(options => ConvertToAdoNetGrainStorageOptions(configureOptions, options));

            return(builder.AddAdoNetGrainStorage(name, newAction));
        }
Esempio n. 3
0
                public void Configure(ISiloBuilder hostBuilder)
                {
                    var connectionString = hostBuilder.GetConfiguration()[ConnectionStringKey];

                    hostBuilder
                    .AddAdoNetGrainStorage("GrainStorageForTest", options =>
                    {
                        options.ConnectionString = (string)connectionString;
                        options.Invariant        = AdoInvariant;
                    })
                    .AddMemoryGrainStorage("MemoryStore");
                }
Esempio n. 4
0
        public static void ConfigureSilo(this ISiloBuilder builder, IConfiguration configuration)
        {
            var config = new SiloOptions();

            configuration.Bind("SiloOptions", config);

            builder
            .Configure <ProcessExitHandlingOptions>(options => { options.FastKillOnProcessExit = false; })
            .UseLocalhostClustering()
            .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "cluster1";
                options.ServiceId = "service1";
            })
            //.UseAzureStorageClustering(options => options.ConnectionString = connectionString)
            .AddLogStorageBasedLogConsistencyProvider()
            //.ConfigureEndpoints(Dns.GetHostName(), siloPort, gatewayPort)
            .ConfigureApplicationParts(parts =>
                                       parts.AddApplicationPart(typeof(HelloGrain).Assembly).WithReferences())
            .ConfigureLogging(logging => logging.AddConsole())
            .ConfigureLogging(logging => logging.SetMinimumLevel(LogLevel.Warning));

            if (config.UseAzureStorage)
            {
                var connectionString = configuration.GetConnectionString("AzureStorage");
                builder.AddAzureBlobGrainStorage("StorageProvider", options =>
                {
                    options.UseJson          = true;
                    options.ConnectionString = connectionString;
                });
            }
            else
            {
                var connectionString = configuration.GetConnectionString("AdoStorage");
                builder.AddAdoNetGrainStorage("StorageProvider", options =>
                {
                    options.Invariant        = "System.Data.SqlClient";
                    options.ConnectionString = connectionString;
                    options.UseJsonFormat    = true;
                });
                //.Configure<EndpointOptions>(options => options.AdvertisedIPAddress = IPAddress.Loopback);
            }
        }
Esempio n. 5
0
        public static ISiloBuilder ConfigureSilo(this ISiloBuilder builder)
        {
            var connectionStringBuilder = new NpgsqlConnectionStringBuilder
            {
                Host     = "orleans-postgres",
                Database = "orleans",
                Username = "******",
                Password = "******"
            };

            builder.Configure((Action <ClusterOptions>)(options =>
            {
                options.ClusterId = "heterogenous-test-cluster";
                options.ServiceId = "heterogenous-test-cluster";
            }));
            builder.ConfigureEndpoints(11111, 30000);
            builder.AddAdoNetGrainStorage("grain-storage", options =>
            {
                options.Invariant        = "Npgsql";
                options.ConnectionString = connectionStringBuilder.ConnectionString;
            });

            builder.UseAdoNetClustering(options =>
            {
                options.Invariant        = "Npgsql";
                options.ConnectionString = connectionStringBuilder.ConnectionString;
            });

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                builder.UseLinuxEnvironmentStatistics();
            }

            builder.UseDashboard(options => { options.Port = 1337; });

            return(builder);
        }
 /// <summary>
 /// Configure silo to use  AdoNet grain storage as the default grain storage. Instructions on configuring your database are available at <see href="http://aka.ms/orleans-sql-scripts"/>.
 /// </summary>
 /// <remarks>
 /// Instructions on configuring your database are available at <see href="http://aka.ms/orleans-sql-scripts"/>.
 /// </remarks>
 public static ISiloBuilder AddAdoNetGrainStorageAsDefault(this ISiloBuilder builder, Action <OptionsBuilder <AdoNetGrainStorageOptions> > configureOptions = null)
 {
     return(builder.AddAdoNetGrainStorage(ProviderConstants.DEFAULT_STORAGE_PROVIDER_NAME, configureOptions));
 }
Esempio n. 7
0
        public static void Configure(this ISiloBuilder siloBuilder, OrleansClusterConfiguration configuration)
        {
            // Local or distribute cluster
            if (configuration.Membership.Enabled)
            {
                siloBuilder
                .UseAdoNetClustering(options =>
                {
                    options.Invariant        = configuration.Membership.Provider;
                    options.ConnectionString = configuration.Membership.ConnectionString;
                })
                .Configure <EndpointOptions>(options =>
                {
                    options.SiloPort    = configuration.Endpoint.SiloPort;
                    options.GatewayPort = configuration.Endpoint.GatewayPort;

                    // IP Address to advertise in the cluster
                    if (IPAddress.TryParse(configuration.Endpoint.AdvertisedIPAddress, out var iPAddress))
                    {
                        options.AdvertisedIPAddress = iPAddress;
                    }

                    // The socket used for silo-to-silo will bind to this endpoint
                    if (configuration.Endpoint.GatewayListeningPort > 0 && IPAddress.TryParse(configuration.Endpoint.AdvertisedIPAddress, out var gatewayIPAddress))
                    {
                        options.GatewayListeningEndpoint = new IPEndPoint(gatewayIPAddress, configuration.Endpoint.GatewayListeningPort);
                    }

                    // The socket used by the gateway will bind to this endpoint
                    if (configuration.Endpoint.SiloListeningPort > 0 && IPAddress.TryParse(configuration.Endpoint.SiloListeningIP, out var siloIPAddress))
                    {
                        options.SiloListeningEndpoint = new IPEndPoint(siloIPAddress, configuration.Endpoint.SiloListeningPort);
                    }
                });
            }
            else
            {
                siloBuilder.UseLocalhostClustering();
            }

            // Cluster identity
            siloBuilder
            .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = configuration.ClusterId;
                options.ServiceId = configuration.ServiceId;
            })

            .Configure <GrainCollectionOptions>(options =>
            {
                // Set the value of CollectionAge to 3 minutes for all grain
                options.CollectionAge = TimeSpan.FromMinutes(3);

                // Override the value of CollectionAge to 5 minutes for MyGrainImplementation
                // options.ClassSpecificCollectionAge[typeof(FeedSubscriberGrain).FullName] = TimeSpan.FromMinutes(5);
            });

            //.UsePerfCounterEnvironmentStatistics()
            //.Configure<SiloMessagingOptions>(options =>
            //{
            //    options.ResponseTimeout = TimeSpan.FromSeconds(5);
            //})

            // Reminder
            if (configuration.Reminder.Enabled)
            {
                siloBuilder
                .UseAdoNetReminderService(options =>
                {
                    options.Invariant        = configuration.Reminder.Provider;
                    options.ConnectionString = configuration.Reminder.ConnectionString;
                });
            }
            else
            {
                siloBuilder
                .UseInMemoryReminderService();
            }

            // Storage
            if (configuration.Storage.Enabled)
            {
                siloBuilder
                .AddAdoNetGrainStorage("stateStore", options =>
                {
                    options.Invariant        = configuration.Storage.Provider;
                    options.ConnectionString = configuration.Storage.ConnectionString;
                });
            }
            else
            {
                siloBuilder.AddMemoryGrainStorage("stateStore");
            }

            //if (context.HostingEnvironment.IsDevelopment())
            //    builder.UseDevelopmentOrleans(new IPEndPoint(6, 11111));


            // HealthChecks
            //siloBuilder.UseUdfsClusterHealthChecks();
        }
Esempio n. 8
0
        public static void ConfigureUdfs(this ISiloBuilder siloBuilder, UdfsClusterOptions udfsClusterOptions)
        {
            // Local or distribute cluster
            if (udfsClusterOptions.Membership.Enabled)
            {
                siloBuilder
                .UseAdoNetClustering(options =>
                {
                    options.Invariant        = udfsClusterOptions.Membership.Provider;
                    options.ConnectionString = udfsClusterOptions.Membership.ConnectionString;
                })
                .Configure <EndpointOptions>(options =>
                {
                    options.AdvertisedIPAddress      = udfsClusterOptions.EndPoint.AdvertisedIPAddress ?? IPAddress.Loopback;
                    options.GatewayListeningEndpoint = udfsClusterOptions.EndPoint.GatewayListeningEndpoint;
                    options.GatewayPort           = udfsClusterOptions.EndPoint.GatewayPort;
                    options.SiloListeningEndpoint = udfsClusterOptions.EndPoint.SiloListeningEndpoint;
                    options.SiloPort = udfsClusterOptions.EndPoint.SiloPort;
                });
            }
            else
            {
                siloBuilder.UseLocalhostClustering();
            }

            // Cluster identity
            siloBuilder
            .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = udfsClusterOptions.ClusterService.ClusterId;
                options.ServiceId = udfsClusterOptions.ClusterService.ServiceId;
            });

            // siloBuilder
            //.ConfigureLogging((hostingContext, logging) =>
            //{
            //    //TODO: Logging slows down testing a bit.
            //    //logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
            //    logging.AddConsole();
            //              logging.AddDebug();
            //          })
            //.UsePerfCounterEnvironmentStatistics()
            //.Configure<SiloMessagingOptions>(options =>
            //{
            //    options.ResponseTimeout = TimeSpan.FromSeconds(5);
            //})
            //.Configure<GrainCollectionOptions>(options =>
            //{
            //    // Set the value of CollectionAge to 10 minutes for all grain
            //    options.CollectionAge = TimeSpan.FromMinutes(10);

            //    // Override the value of CollectionAge to 5 minutes for MyGrainImplementation
            //    // options.ClassSpecificCollectionAge[typeof(AdoNetOrleansSiloOptions).FullName] = TimeSpan.FromMinutes(5);
            //});

            // Reminder
            if (udfsClusterOptions.Reminder.Enabled)
            {
                siloBuilder
                .UseAdoNetReminderService(options =>
                {
                    options.Invariant        = udfsClusterOptions.Reminder.Provider;
                    options.ConnectionString = udfsClusterOptions.Reminder.ConnectionString;
                });
            }
            else
            {
                siloBuilder
                .UseInMemoryReminderService();
            }

            // Storage
            if (udfsClusterOptions.Storage.Enabled)
            {
                siloBuilder
                .AddAdoNetGrainStorage(UdfsGrainStorages.UDFS_GRAIN_STORAGE, options =>
                {
                    options.Invariant        = udfsClusterOptions.Storage.Provider;
                    options.ConnectionString = udfsClusterOptions.Storage.ConnectionString;
                });
            }
            else
            {
                siloBuilder.AddMemoryGrainStorage(UdfsGrainStorages.UDFS_GRAIN_STORAGE);
            }

            //if (context.HostingEnvironment.IsDevelopment())
            //    builder.UseDevelopmentOrleans(new IPEndPoint(6, 11111));

            // Grains
            foreach (var item in udfsClusterOptions.GrainAssemblies)
            {
                siloBuilder.ConfigureApplicationParts(parts => parts.AddApplicationPart(item).WithReferences());
            }


            // HealthChecks
            siloBuilder.UseUdfsClusterHealthChecks();
        }