-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,290 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
[project] | ||
name = "mydiracx-db" | ||
description = "TODO" | ||
readme = "README.md" | ||
requires-python = ">=3.10" | ||
keywords = [] | ||
license = {text = "GPL-3.0-only"} | ||
classifiers = [ | ||
"Intended Audience :: Science/Research", | ||
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)", | ||
"Programming Language :: Python :: 3", | ||
"Topic :: Scientific/Engineering", | ||
"Topic :: System :: Distributed Computing", | ||
] | ||
dependencies = [ | ||
"dirac", | ||
"diracx-core", | ||
"fastapi", | ||
"opensearch-py[async]", | ||
"pydantic", | ||
"sqlalchemy[aiomysql,aiosqlite]", | ||
] | ||
dynamic = ["version"] | ||
|
||
[project.optional-dependencies] | ||
testing = [ | ||
"diracx-testing", | ||
] | ||
|
||
[project.entry-points."diracx.db.sql"] | ||
DummyDB = "mydiracx.db.sql:DummyDB" | ||
|
||
[tool.setuptools.packages.find] | ||
where = ["src"] | ||
|
||
[build-system] | ||
requires = ["setuptools>=61", "wheel", "setuptools_scm>=8"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.setuptools_scm] | ||
root = "../../.." | ||
|
||
[tool.pytest.ini_options] | ||
testpaths = ["tests"] | ||
addopts = [ | ||
"-v", | ||
"--cov=diracx.db", "--cov-report=term-missing", | ||
"-pdiracx.testing", "-pdiracx.testing.osdb", | ||
"--import-mode=importlib", | ||
] | ||
asyncio_mode = "auto" | ||
markers = [ | ||
"enabled_dependencies: List of dependencies which should be available to the FastAPI test client", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from __future__ import annotations | ||
|
||
__all__ = ("sql", "os", "exceptions") | ||
|
||
from . import exceptions, os, sql |
56 changes: 56 additions & 0 deletions
56
extensions/mydiracx/mydiracx-db/src/mydiracx/db/__main__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from __future__ import annotations | ||
|
||
import argparse | ||
import asyncio | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser() | ||
subparsers = parser.add_subparsers(required=True) | ||
|
||
init_sql_parser = subparsers.add_parser( | ||
"init-sql", help="Initialise schema for SQL databases" | ||
) | ||
init_sql_parser.set_defaults(func=init_sql) | ||
|
||
init_os_parser = subparsers.add_parser( | ||
"init-os", help="Initialise schema for OpenSearch databases" | ||
) | ||
init_os_parser.set_defaults(func=init_os) | ||
|
||
args = parser.parse_args() | ||
logger.setLevel(logging.INFO) | ||
asyncio.run(args.func()) | ||
|
||
|
||
async def init_sql(): | ||
logger.info("Initialising SQL databases") | ||
from diracx.db.sql.utils import BaseSQLDB | ||
|
||
for db_name, db_url in BaseSQLDB.available_urls().items(): | ||
logger.info("Initialising %s", db_name) | ||
db = BaseSQLDB.available_implementations(db_name)[0](db_url) | ||
async with db.engine_context(): | ||
async with db.engine.begin() as conn: | ||
# set PRAGMA foreign_keys=ON if sqlite | ||
if db._db_url.startswith("sqlite"): | ||
await conn.exec_driver_sql("PRAGMA foreign_keys=ON") | ||
await conn.run_sync(db.metadata.create_all) | ||
|
||
|
||
async def init_os(): | ||
logger.info("Initialising OpenSearch databases") | ||
from diracx.db.os.utils import BaseOSDB | ||
|
||
for db_name, db_url in BaseOSDB.available_urls().items(): | ||
logger.info("Initialising %s", db_name) | ||
db = BaseOSDB.available_implementations(db_name)[0](db_url) | ||
async with db.client_context(): | ||
await db.create_index_template() | ||
|
||
|
||
if __name__ == "__main__": | ||
parse_args() |
2 changes: 2 additions & 0 deletions
2
extensions/mydiracx/mydiracx-db/src/mydiracx/db/exceptions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class DBUnavailable(Exception): | ||
pass |
5 changes: 5 additions & 0 deletions
5
extensions/mydiracx/mydiracx-db/src/mydiracx/db/os/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from __future__ import annotations | ||
|
||
__all__ = ("JobParametersDB",) | ||
|
||
from .job_parameters import JobParametersDB |
25 changes: 25 additions & 0 deletions
25
extensions/mydiracx/mydiracx-db/src/mydiracx/db/os/job_parameters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from __future__ import annotations | ||
|
||
from diracx.db.os.utils import BaseOSDB | ||
|
||
|
||
class JobParametersDB(BaseOSDB): | ||
fields = { | ||
"JobID": {"type": "long"}, | ||
"timestamp": {"type": "date"}, | ||
"CPUNormalizationFactor": {"type": "long"}, | ||
"NormCPUTime(s)": {"type": "long"}, | ||
"Memory(kB)": {"type": "long"}, | ||
"TotalCPUTime(s)": {"type": "long"}, | ||
"MemoryUsed(kb)": {"type": "long"}, | ||
"HostName": {"type": "keyword"}, | ||
"GridCE": {"type": "keyword"}, | ||
"ModelName": {"type": "keyword"}, | ||
"Status": {"type": "keyword"}, | ||
"JobType": {"type": "keyword"}, | ||
} | ||
index_prefix = "mysetup_elasticjobparameters_index_" | ||
|
||
def index_name(self, doc_id: int) -> str: | ||
# TODO: Remove setup and replace "123.0m" with "120m"? | ||
return f"{self.index_prefix}_{doc_id // 1e6:.1f}m" |
Oops, something went wrong.