Пример #1
0
        public void Error_if_script_has_both_apply_to_all_documents_and_collections_specified()
        {
            var config = new RavenEtlConfiguration
            {
                Name = "test",
                ConnectionStringName = "test",
                Transforms           =
                {
                    new Transformation
                    {
                        Name = "test",
                        ApplyToAllDocuments = true,
                        Collections         = { "Users" }
                    }
                }
            };

            config.Initialize(new RavenConnectionString()
            {
                Database = "Foo", TopologyDiscoveryUrls = new[] { "http://localhost:8080" }
            });

            List <string> errors;

            config.Validate(out errors);

            Assert.Equal(1, errors.Count);

            Assert.Equal("Collections cannot be specified when ApplyToAllDocuments is set", errors[0]);
        }
Пример #2
0
        public void Error_if_script_does_not_contain_any_loadTo_method()
        {
            var config = new RavenEtlConfiguration
            {
                Name = "test",
                ConnectionStringName = "test",
                Transforms           =
                {
                    new Transformation
                    {
                        Name        = "test",
                        Collections ={ "Users"                   },
                        Script      = @"this.Name = 'aaa';"
                    }
                }
            };

            config.Initialize(new RavenConnectionString()
            {
                Database = "Foo", TopologyDiscoveryUrls = new[] { "http://localhost:8080" }
            });

            List <string> errors;

            config.Validate(out errors);

            Assert.Equal(1, errors.Count);

            Assert.Equal("No `loadTo[CollectionName]` method call found in 'test' script", errors[0]);
        }
Пример #3
0
        public void Can_put_space_after_loadTo_method_in_script()
        {
            var config = new RavenEtlConfiguration
            {
                Name = "test",
                ConnectionStringName = "test",
                Transforms           =
                {
                    new Transformation
                    {
                        Name        = "test",
                        Collections ={ "Users"                   },
                        Script      = @"loadToUsers (this);"
                    }
                }
            };

            config.Initialize(new RavenConnectionString()
            {
                Database = "Foo", TopologyDiscoveryUrls = new [] { "http://localhost:8080" }
            });

            List <string> errors;

            config.Validate(out errors);

            Assert.Equal(0, errors.Count);

            var collections = config.Transforms[0].GetCollectionsFromScript();

            Assert.Equal(1, collections.Length);
            Assert.Equal("Users", collections[0]);
        }
Пример #4
0
        public void Should_throw_when_transforms_is_empty()
        {
            var configuration = new RavenEtlConfiguration {
                ConnectionStringName = "test", Name = "myConfig", MentorNode = "A", Transforms = new List <Transformation>()
            };

            configuration.Initialize(new RavenConnectionString());
            var e = Assert.Throws <InvalidOperationException>(() => configuration.Validate(out List <string> _));

            Assert.Equal($"'{nameof(RavenEtlConfiguration.Transforms)}' list cannot be empty.", e.Message);
        }
Пример #5
0
        public void Error_if_script_does_not_contain_any_loadTo_method_and_isnt_empty()
        {
            var config = new RavenEtlConfiguration
            {
                Name = "test",
                ConnectionStringName = "test",
                Transforms           =
                {
                    new Transformation
                    {
                        Name        = "test",
                        Collections ={ "Users"                   },
                        Script      = @"
                        
                        this.Name = 'aaa'; // we have some modification but we don't call loadTo method so it should error

                        function deleteDocumentsOfUsersBehavior(docId) {
                            return false;
                        }
                    "
                    }
                }
            };

            config.Initialize(new RavenConnectionString()
            {
                Database = "Foo", TopologyDiscoveryUrls = new[] { "http://localhost:8080" }
            });

            List <string> errors;

            config.Validate(out errors);

            Assert.Equal(1, errors.Count);

            Assert.Equal("No `loadTo<CollectionName>()` method call found in 'test' script", errors[0]);
        }
Пример #6
0
        private IEnumerable <EtlProcess> GetRelevantProcesses <T, TConnectionString>(List <T> configurations, HashSet <string> uniqueNames) where T : EtlConfiguration <TConnectionString> where TConnectionString : ConnectionString
        {
            foreach (var config in configurations)
            {
                SqlEtlConfiguration   sqlConfig   = null;
                RavenEtlConfiguration ravenConfig = null;

                var connectionStringNotFound = false;

                switch (config.EtlType)
                {
                case EtlType.Raven:
                    ravenConfig = config as RavenEtlConfiguration;
                    if (_databaseRecord.RavenConnectionStrings.TryGetValue(config.ConnectionStringName, out var ravenConnection))
                    {
                        ravenConfig.Initialize(ravenConnection);
                    }
                    else
                    {
                        connectionStringNotFound = true;
                    }

                    break;

                case EtlType.Sql:
                    sqlConfig = config as SqlEtlConfiguration;
                    if (_databaseRecord.SqlConnectionStrings.TryGetValue(config.ConnectionStringName, out var sqlConnection))
                    {
                        sqlConfig.Initialize(sqlConnection);
                    }
                    else
                    {
                        connectionStringNotFound = true;
                    }

                    break;

                default:
                    ThrownUnknownEtlConfiguration(config.GetType());
                    break;
                }

                if (connectionStringNotFound)
                {
                    LogConfigurationError(config,
                                          new List <string>
                    {
                        $"Connection string named '{config.ConnectionStringName}' was not found for {config.EtlType} ETL"
                    });

                    continue;
                }

                if (config.Disabled)
                {
                    continue;
                }

                if (ValidateConfiguration(config, uniqueNames) == false)
                {
                    continue;
                }

                var processState  = GetProcessState(config.Transforms, _database, config.Name);
                var whoseTaskIsIt = _database.WhoseTaskIsIt(_databaseRecord.Topology, config, processState);
                if (whoseTaskIsIt != _serverStore.NodeTag)
                {
                    continue;
                }

                foreach (var transform in config.Transforms)
                {
                    if (transform.Disabled)
                    {
                        continue;
                    }

                    EtlProcess process = null;

                    if (sqlConfig != null)
                    {
                        process = new SqlEtl(transform, sqlConfig, _database, _serverStore);
                    }

                    if (ravenConfig != null)
                    {
                        process = new RavenEtl(transform, ravenConfig, _database, _serverStore);
                    }

                    yield return(process);
                }
            }
        }