|
@@ -20,7 +20,15 @@ from taipy.logger._taipy_logger import _TaipyLogger
|
|
|
from ._entity._entity import _Entity
|
|
|
from ._entity._reload import _get_manager
|
|
|
from ._version._version_manager_factory import _VersionManagerFactory
|
|
|
-from .common._check_entity_and_get_manager import _check_entity_and_get_manager
|
|
|
+from .common._check_instance import (
|
|
|
+ _is_cycle,
|
|
|
+ _is_data_node,
|
|
|
+ _is_job,
|
|
|
+ _is_scenario,
|
|
|
+ _is_sequence,
|
|
|
+ _is_submission,
|
|
|
+ _is_task,
|
|
|
+)
|
|
|
from .common._warnings import _warn_no_core_service
|
|
|
from .config.data_node_config import DataNodeConfig
|
|
|
from .config.scenario_config import ScenarioConfig
|
|
@@ -62,8 +70,16 @@ def set(entity: Union[DataNode, Task, Sequence, Scenario, Cycle]):
|
|
|
entity (Union[DataNode^, Task^, Sequence^, Scenario^, Cycle^]): The
|
|
|
entity to save or update.
|
|
|
"""
|
|
|
- if manager := _check_entity_and_get_manager(entity, [Cycle, Scenario, Sequence, Task, DataNode]):
|
|
|
- manager._set(entity)
|
|
|
+ if _is_cycle(entity):
|
|
|
+ return _get_manager(Cycle._MANAGER_NAME)._set(entity)
|
|
|
+ if _is_scenario(entity):
|
|
|
+ return _get_manager(Scenario._MANAGER_NAME)._set(entity)
|
|
|
+ if _is_sequence(entity):
|
|
|
+ return _get_manager(Sequence._MANAGER_NAME)._set(entity)
|
|
|
+ if _is_task(entity):
|
|
|
+ return _get_manager(Task._MANAGER_NAME)._set(entity)
|
|
|
+ if _is_data_node(entity):
|
|
|
+ return _get_manager(DataNode._MANAGER_NAME)._set(entity)
|
|
|
|
|
|
|
|
|
def is_submittable(entity: Union[Scenario, ScenarioId, Sequence, SequenceId, Task, TaskId]) -> bool:
|
|
@@ -74,8 +90,12 @@ def is_submittable(entity: Union[Scenario, ScenarioId, Sequence, SequenceId, Tas
|
|
|
Returns:
|
|
|
True if the given entity can be submitted. False otherwise.
|
|
|
"""
|
|
|
- if manager := _check_entity_and_get_manager(entity, [Scenario, Sequence, Task]):
|
|
|
- return manager._is_submittable(entity) # type: ignore
|
|
|
+ if _is_scenario(entity):
|
|
|
+ return _get_manager(Scenario._MANAGER_NAME)._is_submittable(entity) # type: ignore
|
|
|
+ if _is_sequence(entity):
|
|
|
+ return _get_manager(Sequence._MANAGER_NAME)._is_submittable(entity) # type: ignore
|
|
|
+ if _is_task(entity):
|
|
|
+ return _get_manager(Task._MANAGER_NAME)._is_submittable(entity) # type: ignore
|
|
|
return False
|
|
|
|
|
|
|
|
@@ -104,8 +124,20 @@ def is_editable(
|
|
|
Returns:
|
|
|
True if the given entity can be edited. False otherwise.
|
|
|
"""
|
|
|
- if manager := _check_entity_and_get_manager(entity, [Cycle, Scenario, Sequence, Task, Job, DataNode, Submission]):
|
|
|
- return manager._is_editable(entity)
|
|
|
+ if _is_cycle(entity):
|
|
|
+ return _get_manager(Cycle._MANAGER_NAME)._is_editable(entity)
|
|
|
+ if _is_scenario(entity):
|
|
|
+ return _get_manager(Scenario._MANAGER_NAME)._is_editable(entity)
|
|
|
+ if _is_sequence(entity):
|
|
|
+ return _get_manager(Sequence._MANAGER_NAME)._is_editable(entity)
|
|
|
+ if _is_task(entity):
|
|
|
+ return _get_manager(Task._MANAGER_NAME)._is_editable(entity)
|
|
|
+ if _is_job(entity):
|
|
|
+ return _get_manager(Job._MANAGER_NAME)._is_editable(entity)
|
|
|
+ if _is_data_node(entity):
|
|
|
+ return _get_manager(DataNode._MANAGER_NAME)._is_editable(entity)
|
|
|
+ if _is_submission(entity):
|
|
|
+ return _get_manager(Submission._MANAGER_NAME)._is_editable(entity)
|
|
|
return False
|
|
|
|
|
|
|
|
@@ -134,8 +166,20 @@ def is_readable(
|
|
|
Returns:
|
|
|
True if the given entity can be read. False otherwise.
|
|
|
"""
|
|
|
- if manager := _check_entity_and_get_manager(entity, [Cycle, Scenario, Sequence, Task, Job, DataNode, Submission]):
|
|
|
- return manager._is_readable(entity)
|
|
|
+ if _is_cycle(entity):
|
|
|
+ return _get_manager(Cycle._MANAGER_NAME)._is_readable(entity)
|
|
|
+ if _is_scenario(entity):
|
|
|
+ return _get_manager(Scenario._MANAGER_NAME)._is_readable(entity)
|
|
|
+ if _is_sequence(entity):
|
|
|
+ return _get_manager(Sequence._MANAGER_NAME)._is_readable(entity)
|
|
|
+ if _is_task(entity):
|
|
|
+ return _get_manager(Task._MANAGER_NAME)._is_readable(entity)
|
|
|
+ if _is_job(entity):
|
|
|
+ return _get_manager(Job._MANAGER_NAME)._is_readable(entity)
|
|
|
+ if _is_data_node(entity):
|
|
|
+ return _get_manager(DataNode._MANAGER_NAME)._is_readable(entity)
|
|
|
+ if _is_submission(entity):
|
|
|
+ return _get_manager(Submission._MANAGER_NAME)._is_readable(entity)
|
|
|
return False
|
|
|
|
|
|
|
|
@@ -167,8 +211,16 @@ def submit(
|
|
|
- If a `Scenario^` or a `Sequence^` is provided, it will return a list of `Job^`.
|
|
|
- If a `Task^` is provided, it will return the created `Job^`.
|
|
|
"""
|
|
|
- if manager := _check_entity_and_get_manager(entity, [Scenario, Sequence, Task]):
|
|
|
- return manager._submit(entity, force=force, wait=wait, timeout=timeout) # type: ignore
|
|
|
+ if _is_scenario(entity):
|
|
|
+ return _get_manager(Scenario._MANAGER_NAME)._submit( # type: ignore
|
|
|
+ entity, force=force, wait=wait, timeout=timeout
|
|
|
+ )
|
|
|
+ if _is_sequence(entity):
|
|
|
+ return _get_manager(Sequence._MANAGER_NAME)._submit( # type: ignore
|
|
|
+ entity, force=force, wait=wait, timeout=timeout
|
|
|
+ )
|
|
|
+ if _is_task(entity):
|
|
|
+ return _get_manager(Task._MANAGER_NAME)._submit(entity, force=force, wait=wait, timeout=timeout) # type: ignore
|
|
|
return None
|
|
|
|
|
|
|
|
@@ -235,10 +287,20 @@ def exists(entity_id: Union[TaskId, DataNodeId, SequenceId, ScenarioId, JobId, C
|
|
|
(`Job^`, `Cycle^`, `Scenario^`, `Sequence^`, `Task^`, `DataNode^`)
|
|
|
based on their respective identifier prefixes.
|
|
|
"""
|
|
|
- if manager := _check_entity_and_get_manager(
|
|
|
- entity_id, [Cycle, Scenario, Sequence, Task, Job, DataNode, Submission]
|
|
|
- ):
|
|
|
- return manager._exists(entity_id)
|
|
|
+ if _is_job(entity_id):
|
|
|
+ return _get_manager(Job._MANAGER_NAME)._exists(JobId(entity_id))
|
|
|
+ if _is_cycle(entity_id):
|
|
|
+ return _get_manager(Cycle._MANAGER_NAME)._exists(CycleId(entity_id))
|
|
|
+ if _is_scenario(entity_id):
|
|
|
+ return _get_manager(Scenario._MANAGER_NAME)._exists(ScenarioId(entity_id))
|
|
|
+ if _is_sequence(entity_id):
|
|
|
+ return _get_manager(Sequence._MANAGER_NAME)._exists(SequenceId(entity_id))
|
|
|
+ if _is_task(entity_id):
|
|
|
+ return _get_manager(Task._MANAGER_NAME)._exists(TaskId(entity_id))
|
|
|
+ if _is_data_node(entity_id):
|
|
|
+ return _get_manager(DataNode._MANAGER_NAME)._exists(DataNodeId(entity_id))
|
|
|
+ if _is_submission(entity_id):
|
|
|
+ return _get_manager(Submission._MANAGER_NAME)._exists(SubmissionId(entity_id))
|
|
|
|
|
|
raise ModelNotFound("NOT_DETERMINED", entity_id)
|
|
|
|
|
@@ -305,10 +367,20 @@ def get(
|
|
|
Raises:
|
|
|
ModelNotFound^: If the provided *entity_id* does not match any known entity pattern.
|
|
|
"""
|
|
|
- if manager := _check_entity_and_get_manager(
|
|
|
- entity_id, [Cycle, Scenario, Sequence, Task, Job, DataNode, Submission]
|
|
|
- ):
|
|
|
- return manager._get(entity_id)
|
|
|
+ if _is_job(entity_id):
|
|
|
+ return _get_manager(Job._MANAGER_NAME)._get(JobId(entity_id))
|
|
|
+ if _is_cycle(entity_id):
|
|
|
+ return _get_manager(Cycle._MANAGER_NAME)._get(CycleId(entity_id))
|
|
|
+ if _is_scenario(entity_id):
|
|
|
+ return _get_manager(Scenario._MANAGER_NAME)._get(ScenarioId(entity_id))
|
|
|
+ if _is_sequence(entity_id):
|
|
|
+ return _get_manager(Sequence._MANAGER_NAME)._get(SequenceId(entity_id))
|
|
|
+ if _is_task(entity_id):
|
|
|
+ return _get_manager(Task._MANAGER_NAME)._get(TaskId(entity_id))
|
|
|
+ if _is_data_node(entity_id):
|
|
|
+ return _get_manager(DataNode._MANAGER_NAME)._get(DataNodeId(entity_id))
|
|
|
+ if _is_submission(entity_id):
|
|
|
+ return _get_manager(Submission._MANAGER_NAME)._get(SubmissionId(entity_id))
|
|
|
|
|
|
raise ModelNotFound("NOT_DETERMINED", entity_id)
|
|
|
|
|
@@ -337,8 +409,12 @@ def is_deletable(entity: Union[Scenario, Job, Submission, ScenarioId, JobId, Sub
|
|
|
Returns:
|
|
|
True if the given scenario, job or submission can be deleted. False otherwise.
|
|
|
"""
|
|
|
- if manager := _check_entity_and_get_manager(entity, [Scenario, Job, Submission]):
|
|
|
- return manager._is_deletable(entity) # type: ignore
|
|
|
+ if _is_job(entity):
|
|
|
+ return _get_manager(Job._MANAGER_NAME)._is_deletable(entity) # type: ignore
|
|
|
+ if _is_scenario(entity):
|
|
|
+ return _get_manager(Scenario._MANAGER_NAME)._is_deletable(entity) # type: ignore
|
|
|
+ if _is_submission(entity):
|
|
|
+ return _get_manager(Submission._MANAGER_NAME)._is_deletable(entity) # type: ignore
|
|
|
return True
|
|
|
|
|
|
|
|
@@ -349,29 +425,39 @@ def delete(entity_id: Union[TaskId, DataNodeId, SequenceId, ScenarioId, JobId, C
|
|
|
The behavior varies depending on the type of entity provided:
|
|
|
|
|
|
- If a `CycleId` is provided, the nested scenarios, tasks, data nodes, and jobs are deleted.
|
|
|
- - If a `ScenarioId` is provided, the nested tasks, data nodes, and jobs are deleted.
|
|
|
+ - If a `ScenarioId` is provided, the nested sequences, tasks, data nodes, submissions and jobs are deleted.
|
|
|
If the scenario is primary, it can only be deleted if it is the only scenario in the cycle.
|
|
|
In that case, its cycle is also deleted. Use the `is_deletable()^` function to check if
|
|
|
the scenario can be deleted.
|
|
|
- If a `SequenceId` is provided, the related jobs are deleted.
|
|
|
- If a `TaskId` is provided, the related data nodes, and jobs are deleted.
|
|
|
- If a `DataNodeId` is provided, the data node is deleted.
|
|
|
- - If a `SubmissionId^` or a `JobId^` is provided, the submission or job entity can only be deleted if
|
|
|
- the execution has been finished.
|
|
|
+ - If a `SubmissionId^` is provided, the related jobs are deleted.
|
|
|
+ The submission can only be deleted if the execution has been finished.
|
|
|
+ - If a `JobId^` is provided, the job entity can only be deleted if the execution has been finished.
|
|
|
|
|
|
Parameters:
|
|
|
- entity_id (Union[TaskId, DataNodeId, SequenceId, ScenarioId, JobId, CycleId]):
|
|
|
+ entity_id (Union[TaskId, DataNodeId, SequenceId, ScenarioId, SubmissionId, JobId, CycleId]):
|
|
|
The identifier of the entity to delete.
|
|
|
|
|
|
Raises:
|
|
|
ModelNotFound: No entity corresponds to the specified *entity_id*.
|
|
|
"""
|
|
|
- if manager := _check_entity_and_get_manager(entity_id, [Cycle, Scenario, Sequence, Task]):
|
|
|
- return manager._hard_delete(entity_id) # type: ignore
|
|
|
-
|
|
|
- if manager := _check_entity_and_get_manager(entity_id, [Job, DataNode, Submission]):
|
|
|
- return manager._delete(entity_id) # type: ignore
|
|
|
-
|
|
|
+ if _is_job(entity_id):
|
|
|
+ job_manager = _get_manager(Job._MANAGER_NAME)
|
|
|
+ return job_manager._delete(job_manager._get(JobId(entity_id))) # type: ignore
|
|
|
+ if _is_cycle(entity_id):
|
|
|
+ return _get_manager(Cycle._MANAGER_NAME)._hard_delete(CycleId(entity_id)) # type: ignore
|
|
|
+ if _is_scenario(entity_id):
|
|
|
+ return _get_manager(Scenario._MANAGER_NAME)._hard_delete(ScenarioId(entity_id)) # type: ignore
|
|
|
+ if _is_sequence(entity_id):
|
|
|
+ return _get_manager(Sequence._MANAGER_NAME)._hard_delete(SequenceId(entity_id)) # type: ignore
|
|
|
+ if _is_task(entity_id):
|
|
|
+ return _get_manager(Task._MANAGER_NAME)._hard_delete(TaskId(entity_id)) # type: ignore
|
|
|
+ if _is_data_node(entity_id):
|
|
|
+ return _get_manager(DataNode._MANAGER_NAME)._delete(DataNodeId(entity_id)) # type: ignore
|
|
|
+ if _is_submission(entity_id):
|
|
|
+ return _get_manager(Submission._MANAGER_NAME)._hard_delete(SubmissionId(entity_id)) # type: ignore
|
|
|
raise ModelNotFound("NOT_DETERMINED", entity_id)
|
|
|
|
|
|
|