digitalhub 0.8.1__py3-none-any.whl → 0.9.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 +19 -2
- digitalhub/client/_base/api_builder.py +16 -0
- digitalhub/client/_base/client.py +67 -0
- digitalhub/client/_base/key_builder.py +52 -0
- digitalhub/client/api.py +2 -38
- digitalhub/client/dhcore/api_builder.py +100 -0
- digitalhub/client/dhcore/client.py +81 -25
- digitalhub/client/dhcore/enums.py +27 -0
- digitalhub/client/dhcore/env.py +2 -2
- digitalhub/client/dhcore/key_builder.py +58 -0
- digitalhub/client/dhcore/utils.py +17 -17
- digitalhub/client/local/api_builder.py +100 -0
- digitalhub/client/local/client.py +22 -0
- digitalhub/client/local/key_builder.py +58 -0
- digitalhub/context/api.py +3 -38
- digitalhub/context/builder.py +10 -23
- digitalhub/context/context.py +20 -92
- digitalhub/entities/_base/context/entity.py +30 -22
- digitalhub/entities/_base/entity/_constructors/metadata.py +12 -1
- digitalhub/entities/_base/entity/_constructors/name.py +1 -1
- digitalhub/entities/_base/entity/_constructors/spec.py +1 -1
- digitalhub/entities/_base/entity/_constructors/status.py +3 -2
- digitalhub/entities/_base/entity/builder.py +6 -1
- digitalhub/entities/_base/entity/entity.py +32 -10
- digitalhub/entities/_base/entity/metadata.py +22 -0
- digitalhub/entities/_base/entity/spec.py +7 -2
- digitalhub/entities/_base/executable/entity.py +8 -8
- digitalhub/entities/_base/material/entity.py +49 -17
- digitalhub/entities/_base/material/status.py +0 -31
- digitalhub/entities/_base/material/utils.py +106 -0
- digitalhub/entities/_base/project/entity.py +341 -0
- digitalhub/entities/_base/unversioned/entity.py +3 -24
- digitalhub/entities/_base/versioned/entity.py +2 -26
- digitalhub/entities/_commons/enums.py +103 -0
- digitalhub/entities/_commons/utils.py +83 -0
- digitalhub/entities/_operations/processor.py +1873 -0
- digitalhub/entities/artifact/_base/builder.py +1 -1
- digitalhub/entities/artifact/_base/entity.py +1 -1
- digitalhub/entities/artifact/artifact/builder.py +2 -1
- digitalhub/entities/artifact/crud.py +46 -29
- digitalhub/entities/artifact/utils.py +62 -0
- digitalhub/entities/dataitem/_base/builder.py +1 -1
- digitalhub/entities/dataitem/_base/entity.py +6 -6
- digitalhub/entities/dataitem/crud.py +50 -66
- digitalhub/entities/dataitem/dataitem/builder.py +2 -1
- digitalhub/entities/dataitem/iceberg/builder.py +2 -1
- digitalhub/entities/dataitem/table/builder.py +2 -1
- digitalhub/entities/dataitem/table/entity.py +5 -10
- digitalhub/entities/dataitem/table/models.py +4 -5
- digitalhub/entities/dataitem/utils.py +137 -0
- digitalhub/entities/function/_base/builder.py +1 -1
- digitalhub/entities/function/_base/entity.py +6 -2
- digitalhub/entities/function/crud.py +36 -17
- digitalhub/entities/model/_base/builder.py +1 -1
- digitalhub/entities/model/_base/entity.py +1 -1
- digitalhub/entities/model/crud.py +46 -29
- digitalhub/entities/model/huggingface/builder.py +2 -1
- digitalhub/entities/model/huggingface/spec.py +4 -2
- digitalhub/entities/model/mlflow/builder.py +2 -1
- digitalhub/entities/model/mlflow/models.py +17 -9
- digitalhub/entities/model/mlflow/spec.py +6 -1
- digitalhub/entities/model/mlflow/utils.py +4 -2
- digitalhub/entities/model/model/builder.py +2 -1
- digitalhub/entities/model/sklearn/builder.py +2 -1
- digitalhub/entities/model/utils.py +62 -0
- digitalhub/entities/project/_base/builder.py +2 -2
- digitalhub/entities/project/_base/entity.py +82 -272
- digitalhub/entities/project/crud.py +110 -91
- digitalhub/entities/project/utils.py +35 -0
- digitalhub/entities/run/_base/builder.py +3 -1
- digitalhub/entities/run/_base/entity.py +52 -54
- digitalhub/entities/run/_base/spec.py +15 -7
- digitalhub/entities/run/crud.py +35 -17
- digitalhub/entities/secret/_base/builder.py +2 -2
- digitalhub/entities/secret/_base/entity.py +4 -10
- digitalhub/entities/secret/crud.py +36 -21
- digitalhub/entities/task/_base/builder.py +14 -14
- digitalhub/entities/task/_base/entity.py +21 -14
- digitalhub/entities/task/_base/models.py +35 -6
- digitalhub/entities/task/_base/spec.py +50 -13
- digitalhub/entities/task/_base/utils.py +18 -0
- digitalhub/entities/task/crud.py +35 -15
- digitalhub/entities/workflow/_base/builder.py +1 -1
- digitalhub/entities/workflow/_base/entity.py +22 -6
- digitalhub/entities/workflow/crud.py +36 -17
- digitalhub/factory/utils.py +1 -1
- digitalhub/readers/_base/reader.py +2 -2
- digitalhub/readers/_commons/enums.py +13 -0
- digitalhub/readers/api.py +3 -2
- digitalhub/readers/factory.py +12 -6
- digitalhub/readers/pandas/reader.py +20 -8
- digitalhub/runtimes/_base.py +0 -7
- digitalhub/runtimes/enums.py +12 -0
- digitalhub/stores/_base/store.py +59 -11
- digitalhub/stores/builder.py +5 -5
- digitalhub/stores/local/store.py +43 -4
- digitalhub/stores/remote/store.py +31 -5
- digitalhub/stores/s3/store.py +129 -48
- digitalhub/stores/sql/store.py +122 -47
- digitalhub/utils/exceptions.py +6 -0
- digitalhub/utils/file_utils.py +60 -2
- digitalhub/utils/generic_utils.py +45 -4
- digitalhub/utils/io_utils.py +18 -0
- digitalhub/utils/s3_utils.py +17 -0
- digitalhub/utils/uri_utils.py +153 -15
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0.dist-info}/LICENSE.txt +1 -1
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0.dist-info}/METADATA +3 -3
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0.dist-info}/RECORD +116 -114
- test/local/instances/test_validate.py +55 -0
- test/testkfp.py +4 -1
- digitalhub/datastores/_base/datastore.py +0 -85
- digitalhub/datastores/api.py +0 -37
- digitalhub/datastores/builder.py +0 -110
- digitalhub/datastores/local/datastore.py +0 -50
- digitalhub/datastores/remote/__init__.py +0 -0
- digitalhub/datastores/remote/datastore.py +0 -31
- digitalhub/datastores/s3/__init__.py +0 -0
- digitalhub/datastores/s3/datastore.py +0 -46
- digitalhub/datastores/sql/__init__.py +0 -0
- digitalhub/datastores/sql/datastore.py +0 -68
- digitalhub/entities/_base/api_utils.py +0 -620
- digitalhub/entities/_base/crud.py +0 -468
- digitalhub/entities/function/_base/models.py +0 -118
- digitalhub/entities/utils/__init__.py +0 -0
- digitalhub/entities/utils/api.py +0 -346
- digitalhub/entities/utils/entity_types.py +0 -19
- digitalhub/entities/utils/state.py +0 -31
- digitalhub/entities/utils/utils.py +0 -202
- /digitalhub/{context → entities/_base/project}/__init__.py +0 -0
- /digitalhub/{datastores → entities/_commons}/__init__.py +0 -0
- /digitalhub/{datastores/_base → entities/_operations}/__init__.py +0 -0
- /digitalhub/{datastores/local → readers/_commons}/__init__.py +0 -0
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0.dist-info}/WHEEL +0 -0
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0.dist-info}/top_level.txt +0 -0
digitalhub/entities/run/crud.py
CHANGED
|
@@ -2,14 +2,8 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
|
-
from digitalhub.entities.
|
|
6
|
-
|
|
7
|
-
get_unversioned_entity,
|
|
8
|
-
import_context_entity,
|
|
9
|
-
list_context_entities,
|
|
10
|
-
new_context_entity,
|
|
11
|
-
)
|
|
12
|
-
from digitalhub.entities.utils.entity_types import EntityTypes
|
|
5
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
6
|
+
from digitalhub.entities._operations.processor import processor
|
|
13
7
|
from digitalhub.utils.exceptions import EntityError
|
|
14
8
|
|
|
15
9
|
if typing.TYPE_CHECKING:
|
|
@@ -59,7 +53,7 @@ def new_run(
|
|
|
59
53
|
>>> kind="python+run",
|
|
60
54
|
>>> task="task-string")
|
|
61
55
|
"""
|
|
62
|
-
return
|
|
56
|
+
return processor.create_context_entity(
|
|
63
57
|
project=project,
|
|
64
58
|
kind=kind,
|
|
65
59
|
uuid=uuid,
|
|
@@ -101,7 +95,7 @@ def get_run(
|
|
|
101
95
|
>>> obj = get_run("my-run-id"
|
|
102
96
|
>>> project="my-project")
|
|
103
97
|
"""
|
|
104
|
-
return
|
|
98
|
+
return processor.read_unversioned_entity(
|
|
105
99
|
identifier,
|
|
106
100
|
entity_type=ENTITY_TYPE,
|
|
107
101
|
project=project,
|
|
@@ -130,7 +124,7 @@ def list_runs(project: str, **kwargs) -> list[Run]:
|
|
|
130
124
|
>>> objs = list_runs(project="my-project")
|
|
131
125
|
"""
|
|
132
126
|
# TODO more examples: search by function, latest for task and function
|
|
133
|
-
return list_context_entities(
|
|
127
|
+
return processor.list_context_entities(
|
|
134
128
|
project=project,
|
|
135
129
|
entity_type=ENTITY_TYPE,
|
|
136
130
|
**kwargs,
|
|
@@ -139,7 +133,7 @@ def list_runs(project: str, **kwargs) -> list[Run]:
|
|
|
139
133
|
|
|
140
134
|
def import_run(file: str) -> Run:
|
|
141
135
|
"""
|
|
142
|
-
|
|
136
|
+
Import object from a YAML file and create a new object into the backend.
|
|
143
137
|
|
|
144
138
|
Parameters
|
|
145
139
|
----------
|
|
@@ -155,7 +149,28 @@ def import_run(file: str) -> Run:
|
|
|
155
149
|
-------
|
|
156
150
|
>>> obj = import_run("my-run.yaml")
|
|
157
151
|
"""
|
|
158
|
-
return import_context_entity(file)
|
|
152
|
+
return processor.import_context_entity(file)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def load_run(file: str) -> Run:
|
|
156
|
+
"""
|
|
157
|
+
Load object from a YAML file and update an existing object into the backend.
|
|
158
|
+
|
|
159
|
+
Parameters
|
|
160
|
+
----------
|
|
161
|
+
file : str
|
|
162
|
+
Path to YAML file.
|
|
163
|
+
|
|
164
|
+
Returns
|
|
165
|
+
-------
|
|
166
|
+
Run
|
|
167
|
+
Object instance.
|
|
168
|
+
|
|
169
|
+
Examples
|
|
170
|
+
--------
|
|
171
|
+
>>> obj = load_run("my-run.yaml")
|
|
172
|
+
"""
|
|
173
|
+
return processor.load_context_entity(file)
|
|
159
174
|
|
|
160
175
|
|
|
161
176
|
def update_run(entity: Run) -> Run:
|
|
@@ -176,7 +191,12 @@ def update_run(entity: Run) -> Run:
|
|
|
176
191
|
--------
|
|
177
192
|
>>> obj = update_run(obj)
|
|
178
193
|
"""
|
|
179
|
-
return
|
|
194
|
+
return processor.update_context_entity(
|
|
195
|
+
project=entity.project,
|
|
196
|
+
entity_type=entity.ENTITY_TYPE,
|
|
197
|
+
entity_id=entity.id,
|
|
198
|
+
entity_dict=entity.to_dict(),
|
|
199
|
+
)
|
|
180
200
|
|
|
181
201
|
|
|
182
202
|
def delete_run(
|
|
@@ -208,12 +228,10 @@ def delete_run(
|
|
|
208
228
|
"""
|
|
209
229
|
if not identifier.startswith("store://") and project is None:
|
|
210
230
|
raise EntityError("Specify entity key or entity ID combined with project")
|
|
211
|
-
return
|
|
231
|
+
return processor.delete_context_entity(
|
|
212
232
|
identifier=identifier,
|
|
213
233
|
entity_type=ENTITY_TYPE,
|
|
214
234
|
project=project,
|
|
215
235
|
entity_id=identifier,
|
|
216
236
|
**kwargs,
|
|
217
237
|
)
|
|
218
|
-
|
|
219
|
-
# TODO read logs
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from digitalhub.entities._base.versioned.builder import VersionedBuilder
|
|
4
|
+
from digitalhub.entities._commons.enums import EntityKinds, EntityTypes
|
|
4
5
|
from digitalhub.entities.secret._base.entity import Secret
|
|
5
6
|
from digitalhub.entities.secret._base.spec import SecretSpec, SecretValidator
|
|
6
7
|
from digitalhub.entities.secret._base.status import SecretStatus
|
|
7
|
-
from digitalhub.entities.utils.entity_types import EntityTypes
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class SecretSecretBuilder(VersionedBuilder):
|
|
@@ -17,7 +17,7 @@ class SecretSecretBuilder(VersionedBuilder):
|
|
|
17
17
|
ENTITY_SPEC_CLASS = SecretSpec
|
|
18
18
|
ENTITY_SPEC_VALIDATOR = SecretValidator
|
|
19
19
|
ENTITY_STATUS_CLASS = SecretStatus
|
|
20
|
-
ENTITY_KIND =
|
|
20
|
+
ENTITY_KIND = EntityKinds.SECRET_SECRET.value
|
|
21
21
|
|
|
22
22
|
def build(
|
|
23
23
|
self,
|
|
@@ -2,9 +2,9 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
|
-
from digitalhub.entities._base.api_utils import get_data_api, set_data_api
|
|
6
5
|
from digitalhub.entities._base.versioned.entity import VersionedEntity
|
|
7
|
-
from digitalhub.entities.
|
|
6
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
7
|
+
from digitalhub.entities._operations.processor import processor
|
|
8
8
|
|
|
9
9
|
if typing.TYPE_CHECKING:
|
|
10
10
|
from digitalhub.entities._base.entity.metadata import Metadata
|
|
@@ -51,11 +51,8 @@ class Secret(VersionedEntity):
|
|
|
51
51
|
-------
|
|
52
52
|
None
|
|
53
53
|
"""
|
|
54
|
-
if self._context().local:
|
|
55
|
-
raise NotImplementedError("set_secret() is not implemented for local projects.")
|
|
56
|
-
|
|
57
54
|
obj = {self.name: value}
|
|
58
|
-
|
|
55
|
+
processor.update_secret_data(self.project, self.ENTITY_TYPE, obj)
|
|
59
56
|
|
|
60
57
|
def read_secret_value(self) -> dict:
|
|
61
58
|
"""
|
|
@@ -66,9 +63,6 @@ class Secret(VersionedEntity):
|
|
|
66
63
|
str
|
|
67
64
|
Value of the secret.
|
|
68
65
|
"""
|
|
69
|
-
if self._context().local:
|
|
70
|
-
raise NotImplementedError("read_secret() is not implemented for local projects.")
|
|
71
|
-
|
|
72
66
|
params = {"keys": self.name}
|
|
73
|
-
data =
|
|
67
|
+
data = processor.read_secret_data(self.project, self.ENTITY_TYPE, params=params)
|
|
74
68
|
return data[self.name]
|
|
@@ -2,16 +2,8 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
|
-
from digitalhub.
|
|
6
|
-
from digitalhub.entities.
|
|
7
|
-
delete_entity,
|
|
8
|
-
get_context_entity_versions,
|
|
9
|
-
get_versioned_entity,
|
|
10
|
-
import_context_entity,
|
|
11
|
-
list_context_entities,
|
|
12
|
-
new_context_entity,
|
|
13
|
-
)
|
|
14
|
-
from digitalhub.entities.utils.entity_types import EntityTypes
|
|
5
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
6
|
+
from digitalhub.entities._operations.processor import processor
|
|
15
7
|
from digitalhub.utils.exceptions import EntityNotExistsError
|
|
16
8
|
|
|
17
9
|
if typing.TYPE_CHECKING:
|
|
@@ -64,11 +56,9 @@ def new_secret(
|
|
|
64
56
|
>>> name="my-secret",
|
|
65
57
|
>>> secret_value="my-secret-value")
|
|
66
58
|
"""
|
|
67
|
-
check_context(project)
|
|
68
|
-
|
|
69
59
|
if secret_value is None:
|
|
70
60
|
raise ValueError("secret_value must be provided.")
|
|
71
|
-
obj: Secret =
|
|
61
|
+
obj: Secret = processor.create_context_entity(
|
|
72
62
|
project=project,
|
|
73
63
|
name=name,
|
|
74
64
|
kind="secret",
|
|
@@ -124,8 +114,7 @@ def get_secret(
|
|
|
124
114
|
return secret
|
|
125
115
|
else:
|
|
126
116
|
raise EntityNotExistsError(f"Secret {identifier} not found.")
|
|
127
|
-
|
|
128
|
-
return get_versioned_entity(
|
|
117
|
+
return processor.read_context_entity(
|
|
129
118
|
identifier,
|
|
130
119
|
entity_type=ENTITY_TYPE,
|
|
131
120
|
project=project,
|
|
@@ -165,7 +154,7 @@ def get_secret_versions(
|
|
|
165
154
|
>>> objs = get_secret_versions("my-secret-name",
|
|
166
155
|
>>> project="my-project")
|
|
167
156
|
"""
|
|
168
|
-
return
|
|
157
|
+
return processor.read_context_entity_versions(
|
|
169
158
|
identifier,
|
|
170
159
|
entity_type=ENTITY_TYPE,
|
|
171
160
|
project=project,
|
|
@@ -193,7 +182,7 @@ def list_secrets(project: str, **kwargs) -> list[Secret]:
|
|
|
193
182
|
--------
|
|
194
183
|
>>> objs = list_secrets(project="my-project")
|
|
195
184
|
"""
|
|
196
|
-
return list_context_entities(
|
|
185
|
+
return processor.list_context_entities(
|
|
197
186
|
project=project,
|
|
198
187
|
entity_type=ENTITY_TYPE,
|
|
199
188
|
**kwargs,
|
|
@@ -202,7 +191,7 @@ def list_secrets(project: str, **kwargs) -> list[Secret]:
|
|
|
202
191
|
|
|
203
192
|
def import_secret(file: str) -> Secret:
|
|
204
193
|
"""
|
|
205
|
-
Import object from a YAML file.
|
|
194
|
+
Import object from a YAML file and create a new object into the backend.
|
|
206
195
|
|
|
207
196
|
Parameters
|
|
208
197
|
----------
|
|
@@ -218,7 +207,28 @@ def import_secret(file: str) -> Secret:
|
|
|
218
207
|
--------
|
|
219
208
|
>>> obj = import_secret("my-secret.yaml")
|
|
220
209
|
"""
|
|
221
|
-
return import_context_entity(file)
|
|
210
|
+
return processor.import_context_entity(file)
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def load_secret(file: str) -> Secret:
|
|
214
|
+
"""
|
|
215
|
+
Load object from a YAML file and update an existing object into the backend.
|
|
216
|
+
|
|
217
|
+
Parameters
|
|
218
|
+
----------
|
|
219
|
+
file : str
|
|
220
|
+
Path to YAML file.
|
|
221
|
+
|
|
222
|
+
Returns
|
|
223
|
+
-------
|
|
224
|
+
Secret
|
|
225
|
+
Object instance.
|
|
226
|
+
|
|
227
|
+
Examples
|
|
228
|
+
--------
|
|
229
|
+
>>> obj = load_secret("my-secret.yaml")
|
|
230
|
+
"""
|
|
231
|
+
return processor.load_context_entity(file)
|
|
222
232
|
|
|
223
233
|
|
|
224
234
|
def update_secret(entity: Secret) -> Secret:
|
|
@@ -239,7 +249,12 @@ def update_secret(entity: Secret) -> Secret:
|
|
|
239
249
|
--------
|
|
240
250
|
>>> obj = update_secret(obj)
|
|
241
251
|
"""
|
|
242
|
-
return
|
|
252
|
+
return processor.update_context_entity(
|
|
253
|
+
project=entity.project,
|
|
254
|
+
entity_type=entity.ENTITY_TYPE,
|
|
255
|
+
entity_id=entity.id,
|
|
256
|
+
entity_dict=entity.to_dict(),
|
|
257
|
+
)
|
|
243
258
|
|
|
244
259
|
|
|
245
260
|
def delete_secret(
|
|
@@ -280,7 +295,7 @@ def delete_secret(
|
|
|
280
295
|
>>> project="my-project",
|
|
281
296
|
>>> delete_all_versions=True)
|
|
282
297
|
"""
|
|
283
|
-
return
|
|
298
|
+
return processor.delete_context_entity(
|
|
284
299
|
identifier=identifier,
|
|
285
300
|
entity_type=ENTITY_TYPE,
|
|
286
301
|
project=project,
|
|
@@ -4,7 +4,7 @@ import typing
|
|
|
4
4
|
|
|
5
5
|
from digitalhub.entities._base.runtime_entity.builder import EntityError, RuntimeEntityBuilder
|
|
6
6
|
from digitalhub.entities._base.unversioned.builder import UnversionedBuilder
|
|
7
|
-
from digitalhub.entities.
|
|
7
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
8
8
|
|
|
9
9
|
if typing.TYPE_CHECKING:
|
|
10
10
|
from digitalhub.entities.task._base.entity import Task
|
|
@@ -23,7 +23,6 @@ class TaskBuilder(UnversionedBuilder, RuntimeEntityBuilder):
|
|
|
23
23
|
kind: str,
|
|
24
24
|
uuid: str | None = None,
|
|
25
25
|
labels: list[str] | None = None,
|
|
26
|
-
function: str | None = None,
|
|
27
26
|
**kwargs,
|
|
28
27
|
) -> Task:
|
|
29
28
|
"""
|
|
@@ -39,8 +38,6 @@ class TaskBuilder(UnversionedBuilder, RuntimeEntityBuilder):
|
|
|
39
38
|
ID of the object.
|
|
40
39
|
labels : list[str]
|
|
41
40
|
List of labels.
|
|
42
|
-
function : str
|
|
43
|
-
Name of the executable associated with the task.
|
|
44
41
|
**kwargs : dict
|
|
45
42
|
Spec keyword arguments.
|
|
46
43
|
|
|
@@ -49,10 +46,14 @@ class TaskBuilder(UnversionedBuilder, RuntimeEntityBuilder):
|
|
|
49
46
|
Task
|
|
50
47
|
Object instance.
|
|
51
48
|
"""
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
# Check executable kind validity
|
|
50
|
+
fnc = kwargs.get("function", None)
|
|
51
|
+
wkf = kwargs.get("workflow", None)
|
|
52
|
+
executable = fnc if fnc is not None else wkf
|
|
53
|
+
if executable is None:
|
|
54
|
+
raise EntityError("Function or workflow must be provided")
|
|
55
|
+
self._check_kind_validity(executable)
|
|
54
56
|
|
|
55
|
-
self._check_kind_validity(function)
|
|
56
57
|
uuid = self.build_uuid(uuid)
|
|
57
58
|
metadata = self.build_metadata(
|
|
58
59
|
project=project,
|
|
@@ -60,7 +61,6 @@ class TaskBuilder(UnversionedBuilder, RuntimeEntityBuilder):
|
|
|
60
61
|
labels=labels,
|
|
61
62
|
)
|
|
62
63
|
spec = self.build_spec(
|
|
63
|
-
function=function,
|
|
64
64
|
**kwargs,
|
|
65
65
|
)
|
|
66
66
|
status = self.build_status()
|
|
@@ -73,19 +73,19 @@ class TaskBuilder(UnversionedBuilder, RuntimeEntityBuilder):
|
|
|
73
73
|
status=status,
|
|
74
74
|
)
|
|
75
75
|
|
|
76
|
-
def _check_kind_validity(self,
|
|
76
|
+
def _check_kind_validity(self, executable: str) -> None:
|
|
77
77
|
"""
|
|
78
78
|
Check kind validity.
|
|
79
79
|
|
|
80
80
|
Parameters
|
|
81
81
|
----------
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
executable : str
|
|
83
|
+
Executable string.
|
|
84
84
|
|
|
85
85
|
Returns
|
|
86
86
|
-------
|
|
87
87
|
None
|
|
88
88
|
"""
|
|
89
|
-
|
|
90
|
-
if self.EXECUTABLE_KIND !=
|
|
91
|
-
raise EntityError(f"Invalid task '{self.ENTITY_KIND}' for
|
|
89
|
+
exec_kind = executable.split("://")[0]
|
|
90
|
+
if self.EXECUTABLE_KIND != exec_kind:
|
|
91
|
+
raise EntityError(f"Invalid task '{self.ENTITY_KIND}' for executable kind '{exec_kind}'")
|
|
@@ -3,9 +3,9 @@ from __future__ import annotations
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
5
|
from digitalhub.entities._base.unversioned.entity import UnversionedEntity
|
|
6
|
-
from digitalhub.entities.
|
|
7
|
-
from digitalhub.entities.
|
|
8
|
-
from digitalhub.factory.api import build_entity_from_params
|
|
6
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
7
|
+
from digitalhub.entities._operations.processor import processor
|
|
8
|
+
from digitalhub.factory.api import build_entity_from_params, get_entity_type_from_kind, get_executable_kind
|
|
9
9
|
|
|
10
10
|
if typing.TYPE_CHECKING:
|
|
11
11
|
from digitalhub.entities._base.entity.metadata import Metadata
|
|
@@ -42,6 +42,7 @@ class Task(UnversionedEntity):
|
|
|
42
42
|
def run(
|
|
43
43
|
self,
|
|
44
44
|
run_kind: str,
|
|
45
|
+
save: bool = True,
|
|
45
46
|
local_execution: bool = False,
|
|
46
47
|
**kwargs,
|
|
47
48
|
) -> Run:
|
|
@@ -62,7 +63,11 @@ class Task(UnversionedEntity):
|
|
|
62
63
|
Run
|
|
63
64
|
Run object.
|
|
64
65
|
"""
|
|
66
|
+
exec_kind = get_executable_kind(self.kind)
|
|
67
|
+
exec_type = get_entity_type_from_kind(exec_kind)
|
|
68
|
+
kwargs[exec_type] = getattr(self.spec, exec_type)
|
|
65
69
|
return self.new_run(
|
|
70
|
+
save=save,
|
|
66
71
|
project=self.project,
|
|
67
72
|
task=self._get_task_string(),
|
|
68
73
|
kind=run_kind,
|
|
@@ -79,30 +84,31 @@ class Task(UnversionedEntity):
|
|
|
79
84
|
str
|
|
80
85
|
Task string.
|
|
81
86
|
"""
|
|
82
|
-
|
|
83
|
-
return f"{self.kind}://{splitted[1]}"
|
|
87
|
+
return f"{self.kind}://{self.project}/{self.id}"
|
|
84
88
|
|
|
85
89
|
##############################
|
|
86
90
|
# CRUD Methods for Run
|
|
87
91
|
##############################
|
|
88
92
|
|
|
89
|
-
def new_run(self, **kwargs) -> Run:
|
|
93
|
+
def new_run(self, save: bool = True, **kwargs) -> Run:
|
|
90
94
|
"""
|
|
91
95
|
Create a new run.
|
|
92
96
|
|
|
93
97
|
Parameters
|
|
94
98
|
----------
|
|
99
|
+
save : bool
|
|
100
|
+
Flag to indicate save.
|
|
95
101
|
**kwargs : dict
|
|
96
|
-
Keyword arguments.
|
|
102
|
+
Keyword arguments to build run. See new_run().
|
|
97
103
|
|
|
98
104
|
Returns
|
|
99
105
|
-------
|
|
100
106
|
Run
|
|
101
107
|
Run object.
|
|
102
108
|
"""
|
|
103
|
-
if
|
|
104
|
-
return
|
|
105
|
-
return
|
|
109
|
+
if save:
|
|
110
|
+
return processor.create_context_entity(**kwargs)
|
|
111
|
+
return build_entity_from_params(**kwargs)
|
|
106
112
|
|
|
107
113
|
def get_run(self, entity_key: str) -> Run:
|
|
108
114
|
"""
|
|
@@ -118,9 +124,9 @@ class Task(UnversionedEntity):
|
|
|
118
124
|
Run
|
|
119
125
|
Run object.
|
|
120
126
|
"""
|
|
121
|
-
return
|
|
127
|
+
return processor.read_context_entity(entity_key)
|
|
122
128
|
|
|
123
|
-
def delete_run(self, entity_key: str) ->
|
|
129
|
+
def delete_run(self, entity_key: str) -> dict:
|
|
124
130
|
"""
|
|
125
131
|
Delete run.
|
|
126
132
|
|
|
@@ -131,6 +137,7 @@ class Task(UnversionedEntity):
|
|
|
131
137
|
|
|
132
138
|
Returns
|
|
133
139
|
-------
|
|
134
|
-
|
|
140
|
+
dict
|
|
141
|
+
Response from backend.
|
|
135
142
|
"""
|
|
136
|
-
|
|
143
|
+
return processor.delete_context_entity(entity_key)
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from
|
|
4
|
-
|
|
3
|
+
from enum import Enum
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class VolumeType(Enum):
|
|
9
|
+
"""
|
|
10
|
+
Volume type.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
PERSISTENT_VOLUME_CLAIM = "persistent_volume_claim"
|
|
14
|
+
EMPTY_DIR = "empty_dir"
|
|
5
15
|
|
|
6
16
|
|
|
7
17
|
class Volume(BaseModel):
|
|
@@ -9,7 +19,9 @@ class Volume(BaseModel):
|
|
|
9
19
|
Volume model.
|
|
10
20
|
"""
|
|
11
21
|
|
|
12
|
-
|
|
22
|
+
model_config = ConfigDict(use_enum_values=True)
|
|
23
|
+
|
|
24
|
+
volume_type: VolumeType
|
|
13
25
|
"""Volume type."""
|
|
14
26
|
|
|
15
27
|
name: str
|
|
@@ -18,7 +30,7 @@ class Volume(BaseModel):
|
|
|
18
30
|
mount_path: str
|
|
19
31
|
"""Volume mount path inside the container."""
|
|
20
32
|
|
|
21
|
-
spec: dict[str, str]
|
|
33
|
+
spec: dict[str, str] = None
|
|
22
34
|
"""Volume spec."""
|
|
23
35
|
|
|
24
36
|
|
|
@@ -39,10 +51,10 @@ class ResourceItem(BaseModel):
|
|
|
39
51
|
Resource item model.
|
|
40
52
|
"""
|
|
41
53
|
|
|
42
|
-
requests: str = Field(default=None,
|
|
54
|
+
requests: str = Field(default=None, pattern=r"[\d]+|^([0-9])+([a-zA-Z])+$")
|
|
43
55
|
"""Resource requests."""
|
|
44
56
|
|
|
45
|
-
limits: str = Field(default=None,
|
|
57
|
+
limits: str = Field(default=None, pattern=r"[\d]+|^([0-9])+([a-zA-Z])+$")
|
|
46
58
|
"""Resource limits."""
|
|
47
59
|
|
|
48
60
|
|
|
@@ -198,6 +210,12 @@ class K8s(BaseModel):
|
|
|
198
210
|
profile: str = None
|
|
199
211
|
"""Profile template."""
|
|
200
212
|
|
|
213
|
+
runtime_class: str = None
|
|
214
|
+
"""Runtime class name."""
|
|
215
|
+
|
|
216
|
+
priority_class: str = None
|
|
217
|
+
"""Priority class."""
|
|
218
|
+
|
|
201
219
|
|
|
202
220
|
class CorePort(BaseModel):
|
|
203
221
|
"""
|
|
@@ -206,3 +224,14 @@ class CorePort(BaseModel):
|
|
|
206
224
|
|
|
207
225
|
port: int
|
|
208
226
|
target_port: int
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
class CoreServiceType(Enum):
|
|
230
|
+
"""
|
|
231
|
+
CoreServiceType enum.
|
|
232
|
+
"""
|
|
233
|
+
|
|
234
|
+
EXTERNAL_NAME = "ExternalName"
|
|
235
|
+
CLUSTER_IP = "ClusterIP"
|
|
236
|
+
NODE_PORT = "NodePort"
|
|
237
|
+
LOAD_BALANCER = "LoadBalancer"
|
|
@@ -7,27 +7,57 @@ from digitalhub.entities.task._base.models import K8s
|
|
|
7
7
|
class TaskSpec(Spec):
|
|
8
8
|
"""TaskSpec specifications."""
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
class TaskSpecFunction(TaskSpec):
|
|
12
|
+
"""TaskSpecFunction specifications."""
|
|
13
|
+
|
|
14
|
+
def __init__(
|
|
15
|
+
self,
|
|
16
|
+
function: str,
|
|
17
|
+
node_selector: list[dict] | None = None,
|
|
18
|
+
volumes: list[dict] | None = None,
|
|
19
|
+
resources: dict | None = None,
|
|
20
|
+
affinity: dict | None = None,
|
|
21
|
+
tolerations: list[dict] | None = None,
|
|
22
|
+
envs: list[dict] | None = None,
|
|
23
|
+
secrets: list[str] | None = None,
|
|
24
|
+
profile: str | None = None,
|
|
25
|
+
runtime_class: str | None = None,
|
|
26
|
+
priority_class: str | None = None,
|
|
27
|
+
**kwargs,
|
|
28
|
+
) -> None:
|
|
11
29
|
self.function = function
|
|
30
|
+
self.node_selector = node_selector
|
|
31
|
+
self.volumes = volumes
|
|
32
|
+
self.resources = resources
|
|
33
|
+
self.affinity = affinity
|
|
34
|
+
self.tolerations = tolerations
|
|
35
|
+
self.envs = envs
|
|
36
|
+
self.secrets = secrets
|
|
37
|
+
self.profile = profile
|
|
38
|
+
self.runtime_class = runtime_class
|
|
39
|
+
self.priority_class = priority_class
|
|
12
40
|
|
|
13
41
|
|
|
14
|
-
class
|
|
15
|
-
"""
|
|
42
|
+
class TaskSpecWorkflow(TaskSpec):
|
|
43
|
+
"""TaskSpecWorkflow specifications."""
|
|
16
44
|
|
|
17
45
|
def __init__(
|
|
18
46
|
self,
|
|
19
|
-
|
|
20
|
-
node_selector: dict | None = None,
|
|
21
|
-
volumes: list | None = None,
|
|
47
|
+
workflow: str,
|
|
48
|
+
node_selector: list[dict] | None = None,
|
|
49
|
+
volumes: list[dict] | None = None,
|
|
22
50
|
resources: dict | None = None,
|
|
23
51
|
affinity: dict | None = None,
|
|
24
|
-
tolerations: list | None = None,
|
|
25
|
-
envs: list | None = None,
|
|
26
|
-
secrets: list | None = None,
|
|
52
|
+
tolerations: list[dict] | None = None,
|
|
53
|
+
envs: list[dict] | None = None,
|
|
54
|
+
secrets: list[str] | None = None,
|
|
27
55
|
profile: str | None = None,
|
|
56
|
+
runtime_class: str | None = None,
|
|
57
|
+
priority_class: str | None = None,
|
|
28
58
|
**kwargs,
|
|
29
59
|
) -> None:
|
|
30
|
-
|
|
60
|
+
self.workflow = workflow
|
|
31
61
|
self.node_selector = node_selector
|
|
32
62
|
self.volumes = volumes
|
|
33
63
|
self.resources = resources
|
|
@@ -43,11 +73,18 @@ class TaskValidator(SpecValidator):
|
|
|
43
73
|
TaskValidator validator.
|
|
44
74
|
"""
|
|
45
75
|
|
|
76
|
+
|
|
77
|
+
class TaskValidatorFunction(TaskValidator, K8s):
|
|
78
|
+
"""
|
|
79
|
+
TaskValidatorFunction validator.
|
|
80
|
+
"""
|
|
81
|
+
|
|
46
82
|
function: str
|
|
47
|
-
"""Function string."""
|
|
48
83
|
|
|
49
84
|
|
|
50
|
-
class
|
|
85
|
+
class TaskValidatorWorkflow(TaskValidator, K8s):
|
|
51
86
|
"""
|
|
52
|
-
|
|
87
|
+
TaskValidatorWorkflow validator.
|
|
53
88
|
"""
|
|
89
|
+
|
|
90
|
+
workflow: str
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def build_task_actions(kind_action_list: list[tuple[str, str]]) -> dict[str, str]:
|
|
5
|
+
"""
|
|
6
|
+
Build task actions.
|
|
7
|
+
|
|
8
|
+
Parameters
|
|
9
|
+
----------
|
|
10
|
+
kind_action_list : list[tuple[str, str]]
|
|
11
|
+
List of kind-action couples.
|
|
12
|
+
|
|
13
|
+
Returns
|
|
14
|
+
-------
|
|
15
|
+
dict[str, str]
|
|
16
|
+
Returns the task actions.
|
|
17
|
+
"""
|
|
18
|
+
return [{"kind": kind, "action": action} for (kind, action) in kind_action_list]
|