digitalhub 0.8.0b0__py3-none-any.whl → 0.8.0b2__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 +62 -94
- digitalhub/client/__init__.py +0 -0
- digitalhub/client/builder.py +105 -0
- digitalhub/client/objects/__init__.py +0 -0
- digitalhub/client/objects/base.py +56 -0
- digitalhub/client/objects/dhcore.py +681 -0
- digitalhub/client/objects/local.py +533 -0
- digitalhub/context/__init__.py +0 -0
- digitalhub/context/builder.py +178 -0
- digitalhub/context/context.py +136 -0
- digitalhub/datastores/__init__.py +0 -0
- digitalhub/datastores/builder.py +134 -0
- digitalhub/datastores/objects/__init__.py +0 -0
- digitalhub/datastores/objects/base.py +85 -0
- digitalhub/datastores/objects/local.py +42 -0
- digitalhub/datastores/objects/remote.py +23 -0
- digitalhub/datastores/objects/s3.py +38 -0
- digitalhub/datastores/objects/sql.py +60 -0
- digitalhub/entities/__init__.py +0 -0
- digitalhub/entities/_base/__init__.py +0 -0
- digitalhub/entities/_base/api.py +346 -0
- digitalhub/entities/_base/base.py +82 -0
- digitalhub/entities/_base/crud.py +610 -0
- digitalhub/entities/_base/entity/__init__.py +0 -0
- digitalhub/entities/_base/entity/base.py +132 -0
- digitalhub/entities/_base/entity/context.py +118 -0
- digitalhub/entities/_base/entity/executable.py +380 -0
- digitalhub/entities/_base/entity/material.py +214 -0
- digitalhub/entities/_base/entity/unversioned.py +87 -0
- digitalhub/entities/_base/entity/versioned.py +94 -0
- digitalhub/entities/_base/metadata.py +59 -0
- digitalhub/entities/_base/spec/__init__.py +0 -0
- digitalhub/entities/_base/spec/base.py +58 -0
- digitalhub/entities/_base/spec/material.py +22 -0
- digitalhub/entities/_base/state.py +31 -0
- digitalhub/entities/_base/status/__init__.py +0 -0
- digitalhub/entities/_base/status/base.py +32 -0
- digitalhub/entities/_base/status/material.py +49 -0
- digitalhub/entities/_builders/__init__.py +0 -0
- digitalhub/entities/_builders/metadata.py +60 -0
- digitalhub/entities/_builders/name.py +31 -0
- digitalhub/entities/_builders/spec.py +43 -0
- digitalhub/entities/_builders/status.py +62 -0
- digitalhub/entities/_builders/uuid.py +33 -0
- digitalhub/entities/artifact/__init__.py +0 -0
- digitalhub/entities/artifact/builder.py +133 -0
- digitalhub/entities/artifact/crud.py +358 -0
- digitalhub/entities/artifact/entity/__init__.py +0 -0
- digitalhub/entities/artifact/entity/_base.py +39 -0
- digitalhub/entities/artifact/entity/artifact.py +9 -0
- digitalhub/entities/artifact/spec.py +39 -0
- digitalhub/entities/artifact/status.py +15 -0
- digitalhub/entities/dataitem/__init__.py +0 -0
- digitalhub/entities/dataitem/builder.py +144 -0
- digitalhub/entities/dataitem/crud.py +395 -0
- digitalhub/entities/dataitem/entity/__init__.py +0 -0
- digitalhub/entities/dataitem/entity/_base.py +75 -0
- digitalhub/entities/dataitem/entity/dataitem.py +9 -0
- digitalhub/entities/dataitem/entity/iceberg.py +7 -0
- digitalhub/entities/dataitem/entity/table.py +125 -0
- digitalhub/entities/dataitem/models.py +62 -0
- digitalhub/entities/dataitem/spec.py +61 -0
- digitalhub/entities/dataitem/status.py +38 -0
- digitalhub/entities/entity_types.py +19 -0
- digitalhub/entities/function/__init__.py +0 -0
- digitalhub/entities/function/builder.py +86 -0
- digitalhub/entities/function/crud.py +305 -0
- digitalhub/entities/function/entity.py +101 -0
- digitalhub/entities/function/models.py +118 -0
- digitalhub/entities/function/spec.py +81 -0
- digitalhub/entities/function/status.py +9 -0
- digitalhub/entities/model/__init__.py +0 -0
- digitalhub/entities/model/builder.py +152 -0
- digitalhub/entities/model/crud.py +358 -0
- digitalhub/entities/model/entity/__init__.py +0 -0
- digitalhub/entities/model/entity/_base.py +34 -0
- digitalhub/entities/model/entity/huggingface.py +9 -0
- digitalhub/entities/model/entity/mlflow.py +90 -0
- digitalhub/entities/model/entity/model.py +9 -0
- digitalhub/entities/model/entity/sklearn.py +9 -0
- digitalhub/entities/model/models.py +26 -0
- digitalhub/entities/model/spec.py +146 -0
- digitalhub/entities/model/status.py +33 -0
- digitalhub/entities/project/__init__.py +0 -0
- digitalhub/entities/project/builder.py +82 -0
- digitalhub/entities/project/crud.py +350 -0
- digitalhub/entities/project/entity.py +2060 -0
- digitalhub/entities/project/spec.py +50 -0
- digitalhub/entities/project/status.py +9 -0
- digitalhub/entities/registries.py +48 -0
- digitalhub/entities/run/__init__.py +0 -0
- digitalhub/entities/run/builder.py +77 -0
- digitalhub/entities/run/crud.py +232 -0
- digitalhub/entities/run/entity.py +461 -0
- digitalhub/entities/run/spec.py +153 -0
- digitalhub/entities/run/status.py +114 -0
- digitalhub/entities/secret/__init__.py +0 -0
- digitalhub/entities/secret/builder.py +93 -0
- digitalhub/entities/secret/crud.py +294 -0
- digitalhub/entities/secret/entity.py +73 -0
- digitalhub/entities/secret/spec.py +35 -0
- digitalhub/entities/secret/status.py +9 -0
- digitalhub/entities/task/__init__.py +0 -0
- digitalhub/entities/task/builder.py +74 -0
- digitalhub/entities/task/crud.py +241 -0
- digitalhub/entities/task/entity.py +135 -0
- digitalhub/entities/task/models.py +199 -0
- digitalhub/entities/task/spec.py +51 -0
- digitalhub/entities/task/status.py +9 -0
- digitalhub/entities/utils.py +184 -0
- digitalhub/entities/workflow/__init__.py +0 -0
- digitalhub/entities/workflow/builder.py +91 -0
- digitalhub/entities/workflow/crud.py +304 -0
- digitalhub/entities/workflow/entity.py +77 -0
- digitalhub/entities/workflow/spec.py +15 -0
- digitalhub/entities/workflow/status.py +9 -0
- digitalhub/readers/__init__.py +0 -0
- digitalhub/readers/builder.py +54 -0
- digitalhub/readers/objects/__init__.py +0 -0
- digitalhub/readers/objects/base.py +70 -0
- digitalhub/readers/objects/pandas.py +207 -0
- digitalhub/readers/registry.py +15 -0
- digitalhub/registry/__init__.py +0 -0
- digitalhub/registry/models.py +87 -0
- digitalhub/registry/registry.py +74 -0
- digitalhub/registry/utils.py +150 -0
- digitalhub/runtimes/__init__.py +0 -0
- digitalhub/runtimes/base.py +164 -0
- digitalhub/runtimes/builder.py +53 -0
- digitalhub/runtimes/kind_registry.py +170 -0
- digitalhub/stores/__init__.py +0 -0
- digitalhub/stores/builder.py +257 -0
- digitalhub/stores/objects/__init__.py +0 -0
- digitalhub/stores/objects/base.py +189 -0
- digitalhub/stores/objects/local.py +230 -0
- digitalhub/stores/objects/remote.py +143 -0
- digitalhub/stores/objects/s3.py +563 -0
- digitalhub/stores/objects/sql.py +328 -0
- digitalhub/utils/__init__.py +0 -0
- digitalhub/utils/data_utils.py +127 -0
- digitalhub/utils/env_utils.py +123 -0
- digitalhub/utils/exceptions.py +55 -0
- digitalhub/utils/file_utils.py +204 -0
- digitalhub/utils/generic_utils.py +207 -0
- digitalhub/utils/git_utils.py +148 -0
- digitalhub/utils/io_utils.py +79 -0
- digitalhub/utils/logger.py +17 -0
- digitalhub/utils/uri_utils.py +56 -0
- {digitalhub-0.8.0b0.dist-info → digitalhub-0.8.0b2.dist-info}/METADATA +27 -12
- digitalhub-0.8.0b2.dist-info/RECORD +161 -0
- test/test_crud_artifacts.py +1 -1
- test/test_crud_dataitems.py +1 -1
- test/test_crud_functions.py +1 -1
- test/test_crud_runs.py +1 -1
- test/test_crud_tasks.py +1 -1
- digitalhub-0.8.0b0.dist-info/RECORD +0 -14
- {digitalhub-0.8.0b0.dist-info → digitalhub-0.8.0b2.dist-info}/LICENSE.txt +0 -0
- {digitalhub-0.8.0b0.dist-info → digitalhub-0.8.0b2.dist-info}/WHEEL +0 -0
- {digitalhub-0.8.0b0.dist-info → digitalhub-0.8.0b2.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from digitalhub.context.builder import check_context
|
|
6
|
+
from digitalhub.entities._base.crud import delete_entity_api_ctx, list_entity_api_ctx, read_entity_api_ctx
|
|
7
|
+
from digitalhub.entities.entity_types import EntityTypes
|
|
8
|
+
from digitalhub.entities.task.builder import task_from_dict, task_from_parameters
|
|
9
|
+
from digitalhub.utils.exceptions import EntityAlreadyExistsError, EntityError
|
|
10
|
+
from digitalhub.utils.io_utils import read_yaml
|
|
11
|
+
|
|
12
|
+
if typing.TYPE_CHECKING:
|
|
13
|
+
from digitalhub.entities.task.entity import Task
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
ENTITY_TYPE = EntityTypes.TASK.value
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def new_task(
|
|
20
|
+
project: str,
|
|
21
|
+
kind: str,
|
|
22
|
+
uuid: str | None = None,
|
|
23
|
+
labels: list[str] | None = None,
|
|
24
|
+
function: str | None = None,
|
|
25
|
+
**kwargs,
|
|
26
|
+
) -> Task:
|
|
27
|
+
"""
|
|
28
|
+
Create a new object.
|
|
29
|
+
|
|
30
|
+
Parameters
|
|
31
|
+
----------
|
|
32
|
+
project : str
|
|
33
|
+
Project name.
|
|
34
|
+
kind : str
|
|
35
|
+
Kind the object.
|
|
36
|
+
uuid : str
|
|
37
|
+
ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).
|
|
38
|
+
labels : list[str]
|
|
39
|
+
List of labels.
|
|
40
|
+
function : str
|
|
41
|
+
Name of the executable associated with the task.
|
|
42
|
+
**kwargs : dict
|
|
43
|
+
Spec keyword arguments.
|
|
44
|
+
|
|
45
|
+
Returns
|
|
46
|
+
-------
|
|
47
|
+
Task
|
|
48
|
+
Object instance.
|
|
49
|
+
|
|
50
|
+
Examples
|
|
51
|
+
--------
|
|
52
|
+
>>> obj = new_function(project="my-project",
|
|
53
|
+
>>> name="my-function",
|
|
54
|
+
>>> kind="python+task",
|
|
55
|
+
>>> task="task-string"
|
|
56
|
+
"""
|
|
57
|
+
check_context(project)
|
|
58
|
+
obj = task_from_parameters(
|
|
59
|
+
project=project,
|
|
60
|
+
kind=kind,
|
|
61
|
+
uuid=uuid,
|
|
62
|
+
labels=labels,
|
|
63
|
+
function=function,
|
|
64
|
+
**kwargs,
|
|
65
|
+
)
|
|
66
|
+
obj.save()
|
|
67
|
+
return obj
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def get_task(
|
|
71
|
+
identifier: str,
|
|
72
|
+
project: str | None = None,
|
|
73
|
+
**kwargs,
|
|
74
|
+
) -> Task:
|
|
75
|
+
"""
|
|
76
|
+
Get object from backend.
|
|
77
|
+
|
|
78
|
+
Parameters
|
|
79
|
+
----------
|
|
80
|
+
identifier : str
|
|
81
|
+
Entity key (store://...) or entity ID.
|
|
82
|
+
project : str
|
|
83
|
+
Project name.
|
|
84
|
+
**kwargs : dict
|
|
85
|
+
Parameters to pass to the API call.
|
|
86
|
+
|
|
87
|
+
Returns
|
|
88
|
+
-------
|
|
89
|
+
Task
|
|
90
|
+
Object instance.
|
|
91
|
+
|
|
92
|
+
Examples
|
|
93
|
+
--------
|
|
94
|
+
Using entity key:
|
|
95
|
+
>>> obj = get_task("store://my-task-key")
|
|
96
|
+
|
|
97
|
+
Using entity ID:
|
|
98
|
+
>>> obj = get_task("my-task-id"
|
|
99
|
+
>>> project="my-project")
|
|
100
|
+
"""
|
|
101
|
+
if not identifier.startswith("store://"):
|
|
102
|
+
raise EntityError("Task has no name. Use key instead.")
|
|
103
|
+
obj = read_entity_api_ctx(
|
|
104
|
+
identifier,
|
|
105
|
+
ENTITY_TYPE,
|
|
106
|
+
project=project,
|
|
107
|
+
entity_id=identifier,
|
|
108
|
+
**kwargs,
|
|
109
|
+
)
|
|
110
|
+
return task_from_dict(obj)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def list_tasks(project: str, **kwargs) -> list[Task]:
|
|
114
|
+
"""
|
|
115
|
+
List all latest version objects from backend.
|
|
116
|
+
|
|
117
|
+
Parameters
|
|
118
|
+
----------
|
|
119
|
+
project : str
|
|
120
|
+
Project name.
|
|
121
|
+
**kwargs : dict
|
|
122
|
+
Parameters to pass to the API call.
|
|
123
|
+
|
|
124
|
+
Returns
|
|
125
|
+
-------
|
|
126
|
+
list[Task]
|
|
127
|
+
List of object instances.
|
|
128
|
+
|
|
129
|
+
Examples
|
|
130
|
+
--------
|
|
131
|
+
>>> objs = list_tasks(project="my-project")
|
|
132
|
+
"""
|
|
133
|
+
objs = list_entity_api_ctx(
|
|
134
|
+
project=project,
|
|
135
|
+
entity_type=ENTITY_TYPE,
|
|
136
|
+
**kwargs,
|
|
137
|
+
)
|
|
138
|
+
return [task_from_dict(obj) for obj in objs]
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def import_task(file: str) -> Task:
|
|
142
|
+
"""
|
|
143
|
+
Get object from file.
|
|
144
|
+
|
|
145
|
+
Parameters
|
|
146
|
+
----------
|
|
147
|
+
file : str
|
|
148
|
+
Path to YAML file.
|
|
149
|
+
|
|
150
|
+
Returns
|
|
151
|
+
-------
|
|
152
|
+
Task
|
|
153
|
+
Object instance.
|
|
154
|
+
|
|
155
|
+
Example
|
|
156
|
+
-------
|
|
157
|
+
>>> obj = import_task("my-task.yaml")
|
|
158
|
+
"""
|
|
159
|
+
dict_obj: dict = read_yaml(file)
|
|
160
|
+
obj = task_from_dict(dict_obj)
|
|
161
|
+
try:
|
|
162
|
+
obj.save()
|
|
163
|
+
except EntityAlreadyExistsError:
|
|
164
|
+
pass
|
|
165
|
+
finally:
|
|
166
|
+
return obj
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def update_task(entity: Task) -> Task:
|
|
170
|
+
"""
|
|
171
|
+
Update object. Note that object spec are immutable.
|
|
172
|
+
|
|
173
|
+
Parameters
|
|
174
|
+
----------
|
|
175
|
+
entity : Task
|
|
176
|
+
Object to update.
|
|
177
|
+
|
|
178
|
+
Returns
|
|
179
|
+
-------
|
|
180
|
+
Task
|
|
181
|
+
Entity updated.
|
|
182
|
+
|
|
183
|
+
Examples
|
|
184
|
+
--------
|
|
185
|
+
>>> obj = update_task(obj)
|
|
186
|
+
"""
|
|
187
|
+
return entity.save(update=True)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def delete_task(
|
|
191
|
+
identifier: str,
|
|
192
|
+
project: str | None = None,
|
|
193
|
+
entity_id: str | None = None,
|
|
194
|
+
delete_all_versions: bool = False,
|
|
195
|
+
cascade: bool = True,
|
|
196
|
+
**kwargs,
|
|
197
|
+
) -> dict:
|
|
198
|
+
"""
|
|
199
|
+
Delete object from backend.
|
|
200
|
+
|
|
201
|
+
Parameters
|
|
202
|
+
----------
|
|
203
|
+
identifier : str
|
|
204
|
+
Entity key (store://...) or entity name.
|
|
205
|
+
project : str
|
|
206
|
+
Project name.
|
|
207
|
+
entity_id : str
|
|
208
|
+
Entity ID.
|
|
209
|
+
delete_all_versions : bool
|
|
210
|
+
Delete all versions of the named entity. If True, use entity name instead of entity key as identifier.
|
|
211
|
+
cascade : bool
|
|
212
|
+
Cascade delete.
|
|
213
|
+
**kwargs : dict
|
|
214
|
+
Parameters to pass to the API call.
|
|
215
|
+
|
|
216
|
+
Returns
|
|
217
|
+
-------
|
|
218
|
+
dict
|
|
219
|
+
Response from backend.
|
|
220
|
+
|
|
221
|
+
Examples
|
|
222
|
+
--------
|
|
223
|
+
If delete_all_versions is False:
|
|
224
|
+
>>> obj = delete_task("store://my-task-key")
|
|
225
|
+
|
|
226
|
+
Otherwise:
|
|
227
|
+
>>> obj = delete_task("task-name",
|
|
228
|
+
>>> project="my-project",
|
|
229
|
+
>>> delete_all_versions=True)
|
|
230
|
+
"""
|
|
231
|
+
if not identifier.startswith("store://"):
|
|
232
|
+
raise EntityError("Task has no name. Use key instead.")
|
|
233
|
+
return delete_entity_api_ctx(
|
|
234
|
+
identifier=identifier,
|
|
235
|
+
entity_type=ENTITY_TYPE,
|
|
236
|
+
project=project,
|
|
237
|
+
entity_id=entity_id,
|
|
238
|
+
delete_all_versions=delete_all_versions,
|
|
239
|
+
cascade=cascade,
|
|
240
|
+
**kwargs,
|
|
241
|
+
)
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from digitalhub.entities._base.entity.unversioned import UnversionedEntity
|
|
6
|
+
from digitalhub.entities.entity_types import EntityTypes
|
|
7
|
+
from digitalhub.entities.run.crud import delete_run, get_run, new_run, run_from_parameters
|
|
8
|
+
|
|
9
|
+
if typing.TYPE_CHECKING:
|
|
10
|
+
from digitalhub.entities._base.metadata import Metadata
|
|
11
|
+
from digitalhub.entities.run.entity import Run
|
|
12
|
+
from digitalhub.entities.task.spec import TaskSpec
|
|
13
|
+
from digitalhub.entities.task.status import TaskStatus
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Task(UnversionedEntity):
|
|
17
|
+
"""
|
|
18
|
+
A class representing a task.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
ENTITY_TYPE = EntityTypes.TASK.value
|
|
22
|
+
|
|
23
|
+
def __init__(
|
|
24
|
+
self,
|
|
25
|
+
project: str,
|
|
26
|
+
uuid: str,
|
|
27
|
+
kind: str,
|
|
28
|
+
metadata: Metadata,
|
|
29
|
+
spec: TaskSpec,
|
|
30
|
+
status: TaskStatus,
|
|
31
|
+
user: str | None = None,
|
|
32
|
+
) -> None:
|
|
33
|
+
super().__init__(project, uuid, kind, metadata, spec, status, user)
|
|
34
|
+
self.spec: TaskSpec
|
|
35
|
+
self.status: TaskStatus
|
|
36
|
+
|
|
37
|
+
##############################
|
|
38
|
+
# Task methods
|
|
39
|
+
##############################
|
|
40
|
+
|
|
41
|
+
def run(
|
|
42
|
+
self,
|
|
43
|
+
run_kind: str,
|
|
44
|
+
local_execution: bool = False,
|
|
45
|
+
**kwargs,
|
|
46
|
+
) -> Run:
|
|
47
|
+
"""
|
|
48
|
+
Run task.
|
|
49
|
+
|
|
50
|
+
Parameters
|
|
51
|
+
----------
|
|
52
|
+
run_kind : str
|
|
53
|
+
Kind the object.
|
|
54
|
+
local_execution : bool
|
|
55
|
+
Flag to indicate if the run will be executed locally.
|
|
56
|
+
**kwargs : dict
|
|
57
|
+
Keyword arguments.
|
|
58
|
+
|
|
59
|
+
Returns
|
|
60
|
+
-------
|
|
61
|
+
Run
|
|
62
|
+
Run object.
|
|
63
|
+
"""
|
|
64
|
+
return self.new_run(
|
|
65
|
+
project=self.project,
|
|
66
|
+
task=self._get_task_string(),
|
|
67
|
+
kind=run_kind,
|
|
68
|
+
local_execution=local_execution,
|
|
69
|
+
**kwargs,
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
def _get_task_string(self) -> str:
|
|
73
|
+
"""
|
|
74
|
+
Get task string.
|
|
75
|
+
|
|
76
|
+
Returns
|
|
77
|
+
-------
|
|
78
|
+
str
|
|
79
|
+
Task string.
|
|
80
|
+
"""
|
|
81
|
+
splitted = self.spec.function.split("://")
|
|
82
|
+
return f"{self.kind}://{splitted[1]}"
|
|
83
|
+
|
|
84
|
+
##############################
|
|
85
|
+
# CRUD Methods for Run
|
|
86
|
+
##############################
|
|
87
|
+
|
|
88
|
+
def new_run(self, **kwargs) -> Run:
|
|
89
|
+
"""
|
|
90
|
+
Create a new run.
|
|
91
|
+
|
|
92
|
+
Parameters
|
|
93
|
+
----------
|
|
94
|
+
**kwargs : dict
|
|
95
|
+
Keyword arguments.
|
|
96
|
+
|
|
97
|
+
Returns
|
|
98
|
+
-------
|
|
99
|
+
Run
|
|
100
|
+
Run object.
|
|
101
|
+
"""
|
|
102
|
+
if kwargs["local_execution"]:
|
|
103
|
+
return run_from_parameters(**kwargs)
|
|
104
|
+
return new_run(**kwargs)
|
|
105
|
+
|
|
106
|
+
def get_run(self, entity_key: str) -> Run:
|
|
107
|
+
"""
|
|
108
|
+
Get run.
|
|
109
|
+
|
|
110
|
+
Parameters
|
|
111
|
+
----------
|
|
112
|
+
entity_key : str
|
|
113
|
+
Entity key.
|
|
114
|
+
|
|
115
|
+
Returns
|
|
116
|
+
-------
|
|
117
|
+
Run
|
|
118
|
+
Run object.
|
|
119
|
+
"""
|
|
120
|
+
return get_run(entity_key)
|
|
121
|
+
|
|
122
|
+
def delete_run(self, entity_key: str) -> None:
|
|
123
|
+
"""
|
|
124
|
+
Delete run.
|
|
125
|
+
|
|
126
|
+
Parameters
|
|
127
|
+
----------
|
|
128
|
+
entity_key : str
|
|
129
|
+
Entity key.
|
|
130
|
+
|
|
131
|
+
Returns
|
|
132
|
+
-------
|
|
133
|
+
None
|
|
134
|
+
"""
|
|
135
|
+
delete_run(entity_key)
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, Field
|
|
4
|
+
from typing_extensions import Literal
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Volume(BaseModel):
|
|
8
|
+
"""
|
|
9
|
+
Volume model.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
volume_type: Literal["persistent_volume_claim", "empty_dir"]
|
|
13
|
+
"""Volume type."""
|
|
14
|
+
|
|
15
|
+
name: str
|
|
16
|
+
"""Volume name."""
|
|
17
|
+
|
|
18
|
+
mount_path: str
|
|
19
|
+
"""Volume mount path inside the container."""
|
|
20
|
+
|
|
21
|
+
spec: dict[str, str]
|
|
22
|
+
"""Volume spec."""
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class NodeSelector(BaseModel):
|
|
26
|
+
"""
|
|
27
|
+
NodeSelector model.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
key: str
|
|
31
|
+
"""Node selector key."""
|
|
32
|
+
|
|
33
|
+
value: str
|
|
34
|
+
"""Node selector value."""
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class ResourceItem(BaseModel):
|
|
38
|
+
"""
|
|
39
|
+
Resource item model.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
requests: str = Field(default=None, regex=r"[\d]+|^([0-9])+([a-zA-Z])+$")
|
|
43
|
+
"""Resource requests."""
|
|
44
|
+
|
|
45
|
+
limits: str = Field(default=None, regex=r"[\d]+|^([0-9])+([a-zA-Z])+$")
|
|
46
|
+
"""Resource limits."""
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class Resource(BaseModel):
|
|
50
|
+
"""
|
|
51
|
+
Resource model.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
cpu: ResourceItem = None
|
|
55
|
+
"""CPU resource model."""
|
|
56
|
+
|
|
57
|
+
mem: ResourceItem = None
|
|
58
|
+
"""Memory resource model."""
|
|
59
|
+
|
|
60
|
+
gpu: ResourceItem = None
|
|
61
|
+
"""GPU resource model."""
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class Env(BaseModel):
|
|
65
|
+
"""
|
|
66
|
+
Env variable model.
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
name: str
|
|
70
|
+
"""Env variable name."""
|
|
71
|
+
|
|
72
|
+
value: str
|
|
73
|
+
"""Env variable value."""
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class Toleration(BaseModel):
|
|
77
|
+
"""
|
|
78
|
+
Toleration model.
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
key: str = None
|
|
82
|
+
"""Toleration key."""
|
|
83
|
+
|
|
84
|
+
operator: str = None
|
|
85
|
+
"""Toleration operator."""
|
|
86
|
+
|
|
87
|
+
value: str = None
|
|
88
|
+
"""Toleration value."""
|
|
89
|
+
|
|
90
|
+
effect: str = None
|
|
91
|
+
"""Toleration effect."""
|
|
92
|
+
|
|
93
|
+
toleration_seconds: int = None
|
|
94
|
+
"""Toleration seconds."""
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class V1NodeSelectorRequirement(BaseModel):
|
|
98
|
+
key: str
|
|
99
|
+
operator: str
|
|
100
|
+
values: list[str] = None
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class V1NodeSelectorTerm(BaseModel):
|
|
104
|
+
match_expressions: list[V1NodeSelectorRequirement] = None
|
|
105
|
+
match_fields: list[V1NodeSelectorRequirement] = None
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class V1NodeSelector(BaseModel):
|
|
109
|
+
node_selector_terms: list[V1NodeSelectorTerm]
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class V1PreferredSchedulingTerm(BaseModel):
|
|
113
|
+
preference: V1NodeSelector
|
|
114
|
+
weight: int
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class V1LabelSelectorRequirement(BaseModel):
|
|
118
|
+
key: str
|
|
119
|
+
operator: str
|
|
120
|
+
values: list[str] = None
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class V1LabelSelector(BaseModel):
|
|
124
|
+
match_expressions: list[V1LabelSelectorRequirement] = None
|
|
125
|
+
match_labels: dict[str, str] = None
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class V1PodAffinityTerm(BaseModel):
|
|
129
|
+
label_selector: V1LabelSelector = None
|
|
130
|
+
match_label_keys: list[str] = None
|
|
131
|
+
mismatch_label_keys: list[str] = None
|
|
132
|
+
namespace_selector: V1LabelSelector = None
|
|
133
|
+
namespaces: list[str] = None
|
|
134
|
+
topology_key: str
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class V1WeightedPodAffinityTerm(BaseModel):
|
|
138
|
+
pod_affinity_term: V1PodAffinityTerm
|
|
139
|
+
weight: int
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
class V1NodeAffinity(BaseModel):
|
|
143
|
+
preferred_during_scheduling_ignored_during_execution: list[V1PreferredSchedulingTerm] = None
|
|
144
|
+
required_during_scheduling_ignored_during_execution: V1NodeSelector = None
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
class V1PodAffinity(BaseModel):
|
|
148
|
+
preferred_during_scheduling_ignored_during_execution: list[V1WeightedPodAffinityTerm] = None
|
|
149
|
+
required_during_scheduling_ignored_during_execution: list[V1PodAffinityTerm] = None
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
class V1PodAntiAffinity(BaseModel):
|
|
153
|
+
preferred_during_scheduling_ignored_during_execution: list[V1WeightedPodAffinityTerm] = None
|
|
154
|
+
required_during_scheduling_ignored_during_execution: list[V1PodAffinityTerm] = None
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class Affinity(BaseModel):
|
|
158
|
+
"""
|
|
159
|
+
Affinity model.
|
|
160
|
+
"""
|
|
161
|
+
|
|
162
|
+
node_affinity: V1NodeAffinity = None
|
|
163
|
+
"""Node affinity."""
|
|
164
|
+
|
|
165
|
+
pod_affinity: V1PodAffinity = None
|
|
166
|
+
"""Pod affinity."""
|
|
167
|
+
|
|
168
|
+
pod_anti_affinity: V1PodAntiAffinity = None
|
|
169
|
+
"""Pod anti affinity."""
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
class K8s(BaseModel):
|
|
173
|
+
"""
|
|
174
|
+
Kubernetes resource model.
|
|
175
|
+
"""
|
|
176
|
+
|
|
177
|
+
node_selector: list[NodeSelector] = None
|
|
178
|
+
"""Node selector."""
|
|
179
|
+
|
|
180
|
+
volumes: list[Volume] = None
|
|
181
|
+
"""List of volumes."""
|
|
182
|
+
|
|
183
|
+
resources: Resource = None
|
|
184
|
+
"""Resources restrictions."""
|
|
185
|
+
|
|
186
|
+
affinity: Affinity = None
|
|
187
|
+
"""Affinity."""
|
|
188
|
+
|
|
189
|
+
tolerations: list[Toleration] = None
|
|
190
|
+
"""Tolerations."""
|
|
191
|
+
|
|
192
|
+
envs: list[Env] = None
|
|
193
|
+
"""Env variables."""
|
|
194
|
+
|
|
195
|
+
secrets: list[str] = None
|
|
196
|
+
"""List of secret names."""
|
|
197
|
+
|
|
198
|
+
profile: str = None
|
|
199
|
+
"""Profile template."""
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from digitalhub.entities._base.spec.base import Spec, SpecParams
|
|
4
|
+
from digitalhub.entities.task.models import K8s
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TaskSpec(Spec):
|
|
8
|
+
"""Task specification."""
|
|
9
|
+
|
|
10
|
+
def __init__(self, function: str) -> None:
|
|
11
|
+
self.function = function
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TaskSpecK8s(TaskSpec):
|
|
15
|
+
def __init__(
|
|
16
|
+
self,
|
|
17
|
+
function: str,
|
|
18
|
+
node_selector: dict | None = None,
|
|
19
|
+
volumes: list | None = None,
|
|
20
|
+
resources: dict | None = None,
|
|
21
|
+
affinity: dict | None = None,
|
|
22
|
+
tolerations: list | None = None,
|
|
23
|
+
envs: list | None = None,
|
|
24
|
+
secrets: list | None = None,
|
|
25
|
+
profile: str | None = None,
|
|
26
|
+
**kwargs,
|
|
27
|
+
) -> None:
|
|
28
|
+
super().__init__(function)
|
|
29
|
+
self.node_selector = node_selector
|
|
30
|
+
self.volumes = volumes
|
|
31
|
+
self.resources = resources
|
|
32
|
+
self.affinity = affinity
|
|
33
|
+
self.tolerations = tolerations
|
|
34
|
+
self.envs = envs
|
|
35
|
+
self.secrets = secrets
|
|
36
|
+
self.profile = profile
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class TaskParams(SpecParams):
|
|
40
|
+
"""
|
|
41
|
+
Base task model.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
function: str
|
|
45
|
+
"""Function string."""
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class TaskParamsK8s(TaskParams, K8s):
|
|
49
|
+
"""
|
|
50
|
+
Kubernetes task model.
|
|
51
|
+
"""
|