digitalhub 0.9.0__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/client/_base/client.py +20 -56
- digitalhub/client/dhcore/client.py +13 -16
- digitalhub/client/dhcore/enums.py +1 -2
- digitalhub/client/dhcore/utils.py +13 -13
- digitalhub/client/local/client.py +0 -2
- digitalhub/entities/_base/entity/entity.py +4 -6
- digitalhub/entities/_base/entity/metadata.py +1 -1
- digitalhub/entities/_base/material/entity.py +1 -1
- digitalhub/entities/_base/project/entity.py +1 -1
- digitalhub/entities/_base/unversioned/entity.py +1 -2
- digitalhub/entities/_base/versioned/entity.py +1 -2
- digitalhub/entities/_operations/processor.py +2 -128
- digitalhub/entities/function/_base/entity.py +3 -3
- digitalhub/entities/run/_base/spec.py +0 -4
- digitalhub/entities/task/_base/entity.py +9 -16
- digitalhub/entities/task/_base/models.py +0 -6
- digitalhub/entities/task/_base/spec.py +0 -6
- digitalhub/entities/workflow/_base/entity.py +4 -12
- digitalhub/stores/_base/store.py +2 -6
- digitalhub/stores/local/store.py +2 -6
- digitalhub/stores/remote/store.py +2 -6
- digitalhub/stores/s3/store.py +46 -100
- digitalhub/stores/sql/store.py +2 -10
- digitalhub/utils/s3_utils.py +0 -17
- {digitalhub-0.9.0.dist-info → digitalhub-0.9.0b0.dist-info}/LICENSE.txt +1 -1
- {digitalhub-0.9.0.dist-info → digitalhub-0.9.0b0.dist-info}/METADATA +2 -2
- {digitalhub-0.9.0.dist-info → digitalhub-0.9.0b0.dist-info}/RECORD +29 -34
- digitalhub/client/_base/key_builder.py +0 -52
- digitalhub/client/dhcore/key_builder.py +0 -58
- digitalhub/client/local/key_builder.py +0 -58
- digitalhub/runtimes/enums.py +0 -12
- test/local/instances/test_validate.py +0 -55
- {digitalhub-0.9.0.dist-info → digitalhub-0.9.0b0.dist-info}/WHEEL +0 -0
- {digitalhub-0.9.0.dist-info → digitalhub-0.9.0b0.dist-info}/top_level.txt +0 -0
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
import typing
|
|
4
3
|
from abc import abstractmethod
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
from digitalhub.client._base.api_builder import ClientApiBuilder
|
|
8
|
-
from digitalhub.client._base.key_builder import ClientKeyBuilder
|
|
5
|
+
from digitalhub.client._base.api_builder import ClientApiBuilder
|
|
9
6
|
|
|
10
7
|
|
|
11
8
|
class Client:
|
|
@@ -19,11 +16,26 @@ class Client:
|
|
|
19
16
|
|
|
20
17
|
def __init__(self) -> None:
|
|
21
18
|
self._api_builder: ClientApiBuilder = None
|
|
22
|
-
self._key_builder: ClientKeyBuilder = None
|
|
23
19
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
def build_api(self, category: str, operation: str, **kwargs) -> str:
|
|
21
|
+
"""
|
|
22
|
+
Build the API for the client.
|
|
23
|
+
|
|
24
|
+
Parameters
|
|
25
|
+
----------
|
|
26
|
+
category : str
|
|
27
|
+
API category.
|
|
28
|
+
operation : str
|
|
29
|
+
API operation.
|
|
30
|
+
**kwargs : dict
|
|
31
|
+
Additional parameters.
|
|
32
|
+
|
|
33
|
+
Returns
|
|
34
|
+
-------
|
|
35
|
+
str
|
|
36
|
+
API formatted.
|
|
37
|
+
"""
|
|
38
|
+
return self._api_builder.build_api(category, operation, **kwargs)
|
|
27
39
|
|
|
28
40
|
@abstractmethod
|
|
29
41
|
def create_object(self, api: str, obj: dict, **kwargs) -> dict:
|
|
@@ -67,54 +79,6 @@ class Client:
|
|
|
67
79
|
Search objects method.
|
|
68
80
|
"""
|
|
69
81
|
|
|
70
|
-
##############################
|
|
71
|
-
# Build methods
|
|
72
|
-
##############################
|
|
73
|
-
|
|
74
|
-
def build_api(self, category: str, operation: str, **kwargs) -> str:
|
|
75
|
-
"""
|
|
76
|
-
Build the API for the client.
|
|
77
|
-
|
|
78
|
-
Parameters
|
|
79
|
-
----------
|
|
80
|
-
category : str
|
|
81
|
-
API category.
|
|
82
|
-
operation : str
|
|
83
|
-
API operation.
|
|
84
|
-
**kwargs : dict
|
|
85
|
-
Additional parameters.
|
|
86
|
-
|
|
87
|
-
Returns
|
|
88
|
-
-------
|
|
89
|
-
str
|
|
90
|
-
API formatted.
|
|
91
|
-
"""
|
|
92
|
-
return self._api_builder.build_api(category, operation, **kwargs)
|
|
93
|
-
|
|
94
|
-
def build_key(self, category: str, *args, **kwargs) -> str:
|
|
95
|
-
"""
|
|
96
|
-
Build the key for the client.
|
|
97
|
-
|
|
98
|
-
Parameters
|
|
99
|
-
----------
|
|
100
|
-
category : str
|
|
101
|
-
Key category.
|
|
102
|
-
*args : tuple
|
|
103
|
-
Additional arguments.
|
|
104
|
-
**kwargs : dict
|
|
105
|
-
Additional parameters.
|
|
106
|
-
|
|
107
|
-
Returns
|
|
108
|
-
-------
|
|
109
|
-
str
|
|
110
|
-
Key formatted.
|
|
111
|
-
"""
|
|
112
|
-
return self._key_builder.build_key(category, *args, **kwargs)
|
|
113
|
-
|
|
114
|
-
##############################
|
|
115
|
-
# Interface methods
|
|
116
|
-
##############################
|
|
117
|
-
|
|
118
82
|
@staticmethod
|
|
119
83
|
@abstractmethod
|
|
120
84
|
def is_local() -> bool:
|
|
@@ -12,9 +12,8 @@ from requests.exceptions import HTTPError, JSONDecodeError, RequestException
|
|
|
12
12
|
|
|
13
13
|
from digitalhub.client._base.client import Client
|
|
14
14
|
from digitalhub.client.dhcore.api_builder import ClientDHCoreApiBuilder
|
|
15
|
-
from digitalhub.client.dhcore.enums import AuthType,
|
|
15
|
+
from digitalhub.client.dhcore.enums import AuthType, EnvVar
|
|
16
16
|
from digitalhub.client.dhcore.env import ENV_FILE, FALLBACK_USER, LIB_VERSION, MAX_API_LEVEL, MIN_API_LEVEL
|
|
17
|
-
from digitalhub.client.dhcore.key_builder import ClientDHCoreKeyBuilder
|
|
18
17
|
from digitalhub.client.dhcore.models import BasicAuth, OAuth2TokenAuth
|
|
19
18
|
from digitalhub.utils.exceptions import (
|
|
20
19
|
BackendError,
|
|
@@ -53,9 +52,6 @@ class ClientDHCore(Client):
|
|
|
53
52
|
# API builder
|
|
54
53
|
self._api_builder = ClientDHCoreApiBuilder()
|
|
55
54
|
|
|
56
|
-
# Key builder
|
|
57
|
-
self._key_builder = ClientDHCoreKeyBuilder()
|
|
58
|
-
|
|
59
55
|
# Endpoints
|
|
60
56
|
self._endpoint_core: str | None = None
|
|
61
57
|
self._endpoint_issuer: str | None = None
|
|
@@ -524,6 +520,7 @@ class ClientDHCore(Client):
|
|
|
524
520
|
-------
|
|
525
521
|
None
|
|
526
522
|
"""
|
|
523
|
+
|
|
527
524
|
self._get_endpoints_from_env()
|
|
528
525
|
|
|
529
526
|
if config is not None:
|
|
@@ -561,12 +558,12 @@ class ClientDHCore(Client):
|
|
|
561
558
|
Exception
|
|
562
559
|
If the endpoint of DHCore is not set in the env variables.
|
|
563
560
|
"""
|
|
564
|
-
core_endpt = os.getenv(
|
|
561
|
+
core_endpt = os.getenv(EnvVar.ENDPOINT.value)
|
|
565
562
|
if core_endpt is None:
|
|
566
563
|
raise BackendError("Endpoint not set as environment variables.")
|
|
567
564
|
self._endpoint_core = self._sanitize_endpoint(core_endpt)
|
|
568
565
|
|
|
569
|
-
issr_endpt = os.getenv(
|
|
566
|
+
issr_endpt = os.getenv(EnvVar.ISSUER.value)
|
|
570
567
|
if issr_endpt is not None:
|
|
571
568
|
self._endpoint_issuer = self._sanitize_endpoint(issr_endpt)
|
|
572
569
|
|
|
@@ -592,17 +589,17 @@ class ClientDHCore(Client):
|
|
|
592
589
|
-------
|
|
593
590
|
None
|
|
594
591
|
"""
|
|
595
|
-
self._user = os.getenv(
|
|
596
|
-
self._refresh_token = os.getenv(
|
|
597
|
-
self._client_id = os.getenv(
|
|
592
|
+
self._user = os.getenv(EnvVar.USER.value, FALLBACK_USER)
|
|
593
|
+
self._refresh_token = os.getenv(EnvVar.REFRESH_TOKEN.value)
|
|
594
|
+
self._client_id = os.getenv(EnvVar.CLIENT_ID.value)
|
|
598
595
|
|
|
599
|
-
token = os.getenv(
|
|
596
|
+
token = os.getenv(EnvVar.ACCESS_TOKEN.value)
|
|
600
597
|
if token is not None and token != "":
|
|
601
598
|
self._auth_type = AuthType.OAUTH2.value
|
|
602
599
|
self._access_token = token
|
|
603
600
|
return
|
|
604
601
|
|
|
605
|
-
password = os.getenv(
|
|
602
|
+
password = os.getenv(EnvVar.PASSWORD.value)
|
|
606
603
|
if self._user is not None and password is not None:
|
|
607
604
|
self._auth_type = AuthType.BASIC.value
|
|
608
605
|
self._password = password
|
|
@@ -622,12 +619,12 @@ class ClientDHCore(Client):
|
|
|
622
619
|
|
|
623
620
|
# Call refresh token endpoint
|
|
624
621
|
# Try token from env
|
|
625
|
-
refresh_token = os.getenv(
|
|
622
|
+
refresh_token = os.getenv(EnvVar.REFRESH_TOKEN.value)
|
|
626
623
|
response = self._call_refresh_token_endpoint(url, refresh_token)
|
|
627
624
|
|
|
628
625
|
# Otherwise try token from file
|
|
629
626
|
if response.status_code in (400, 401, 403):
|
|
630
|
-
refresh_token = get_key(ENV_FILE,
|
|
627
|
+
refresh_token = get_key(ENV_FILE, EnvVar.REFRESH_TOKEN.value)
|
|
631
628
|
response = self._call_refresh_token_endpoint(url, refresh_token)
|
|
632
629
|
|
|
633
630
|
response.raise_for_status()
|
|
@@ -697,9 +694,9 @@ class ClientDHCore(Client):
|
|
|
697
694
|
"""
|
|
698
695
|
keys = {}
|
|
699
696
|
if self._access_token is not None:
|
|
700
|
-
keys[
|
|
697
|
+
keys[EnvVar.ACCESS_TOKEN.value] = self._access_token
|
|
701
698
|
if self._refresh_token is not None:
|
|
702
|
-
keys[
|
|
699
|
+
keys[EnvVar.REFRESH_TOKEN.value] = self._refresh_token
|
|
703
700
|
|
|
704
701
|
for k, v in keys.items():
|
|
705
702
|
set_key(dotenv_path=ENV_FILE, key_to_set=k, value_to_set=v)
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
from enum import Enum
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
class
|
|
6
|
+
class EnvVar(Enum):
|
|
7
7
|
"""
|
|
8
8
|
Environment variables.
|
|
9
9
|
"""
|
|
@@ -15,7 +15,6 @@ class DhcoreEnvVar(Enum):
|
|
|
15
15
|
CLIENT_ID = "DHCORE_CLIENT_ID"
|
|
16
16
|
ACCESS_TOKEN = "DHCORE_ACCESS_TOKEN"
|
|
17
17
|
REFRESH_TOKEN = "DHCORE_REFRESH_TOKEN"
|
|
18
|
-
WORKFLOW_IMAGE = "DHCORE_WORKFLOW_IMAGE"
|
|
19
18
|
|
|
20
19
|
|
|
21
20
|
class AuthType(Enum):
|
|
@@ -4,7 +4,7 @@ import os
|
|
|
4
4
|
import typing
|
|
5
5
|
|
|
6
6
|
from digitalhub.client.api import get_client
|
|
7
|
-
from digitalhub.client.dhcore.enums import AuthType,
|
|
7
|
+
from digitalhub.client.dhcore.enums import AuthType, EnvVar
|
|
8
8
|
|
|
9
9
|
if typing.TYPE_CHECKING:
|
|
10
10
|
from digitalhub.client.dhcore.client import ClientDHCore
|
|
@@ -44,17 +44,17 @@ def set_dhcore_env(
|
|
|
44
44
|
None
|
|
45
45
|
"""
|
|
46
46
|
if endpoint is not None:
|
|
47
|
-
os.environ[
|
|
47
|
+
os.environ[EnvVar.ENDPOINT.value] = endpoint
|
|
48
48
|
if user is not None:
|
|
49
|
-
os.environ[
|
|
49
|
+
os.environ[EnvVar.USER.value] = user
|
|
50
50
|
if password is not None:
|
|
51
|
-
os.environ[
|
|
51
|
+
os.environ[EnvVar.PASSWORD.value] = password
|
|
52
52
|
if access_token is not None:
|
|
53
|
-
os.environ[
|
|
53
|
+
os.environ[EnvVar.ACCESS_TOKEN.value] = access_token
|
|
54
54
|
if refresh_token is not None:
|
|
55
|
-
os.environ[
|
|
55
|
+
os.environ[EnvVar.REFRESH_TOKEN.value] = refresh_token
|
|
56
56
|
if client_id is not None:
|
|
57
|
-
os.environ[
|
|
57
|
+
os.environ[EnvVar.CLIENT_ID.value] = client_id
|
|
58
58
|
|
|
59
59
|
update_client_from_env()
|
|
60
60
|
|
|
@@ -70,16 +70,16 @@ def update_client_from_env() -> None:
|
|
|
70
70
|
client: ClientDHCore = get_client(local=False)
|
|
71
71
|
|
|
72
72
|
# Update endpoint
|
|
73
|
-
endpoint = os.getenv(
|
|
73
|
+
endpoint = os.getenv(EnvVar.ENDPOINT.value)
|
|
74
74
|
if endpoint is not None:
|
|
75
75
|
client._endpoint_core = endpoint
|
|
76
76
|
|
|
77
77
|
# Update auth
|
|
78
78
|
|
|
79
79
|
# If token is set, it will override the other auth options
|
|
80
|
-
access_token = os.getenv(
|
|
81
|
-
refresh_token = os.getenv(
|
|
82
|
-
client_id = os.getenv(
|
|
80
|
+
access_token = os.getenv(EnvVar.ACCESS_TOKEN.value)
|
|
81
|
+
refresh_token = os.getenv(EnvVar.REFRESH_TOKEN.value)
|
|
82
|
+
client_id = os.getenv(EnvVar.CLIENT_ID.value)
|
|
83
83
|
|
|
84
84
|
if access_token is not None:
|
|
85
85
|
if refresh_token is not None:
|
|
@@ -91,8 +91,8 @@ def update_client_from_env() -> None:
|
|
|
91
91
|
return
|
|
92
92
|
|
|
93
93
|
# Otherwise, if user and password are set, basic auth will be used
|
|
94
|
-
username = os.getenv(
|
|
95
|
-
password = os.getenv(
|
|
94
|
+
username = os.getenv(EnvVar.USER.value)
|
|
95
|
+
password = os.getenv(EnvVar.PASSWORD.value)
|
|
96
96
|
if username is not None and password is not None:
|
|
97
97
|
client._user = username
|
|
98
98
|
client._password = password
|
|
@@ -5,7 +5,6 @@ from datetime import datetime, timezone
|
|
|
5
5
|
|
|
6
6
|
from digitalhub.client._base.client import Client
|
|
7
7
|
from digitalhub.client.local.api_builder import ClientLocalApiBuilder
|
|
8
|
-
from digitalhub.client.local.key_builder import ClientLocalKeyBuilder
|
|
9
8
|
from digitalhub.utils.exceptions import BackendError
|
|
10
9
|
|
|
11
10
|
|
|
@@ -25,7 +24,6 @@ class ClientLocal(Client):
|
|
|
25
24
|
def __init__(self) -> None:
|
|
26
25
|
super().__init__()
|
|
27
26
|
self._api_builder = ClientLocalApiBuilder()
|
|
28
|
-
self._key_builder = ClientLocalKeyBuilder()
|
|
29
27
|
self._db: dict[str, dict[str, dict]] = {}
|
|
30
28
|
|
|
31
29
|
##############################
|
|
@@ -79,7 +79,7 @@ class Entity(Base):
|
|
|
79
79
|
Abstract export method.
|
|
80
80
|
"""
|
|
81
81
|
|
|
82
|
-
def add_relationship(self, relation: str,
|
|
82
|
+
def add_relationship(self, relation: str, source: str, dest: str) -> None:
|
|
83
83
|
"""
|
|
84
84
|
Add relationship to entity metadata.
|
|
85
85
|
|
|
@@ -87,10 +87,10 @@ class Entity(Base):
|
|
|
87
87
|
----------
|
|
88
88
|
relation : str
|
|
89
89
|
The type of relationship.
|
|
90
|
-
dest : str
|
|
91
|
-
The target entity.
|
|
92
90
|
source : str
|
|
93
91
|
The source entity.
|
|
92
|
+
dest : str
|
|
93
|
+
The target entity..
|
|
94
94
|
|
|
95
95
|
Returns
|
|
96
96
|
-------
|
|
@@ -98,9 +98,7 @@ class Entity(Base):
|
|
|
98
98
|
"""
|
|
99
99
|
if self.metadata.relationships is None:
|
|
100
100
|
self.metadata.relationships = []
|
|
101
|
-
obj = {"type": relation, "dest": dest}
|
|
102
|
-
if source is not None:
|
|
103
|
-
obj["source"] = source
|
|
101
|
+
obj = {"type": relation, "source": source, "dest": dest}
|
|
104
102
|
self.metadata.relationships.append(obj)
|
|
105
103
|
|
|
106
104
|
def to_dict(self) -> dict:
|
|
@@ -168,7 +168,7 @@ class MaterialEntity(VersionedEntity):
|
|
|
168
168
|
paths = store.upload(source, self.spec.path)
|
|
169
169
|
|
|
170
170
|
# Update files info
|
|
171
|
-
files_info = store.get_file_info(
|
|
171
|
+
files_info = store.get_file_info(paths)
|
|
172
172
|
self._update_files_info(files_info)
|
|
173
173
|
|
|
174
174
|
##############################
|
|
@@ -40,7 +40,7 @@ class ProjectEntity(Entity):
|
|
|
40
40
|
super().__init__(kind, metadata, spec, status, user)
|
|
41
41
|
self.id = name
|
|
42
42
|
self.name = name
|
|
43
|
-
self.key =
|
|
43
|
+
self.key = f"store://{name}"
|
|
44
44
|
|
|
45
45
|
self._obj_attr.extend(["id", "name"])
|
|
46
46
|
|
|
@@ -3,7 +3,6 @@ from __future__ import annotations
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
5
|
from digitalhub.entities._base.context.entity import ContextEntity
|
|
6
|
-
from digitalhub.entities._operations.processor import processor
|
|
7
6
|
|
|
8
7
|
if typing.TYPE_CHECKING:
|
|
9
8
|
from digitalhub.entities._base.entity.metadata import Metadata
|
|
@@ -25,4 +24,4 @@ class UnversionedEntity(ContextEntity):
|
|
|
25
24
|
super().__init__(project, kind, metadata, spec, status, user)
|
|
26
25
|
self.id = uuid
|
|
27
26
|
self.name = uuid
|
|
28
|
-
self.key =
|
|
27
|
+
self.key = f"store://{project}/{self.ENTITY_TYPE}/{kind}/{uuid}"
|
|
@@ -3,7 +3,6 @@ from __future__ import annotations
|
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
5
|
from digitalhub.entities._base.context.entity import ContextEntity
|
|
6
|
-
from digitalhub.entities._operations.processor import processor
|
|
7
6
|
|
|
8
7
|
if typing.TYPE_CHECKING:
|
|
9
8
|
from digitalhub.entities._base.entity.metadata import Metadata
|
|
@@ -26,4 +25,4 @@ class VersionedEntity(ContextEntity):
|
|
|
26
25
|
super().__init__(project, kind, metadata, spec, status, user)
|
|
27
26
|
self.name = name
|
|
28
27
|
self.id = uuid
|
|
29
|
-
self.key =
|
|
28
|
+
self.key = f"store://{project}/{self.ENTITY_TYPE}/{kind}/{name}:{uuid}"
|
|
@@ -427,55 +427,6 @@ class OperationsProcessor:
|
|
|
427
427
|
**kwargs,
|
|
428
428
|
)
|
|
429
429
|
|
|
430
|
-
##############################
|
|
431
|
-
# Base entity operations
|
|
432
|
-
##############################
|
|
433
|
-
|
|
434
|
-
def _build_base_entity_key(
|
|
435
|
-
self,
|
|
436
|
-
client: Client,
|
|
437
|
-
entity_id: str,
|
|
438
|
-
) -> str:
|
|
439
|
-
"""
|
|
440
|
-
Build object key.
|
|
441
|
-
|
|
442
|
-
Parameters
|
|
443
|
-
----------
|
|
444
|
-
client : Client
|
|
445
|
-
Client instance.
|
|
446
|
-
entity_id : str
|
|
447
|
-
Entity ID.
|
|
448
|
-
|
|
449
|
-
Returns
|
|
450
|
-
-------
|
|
451
|
-
str
|
|
452
|
-
Object key.
|
|
453
|
-
"""
|
|
454
|
-
return client.build_key(ApiCategories.BASE.value, entity_id)
|
|
455
|
-
|
|
456
|
-
def build_project_key(
|
|
457
|
-
self,
|
|
458
|
-
entity_id: str,
|
|
459
|
-
**kwargs,
|
|
460
|
-
) -> str:
|
|
461
|
-
"""
|
|
462
|
-
Build object key.
|
|
463
|
-
|
|
464
|
-
Parameters
|
|
465
|
-
----------
|
|
466
|
-
entity_id : str
|
|
467
|
-
Entity ID.
|
|
468
|
-
**kwargs : dict
|
|
469
|
-
Parameters to pass to entity builder.
|
|
470
|
-
|
|
471
|
-
Returns
|
|
472
|
-
-------
|
|
473
|
-
str
|
|
474
|
-
Object key.
|
|
475
|
-
"""
|
|
476
|
-
client = get_client(kwargs.pop("local", False))
|
|
477
|
-
return self._build_base_entity_key(client, entity_id)
|
|
478
|
-
|
|
479
430
|
def share_project_entity(
|
|
480
431
|
self,
|
|
481
432
|
entity_type: str,
|
|
@@ -587,10 +538,7 @@ class OperationsProcessor:
|
|
|
587
538
|
new_obj = self._create_context_entity(context, obj.ENTITY_TYPE, obj.to_dict())
|
|
588
539
|
return build_entity_from_dict(new_obj)
|
|
589
540
|
|
|
590
|
-
def log_material_entity(
|
|
591
|
-
self,
|
|
592
|
-
**kwargs,
|
|
593
|
-
) -> MaterialEntity:
|
|
541
|
+
def log_material_entity(self, **kwargs,) -> MaterialEntity:
|
|
594
542
|
"""
|
|
595
543
|
Create object in backend and upload file.
|
|
596
544
|
|
|
@@ -608,7 +556,7 @@ class OperationsProcessor:
|
|
|
608
556
|
context = self._get_context(kwargs["project"])
|
|
609
557
|
obj = build_entity_from_params(**kwargs)
|
|
610
558
|
if context.is_running:
|
|
611
|
-
obj.add_relationship(Relationship.PRODUCEDBY.value, context.get_run_ctx())
|
|
559
|
+
obj.add_relationship(Relationship.PRODUCEDBY.value, obj.key, context.get_run_ctx())
|
|
612
560
|
|
|
613
561
|
new_obj: MaterialEntity = self._create_context_entity(context, obj.ENTITY_TYPE, obj.to_dict())
|
|
614
562
|
new_obj = build_entity_from_dict(new_obj)
|
|
@@ -785,10 +733,6 @@ class OperationsProcessor:
|
|
|
785
733
|
"""
|
|
786
734
|
if not identifier.startswith("store://"):
|
|
787
735
|
entity_id = identifier
|
|
788
|
-
else:
|
|
789
|
-
splt = identifier.split(":")
|
|
790
|
-
if len(splt) == 3:
|
|
791
|
-
identifier = f"{splt[0]}:{splt[1]}"
|
|
792
736
|
return self.read_context_entity(
|
|
793
737
|
identifier,
|
|
794
738
|
entity_type=entity_type,
|
|
@@ -1328,76 +1272,6 @@ class OperationsProcessor:
|
|
|
1328
1272
|
# Context entity operations
|
|
1329
1273
|
##############################
|
|
1330
1274
|
|
|
1331
|
-
def _build_context_entity_key(
|
|
1332
|
-
self,
|
|
1333
|
-
context: Context,
|
|
1334
|
-
entity_type: str,
|
|
1335
|
-
entity_kind: str,
|
|
1336
|
-
entity_name: str,
|
|
1337
|
-
entity_id: str | None = None,
|
|
1338
|
-
) -> str:
|
|
1339
|
-
"""
|
|
1340
|
-
Build object key.
|
|
1341
|
-
|
|
1342
|
-
Parameters
|
|
1343
|
-
----------
|
|
1344
|
-
context : Context
|
|
1345
|
-
Context instance.
|
|
1346
|
-
entity_type : str
|
|
1347
|
-
Entity type.
|
|
1348
|
-
entity_kind : str
|
|
1349
|
-
Entity kind.
|
|
1350
|
-
entity_name : str
|
|
1351
|
-
Entity name.
|
|
1352
|
-
entity_id : str
|
|
1353
|
-
Entity ID.
|
|
1354
|
-
|
|
1355
|
-
Returns
|
|
1356
|
-
-------
|
|
1357
|
-
str
|
|
1358
|
-
Object key.
|
|
1359
|
-
"""
|
|
1360
|
-
return context.client.build_key(
|
|
1361
|
-
ApiCategories.CONTEXT.value,
|
|
1362
|
-
project=context.name,
|
|
1363
|
-
entity_type=entity_type,
|
|
1364
|
-
entity_kind=entity_kind,
|
|
1365
|
-
entity_name=entity_name,
|
|
1366
|
-
entity_id=entity_id,
|
|
1367
|
-
)
|
|
1368
|
-
|
|
1369
|
-
def build_context_entity_key(
|
|
1370
|
-
self,
|
|
1371
|
-
project: str,
|
|
1372
|
-
entity_type: str,
|
|
1373
|
-
entity_kind: str,
|
|
1374
|
-
entity_name: str,
|
|
1375
|
-
entity_id: str | None = None,
|
|
1376
|
-
) -> str:
|
|
1377
|
-
"""
|
|
1378
|
-
Build object key.
|
|
1379
|
-
|
|
1380
|
-
Parameters
|
|
1381
|
-
----------
|
|
1382
|
-
project : str
|
|
1383
|
-
Project name.
|
|
1384
|
-
entity_type : str
|
|
1385
|
-
Entity type.
|
|
1386
|
-
entity_kind : str
|
|
1387
|
-
Entity kind.
|
|
1388
|
-
entity_name : str
|
|
1389
|
-
Entity name.
|
|
1390
|
-
entity_id : str
|
|
1391
|
-
Entity ID.
|
|
1392
|
-
|
|
1393
|
-
Returns
|
|
1394
|
-
-------
|
|
1395
|
-
str
|
|
1396
|
-
Object key.
|
|
1397
|
-
"""
|
|
1398
|
-
context = self._get_context(project)
|
|
1399
|
-
return self._build_context_entity_key(context, entity_type, entity_kind, entity_name, entity_id)
|
|
1400
|
-
|
|
1401
1275
|
def read_secret_data(
|
|
1402
1276
|
self,
|
|
1403
1277
|
project: str,
|
|
@@ -79,11 +79,11 @@ class Function(ExecutableEntity):
|
|
|
79
79
|
task = self._get_or_create_task(task_kind)
|
|
80
80
|
|
|
81
81
|
# Run function from task
|
|
82
|
-
run = task.run(run_kind,
|
|
82
|
+
run = task.run(run_kind, local_execution, **kwargs)
|
|
83
83
|
|
|
84
84
|
# Set as run's parent
|
|
85
|
-
run.add_relationship(Relationship.RUN_OF.value, self.key)
|
|
86
|
-
run.save()
|
|
85
|
+
run.add_relationship(Relationship.RUN_OF.value, run.key + ":" + run.id, self.key)
|
|
86
|
+
run.save(update=True)
|
|
87
87
|
|
|
88
88
|
# If execution is done by DHCore backend, return the object
|
|
89
89
|
if not local_execution:
|
|
@@ -21,8 +21,6 @@ class RunSpec(Spec):
|
|
|
21
21
|
envs: list[dict] | None = None,
|
|
22
22
|
secrets: list[str] | None = None,
|
|
23
23
|
profile: str | None = None,
|
|
24
|
-
runtime_class: str | None = None,
|
|
25
|
-
priority_class: str | None = None,
|
|
26
24
|
**kwargs,
|
|
27
25
|
) -> None:
|
|
28
26
|
self.task = task
|
|
@@ -37,8 +35,6 @@ class RunSpec(Spec):
|
|
|
37
35
|
self.envs = envs
|
|
38
36
|
self.secrets = secrets
|
|
39
37
|
self.profile = profile
|
|
40
|
-
self.runtime_class = runtime_class
|
|
41
|
-
self.priority_class = priority_class
|
|
42
38
|
|
|
43
39
|
|
|
44
40
|
class RunValidator(SpecValidator, K8s):
|
|
@@ -4,8 +4,8 @@ import typing
|
|
|
4
4
|
|
|
5
5
|
from digitalhub.entities._base.unversioned.entity import UnversionedEntity
|
|
6
6
|
from digitalhub.entities._commons.enums import EntityTypes
|
|
7
|
-
from digitalhub.entities.
|
|
8
|
-
from digitalhub.factory.api import
|
|
7
|
+
from digitalhub.entities.run.crud import delete_run, get_run, new_run
|
|
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
|
|
@@ -42,7 +42,6 @@ class Task(UnversionedEntity):
|
|
|
42
42
|
def run(
|
|
43
43
|
self,
|
|
44
44
|
run_kind: str,
|
|
45
|
-
save: bool = True,
|
|
46
45
|
local_execution: bool = False,
|
|
47
46
|
**kwargs,
|
|
48
47
|
) -> Run:
|
|
@@ -67,7 +66,6 @@ class Task(UnversionedEntity):
|
|
|
67
66
|
exec_type = get_entity_type_from_kind(exec_kind)
|
|
68
67
|
kwargs[exec_type] = getattr(self.spec, exec_type)
|
|
69
68
|
return self.new_run(
|
|
70
|
-
save=save,
|
|
71
69
|
project=self.project,
|
|
72
70
|
task=self._get_task_string(),
|
|
73
71
|
kind=run_kind,
|
|
@@ -90,25 +88,21 @@ class Task(UnversionedEntity):
|
|
|
90
88
|
# CRUD Methods for Run
|
|
91
89
|
##############################
|
|
92
90
|
|
|
93
|
-
def new_run(self,
|
|
91
|
+
def new_run(self, **kwargs) -> Run:
|
|
94
92
|
"""
|
|
95
93
|
Create a new run.
|
|
96
94
|
|
|
97
95
|
Parameters
|
|
98
96
|
----------
|
|
99
|
-
save : bool
|
|
100
|
-
Flag to indicate save.
|
|
101
97
|
**kwargs : dict
|
|
102
|
-
Keyword arguments
|
|
98
|
+
Keyword arguments.
|
|
103
99
|
|
|
104
100
|
Returns
|
|
105
101
|
-------
|
|
106
102
|
Run
|
|
107
103
|
Run object.
|
|
108
104
|
"""
|
|
109
|
-
|
|
110
|
-
return processor.create_context_entity(**kwargs)
|
|
111
|
-
return build_entity_from_params(**kwargs)
|
|
105
|
+
return new_run(**kwargs)
|
|
112
106
|
|
|
113
107
|
def get_run(self, entity_key: str) -> Run:
|
|
114
108
|
"""
|
|
@@ -124,9 +118,9 @@ class Task(UnversionedEntity):
|
|
|
124
118
|
Run
|
|
125
119
|
Run object.
|
|
126
120
|
"""
|
|
127
|
-
return
|
|
121
|
+
return get_run(entity_key)
|
|
128
122
|
|
|
129
|
-
def delete_run(self, entity_key: str) ->
|
|
123
|
+
def delete_run(self, entity_key: str) -> None:
|
|
130
124
|
"""
|
|
131
125
|
Delete run.
|
|
132
126
|
|
|
@@ -137,7 +131,6 @@ class Task(UnversionedEntity):
|
|
|
137
131
|
|
|
138
132
|
Returns
|
|
139
133
|
-------
|
|
140
|
-
|
|
141
|
-
Response from backend.
|
|
134
|
+
None
|
|
142
135
|
"""
|
|
143
|
-
|
|
136
|
+
delete_run(entity_key)
|
|
@@ -210,12 +210,6 @@ class K8s(BaseModel):
|
|
|
210
210
|
profile: str = None
|
|
211
211
|
"""Profile template."""
|
|
212
212
|
|
|
213
|
-
runtime_class: str = None
|
|
214
|
-
"""Runtime class name."""
|
|
215
|
-
|
|
216
|
-
priority_class: str = None
|
|
217
|
-
"""Priority class."""
|
|
218
|
-
|
|
219
213
|
|
|
220
214
|
class CorePort(BaseModel):
|
|
221
215
|
"""
|