Class: ElasticGraph::DatastoreCore

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_graph/datastore_core.rb,
lib/elastic_graph/datastore_core/config.rb,
lib/elastic_graph/datastore_core/index_definition.rb,
lib/elastic_graph/datastore_core/index_definition/base.rb,
lib/elastic_graph/datastore_core/index_definition/index.rb,
lib/elastic_graph/datastore_core/index_config_normalizer.rb,
lib/elastic_graph/datastore_core/configuration/index_definition.rb,
lib/elastic_graph/datastore_core/index_definition/rollover_index.rb,
lib/elastic_graph/datastore_core/configuration/cluster_definition.rb,
lib/elastic_graph/datastore_core/configuration/client_faraday_adapter.rb,
lib/elastic_graph/datastore_core/index_definition/rollover_index_template.rb

Overview

The entry point into this library. Create an instance of this class to get access to the public interfaces provided by this library.

Defined Under Namespace

Modules: Configuration, IndexConfigNormalizer, IndexDefinition Classes: Config

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config:, logger:, schema_artifacts:, clients_by_name: nil, client_customization_block: nil) ⇒ DatastoreCore

Returns a new instance of DatastoreCore.



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/elastic_graph/datastore_core.rb', line 29

def initialize(
  config:,
  logger:,
  schema_artifacts:,
  clients_by_name: nil,
  client_customization_block: nil
)
  @config = config
  @logger = logger
  @schema_artifacts = schema_artifacts
  @clients_by_name = clients_by_name
  @client_customization_block = client_customization_block
end

Instance Attribute Details

#client_customization_blockObject (readonly)

Returns the value of attribute client_customization_block.



18
19
20
# File 'lib/elastic_graph/datastore_core.rb', line 18

def client_customization_block
  @client_customization_block
end

#configObject (readonly)

Returns the value of attribute config.



18
19
20
# File 'lib/elastic_graph/datastore_core.rb', line 18

def config
  @config
end

#loggerObject (readonly)

Returns the value of attribute logger.



18
19
20
# File 'lib/elastic_graph/datastore_core.rb', line 18

def logger
  @logger
end

#schema_artifactsObject (readonly)

Returns the value of attribute schema_artifacts.



18
19
20
# File 'lib/elastic_graph/datastore_core.rb', line 18

def schema_artifacts
  @schema_artifacts
end

Class Method Details

.from_parsed_yaml(parsed_yaml, for_context:, &client_customization_block) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/elastic_graph/datastore_core.rb', line 20

def self.from_parsed_yaml(parsed_yaml, for_context:, &client_customization_block)
  new(
    config: DatastoreCore::Config.from_parsed_yaml(parsed_yaml),
    logger: Support::Logger.from_parsed_yaml(parsed_yaml),
    schema_artifacts: SchemaArtifacts.from_parsed_yaml(parsed_yaml, for_context: for_context),
    client_customization_block: client_customization_block
  )
end

Instance Method Details

#clients_by_nameObject

Exposes the datastore clients in a map, keyed by cluster name.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/elastic_graph/datastore_core.rb', line 76

def clients_by_name
  @clients_by_name ||= begin
    if (adapter_lib = config.client_faraday_adapter&.require)
      require adapter_lib
    end

    adapter_name = config.client_faraday_adapter&.name
    client_logger = config.log_traffic ? logger : nil

    config.clusters.to_h do |name, cluster_def|
      client = cluster_def.backend_client_class.new(
        name,
        faraday_adapter: adapter_name,
        url: cluster_def.url,
        logger: client_logger,
        retry_on_failure: config.max_client_retries,
        &@client_customization_block
      )

      [name, client]
    end
  end
end

#index_definitions_by_graphql_typeObject

Exposes the datastore index definitions as a map, keyed by GraphQL type. Note: the GraphQL type name is also used in non-GraphQL contexts (e.g. it is used in events processed by elasticgraph-indexer), so we expose this hear instead of from elasticgraph-graphql.



64
65
66
67
68
69
70
71
72
73
# File 'lib/elastic_graph/datastore_core.rb', line 64

def index_definitions_by_graphql_type
  @index_definitions_by_graphql_type ||= schema_artifacts
    .
    .object_types_by_name
    .transform_values do ||
      .index_definition_names.map do |name|
        index_definitions_by_name.fetch(name)
      end
    end
end

#index_definitions_by_nameObject

Exposes the datastore index definitions as a map, keyed by index definition name.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/elastic_graph/datastore_core.rb', line 44

def index_definitions_by_name
  @index_definitions_by_name ||= begin
    require "elastic_graph/datastore_core/index_definition"
    schema_artifacts..index_definitions_by_name.to_h do |name, |
      index_def = IndexDefinition.with(
        name: name,
        runtime_metadata: ,
        config: config,
        datastore_clients_by_name: clients_by_name
      )

      [name, index_def]
    end
  end
end