Skip to content

Commit a417797

Browse files
authored
Merge pull request #5698 from rupozzi/replace-ES
[integration] Replace Elasticsearch clients with OpenSearch, remove support for ES6 - resolves #5167
2 parents 1d6220e + 2fb7e78 commit a417797

File tree

6 files changed

+19
-32
lines changed

6 files changed

+19
-32
lines changed

.github/workflows/integration.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ jobs:
3535
ARGS: MYSQL_VER=mysql:5.7
3636
- TEST_NAME: "MariaDB 10.6, opensearch:1.0.0"
3737
ARGS: MYSQL_VER=mariadb:10.6.3 ES_VER=opensearchproject/opensearch:1.0.0
38-
- TEST_NAME: "Elasticsearch 6.6.0"
39-
ARGS: ES_VER=elasticsearch:6.6.0
4038
- TEST_NAME: "HTTPS"
4139
ARGS: TEST_HTTPS=Yes
4240

docs/source/AdministratorGuide/ExternalsSupport/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ ElasticSearch versions:
5757

5858
ElasticSearch is an optional dependency for DIRAC servers installations. Supported versions:
5959

60-
- 6.x
6160
- 7.x
6261

6362
ElasticSearch server is not shipped with DIRAC. You are responsible of its administration.

docs/source/AdministratorGuide/Systems/MonitoringSystem/index.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ Install Elasticsearch
2323
======================
2424

2525
This is not covered here, as installation and administration of ES are not part of DIRAC guide.
26-
Just a note on the ES versions supported: ES7 and ES6 are supported, the support for ES5 is not assured,
27-
and the one for ES6 will be dropped in a future release.
26+
Just a note on the ES versions supported: only ES7+ versions are currently supported, and are later to be replaced by OpenSearch services.
2827

2928
Configure the MonitoringSystem
3029
===============================

environment.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ dependencies:
1919
- db12
2020
- elasticsearch <7.14
2121
- elasticsearch-dsl
22+
- opensearch-py
23+
- opensearch-dsl
2224
- fts3
2325
- future
2426
- gitpython >=2.1.0

src/DIRAC/Core/Utilities/ElasticSearchDB.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
It is used to query Elasticsearch instances.
44
"""
55

6-
from __future__ import absolute_import
7-
from __future__ import division
8-
from __future__ import print_function
9-
10-
__RCSID__ = "$Id$"
11-
126
from datetime import datetime
137
from datetime import timedelta
148

@@ -17,10 +11,16 @@
1711
import functools
1812
import json
1913

20-
from elasticsearch import Elasticsearch
21-
from elasticsearch_dsl import Search, Q, A
22-
from elasticsearch.exceptions import ConnectionError, TransportError, NotFoundError, RequestError
23-
from elasticsearch.helpers import BulkIndexError, bulk
14+
try:
15+
from opensearchpy import OpenSearch as Elasticsearch
16+
from opensearch_dsl import Search, Q, A
17+
from opensearchpy.exceptions import ConnectionError, TransportError, NotFoundError, RequestError
18+
from opensearchpy.helpers import BulkIndexError, bulk
19+
except ImportError:
20+
from elasticsearch import Elasticsearch
21+
from elasticsearch_dsl import Search, Q, A
22+
from elasticsearch.exceptions import ConnectionError, TransportError, NotFoundError, RequestError
23+
from elasticsearch.helpers import BulkIndexError, bulk
2424

2525
from DIRAC import gLogger, S_OK, S_ERROR
2626
from DIRAC.Core.Utilities import Time, DErrno
@@ -53,8 +53,7 @@ def generateDocs(data, withTimeStamp=True):
5353
:return: doc
5454
"""
5555
for doc in copy.deepcopy(data):
56-
if "_type" not in doc:
57-
doc["_type"] = "_doc"
56+
5857
if withTimeStamp:
5958
if "timestamp" not in doc:
6059
sLog.warn("timestamp is not given")
@@ -231,7 +230,7 @@ def update(self, index, query=None, updateByQuery=True, id=None):
231230
if updateByQuery:
232231
esDSLQueryResult = self.client.update_by_query(index=index, body=query)
233232
else:
234-
esDSLQueryResult = self.client.index(index=index, doc_type="_doc", body=query, id=id)
233+
esDSLQueryResult = self.client.index(index=index, body=query, id=id)
235234
return S_OK(esDSLQueryResult)
236235
except RequestError as re:
237236
return S_ERROR(re)
@@ -343,11 +342,8 @@ def createIndex(self, indexPrefix, mapping=None, period="day"):
343342

344343
try:
345344
sLog.info("Create index: ", fullIndex + str(mapping))
346-
try:
347-
self.client.indices.create(index=fullIndex, body={"mappings": mapping}) # ES7
348-
except RequestError as re:
349-
if re.error == "mapper_parsing_exception":
350-
self.client.indices.create(index=fullIndex, body={"mappings": {"_doc": mapping}}) # ES6
345+
self.client.indices.create(index=fullIndex, body={"mappings": mapping}) # ES7
346+
351347
return S_OK(fullIndex)
352348
except Exception as e: # pylint: disable=broad-except
353349
sLog.error("Can not create the index:", repr(e))
@@ -388,7 +384,7 @@ def index(self, indexName, body=None, docID=None):
388384
return S_ERROR("Missing index or body")
389385

390386
try:
391-
res = self.client.index(index=indexName, doc_type="_doc", body=body, id=docID)
387+
res = self.client.index(index=indexName, body=body, id=docID)
392388
except (RequestError, TransportError) as e:
393389
sLog.exception()
394390
return S_ERROR(e)

src/DIRAC/MonitoringSystem/DB/MonitoringDB.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,7 @@ def getKeyValues(self, monitoringType):
138138
docs = retVal["Value"]
139139
self.log.debug("Doc types", docs)
140140
monfields = self.documentTypes[monitoringType]["monitoringFields"]
141-
142-
try:
143-
properties = docs[monitoringType]["properties"] # "old" way, with ES types == Monitoring types
144-
except KeyError:
145-
try:
146-
properties = docs["_doc"]["properties"] # "ES6" way, with ES types == '_doc'
147-
except KeyError:
148-
properties = docs["properties"] # "ES7" way, no types
141+
properties = docs["properties"] # "ES7" way, no types
149142

150143
for i in properties:
151144
if i not in monfields and not i.startswith("time") and i != "metric":

0 commit comments

Comments
 (0)