Skip to content

Commit

Permalink
fix: get rid of red error marking in Dag class
Browse files Browse the repository at this point in the history
  • Loading branch information
SteBaum committed Oct 21, 2024
1 parent 4b51b7c commit 4f2ad36
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions tdp/core/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import networkx as nx

from tdp.core.constants import DEFAULT_SERVICE_PRIORITY, SERVICE_PRIORITY
from tdp.core.entities.operation import Operations
from tdp.core.operation import Operation

if TYPE_CHECKING:
Expand Down Expand Up @@ -50,7 +51,7 @@ def __init__(self, collections: Collections):
self._graph = self._generate_graph(self.operations)

@property
def operations(self) -> dict[str, Operation]:
def operations(self) -> Operations:
"""DAG operations dictionary."""
return self._operations

Expand Down Expand Up @@ -239,7 +240,7 @@ def get_operation_descendants(
)

# TODO: can take a list of operations instead of a dict
def _generate_graph(self, nodes: dict[str, Operation]) -> nx.DiGraph:
def _generate_graph(self, nodes: Operations) -> nx.DiGraph:
DG = nx.DiGraph()
for operation_name, operation in nodes.items():
DG.add_node(operation_name)
Expand All @@ -258,7 +259,7 @@ def _generate_graph(self, nodes: dict[str, Operation]) -> nx.DiGraph:

# TODO: call this method inside of Collections._init_operations instead of the Dag constructor
# TODO: remove Collections dependency
def validate_dag_nodes(nodes: dict[str, Operation], collections: Collections) -> None:
def validate_dag_nodes(nodes: Operations, collections: Collections) -> None:
r"""Validation rules :
- \*_start operations can only be required from within its own service
- \*_install operations should only depend on other \*_install operations
Expand All @@ -274,28 +275,29 @@ def warning(collection_name: str, message: str) -> None:
logger.warning(message + f", collection: {collection_name}")

for operation_name, operation in nodes.items():
c_warning = functools.partial(warning, operation.collection_name)
for dependency in operation.depends_on:
# *_start operations can only be required from within its own service
dependency_service = nodes[dependency].service_name
if (
dependency.endswith("_start")
and dependency_service != operation.service_name
):
c_warning(
f"Operation '{operation_name}' is in service '{operation.service_name}', depends on "
f"'{dependency}' which is a start action in service '{dependency_service}' and should "
f"only depends on start action within its own service"
)
if operation.collection_name is not None:
c_warning = functools.partial(warning, operation.collection_name)
for dependency in operation.depends_on:
# *_start operations can only be required from within its own service
dependency_service = nodes[dependency].service_name
if (
dependency.endswith("_start")
and dependency_service != operation.service_name
):
c_warning(
f"Operation '{operation_name}' is in service '{operation.service_name}', depends on "
f"'{dependency}' which is a start action in service '{dependency_service}' and should "
f"only depends on start action within its own service"
)

# *_install operations should only depend on other *_install operations
if operation_name.endswith("_install") and not dependency.endswith(
"_install"
):
c_warning(
f"Operation '{operation_name}' is an install action, depends on '{dependency}' which is "
f"not an install action and should only depends on other install action"
)
# *_install operations should only depend on other *_install operations
if operation_name.endswith("_install") and not dependency.endswith(
"_install"
):
c_warning(
f"Operation '{operation_name}' is an install action, depends on '{dependency}' which is "
f"not an install action and should only depends on other install action"
)

# Each service (HDFS, HBase, Hive, etc) should have *_install, *_config, *_init and *_start actions
# even if they are "empty" (tagged with noop)
Expand Down

0 comments on commit 4f2ad36

Please sign in to comment.