digitalhub 0.8.1__py3-none-any.whl → 0.9.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 +19 -2
- digitalhub/client/_base/api_builder.py +16 -0
- digitalhub/client/_base/client.py +31 -0
- digitalhub/client/api.py +2 -38
- digitalhub/client/dhcore/api_builder.py +100 -0
- digitalhub/client/dhcore/client.py +77 -24
- digitalhub/client/dhcore/enums.py +26 -0
- digitalhub/client/dhcore/env.py +2 -2
- digitalhub/client/dhcore/utils.py +17 -17
- digitalhub/client/local/api_builder.py +100 -0
- digitalhub/client/local/client.py +20 -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 +30 -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 +48 -16
- 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 +1 -23
- digitalhub/entities/_base/versioned/entity.py +0 -25
- digitalhub/entities/_commons/enums.py +103 -0
- digitalhub/entities/_commons/utils.py +83 -0
- digitalhub/entities/_operations/processor.py +1747 -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 +5 -1
- 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 +11 -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 +6 -6
- digitalhub/entities/task/_base/models.py +29 -6
- digitalhub/entities/task/_base/spec.py +44 -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 +14 -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/stores/_base/store.py +53 -9
- digitalhub/stores/builder.py +5 -5
- digitalhub/stores/local/store.py +37 -2
- digitalhub/stores/remote/store.py +25 -3
- digitalhub/stores/s3/store.py +34 -7
- digitalhub/stores/sql/store.py +112 -45
- 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/uri_utils.py +153 -15
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0b0.dist-info}/METADATA +2 -2
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0b0.dist-info}/RECORD +110 -113
- 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.0b0.dist-info}/LICENSE.txt +0 -0
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0b0.dist-info}/WHEEL +0 -0
- {digitalhub-0.8.1.dist-info → digitalhub-0.9.0b0.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._commons.enums import EntityTypes
|
|
6
7
|
from digitalhub.entities.run.crud import delete_run, get_run, new_run
|
|
7
|
-
from digitalhub.
|
|
8
|
-
from digitalhub.factory.api import build_entity_from_params
|
|
8
|
+
from digitalhub.factory.api import 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
|
|
@@ -62,6 +62,9 @@ class Task(UnversionedEntity):
|
|
|
62
62
|
Run
|
|
63
63
|
Run object.
|
|
64
64
|
"""
|
|
65
|
+
exec_kind = get_executable_kind(self.kind)
|
|
66
|
+
exec_type = get_entity_type_from_kind(exec_kind)
|
|
67
|
+
kwargs[exec_type] = getattr(self.spec, exec_type)
|
|
65
68
|
return self.new_run(
|
|
66
69
|
project=self.project,
|
|
67
70
|
task=self._get_task_string(),
|
|
@@ -79,8 +82,7 @@ class Task(UnversionedEntity):
|
|
|
79
82
|
str
|
|
80
83
|
Task string.
|
|
81
84
|
"""
|
|
82
|
-
|
|
83
|
-
return f"{self.kind}://{splitted[1]}"
|
|
85
|
+
return f"{self.kind}://{self.project}/{self.id}"
|
|
84
86
|
|
|
85
87
|
##############################
|
|
86
88
|
# CRUD Methods for Run
|
|
@@ -100,8 +102,6 @@ class Task(UnversionedEntity):
|
|
|
100
102
|
Run
|
|
101
103
|
Run object.
|
|
102
104
|
"""
|
|
103
|
-
if kwargs["local_execution"]:
|
|
104
|
-
return build_entity_from_params(**kwargs)
|
|
105
105
|
return new_run(**kwargs)
|
|
106
106
|
|
|
107
107
|
def get_run(self, entity_key: str) -> Run:
|
|
@@ -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
|
|
|
@@ -206,3 +218,14 @@ class CorePort(BaseModel):
|
|
|
206
218
|
|
|
207
219
|
port: int
|
|
208
220
|
target_port: int
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
class CoreServiceType(Enum):
|
|
224
|
+
"""
|
|
225
|
+
CoreServiceType enum.
|
|
226
|
+
"""
|
|
227
|
+
|
|
228
|
+
EXTERNAL_NAME = "ExternalName"
|
|
229
|
+
CLUSTER_IP = "ClusterIP"
|
|
230
|
+
NODE_PORT = "NodePort"
|
|
231
|
+
LOAD_BALANCER = "LoadBalancer"
|
|
@@ -7,27 +7,51 @@ 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
|
+
**kwargs,
|
|
26
|
+
) -> None:
|
|
11
27
|
self.function = function
|
|
28
|
+
self.node_selector = node_selector
|
|
29
|
+
self.volumes = volumes
|
|
30
|
+
self.resources = resources
|
|
31
|
+
self.affinity = affinity
|
|
32
|
+
self.tolerations = tolerations
|
|
33
|
+
self.envs = envs
|
|
34
|
+
self.secrets = secrets
|
|
35
|
+
self.profile = profile
|
|
12
36
|
|
|
13
37
|
|
|
14
|
-
class
|
|
15
|
-
"""
|
|
38
|
+
class TaskSpecWorkflow(TaskSpec):
|
|
39
|
+
"""TaskSpecWorkflow specifications."""
|
|
16
40
|
|
|
17
41
|
def __init__(
|
|
18
42
|
self,
|
|
19
|
-
|
|
20
|
-
node_selector: dict | None = None,
|
|
21
|
-
volumes: list | None = None,
|
|
43
|
+
workflow: str,
|
|
44
|
+
node_selector: list[dict] | None = None,
|
|
45
|
+
volumes: list[dict] | None = None,
|
|
22
46
|
resources: dict | None = None,
|
|
23
47
|
affinity: dict | None = None,
|
|
24
|
-
tolerations: list | None = None,
|
|
25
|
-
envs: list | None = None,
|
|
26
|
-
secrets: list | None = None,
|
|
48
|
+
tolerations: list[dict] | None = None,
|
|
49
|
+
envs: list[dict] | None = None,
|
|
50
|
+
secrets: list[str] | None = None,
|
|
27
51
|
profile: str | None = None,
|
|
28
52
|
**kwargs,
|
|
29
53
|
) -> None:
|
|
30
|
-
|
|
54
|
+
self.workflow = workflow
|
|
31
55
|
self.node_selector = node_selector
|
|
32
56
|
self.volumes = volumes
|
|
33
57
|
self.resources = resources
|
|
@@ -43,11 +67,18 @@ class TaskValidator(SpecValidator):
|
|
|
43
67
|
TaskValidator validator.
|
|
44
68
|
"""
|
|
45
69
|
|
|
70
|
+
|
|
71
|
+
class TaskValidatorFunction(TaskValidator, K8s):
|
|
72
|
+
"""
|
|
73
|
+
TaskValidatorFunction validator.
|
|
74
|
+
"""
|
|
75
|
+
|
|
46
76
|
function: str
|
|
47
|
-
"""Function string."""
|
|
48
77
|
|
|
49
78
|
|
|
50
|
-
class
|
|
79
|
+
class TaskValidatorWorkflow(TaskValidator, K8s):
|
|
51
80
|
"""
|
|
52
|
-
|
|
81
|
+
TaskValidatorWorkflow validator.
|
|
53
82
|
"""
|
|
83
|
+
|
|
84
|
+
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]
|
digitalhub/entities/task/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:
|
|
@@ -56,7 +50,7 @@ def new_task(
|
|
|
56
50
|
>>> kind="python+job",
|
|
57
51
|
>>> function="function-string")
|
|
58
52
|
"""
|
|
59
|
-
return
|
|
53
|
+
return processor.create_context_entity(
|
|
60
54
|
project=project,
|
|
61
55
|
kind=kind,
|
|
62
56
|
uuid=uuid,
|
|
@@ -97,7 +91,7 @@ def get_task(
|
|
|
97
91
|
>>> obj = get_task("my-task-id"
|
|
98
92
|
>>> project="my-project")
|
|
99
93
|
"""
|
|
100
|
-
return
|
|
94
|
+
return processor.read_unversioned_entity(
|
|
101
95
|
identifier,
|
|
102
96
|
entity_type=ENTITY_TYPE,
|
|
103
97
|
project=project,
|
|
@@ -125,7 +119,7 @@ def list_tasks(project: str, **kwargs) -> list[Task]:
|
|
|
125
119
|
--------
|
|
126
120
|
>>> objs = list_tasks(project="my-project")
|
|
127
121
|
"""
|
|
128
|
-
return list_context_entities(
|
|
122
|
+
return processor.list_context_entities(
|
|
129
123
|
project=project,
|
|
130
124
|
entity_type=ENTITY_TYPE,
|
|
131
125
|
**kwargs,
|
|
@@ -134,7 +128,7 @@ def list_tasks(project: str, **kwargs) -> list[Task]:
|
|
|
134
128
|
|
|
135
129
|
def import_task(file: str) -> Task:
|
|
136
130
|
"""
|
|
137
|
-
|
|
131
|
+
Import object from a YAML file and create a new object into the backend.
|
|
138
132
|
|
|
139
133
|
Parameters
|
|
140
134
|
----------
|
|
@@ -150,7 +144,28 @@ def import_task(file: str) -> Task:
|
|
|
150
144
|
-------
|
|
151
145
|
>>> obj = import_task("my-task.yaml")
|
|
152
146
|
"""
|
|
153
|
-
return import_context_entity(file)
|
|
147
|
+
return processor.import_context_entity(file)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def load_task(file: str) -> Task:
|
|
151
|
+
"""
|
|
152
|
+
Load object from a YAML file and update an existing object into the backend.
|
|
153
|
+
|
|
154
|
+
Parameters
|
|
155
|
+
----------
|
|
156
|
+
file : str
|
|
157
|
+
Path to YAML file.
|
|
158
|
+
|
|
159
|
+
Returns
|
|
160
|
+
-------
|
|
161
|
+
Task
|
|
162
|
+
Object instance.
|
|
163
|
+
|
|
164
|
+
Examples
|
|
165
|
+
--------
|
|
166
|
+
>>> obj = load_task("my-task.yaml")
|
|
167
|
+
"""
|
|
168
|
+
return processor.load_context_entity(file)
|
|
154
169
|
|
|
155
170
|
|
|
156
171
|
def update_task(entity: Task) -> Task:
|
|
@@ -171,7 +186,12 @@ def update_task(entity: Task) -> Task:
|
|
|
171
186
|
--------
|
|
172
187
|
>>> obj = update_task(obj)
|
|
173
188
|
"""
|
|
174
|
-
return
|
|
189
|
+
return processor.update_context_entity(
|
|
190
|
+
project=entity.project,
|
|
191
|
+
entity_type=entity.ENTITY_TYPE,
|
|
192
|
+
entity_id=entity.id,
|
|
193
|
+
entity_dict=entity.to_dict(),
|
|
194
|
+
)
|
|
175
195
|
|
|
176
196
|
|
|
177
197
|
def delete_task(
|
|
@@ -217,7 +237,7 @@ def delete_task(
|
|
|
217
237
|
"""
|
|
218
238
|
if not identifier.startswith("store://"):
|
|
219
239
|
raise EntityError("Task has no name. Use key instead.")
|
|
220
|
-
return
|
|
240
|
+
return processor.delete_context_entity(
|
|
221
241
|
identifier=identifier,
|
|
222
242
|
entity_type=ENTITY_TYPE,
|
|
223
243
|
project=project,
|
|
@@ -4,7 +4,7 @@ import typing
|
|
|
4
4
|
|
|
5
5
|
from digitalhub.entities._base.runtime_entity.builder import RuntimeEntityBuilder
|
|
6
6
|
from digitalhub.entities._base.versioned.builder import VersionedBuilder
|
|
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.workflow._base.entity import Workflow
|