digitalhub 0.13.3__py3-none-any.whl → 0.14.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 +3 -8
- digitalhub/context/api.py +1 -5
- digitalhub/context/builder.py +1 -5
- digitalhub/context/context.py +15 -9
- digitalhub/entities/_base/_base/entity.py +0 -15
- digitalhub/entities/_base/context/entity.py +1 -1
- digitalhub/entities/_base/entity/builder.py +5 -5
- digitalhub/entities/_base/entity/entity.py +0 -8
- digitalhub/entities/_base/executable/entity.py +169 -79
- digitalhub/entities/_base/material/entity.py +6 -22
- digitalhub/entities/_base/material/utils.py +1 -4
- digitalhub/entities/_base/runtime_entity/builder.py +53 -18
- digitalhub/entities/_base/unversioned/entity.py +1 -1
- digitalhub/entities/_base/versioned/entity.py +1 -1
- digitalhub/entities/_commons/enums.py +1 -31
- digitalhub/entities/_commons/utils.py +83 -21
- digitalhub/entities/_constructors/_resources.py +151 -0
- digitalhub/entities/{_base/entity/_constructors → _constructors}/name.py +18 -0
- digitalhub/entities/_processors/base/__init__.py +3 -0
- digitalhub/entities/_processors/{base.py → base/crud.py} +14 -226
- digitalhub/entities/_processors/base/import_export.py +123 -0
- digitalhub/entities/_processors/base/processor.py +302 -0
- digitalhub/entities/_processors/base/special_ops.py +108 -0
- digitalhub/entities/_processors/context/__init__.py +3 -0
- digitalhub/entities/_processors/context/crud.py +652 -0
- digitalhub/entities/_processors/context/import_export.py +242 -0
- digitalhub/entities/_processors/context/material.py +123 -0
- digitalhub/entities/_processors/context/processor.py +400 -0
- digitalhub/entities/_processors/context/special_ops.py +476 -0
- digitalhub/entities/_processors/processors.py +12 -0
- digitalhub/entities/_processors/utils.py +12 -11
- digitalhub/entities/artifact/crud.py +58 -22
- digitalhub/entities/artifact/utils.py +3 -3
- digitalhub/entities/dataitem/crud.py +63 -20
- digitalhub/entities/dataitem/table/entity.py +24 -22
- digitalhub/entities/dataitem/utils.py +15 -15
- digitalhub/entities/function/_base/entity.py +3 -3
- digitalhub/entities/function/crud.py +55 -24
- digitalhub/entities/model/_base/entity.py +62 -20
- digitalhub/entities/model/crud.py +58 -22
- digitalhub/entities/model/utils.py +3 -3
- digitalhub/entities/project/_base/entity.py +321 -152
- digitalhub/entities/project/crud.py +15 -23
- digitalhub/entities/run/_base/builder.py +0 -4
- digitalhub/entities/run/_base/entity.py +70 -63
- digitalhub/entities/run/crud.py +79 -26
- digitalhub/entities/secret/_base/entity.py +1 -5
- digitalhub/entities/secret/crud.py +29 -26
- digitalhub/entities/task/_base/builder.py +0 -4
- digitalhub/entities/task/_base/entity.py +5 -5
- digitalhub/entities/task/_base/models.py +13 -16
- digitalhub/entities/task/crud.py +61 -29
- digitalhub/entities/trigger/_base/entity.py +1 -5
- digitalhub/entities/trigger/crud.py +64 -24
- digitalhub/entities/workflow/_base/entity.py +3 -3
- digitalhub/entities/workflow/crud.py +55 -21
- digitalhub/factory/entity.py +283 -0
- digitalhub/factory/enums.py +18 -0
- digitalhub/factory/registry.py +197 -0
- digitalhub/factory/runtime.py +44 -0
- digitalhub/factory/utils.py +3 -54
- digitalhub/runtimes/_base.py +2 -2
- digitalhub/stores/client/_base/enums.py +39 -0
- digitalhub/stores/client/_base/key_builder.py +2 -2
- digitalhub/stores/client/_base/params_builder.py +48 -0
- digitalhub/stores/client/api.py +6 -10
- digitalhub/stores/client/builder.py +4 -4
- digitalhub/stores/client/dhcore/api_builder.py +2 -1
- digitalhub/stores/client/dhcore/client.py +85 -429
- digitalhub/stores/client/dhcore/configurator.py +109 -328
- digitalhub/stores/client/dhcore/enums.py +0 -16
- digitalhub/stores/client/dhcore/error_parser.py +0 -4
- digitalhub/stores/client/dhcore/header_manager.py +61 -0
- digitalhub/stores/client/dhcore/http_handler.py +133 -0
- digitalhub/stores/client/dhcore/params_builder.py +147 -134
- digitalhub/stores/client/dhcore/response_processor.py +102 -0
- digitalhub/stores/client/dhcore/utils.py +6 -72
- digitalhub/stores/client/local/api_builder.py +1 -1
- digitalhub/stores/client/local/client.py +79 -47
- digitalhub/stores/client/local/params_builder.py +18 -41
- digitalhub/stores/credentials/api.py +0 -4
- digitalhub/stores/credentials/configurator.py +2 -28
- digitalhub/stores/credentials/enums.py +3 -0
- digitalhub/stores/credentials/handler.py +0 -12
- digitalhub/stores/credentials/ini_module.py +0 -22
- digitalhub/stores/credentials/store.py +0 -4
- digitalhub/stores/data/_base/store.py +0 -16
- digitalhub/stores/data/builder.py +1 -5
- digitalhub/stores/data/local/store.py +0 -103
- digitalhub/stores/data/remote/store.py +0 -4
- digitalhub/stores/data/s3/configurator.py +60 -14
- digitalhub/stores/data/s3/store.py +49 -16
- digitalhub/stores/data/sql/configurator.py +0 -8
- digitalhub/stores/data/sql/store.py +21 -10
- digitalhub/stores/readers/data/factory.py +0 -8
- digitalhub/stores/readers/data/pandas/reader.py +0 -16
- digitalhub/utils/file_utils.py +0 -17
- digitalhub/utils/generic_utils.py +0 -12
- digitalhub/utils/git_utils.py +0 -8
- digitalhub/utils/io_utils.py +0 -12
- digitalhub/utils/store_utils.py +44 -0
- {digitalhub-0.13.3.dist-info → digitalhub-0.14.0.dist-info}/METADATA +3 -2
- {digitalhub-0.13.3.dist-info → digitalhub-0.14.0.dist-info}/RECORD +111 -95
- digitalhub/entities/_processors/context.py +0 -1450
- digitalhub/entities/task/_base/utils.py +0 -22
- digitalhub/factory/factory.py +0 -381
- digitalhub/stores/client/dhcore/models.py +0 -40
- digitalhub/stores/data/s3/utils.py +0 -78
- /digitalhub/entities/{_base/entity/_constructors → _constructors}/__init__.py +0 -0
- /digitalhub/entities/{_base/entity/_constructors → _constructors}/metadata.py +0 -0
- /digitalhub/entities/{_base/entity/_constructors → _constructors}/spec.py +0 -0
- /digitalhub/entities/{_base/entity/_constructors → _constructors}/status.py +0 -0
- /digitalhub/entities/{_base/entity/_constructors → _constructors}/uuid.py +0 -0
- {digitalhub-0.13.3.dist-info → digitalhub-0.14.0.dist-info}/WHEEL +0 -0
- {digitalhub-0.13.3.dist-info → digitalhub-0.14.0.dist-info}/licenses/AUTHORS +0 -0
- {digitalhub-0.13.3.dist-info → digitalhub-0.14.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import typing
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from digitalhub.entities._processors.utils import get_context_from_project
|
|
11
|
+
from digitalhub.stores.client._base.enums import ApiCategories, BackendOperations
|
|
12
|
+
|
|
13
|
+
if typing.TYPE_CHECKING:
|
|
14
|
+
from digitalhub.entities._base.context.entity import ContextEntity
|
|
15
|
+
from digitalhub.entities._processors.context.crud import ContextEntityCRUDProcessor
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ContextEntitySpecialOpsProcessor:
|
|
19
|
+
"""
|
|
20
|
+
Processor for specialized context entity operations.
|
|
21
|
+
|
|
22
|
+
Handles backend operations like secrets management, logging,
|
|
23
|
+
entity control (start/stop/resume), file operations, and metrics.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def build_context_entity_key(
|
|
27
|
+
self,
|
|
28
|
+
project: str,
|
|
29
|
+
entity_type: str,
|
|
30
|
+
entity_kind: str,
|
|
31
|
+
entity_name: str,
|
|
32
|
+
entity_id: str | None = None,
|
|
33
|
+
) -> str:
|
|
34
|
+
"""
|
|
35
|
+
Build a storage key for a context entity.
|
|
36
|
+
|
|
37
|
+
Creates a standardized key string for context entity identification
|
|
38
|
+
and storage, resolving the project context automatically.
|
|
39
|
+
|
|
40
|
+
Parameters
|
|
41
|
+
----------
|
|
42
|
+
project : str
|
|
43
|
+
The project name containing the entity.
|
|
44
|
+
entity_type : str
|
|
45
|
+
The type of entity.
|
|
46
|
+
entity_kind : str
|
|
47
|
+
The kind/subtype of entity.
|
|
48
|
+
entity_name : str
|
|
49
|
+
The name of the entity.
|
|
50
|
+
entity_id : str
|
|
51
|
+
The unique identifier of the entity version.
|
|
52
|
+
|
|
53
|
+
Returns
|
|
54
|
+
-------
|
|
55
|
+
str
|
|
56
|
+
The constructed context entity key string.
|
|
57
|
+
"""
|
|
58
|
+
context = get_context_from_project(project)
|
|
59
|
+
return context.client.build_key(
|
|
60
|
+
ApiCategories.CONTEXT.value,
|
|
61
|
+
project=context.name,
|
|
62
|
+
entity_type=entity_type,
|
|
63
|
+
entity_kind=entity_kind,
|
|
64
|
+
entity_name=entity_name,
|
|
65
|
+
entity_id=entity_id,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
def read_secret_data(
|
|
69
|
+
self,
|
|
70
|
+
project: str,
|
|
71
|
+
entity_type: str,
|
|
72
|
+
**kwargs,
|
|
73
|
+
) -> dict:
|
|
74
|
+
"""
|
|
75
|
+
Read secret data from the backend.
|
|
76
|
+
|
|
77
|
+
Retrieves secret data stored in the backend for a specific
|
|
78
|
+
project and entity type.
|
|
79
|
+
|
|
80
|
+
Parameters
|
|
81
|
+
----------
|
|
82
|
+
project : str
|
|
83
|
+
The project name containing the secrets.
|
|
84
|
+
entity_type : str
|
|
85
|
+
The type of entity (typically 'secret').
|
|
86
|
+
**kwargs : dict
|
|
87
|
+
Additional parameters to pass to the API call.
|
|
88
|
+
|
|
89
|
+
Returns
|
|
90
|
+
-------
|
|
91
|
+
dict
|
|
92
|
+
Secret data retrieved from the backend.
|
|
93
|
+
"""
|
|
94
|
+
context = get_context_from_project(project)
|
|
95
|
+
api = context.client.build_api(
|
|
96
|
+
ApiCategories.CONTEXT.value,
|
|
97
|
+
BackendOperations.DATA.value,
|
|
98
|
+
project=context.name,
|
|
99
|
+
entity_type=entity_type,
|
|
100
|
+
)
|
|
101
|
+
return context.client.read_object(api, **kwargs)
|
|
102
|
+
|
|
103
|
+
def update_secret_data(
|
|
104
|
+
self,
|
|
105
|
+
project: str,
|
|
106
|
+
entity_type: str,
|
|
107
|
+
data: dict,
|
|
108
|
+
**kwargs,
|
|
109
|
+
) -> None:
|
|
110
|
+
"""
|
|
111
|
+
Update secret data in the backend.
|
|
112
|
+
|
|
113
|
+
Stores or updates secret data in the backend for a specific
|
|
114
|
+
project and entity type.
|
|
115
|
+
|
|
116
|
+
Parameters
|
|
117
|
+
----------
|
|
118
|
+
project : str
|
|
119
|
+
The project name to store secrets in.
|
|
120
|
+
entity_type : str
|
|
121
|
+
The type of entity (typically 'secret').
|
|
122
|
+
data : dict
|
|
123
|
+
The secret data dictionary to store.
|
|
124
|
+
**kwargs : dict
|
|
125
|
+
Additional parameters to pass to the API call.
|
|
126
|
+
"""
|
|
127
|
+
context = get_context_from_project(project)
|
|
128
|
+
api = context.client.build_api(
|
|
129
|
+
ApiCategories.CONTEXT.value,
|
|
130
|
+
BackendOperations.DATA.value,
|
|
131
|
+
project=context.name,
|
|
132
|
+
entity_type=entity_type,
|
|
133
|
+
)
|
|
134
|
+
context.client.update_object(api, data, **kwargs)
|
|
135
|
+
|
|
136
|
+
def read_run_logs(
|
|
137
|
+
self,
|
|
138
|
+
project: str,
|
|
139
|
+
entity_type: str,
|
|
140
|
+
entity_id: str,
|
|
141
|
+
**kwargs,
|
|
142
|
+
) -> dict:
|
|
143
|
+
"""
|
|
144
|
+
Read execution logs from the backend.
|
|
145
|
+
|
|
146
|
+
Retrieves logs for a specific run or task execution from
|
|
147
|
+
the backend.
|
|
148
|
+
|
|
149
|
+
Parameters
|
|
150
|
+
----------
|
|
151
|
+
project : str
|
|
152
|
+
The project name containing the entity.
|
|
153
|
+
entity_type : str
|
|
154
|
+
The type of entity (typically 'run' or 'task').
|
|
155
|
+
entity_id : str
|
|
156
|
+
The unique identifier of the entity to get logs for.
|
|
157
|
+
**kwargs : dict
|
|
158
|
+
Additional parameters to pass to the API call.
|
|
159
|
+
|
|
160
|
+
Returns
|
|
161
|
+
-------
|
|
162
|
+
dict
|
|
163
|
+
Log data retrieved from the backend.
|
|
164
|
+
"""
|
|
165
|
+
context = get_context_from_project(project)
|
|
166
|
+
api = context.client.build_api(
|
|
167
|
+
ApiCategories.CONTEXT.value,
|
|
168
|
+
BackendOperations.LOGS.value,
|
|
169
|
+
project=context.name,
|
|
170
|
+
entity_type=entity_type,
|
|
171
|
+
entity_id=entity_id,
|
|
172
|
+
)
|
|
173
|
+
return context.client.read_object(api, **kwargs)
|
|
174
|
+
|
|
175
|
+
def stop_entity(
|
|
176
|
+
self,
|
|
177
|
+
project: str,
|
|
178
|
+
entity_type: str,
|
|
179
|
+
entity_id: str,
|
|
180
|
+
**kwargs,
|
|
181
|
+
) -> None:
|
|
182
|
+
"""
|
|
183
|
+
Stop a running entity in the backend.
|
|
184
|
+
|
|
185
|
+
Sends a stop signal to halt execution of a running entity
|
|
186
|
+
such as a workflow or long-running task.
|
|
187
|
+
|
|
188
|
+
Parameters
|
|
189
|
+
----------
|
|
190
|
+
project : str
|
|
191
|
+
The project name containing the entity.
|
|
192
|
+
entity_type : str
|
|
193
|
+
The type of entity to stop.
|
|
194
|
+
entity_id : str
|
|
195
|
+
The unique identifier of the entity to stop.
|
|
196
|
+
**kwargs : dict
|
|
197
|
+
Additional parameters to pass to the API call.
|
|
198
|
+
"""
|
|
199
|
+
context = get_context_from_project(project)
|
|
200
|
+
api = context.client.build_api(
|
|
201
|
+
ApiCategories.CONTEXT.value,
|
|
202
|
+
BackendOperations.STOP.value,
|
|
203
|
+
project=context.name,
|
|
204
|
+
entity_type=entity_type,
|
|
205
|
+
entity_id=entity_id,
|
|
206
|
+
)
|
|
207
|
+
context.client.create_object(api, **kwargs)
|
|
208
|
+
|
|
209
|
+
def resume_entity(
|
|
210
|
+
self,
|
|
211
|
+
project: str,
|
|
212
|
+
entity_type: str,
|
|
213
|
+
entity_id: str,
|
|
214
|
+
**kwargs,
|
|
215
|
+
) -> None:
|
|
216
|
+
"""
|
|
217
|
+
Resume a stopped entity in the backend.
|
|
218
|
+
|
|
219
|
+
Sends a resume signal to restart execution of a previously
|
|
220
|
+
stopped entity such as a workflow or task.
|
|
221
|
+
|
|
222
|
+
Parameters
|
|
223
|
+
----------
|
|
224
|
+
project : str
|
|
225
|
+
The project name containing the entity.
|
|
226
|
+
entity_type : str
|
|
227
|
+
The type of entity to resume.
|
|
228
|
+
entity_id : str
|
|
229
|
+
The unique identifier of the entity to resume.
|
|
230
|
+
**kwargs : dict
|
|
231
|
+
Additional parameters to pass to the API call.
|
|
232
|
+
"""
|
|
233
|
+
context = get_context_from_project(project)
|
|
234
|
+
api = context.client.build_api(
|
|
235
|
+
ApiCategories.CONTEXT.value,
|
|
236
|
+
BackendOperations.RESUME.value,
|
|
237
|
+
project=context.name,
|
|
238
|
+
entity_type=entity_type,
|
|
239
|
+
entity_id=entity_id,
|
|
240
|
+
)
|
|
241
|
+
context.client.create_object(api, **kwargs)
|
|
242
|
+
|
|
243
|
+
def read_files_info(
|
|
244
|
+
self,
|
|
245
|
+
project: str,
|
|
246
|
+
entity_type: str,
|
|
247
|
+
entity_id: str,
|
|
248
|
+
**kwargs,
|
|
249
|
+
) -> list[dict]:
|
|
250
|
+
"""
|
|
251
|
+
Read file information from the backend.
|
|
252
|
+
|
|
253
|
+
Retrieves metadata about files associated with an entity,
|
|
254
|
+
including file paths, sizes, and other attributes.
|
|
255
|
+
|
|
256
|
+
Parameters
|
|
257
|
+
----------
|
|
258
|
+
project : str
|
|
259
|
+
The project name containing the entity.
|
|
260
|
+
entity_type : str
|
|
261
|
+
The type of entity to get file info for.
|
|
262
|
+
entity_id : str
|
|
263
|
+
The unique identifier of the entity.
|
|
264
|
+
**kwargs : dict
|
|
265
|
+
Additional parameters to pass to the API call.
|
|
266
|
+
|
|
267
|
+
Returns
|
|
268
|
+
-------
|
|
269
|
+
list[dict]
|
|
270
|
+
List of file information dictionaries from the backend.
|
|
271
|
+
"""
|
|
272
|
+
context = get_context_from_project(project)
|
|
273
|
+
api = context.client.build_api(
|
|
274
|
+
ApiCategories.CONTEXT.value,
|
|
275
|
+
BackendOperations.FILES.value,
|
|
276
|
+
project=context.name,
|
|
277
|
+
entity_type=entity_type,
|
|
278
|
+
entity_id=entity_id,
|
|
279
|
+
)
|
|
280
|
+
return context.client.read_object(api, **kwargs)
|
|
281
|
+
|
|
282
|
+
def update_files_info(
|
|
283
|
+
self,
|
|
284
|
+
project: str,
|
|
285
|
+
entity_type: str,
|
|
286
|
+
entity_id: str,
|
|
287
|
+
entity_list: list[dict],
|
|
288
|
+
**kwargs,
|
|
289
|
+
) -> None:
|
|
290
|
+
"""
|
|
291
|
+
Get files info from backend.
|
|
292
|
+
|
|
293
|
+
Parameters
|
|
294
|
+
----------
|
|
295
|
+
project : str
|
|
296
|
+
Project name.
|
|
297
|
+
entity_type : str
|
|
298
|
+
Entity type.
|
|
299
|
+
entity_id : str
|
|
300
|
+
Entity ID.
|
|
301
|
+
entity_list : list[dict]
|
|
302
|
+
Entity list.
|
|
303
|
+
**kwargs : dict
|
|
304
|
+
Parameters to pass to the API call.
|
|
305
|
+
"""
|
|
306
|
+
context = get_context_from_project(project)
|
|
307
|
+
api = context.client.build_api(
|
|
308
|
+
ApiCategories.CONTEXT.value,
|
|
309
|
+
BackendOperations.FILES.value,
|
|
310
|
+
project=context.name,
|
|
311
|
+
entity_type=entity_type,
|
|
312
|
+
entity_id=entity_id,
|
|
313
|
+
)
|
|
314
|
+
return context.client.update_object(api, entity_list, **kwargs)
|
|
315
|
+
|
|
316
|
+
def read_metrics(
|
|
317
|
+
self,
|
|
318
|
+
project: str,
|
|
319
|
+
entity_type: str,
|
|
320
|
+
entity_id: str,
|
|
321
|
+
metric_name: str | None = None,
|
|
322
|
+
**kwargs,
|
|
323
|
+
) -> dict:
|
|
324
|
+
"""
|
|
325
|
+
Read metrics from the backend for a specific entity.
|
|
326
|
+
|
|
327
|
+
Retrieves metrics data associated with an entity. Can fetch either
|
|
328
|
+
all metrics or a specific metric by name. Used for performance
|
|
329
|
+
monitoring and analysis of entity operations.
|
|
330
|
+
|
|
331
|
+
Parameters
|
|
332
|
+
----------
|
|
333
|
+
project : str
|
|
334
|
+
The project name containing the entity.
|
|
335
|
+
entity_type : str
|
|
336
|
+
The type of entity to read metrics from.
|
|
337
|
+
entity_id : str
|
|
338
|
+
The unique identifier of the entity.
|
|
339
|
+
metric_name : str
|
|
340
|
+
The name of a specific metric to retrieve.
|
|
341
|
+
If None, retrieves all available metrics.
|
|
342
|
+
**kwargs : dict
|
|
343
|
+
Additional parameters to pass to the API call.
|
|
344
|
+
|
|
345
|
+
Returns
|
|
346
|
+
-------
|
|
347
|
+
dict
|
|
348
|
+
Dictionary containing metric data from the backend.
|
|
349
|
+
"""
|
|
350
|
+
context = get_context_from_project(project)
|
|
351
|
+
api = context.client.build_api(
|
|
352
|
+
ApiCategories.CONTEXT.value,
|
|
353
|
+
BackendOperations.METRICS.value,
|
|
354
|
+
project=context.name,
|
|
355
|
+
entity_type=entity_type,
|
|
356
|
+
entity_id=entity_id,
|
|
357
|
+
metric_name=metric_name,
|
|
358
|
+
)
|
|
359
|
+
return context.client.read_object(api, **kwargs)
|
|
360
|
+
|
|
361
|
+
def update_metric(
|
|
362
|
+
self,
|
|
363
|
+
project: str,
|
|
364
|
+
entity_type: str,
|
|
365
|
+
entity_id: str,
|
|
366
|
+
metric_name: str,
|
|
367
|
+
metric_value: Any,
|
|
368
|
+
**kwargs,
|
|
369
|
+
) -> None:
|
|
370
|
+
"""
|
|
371
|
+
Update or create a metric value for an entity in the backend.
|
|
372
|
+
|
|
373
|
+
Updates an existing metric or creates a new one with the specified
|
|
374
|
+
value. Metrics are used for tracking performance, status, and
|
|
375
|
+
other quantitative aspects of entity operations.
|
|
376
|
+
|
|
377
|
+
Parameters
|
|
378
|
+
----------
|
|
379
|
+
project : str
|
|
380
|
+
The project name containing the entity.
|
|
381
|
+
entity_type : str
|
|
382
|
+
The type of entity to update metrics for.
|
|
383
|
+
entity_id : str
|
|
384
|
+
The unique identifier of the entity.
|
|
385
|
+
metric_name : str
|
|
386
|
+
The name of the metric to update or create.
|
|
387
|
+
metric_value : Any
|
|
388
|
+
The value to set for the metric.
|
|
389
|
+
Can be numeric, string, or other supported types.
|
|
390
|
+
**kwargs : dict
|
|
391
|
+
Additional parameters to pass to the API call.
|
|
392
|
+
"""
|
|
393
|
+
context = get_context_from_project(project)
|
|
394
|
+
api = context.client.build_api(
|
|
395
|
+
ApiCategories.CONTEXT.value,
|
|
396
|
+
BackendOperations.METRICS.value,
|
|
397
|
+
project=context.name,
|
|
398
|
+
entity_type=entity_type,
|
|
399
|
+
entity_id=entity_id,
|
|
400
|
+
metric_name=metric_name,
|
|
401
|
+
)
|
|
402
|
+
context.client.update_object(api, metric_value, **kwargs)
|
|
403
|
+
|
|
404
|
+
def search_entity(
|
|
405
|
+
self,
|
|
406
|
+
crud_processor: ContextEntityCRUDProcessor,
|
|
407
|
+
project: str,
|
|
408
|
+
query: str | None = None,
|
|
409
|
+
entity_types: list[str] | None = None,
|
|
410
|
+
name: str | None = None,
|
|
411
|
+
kind: str | None = None,
|
|
412
|
+
created: str | None = None,
|
|
413
|
+
updated: str | None = None,
|
|
414
|
+
description: str | None = None,
|
|
415
|
+
labels: list[str] | None = None,
|
|
416
|
+
**kwargs,
|
|
417
|
+
) -> list[ContextEntity]:
|
|
418
|
+
"""
|
|
419
|
+
Search for entities in the backend using various criteria.
|
|
420
|
+
|
|
421
|
+
Performs a flexible search across multiple entity attributes,
|
|
422
|
+
allowing for complex queries and filtering. Returns matching
|
|
423
|
+
entities from the project context.
|
|
424
|
+
|
|
425
|
+
Parameters
|
|
426
|
+
----------
|
|
427
|
+
crud_processor : ContextEntityCRUDProcessor
|
|
428
|
+
The CRUD processor instance for entity operations.
|
|
429
|
+
project : str
|
|
430
|
+
The project name to search within.
|
|
431
|
+
query : str
|
|
432
|
+
Free-text search query to match against entity content.
|
|
433
|
+
entity_types : list[str]
|
|
434
|
+
List of entity types to filter by.
|
|
435
|
+
If None, searches all entity types.
|
|
436
|
+
name : str
|
|
437
|
+
Entity name pattern to match.
|
|
438
|
+
kind : str
|
|
439
|
+
Entity kind to filter by.
|
|
440
|
+
created : str
|
|
441
|
+
Creation date filter (ISO format).
|
|
442
|
+
updated : str
|
|
443
|
+
Last update date filter (ISO format).
|
|
444
|
+
description : str
|
|
445
|
+
Description pattern to match.
|
|
446
|
+
labels : list[str]
|
|
447
|
+
List of label patterns to match.
|
|
448
|
+
**kwargs : dict
|
|
449
|
+
Additional search parameters to pass to the API call.
|
|
450
|
+
|
|
451
|
+
Returns
|
|
452
|
+
-------
|
|
453
|
+
list[ContextEntity]
|
|
454
|
+
List of matching entity instances from the search.
|
|
455
|
+
"""
|
|
456
|
+
context = get_context_from_project(project)
|
|
457
|
+
kwargs = context.client.build_parameters(
|
|
458
|
+
ApiCategories.CONTEXT.value,
|
|
459
|
+
BackendOperations.SEARCH.value,
|
|
460
|
+
query=query,
|
|
461
|
+
entity_types=entity_types,
|
|
462
|
+
name=name,
|
|
463
|
+
kind=kind,
|
|
464
|
+
created=created,
|
|
465
|
+
updated=updated,
|
|
466
|
+
description=description,
|
|
467
|
+
labels=labels,
|
|
468
|
+
**kwargs,
|
|
469
|
+
)
|
|
470
|
+
api = context.client.build_api(
|
|
471
|
+
ApiCategories.CONTEXT.value,
|
|
472
|
+
BackendOperations.SEARCH.value,
|
|
473
|
+
project=context.name,
|
|
474
|
+
)
|
|
475
|
+
entities_dict = context.client.read_object(api, **kwargs)
|
|
476
|
+
return [crud_processor.read_context_entity(entity["key"]) for entity in entities_dict["content"]]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from digitalhub.entities._processors.base.processor import BaseEntityOperationsProcessor
|
|
6
|
+
from digitalhub.entities._processors.context.processor import ContextEntityOperationsProcessor
|
|
7
|
+
|
|
8
|
+
# Base processor singleton instance
|
|
9
|
+
base_processor = BaseEntityOperationsProcessor()
|
|
10
|
+
|
|
11
|
+
# Context processor singleton instance
|
|
12
|
+
context_processor = ContextEntityOperationsProcessor()
|
|
@@ -7,9 +7,10 @@ from __future__ import annotations
|
|
|
7
7
|
import typing
|
|
8
8
|
|
|
9
9
|
from digitalhub.context.api import get_context
|
|
10
|
-
from digitalhub.entities._commons.enums import
|
|
11
|
-
from digitalhub.entities._commons.utils import get_project_from_key, parse_entity_key
|
|
12
|
-
from digitalhub.factory.
|
|
10
|
+
from digitalhub.entities._commons.enums import EntityTypes
|
|
11
|
+
from digitalhub.entities._commons.utils import get_project_from_key, is_valid_key, parse_entity_key
|
|
12
|
+
from digitalhub.factory.entity import entity_factory
|
|
13
|
+
from digitalhub.stores.client._base.enums import ApiCategories, BackendOperations
|
|
13
14
|
from digitalhub.stores.client.api import get_client
|
|
14
15
|
from digitalhub.utils.exceptions import ContextError, EntityError, EntityNotExistsError
|
|
15
16
|
|
|
@@ -37,13 +38,13 @@ def parse_identifier(
|
|
|
37
38
|
identifier : str
|
|
38
39
|
The entity identifier to parse. Can be either a full entity key
|
|
39
40
|
(store://project/entity_type/kind/name:id) or a simple entity name.
|
|
40
|
-
project : str
|
|
41
|
+
project : str
|
|
41
42
|
The project name. Required when identifier is not a full key.
|
|
42
|
-
entity_type : str
|
|
43
|
+
entity_type : str
|
|
43
44
|
The entity type. Required when identifier is not a full key.
|
|
44
|
-
entity_kind : str
|
|
45
|
+
entity_kind : str
|
|
45
46
|
The entity kind specification.
|
|
46
|
-
entity_id : str
|
|
47
|
+
entity_id : str
|
|
47
48
|
The entity version identifier.
|
|
48
49
|
|
|
49
50
|
Returns
|
|
@@ -57,7 +58,7 @@ def parse_identifier(
|
|
|
57
58
|
ValueError
|
|
58
59
|
If identifier is not a full key and project or entity_type is None.
|
|
59
60
|
"""
|
|
60
|
-
if not identifier
|
|
61
|
+
if not is_valid_key(identifier):
|
|
61
62
|
if project is None or entity_type is None:
|
|
62
63
|
raise ValueError("Project and entity type must be specified.")
|
|
63
64
|
return project, entity_type, entity_kind, identifier, entity_id
|
|
@@ -80,7 +81,7 @@ def get_context_from_identifier(
|
|
|
80
81
|
identifier : str
|
|
81
82
|
The entity identifier to extract context from. Can be either
|
|
82
83
|
a full entity key (store://...) or a simple entity name.
|
|
83
|
-
project : str
|
|
84
|
+
project : str
|
|
84
85
|
The project name. Required when identifier is not a full key.
|
|
85
86
|
|
|
86
87
|
Returns
|
|
@@ -93,7 +94,7 @@ def get_context_from_identifier(
|
|
|
93
94
|
EntityError
|
|
94
95
|
If identifier is not a full key and project parameter is None.
|
|
95
96
|
"""
|
|
96
|
-
if not identifier
|
|
97
|
+
if not is_valid_key(identifier):
|
|
97
98
|
if project is None:
|
|
98
99
|
raise EntityError("Specify project if you do not specify entity key.")
|
|
99
100
|
else:
|
|
@@ -161,7 +162,7 @@ def get_context_from_remote(
|
|
|
161
162
|
try:
|
|
162
163
|
client = get_client()
|
|
163
164
|
obj = _read_base_entity(client, EntityTypes.PROJECT.value, project)
|
|
164
|
-
|
|
165
|
+
entity_factory.build_entity_from_dict(obj)
|
|
165
166
|
return get_context(project)
|
|
166
167
|
except EntityNotExistsError:
|
|
167
168
|
raise ContextError(f"Project '{project}' not found.")
|