Skip to content

app_tree

controller.app_tree

Application tree information.

Classes

AppTree(name, children, host, detector='') dataclass

Application tree information.

Attributes
children instance-attribute

The children of the application.

detector = '' class-attribute instance-attribute

The detector of the application.

host instance-attribute

The hostname of the application.

name instance-attribute

The name of the application.

Functions
to_list(indent='')

Convert the app tree to a list of dicts with name indentation.

Parameters:

Name Type Description Default
indent str

The string to use to indent the app name in the table.

''

Returns:

Type Description
list[dict[str, str]]

The list of dicts with the app tree information, indenting the name based

list[dict[str, str]]

on the depth within the tree.

Source code in controller/app_tree.py
def to_list(self, indent: str = "") -> list[dict[str, str]]:
    """Convert the app tree to a list of dicts with name indentation.

    Args:
        indent: The string to use to indent the app name in the table.

    Returns:
        The list of dicts with the app tree information, indenting the name based
        on the depth within the tree.
    """
    table_data = [
        {
            "name": mark_safe(indent + self.name),
            "host": self.host,
            "detector": self.detector,
        }
    ]
    for child in self.children:
        table_data.extend(child.to_list(indent + "⋅" + " " * 8))

    return table_data

Functions

get_app_tree(user, status=None, hostnames=None, detectors=None)

Get the application tree for the controller.

It recursively gets the tree of applications and their children.

Parameters:

Name Type Description Default
user str

The user to get the tree for.

required
status Status | None

The status to get the tree for. If None, the root controller status is used as the starting point.

None
hostnames dict[str, str] | None

The hostnames of the applications. If None, the hostnames are retrieved from the process manager.

None
detectors dict[str, str] | None

The detectors reported by the controller for each application.

None

Returns:

Type Description
AppTree

The application tree as a AppType object.

Source code in controller/app_tree.py
def get_app_tree(
    user: str,
    status: Status | None = None,
    hostnames: dict[str, str] | None = None,
    detectors: dict[str, str] | None = None,
) -> AppTree:
    """Get the application tree for the controller.

    It recursively gets the tree of applications and their children.

    Args:
        user: The user to get the tree for.
        status: The status to get the tree for. If None, the root controller status is
            used as the starting point.
        hostnames: The hostnames of the applications. If None, the hostnames are
            retrieved from the process manager.
        detectors: The detectors reported by the controller for each application.

    Returns:
        The application tree as a AppType object.
    """
    status = status or get_controller_status()
    hostnames = hostnames or get_hostnames(user)
    detectors = detectors or get_detectors()

    return AppTree(
        status.name,  # type: ignore [attr-defined]
        [
            get_app_tree(user, app, hostnames, detectors)
            for app in status.children  # type: ignore [attr-defined]
        ],
        hostnames.get(status.name, "unknown"),  # type: ignore [attr-defined]
        detectors.get(status.name, ""),  # type: ignore [attr-defined]
    )