Ejemplo n.º 1
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);
            });
        }
Ejemplo n.º 2
0
        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());
            });
        }
Ejemplo n.º 3
0
        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);
        }