Exemple #1
0
        static async Task Main(string[] args)
        {
            var hostBuilder = new SiloHostBuilder();

            hostBuilder
            .UseLocalhostClustering()
            .UseServiceProviderFactory(collection =>
            {
                collection.AddLogging(logging =>
                {
                    logging.AddConsole();
                    logging.SetMinimumLevel(LogLevel.Debug);
                    logging.AddFilter((s, level) => s.StartsWith("Orleans") && level >= LogLevel.Warning);
                    logging.AddFilter((s, level) => s.Contains("Claptrap"));
                });
                var builder = new ContainerBuilder();

                builder.Populate(collection);

                var buildServiceProvider = collection.BuildServiceProvider();
                var loggerFactory        = buildServiceProvider.GetService <ILoggerFactory>();
                var bootstrapperBuilder  = new AutofacClaptrapBootstrapperBuilder(loggerFactory, builder);
                var claptrapBootstrapper = bootstrapperBuilder
                                           .ScanClaptrapModule()
                                           .UseSQLiteAsTestingStorage()
                                           .ScanClaptrapDesigns(new[]
                {
                    typeof(ArticleGrain).Assembly
                })
                                           .Build();
                claptrapBootstrapper.Boot();


                var container       = builder.Build();
                var serviceProvider = new AutofacServiceProvider(container);
                return(serviceProvider);
            })
            .ConfigureApplicationParts(manager =>
                                       manager.AddFromDependencyContext().WithReferences())
            ;
            var siloHost = hostBuilder.Build();

            Console.WriteLine("server starting");
            await siloHost.StartAsync();

            Console.WriteLine("server started");

            Console.ReadLine();
        }
        public SiloWrapper(IConfiguration config, ISemanticLog log)
        {
            this.log = log;

            silo = new Lazy <ISiloHost>(() =>
            {
                J.Serializer = SerializationServices.DefaultJsonSerializer;

                var hostBuilder = new SiloHostBuilder()
                                  .UseDashboard(options => options.HostSelf = true)
                                  .AddStartupTask <Bootstrap <IContentSchedulerGrain> >()
                                  .AddStartupTask <Bootstrap <IEventConsumerManagerGrain> >()
                                  .AddStartupTask <Bootstrap <IRuleDequeuerGrain> >()
                                  .AddStartupTask((services, ct) =>
                {
                    services.RunInitialization();

                    return(TaskHelper.Done);
                })
                                  .Configure <ClusterOptions>(options =>
                {
                    options.ClusterId = "squidex";
                })
                                  .ConfigureLogging((hostingContext, builder) =>
                {
                    builder.AddConfiguration(hostingContext.Configuration.GetSection("logging"));
                    builder.AddSemanticLog();
                    builder.AddFilter("Orleans.Runtime.SiloControl", LogLevel.Warning);
                })
                                  .ConfigureApplicationParts(builder =>
                {
                    builder.AddApplicationPart(SquidexEntities.Assembly);
                    builder.AddApplicationPart(SquidexInfrastructure.Assembly);
                })
                                  .ConfigureServices((context, services) =>
                {
                    services.AddAppSiloServices(context.Configuration);
                    services.AddAppServices(context.Configuration);

                    services.Configure <ProcessExitHandlingOptions>(options => options.FastKillOnProcessExit = false);
                })
                                  .ConfigureAppConfiguration((hostContext, builder) =>
                {
                    if (config is IConfigurationRoot root)
                    {
                        foreach (var provider in root.Providers)
                        {
                            builder.Add(new Source(provider));
                        }
                    }
                });

                config.ConfigureByOption("orleans:clustering", new Options
                {
                    ["MongoDB"] = () =>
                    {
                        hostBuilder.ConfigureEndpoints(Dns.GetHostName(), 11111, 40000, listenOnAnyHostAddress: true);

                        var mongoConfiguration = config.GetRequiredValue("store:mongoDb:configuration");
                        var mongoDatabaseName  = config.GetRequiredValue("store:mongoDb:database");

                        hostBuilder.UseMongoDBClustering(options =>
                        {
                            options.ConnectionString = mongoConfiguration;
                            options.CollectionPrefix = "Orleans_";
                            options.DatabaseName     = mongoDatabaseName;
                        });
                    },
                    ["Development"] = () =>
                    {
                        hostBuilder.UseLocalhostClustering(gatewayPort: 40000, clusterId: "squidex");
                        hostBuilder.Configure <ClusterMembershipOptions>(options => options.ExpectedClusterSize = 1);
                    }
                });

                config.ConfigureByOption("store:type", new Options
                {
                    ["MongoDB"] = () =>
                    {
                        var mongoConfiguration = config.GetRequiredValue("store:mongoDb:configuration");
                        var mongoDatabaseName  = config.GetRequiredValue("store:mongoDb:database");

                        hostBuilder.UseMongoDBReminders(options =>
                        {
                            options.ConnectionString = mongoConfiguration;
                            options.CollectionPrefix = "Orleans_";
                            options.DatabaseName     = mongoDatabaseName;
                        });
                    }
                });

                return(hostBuilder.Build());
            });
        }
Exemple #3
0
        public SiloWrapper(IConfiguration config, ISemanticLog log, IApplicationLifetime lifetime)
        {
            this.lifetime = lifetime;
            this.log      = log;

            lazySilo = new Lazy <ISiloHost>(() =>
            {
                var hostBuilder = new SiloHostBuilder()
                                  .UseDashboard(options => options.HostSelf = false)
                                  .EnableDirectClient()
                                  .AddIncomingGrainCallFilter <LocalCacheFilter>()
                                  .AddStartupTask <InitializerStartup>()
                                  .AddStartupTask <Bootstrap <IContentSchedulerGrain> >()
                                  .AddStartupTask <Bootstrap <IEventConsumerManagerGrain> >()
                                  .AddStartupTask <Bootstrap <IRuleDequeuerGrain> >()
                                  .AddStartupTask <Bootstrap <IUsageTrackerGrain> >()
                                  .Configure <ClusterOptions>(options =>
                {
                    options.Configure();
                })
                                  .ConfigureApplicationParts(builder =>
                {
                    builder.AddMyParts();
                })
                                  .ConfigureLogging((hostingContext, builder) =>
                {
                    builder.AddConfiguration(hostingContext.Configuration.GetSection("logging"));
                    builder.AddSemanticLog();
                    builder.AddFilter();
                })
                                  .ConfigureServices((context, services) =>
                {
                    services.AddAppSiloServices(context.Configuration);
                    services.AddAppServices(context.Configuration);

                    services.Configure <ProcessExitHandlingOptions>(options => options.FastKillOnProcessExit = false);
                })
                                  .ConfigureAppConfiguration((hostContext, builder) =>
                {
                    if (config is IConfigurationRoot root)
                    {
                        foreach (var provider in root.Providers)
                        {
                            builder.Add(new Source(provider));
                        }
                    }
                });

                config.ConfigureByOption("orleans:clustering", new Options
                {
                    ["MongoDB"] = () =>
                    {
                        hostBuilder.ConfigureEndpoints(Dns.GetHostName(), 11111, 40000, listenOnAnyHostAddress: true);

                        var mongoConfiguration = config.GetRequiredValue("store:mongoDb:configuration");
                        var mongoDatabaseName  = config.GetRequiredValue("store:mongoDb:database");

                        hostBuilder.UseMongoDBClustering(options =>
                        {
                            options.ConnectionString = mongoConfiguration;
                            options.CollectionPrefix = "Orleans_";
                            options.DatabaseName     = mongoDatabaseName;
                        });
                    },
                    ["Development"] = () =>
                    {
                        hostBuilder.UseLocalhostClustering(gatewayPort: 40000, serviceId: Constants.OrleansClusterId, clusterId: Constants.OrleansClusterId);
                        hostBuilder.Configure <ClusterMembershipOptions>(options => options.ExpectedClusterSize = 1);
                    }
                });

                config.ConfigureByOption("store:type", new Options
                {
                    ["MongoDB"] = () =>
                    {
                        var mongoConfiguration = config.GetRequiredValue("store:mongoDb:configuration");
                        var mongoDatabaseName  = config.GetRequiredValue("store:mongoDb:database");

                        hostBuilder.UseMongoDBReminders(options =>
                        {
                            options.ConnectionString = mongoConfiguration;
                            options.CollectionPrefix = "Orleans_";
                            options.DatabaseName     = mongoDatabaseName;
                        });
                    }
                });

                var silo = hostBuilder.Build();

                silo.Stopped.ContinueWith(x =>
                {
                    if (!isStopping)
                    {
                        lifetime.StopApplication();
                    }
                });

                return(silo);
            });
        }
        public static IServiceProvider AddAndBuildOrleans(this IServiceCollection services, IConfiguration config, Action <IServiceCollection> afterServices)
        {
            services.Configure <ClusterOptions>(options =>
            {
                options.Configure();
            });

            services.Configure <ProcessExitHandlingOptions>(options =>
            {
                options.FastKillOnProcessExit = false;
            });

            services.AddServicesForSelfHostedDashboard(null, options =>
            {
                options.HideTrace = true;
            });

            services.AddHostedService <SiloHost>();

            var hostBuilder = new SiloHostBuilder()
                              .UseDashboardEx()
                              .EnableDirectClient()
                              .AddIncomingGrainCallFilter <LocalCacheFilter>()
                              .AddStartupTask <Bootstrap <IContentSchedulerGrain> >()
                              .AddStartupTask <Bootstrap <IEventConsumerManagerGrain> >()
                              .AddStartupTask <Bootstrap <IRuleDequeuerGrain> >()
                              .AddStartupTask <Bootstrap <IUsageTrackerGrain> >()
                              .ConfigureApplicationParts(builder =>
            {
                builder.AddMyParts();
            });

            var gatewayPort = config.GetOptionalValue("orleans:gatewayPort", 40000);

            var siloPort = config.GetOptionalValue("orleans:siloPort", 11111);

            config.ConfigureByOption("orleans:clustering", new Options
            {
                ["MongoDB"] = () =>
                {
                    hostBuilder.ConfigureEndpoints(Dns.GetHostName(), siloPort, gatewayPort, listenOnAnyHostAddress: true);

                    var mongoConfiguration = config.GetRequiredValue("store:mongoDb:configuration");
                    var mongoDatabaseName  = config.GetRequiredValue("store:mongoDb:database");

                    hostBuilder.UseMongoDBClustering(options =>
                    {
                        options.ConnectionString = mongoConfiguration;
                        options.CollectionPrefix = "Orleans_";
                        options.DatabaseName     = mongoDatabaseName;
                    });
                },
                ["Development"] = () =>
                {
                    hostBuilder.UseLocalhostClustering(siloPort, gatewayPort, null, Constants.OrleansClusterId, Constants.OrleansClusterId);
                    hostBuilder.Configure <ClusterMembershipOptions>(options => options.ExpectedClusterSize = 1);
                }
            });

            config.ConfigureByOption("store:type", new Options
            {
                ["MongoDB"] = () =>
                {
                    var mongoConfiguration = config.GetRequiredValue("store:mongoDb:configuration");
                    var mongoDatabaseName  = config.GetRequiredValue("store:mongoDb:database");

                    hostBuilder.UseMongoDBReminders(options =>
                    {
                        options.ConnectionString = mongoConfiguration;
                        options.CollectionPrefix = "Orleans_";
                        options.DatabaseName     = mongoDatabaseName;
                    });
                }
            });

            IServiceProvider provider = null;

            hostBuilder.UseServiceProviderFactory((siloServices) =>
            {
                foreach (var descriptor in services)
                {
                    siloServices.Add(descriptor);
                }

                afterServices(siloServices);

                provider = siloServices.BuildServiceProvider();

                return(provider);
            }).Build();

            return(provider);
        }
Exemple #5
0
        private static ISiloHost ConfigureSilo()
        {
            var builder = new ConfigurationBuilder()
                          .AddJsonFile($"appsettings.json", true, true)
                          .AddJsonFile($"appsettings.{EnvironmentName}.json", true, true)
                          .AddEnvironmentVariables();

            Configuration = builder.Build();

            var siloHostBuilder = new SiloHostBuilder();

            BsonClassMap.RegisterClassMap <AccountEvent>(cm =>
            {
                cm.AutoMap();
                cm.SetIsRootClass(true);
            });

            BsonClassMap.RegisterClassMap <AccountNameEvent>();
            BsonClassMap.RegisterClassMap <DepositEvent>();
            BsonClassMap.RegisterClassMap <NewStakeholderEvent>();
            BsonClassMap.RegisterClassMap <NewTransactionEvent>();
            BsonClassMap.RegisterClassMap <WithdrawEvent>();
            IMongoDatabase database;


            siloHostBuilder.Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "dev";
                options.ServiceId = "bancor-silohost";
            });

            switch (EnvironmentName)
            {
            case "Integration":
                siloHostBuilder
                .UseConsulClustering(options => { options.Address = new Uri("http://consul:8500"); })
                .ConfigureEndpoints(siloPort: 11111, gatewayPort: 30000);
                database = new MongoDbFactory().Create();
                break;

            case "Development":
                siloHostBuilder
                .UseLocalhostClustering()
                .Configure <EndpointOptions>(options => options.AdvertisedIPAddress = IPAddress.Loopback);
                database = new MongoDbFactory().Create("mongodb://localhost:27017");
                break;

            default:
                throw new Exception($"Unknown environment '{EnvironmentName}'");
            }


            siloHostBuilder.Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "dev";
                options.ServiceId = "bancor";
            })
            .ConfigureServices(s => s.TryAddSingleton <IGrainStorage, MongoCustomerStorageProvider>())
            .ConfigureServices(s => s.TryAddTransient <ICustomerRepository, CustomerRepository>())
            .ConfigureServices(s => s.TryAddSingleton(database))
            .ConfigureServices(s => s.TryAddTransient <IJournaldAccountRepository, JournalAccountRepository>())
            .ConfigureServices(s =>
                               s.AddSingletonNamedService <IGrainStorage>("CustomerStorageProvider",
                                                                          (x, y) => new MongoCustomerStorageProvider(database,
                                                                                                                     (IGrainFactory)x.GetService(typeof(IGrainFactory)))))
            .ConfigureLogging(logging => logging.AddConsole())
            .AddMemoryGrainStorageAsDefault()
            .AddSimpleMessageStreamProvider("SMSProvider")
            .AddMemoryGrainStorage("PubSubStore")
            .AddCustomStorageBasedLogConsistencyProvider("CustomStorage")
            .UseTransactions();

            var host = siloHostBuilder.Build();

            return(host);
        }
Exemple #6
0
        void BuildSiloHost()
        {
            var instrumentationKey           = _configuration.GetValue <string>("ApplicationInsights:InstrumentationKey");
            var hostname                     = _configuration.GetValue <string>("HOSTNAME");
            var azureStorageConnectionString = _configuration.GetValue <string>("Storage:AzureStorageConnectionString");
            var redisClusteringUrl           = _configuration.GetValue <string>("REDIS_URL");

            var builder = new SiloHostBuilder()
                          .ConfigureLogging(loggingBuilder =>
            {
                if (!string.IsNullOrEmpty(instrumentationKey))
                {
                    loggingBuilder.AddApplicationInsights(instrumentationKey);
                }
                loggingBuilder.AddConsole();
            })
                          // Configure ClusterId and ServiceId
                          .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = "dev";
                options.ServiceId = "TwitchServices";
            })
                          .AddStartupTask <LoadConfigurationStartupTask>()
                          .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(ChannelGrain).Assembly).WithReferences())
                          // Configure connectivity
                          .ConfigureEndpoints(hostname: hostname, siloPort: 11111, gatewayPort: 30000);

            if (!string.IsNullOrEmpty(azureStorageConnectionString))
            {
                builder.AddAzureTableGrainStorage("profileStore", (AzureTableStorageOptions options) =>
                {
                    options.ConnectionString = azureStorageConnectionString;
                    options.TableName        = "profiles";
                    options.UseJson          = true;
                    options.IndentJson       = false;
                });
                builder.AddAzureTableGrainStorage("channelStore", (AzureTableStorageOptions options) =>
                {
                    options.ConnectionString = azureStorageConnectionString;
                    options.TableName        = "channels";
                    options.UseJson          = true;
                    options.IndentJson       = false;
                });
                builder.AddAzureTableGrainStorage("botSettingsStore", (AzureTableStorageOptions options) =>
                {
                    options.ConnectionString = azureStorageConnectionString;
                    options.TableName        = "botsettings";
                    options.UseJson          = true;
                    options.IndentJson       = false;
                });
                builder.AddCustomCategoriesStorage("customCategoriesStore", (CustomCategoriesStorageOptions options) =>
                {
                    options.ConnectionString = azureStorageConnectionString;
                    options.TableName        = "customcategories";
                });
            }
            else
            {
                builder.AddMemoryGrainStorage("profileStore");
                builder.AddMemoryGrainStorage("channelStore");
                builder.AddMemoryGrainStorage("botSettingsStore");
                builder.AddMemoryGrainStorage("customCategoriesStore");
            }

            if (!string.IsNullOrEmpty(redisClusteringUrl))
            {
                // Use redis clustering when available
                builder.UseRedisClustering(redisClusteringUrl);
            }
            else
            {
                // Use localhost clustering for a single local silo
                builder.UseLocalhostClustering(11111, 30000, null, "TwitchServices", "dev");
            }

            // Temp

            builder.ConfigureServices((context, services) =>
            {
                // Load channels and command configuration from static json file, and inject
                var channelsConfig = new ConfigurationBuilder().AddJsonFile("channels.json").Build();
                IEnumerable <ChannelOptions> channelOptions = new List <ChannelOptions>();
                channelsConfig.GetSection("channels").Bind(channelOptions);
                services.AddTransient <IEnumerable <ChannelOptions> >((_) => channelOptions);

                // Configure services
                services.AddHttpClient();
                services.Configure <TwitchApplicationOptions>(_configuration.GetSection("twitch"));
                services.Configure <TwitchChatClientOptions>(_configuration.GetSection("twitch").GetSection("IrcOptions"));
                services.Configure <AzureGameLocalizationStoreOptions>(_configuration.GetSection("loc:azure"));
                services.AddSingleton <IMessageProcessor, TracingMessageProcessor>();
                services.AddTransient <TwitchChatClient>();
                services.AddTransient <TwitchAPIClient>();
                services.AddTransient <IGDBClient>();
                services.AddSingleton <IMemoryCache, MemoryCache>();
                services.AddSingleton <SteamStoreClient>();
                services.AddSingleton <IAuthenticated>(s =>
                                                       Twitch.Authenticate()
                                                       .FromAppCredentials(
                                                           s.GetService <IOptions <TwitchApplicationOptions> >().Value.ClientId,
                                                           s.GetService <IOptions <TwitchApplicationOptions> >().Value.ClientSecret)
                                                       .Build()
                                                       );
                services.AddTransient <ITwitchCategoryProvider, GrainTwitchCategoryProvider>();
                services.AddSingleton <IGameLocalizationStore, AzureStorageGameLocalizationStore>();
                services.PostConfigure <TwitchChatClientOptions>(options =>
                {
                    var oauth = Twitch.Authenticate()
                                .FromOAuthToken(options.OAuthToken)
                                .Build();
                    var loggerFactory = new LoggerFactory();
                    using (var httpClient = new HttpClient())
                        using (var apiClient = TwitchAPIClient.Create(oauth))
                        {
                            options.TokenInfo = apiClient.ValidateToken().Result;
                        }
                });

                // Configure commands
                services.AddCommand <GameSynopsisCommand>("GameSynopsis");
                services.AddCommand <TracingMessageProcessor>("Logger");
                services.AddCommand <ResponseCommandProcessor>("Response");
            });
            _siloHost = builder.Build();
        }
Exemple #7
0
        private static async Task <ISiloHost> StartSilo()
        {
            var baseDir = Path.Combine(AppContext.BaseDirectory);

            Configuration = AppConfiguration.GetIConfigurationRoot(baseDir);

            var appOptions       = AppConfiguration.GetApplicationConfiguration(baseDir);
            var dashboardOptions = AppConfiguration.GetConfiguration <DashboardOptions>(baseDir, "Dashboard");
            // define the cluster configuration
            var builder = new SiloHostBuilder();

            switch (appOptions.StorageType)
            {
            case StorageType.AzureTable:
                builder.AddAzureTableGrainStorage(Constants.StorageName, options =>
                {
                    options.ConnectionString = appOptions.OrleansConnectionString;
                    options.TableName        = appOptions.AzureTableName;
                    options.UseJson          = appOptions.UseJson;
                });
                builder.UseAzureTableReminderService(options => {
                    options.ConnectionString = appOptions.OrleansConnectionString;
                });
                break;

            default:
                builder.AddAdoNetGrainStorage(Constants.StorageName, options =>
                {
                    options.Invariant        = appOptions.AdoInvariant;
                    options.ConnectionString = appOptions.OrleansConnectionString;
                    options.UseJsonFormat    = appOptions.UseJson;
                });
                builder.UseAdoNetReminderService(options => {
                    options.ConnectionString = appOptions.OrleansConnectionString;
                });
                break;
            }
            builder.UseLocalhostClustering()
            .Configure <ClusterOptions>(options =>
            {
                options.ClusterId = appOptions.ClusterId;
                options.ServiceId = appOptions.ServiceId;
            })
            .Configure <EndpointOptions>(options => options.AdvertisedIPAddress = IPAddress.Loopback)
            .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IGrainMarker).Assembly).WithReferences())
            .AddSimpleMessageStreamProvider(Constants.StreamProvider)
            .AddMemoryGrainStorage(Constants.StreamStorage)
            .ConfigureServices((service) => {
                service.Configure <ApplicationOptions>(Configuration);
                service.AddOptions();
                service.AddSingleton <ApplicationOptions>(appOptions);
                DependencyInjectionHelper.IocContainerRegistration(service);
            })
            .ConfigureLogging(logging => logging.AddConsole())
            .UseDashboard(options => {
                options.Host     = dashboardOptions.Host;
                options.Port     = dashboardOptions.Port;
                options.HostSelf = dashboardOptions.HostSelf;
                options.CounterUpdateIntervalMs = dashboardOptions.CounterUpdateIntervalMs;
            });
            var host = builder.Build();
            await host.StartAsync();

            return(host);
        }