Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename hostable entity name to entity name #631

Merged
merged 1 commit into from
Nov 21, 2024
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
6 changes: 3 additions & 3 deletions tdp/cli/commands/vars/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions tdp/core/cluster_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion tdp/core/collections/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tdp/core/deployment/deployment_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
)

Expand Down
rpignolet marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


@dataclass(frozen=True)
class HostableEntityName(ABC):
class EntityName(ABC):
service: str

@property
Expand All @@ -33,15 +33,15 @@ def __str__(self):


@dataclass(frozen=True)
class ServiceName(HostableEntityName):
class ServiceName(EntityName):

@property
def name(self) -> str:
return self.service


@dataclass(frozen=True)
class ServiceComponentName(HostableEntityName):
class ServiceComponentName(EntityName):
component: str

def __post_init__(self):
Expand All @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions tdp/core/entities/hosted_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -16,7 +16,7 @@
class HostedEntity(ABC):
@property
@abstractmethod
def name(self) -> HostableEntityName:
def name(self) -> EntityName:
pass

@property
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions tdp/core/variables/service_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tdp/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions test_dag_order/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Loading