Skip to content

Latest commit

 

History

History
185 lines (131 loc) · 8.42 KB

File metadata and controls

185 lines (131 loc) · 8.42 KB

ElasticsearchService.js

This is a description of file ElasticsearchService.js. For more information about the Elasticsearch concept, consult here.

new ElasticsearchService()

This class represents Elasticsearch service running on server.

Version of Elasticsearch used is 7.

Exported is one instance of this class.

elasticsearchService.getClient

elasticsearchService.getClient(forceCreate, [uuid]) ⇒ Promise.<object>

This method MUST be called in order to use Elasticsearch client directly. There is always one instance of ES client runnning within this class. This class maintains an ES client for each ES instance configured (uuid). If any information from following list changes, it's the responsibility of the caller to set 'forceCreate' parameter to true.

  • IP address
  • protocol
  • port
  • API key

Each error coming from Elasticsearch is logged to console. Users of this client MUST handle ElasticsearchClientError accordingly.

Client is configured with 2s request timeout. If a request is expected to take longer, this parameter can be overriden in the specific request.

Returns: Promise.<object> - Elasticsearch client version 7

Param Type Description
forceCreate boolean should be set to true in caller methods where any attribute of ES configuration has changed, eg. IP address, API Key to force recreating the client.
[uuid] String optional, Elasticsearch client uuid, denotes client uuid (MUST be used if there are more ES clients configured)

elasticsearchService.getElasticsearchClientOperationalStateAsync

elasticsearchService.getElasticsearchClientOperationalStateAsync([uuid]) ⇒ Promise.<String>

Issues ping to Elasticsearch instance. Returns operational state UNAVAILABLE if a connection error occurs. MUST be used to implement getElasticsearchClientOperationalState REST API method

Returns: Promise.<String> - AVAILABLE if the ping returns with http status code 200, UNAVAILABLE if not

Param Type Description
[uuid] String optional, UUID of Elasticsearch client

elasticsearchService.putElasticsearchClientServiceRecordsPolicyAsync

elasticsearchService.putElasticsearchClientServiceRecordsPolicyAsync(uuid, body) ⇒ Promise.<object>

Creates/updates service records policy object in Elasticsearch instance MUST be used to implement putElasticsearchClientServiceRecordsPolicy REST API method

Returns: Promise.<object> - result of the putLifecycle operation

Param Type Description
uuid String optional, UUID of Elasticsearch client
body object service records policy

elasticsearchService.assignPolicyToIndexTemplate

elasticsearchService.assignPolicyToIndexTemplate(policyName, [uuid]) ⇒ Promise.<void>

Rewrites index-template to include service policy with given name.

This method will be also called when index-alias changes in the config file, to 'reassign' service policy from old index-alias to new one.

Param Type Description
policyName String Service policy that should be assigned to configured index-alias.
[uuid] String UUID of ES client in Config file

elasticsearchService.getExistingIndexTemplate

elasticsearchService.getExistingIndexTemplate([uuid]) ⇒ Promise.<Object>

Returns index-template associated with configured index-alias. First request returns all configured index-templates, where it searches for index-alias among index-patterns.

Returns: Promise.<Object> - existing template or undefined if there is no such template

Param Type Description
[uuid] String UUID of ES client in Config file

elasticsearchService.getElasticsearchClientServiceRecordsPolicyAsync

elasticsearchService.getElasticsearchClientServiceRecordsPolicyAsync([uuid]) ⇒ Promise.<object>

Fetches service records policy associated with configured index alias. MUST be used to implement getElasticsearchClientServiceRecordsPolicy REST API method

Returns: Promise.<object> - service records policy if the policy exists

Param Type Description
[uuid] String optional, UUID of Elasticsearch client

elasticsearchService.updateControlConstructWithServicePolicy

elasticsearchService.updateControlConstructWithServicePolicy(controlConstruct) ⇒ Promise.<Object>

Updates controlConstruct object with information about service policy configured for each Elasticsearch client.

Returns: Promise.<Object> - controlConstruct object enriched with service-policy-record object

Param Type
controlConstruct Object

elasticsearchService.createAlias

elasticsearchService.createAlias([uuid]) ⇒ Promise.<void>

Creates index-alias with first index serving as write_index (if such alias does not exist yet). Such index will always end with '-000001' to allow for automated rollover.

Param Type Description
[uuid] String optional, UUID of Elasticsearch client

getApiKeyAsync

getApiKeyAsync([uuid]) ⇒ Promise.<String>

Performs uuid check.

Returns: Promise.<String> - configured API key for Elasticsearch

Param Type Description
[uuid] String optional, UUID of Elasticsearch client

getIndexAliasAsync

getIndexAliasAsync([uuid]) ⇒ Promise.<String>

Returns index alias from config file. If uuid is present, performs check if its an ES client uuid, if it's not present, assumes only one ES client is configured.

Returns: Promise.<String> - index alias from config file

Param Type Description
[uuid] String optional, UUID of Elasticsearch client

createResultArray

createResultArray(result) ⇒ Array

Helper method, creates Javascript array from Elasticsearch response.

Returns: Array - resulting array

Param Type Description
result object Elasticsearch response

isTcpClientElasticsearch

isTcpClientElasticsearch(tcpClientUuid) ⇒ Promise.<boolean>

Checks whether given TCP client UUID belongs to an Elasticsearch client.

Returns: Promise.<boolean> - true if the TCP client is configured for an Elasticsearch client

Param Type Description
tcpClientUuid String TCP client UUID