public static void Main(string[] args)
        {
            StateInitializationRoot.Instance.PerformTypesMassProcessing(Array.Empty <IMassProcessor>(), true,
                                                                        typeof(object));

            var commands = new List <ICommand>();
            var tenants  = ParseTenants(args);

            if (args.Contains("-facts"))
            {
                if (tenants.Count != 0)
                {
                    commands.AddRange(BulkReplicationCommands.ErmToFacts
                                      .Where(x => IsTenantConfigured(x, tenants)));
                    commands.Add(SchemaInitializationCommands.ErmFacts);
                }

                var flows = ParseFlows(args);
                if (flows.Count != 0)
                {
                    commands.AddRange(BulkReplicationCommands.KafkaToFacts
                                      .Where(x => flows.Contains(x.MessageFlow)));
                    commands.AddRange(SchemaInitializationCommands.KafkaFacts
                                      .Where(x => flows.Contains(x.Key))
                                      .Select(x => x.Value));
                }
            }

            if (args.Contains("-aggregates"))
            {
                commands.Add(BulkReplicationCommands.FactsToAggregates);
                commands.Add(SchemaInitializationCommands.Aggregates);
            }

            if (args.Contains("-messages"))
            {
                commands.AddRange(BulkReplicationCommands.ErmToMessages
                                  .Where(x => IsTenantConfigured(x, tenants)));
                commands.Add(BulkReplicationCommands.AggregatesToMessages);
                commands.Add(SchemaInitializationCommands.Messages);
            }

            if (args.Contains("-events"))
            {
                commands.Add(SchemaInitializationCommands.Events);
            }

            var environmentSettings = new EnvironmentSettingsAspect();
            var tracer = CreateTracer(environmentSettings);

            var kafkaSettingsFactory            = new StateInitKafkaSettingsFactory(new KafkaSettingsFactory(ConnectionStringSettings));
            var kafkaMessageFlowReceiverFactory = new KafkaMessageFlowReceiverFactory(new NullTracer(), kafkaSettingsFactory);

            var bulkReplicationActor  = new BulkReplicationActor(ConnectionStringSettings);
            var kafkaReplicationActor = new KafkaReplicationActor(ConnectionStringSettings,
                                                                  kafkaMessageFlowReceiverFactory,
                                                                  new KafkaMessageFlowInfoProvider(kafkaSettingsFactory),
                                                                  new KafkaFactsBulkCommandFactory(kafkaSettingsFactory),
                                                                  tracer);

            var schemaInitializationActor = new SchemaInitializationActor(ConnectionStringSettings);

            var sw = Stopwatch.StartNew();

            schemaInitializationActor.ExecuteCommands(commands);
            bulkReplicationActor.ExecuteCommands(commands.Where(x => BulkReplicationCommands.ErmToFacts.Contains(x))
                                                 .ToList());
            kafkaReplicationActor.ExecuteCommands(commands);
            bulkReplicationActor.ExecuteCommands(commands.Where(x => !BulkReplicationCommands.ErmToFacts.Contains(x))
                                                 .ToList());

            var webAppSchemaHelper = new WebAppSchemaInitializationHelper(ConnectionStringSettings);

            if (args.Contains("-webapp"))
            {
                webAppSchemaHelper.CreateWebAppSchema(SchemaInitializationCommands.WebApp);
            }

            if (args.Contains("-webapp-drop"))
            {
                webAppSchemaHelper.DropWebAppSchema(SchemaInitializationCommands.WebApp);
            }

            Console.WriteLine($"Total time: {sw.ElapsedMilliseconds}ms");
        }
        public static void Main(string[] args)
        {
            StateInitializationRoot.Instance.PerformTypesMassProcessing(Array.Empty <IMassProcessor>(), true, typeof(object));

            var commands = new List <ICommand>();

            if (args.Contains("-facts"))
            {
                commands.Add(BulkReplicationCommands.ErmToFacts);
                // Надо подумать о лишней обёртке
                commands.Add(new KafkaReplicationCommand(AmsFactsFlow.Instance, BulkReplicationCommands.AmsToFacts));
                commands.Add(new KafkaReplicationCommand(RulesetFactsFlow.Instance, BulkReplicationCommands.RulesetsToFacts));
                commands.Add(SchemaInitializationCommands.WebApp);
                commands.Add(SchemaInitializationCommands.Facts);
            }

            if (args.Contains("-aggregates"))
            {
                commands.Add(BulkReplicationCommands.FactsToAggregates);
                commands.Add(SchemaInitializationCommands.WebApp);
                commands.Add(SchemaInitializationCommands.Aggregates);
            }

            if (args.Contains("-messages"))
            {
                commands.Add(BulkReplicationCommands.AggregatesToMessages);
                commands.Add(SchemaInitializationCommands.WebApp);
                commands.Add(SchemaInitializationCommands.Messages);
            }

            var connectionStrings = ConnectionStrings.For(ErmConnectionStringIdentity.Instance,
                                                          AmsConnectionStringIdentity.Instance,
                                                          FactsConnectionStringIdentity.Instance,
                                                          AggregatesConnectionStringIdentity.Instance,
                                                          MessagesConnectionStringIdentity.Instance,
                                                          RulesetConnectionStringIdentity.Instance);
            var connectionStringSettings = new ConnectionStringSettingsAspect(connectionStrings);
            var environmentSettings      = new EnvironmentSettingsAspect();
            var businessModelSettings    = new BusinessModelSettingsAspect();

            var tracer = CreateTracer(environmentSettings, businessModelSettings);

            var kafkaSettingsFactory =
                new KafkaSettingsFactory(new Dictionary <IMessageFlow, string>
            {
                [AmsFactsFlow.Instance] =
                    connectionStringSettings.GetConnectionString(AmsConnectionStringIdentity.Instance),
                [RulesetFactsFlow.Instance] =
                    connectionStringSettings.GetConnectionString(RulesetConnectionStringIdentity.Instance)
            },
                                         environmentSettings,
                                         Offset.Beginning);

            var kafkaMessageFlowReceiverFactory = new KafkaMessageFlowReceiverFactory(new NullTracer(), kafkaSettingsFactory);

            var dataObjectTypesProviderFactory = new DataObjectTypesProviderFactory();
            var bulkReplicationActor           = new BulkReplicationActor(dataObjectTypesProviderFactory, connectionStringSettings);
            var kafkaReplicationActor          = new KafkaReplicationActor(connectionStringSettings,
                                                                           dataObjectTypesProviderFactory,
                                                                           kafkaMessageFlowReceiverFactory,
                                                                           new KafkaMessageFlowInfoProvider(kafkaSettingsFactory),
                                                                           new IBulkCommandFactory <Message>[]
            {
                new AmsFactsBulkCommandFactory(),
                new RulesetFactsBulkCommandFactory(businessModelSettings)
            },
                                                                           tracer);

            var schemaInitializationActor = new SchemaInitializationActor(connectionStringSettings);

            var sw = Stopwatch.StartNew();

            schemaInitializationActor.ExecuteCommands(commands);
            bulkReplicationActor.ExecuteCommands(commands.Where(x => x == BulkReplicationCommands.ErmToFacts).ToList());
            kafkaReplicationActor.ExecuteCommands(commands);
            bulkReplicationActor.ExecuteCommands(commands.Where(x => x != BulkReplicationCommands.ErmToFacts).ToList());

            Console.WriteLine($"Total time: {sw.ElapsedMilliseconds}ms");
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            StateInitializationRoot.Instance.PerformTypesMassProcessing(Array.Empty <IMassProcessor>(), true,
                                                                        typeof(object));

            var commands = new List <ICommand>();

            if (args.Any(x => x.Contains("-facts")))
            {
                commands.AddRange(BulkReplicationCommands.ErmToFacts
                                  .Where(x => IsConfigured(x.SourceStorageDescriptor)));
                commands.Add(new KafkaReplicationCommand(AmsFactsFlow.Instance, BulkReplicationCommands.AmsToFacts));
                commands.Add(new KafkaReplicationCommand(RulesetFactsFlow.Instance, BulkReplicationCommands.RulesetsToFacts, 500));
                // TODO: отдельный schema init для erm\ams\ruleset facts
                commands.Add(SchemaInitializationCommands.Facts);
            }

            if (args.Contains("-aggregates"))
            {
                commands.Add(BulkReplicationCommands.FactsToAggregates);
                commands.Add(SchemaInitializationCommands.Aggregates);
            }

            if (args.Contains("-messages"))
            {
                commands.AddRange(BulkReplicationCommands.ErmToMessages
                                  .Where(x => IsConfigured(x.SourceStorageDescriptor)));
                commands.Add(BulkReplicationCommands.AggregatesToMessages);
                commands.Add(SchemaInitializationCommands.Messages);
            }

            var environmentSettings = new EnvironmentSettingsAspect();
            var tracer = CreateTracer(environmentSettings);

            var kafkaSettingsFactory = new KafkaSettingsFactory(new Dictionary <IMessageFlow, string>
            {
                {
                    AmsFactsFlow.Instance,
                    ConnectionStringSettings.GetConnectionString(AmsConnectionStringIdentity.Instance)
                },
                {
                    RulesetFactsFlow.Instance,
                    ConnectionStringSettings.GetConnectionString(RulesetConnectionStringIdentity.Instance)
                }
            },
                                                                environmentSettings);

            var kafkaMessageFlowReceiverFactory =
                new StateInitKafkaMessageFlowReceiverFactory(new NullTracer(), kafkaSettingsFactory);

            var bulkReplicationActor  = new BulkReplicationActor(ConnectionStringSettings);
            var kafkaReplicationActor = new KafkaReplicationActor(ConnectionStringSettings,
                                                                  kafkaMessageFlowReceiverFactory,
                                                                  new KafkaMessageFlowInfoProvider(kafkaSettingsFactory),
                                                                  new IBulkCommandFactory <ConsumeResult <Ignore, byte[]> >[]
            {
                new AmsFactsBulkCommandFactory(),
                new RulesetFactsBulkCommandFactory()
            },
                                                                  tracer);

            var schemaInitializationActor = new SchemaInitializationActor(ConnectionStringSettings);

            var sw = Stopwatch.StartNew();

            schemaInitializationActor.ExecuteCommands(commands);
            bulkReplicationActor.ExecuteCommands(commands.Where(x => BulkReplicationCommands.ErmToFacts.Contains(x))
                                                 .ToList());
            kafkaReplicationActor.ExecuteCommands(commands);
            bulkReplicationActor.ExecuteCommands(commands.Where(x => !BulkReplicationCommands.ErmToFacts.Contains(x))
                                                 .ToList());

            var webAppSchemaHelper = new WebAppSchemaInitializationHelper(ConnectionStringSettings);

            if (args.Contains("-webapp"))
            {
                webAppSchemaHelper.CreateWebAppSchema(SchemaInitializationCommands.WebApp);
            }

            if (args.Contains("-webapp-drop"))
            {
                webAppSchemaHelper.DropWebAppSchema(SchemaInitializationCommands.WebApp);
            }

            Console.WriteLine($"Total time: {sw.ElapsedMilliseconds}ms");
        }