コード例 #1
0
        private void ReadAndSetSchema(QueryConfig config, QueueContext queueContext, Job job)
        {
            var fileUploader = new FileUploader(queueContext.Config.ElasticSearchUserName,
                                                queueContext.Config.ElasticSearchPassword, job.Config.KeepIndexOnline);

            if (config.UploadToElasticSearch && config.DropAndReloadIndex)
            {
                Task.Run(
                    async() =>
                {
                    await fileUploader.DeleteIndex(config.Urls, queueContext.MainMappingUploadRelativeUrl, config.Index, config.Alias);
                })
                .Wait();
            }

            var tasks = new List <Task>();
            // ReSharper disable once JoinDeclarationAndInitializer
            IList <Task> newTasks;

            var sqlGetSchemaQueue = queueContext.QueueManager
                                    .CreateInputQueue <SqlGetSchemaQueueItem>(_stepNumber + 1);

            sqlGetSchemaQueue.Add(new SqlGetSchemaQueueItem
            {
                Loads = job.Data.DataSources
            });

            sqlGetSchemaQueue.CompleteAdding();

            newTasks = RunAsync(() => new SqlGetSchemaQueueProcessor(queueContext), 1, queueContext);
            tasks.AddRange(newTasks);

            newTasks = RunAsync(() => new SaveSchemaQueueProcessor(queueContext), 1, queueContext);
            tasks.AddRange(newTasks);

            if (config.UploadToElasticSearch)
            {
                newTasks = RunAsync(() => new MappingUploadQueueProcessor(queueContext), 1, queueContext);
            }
            else
            {
                newTasks = RunAsync(() => new DummyMappingUploadQueueProcessor(queueContext), 1, queueContext);
            }
            tasks.AddRange(newTasks);

            Task.WaitAll(tasks.ToArray());

            // set up aliases
            if (config.UploadToElasticSearch)
            {
                fileUploader.SetupAlias(config.Urls, config.Index, config.Alias).Wait();
            }
        }