digitalhub 0.10.1__py3-none-any.whl → 0.11.0b0__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 +30 -4
- digitalhub/entities/_base/material/utils.py +11 -11
- digitalhub/entities/_commons/enums.py +2 -0
- digitalhub/entities/_processors/base.py +15 -15
- digitalhub/entities/_processors/context.py +13 -13
- digitalhub/entities/_processors/utils.py +2 -2
- digitalhub/entities/builders.py +2 -0
- digitalhub/entities/function/_base/entity.py +49 -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 +22 -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 +30 -0
- digitalhub/entities/trigger/_base/status.py +9 -0
- digitalhub/entities/trigger/crud.py +303 -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 +22 -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/configurator/configurator.py +2 -1
- digitalhub/stores/configurator/enums.py +9 -0
- digitalhub/stores/data/api.py +4 -2
- digitalhub/stores/data/builder.py +4 -4
- digitalhub/stores/data/enums.py +11 -0
- digitalhub/stores/data/local/store.py +2 -2
- digitalhub/stores/data/remote/store.py +2 -2
- digitalhub/stores/data/s3/configurator.py +11 -7
- digitalhub/stores/data/s3/store.py +4 -10
- digitalhub/stores/data/sql/configurator.py +20 -11
- digitalhub/stores/data/sql/store.py +2 -4
- digitalhub/stores/data/utils.py +34 -0
- digitalhub/utils/uri_utils.py +5 -0
- {digitalhub-0.10.1.dist-info → digitalhub-0.11.0b0.dist-info}/METADATA +2 -3
- {digitalhub-0.10.1.dist-info → digitalhub-0.11.0b0.dist-info}/RECORD +56 -42
- digitalhub/factory/api.py +0 -277
- {digitalhub-0.10.1.dist-info → digitalhub-0.11.0b0.dist-info}/WHEEL +0 -0
- {digitalhub-0.10.1.dist-info → digitalhub-0.11.0b0.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -5,14 +5,16 @@ 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:
|
|
12
12
|
from digitalhub.entities._base.entity.metadata import Metadata
|
|
13
|
+
from digitalhub.entities._base.entity.spec import SpecValidator
|
|
13
14
|
from digitalhub.entities.function._base.spec import FunctionSpec
|
|
14
15
|
from digitalhub.entities.function._base.status import FunctionStatus
|
|
15
16
|
from digitalhub.entities.run._base.entity import Run
|
|
17
|
+
from digitalhub.entities.trigger._base.entity import Trigger
|
|
16
18
|
|
|
17
19
|
|
|
18
20
|
class Function(ExecutableEntity):
|
|
@@ -72,8 +74,8 @@ class Function(ExecutableEntity):
|
|
|
72
74
|
Run instance.
|
|
73
75
|
"""
|
|
74
76
|
# Get task and run kind
|
|
75
|
-
task_kind = get_task_kind_from_action(self.kind, action)
|
|
76
|
-
run_kind = get_run_kind(self.kind)
|
|
77
|
+
task_kind = factory.get_task_kind_from_action(self.kind, action)
|
|
78
|
+
run_kind = factory.get_run_kind(self.kind)
|
|
77
79
|
|
|
78
80
|
# Create or update new task
|
|
79
81
|
task = self._get_or_create_task(task_kind)
|
|
@@ -100,3 +102,47 @@ class Function(ExecutableEntity):
|
|
|
100
102
|
result = executor.submit(run.run)
|
|
101
103
|
r = result.result()
|
|
102
104
|
return r
|
|
105
|
+
|
|
106
|
+
def trigger(self, action: str, trigger_kind: str, trigger_name: str, **kwargs) -> Trigger:
|
|
107
|
+
"""
|
|
108
|
+
Trigger function.
|
|
109
|
+
|
|
110
|
+
Parameters
|
|
111
|
+
----------
|
|
112
|
+
action : str
|
|
113
|
+
Action to execute.
|
|
114
|
+
trigger_kind : str
|
|
115
|
+
Trigger kind.
|
|
116
|
+
**kwargs : dict
|
|
117
|
+
Keyword arguments passed to Run builder.
|
|
118
|
+
|
|
119
|
+
Returns
|
|
120
|
+
-------
|
|
121
|
+
Run
|
|
122
|
+
Run instance.
|
|
123
|
+
"""
|
|
124
|
+
# Get task
|
|
125
|
+
task_kind = factory.get_task_kind_from_action(self.kind, action)
|
|
126
|
+
task = self._get_or_create_task(task_kind)
|
|
127
|
+
task_string = task._get_task_string()
|
|
128
|
+
|
|
129
|
+
# Get run validator for building trigger template
|
|
130
|
+
run_kind = factory.get_run_kind(self.kind)
|
|
131
|
+
run_validator: SpecValidator = factory.get_spec_validator(run_kind)
|
|
132
|
+
if kwargs is None:
|
|
133
|
+
kwargs = {}
|
|
134
|
+
kwargs[self.ENTITY_TYPE] = self._get_executable_string()
|
|
135
|
+
kwargs["task"] = task_string
|
|
136
|
+
|
|
137
|
+
template = run_validator(**kwargs).to_dict()
|
|
138
|
+
|
|
139
|
+
# Override kwargs
|
|
140
|
+
kwargs["project"] = self.project
|
|
141
|
+
kwargs["kind"] = trigger_kind
|
|
142
|
+
kwargs["name"] = trigger_name
|
|
143
|
+
kwargs["template"] = template
|
|
144
|
+
|
|
145
|
+
# Create object instance
|
|
146
|
+
trigger: Trigger = factory.build_entity_from_params(**kwargs)
|
|
147
|
+
trigger.save()
|
|
148
|
+
return trigger
|
|
@@ -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_FILE_STORE = "s3://datalake"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ProfileConfig(BaseModel):
|
|
11
|
+
"""
|
|
12
|
+
Configuration profiles.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
default_files_store: Optional[str] = _DEFAULT_FILE_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,26 @@ 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
|
+
medium: Optional[str] = None
|
|
24
|
+
|
|
25
|
+
size_limit: Optional[str] = "128Mi"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class SpecPVC(BaseModel):
|
|
29
|
+
"""
|
|
30
|
+
Spec PVC model.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
size: str
|
|
34
|
+
|
|
35
|
+
storage_class: str
|
|
36
|
+
|
|
37
|
+
|
|
18
38
|
class Volume(BaseModel):
|
|
19
39
|
"""
|
|
20
40
|
Volume model.
|
|
@@ -31,7 +51,7 @@ class Volume(BaseModel):
|
|
|
31
51
|
mount_path: str
|
|
32
52
|
"""Volume mount path inside the container."""
|
|
33
53
|
|
|
34
|
-
spec: Optional[
|
|
54
|
+
spec: Optional[Union[SpecEmptyDir, SpecPVC]] = None
|
|
35
55
|
"""Volume spec."""
|
|
36
56
|
|
|
37
57
|
|
|
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,30 @@
|
|
|
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__(self, task: str, function: str, template: dict) -> None:
|
|
12
|
+
super().__init__()
|
|
13
|
+
self.task = task
|
|
14
|
+
self.function = function
|
|
15
|
+
self.template = template
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class TriggerValidator(SpecValidator):
|
|
19
|
+
"""
|
|
20
|
+
TriggerValidator validator.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
task: str
|
|
24
|
+
"""Task string."""
|
|
25
|
+
|
|
26
|
+
function: str
|
|
27
|
+
"""Function string."""
|
|
28
|
+
|
|
29
|
+
template: dict
|
|
30
|
+
"""Template string."""
|