diff --git a/tdp/cli/commands/vars/edit.py b/tdp/cli/commands/vars/edit.py index 2be7bde1..8246442d 100644 --- a/tdp/cli/commands/vars/edit.py +++ b/tdp/cli/commands/vars/edit.py @@ -16,9 +16,9 @@ ) from tdp.core.collections import Collections from tdp.core.constants import YML_EXTENSION -from tdp.core.entities.hostable_entity_name import ( +from tdp.core.entities.entity_name import ( ServiceComponentName, - parse_hostable_entity_name, + parse_entity_name, ) from tdp.core.repository.repository import EmptyCommit from tdp.core.variables import ClusterVariables @@ -94,7 +94,7 @@ def edit( ) # Check if component exists - entity_name = parse_hostable_entity_name(variables_file.stem) + entity_name = parse_entity_name(variables_file.stem) if isinstance(entity_name, ServiceComponentName): if entity_name not in collections.hostable_entities[service_name]: raise click.ClickException( diff --git a/tdp/core/cluster_status.py b/tdp/core/cluster_status.py index 69bf25a9..afaceabb 100644 --- a/tdp/core/cluster_status.py +++ b/tdp/core/cluster_status.py @@ -8,9 +8,9 @@ from typing import TYPE_CHECKING, Optional from tdp.core.dag import Dag -from tdp.core.entities.hostable_entity_name import ( - HostableEntityName, - create_hostable_entity_name, +from tdp.core.entities.entity_name import ( + EntityName, + create_entity_name, ) from tdp.core.entities.hosted_entity import ( HostedEntity, @@ -136,7 +136,7 @@ def generate_stale_sch_logs( for host in operation.host_names: log = logs.setdefault( create_hosted_entity( - create_hostable_entity_name( + create_entity_name( operation.service_name, operation.component_name ), host, @@ -198,7 +198,7 @@ def update_hosted_entity( ) def is_sc_stale( - self, entity_name: HostableEntityName, /, hosts: Optional[Iterable[str]] + self, entity_name: EntityName, /, hosts: Optional[Iterable[str]] ) -> bool: """Whether a service or component is stale. diff --git a/tdp/core/collections/collections.py b/tdp/core/collections/collections.py index 05024b34..bb2d5eb1 100644 --- a/tdp/core/collections/collections.py +++ b/tdp/core/collections/collections.py @@ -17,7 +17,7 @@ from pathlib import Path from typing import TYPE_CHECKING, Optional -from tdp.core.entities.hostable_entity_name import ServiceComponentName +from tdp.core.entities.entity_name import ServiceComponentName from tdp.core.entities.operation import Operations, Playbook from tdp.core.inventory_reader import InventoryReader from tdp.core.operation import Operation diff --git a/tdp/core/deployment/deployment_iterator.py b/tdp/core/deployment/deployment_iterator.py index 241bd018..facc7608 100644 --- a/tdp/core/deployment/deployment_iterator.py +++ b/tdp/core/deployment/deployment_iterator.py @@ -11,7 +11,7 @@ from typing import TYPE_CHECKING, Optional from tdp.core.constants import OPERATION_SLEEP_NAME -from tdp.core.entities.hostable_entity_name import create_hostable_entity_name +from tdp.core.entities.entity_name import create_entity_name from tdp.core.entities.hosted_entity import create_hosted_entity from tdp.core.models import ( DeploymentModel, @@ -165,7 +165,7 @@ def _process_operation_fn( return sch_status_logs: list[SCHStatusLogModel] = [] - entity_name = create_hostable_entity_name( + entity_name = create_entity_name( operation.service_name, operation.component_name ) diff --git a/tdp/core/entities/hostable_entity_name.py b/tdp/core/entities/entity_name.py similarity index 89% rename from tdp/core/entities/hostable_entity_name.py rename to tdp/core/entities/entity_name.py index c69d59a0..fcec82f0 100644 --- a/tdp/core/entities/hostable_entity_name.py +++ b/tdp/core/entities/entity_name.py @@ -11,7 +11,7 @@ @dataclass(frozen=True) -class HostableEntityName(ABC): +class EntityName(ABC): service: str @property @@ -33,7 +33,7 @@ def __str__(self): @dataclass(frozen=True) -class ServiceName(HostableEntityName): +class ServiceName(EntityName): @property def name(self) -> str: @@ -41,7 +41,7 @@ def name(self) -> str: @dataclass(frozen=True) -class ServiceComponentName(HostableEntityName): +class ServiceComponentName(EntityName): component: str def __post_init__(self): @@ -64,13 +64,13 @@ def from_name(cls, name: str) -> ServiceComponentName: return cls(service_name, component_name) -def parse_hostable_entity_name(name: str) -> Union[ServiceName, ServiceComponentName]: +def parse_entity_name(name: str) -> Union[ServiceName, ServiceComponentName]: if "_" in name: return ServiceComponentName.from_name(name) return ServiceName(name) -def create_hostable_entity_name( +def create_entity_name( service_name: str, component_name: Optional[str] ) -> Union[ServiceName, ServiceComponentName]: if component_name is None: diff --git a/tdp/core/entities/hosted_entity.py b/tdp/core/entities/hosted_entity.py index 60c1c73d..bf73965c 100644 --- a/tdp/core/entities/hosted_entity.py +++ b/tdp/core/entities/hosted_entity.py @@ -5,8 +5,8 @@ from dataclasses import dataclass from typing import Optional, Union -from tdp.core.entities.hostable_entity_name import ( - HostableEntityName, +from tdp.core.entities.entity_name import ( + EntityName, ServiceComponentName, ServiceName, ) @@ -16,7 +16,7 @@ class HostedEntity(ABC): @property @abstractmethod - def name(self) -> HostableEntityName: + def name(self) -> EntityName: pass @property @@ -54,7 +54,7 @@ def host(self) -> Optional[str]: def create_hosted_entity( - name: HostableEntityName, host: Optional[str] + name: EntityName, host: Optional[str] ) -> Union[HostedService, HostedServiceComponent]: if isinstance(name, ServiceName): return HostedService(name, host) diff --git a/tdp/core/variables/service_variables.py b/tdp/core/variables/service_variables.py index bd6cb286..8d136049 100644 --- a/tdp/core/variables/service_variables.py +++ b/tdp/core/variables/service_variables.py @@ -19,7 +19,7 @@ ) if TYPE_CHECKING: - from tdp.core.entities.hostable_entity_name import HostableEntityName + from tdp.core.entities.entity_name import EntityName from tdp.core.repository.repository import Repository from tdp.core.variables.schema.service_schema import ServiceSchema from tdp.core.variables.variables import _VariablesIOWrapper @@ -141,9 +141,7 @@ def open_files( with self.repository.validate(validation_message) as repo: repo.add_for_validation(open_files.keys()) - def is_entity_modified_from_version( - self, entity: HostableEntityName, version: str - ) -> bool: + def is_entity_modified_from_version(self, entity: EntityName, version: str) -> bool: """Check if a component has been modified since the given version. A component is modified if the component variable file is modified diff --git a/tdp/dao.py b/tdp/dao.py index 78d4420a..e5c2ebf1 100644 --- a/tdp/dao.py +++ b/tdp/dao.py @@ -7,7 +7,7 @@ from sqlalchemy.orm import aliased, sessionmaker from tdp.core.cluster_status import ClusterStatus -from tdp.core.entities.hostable_entity_name import create_hostable_entity_name +from tdp.core.entities.entity_name import create_entity_name from tdp.core.entities.hosted_entity import create_hosted_entity from tdp.core.entities.hosted_entity_status import HostedEntityStatus from tdp.core.models.deployment_model import DeploymentModel @@ -163,7 +163,7 @@ def get_hosted_entity_statuses( return [ HostedEntityStatus( entity=create_hosted_entity( - name=create_hostable_entity_name( + name=create_entity_name( service_name=status.service, component_name=status.component ), host=status.host, diff --git a/test_dag_order/helpers.py b/test_dag_order/helpers.py index f33de363..ac375686 100644 --- a/test_dag_order/helpers.py +++ b/test_dag_order/helpers.py @@ -18,9 +18,9 @@ PathIsNotADirectoryError, ) from tdp.core.constants import YML_EXTENSION -from tdp.core.entities.hostable_entity_name import ( +from tdp.core.entities.entity_name import ( ServiceName, - parse_hostable_entity_name, + parse_entity_name, ) from tdp.core.inventory_reader import InventoryReader @@ -186,7 +186,7 @@ def resolve_components( resolved_components: set[str] = set() service_component_map: dict[str, str] = {} for service_component in service_components: - if isinstance(parse_hostable_entity_name(service_component), ServiceName): + if isinstance(parse_entity_name(service_component), ServiceName): for component in collections.hostable_entities[service_component]: resolved_components.add(component.name) service_component_map[component.name] = service_component