Skip to content

Commit

Permalink
feat: ElasticJobParameters index new names: JobParameters_indexSplt
Browse files Browse the repository at this point in the history
  • Loading branch information
fstagni committed Apr 16, 2024
1 parent 8fd8f25 commit 0f463fd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/DIRAC/Core/Base/ElasticDB.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
""" ElasticDB is a base class used to connect an Elasticsearch database and manages queries.
"""
from DIRAC.ConfigurationSystem.Client.Utilities import getElasticDBParameters
from DIRAC.Core.Base.DIRACDB import DIRACDB
from DIRAC.Core.Utilities.ElasticSearchDB import ElasticSearchDB
from DIRAC.ConfigurationSystem.Client.Utilities import getElasticDBParameters


class ElasticDB(DIRACDB, ElasticSearchDB):
Expand Down
19 changes: 6 additions & 13 deletions src/DIRAC/WorkloadManagementSystem/DB/ElasticJobParametersDB.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
""" Module containing a front-end to the ElasticSearch-based ElasticJobParametersDB.
This is a drop-in replacement for MySQL-based table JobDB.JobParameters.
The reason for switching to a ES-based JobParameters lies in the extended searching
capabilities of ES.
This results in higher traceability for DIRAC jobs.
The following class methods are provided for public usage
- getJobParameters()
- setJobParameter()
- deleteJobParameters()
"""
from DIRAC import S_ERROR, S_OK
from DIRAC.ConfigurationSystem.Client.Helpers import CSGlobals
from DIRAC.Core.Base.ElasticDB import ElasticDB
from DIRAC.Core.Utilities import TimeUtilities


mapping = {
"properties": {
"JobID": {"type": "long"},
Expand All @@ -38,24 +32,23 @@ class ElasticJobParametersDB(ElasticDB):
def __init__(self, parentLogger=None):
"""Standard Constructor"""

try:
indexPrefix = CSGlobals.getSetup().lower()
self.fullname = "WorkloadManagement/ElasticJobParametersDB"
self.index_name = self.getCSOption("index_name", "job_parameters")

try:
# Connecting to the ES cluster
super().__init__("WorkloadManagement/ElasticJobParametersDB", indexPrefix, parentLogger=parentLogger)
super().__init__(self.fullname, self.index_name, parentLogger=parentLogger)
except Exception as ex:
self.log.error("Can't connect to ElasticJobParametersDB", repr(ex))
raise RuntimeError("Can't connect to ElasticJobParametersDB") from ex

self.indexName_base = f"{self.getIndexPrefix()}_elasticjobparameters_index"

def _indexName(self, jobID: int) -> str:
"""construct the index name
:param jobID: Job ID
"""
indexSplit = int(jobID) // 1e6
return f"{self.indexName_base}_{indexSplit}m"
indexSplit = int(jobID // 1e6)
return f"{self.index_name}_{indexSplit}m"

def _createIndex(self, indexName: str) -> None:
"""Create a new index if needed
Expand Down

0 comments on commit 0f463fd

Please sign in to comment.