Exemple #1
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;
            }
        }
Exemple #2
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;
            }
        }
        public void ShouldRegisterConfigureModuleViaConfiguration()
        {
            var sut     = new ManualLocatorConfigure();
            var builder = StartupBuilder.Create();

            builder
            .ConfigureAssemblies(assemblies =>
            {
                assemblies
                .WithAssembliesFromTypes(typeof(StringLogger), typeof(RegistrationConfiguration))
                .WithAssemblyFromType <DryIocLocatorFactory>();
            })
            .ConfigureStartupModules(modules =>
            {
                modules
                .ConfigureLocatorModuleCollection(configureModules =>
                {
                    configureModules.Add(sut);
                })
                .RemoveConfigureModule <BadConfigureModule>();
            })
            .Build(useApplicationContext: false)
            .Run();

            Assert.IsTrue(sut.Executed);
        }
Exemple #4
0
        public static void Setup(TestContext context)
        {
            var builder = StartupBuilder.Create();

            builder
            .UseEnvironment(new UnitTestEnvironment())
            .ConfigureStartupModules(x => x.RemoveStartupModule <Mocks.ExcludeModule>())
            .ConfigureAssemblies(assemblies =>
            {
                assemblies
                .WithAssemblyFromType <Mocks.FooService>()
                .WithAssemblyFromType <StartupBuilder>()
                .WithAssemblyFromType <RegistrationConfiguration>();
            })
            .OverrideDefaults(d =>
            {
                d
                .UseAssemblyFilter(new Mocks.TestAssemblyFilter())
                .UseLogger(new Mocks.TestLogger());
            })
            .AddLocatorAssembly()
            .Build()
            .Run();

            TestContext = builder.StartupContext;
        }
 public void ShouldExecuteFromDefaults()
 {
     // only using discoverable assemblies to remove bad modules for unit testing
     StartupBuilder.Create().Build(useDiscoverableAssemblies: true).Run();
     Assert.IsNotNull(ApplicationContext.Default);
     Internal.UnitTestHelper.ResetApplication();
 }
Exemple #6
0
        private static void AddStartupEnvironmentsWithServices(string solutionDirectory, ApiTemplate template)
        {
            // add a development environment by default for local work if none exists
            if (template.Environments.Where(e => e.EnvironmentName == "Development").Count() == 0)
            {
                template.Environments.Add(new ApiEnvironment {
                    EnvironmentName = "Development", ProfileName = $"{template.SolutionName} (Development)"
                });
            }

            foreach (var env in template.Environments)
            {
                // default startup is already built in cleanup phase
                if (env.EnvironmentName != "Startup")
                {
                    StartupBuilder.CreateStartup(solutionDirectory, env.EnvironmentName, template);
                }

                AppSettingsBuilder.CreateAppSettings(solutionDirectory, env, template.DbContext.DatabaseName, template);
                LaunchSettingsModifier.AddProfile(solutionDirectory, env);

                //services
                if (!template.SwaggerConfig.IsSameOrEqualTo(new SwaggerConfig()))
                {
                    SwaggerBuilder.RegisterSwaggerInStartup(solutionDirectory, env);
                }
            }
        }
Exemple #7
0
        public static void AddStartupEnvironmentsWithServices(
            string solutionDirectory,
            string solutionName,
            string dbName,
            List <ApiEnvironment> environments,
            SwaggerConfig swaggerConfig,
            int port,
            bool useJwtAuth,
            string projectBaseName = "")
        {
            // add a development environment by default for local work if none exists
            if (environments.Where(e => e.EnvironmentName == "Development").Count() == 0)
            {
                environments.Add(new ApiEnvironment {
                    EnvironmentName = "Development", ProfileName = $"{solutionName} (Development)"
                });
            }

            if (environments.Where(e => e.EnvironmentName == "Production").Count() == 0)
            {
                environments.Add(new ApiEnvironment {
                    EnvironmentName = "Production", ProfileName = $"{solutionName} (Production)"
                });
            }

            var sortedEnvironments = environments.OrderBy(e => e.EnvironmentName == "Development" ? 1 : 0).ToList(); // sets dev as default profile

            foreach (var env in sortedEnvironments)
            {
                // default startup is already built in cleanup phase
                if (env.EnvironmentName != "Production")
                {
                    StartupBuilder.CreateWebApiStartup(solutionDirectory, env.EnvironmentName, useJwtAuth, projectBaseName);
                }

                WebApiAppSettingsBuilder.CreateAppSettings(solutionDirectory, env, dbName, projectBaseName);
                WebApiLaunchSettingsModifier.AddProfile(solutionDirectory, env, port, projectBaseName);

                //services
                if (!swaggerConfig.IsSameOrEqualTo(new SwaggerConfig()))
                {
                    SwaggerBuilder.RegisterSwaggerInStartup(solutionDirectory, env, projectBaseName);
                }
            }

            // add an integration testing env to make sure that an in memory database is used
            var functionalEnv = new ApiEnvironment()
            {
                EnvironmentName = "FunctionalTesting"
            };

            WebApiAppSettingsBuilder.CreateAppSettings(solutionDirectory, functionalEnv, "", projectBaseName);
        }
Exemple #8
0
        protected virtual Tuple <string[], string[]> StartupParameters()
        {
            var startupBuilder = new StartupBuilder(this);

            return(startupBuilder.GetStartupParameters(new StartupBuilderSpec {
                GamePath = InstalledState.Directory,
                GameVersion = GetVersion(),
                Mission = CalculatedSettings.Mission,
                Server = ShouldConnectToServer() ? CalculatedSettings.Server : null,
                StartupParameters = Settings.StartupParameters.Get(),
                UseParFile = true
            }));
        }
Exemple #9
0
        public void GetStartupText_Development_env_returns_expected_text()
        {
            var fileText = StartupBuilder.GetStartupText("", "WebApi", "Development", false, "MyBc");

            var expectedText = @$ "namespace WebApi
{{
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using MyBc.Infrastructure;
    using MyBc.Infrastructure.Seeders;
    using MyBc.Infrastructure.Contexts;
    using MyBc.WebApi.Extensions;
    using Serilog;
Exemple #10
0
        // will probably want to refactor this in the future when there is > 1 startup based on env
        public static void CleanStartup(string solutionDirectory, ApiTemplate template)
        {
            var classPath = ClassPathHelper.StartupClassPath(solutionDirectory, "Startup.cs");

            if (!Directory.Exists(classPath.ClassDirectory))
            {
                throw new DirectoryNotFoundException($"The `{classPath.ClassDirectory}` directory could not be found.");
            }

            if (!File.Exists(classPath.FullClassPath))
            {
                throw new FileNotFoundException($"The `{classPath.FullClassPath}` file could not be found.");
            }

            File.Delete(classPath.FullClassPath);

            StartupBuilder.CreateStartup(solutionDirectory, "Startup", template);
        }
Exemple #11
0
        public void GetStartupText_Devlopment_env_returns_expected_text()
        {
            var template = new ApiTemplate()
            {
            };
            var fileText = StartupBuilder.GetStartupText("Development", template);

            var expectedText = @$ "namespace WebApi
{{
    using Application;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Infrastructure.Persistence;
    using Infrastructure.Shared;
    using Infrastructure.Persistence.Seeders;
    using Infrastructure.Persistence.Contexts;
    using WebApi.Extensions;
Exemple #12
0
        public static void AddAuthServer(string solutionDirectory, IFileSystem fileSystem, AuthServerTemplate template)
        {
            SolutionBuilder.BuildAuthServerProject(solutionDirectory, template.Name, fileSystem);

            AuthServerLaunchSettingsBuilder.CreateLaunchSettings(solutionDirectory, template.Name, template.Port, fileSystem);
            StartupBuilder.CreateAuthServerStartup(solutionDirectory, template.Name, fileSystem);
            ProgramBuilder.CreateAuthServerProgram(solutionDirectory, template.Name, fileSystem);
            AuthServerConfigBuilder.CreateConfig(solutionDirectory, template, fileSystem);
            AppSettingsBuilder.CreateAuthServerAppSettings(solutionDirectory, template.Name, fileSystem);

            AuthServerPackageJsonBuilder.CreatePackageJson(solutionDirectory, template.Name, fileSystem);
            AuthServerTailwindConfigBuilder.CreateTailwindConfig(solutionDirectory, template.Name, fileSystem);
            AuthServerPostCssBuilder.CreatePostCss(solutionDirectory, template.Name, fileSystem);

            // controllers
            AuthServerAccountControllerBuilder.CreateAccountController(solutionDirectory, template.Name, fileSystem);
            AuthServerExternalControllerBuilder.CreateExternalController(solutionDirectory, template.Name, fileSystem);
            // AuthServerHomeControllerBuilder.CreateHomeController(projectDirectory, template.Name, fileSystem);

            // view models + models
            AuthServerAccountViewModelsBuilder.CreateViewModels(solutionDirectory, template.Name, fileSystem);
            AuthServerSharedViewModelsBuilder.CreateViewModels(solutionDirectory, template.Name, fileSystem);
            AuthServerExternalModelsBuilder.CreateModels(solutionDirectory, template.Name, fileSystem);
            AuthServerAccountModelsBuilder.CreateModels(solutionDirectory, template.Name, fileSystem);

            // views
            AuthServerAccountViewsBuilder.CreateLoginView(solutionDirectory, template.Name, fileSystem);
            AuthServerAccountViewsBuilder.CreateLogoutView(solutionDirectory, template.Name, fileSystem);
            AuthServerAccountViewsBuilder.CreateAccessDeniedView(solutionDirectory, template.Name, fileSystem);
            AuthServerSharedViewsBuilder.CreateLayoutView(solutionDirectory, template.Name, fileSystem);
            AuthServerSharedViewsBuilder.CreateStartView(solutionDirectory, template.Name, fileSystem);
            AuthServerSharedViewsBuilder.CreateViewImports(solutionDirectory, template.Name, fileSystem);

            // css files for TW
            AuthServerCssBuilder.CreateOutputCss(solutionDirectory, template.Name, fileSystem);
            AuthServerCssBuilder.CreateSiteCss(solutionDirectory, template.Name, fileSystem);

            // helpers
            AuthServerTestUsersBuilder.CreateTestModels(solutionDirectory, template.Name, fileSystem);
            AuthServerExtensionsBuilder.CreateExtensions(solutionDirectory, template.Name, fileSystem);
            SecurityHeadersAttributeBuilder.CreateAttribute(solutionDirectory, template.Name, fileSystem);
        }
        public static StartupBuilder AddLocatorAssembly(this StartupBuilder builder)
        {
#if DRYIOC_LOCATOR
            builder.ConfigureAssemblies(a => a.WithAssemblyFromType <DotNetStarter.Locators.DryIocLocatorFactory>());
#elif STRUCTUREMAP_LOCATOR
            builder.ConfigureAssemblies(a => a.WithAssemblyFromType <DotNetStarter.Locators.StructureMapFactory>());
#elif STRUCTUREMAPSIGNED_LOCATOR
            builder.ConfigureAssemblies(a => a.WithAssemblyFromType <DotNetStarter.Locators.StructureMapSignedFactory>());
#elif LIGHTINJECT_LOCATOR
            builder.ConfigureAssemblies(a => a.WithAssemblyFromType <DotNetStarter.Locators.LightInjectLocatorRegistryFactory>());
#elif GRACE_LOCATOR
            builder.ConfigureAssemblies(a => a.WithAssemblyFromType <DotNetStarter.Locators.GraceLocatorRegistryFactory>());
#elif LAMAR_LOCATOR
            builder.ConfigureAssemblies(a => a.WithAssemblyFromType <DotNetStarter.Locators.LamarLocatorRegistryFactory>());
#elif AUTOFAC_LOCATOR
            builder.ConfigureAssemblies(a => a.WithAssemblyFromType <DotNetStarter.Locators.AutofacLocatorRegistryFactory>());
#elif STASHBOX_LOCATOR
            builder.ConfigureAssemblies(a => a.WithAssemblyFromType <DotNetStarter.Locators.StashboxLocatorRegistryFactory>());
#else
            throw new Exception("Container not setup for tests!");
#endif
            return(builder);
        }
        public static StartupBuilder UseTestLocator(this StartupBuilder builder)
        {
#if DRYIOC_LOCATOR
            builder.OverrideDefaults(d => d.UseLocatorRegistryFactory(new DotNetStarter.Locators.DryIocLocatorFactory()));
#elif STRUCTUREMAP_LOCATOR
            builder.OverrideDefaults(d => d.UseLocatorRegistryFactory(new DotNetStarter.Locators.StructureMapFactory()));
#elif STRUCTUREMAPSIGNED_LOCATOR
            builder.OverrideDefaults(d => d.UseLocatorRegistryFactory(new DotNetStarter.Locators.StructureMapSignedFactory()));
#elif LIGHTINJECT_LOCATOR
            builder.OverrideDefaults(d => d.UseLocatorRegistryFactory(new DotNetStarter.Locators.LightInjectLocatorRegistryFactory()));
#elif GRACE_LOCATOR
            builder.OverrideDefaults(d => d.UseLocatorRegistryFactory(new DotNetStarter.Locators.GraceLocatorRegistryFactory()));
#elif LAMAR_LOCATOR
            builder.OverrideDefaults(d => d.UseLocatorRegistryFactory(new DotNetStarter.Locators.LamarLocatorRegistryFactory()));
#elif AUTOFAC_LOCATOR
            builder.OverrideDefaults(d => d.UseLocatorRegistryFactory(new DotNetStarter.Locators.AutofacLocatorRegistryFactory()));
#elif STASHBOX_LOCATOR
            builder.OverrideDefaults(d => d.UseLocatorRegistryFactory(new DotNetStarter.Locators.StashboxLocatorRegistryFactory()));
#else
            throw new Exception("Container not setup for tests!");
#endif
            return(builder);
        }
 public static IApplicationBuilder UsePole(this IApplicationBuilder applicationBuilder)
 {
     StartupBuilder.StartPole(applicationBuilder.ApplicationServices).GetAwaiter().GetResult();
     return(applicationBuilder);
 }
Exemple #16
0
        internal Silo(SiloInitializationParameters initializationParams, IServiceProvider services)
        {
            string name = initializationParams.Name;
            ClusterConfiguration config = initializationParams.ClusterConfig;

            this.initializationParams = initializationParams;

            this.SystemStatus      = SystemStatus.Creating;
            AsynchAgent.IsStarting = true;

            var startTime = DateTime.UtcNow;

            services?.GetService <TelemetryManager>()?.AddFromConfiguration(services, LocalConfig.TelemetryConfiguration);
            StatisticsCollector.Initialize(LocalConfig);

            initTimeout = GlobalConfig.MaxJoinAttemptTime;
            if (Debugger.IsAttached)
            {
                initTimeout = StandardExtensions.Max(TimeSpan.FromMinutes(10), GlobalConfig.MaxJoinAttemptTime);
                stopTimeout = initTimeout;
            }

            var localEndpoint = this.initializationParams.SiloAddress.Endpoint;

            // Configure DI using Startup type
            if (services == null)
            {
                var serviceCollection = new ServiceCollection();
                serviceCollection.AddSingleton <Silo>(this);
                serviceCollection.AddSingleton(initializationParams);
                serviceCollection.AddLegacyClusterConfigurationSupport(config);
                serviceCollection.Configure <SiloIdentityOptions>(options => options.SiloName = name);
                var hostContext = new HostBuilderContext(new Dictionary <object, object>());
                DefaultSiloServices.AddDefaultServices(hostContext, serviceCollection);

                var applicationPartManager = hostContext.GetApplicationPartManager();
                applicationPartManager.AddApplicationPartsFromAppDomain();
                applicationPartManager.AddApplicationPartsFromBasePath();

                services = StartupBuilder.ConfigureStartup(this.LocalConfig.StartupTypeName, serviceCollection);
                services.GetService <TelemetryManager>()?.AddFromConfiguration(services, LocalConfig.TelemetryConfiguration);
            }

            services.GetService <SerializationManager>().RegisterSerializers(services.GetService <ApplicationPartManager>());

            this.Services = services;
            this.Services.InitializeSiloUnobservedExceptionsHandler();
            //set PropagateActivityId flag from node cofnig
            RequestContext.PropagateActivityId = this.initializationParams.NodeConfig.PropagateActivityId;
            this.loggerFactory = this.Services.GetRequiredService <ILoggerFactory>();
            logger             = this.loggerFactory.CreateLogger <Silo>();

            logger.Info(ErrorCode.SiloGcSetting, "Silo starting with GC settings: ServerGC={0} GCLatencyMode={1}", GCSettings.IsServerGC, Enum.GetName(typeof(GCLatencyMode), GCSettings.LatencyMode));
            if (!GCSettings.IsServerGC)
            {
                logger.Warn(ErrorCode.SiloGcWarning, "Note: Silo not running with ServerGC turned on - recommend checking app config : <configuration>-<runtime>-<gcServer enabled=\"true\">");
                logger.Warn(ErrorCode.SiloGcWarning, "Note: ServerGC only kicks in on multi-core systems (settings enabling ServerGC have no effect on single-core machines).");
            }

            logger.Info(ErrorCode.SiloInitializing, "-------------- Initializing {0} silo on host {1} MachineName {2} at {3}, gen {4} --------------",
                        this.initializationParams.Type, LocalConfig.DNSHostName, Environment.MachineName, localEndpoint, this.initializationParams.SiloAddress.Generation);
            logger.Info(ErrorCode.SiloInitConfig, "Starting silo {0} with the following configuration= " + Environment.NewLine + "{1}",
                        name, config.ToString(name));

            var siloMessagingOptions = this.Services.GetRequiredService <IOptions <SiloMessagingOptions> >();

            BufferPool.InitGlobalBufferPool(siloMessagingOptions);

            try
            {
                grainFactory = Services.GetRequiredService <GrainFactory>();
            }
            catch (InvalidOperationException exc)
            {
                logger.Error(ErrorCode.SiloStartError, "Exception during Silo.Start, GrainFactory was not registered in Dependency Injection container", exc);
                throw;
            }

            // Performance metrics
            siloStatistics = Services.GetRequiredService <SiloStatisticsManager>();

            // The scheduler
            scheduler = Services.GetRequiredService <OrleansTaskScheduler>();
            healthCheckParticipants.Add(scheduler);

            runtimeClient = Services.GetRequiredService <InsideRuntimeClient>();

            // Initialize the message center
            messageCenter = Services.GetRequiredService <MessageCenter>();
            var dispatcher = this.Services.GetRequiredService <Dispatcher>();

            messageCenter.RerouteHandler       = dispatcher.RerouteMessage;
            messageCenter.SniffIncomingMessage = runtimeClient.SniffIncomingMessage;

            // GrainRuntime can be created only here, after messageCenter was created.
            grainRuntime          = Services.GetRequiredService <IGrainRuntime>();
            StreamProviderManager = Services.GetRequiredService <IStreamProviderManager>();

            // Now the router/directory service
            // This has to come after the message center //; note that it then gets injected back into the message center.;
            localGrainDirectory = Services.GetRequiredService <LocalGrainDirectory>();

            // Now the activation directory.
            activationDirectory = Services.GetRequiredService <ActivationDirectory>();

            // Now the consistent ring provider
            RingProvider = Services.GetRequiredService <IConsistentRingProvider>();

            catalog = Services.GetRequiredService <Catalog>();
            siloStatistics.MetricsTable.Scheduler           = scheduler;
            siloStatistics.MetricsTable.ActivationDirectory = activationDirectory;
            siloStatistics.MetricsTable.ActivationCollector = catalog.ActivationCollector;
            siloStatistics.MetricsTable.MessageCenter       = messageCenter;

            executorService = Services.GetRequiredService <ExecutorService>();

            // Now the incoming message agents
            var messageFactory = this.Services.GetRequiredService <MessageFactory>();

            incomingSystemAgent = new IncomingMessageAgent(Message.Categories.System, messageCenter, activationDirectory, scheduler, catalog.Dispatcher, messageFactory, executorService, this.loggerFactory);
            incomingPingAgent   = new IncomingMessageAgent(Message.Categories.Ping, messageCenter, activationDirectory, scheduler, catalog.Dispatcher, messageFactory, executorService, this.loggerFactory);
            incomingAgent       = new IncomingMessageAgent(Message.Categories.Application, messageCenter, activationDirectory, scheduler, catalog.Dispatcher, messageFactory, executorService, this.loggerFactory);

            membershipOracle = Services.GetRequiredService <IMembershipOracle>();

            if (!this.GlobalConfig.HasMultiClusterNetwork)
            {
                logger.Info("Skip multicluster oracle creation (no multicluster network configured)");
            }
            else
            {
                multiClusterOracle = Services.GetRequiredService <IMultiClusterOracle>();
            }

            this.SystemStatus      = SystemStatus.Created;
            AsynchAgent.IsStarting = false;

            StringValueStatistic.FindOrCreate(StatisticNames.SILO_START_TIME,
                                              () => LogFormatter.PrintDate(startTime)); // this will help troubleshoot production deployment when looking at MDS logs.

            var fullSiloLifecycle = this.Services.GetRequiredService <SiloLifecycle>();

            this.siloLifecycle = fullSiloLifecycle;
            IEnumerable <ILifecycleParticipant <ISiloLifecycle> > lifecyleParticipants = this.Services.GetServices <ILifecycleParticipant <ISiloLifecycle> >();

            foreach (ILifecycleParticipant <ISiloLifecycle> participant in lifecyleParticipants)
            {
                participant.Participate(fullSiloLifecycle);
            }
            this.Participate(fullSiloLifecycle);

            logger.Info(ErrorCode.SiloInitializingFinished, "-------------- Started silo {0}, ConsistentHashCode {1:X} --------------", SiloAddress.ToLongString(), SiloAddress.GetConsistentHashCode());
        }
Exemple #17
0
        internal Silo(string name, SiloType siloType, ClusterConfiguration config, ILocalDataStore keyStore)
        {
            SystemStatus.Current = SystemStatus.Creating;

            CurrentSilo = this;

            var startTime = DateTime.UtcNow;

            this.siloType = siloType;
            Name          = name;

            siloTerminatedEvent = new ManualResetEvent(false);

            OrleansConfig = config;
            globalConfig  = config.Globals;
            config.OnConfigChange("Defaults", () => nodeConfig = config.GetOrCreateNodeConfigurationForSilo(name));

            if (!LogManager.IsInitialized)
            {
                LogManager.Initialize(nodeConfig);
            }

            config.OnConfigChange("Defaults/Tracing", () => LogManager.Initialize(nodeConfig, true), false);
            MultiClusterRegistrationStrategy.Initialize(config.Globals);
            ActivationData.Init(config, nodeConfig);
            StatisticsCollector.Initialize(nodeConfig);

            SerializationManager.Initialize(globalConfig.SerializationProviders, this.globalConfig.FallbackSerializationProvider);
            initTimeout = globalConfig.MaxJoinAttemptTime;
            if (Debugger.IsAttached)
            {
                initTimeout = StandardExtensions.Max(TimeSpan.FromMinutes(10), globalConfig.MaxJoinAttemptTime);
                stopTimeout = initTimeout;
            }

            IPEndPoint here       = nodeConfig.Endpoint;
            int        generation = nodeConfig.Generation;

            if (generation == 0)
            {
                generation            = SiloAddress.AllocateNewGeneration();
                nodeConfig.Generation = generation;
            }
            LogManager.MyIPEndPoint = here;
            logger = LogManager.GetLogger("Silo", LoggerType.Runtime);

            logger.Info(ErrorCode.SiloGcSetting, "Silo starting with GC settings: ServerGC={0} GCLatencyMode={1}", GCSettings.IsServerGC, Enum.GetName(typeof(GCLatencyMode), GCSettings.LatencyMode));
            if (!GCSettings.IsServerGC || !GCSettings.LatencyMode.Equals(GCLatencyMode.Batch))
            {
                logger.Warn(ErrorCode.SiloGcWarning, "Note: Silo not running with ServerGC turned on or with GCLatencyMode.Batch enabled - recommend checking app config : <configuration>-<runtime>-<gcServer enabled=\"true\"> and <configuration>-<runtime>-<gcConcurrent enabled=\"false\"/>");
                logger.Warn(ErrorCode.SiloGcWarning, "Note: ServerGC only kicks in on multi-core systems (settings enabling ServerGC have no effect on single-core machines).");
            }

            logger.Info(ErrorCode.SiloInitializing, "-------------- Initializing {0} silo on host {1} MachineName {2} at {3}, gen {4} --------------",
                        siloType, nodeConfig.DNSHostName, Environment.MachineName, here, generation);
            logger.Info(ErrorCode.SiloInitConfig, "Starting silo {0} with the following configuration= " + Environment.NewLine + "{1}",
                        name, config.ToString(name));

            if (keyStore != null)
            {
                // Re-establish reference to shared local key store in this app domain
                LocalDataStoreInstance.LocalDataStore = keyStore;
            }

            // Configure DI using Startup type
            bool usingCustomServiceProvider;

            Services = StartupBuilder.ConfigureStartup(nodeConfig.StartupTypeName, out usingCustomServiceProvider);

            healthCheckParticipants = new List <IHealthCheckParticipant>();
            allSiloProviders        = new List <IProvider>();

            BufferPool.InitGlobalBufferPool(globalConfig);
            PlacementStrategy.Initialize(globalConfig);

            UnobservedExceptionsHandlerClass.SetUnobservedExceptionHandler(UnobservedExceptionHandler);
            AppDomain.CurrentDomain.UnhandledException +=
                (obj, ev) => DomainUnobservedExceptionHandler(obj, (Exception)ev.ExceptionObject);

            try
            {
                grainFactory = Services.GetRequiredService <GrainFactory>();
            }
            catch (InvalidOperationException exc)
            {
                logger.Error(ErrorCode.SiloStartError, "Exception during Silo.Start, GrainFactory was not registered in Dependency Injection container", exc);
                throw;
            }

            typeManager = new GrainTypeManager(
                here.Address.Equals(IPAddress.Loopback),
                grainFactory,
                new SiloAssemblyLoader(OrleansConfig.Defaults.AdditionalAssemblyDirectories));

            // Performance metrics
            siloStatistics = new SiloStatisticsManager(globalConfig, nodeConfig);
            config.OnConfigChange("Defaults/LoadShedding", () => siloStatistics.MetricsTable.NodeConfig = nodeConfig, false);

            // The scheduler
            scheduler = new OrleansTaskScheduler(globalConfig, nodeConfig);
            healthCheckParticipants.Add(scheduler);

            // Initialize the message center
            var mc = new MessageCenter(here, generation, globalConfig, siloStatistics.MetricsTable);

            if (nodeConfig.IsGatewayNode)
            {
                mc.InstallGateway(nodeConfig.ProxyGatewayEndpoint);
            }

            messageCenter = mc;

            SiloIdentity = SiloAddress.ToLongString();

            // GrainRuntime can be created only here, after messageCenter was created.
            grainRuntime = new GrainRuntime(
                globalConfig.ServiceId,
                SiloIdentity,
                grainFactory,
                new TimerRegistry(),
                new ReminderRegistry(),
                new StreamProviderManager(),
                Services);


            // Now the router/directory service
            // This has to come after the message center //; note that it then gets injected back into the message center.;
            localGrainDirectory = new LocalGrainDirectory(this);

            RegistrarManager.InitializeGrainDirectoryManager(localGrainDirectory, globalConfig.GlobalSingleInstanceNumberRetries);

            // Now the activation directory.
            // This needs to know which router to use so that it can keep the global directory in synch with the local one.
            activationDirectory = new ActivationDirectory();

            // Now the consistent ring provider
            RingProvider = GlobalConfig.UseVirtualBucketsConsistentRing ?
                           (IConsistentRingProvider) new VirtualBucketsRingProvider(SiloAddress, GlobalConfig.NumVirtualBucketsConsistentRing)
                : new ConsistentRingProvider(SiloAddress);

            // to preserve backwards compatibility, only use the service provider to inject grain dependencies if the user supplied his own
            // service provider, meaning that he is explicitly opting into it.
            var grainCreator = new GrainCreator(grainRuntime, usingCustomServiceProvider ? Services : null);

            Action <Dispatcher> setDispatcher;

            catalog = new Catalog(Constants.CatalogId, SiloAddress, Name, LocalGrainDirectory, typeManager, scheduler, activationDirectory, config, grainCreator, out setDispatcher);
            var dispatcher = new Dispatcher(scheduler, messageCenter, catalog, config);

            setDispatcher(dispatcher);

            RuntimeClient.Current = new InsideRuntimeClient(
                dispatcher,
                catalog,
                LocalGrainDirectory,
                SiloAddress,
                config,
                RingProvider,
                typeManager,
                grainFactory);
            messageCenter.RerouteHandler       = InsideRuntimeClient.Current.RerouteMessage;
            messageCenter.SniffIncomingMessage = InsideRuntimeClient.Current.SniffIncomingMessage;

            siloStatistics.MetricsTable.Scheduler           = scheduler;
            siloStatistics.MetricsTable.ActivationDirectory = activationDirectory;
            siloStatistics.MetricsTable.ActivationCollector = catalog.ActivationCollector;
            siloStatistics.MetricsTable.MessageCenter       = messageCenter;

            DeploymentLoadPublisher.CreateDeploymentLoadPublisher(this, globalConfig);
            PlacementDirectorsManager.CreatePlacementDirectorsManager(globalConfig);

            // Now the incoming message agents
            incomingSystemAgent = new IncomingMessageAgent(Message.Categories.System, messageCenter, activationDirectory, scheduler, dispatcher);
            incomingPingAgent   = new IncomingMessageAgent(Message.Categories.Ping, messageCenter, activationDirectory, scheduler, dispatcher);
            incomingAgent       = new IncomingMessageAgent(Message.Categories.Application, messageCenter, activationDirectory, scheduler, dispatcher);

            membershipFactory   = new MembershipFactory();
            multiClusterFactory = new MultiClusterOracleFactory();
            reminderFactory     = new LocalReminderServiceFactory();

            SystemStatus.Current = SystemStatus.Created;

            StringValueStatistic.FindOrCreate(StatisticNames.SILO_START_TIME,
                                              () => LogFormatter.PrintDate(startTime)); // this will help troubleshoot production deployment when looking at MDS logs.

            logger.Info(ErrorCode.SiloInitializingFinished, "-------------- Started silo {0}, ConsistentHashCode {1:X} --------------", SiloAddress.ToLongString(), SiloAddress.GetConsistentHashCode());
        }
Exemple #18
0
 protected override Tuple<string[], string[]> StartupParameters() {
     var startupBuilder = new StartupBuilder(this, new Arma3ModListBuilder(_aiaGames));
     return startupBuilder.GetStartupParameters(GetStartupSpec());
 }
 private StartupBuilder CreateTestBuilder() => StartupBuilder.Create()
 .UseEnvironment(new StartupEnvironment("UnitTest1", ""))
 .OverrideDefaults(d => d.UseLocatorRegistryFactory(new DryIocLocatorFactory()));
Exemple #20
0
        internal Silo(SiloInitializationParameters initializationParams, IServiceProvider services)
        {
            string name = initializationParams.Name;
            ClusterConfiguration config = initializationParams.ClusterConfig;

            this.initializationParams = initializationParams;

            this.SystemStatus      = SystemStatus.Creating;
            AsynchAgent.IsStarting = true;

            var startTime = DateTime.UtcNow;

            if (!LogManager.IsInitialized)
            {
                LogManager.Initialize(LocalConfig);
            }
            services?.GetService <TelemetryManager>()?.AddFromConfiguration(services, LocalConfig.TelemetryConfiguration);

            config.OnConfigChange("Defaults/Tracing", () => LogManager.Initialize(LocalConfig, true), false);
            StatisticsCollector.Initialize(LocalConfig);

            initTimeout = GlobalConfig.MaxJoinAttemptTime;
            if (Debugger.IsAttached)
            {
                initTimeout = StandardExtensions.Max(TimeSpan.FromMinutes(10), GlobalConfig.MaxJoinAttemptTime);
                stopTimeout = initTimeout;
            }

            var localEndpoint = this.initializationParams.SiloAddress.Endpoint;

            LogManager.MyIPEndPoint = localEndpoint;
            logger = LogManager.GetLogger("Silo", LoggerType.Runtime);

            logger.Info(ErrorCode.SiloGcSetting, "Silo starting with GC settings: ServerGC={0} GCLatencyMode={1}", GCSettings.IsServerGC, Enum.GetName(typeof(GCLatencyMode), GCSettings.LatencyMode));
            if (!GCSettings.IsServerGC)
            {
                logger.Warn(ErrorCode.SiloGcWarning, "Note: Silo not running with ServerGC turned on - recommend checking app config : <configuration>-<runtime>-<gcServer enabled=\"true\">");
                logger.Warn(ErrorCode.SiloGcWarning, "Note: ServerGC only kicks in on multi-core systems (settings enabling ServerGC have no effect on single-core machines).");
            }

            logger.Info(ErrorCode.SiloInitializing, "-------------- Initializing {0} silo on host {1} MachineName {2} at {3}, gen {4} --------------",
                        this.initializationParams.Type, LocalConfig.DNSHostName, Environment.MachineName, localEndpoint, this.initializationParams.SiloAddress.Generation);
            logger.Info(ErrorCode.SiloInitConfig, "Starting silo {0} with the following configuration= " + Environment.NewLine + "{1}",
                        name, config.ToString(name));

            // Configure DI using Startup type
            if (services == null)
            {
                var serviceCollection = new ServiceCollection();
                serviceCollection.AddSingleton <Silo>(this);
                serviceCollection.AddSingleton(initializationParams);
                DefaultSiloServices.AddDefaultServices(serviceCollection);
                services = StartupBuilder.ConfigureStartup(this.LocalConfig.StartupTypeName, serviceCollection);
                services.GetService <TelemetryManager>()?.AddFromConfiguration(services, LocalConfig.TelemetryConfiguration);
            }

            this.Services = services;

            this.assemblyProcessor = this.Services.GetRequiredService <AssemblyProcessor>();
            this.assemblyProcessor.Initialize();

            BufferPool.InitGlobalBufferPool(GlobalConfig);

            if (!UnobservedExceptionsHandlerClass.TrySetUnobservedExceptionHandler(UnobservedExceptionHandler))
            {
                logger.Warn(ErrorCode.Runtime_Error_100153, "Unable to set unobserved exception handler because it was already set.");
            }

            AppDomain.CurrentDomain.UnhandledException += this.DomainUnobservedExceptionHandler;

            try
            {
                grainFactory = Services.GetRequiredService <GrainFactory>();
            }
            catch (InvalidOperationException exc)
            {
                logger.Error(ErrorCode.SiloStartError, "Exception during Silo.Start, GrainFactory was not registered in Dependency Injection container", exc);
                throw;
            }

            grainTypeManager = Services.GetRequiredService <GrainTypeManager>();

            // Performance metrics
            siloStatistics = Services.GetRequiredService <SiloStatisticsManager>();

            // The scheduler
            scheduler = Services.GetRequiredService <OrleansTaskScheduler>();
            healthCheckParticipants.Add(scheduler);

            runtimeClient = Services.GetRequiredService <InsideRuntimeClient>();

            // Initialize the message center
            messageCenter = Services.GetRequiredService <MessageCenter>();
            var dispatcher = this.Services.GetRequiredService <Dispatcher>();

            messageCenter.RerouteHandler       = dispatcher.RerouteMessage;
            messageCenter.SniffIncomingMessage = runtimeClient.SniffIncomingMessage;

            // GrainRuntime can be created only here, after messageCenter was created.
            grainRuntime = Services.GetRequiredService <IGrainRuntime>();

            // Now the router/directory service
            // This has to come after the message center //; note that it then gets injected back into the message center.;
            localGrainDirectory = Services.GetRequiredService <LocalGrainDirectory>();

            // Now the activation directory.
            activationDirectory = Services.GetRequiredService <ActivationDirectory>();

            // Now the consistent ring provider
            RingProvider = Services.GetRequiredService <IConsistentRingProvider>();

            catalog = Services.GetRequiredService <Catalog>();
            siloStatistics.MetricsTable.Scheduler           = scheduler;
            siloStatistics.MetricsTable.ActivationDirectory = activationDirectory;
            siloStatistics.MetricsTable.ActivationCollector = catalog.ActivationCollector;
            siloStatistics.MetricsTable.MessageCenter       = messageCenter;

            // Now the incoming message agents
            var messageFactory = this.Services.GetRequiredService <MessageFactory>();

            incomingSystemAgent = new IncomingMessageAgent(Message.Categories.System, messageCenter, activationDirectory, scheduler, catalog.Dispatcher, messageFactory);
            incomingPingAgent   = new IncomingMessageAgent(Message.Categories.Ping, messageCenter, activationDirectory, scheduler, catalog.Dispatcher, messageFactory);
            incomingAgent       = new IncomingMessageAgent(Message.Categories.Application, messageCenter, activationDirectory, scheduler, catalog.Dispatcher, messageFactory);

            membershipOracle = Services.GetRequiredService <IMembershipOracle>();

            if (!this.GlobalConfig.HasMultiClusterNetwork)
            {
                logger.Info("Skip multicluster oracle creation (no multicluster network configured)");
            }
            else
            {
                multiClusterOracle = Services.GetRequiredService <IMultiClusterOracle>();
            }

            this.SystemStatus      = SystemStatus.Created;
            AsynchAgent.IsStarting = false;

            StringValueStatistic.FindOrCreate(StatisticNames.SILO_START_TIME,
                                              () => LogFormatter.PrintDate(startTime)); // this will help troubleshoot production deployment when looking at MDS logs.

            logger.Info(ErrorCode.SiloInitializingFinished, "-------------- Started silo {0}, ConsistentHashCode {1:X} --------------", SiloAddress.ToLongString(), SiloAddress.GetConsistentHashCode());
        }
Exemple #21
0
 protected override Tuple<string[], string[]> StartupParameters() {
     var startupBuilder = new StartupBuilder(this);
     return startupBuilder.GetStartupParameters(GetStartupSpec());
 }
Exemple #22
0
        protected override Tuple <string[], string[]> StartupParameters()
        {
            var startupBuilder = new StartupBuilder(this);

            return(startupBuilder.GetStartupParameters(GetStartupSpec()));
        }
Exemple #23
0
        protected override Tuple <string[], string[]> StartupParameters()
        {
            var startupBuilder = new StartupBuilder(this, new Arma3ModListBuilder(_aiaGames));

            return(startupBuilder.GetStartupParameters(GetStartupSpec()));
        }
Exemple #24
0
        private static void RunMicroTemplateBuilders(string solutionDirectory, List <Microservice> microservices, List <Gateway> gateways, IFileSystem fileSystem)
        {
            // services path
            var servicesPath = Path.Combine(solutionDirectory, "services");

            fileSystem.Directory.CreateDirectory(servicesPath);

            foreach (var micro in microservices)
            {
                // set micro path
                var microPath = Path.Combine(servicesPath, micro.ProjectFolderName);

                // add projects
                SolutionBuilder.AddMicroServicesProjects(solutionDirectory, microPath, micro.DbContext.Provider, micro.ProjectFolderName, micro.AddJwtAuthentication, fileSystem);

                // dbcontext
                DbContextBuilder.CreateDbContext(microPath, micro.Entities, micro.DbContext.ContextName, micro.DbContext.Provider, micro.DbContext.DatabaseName);

                //entities
                foreach (var entity in micro.Entities)
                {
                    EntityBuilder.CreateEntity(microPath, entity, fileSystem);
                    DtoBuilder.CreateDtos(microPath, entity);

                    RepositoryBuilder.AddRepository(microPath, entity, micro.DbContext);
                    ValidatorBuilder.CreateValidators(microPath, entity);
                    ProfileBuilder.CreateProfile(microPath, entity);

                    ControllerBuilder.CreateController(microPath, entity, micro.SwaggerConfig.AddSwaggerComments, micro.AuthorizationSettings.Policies);

                    FakesBuilder.CreateFakes(microPath, micro.ProjectFolderName, entity);
                    ReadTestBuilder.CreateEntityReadTests(microPath, micro.ProjectFolderName, entity, micro.DbContext.ContextName);
                    GetTestBuilder.CreateEntityGetTests(microPath, micro.ProjectFolderName, entity, micro.DbContext.ContextName, micro.AuthorizationSettings.Policies);
                    PostTestBuilder.CreateEntityWriteTests(microPath, entity, micro.ProjectFolderName, micro.AuthorizationSettings.Policies);
                    UpdateTestBuilder.CreateEntityUpdateTests(microPath, entity, micro.ProjectFolderName, micro.DbContext.ContextName, micro.AuthorizationSettings.Policies);
                    DeleteIntegrationTestBuilder.CreateEntityDeleteTests(microPath, entity, micro.ProjectFolderName, micro.DbContext.ContextName, micro.AuthorizationSettings.Policies);
                    DeleteTestBuilder.DeleteEntityWriteTests(microPath, entity, micro.ProjectFolderName, micro.DbContext.ContextName);
                    WebAppFactoryBuilder.CreateWebAppFactory(microPath, micro.ProjectFolderName, micro.DbContext.ContextName, micro.AddJwtAuthentication);
                }


                // environments
                Utilities.AddStartupEnvironmentsWithServices(
                    microPath,
                    micro.ProjectFolderName,
                    micro.DbContext.DatabaseName,
                    micro.Environments,
                    micro.SwaggerConfig,
                    micro.Port,
                    micro.AddJwtAuthentication
                    );

                //seeders
                SeederBuilder.AddSeeders(microPath, micro.Entities, micro.DbContext.ContextName);

                //services
                SwaggerBuilder.AddSwagger(microPath, micro.SwaggerConfig, micro.ProjectFolderName, micro.AddJwtAuthentication, micro.AuthorizationSettings.Policies);

                if (micro.AddJwtAuthentication)
                {
                    InfrastructureIdentityServiceRegistrationBuilder.CreateInfrastructureIdentityServiceExtension(microPath, micro.AuthorizationSettings.Policies, fileSystem);
                }
            }

            // gateway path
            var gatewayPath = Path.Combine(solutionDirectory, "gateways");

            fileSystem.Directory.CreateDirectory(gatewayPath);

            foreach (var gateway in gateways)
            {
                SolutionBuilder.AddGatewayProject(solutionDirectory, gatewayPath, gateway.GatewayProjectName, fileSystem);

                foreach (var env in gateway.EnvironmentGateways)
                {
                    //TODO: run quality checks that profile name exists, gateway url is a valid path and https, Env Name

                    if (env.EnvironmentName != "Startup")
                    {
                        StartupBuilder.CreateGatewayStartup(gatewayPath, env.EnvironmentName, gateway.GatewayProjectName);
                    }

                    GatewayAppSettingsBuilder.CreateAppSettings(gatewayPath, env, gateway.GatewayProjectName, microservices);
                    GatewayLaunchSettingsModifier.AddProfile(gatewayPath, env, gateway.GatewayProjectName);
                }
            }
        }