コード例 #1
0
        }                                                                             //Singleton pattern

        private ElasticTelemetry()
        {
            try
            {
                //Load custom app.config for this assembly
                var appConfig = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);



                //Configure connection settings
                var connectionSettings = new ConnectionConfiguration(new Uri(appConfig.AppSettings.Settings["ElasticServer"].Value));
                connectionSettings
                .BasicAuthentication(appConfig.AppSettings.Settings["ElasticUser"].Value, appConfig.AppSettings.Settings["ElasticPassword"].Value)
                .RequestTimeout(TimeSpan.FromSeconds(30))
                .DisableDirectStreaming();

                //Create Elastic client
                _ElasticClient = new ElasticLowLevelClient(connectionSettings);

                //Set Elastic Index and Type
                _ElasticIndex = appConfig.AppSettings.Settings["ElasticIndex"].Value;
                _ElasticType  = appConfig.AppSettings.Settings["ElasticType"].Value;
            }
            catch (Exception e) { logger.Fatal(e); }
        }
        protected override void InitializeTarget()
        {
            base.InitializeTarget();

            var uri            = ConnectionStringName.GetConnectionString() ?? Uri;
            var nodes          = uri.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(url => new Uri(url));
            var connectionPool = new StaticConnectionPool(nodes);

            var config = new ConnectionConfiguration(connectionPool);

            if (RequireAuth)
            {
                config.BasicAuthentication(Username, Password);
            }

            if (ElasticsearchSerializer != null)
            {
                config = new ConnectionConfiguration(connectionPool, _ => ElasticsearchSerializer);
            }

            _client = new ElasticLowLevelClient(config);

            if (!string.IsNullOrEmpty(ExcludedProperties))
            {
                _excludedProperties = ExcludedProperties.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
            }
        }
コード例 #3
0
ファイル: ElasticSearch.cs プロジェクト: Shelipov/BonusSystem
 public ElasticSearch(Configuration _configuration)
 {
     configuration = _configuration;
     _Index        = Index.Core.GetValueAttribute();
     if (configuration != null)
     {
         if (configuration.ElasticSearchUrl != null)
         {
             ElasticDomain   = configuration.ElasticSearchUrl;
             ElasticLogin    = configuration.ElasticSearchLogin;
             ElasticPassword = configuration.ElasticSearchPassword;
             Node            = new Uri(ElasticDomain);
             Config          = new ConnectionConfiguration(Node);
             Config.DisableDirectStreaming(true);
             Envirment = configuration.ElasticSearchEnvirment;
             Domain    = LocalIPAddress().ToString();
             Check     = bool.Parse(configuration.ElasticSearchCheck);
             if (ElasticLogin != null && ElasticLogin != "" && ElasticPassword != null && ElasticPassword != "")
             {
                 Config.BasicAuthentication(ElasticLogin, ElasticPassword);
             }
             Client = new ElasticLowLevelClient(Config);
         }
     }
 }
コード例 #4
0
        public ElasticSearchLogger(string server, int port = 9200, string login = null, string password = null)
        {
            var uri      = new Uri($"http://{server}:{port}");
            var settings = new ConnectionConfiguration(uri);

            if (!string.IsNullOrEmpty(login) || !string.IsNullOrEmpty(password))
            {
                settings.BasicAuthentication(login, password);
            }
            _client = new ElasticLowLevelClient(settings);
        }
コード例 #5
0
        public ElasticsearchClientOperation(ElasticsearchClientOption operation)
        {
            var node   = new Uri($"http://{operation.Hostname}:{operation.Port.ToString()}");
            var config = new ConnectionConfiguration(node);

            if (!string.IsNullOrEmpty(operation.Username))
            {
                config = config.BasicAuthentication(operation.Username, operation.Password);
            }

            lowLevelClient = new ElasticLowLevelClient(config);
        }
コード例 #6
0
        private ElasticLowLevelClient GetElasticsearchClient()
        {
            var node   = new Uri($"{_elasticsearchConfiguration.Address}:{_elasticsearchConfiguration.Port}");
            var config = new ConnectionConfiguration(node);

            if (!string.IsNullOrWhiteSpace(_elasticsearchConfiguration.Username))
            {
                config.BasicAuthentication(_elasticsearchConfiguration.Username, _elasticsearchConfiguration.Password);
            }

            config.ServerCertificateValidationCallback((o, certificate, arg3, arg4) => true);
            return(new ElasticLowLevelClient(config));
        }
        public static void AddElasticSearch(this IServiceCollection collection, ReservationsConfiguration configuration)
        {
            var connectionPool = new SingleNodeConnectionPool(new Uri(configuration.ElasticSearchServerUrl));

            var settings = new ConnectionConfiguration(connectionPool);

            if (!string.IsNullOrEmpty(configuration.ElasticSearchUsername) &&
                !string.IsNullOrEmpty(configuration.ElasticSearchPassword))
            {
                settings.BasicAuthentication(configuration.ElasticSearchUsername, configuration.ElasticSearchPassword);
            }

            collection.AddTransient <IElasticLowLevelClient>(sp => new ElasticLowLevelClient(settings));
            collection.AddSingleton <IElasticSearchQueries, ElasticSearchQueries>();
        }
コード例 #8
0
        internal ConnectionConfiguration CreateConnectionSettings()
        {
            var settings = new ConnectionConfiguration(CreateConnectionPool());

            // TODO can not pass base64 encoded version on connectionsettings
            // if (!string.IsNullOrWhiteSpace(ApiKey))
            //  settings = settings.ApiKeyAuthentication(new ApiKeyAuthenticationCredentials(ApiKey));

            if (!string.IsNullOrWhiteSpace(Username) && !string.IsNullOrWhiteSpace(Password))
            {
                settings = settings.BasicAuthentication(Username, Password);
            }

            return(settings);
        }
コード例 #9
0
        public void Build()
        {
            //MAPS
            foreach (var map in _process.Maps.Where(m => m.Connection != string.Empty && m.Query != string.Empty))
            {
                var connection = _process.Connections.First(c => c.Name == map.Connection);
                if (connection != null && connection.Provider == "elasticsearch")
                {
                    _builder.Register <IMapReader>(ctx => new DefaultMapReader()).Named <IMapReader>(map.Name);
                }
            }

            //CONNECTIONS
            foreach (var connection in _process.Connections.Where(c => c.Provider == "elasticsearch"))
            {
                if (connection.Servers.Any(s => s.Url != "None"))
                {
                    var uris = new List <Uri>();
                    foreach (var server in connection.Servers.Where(s => s.Url != "None"))
                    {
                        server.Url = server.GetElasticUrl();
                        uris.Add(new Uri(server.Url));
                    }
                    // for now, just use static connection pool, there are 2 other types...
                    _builder.Register <IConnectionPool>(ctx => new StaticConnectionPool(uris)).Named <IConnectionPool>(connection.Key);
                }
                else
                {
                    connection.Url = connection.GetElasticUrl();
                    _builder.Register <IConnectionPool>(ctx => new SingleNodeConnectionPool(new Uri(connection.Url))).Named <IConnectionPool>(connection.Key);
                }

                // Elasticsearch.Net
                _builder.Register(ctx => {
                    var settings = new ConnectionConfiguration(ctx.ResolveNamed <IConnectionPool>(connection.Key));
                    if (!string.IsNullOrEmpty(connection.User))
                    {
                        settings.BasicAuthentication(connection.User, connection.Password);
                    }
                    if (_process.Mode != "init" && connection.RequestTimeout >= 0)
                    {
                        settings.RequestTimeout(new TimeSpan(0, 0, 0, connection.RequestTimeout * 1000));
                    }
                    if (connection.Timeout > 0)
                    {
                        settings.PingTimeout(new TimeSpan(0, 0, connection.Timeout));
                    }
                    return(new ElasticLowLevelClient(settings));
                }).Named <IElasticLowLevelClient>(connection.Key);

                // Process-Level Schema Reader
                _builder.Register <ISchemaReader>(ctx => new ElasticSchemaReader(ctx.ResolveNamed <IConnectionContext>(connection.Key), ctx.ResolveNamed <IElasticLowLevelClient>(connection.Key))).Named <ISchemaReader>(connection.Key);

                // Entity Level Schema Readers
                foreach (var entity in _process.Entities.Where(e => e.Input == connection.Name))
                {
                    _builder.Register <ISchemaReader>(ctx => new ElasticSchemaReader(ctx.ResolveNamed <IConnectionContext>(entity.Key), ctx.ResolveNamed <IElasticLowLevelClient>(connection.Key))).Named <ISchemaReader>(entity.Key);
                }
            }

            // Entity Input
            foreach (var entity in _process.Entities.Where(e => _process.Connections.First(c => c.Name == e.Input).Provider == "elasticsearch"))
            {
                _builder.Register <IInputProvider>(ctx => {
                    var input = ctx.ResolveNamed <InputContext>(entity.Key);
                    return(new ElasticInputProvider(input, ctx.ResolveNamed <IElasticLowLevelClient>(input.Connection.Key)));
                }).Named <IInputProvider>(entity.Key);

                // INPUT READER
                _builder.Register <IRead>(ctx => {
                    var input      = ctx.ResolveNamed <InputContext>(entity.Key);
                    var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", input.RowCapacity));

                    if (entity.Query == string.Empty)
                    {
                        return(new ElasticReader(input, input.InputFields, ctx.ResolveNamed <IElasticLowLevelClient>(input.Connection.Key), rowFactory, ReadFrom.Input));
                    }
                    return(new ElasticQueryReader(input, ctx.ResolveNamed <IElasticLowLevelClient>(input.Connection.Key), rowFactory));
                }).Named <IRead>(entity.Key);
            }

            // Entity Output
            if (_process.GetOutputConnection().Provider == "elasticsearch")
            {
                // PROCESS OUTPUT CONTROLLER
                _builder.Register <IOutputController>(ctx => new NullOutputController()).As <IOutputController>();

                // PROCESS INITIALIZER
                _builder.Register <IInitializer>(ctx => {
                    var output = ctx.Resolve <OutputContext>();
                    return(new ElasticInitializer(output, ctx.ResolveNamed <IElasticLowLevelClient>(output.Connection.Key)));
                }).As <IInitializer>();

                foreach (var entity in _process.Entities)
                {
                    // UPDATER
                    _builder.Register <IUpdate>(ctx => {
                        var output = ctx.ResolveNamed <OutputContext>(entity.Key);
                        output.Debug(() => $"{output.Connection.Provider} does not denormalize.");
                        return(new NullMasterUpdater());
                    }).Named <IUpdate>(entity.Key);

                    // OUTPUT
                    _builder.Register <IOutputController>(ctx => {
                        var output = ctx.ResolveNamed <OutputContext>(entity.Key);
                        switch (output.Connection.Provider)
                        {
                        case "elasticsearch":
                            var initializer = _process.Mode == "init" ? (IAction) new ElasticEntityInitializer(output, ctx.ResolveNamed <IElasticLowLevelClient>(output.Connection.Key)) : new NullInitializer();
                            return(new ElasticOutputController(
                                       output,
                                       initializer,
                                       ctx.ResolveNamed <IInputProvider>(entity.Key),
                                       new ElasticOutputProvider(output, ctx.ResolveNamed <IElasticLowLevelClient>(output.Connection.Key)),
                                       ctx.ResolveNamed <IElasticLowLevelClient>(output.Connection.Key)
                                       ));

                        default:
                            return(new NullOutputController());
                        }
                    }).Named <IOutputController>(entity.Key);

                    // WRITER
                    _builder.Register <IWrite>(ctx => {
                        var output = ctx.ResolveNamed <OutputContext>(entity.Key);

                        switch (output.Connection.Provider)
                        {
                        case "elasticsearch":
                            return(new ElasticWriter(output, ctx.ResolveNamed <IElasticLowLevelClient>(output.Connection.Key)));

                        default:
                            return(new NullWriter(output));
                        }
                    }).Named <IWrite>(entity.Key);

                    // DELETE HANDLER
                    if (entity.Delete)
                    {
                        _builder.Register <IEntityDeleteHandler>(ctx => {
                            var context      = ctx.ResolveNamed <IContext>(entity.Key);
                            var inputContext = ctx.ResolveNamed <InputContext>(entity.Key);
                            var rowFactory   = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", inputContext.RowCapacity));
                            IRead input      = new NullReader(context);
                            var primaryKey   = entity.GetPrimaryKey();

                            switch (inputContext.Connection.Provider)
                            {
                            case "elasticsearch":
                                input = new ElasticReader(
                                    inputContext,
                                    primaryKey,
                                    ctx.ResolveNamed <IElasticLowLevelClient>(inputContext.Connection.Key),
                                    rowFactory,
                                    ReadFrom.Input
                                    );
                                break;
                            }

                            IRead output         = new NullReader(context);
                            IDelete deleter      = new NullDeleter(context);
                            var outputConnection = _process.GetOutputConnection();
                            var outputContext    = ctx.ResolveNamed <OutputContext>(entity.Key);

                            switch (outputConnection.Provider)
                            {
                            case "elasticsearch":
                                output = new ElasticReader(
                                    outputContext,
                                    primaryKey,
                                    ctx.ResolveNamed <IElasticLowLevelClient>(inputContext.Connection.Key),
                                    rowFactory,
                                    ReadFrom.Output
                                    );
                                deleter = new ElasticPartialUpdater(
                                    outputContext,
                                    new[] { context.Entity.TflDeleted() },
                                    ctx.ResolveNamed <IElasticLowLevelClient>(inputContext.Connection.Key)
                                    );
                                break;
                            }

                            var handler = new DefaultDeleteHandler(context, input, output, deleter);

                            // since the primary keys from the input may have been transformed into the output, you have to transform before comparing
                            // feels a lot like entity pipeline on just the primary keys... may look at consolidating
                            handler.Register(new DefaultTransform(context, entity.GetPrimaryKey().ToArray()));
                            handler.Register(TransformFactory.GetTransforms(ctx, context, primaryKey));
                            handler.Register(new StringTruncateTransfom(context, primaryKey));

                            return(handler);
                        }).Named <IEntityDeleteHandler>(entity.Key);
                    }
                }
            }
        }