OpenSearch Databases
OpenSearch-based database implementations.
Job Parameters
job_parameters
Classes
JobParametersDB
Bases: BaseOSDB
Source code in diracx-db/src/diracx/db/os/job_parameters.py
Attributes
fields = {'JobID': {'type': 'long'}, 'timestamp': {'type': 'date'}, 'PilotAgent': {'type': 'keyword'}, 'Pilot_Reference': {'type': 'keyword'}, 'JobGroup': {'type': 'keyword'}, 'CPUNormalizationFactor': {'type': 'long'}, 'NormCPUTime(s)': {'type': 'long'}, 'Memory(MB)': {'type': 'long'}, 'LocalAccount': {'type': 'keyword'}, 'TotalCPUTime(s)': {'type': 'long'}, 'PayloadPID': {'type': 'long'}, 'HostName': {'type': 'text'}, 'GridCE': {'type': 'keyword'}, 'CEQueue': {'type': 'keyword'}, 'BatchSystem': {'type': 'keyword'}, 'ModelName': {'type': 'keyword'}, 'Status': {'type': 'keyword'}, 'JobType': {'type': 'keyword'}}
class-attribute
instance-attribute
index_prefix = 'job_parameters'
class-attribute
instance-attribute
Functions
index_name(vo, doc_id)
Utilities
utils
Attributes
logger = logging.getLogger(__name__)
module-attribute
Classes
OpenSearchDBError
OpenSearchDBUnavailableError
Bases: DBUnavailableError, OpenSearchDBError
BaseOSDB
This should be the base class of all the OpenSearch DiracX DBs.
The details covered here should be handled automatically by the service and task machinery of DiracX and this documentation exists for informational purposes.
The available OpenSearch databases are discovered by calling BaseOSDB.available_urls.
This method returns a dictionary of database names to connection parameters.
The available databases are determined by the diracx.dbs.os entrypoint in
the pyproject.toml file and the connection parameters are taken from the
environment variables prefixed with DIRACX_OS_DB_{DB_NAME}.
If extensions to DiracX are being used, there can be multiple implementations
of the same database. To list the available implementations use
BaseOSDB.available_implementations(db_name). The first entry in this list
will be the preferred implementation and it can be initialized by calling
its __init__ function with the connection parameters previously obtained
from BaseOSDB.available_urls.
To control the lifetime of the OpenSearch client, the BaseOSDB.client_context
asynchronous context manager should be entered. When inside this context
manager, the client can be accessed with BaseOSDB.client.
Upon entering, the DB class can then be used as an asynchronous context
manager to perform operations. Currently this context manager has no effect
however it must be used as it may be used in future. When inside this
context manager, the DB connection can be accessed with BaseOSDB.client.
For example:
db_name = ...
conn_params = BaseOSDB.available_urls()[db_name]
MyDBClass = BaseOSDB.available_implementations(db_name)[0]
db = MyDBClass(conn_params)
async with db.client_context:
async with db:
# Do something with the OpenSearch client
Source code in diracx-db/src/diracx/db/os/utils.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
Attributes
fields
instance-attribute
index_prefix
instance-attribute
client
property
Just a getter for _client, making sure we entered the context manager.
Functions
index_name(vo, doc_id)
abstractmethod
available_implementations(db_name)
classmethod
Return the available implementations of the DB in reverse priority order.
Source code in diracx-db/src/diracx/db/os/utils.py
available_urls()
classmethod
Return a dict of available OpenSearch database urls.
The list of available URLs is determined by environment variables
prefixed with DIRACX_OS_DB_{DB_NAME}.
Source code in diracx-db/src/diracx/db/os/utils.py
session()
classmethod
This is just a fake method such that the Dependency overwrite has a hash to use.
client_context()
async
Context manage to manage the client lifecycle. This is called when starting fastapi.
Source code in diracx-db/src/diracx/db/os/utils.py
ping()
async
Check whether the connection to the DB is still working.
We could enable the pre_ping in the engine, but this would
be ran at every query.
Source code in diracx-db/src/diracx/db/os/utils.py
create_index_template()
async
Source code in diracx-db/src/diracx/db/os/utils.py
upsert(vo, doc_id, document)
async
Source code in diracx-db/src/diracx/db/os/utils.py
search(parameters, search, sorts, *, per_page=100, page=None)
async
Search the database for matching results.
See the DiracX search API documentation for details.
Source code in diracx-db/src/diracx/db/os/utils.py
Functions
require_type(operator, field_name, field_type, allowed_types)
apply_search_filters(db_fields, search)
Build an OpenSearch query from the given DiracX search parameters.
If the searched parameters cannot be efficiently translated to a query for OpenSearch an InvalidQueryError exception is raised.