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;
			}
		}
Ejemplo n.º 2
0
 public static ReplicationConfig GetReplicationConfig(this DocumentDatabase database)
 {
     try
     {
         var configDoc = database.ConfigurationRetriever.GetConfigurationDocument <ReplicationConfig>(Constants.RavenReplicationConfig);
         return(configDoc?.MergedDocument);
     }
     catch (Exception e)
     {
         Log.ErrorException("Could not read the configuration for replication conflict resolution", e);
         database.AddAlert(new Alert
         {
             AlertLevel = AlertLevel.Error,
             CreatedAt  = SystemTime.UtcNow,
             Message    = e.Message,
             Title      = "Could not read the configuration for replication conflict resolution",
             Exception  = e.ToString(),
             UniqueKey  = "Replication Conflict Resolution Configuration Error"
         });
         return(null);
     }
 }