public static ElasticsearchClient GetElasticClient(this ElasticsearchReplicationConfig cfg)
        {
            var elasticsearchNodes = cfg.ElasticsearchNodeUrls;
            var connectionPool     = elasticsearchNodes.Count == 1 ? (IConnectionPool)
                                     new SingleNodeConnectionPool(elasticsearchNodes.First()) : new StaticConnectionPool(elasticsearchNodes);

            return(new ElasticsearchClient(new ConnectionConfiguration(connectionPool)));
        }
        public static void AddKibanaDashboard(this ElasticsearchReplicationConfig cfg, string dashboardName,
                                              string dashboardSource)
        {
            var client = GetElasticClient(cfg);
            var rsp    = client.Index("kibana-int", "dashboard", dashboardName, dashboardSource);

            if (!rsp.Success)
            {
                throw new Exception("Error while trying to put Kibana dashboard " + dashboardName, rsp.OriginalException);
            }
        }
Example #3
0
        public ElasticsearchDestinationWriter(DocumentDatabase database, SqlReplicationConfig _cfg, SqlReplicationStatistics replicationStatistics)
        {
            var cfg = new ElasticsearchReplicationConfig(_cfg);

            this.database              = database;
            this.cfg                   = cfg;
            this.targetIndexName       = cfg.FactoryName.ToLowerInvariant(); // Elasticsearch requires all index names to be lowercased
            this.replicationStatistics = replicationStatistics;

            try
            {
                elasticsearchClient = cfg.GetElasticClient();
            }
            catch (UriFormatException e)
            {
                if (database != null)
                {
                    database.AddAlert(new Alert
                    {
                        AlertLevel = AlertLevel.Error,
                        CreatedAt  = SystemTime.UtcNow,
                        Exception  = e.ToString(),
                        Title      = "Invalid Elasticsearch URL provided",
                        Message    = "Elasticsearch Replication could not parse one of the provided node URLs",
                        UniqueKey  = "Elasticsearch Replication Connection Error: " + cfg.ConnectionString
                    });
                }
            }
            catch (Exception e)
            {
                if (database != null)
                {
                    database.AddAlert(new Alert
                    {
                        AlertLevel = AlertLevel.Error,
                        CreatedAt  = SystemTime.UtcNow,
                        Exception  = e.ToString(),
                        Title      = "Elasticsearch Replication could not open connection",
                        Message    = "Elasticsearch Replication could not open connection to " + cfg.ConnectionString,
                        UniqueKey  = "Elasticsearch Replication Connection Error: " + cfg.ConnectionString
                    });
                }
                throw;
            }
        }
        public static void SetupDefaultMapping(this ElasticsearchReplicationConfig cfg)
        {
            var assembly = typeof(ElasticsearchReplicationTask).Assembly;
            var template = GetEmbeddedJson(assembly, ".DefaultIndexTemplate.json");

            if (string.IsNullOrWhiteSpace(template))
            {
                throw new Exception("Can't find the mapping");
            }

            var client = GetElasticClient(cfg);
            var rsp    = client.IndicesPutTemplateForAll("ravendb-elasticsearch-replication", template);

            if (!rsp.Success)
            {
                throw new Exception("Error while trying to put a new template", rsp.OriginalException);
            }
        }
        public ElasticsearchDestinationWriter(DocumentDatabase database, SqlReplicationConfig _cfg, SqlReplicationStatistics replicationStatistics)
		{
            var cfg = new ElasticsearchReplicationConfig(_cfg);

			this.database = database;
			this.cfg = cfg;
            this.targetIndexName = cfg.FactoryName.ToLowerInvariant(); // Elasticsearch requires all index names to be lowercased
			this.replicationStatistics = replicationStatistics;
            
            try
            {
                elasticsearchClient = cfg.GetElasticClient();
            }
            catch (UriFormatException e)
            {
                if (database != null)
                    database.AddAlert(new Alert
                    {
                        AlertLevel = AlertLevel.Error,
                        CreatedAt = SystemTime.UtcNow,
                        Exception = e.ToString(),
                        Title = "Invalid Elasticsearch URL provided",
                        Message = "Elasticsearch Replication could not parse one of the provided node URLs",
                        UniqueKey = "Elasticsearch Replication Connection Error: " + cfg.ConnectionString
                    });
            }
			catch (Exception e)
			{
			    if (database != null)
			        database.AddAlert(new Alert
			        {
			            AlertLevel = AlertLevel.Error,
			            CreatedAt = SystemTime.UtcNow,
			            Exception = e.ToString(),
			            Title = "Elasticsearch Replication could not open connection",
			            Message = "Elasticsearch Replication could not open connection to " + cfg.ConnectionString,
			            UniqueKey = "Elasticsearch Replication Connection Error: " + cfg.ConnectionString
			        });
				throw;
			}
		}