Beispiel #1
0
        /// <summary>
        /// Initialize this silo.
        /// </summary>
        public void InitializeOrleansSilo()
        {
            try
            {
                if (!ConfigLoaded)
                {
                    LoadOrleansConfig();
                }
                var builder = new SiloHostBuilder()
                              .ConfigureSiloName(Name)
                              .UseConfiguration(Config)
                              .ConfigureApplicationParts(parts => parts
                                                         .AddFromAppDomain()
                                                         .AddFromApplicationBaseDirectory());

                if (!string.IsNullOrWhiteSpace(Config.Defaults.StartupTypeName))
                {
                    builder.UseServiceProviderFactory(services =>
                                                      StartupBuilder.ConfigureStartup(Config.Defaults.StartupTypeName, services));
                }

                var host = builder.Build();

                orleans = host.Services.GetRequiredService <Silo>();
                var localConfig = host.Services.GetRequiredService <NodeConfiguration>();

                logger.Info(ErrorCode.Runtime_Error_100288, "Successfully initialized Orleans silo '{0}'.", orleans.Name);
            }
            catch (Exception exc)
            {
                ReportStartupError(exc);
                orleans = null;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Initialize this silo.
        /// </summary>
        public void InitializeOrleansSilo()
        {
            try
            {
                if (!this.ConfigLoaded)
                {
                    LoadOrleansConfig();
                }
                var builder = new SiloHostBuilder()
                              .Configure <SiloOptions>(options => options.SiloName = this.Name)
                              .UseConfiguration(this.Config);

                if (!string.IsNullOrWhiteSpace(this.Config.Defaults.StartupTypeName))
                {
                    builder.UseServiceProviderFactory(services =>
                                                      StartupBuilder.ConfigureStartup(this.Config.Defaults.StartupTypeName, services));
                }

                var host = builder.Build();

                this.orleans = host.Services.GetRequiredService <Silo>();
                var localConfig = host.Services.GetRequiredService <NodeConfiguration>();

                this.logger.Info(ErrorCode.Runtime_Error_100288, "Successfully initialized Orleans silo '{0}'.", this.orleans.Name);
            }
            catch (Exception exc)
            {
                ReportStartupError(exc);
                this.orleans = null;
            }
        }
Beispiel #3
0
            public async Task StartAsync(CancellationToken cancellationToken)
            {
                var siloHostBuilder = new SiloHostBuilder();

                _configure(_provider, siloHostBuilder);
                var parentScope = _provider.GetRequiredService <ILifetimeScope>();

                siloHostBuilder.UseServiceProviderFactory(cs =>
                {
                    _scope = parentScope.BeginLifetimeScope(cb => { cb.Populate(cs); });
                    return(new AutofacServiceProvider(_scope));
                });
                _siloHost = siloHostBuilder.Build();
                await _siloHost.StartAsync(cancellationToken);
            }
Beispiel #4
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);
        }