digitalhub 0.10.3__py3-none-any.whl → 0.11.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of digitalhub might be problematic. Click here for more details.
- digitalhub/__init__.py +10 -0
- digitalhub/context/api.py +10 -4
- digitalhub/context/builder.py +35 -20
- digitalhub/context/context.py +35 -24
- digitalhub/entities/_base/entity/builder.py +11 -0
- digitalhub/entities/_base/executable/entity.py +52 -5
- digitalhub/entities/_base/material/utils.py +11 -11
- digitalhub/entities/_commons/enums.py +4 -0
- digitalhub/entities/_processors/base.py +15 -15
- digitalhub/entities/_processors/context.py +62 -15
- digitalhub/entities/_processors/utils.py +2 -2
- digitalhub/entities/builders.py +2 -0
- digitalhub/entities/function/_base/entity.py +3 -3
- digitalhub/entities/project/_base/builder.py +4 -0
- digitalhub/entities/project/_base/entity.py +5 -2
- digitalhub/entities/project/_base/models.py +18 -0
- digitalhub/entities/project/_base/spec.py +6 -0
- digitalhub/entities/project/crud.py +2 -13
- digitalhub/entities/run/_base/entity.py +6 -12
- digitalhub/entities/task/_base/entity.py +4 -4
- digitalhub/entities/task/_base/models.py +20 -2
- digitalhub/entities/trigger/__init__.py +0 -0
- digitalhub/entities/trigger/_base/__init__.py +0 -0
- digitalhub/entities/trigger/_base/builder.py +70 -0
- digitalhub/entities/trigger/_base/entity.py +34 -0
- digitalhub/entities/trigger/_base/spec.py +40 -0
- digitalhub/entities/trigger/_base/status.py +9 -0
- digitalhub/entities/trigger/crud.py +309 -0
- digitalhub/entities/trigger/lifecycle/__init__.py +0 -0
- digitalhub/entities/trigger/lifecycle/builder.py +19 -0
- digitalhub/entities/trigger/lifecycle/entity.py +32 -0
- digitalhub/entities/trigger/lifecycle/spec.py +38 -0
- digitalhub/entities/trigger/lifecycle/status.py +9 -0
- digitalhub/entities/trigger/scheduler/__init__.py +0 -0
- digitalhub/entities/trigger/scheduler/builder.py +19 -0
- digitalhub/entities/trigger/scheduler/entity.py +32 -0
- digitalhub/entities/trigger/scheduler/spec.py +29 -0
- digitalhub/entities/trigger/scheduler/status.py +9 -0
- digitalhub/entities/workflow/_base/entity.py +3 -3
- digitalhub/factory/factory.py +113 -26
- digitalhub/factory/utils.py +31 -14
- digitalhub/runtimes/_base.py +22 -11
- digitalhub/runtimes/builder.py +16 -3
- digitalhub/runtimes/enums.py +11 -1
- digitalhub/stores/client/api.py +1 -1
- digitalhub/stores/client/builder.py +2 -2
- digitalhub/stores/client/dhcore/client.py +2 -2
- digitalhub/stores/client/dhcore/configurator.py +10 -4
- digitalhub/stores/configurator/configurator.py +2 -1
- digitalhub/stores/configurator/enums.py +9 -0
- digitalhub/stores/data/api.py +2 -2
- digitalhub/stores/data/builder.py +4 -5
- digitalhub/stores/data/enums.py +11 -0
- digitalhub/stores/data/s3/configurator.py +0 -1
- digitalhub/stores/data/s3/enums.py +2 -3
- digitalhub/stores/data/s3/store.py +2 -3
- digitalhub/stores/data/s3/utils.py +13 -18
- digitalhub/stores/data/sql/configurator.py +3 -3
- digitalhub/stores/data/sql/store.py +0 -1
- digitalhub/stores/data/utils.py +34 -0
- digitalhub/utils/file_utils.py +1 -1
- digitalhub/utils/generic_utils.py +37 -0
- digitalhub/utils/uri_utils.py +5 -0
- {digitalhub-0.10.3.dist-info → digitalhub-0.11.0.dist-info}/METADATA +1 -1
- {digitalhub-0.10.3.dist-info → digitalhub-0.11.0.dist-info}/RECORD +67 -48
- digitalhub/factory/api.py +0 -277
- {digitalhub-0.10.3.dist-info → digitalhub-0.11.0.dist-info}/WHEEL +0 -0
- {digitalhub-0.10.3.dist-info → digitalhub-0.11.0.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -3,13 +3,13 @@ from __future__ import annotations
|
|
|
3
3
|
import typing
|
|
4
4
|
from typing import Any
|
|
5
5
|
|
|
6
|
-
from digitalhub.entities._commons.enums import ApiCategories, BackendOperations, Relationship
|
|
6
|
+
from digitalhub.entities._commons.enums import ApiCategories, BackendOperations, Relationship, State
|
|
7
7
|
from digitalhub.entities._processors.utils import (
|
|
8
8
|
get_context_from_identifier,
|
|
9
9
|
get_context_from_project,
|
|
10
10
|
parse_identifier,
|
|
11
11
|
)
|
|
12
|
-
from digitalhub.factory.
|
|
12
|
+
from digitalhub.factory.factory import factory
|
|
13
13
|
from digitalhub.utils.exceptions import EntityAlreadyExistsError, EntityError, EntityNotExistsError
|
|
14
14
|
from digitalhub.utils.io_utils import read_yaml
|
|
15
15
|
from digitalhub.utils.types import SourcesOrListOfSources
|
|
@@ -91,9 +91,9 @@ class ContextEntityOperationsProcessor:
|
|
|
91
91
|
obj = _entity
|
|
92
92
|
else:
|
|
93
93
|
context = get_context_from_project(kwargs["project"])
|
|
94
|
-
obj: ContextEntity = build_entity_from_params(**kwargs)
|
|
94
|
+
obj: ContextEntity = factory.build_entity_from_params(**kwargs)
|
|
95
95
|
new_obj = self._create_context_entity(context, obj.ENTITY_TYPE, obj.to_dict())
|
|
96
|
-
return build_entity_from_dict(new_obj)
|
|
96
|
+
return factory.build_entity_from_dict(new_obj)
|
|
97
97
|
|
|
98
98
|
def log_material_entity(
|
|
99
99
|
self,
|
|
@@ -114,13 +114,36 @@ class ContextEntityOperationsProcessor:
|
|
|
114
114
|
"""
|
|
115
115
|
source: SourcesOrListOfSources = kwargs.pop("source")
|
|
116
116
|
context = get_context_from_project(kwargs["project"])
|
|
117
|
-
obj = build_entity_from_params(**kwargs)
|
|
117
|
+
obj = factory.build_entity_from_params(**kwargs)
|
|
118
118
|
if context.is_running:
|
|
119
119
|
obj.add_relationship(Relationship.PRODUCEDBY.value, context.get_run_ctx())
|
|
120
120
|
|
|
121
121
|
new_obj: MaterialEntity = self._create_context_entity(context, obj.ENTITY_TYPE, obj.to_dict())
|
|
122
|
-
new_obj = build_entity_from_dict(new_obj)
|
|
123
|
-
|
|
122
|
+
new_obj = factory.build_entity_from_dict(new_obj)
|
|
123
|
+
|
|
124
|
+
new_obj.status.state = State.UPLOADING.value
|
|
125
|
+
new_obj = self._update_material_entity(new_obj)
|
|
126
|
+
|
|
127
|
+
# Handle file upload
|
|
128
|
+
try:
|
|
129
|
+
new_obj.upload(source)
|
|
130
|
+
uploaded = True
|
|
131
|
+
msg = None
|
|
132
|
+
except Exception as e:
|
|
133
|
+
uploaded = False
|
|
134
|
+
msg = str(e)
|
|
135
|
+
|
|
136
|
+
new_obj.status.message = msg
|
|
137
|
+
|
|
138
|
+
# Update status after upload
|
|
139
|
+
if uploaded:
|
|
140
|
+
new_obj.status.state = State.READY.value
|
|
141
|
+
new_obj = self._update_material_entity(new_obj)
|
|
142
|
+
else:
|
|
143
|
+
new_obj.status.state = State.ERROR.value
|
|
144
|
+
new_obj = self._update_material_entity(new_obj)
|
|
145
|
+
raise EntityError(msg)
|
|
146
|
+
|
|
124
147
|
return new_obj
|
|
125
148
|
|
|
126
149
|
def _read_context_entity(
|
|
@@ -226,7 +249,7 @@ class ContextEntityOperationsProcessor:
|
|
|
226
249
|
entity_id=entity_id,
|
|
227
250
|
**kwargs,
|
|
228
251
|
)
|
|
229
|
-
entity = build_entity_from_dict(obj)
|
|
252
|
+
entity = factory.build_entity_from_dict(obj)
|
|
230
253
|
return self._post_process_get(entity)
|
|
231
254
|
|
|
232
255
|
def read_unversioned_entity(
|
|
@@ -292,7 +315,7 @@ class ContextEntityOperationsProcessor:
|
|
|
292
315
|
dict_obj: dict = read_yaml(file)
|
|
293
316
|
dict_obj["status"] = {}
|
|
294
317
|
context = get_context_from_project(dict_obj["project"])
|
|
295
|
-
obj = build_entity_from_dict(dict_obj)
|
|
318
|
+
obj = factory.build_entity_from_dict(dict_obj)
|
|
296
319
|
try:
|
|
297
320
|
self._create_context_entity(context, obj.ENTITY_TYPE, obj.to_dict())
|
|
298
321
|
except EntityAlreadyExistsError:
|
|
@@ -329,7 +352,7 @@ class ContextEntityOperationsProcessor:
|
|
|
329
352
|
tsk_dicts = []
|
|
330
353
|
|
|
331
354
|
context = get_context_from_project(exec_dict["project"])
|
|
332
|
-
obj: ExecutableEntity = build_entity_from_dict(exec_dict)
|
|
355
|
+
obj: ExecutableEntity = factory.build_entity_from_dict(exec_dict)
|
|
333
356
|
try:
|
|
334
357
|
self._create_context_entity(context, obj.ENTITY_TYPE, obj.to_dict())
|
|
335
358
|
except EntityAlreadyExistsError:
|
|
@@ -358,7 +381,7 @@ class ContextEntityOperationsProcessor:
|
|
|
358
381
|
"""
|
|
359
382
|
dict_obj: dict = read_yaml(file)
|
|
360
383
|
context = get_context_from_project(dict_obj["project"])
|
|
361
|
-
obj: ContextEntity = build_entity_from_dict(dict_obj)
|
|
384
|
+
obj: ContextEntity = factory.build_entity_from_dict(dict_obj)
|
|
362
385
|
try:
|
|
363
386
|
self._update_context_entity(context, obj.ENTITY_TYPE, obj.id, obj.to_dict())
|
|
364
387
|
except EntityNotExistsError:
|
|
@@ -391,7 +414,7 @@ class ContextEntityOperationsProcessor:
|
|
|
391
414
|
tsk_dicts = []
|
|
392
415
|
|
|
393
416
|
context = get_context_from_project(exec_dict["project"])
|
|
394
|
-
obj: ExecutableEntity = build_entity_from_dict(exec_dict)
|
|
417
|
+
obj: ExecutableEntity = factory.build_entity_from_dict(exec_dict)
|
|
395
418
|
|
|
396
419
|
try:
|
|
397
420
|
self._update_context_entity(context, obj.ENTITY_TYPE, obj.id, obj.to_dict())
|
|
@@ -486,7 +509,7 @@ class ContextEntityOperationsProcessor:
|
|
|
486
509
|
)
|
|
487
510
|
objects = []
|
|
488
511
|
for o in objs:
|
|
489
|
-
entity: ContextEntity = build_entity_from_dict(o)
|
|
512
|
+
entity: ContextEntity = factory.build_entity_from_dict(o)
|
|
490
513
|
entity = self._post_process_get(entity)
|
|
491
514
|
objects.append(entity)
|
|
492
515
|
return objects
|
|
@@ -549,11 +572,35 @@ class ContextEntityOperationsProcessor:
|
|
|
549
572
|
objs = self._list_context_entities(context, entity_type, **kwargs)
|
|
550
573
|
objects = []
|
|
551
574
|
for o in objs:
|
|
552
|
-
entity: ContextEntity = build_entity_from_dict(o)
|
|
575
|
+
entity: ContextEntity = factory.build_entity_from_dict(o)
|
|
553
576
|
entity = self._post_process_get(entity)
|
|
554
577
|
objects.append(entity)
|
|
555
578
|
return objects
|
|
556
579
|
|
|
580
|
+
def _update_material_entity(
|
|
581
|
+
self,
|
|
582
|
+
new_obj: MaterialEntity,
|
|
583
|
+
) -> dict:
|
|
584
|
+
"""
|
|
585
|
+
Update material object shortcut.
|
|
586
|
+
|
|
587
|
+
Parameters
|
|
588
|
+
----------
|
|
589
|
+
new_obj : MaterialEntity
|
|
590
|
+
Object instance.
|
|
591
|
+
|
|
592
|
+
Returns
|
|
593
|
+
-------
|
|
594
|
+
dict
|
|
595
|
+
Response from backend.
|
|
596
|
+
"""
|
|
597
|
+
return self.update_context_entity(
|
|
598
|
+
new_obj.project,
|
|
599
|
+
new_obj.ENTITY_TYPE,
|
|
600
|
+
new_obj.id,
|
|
601
|
+
new_obj.to_dict(),
|
|
602
|
+
)
|
|
603
|
+
|
|
557
604
|
def _update_context_entity(
|
|
558
605
|
self,
|
|
559
606
|
context: Context,
|
|
@@ -629,7 +676,7 @@ class ContextEntityOperationsProcessor:
|
|
|
629
676
|
entity_dict,
|
|
630
677
|
**kwargs,
|
|
631
678
|
)
|
|
632
|
-
return build_entity_from_dict(obj)
|
|
679
|
+
return factory.build_entity_from_dict(obj)
|
|
633
680
|
|
|
634
681
|
def _delete_context_entity(
|
|
635
682
|
self,
|
|
@@ -5,7 +5,7 @@ import typing
|
|
|
5
5
|
from digitalhub.context.api import get_context
|
|
6
6
|
from digitalhub.entities._commons.enums import ApiCategories, BackendOperations, EntityTypes
|
|
7
7
|
from digitalhub.entities._commons.utils import get_project_from_key, parse_entity_key
|
|
8
|
-
from digitalhub.factory.
|
|
8
|
+
from digitalhub.factory.factory import factory
|
|
9
9
|
from digitalhub.stores.client.api import get_client
|
|
10
10
|
from digitalhub.utils.exceptions import ContextError, EntityError, EntityNotExistsError
|
|
11
11
|
|
|
@@ -118,7 +118,7 @@ def get_context_from_remote(
|
|
|
118
118
|
try:
|
|
119
119
|
client = get_client()
|
|
120
120
|
obj = _read_base_entity(client, EntityTypes.PROJECT.value, project)
|
|
121
|
-
build_entity_from_dict(obj)
|
|
121
|
+
factory.build_entity_from_dict(obj)
|
|
122
122
|
return get_context(project)
|
|
123
123
|
except EntityNotExistsError:
|
|
124
124
|
raise ContextError(f"Project '{project}' not found.")
|
digitalhub/entities/builders.py
CHANGED
|
@@ -6,6 +6,7 @@ from digitalhub.entities.dataitem.table.builder import DataitemTableBuilder
|
|
|
6
6
|
from digitalhub.entities.model.mlflow.builder import ModelModelBuilder
|
|
7
7
|
from digitalhub.entities.project._base.builder import ProjectProjectBuilder
|
|
8
8
|
from digitalhub.entities.secret._base.builder import SecretSecretBuilder
|
|
9
|
+
from digitalhub.entities.trigger.scheduler.builder import TriggerSchedulerBuilder
|
|
9
10
|
|
|
10
11
|
entity_builders: tuple = (
|
|
11
12
|
(ProjectProjectBuilder.ENTITY_KIND, ProjectProjectBuilder),
|
|
@@ -14,6 +15,7 @@ entity_builders: tuple = (
|
|
|
14
15
|
(DataitemDataitemBuilder.ENTITY_KIND, DataitemDataitemBuilder),
|
|
15
16
|
(DataitemTableBuilder.ENTITY_KIND, DataitemTableBuilder),
|
|
16
17
|
(ModelModelBuilder.ENTITY_KIND, ModelModelBuilder),
|
|
18
|
+
(TriggerSchedulerBuilder.ENTITY_KIND, TriggerSchedulerBuilder),
|
|
17
19
|
)
|
|
18
20
|
|
|
19
21
|
##############################
|
|
@@ -5,7 +5,7 @@ from concurrent.futures import ThreadPoolExecutor
|
|
|
5
5
|
|
|
6
6
|
from digitalhub.entities._base.executable.entity import ExecutableEntity
|
|
7
7
|
from digitalhub.entities._commons.enums import EntityTypes, Relationship
|
|
8
|
-
from digitalhub.factory.
|
|
8
|
+
from digitalhub.factory.factory import factory
|
|
9
9
|
from digitalhub.utils.exceptions import BackendError
|
|
10
10
|
|
|
11
11
|
if typing.TYPE_CHECKING:
|
|
@@ -72,8 +72,8 @@ class Function(ExecutableEntity):
|
|
|
72
72
|
Run instance.
|
|
73
73
|
"""
|
|
74
74
|
# Get task and run kind
|
|
75
|
-
task_kind = get_task_kind_from_action(self.kind, action)
|
|
76
|
-
run_kind = get_run_kind(self.kind)
|
|
75
|
+
task_kind = factory.get_task_kind_from_action(self.kind, action)
|
|
76
|
+
run_kind = factory.get_run_kind(self.kind)
|
|
77
77
|
|
|
78
78
|
# Create or update new task
|
|
79
79
|
task = self._get_or_create_task(task_kind)
|
|
@@ -26,6 +26,7 @@ class ProjectProjectBuilder(EntityBuilder):
|
|
|
26
26
|
description: str | None = None,
|
|
27
27
|
labels: list[str] | None = None,
|
|
28
28
|
local: bool = False,
|
|
29
|
+
config: dict | None = None,
|
|
29
30
|
context: str | None = None,
|
|
30
31
|
**kwargs,
|
|
31
32
|
) -> Project:
|
|
@@ -44,6 +45,8 @@ class ProjectProjectBuilder(EntityBuilder):
|
|
|
44
45
|
List of labels.
|
|
45
46
|
local : bool
|
|
46
47
|
If True, use local backend, if False use DHCore backend. Default to False.
|
|
48
|
+
config : dict
|
|
49
|
+
DHCore environment configuration.
|
|
47
50
|
context : str
|
|
48
51
|
The context local folder of the project.
|
|
49
52
|
**kwargs : dict
|
|
@@ -62,6 +65,7 @@ class ProjectProjectBuilder(EntityBuilder):
|
|
|
62
65
|
labels=labels,
|
|
63
66
|
)
|
|
64
67
|
spec = self.build_spec(
|
|
68
|
+
config=config,
|
|
65
69
|
context=context,
|
|
66
70
|
**kwargs,
|
|
67
71
|
)
|
|
@@ -67,7 +67,7 @@ from digitalhub.entities.workflow.crud import (
|
|
|
67
67
|
new_workflow,
|
|
68
68
|
update_workflow,
|
|
69
69
|
)
|
|
70
|
-
from digitalhub.factory.
|
|
70
|
+
from digitalhub.factory.factory import factory
|
|
71
71
|
from digitalhub.stores.client.api import get_client
|
|
72
72
|
from digitalhub.utils.exceptions import BackendError, EntityAlreadyExistsError, EntityError
|
|
73
73
|
from digitalhub.utils.generic_utils import get_timestamp
|
|
@@ -106,6 +106,9 @@ class Project(Entity):
|
|
|
106
106
|
local: bool = False,
|
|
107
107
|
) -> None:
|
|
108
108
|
super().__init__(kind, metadata, spec, status, user)
|
|
109
|
+
self.spec: ProjectSpec
|
|
110
|
+
self.status: ProjectStatus
|
|
111
|
+
|
|
109
112
|
self.id = name
|
|
110
113
|
self.name = name
|
|
111
114
|
self.key = base_processor.build_project_key(self.name, local=local)
|
|
@@ -329,7 +332,7 @@ class Project(Entity):
|
|
|
329
332
|
entity["metadata"]["embedded"] = True
|
|
330
333
|
|
|
331
334
|
try:
|
|
332
|
-
build_entity_from_dict(entity).save()
|
|
335
|
+
factory.build_entity_from_dict(entity).save()
|
|
333
336
|
except EntityAlreadyExistsError:
|
|
334
337
|
pass
|
|
335
338
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
|
|
7
|
+
_DEFAULT_FILES_STORE = "s3://datalake"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ProfileConfig(BaseModel):
|
|
11
|
+
"""
|
|
12
|
+
Configuration profiles.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
default_files_store: Optional[str] = _DEFAULT_FILES_STORE
|
|
16
|
+
|
|
17
|
+
def to_dict(self) -> dict:
|
|
18
|
+
return self.model_dump(by_alias=True, exclude_none=True)
|
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
from typing import Optional
|
|
4
4
|
|
|
5
5
|
from digitalhub.entities._base.entity.spec import Spec, SpecValidator
|
|
6
|
+
from digitalhub.entities.project._base.models import ProfileConfig
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
class ProjectSpec(Spec):
|
|
@@ -18,6 +19,7 @@ class ProjectSpec(Spec):
|
|
|
18
19
|
workflows: list | None = None,
|
|
19
20
|
dataitems: list | None = None,
|
|
20
21
|
models: list | None = None,
|
|
22
|
+
config: dict | None = None,
|
|
21
23
|
**kwargs,
|
|
22
24
|
) -> None:
|
|
23
25
|
self.context = context if context is not None else "./"
|
|
@@ -26,6 +28,7 @@ class ProjectSpec(Spec):
|
|
|
26
28
|
self.workflows = workflows if workflows is not None else []
|
|
27
29
|
self.dataitems = dataitems if dataitems is not None else []
|
|
28
30
|
self.models = models if models is not None else []
|
|
31
|
+
self.config = config if config is not None else {}
|
|
29
32
|
|
|
30
33
|
|
|
31
34
|
class ProjectValidator(SpecValidator):
|
|
@@ -50,3 +53,6 @@ class ProjectValidator(SpecValidator):
|
|
|
50
53
|
|
|
51
54
|
models: Optional[list] = None
|
|
52
55
|
"""List of project's models."""
|
|
56
|
+
|
|
57
|
+
config: Optional[ProfileConfig] = None
|
|
58
|
+
"""Project's config."""
|
|
@@ -75,7 +75,6 @@ def new_project(
|
|
|
75
75
|
def get_project(
|
|
76
76
|
name: str,
|
|
77
77
|
local: bool = False,
|
|
78
|
-
config: dict | None = None,
|
|
79
78
|
setup_kwargs: dict | None = None,
|
|
80
79
|
**kwargs,
|
|
81
80
|
) -> Project:
|
|
@@ -88,8 +87,6 @@ def get_project(
|
|
|
88
87
|
The Project name.
|
|
89
88
|
local : bool
|
|
90
89
|
Flag to determine if backend is local.
|
|
91
|
-
config : dict
|
|
92
|
-
DHCore environment configuration.
|
|
93
90
|
setup_kwargs : dict
|
|
94
91
|
Setup keyword arguments passed to setup_project() function.
|
|
95
92
|
**kwargs : dict
|
|
@@ -108,7 +105,6 @@ def get_project(
|
|
|
108
105
|
entity_type=ENTITY_TYPE,
|
|
109
106
|
entity_name=name,
|
|
110
107
|
local=local,
|
|
111
|
-
config=config,
|
|
112
108
|
**kwargs,
|
|
113
109
|
)
|
|
114
110
|
return setup_project(obj, setup_kwargs)
|
|
@@ -117,7 +113,6 @@ def get_project(
|
|
|
117
113
|
def import_project(
|
|
118
114
|
file: str,
|
|
119
115
|
local: bool = False,
|
|
120
|
-
config: dict | None = None,
|
|
121
116
|
setup_kwargs: dict | None = None,
|
|
122
117
|
) -> Project:
|
|
123
118
|
"""
|
|
@@ -129,8 +124,6 @@ def import_project(
|
|
|
129
124
|
Path to YAML file.
|
|
130
125
|
local : bool
|
|
131
126
|
Flag to determine if backend is local.
|
|
132
|
-
config : dict
|
|
133
|
-
DHCore environment configuration.
|
|
134
127
|
setup_kwargs : dict
|
|
135
128
|
Setup keyword arguments passed to setup_project() function.
|
|
136
129
|
|
|
@@ -143,14 +136,13 @@ def import_project(
|
|
|
143
136
|
--------
|
|
144
137
|
>>> obj = import_project("my-project.yaml")
|
|
145
138
|
"""
|
|
146
|
-
obj = base_processor.import_project_entity(file=file, local=local
|
|
139
|
+
obj = base_processor.import_project_entity(file=file, local=local)
|
|
147
140
|
return setup_project(obj, setup_kwargs)
|
|
148
141
|
|
|
149
142
|
|
|
150
143
|
def load_project(
|
|
151
144
|
file: str,
|
|
152
145
|
local: bool = False,
|
|
153
|
-
config: dict | None = None,
|
|
154
146
|
setup_kwargs: dict | None = None,
|
|
155
147
|
) -> Project:
|
|
156
148
|
"""
|
|
@@ -162,8 +154,6 @@ def load_project(
|
|
|
162
154
|
Path to YAML file.
|
|
163
155
|
local : bool
|
|
164
156
|
Flag to determine if backend is local.
|
|
165
|
-
config : dict
|
|
166
|
-
DHCore environment configuration.
|
|
167
157
|
setup_kwargs : dict
|
|
168
158
|
Setup keyword arguments passed to setup_project() function.
|
|
169
159
|
|
|
@@ -176,7 +166,7 @@ def load_project(
|
|
|
176
166
|
--------
|
|
177
167
|
>>> obj = load_project("my-project.yaml")
|
|
178
168
|
"""
|
|
179
|
-
obj = base_processor.load_project_entity(file=file, local=local
|
|
169
|
+
obj = base_processor.load_project_entity(file=file, local=local)
|
|
180
170
|
return setup_project(obj, setup_kwargs)
|
|
181
171
|
|
|
182
172
|
|
|
@@ -234,7 +224,6 @@ def get_or_create_project(
|
|
|
234
224
|
return get_project(
|
|
235
225
|
name,
|
|
236
226
|
local=local,
|
|
237
|
-
config=config,
|
|
238
227
|
setup_kwargs=setup_kwargs,
|
|
239
228
|
**kwargs,
|
|
240
229
|
)
|
|
@@ -7,13 +7,7 @@ from digitalhub.entities._base.unversioned.entity import UnversionedEntity
|
|
|
7
7
|
from digitalhub.entities._commons.enums import EntityTypes, State
|
|
8
8
|
from digitalhub.entities._commons.metrics import MetricType, set_metrics, validate_metric_value
|
|
9
9
|
from digitalhub.entities._processors.context import context_processor
|
|
10
|
-
from digitalhub.factory.
|
|
11
|
-
build_runtime,
|
|
12
|
-
build_spec,
|
|
13
|
-
build_status,
|
|
14
|
-
get_entity_type_from_kind,
|
|
15
|
-
get_executable_kind,
|
|
16
|
-
)
|
|
10
|
+
from digitalhub.factory.factory import factory
|
|
17
11
|
from digitalhub.utils.exceptions import EntityError
|
|
18
12
|
from digitalhub.utils.logger import LOGGER
|
|
19
13
|
|
|
@@ -61,7 +55,7 @@ class Run(UnversionedEntity):
|
|
|
61
55
|
executable = self._get_executable()
|
|
62
56
|
task = self._get_task()
|
|
63
57
|
new_spec = self._get_runtime().build(executable, task, self.to_dict())
|
|
64
|
-
self.spec = build_spec(self.kind, **new_spec)
|
|
58
|
+
self.spec = factory.build_spec(self.kind, **new_spec)
|
|
65
59
|
self._set_state(State.BUILT.value)
|
|
66
60
|
self.save(update=True)
|
|
67
61
|
|
|
@@ -302,7 +296,7 @@ class Run(UnversionedEntity):
|
|
|
302
296
|
-------
|
|
303
297
|
None
|
|
304
298
|
"""
|
|
305
|
-
self.status: RunStatus = build_status(self.kind, **status)
|
|
299
|
+
self.status: RunStatus = factory.build_status(self.kind, **status)
|
|
306
300
|
|
|
307
301
|
def _set_state(self, state: str) -> None:
|
|
308
302
|
"""
|
|
@@ -343,7 +337,7 @@ class Run(UnversionedEntity):
|
|
|
343
337
|
Runtime
|
|
344
338
|
Runtime object.
|
|
345
339
|
"""
|
|
346
|
-
return build_runtime(self.kind, self.project)
|
|
340
|
+
return factory.build_runtime(self.kind, self.project)
|
|
347
341
|
|
|
348
342
|
def _get_executable(self) -> dict:
|
|
349
343
|
"""
|
|
@@ -355,8 +349,8 @@ class Run(UnversionedEntity):
|
|
|
355
349
|
dict
|
|
356
350
|
Executable (function or workflow) from backend.
|
|
357
351
|
"""
|
|
358
|
-
exec_kind = get_executable_kind(self.kind)
|
|
359
|
-
exec_type = get_entity_type_from_kind(exec_kind)
|
|
352
|
+
exec_kind = factory.get_executable_kind(self.kind)
|
|
353
|
+
exec_type = factory.get_entity_type_from_kind(exec_kind)
|
|
360
354
|
string_to_split = getattr(self.spec, exec_type)
|
|
361
355
|
exec_name, exec_id = string_to_split.split("://")[-1].split("/")[-1].split(":")
|
|
362
356
|
return context_processor.read_context_entity(
|
|
@@ -5,7 +5,7 @@ import typing
|
|
|
5
5
|
from digitalhub.entities._base.unversioned.entity import UnversionedEntity
|
|
6
6
|
from digitalhub.entities._commons.enums import EntityTypes
|
|
7
7
|
from digitalhub.entities._processors.context import context_processor
|
|
8
|
-
from digitalhub.factory.
|
|
8
|
+
from digitalhub.factory.factory import factory
|
|
9
9
|
|
|
10
10
|
if typing.TYPE_CHECKING:
|
|
11
11
|
from digitalhub.entities._base.entity.metadata import Metadata
|
|
@@ -63,8 +63,8 @@ class Task(UnversionedEntity):
|
|
|
63
63
|
Run
|
|
64
64
|
Run object.
|
|
65
65
|
"""
|
|
66
|
-
exec_kind = get_executable_kind(self.kind)
|
|
67
|
-
exec_type = get_entity_type_from_kind(exec_kind)
|
|
66
|
+
exec_kind = factory.get_executable_kind(self.kind)
|
|
67
|
+
exec_type = factory.get_entity_type_from_kind(exec_kind)
|
|
68
68
|
kwargs[exec_type] = getattr(self.spec, exec_type)
|
|
69
69
|
return self.new_run(
|
|
70
70
|
save=save,
|
|
@@ -108,7 +108,7 @@ class Task(UnversionedEntity):
|
|
|
108
108
|
"""
|
|
109
109
|
if save:
|
|
110
110
|
return context_processor.create_context_entity(**kwargs)
|
|
111
|
-
return build_entity_from_params(**kwargs)
|
|
111
|
+
return factory.build_entity_from_params(**kwargs)
|
|
112
112
|
|
|
113
113
|
def get_run(self, entity_key: str) -> Run:
|
|
114
114
|
"""
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from enum import Enum
|
|
4
|
-
from typing import Optional
|
|
4
|
+
from typing import Optional, Union
|
|
5
5
|
|
|
6
6
|
from pydantic import BaseModel, ConfigDict, Field
|
|
7
7
|
|
|
@@ -15,6 +15,24 @@ class VolumeType(Enum):
|
|
|
15
15
|
EMPTY_DIR = "empty_dir"
|
|
16
16
|
|
|
17
17
|
|
|
18
|
+
class SpecEmptyDir(BaseModel):
|
|
19
|
+
"""
|
|
20
|
+
Spec empty dir model.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
size_limit: str
|
|
24
|
+
|
|
25
|
+
medium: Optional[str] = None
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class SpecPVC(BaseModel):
|
|
29
|
+
"""
|
|
30
|
+
Spec PVC model.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
size: str
|
|
34
|
+
|
|
35
|
+
|
|
18
36
|
class Volume(BaseModel):
|
|
19
37
|
"""
|
|
20
38
|
Volume model.
|
|
@@ -31,7 +49,7 @@ class Volume(BaseModel):
|
|
|
31
49
|
mount_path: str
|
|
32
50
|
"""Volume mount path inside the container."""
|
|
33
51
|
|
|
34
|
-
spec: Optional[
|
|
52
|
+
spec: Optional[Union[SpecEmptyDir, SpecPVC]] = None
|
|
35
53
|
"""Volume spec."""
|
|
36
54
|
|
|
37
55
|
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from digitalhub.entities._base.versioned.builder import VersionedBuilder
|
|
4
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
5
|
+
from digitalhub.entities.trigger._base.entity import Trigger
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TriggerBuilder(VersionedBuilder):
|
|
9
|
+
"""
|
|
10
|
+
TriggerTriggerBuilder builder.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
ENTITY_TYPE = EntityTypes.TRIGGER.value
|
|
14
|
+
|
|
15
|
+
def build(
|
|
16
|
+
self,
|
|
17
|
+
kind: str,
|
|
18
|
+
project: str,
|
|
19
|
+
name: str,
|
|
20
|
+
uuid: str | None = None,
|
|
21
|
+
description: str | None = None,
|
|
22
|
+
labels: list[str] | None = None,
|
|
23
|
+
**kwargs,
|
|
24
|
+
) -> Trigger:
|
|
25
|
+
"""
|
|
26
|
+
Create a new object.
|
|
27
|
+
|
|
28
|
+
Parameters
|
|
29
|
+
----------
|
|
30
|
+
project : str
|
|
31
|
+
Project name.
|
|
32
|
+
name : str
|
|
33
|
+
Object name.
|
|
34
|
+
kind : str
|
|
35
|
+
Kind the object.
|
|
36
|
+
uuid : str
|
|
37
|
+
ID of the object.
|
|
38
|
+
description : str
|
|
39
|
+
Description of the object (human readable).
|
|
40
|
+
labels : list[str]
|
|
41
|
+
List of labels.
|
|
42
|
+
**kwargs : dict
|
|
43
|
+
Spec keyword arguments.
|
|
44
|
+
|
|
45
|
+
Returns
|
|
46
|
+
-------
|
|
47
|
+
Trigger
|
|
48
|
+
Object instance.
|
|
49
|
+
"""
|
|
50
|
+
name = self.build_name(name)
|
|
51
|
+
uuid = self.build_uuid(uuid)
|
|
52
|
+
metadata = self.build_metadata(
|
|
53
|
+
project=project,
|
|
54
|
+
name=name,
|
|
55
|
+
description=description,
|
|
56
|
+
labels=labels,
|
|
57
|
+
)
|
|
58
|
+
spec = self.build_spec(
|
|
59
|
+
**kwargs,
|
|
60
|
+
)
|
|
61
|
+
status = self.build_status()
|
|
62
|
+
return self.build_entity(
|
|
63
|
+
project=project,
|
|
64
|
+
name=name,
|
|
65
|
+
uuid=uuid,
|
|
66
|
+
kind=kind,
|
|
67
|
+
metadata=metadata,
|
|
68
|
+
spec=spec,
|
|
69
|
+
status=status,
|
|
70
|
+
)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from digitalhub.entities._base.versioned.entity import VersionedEntity
|
|
6
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
7
|
+
|
|
8
|
+
if typing.TYPE_CHECKING:
|
|
9
|
+
from digitalhub.entities._base.entity.metadata import Metadata
|
|
10
|
+
from digitalhub.entities.trigger._base.spec import TriggerSpec
|
|
11
|
+
from digitalhub.entities.trigger._base.status import TriggerStatus
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Trigger(VersionedEntity):
|
|
15
|
+
"""
|
|
16
|
+
A class representing a trigger.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
ENTITY_TYPE = EntityTypes.TRIGGER.value
|
|
20
|
+
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
project: str,
|
|
24
|
+
name: str,
|
|
25
|
+
uuid: str,
|
|
26
|
+
kind: str,
|
|
27
|
+
metadata: Metadata,
|
|
28
|
+
spec: TriggerSpec,
|
|
29
|
+
status: TriggerStatus,
|
|
30
|
+
user: str | None = None,
|
|
31
|
+
) -> None:
|
|
32
|
+
super().__init__(project, name, uuid, kind, metadata, spec, status, user)
|
|
33
|
+
self.spec: TriggerSpec
|
|
34
|
+
self.status: TriggerStatus
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from digitalhub.entities._base.entity.spec import Spec, SpecValidator
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class TriggerSpec(Spec):
|
|
7
|
+
"""
|
|
8
|
+
TriggerSpec specifications.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
def __init__(
|
|
12
|
+
self,
|
|
13
|
+
task: str,
|
|
14
|
+
template: dict,
|
|
15
|
+
function: str | None = None,
|
|
16
|
+
workflow: str | None = None,
|
|
17
|
+
) -> None:
|
|
18
|
+
super().__init__()
|
|
19
|
+
self.task = task
|
|
20
|
+
self.template = template
|
|
21
|
+
self.function = function
|
|
22
|
+
self.workflow = workflow
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TriggerValidator(SpecValidator):
|
|
26
|
+
"""
|
|
27
|
+
TriggerValidator validator.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
task: str
|
|
31
|
+
"""Task string."""
|
|
32
|
+
|
|
33
|
+
template: dict
|
|
34
|
+
"""Template map."""
|
|
35
|
+
|
|
36
|
+
function: str = None
|
|
37
|
+
"""Function string."""
|
|
38
|
+
|
|
39
|
+
workflow: str = None
|
|
40
|
+
"""Workflow string."""
|