Class: Core::ConnectorSettings
- Inherits:
-
Object
- Object
- Core::ConnectorSettings
- Defined in:
- lib/core/connector_settings.rb
Constant Summary collapse
- DEFAULT_REQUEST_PIPELINE =
'ent-search-generic-ingestion'
- DEFAULT_EXTRACT_BINARY_CONTENT =
true
- DEFAULT_REDUCE_WHITESPACE =
true
- DEFAULT_RUN_ML_INFERENCE =
true
- DEFAULT_FILTERING =
{}
- DEFAULT_PAGE_SIZE =
100
Class Method Summary collapse
- .fetch_all_connectors(page_size = DEFAULT_PAGE_SIZE) ⇒ Object
- .fetch_by_id(connector_id) ⇒ Object
- .fetch_crawler_connectors(page_size = DEFAULT_PAGE_SIZE) ⇒ Object
- .fetch_native_connectors(page_size = DEFAULT_PAGE_SIZE) ⇒ Object
Instance Method Summary collapse
- #[](property_name) ⇒ Object
- #any_filtering_feature_enabled? ⇒ Boolean
- #configuration ⇒ Object
- #connector_status ⇒ Object
- #connector_status_allows_sync? ⇒ Boolean
- #custom_scheduling_settings ⇒ Object
- #features ⇒ Object
- #filtering ⇒ Object
- #filtering_advanced_config_feature_enabled? ⇒ Boolean
-
#filtering_rule_feature_enabled? ⇒ Boolean
.dig version is the modern features way of doing things, Right-hand of OR operator is legacy features support When this is fixed with a migration, we can go ahead.
- #formatted ⇒ Object
- #full_sync_scheduling ⇒ Object
- #id ⇒ Object
- #index_name ⇒ Object
- #last_synced ⇒ Object
- #needs_service_type? ⇒ Boolean
- #ready_for_sync? ⇒ Boolean
- #request_pipeline ⇒ Object
- #running? ⇒ Boolean
- #scheduling_settings ⇒ Object
- #service_type ⇒ Object
- #sync_now? ⇒ Boolean
- #update_last_sync!(job) ⇒ Object
- #valid_index_name? ⇒ Boolean
Class Method Details
.fetch_all_connectors(page_size = DEFAULT_PAGE_SIZE) ⇒ Object
53 54 55 56 |
# File 'lib/core/connector_settings.rb', line 53 def self.fetch_all_connectors(page_size = DEFAULT_PAGE_SIZE) query = { match_all: {} } fetch_connectors_by_query(query, page_size) end |
.fetch_by_id(connector_id) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/core/connector_settings.rb', line 27 def self.fetch_by_id(connector_id) es_response = ElasticConnectorActions.get_connector(connector_id) return nil unless es_response[:found] = ElasticConnectorActions. new(es_response, ) end |
.fetch_crawler_connectors(page_size = DEFAULT_PAGE_SIZE) ⇒ Object
48 49 50 51 |
# File 'lib/core/connector_settings.rb', line 48 def self.fetch_crawler_connectors(page_size = DEFAULT_PAGE_SIZE) query = { term: { service_type: Utility::Constants::CRAWLER_SERVICE_TYPE } } fetch_connectors_by_query(query, page_size) end |
.fetch_native_connectors(page_size = DEFAULT_PAGE_SIZE) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/core/connector_settings.rb', line 35 def self.fetch_native_connectors(page_size = DEFAULT_PAGE_SIZE) require 'connectors/registry' unless defined?(Connectors::REGISTRY) query = { bool: { filter: [ { term: { is_native: true } }, { terms: { service_type: Connectors::REGISTRY.registered_connectors } } ] } } fetch_connectors_by_query(query, page_size) end |
Instance Method Details
#[](property_name) ⇒ Object
62 63 64 65 |
# File 'lib/core/connector_settings.rb', line 62 def [](property_name) # TODO: handle not found @elasticsearch_response[:_source][property_name] end |
#any_filtering_feature_enabled? ⇒ Boolean
81 82 83 |
# File 'lib/core/connector_settings.rb', line 81 def any_filtering_feature_enabled? filtering_rule_feature_enabled? || filtering_advanced_config_feature_enabled? end |
#configuration ⇒ Object
101 102 103 |
# File 'lib/core/connector_settings.rb', line 101 def configuration self[:configuration] end |
#connector_status ⇒ Object
89 90 91 |
# File 'lib/core/connector_settings.rb', line 89 def connector_status self[:status] end |
#connector_status_allows_sync? ⇒ Boolean
93 94 95 |
# File 'lib/core/connector_settings.rb', line 93 def connector_status_allows_sync? Connectors::ConnectorStatus::STATUSES_ALLOWING_SYNC.include?(connector_status) end |
#custom_scheduling_settings ⇒ Object
113 114 115 |
# File 'lib/core/connector_settings.rb', line 113 def custom_scheduling_settings self[:custom_scheduling] end |
#features ⇒ Object
67 68 69 |
# File 'lib/core/connector_settings.rb', line 67 def features self[:features] || {} end |
#filtering ⇒ Object
125 126 127 128 129 130 |
# File 'lib/core/connector_settings.rb', line 125 def filtering # assume for now, that first object in filtering array or a filter object itself is the only filtering object filtering = @elasticsearch_response.dig(:_source, :filtering) Utility::Filtering.extract_filter(filtering) end |
#filtering_advanced_config_feature_enabled? ⇒ Boolean
77 78 79 |
# File 'lib/core/connector_settings.rb', line 77 def filtering_advanced_config_feature_enabled? !!features.dig(:sync_rules, :advanced, :enabled) || !!features[:filtering_advanced_config] end |
#filtering_rule_feature_enabled? ⇒ Boolean
.dig version is the modern features way of doing things, Right-hand of OR operator is legacy features support When this is fixed with a migration, we can go ahead
74 75 76 |
# File 'lib/core/connector_settings.rb', line 74 def filtering_rule_feature_enabled? !!features.dig(:sync_rules, :basic, :enabled) || !!features[:filtering_rules] end |
#formatted ⇒ Object
136 137 138 139 140 |
# File 'lib/core/connector_settings.rb', line 136 def formatted properties = ["ID: #{id}"] properties << "Service type: #{service_type}" if service_type "connector (#{properties.join(', ')})" end |
#full_sync_scheduling ⇒ Object
109 110 111 |
# File 'lib/core/connector_settings.rb', line 109 def full_sync_scheduling scheduling_settings[:full] end |
#id ⇒ Object
58 59 60 |
# File 'lib/core/connector_settings.rb', line 58 def id @elasticsearch_response[:_id] end |
#index_name ⇒ Object
85 86 87 |
# File 'lib/core/connector_settings.rb', line 85 def index_name self[:index_name] end |
#last_synced ⇒ Object
121 122 123 |
# File 'lib/core/connector_settings.rb', line 121 def last_synced self[:last_synced] end |
#needs_service_type? ⇒ Boolean
142 143 144 |
# File 'lib/core/connector_settings.rb', line 142 def needs_service_type? service_type.to_s.strip.empty? end |
#ready_for_sync? ⇒ Boolean
150 151 152 153 154 |
# File 'lib/core/connector_settings.rb', line 150 def ready_for_sync? Connectors::REGISTRY.registered?(service_type) && valid_index_name? && connector_status_allows_sync? end |
#request_pipeline ⇒ Object
132 133 134 |
# File 'lib/core/connector_settings.rb', line 132 def request_pipeline Utility::Common.return_if_present(@elasticsearch_response.dig(:_source, :pipeline, :name), @connectors_meta.dig(:pipeline, :default_name), DEFAULT_REQUEST_PIPELINE) end |
#running? ⇒ Boolean
156 157 158 |
# File 'lib/core/connector_settings.rb', line 156 def running? @elasticsearch_response[:_source][:last_sync_status] == Connectors::SyncStatus::IN_PROGRESS end |
#scheduling_settings ⇒ Object
105 106 107 |
# File 'lib/core/connector_settings.rb', line 105 def scheduling_settings self[:scheduling] || {} end |
#service_type ⇒ Object
97 98 99 |
# File 'lib/core/connector_settings.rb', line 97 def service_type self[:service_type] end |
#sync_now? ⇒ Boolean
117 118 119 |
# File 'lib/core/connector_settings.rb', line 117 def sync_now? self[:sync_now] == true end |
#update_last_sync!(job) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/core/connector_settings.rb', line 160 def update_last_sync!(job) # if job is nil, connector still needs to be updated, to avoid it stuck at in_progress job_status = job&.status || Connectors::SyncStatus::ERROR job_error = job.nil? ? 'Could\'t find the job' : job.error job_error ||= 'unknown error' if job_status == Connectors::SyncStatus::ERROR connector_status = (job_status == Connectors::SyncStatus::ERROR ? Connectors::ConnectorStatus::ERROR : Connectors::ConnectorStatus::CONNECTED) doc = { :last_sync_status => job_status, :last_synced => Time.now, :last_sync_error => job_error, :status => connector_status, :error => job_error } if job&.terminated? doc[:last_indexed_document_count] = job[:indexed_document_count] doc[:last_deleted_document_count] = job[:deleted_document_count] end Core::ElasticConnectorActions.update_connector_fields(id, doc) end |
#valid_index_name? ⇒ Boolean
146 147 148 |
# File 'lib/core/connector_settings.rb', line 146 def valid_index_name? index_name&.start_with?(Utility::Constants::CONTENT_INDEX_PREFIX) end |