/// <summary>
        /// Gets the akka system config
        /// </summary>
        /// <param name="containerBuilder">
        /// The container builder
        /// </param>
        /// <returns>
        /// The config
        /// </returns>
        public virtual Config GetAkkaConfig(ContainerBuilder containerBuilder)
        {
            var config = ConfigurationFactory.ParseString(
                @"
                akka.actor.serialize-messages = on
                akka.actor.serialize-creators = off
            ");

            return(BaseInstaller.GetStackedConfig(containerBuilder, config));
        }
Exemple #2
0
        /// <summary>
        /// Performs the dependencies initialization
        /// </summary>
        /// <param name="config">The seeder configuration</param>
        /// <returns>The windsor container</returns>
        private static ContainerBuilder InitializeDependencies(Config config)
        {
            var container = new ContainerBuilder();

            container.RegisterInstallers();
            config = BaseInstaller.GetStackedConfig(container, config);
            container.RegisterInstance(config).As <Config>();
            BaseInstaller.RunComponentRegistration(container, config);
            return(container);
        }
        /// <summary>
        ///  Dependency injection configuration
        /// </summary>
        /// <param name="containerBuilder">Dependency injection container</param>
        /// <param name="configurations">
        /// Startup parameters
        /// </param>
        /// <returns>The DI container</returns>
        public static IContainer ConfigureAndStart(ContainerBuilder containerBuilder, string[] configurations)
        {
            Console.WriteLine(@"Starting bootstrapper");

            containerBuilder.RegisterInstallers();

            Console.WriteLine(@"Preparing config");
            var config = BaseInstaller.GetStackedConfig(containerBuilder, CreateTopLevelConfig(configurations));

            Log.Debug($"Cluster configuration: seed-nodes { string.Join(", ", config.GetStringList("akka.cluster.seed-nodes") ?? new List<string>())}");
            Log.Debug($"Cluster configuration: min-nr-of-members { config.GetInt("akka.cluster.min-nr-of-members")}");
            var roles = string.Join(", ", config.GetStringList("akka.cluster.roles") ?? new List <string>());

            Log.Debug($"Cluster configuration: roles { roles}");
            Log.Debug($"Cluster node hostname: { config.GetString("akka.remote.helios.tcp.hostname") }");
            var publicHostName = config.GetString("akka.remote.helios.tcp.public-hostname");

            if (!string.IsNullOrWhiteSpace(publicHostName))
            {
                Log.Debug($"Cluster node public hostname: { publicHostName }");
            }

            containerBuilder.RegisterInstance(config).As <Config>();
            BaseInstaller.RunComponentRegistration(containerBuilder, config);

            Console.WriteLine(@"Config created");

            // log configuration
            LogEventLevel level;

            if (!Enum.TryParse(config.GetString("KlusterKite.Log.minimumLevel"), true, out level))
            {
                level = LogEventLevel.Verbose;
            }

            var actorSystem = ActorSystem.Create("KlusterKite", config);

            containerBuilder.RegisterInstance(actorSystem).As <ActorSystem>();
            var container = containerBuilder.Build();

            var loggerConfig  = new LoggerConfiguration().MinimumLevel.Is(level);
            var configurators = container.Resolve <IEnumerable <ILoggerConfigurator> >().ToList();

            configurators.ForEach(c => Log.Information("Using log configurator {TypeName}", c.GetType().FullName));

            loggerConfig = configurators.Aggregate(
                loggerConfig,
                (current, loggerConfigurator) => loggerConfigurator.Configure(current, config));

            var hostName = string.IsNullOrWhiteSpace(publicHostName)
                               ? config.GetString("akka.remote.helios.tcp.hostname")
                               : publicHostName;

            loggerConfig = loggerConfig.Enrich.WithProperty("hostName", hostName);
            loggerConfig = loggerConfig.Enrich.WithProperty("roles", roles);

            var logger = loggerConfig.CreateLogger();

            Log.Logger = logger;

            // log configuration finished

            // performing pre-start checks
            BaseInstaller.RunPreCheck(containerBuilder, config);

            // starting Akka system
            Console.WriteLine(@"starting akka system");
            actorSystem.AddDependencyResolver(new AutoFacDependencyResolver(container, actorSystem));

            Console.WriteLine(@"Bootstrapper start finished");

            return(container);
        }
Exemple #4
0
        /// <summary>
        /// Service main entry point
        /// </summary>
        public static void Main()
        {
            var builder = new ContainerBuilder();

            try
            {
                builder.RegisterInstallers();
            }
            catch (ReflectionTypeLoadException exception)
            {
                foreach (var loaderException in exception.LoaderExceptions)
                {
                    throw loaderException;
                }

                throw;
            }

            var providedConfiguration = File.ReadAllText("config.hocon");
            var config = BaseInstaller.GetStackedConfig(
                builder,
                ConfigurationFactory.ParseString(providedConfiguration));

            builder.RegisterInstance(config).As <Config>();
            BaseInstaller.RunComponentRegistration(builder, config);

            var migratorTypeNames = config.GetStringList("KlusterKite.NodeManager.Migrators");

            foreach (var typeName in migratorTypeNames.Where(t => !string.IsNullOrWhiteSpace(t)))
            {
                var type = Type.GetType(typeName, false);
                if (type == null)
                {
                    Errors.Add(
                        new MigrationLogRecord
                    {
                        Type             = EnMigrationLogRecordType.Error,
                        Message          = $"Migrator type {typeName} was not found",
                        MigratorTypeName = typeName
                    });
                    continue;
                }

                if (!type.GetTypeInfo().GetInterfaces().Contains(typeof(IMigrator)))
                {
                    Errors.Add(
                        new MigrationLogRecord
                    {
                        Type             = EnMigrationLogRecordType.Error,
                        Message          = $"Type {typeName} doesn't implement IMigrator",
                        MigratorTypeName = typeName
                    });
                    continue;
                }

                builder.RegisterType(type).As <IMigrator>();
            }

            var context = builder.Build();

            Console.WriteLine(ProcessHelper.EOF);

            MigrationCollector collector;

            using (var standardInput = Console.OpenStandardInput())
            {
                collector = new StreamReader(standardInput).Receive() as MigrationCollector;
            }

            if (collector == null)
            {
                throw new InvalidOperationException("Received object is not a MigrationCollector");
            }

            collector.Errors.AddRange(Errors);
            if (Errors.Count == 0)
            {
                collector.Execute(context);
            }

            Console.Out.Send(collector);
        }