Skip to content
Merged
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
87 changes: 74 additions & 13 deletions pyegeria/view/dashboard_sheet_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
two stay co-elements: same env-var-driven JSON config pattern, same runtime
registration API, same collision semantics.

Unlike report specs, there is no generated/built-in source here — no
Tinderbox/`refresh_specs` pipeline authors dashboard sheets as Egeria
elements (yet; see egeria-workspaces `OVERVIEW_REPORTING_MODEL.md` §10 for
the plan — Dashboard Sheet is planned to become an Egeria `Collection`
subtype). The registry is CONFIG (env-var JSON files) + RUNTIME (dynamically
registered, e.g. by the Dr.Egeria `Create Dashboard Sheet` command's
processor) only.
Unlike report specs, there is no generated/built-in source here. The tiers,
lowest first:
- EGERIA: sheets held in Egeria 6.3 as Dashboard element chains
(`pyegeria.view.dashboards`), loaded with `refresh_egeria_dashboard_sheets(client)`
or set with `set_egeria_dashboard_sheets(...)`. Never fetched implicitly: reading
the registry makes no Egeria call.
- CONFIG (env-var JSON files) and RUNTIME (registered at run time): the local
sources. Same precedence as report specs: a local sheet overrides a same-named
Egeria sheet, with one warning per name per process; never raised.
`get_dashboard_sheet_tier(name)` says which tier a sheet came from.

This module is hand-written and safe to edit — unlike `base_report_formats.py`,
nothing regenerates it.
Expand All @@ -30,6 +33,10 @@

__all__ = [
'DashboardSheetCollision',
'clear_egeria_dashboard_sheets',
'get_dashboard_sheet_tier',
'refresh_egeria_dashboard_sheets',
'set_egeria_dashboard_sheets',
'refresh_dashboard_sheets',
'get_dashboard_sheet_registry',
'register_dashboard_sheets',
Expand All @@ -39,6 +46,9 @@

_RUNTIME_DASHBOARD_SHEETS = DashboardSheetDict()
_CONFIG_DASHBOARD_SHEETS = DashboardSheetDict()
_EGERIA_DASHBOARD_SHEETS = DashboardSheetDict()
_REGISTRY_TIERS: dict = {}
_SHADOW_WARNED: set = set()


class DashboardSheetCollision(ValueError):
Expand Down Expand Up @@ -101,21 +111,72 @@ def refresh_dashboard_sheets() -> None:


def get_dashboard_sheet_registry() -> DashboardSheetDict:
"""Combine config-loaded and runtime dashboard sheets. Enforce no
duplicate names across sources."""
"""Combine the Egeria, config-loaded and runtime dashboard sheets.

The local sources (CONFIG, RUNTIME) must not repeat a name between them (that raises, as before). A
local sheet overrides a same-named Egeria sheet: the Egeria one is left out, with one warning per name
per process."""
local = DashboardSheetDict()
_add_with_collision_check(local, _CONFIG_DASHBOARD_SHEETS, source="CONFIG")
_add_with_collision_check(local, _RUNTIME_DASHBOARD_SHEETS, source="RUNTIME")

combined = DashboardSheetDict()
_add_with_collision_check(combined, _CONFIG_DASHBOARD_SHEETS, source="CONFIG")
_add_with_collision_check(combined, _RUNTIME_DASHBOARD_SHEETS, source="RUNTIME")
tiers = {}
for name, sheet in _EGERIA_DASHBOARD_SHEETS.items():
if name in local.keys():
if name not in _SHADOW_WARNED:
_SHADOW_WARNED.add(name)
logger.warning(f"Dashboard Sheet '{name}' is defined locally and held in Egeria; the local "
f"definition is used.")
continue
combined[name] = sheet
tiers[name] = "egeria"
for name, sheet in local.items():
combined[name] = sheet
tiers[name] = "local"
_REGISTRY_TIERS.clear()
_REGISTRY_TIERS.update(tiers)
return combined


def get_dashboard_sheet_tier(name: str):
""""egeria" or "local" for a sheet in the last registry read, else None."""
if not _REGISTRY_TIERS:
get_dashboard_sheet_registry()
return _REGISTRY_TIERS.get(name)


def set_egeria_dashboard_sheets(sheets) -> None:
"""Replace the EGERIA tier with these sheets (a DashboardSheetDict, a dict, or a list of sheets)."""
global _EGERIA_DASHBOARD_SHEETS
if isinstance(sheets, list):
sheets = {s.name: s for s in sheets}
_EGERIA_DASHBOARD_SHEETS = sheets if isinstance(sheets, DashboardSheetDict) else DashboardSheetDict(sheets)


def refresh_egeria_dashboard_sheets(client=None) -> int:
"""Load the EGERIA tier from Egeria (`pyegeria.view.dashboards.list_dashboard_sheets`). Returns the
number of sheets. With no client, one is made from the environment."""
from pyegeria.view.dashboards import list_dashboard_sheets
sheets = list_dashboard_sheets(client)
set_egeria_dashboard_sheets(sheets)
return len(sheets)


def clear_egeria_dashboard_sheets() -> None:
_EGERIA_DASHBOARD_SHEETS.clear()
_SHADOW_WARNED.clear()


def register_dashboard_sheets(new_sheets: Union[DashboardSheetDict, dict], *, source: str = "runtime") -> None:
"""Dynamically add dashboard sheets at runtime. Raises on duplicate name."""
global _RUNTIME_DASHBOARD_SHEETS
if not isinstance(new_sheets, DashboardSheetDict):
new_sheets = DashboardSheetDict(new_sheets)
existing = get_dashboard_sheet_registry()
for name in new_sheets.keys():
existing = DashboardSheetDict()
_add_with_collision_check(existing, _CONFIG_DASHBOARD_SHEETS, source="CONFIG")
_add_with_collision_check(existing, _RUNTIME_DASHBOARD_SHEETS, source="RUNTIME")
for name in new_sheets.keys(): # a runtime sheet may override an Egeria one; not another local one
if name in existing.keys():
raise DashboardSheetCollision(
f"Dashboard Sheet '{name}' already exists; cannot register from {source}")
Expand Down
Loading
Loading