Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion diracx-db/src/diracx/db/os/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,15 @@ def available_urls(cls) -> dict[str, dict[str, Any]]:
for entry_point in select_from_extension(group=DiracEntryPoint.OS_DB):
db_name = entry_point.name
# Get the field value from the OpenSearchDBSettings model
if field_value := factory_settings.opensearch_dbs.get(db_name):
field_value = factory_settings.opensearch_dbs.get(db_name)
if field_value == "" or not field_value:
logger.warning(
"%s found but no URL connection set: please set "
"DIRACX_OS_DB_%s env variable to enable it.",
db_name,
db_name.upper(),
)
else:
try:
conn_kwargs[db_name] = json.loads(field_value)
except Exception:
Expand Down
10 changes: 9 additions & 1 deletion diracx-db/src/diracx/db/sql/utils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,15 @@ def available_urls(cls) -> dict[str, str]:
for entry_point in select_from_extension(group=DiracEntryPoint.SQL_DB):
db_name = entry_point.name
# Get the field value from the SqlDBSettings model
if db_url := factory_settings.sql_dbs.get(db_name):
db_url = factory_settings.sql_dbs.get(db_name)
if db_url == "" or not db_url:
logger.warning(
"%s found but no URL connection set: please set "
"DIRACX_DB_URL_%s env variable to enable it.",
db_name,
db_name.upper(),
)
else:
try:
if db_url == "sqlite+aiosqlite:///:memory:":
db_urls[db_name] = db_url
Expand Down
26 changes: 21 additions & 5 deletions diracx-routers/src/diracx/routers/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,14 @@ def create_app_inner(
logger.exception("Failed to initialize DB %s", db_name)

if fail_startup:
raise Exception("No SQL database could be initialized, aborting")
raise Exception(
"No SQL database could be initialized, aborting. "
"Please set the following env variables to enable it:\n "
+ "\n ".join(
"DIRACX_DB_URL_" + ep.name.upper()
for ep in select_from_extension(group=DiracEntryPoint.SQL_DB)
)
)

# Instantiate the cacheable sources and override their create methods,
# mirroring the SQL DB wiring above. A single instance is used for each
Expand Down Expand Up @@ -277,22 +284,31 @@ def create_app_inner(
f"Cannot enable {system_name=} as it requires {cls=}"
)

# Ensure required DBs are available
# Ensure required SQL DBs are available
missing_sql_dbs = (
set(find_dependents(router, BaseSQLDB)) - available_sql_db_classes
)

if missing_sql_dbs:
raise NotImplementedError(
f"Cannot enable {system_name=} as it requires {missing_sql_dbs=}"
f"Cannot enable {system_name=} please set the following env "
"variables to enable it:\n "
+ "\n ".join(
"DIRACX_DB_URL_" + x.__name__.upper() for x in missing_sql_dbs
)
)

# Ensure required OpenSearch DBs are available
missing_os_dbs = (
set(find_dependents(router, BaseOSDB)) # type: ignore[type-abstract]
- available_os_db_classes
)
if missing_os_dbs:
raise NotImplementedError(
f"Cannot enable {system_name=} as it requires {missing_os_dbs=}"
f"Cannot enable {system_name=} please set the following env "
"variables to enable it:\n "
+ "\n ".join(
"DIRACX_OS_DB_" + x.__name__.upper() for x in missing_os_dbs
)
)

# Ensure required cacheable sources have been wired, i.e. that the
Expand Down
Loading