cognite-toolkit 0.7.39__py3-none-any.whl → 0.7.40__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.
- cognite_toolkit/_cdf_tk/client/_toolkit_client.py +3 -1
- cognite_toolkit/_cdf_tk/client/api/assets.py +118 -0
- cognite_toolkit/_cdf_tk/client/api/events.py +79 -0
- cognite_toolkit/_cdf_tk/client/api/infield.py +3 -3
- cognite_toolkit/_cdf_tk/client/api/legacy/extended_functions.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/project.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/streams.py +2 -2
- cognite_toolkit/_cdf_tk/client/api/three_d.py +5 -4
- cognite_toolkit/_cdf_tk/client/api/timeseries.py +85 -0
- cognite_toolkit/_cdf_tk/client/cdf_client/__init__.py +9 -0
- cognite_toolkit/_cdf_tk/client/cdf_client/api.py +220 -0
- cognite_toolkit/_cdf_tk/client/{data_classes/api_classes.py → cdf_client/responses.py} +10 -13
- cognite_toolkit/_cdf_tk/client/data_classes/asset.py +54 -0
- cognite_toolkit/_cdf_tk/client/data_classes/base.py +117 -22
- cognite_toolkit/_cdf_tk/client/data_classes/event.py +40 -0
- cognite_toolkit/_cdf_tk/client/data_classes/identifiers.py +44 -0
- cognite_toolkit/_cdf_tk/client/data_classes/instance_api.py +34 -0
- cognite_toolkit/_cdf_tk/client/data_classes/streams.py +3 -2
- cognite_toolkit/_cdf_tk/client/data_classes/three_d.py +29 -34
- cognite_toolkit/_cdf_tk/client/data_classes/timeseries.py +45 -0
- cognite_toolkit/_cdf_tk/{utils → client}/http_client/__init__.py +4 -4
- cognite_toolkit/_cdf_tk/{utils → client}/http_client/_client.py +10 -10
- cognite_toolkit/_cdf_tk/{utils → client}/http_client/_data_classes.py +2 -2
- cognite_toolkit/_cdf_tk/{utils → client}/http_client/_data_classes2.py +10 -33
- cognite_toolkit/_cdf_tk/client/testing.py +2 -0
- cognite_toolkit/_cdf_tk/commands/_migrate/command.py +1 -1
- cognite_toolkit/_cdf_tk/commands/_migrate/conversion.py +6 -7
- cognite_toolkit/_cdf_tk/commands/_migrate/data_classes.py +6 -5
- cognite_toolkit/_cdf_tk/commands/_migrate/data_mapper.py +6 -4
- cognite_toolkit/_cdf_tk/commands/_migrate/migration_io.py +10 -10
- cognite_toolkit/_cdf_tk/commands/_purge.py +7 -7
- cognite_toolkit/_cdf_tk/commands/_upload.py +1 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/classic.py +43 -47
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/fieldops.py +11 -4
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/file.py +2 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/location.py +3 -2
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/relationship.py +2 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/streams.py +1 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/timeseries.py +2 -1
- cognite_toolkit/_cdf_tk/storageio/_applications.py +1 -1
- cognite_toolkit/_cdf_tk/storageio/_asset_centric.py +32 -29
- cognite_toolkit/_cdf_tk/storageio/_base.py +1 -1
- cognite_toolkit/_cdf_tk/storageio/_datapoints.py +7 -7
- cognite_toolkit/_cdf_tk/storageio/_file_content.py +7 -7
- cognite_toolkit/_cdf_tk/storageio/_raw.py +1 -1
- cognite_toolkit/_cdf_tk/utils/useful_types.py +4 -7
- cognite_toolkit/_cdf_tk/utils/useful_types2.py +12 -0
- cognite_toolkit/_repo_files/GitHub/.github/workflows/deploy.yaml +1 -1
- cognite_toolkit/_repo_files/GitHub/.github/workflows/dry-run.yaml +1 -1
- cognite_toolkit/_resources/cdf.toml +1 -1
- cognite_toolkit/_version.py +1 -1
- {cognite_toolkit-0.7.39.dist-info → cognite_toolkit-0.7.40.dist-info}/METADATA +1 -1
- {cognite_toolkit-0.7.39.dist-info → cognite_toolkit-0.7.40.dist-info}/RECORD +57 -47
- {cognite_toolkit-0.7.39.dist-info → cognite_toolkit-0.7.40.dist-info}/WHEEL +1 -1
- /cognite_toolkit/_cdf_tk/{utils → client}/http_client/_exception.py +0 -0
- /cognite_toolkit/_cdf_tk/{utils → client}/http_client/_tracker.py +0 -0
- {cognite_toolkit-0.7.39.dist-info → cognite_toolkit-0.7.40.dist-info}/entry_points.txt +0 -0
|
@@ -7,8 +7,8 @@ from typing import Generic, Literal, Protocol, TypeAlias, TypeVar
|
|
|
7
7
|
import httpx
|
|
8
8
|
from cognite.client.utils import _json
|
|
9
9
|
|
|
10
|
-
from cognite_toolkit._cdf_tk.
|
|
11
|
-
from cognite_toolkit._cdf_tk.
|
|
10
|
+
from cognite_toolkit._cdf_tk.client.http_client._exception import ToolkitAPIError
|
|
11
|
+
from cognite_toolkit._cdf_tk.client.http_client._tracker import ItemsRequestTracker
|
|
12
12
|
from cognite_toolkit._cdf_tk.utils.useful_types import JsonVal, PrimitiveType
|
|
13
13
|
|
|
14
14
|
StatusCode: TypeAlias = int
|
|
@@ -2,22 +2,21 @@ import gzip
|
|
|
2
2
|
import sys
|
|
3
3
|
from abc import ABC, abstractmethod
|
|
4
4
|
from collections import UserList
|
|
5
|
-
from collections.abc import
|
|
5
|
+
from collections.abc import Sequence
|
|
6
6
|
from typing import Any, Literal
|
|
7
7
|
|
|
8
8
|
import httpx
|
|
9
9
|
from cognite.client import global_config
|
|
10
10
|
from pydantic import BaseModel, ConfigDict, Field, JsonValue, TypeAdapter, model_validator
|
|
11
|
-
from pydantic.alias_generators import to_camel
|
|
12
11
|
|
|
13
|
-
from cognite_toolkit._cdf_tk.
|
|
14
|
-
from cognite_toolkit._cdf_tk.
|
|
12
|
+
from cognite_toolkit._cdf_tk.client.http_client._exception import ToolkitAPIError
|
|
13
|
+
from cognite_toolkit._cdf_tk.client.http_client._tracker import ItemsRequestTracker
|
|
15
14
|
from cognite_toolkit._cdf_tk.utils.useful_types import PrimitiveType
|
|
16
15
|
|
|
17
16
|
if sys.version_info >= (3, 11):
|
|
18
|
-
|
|
17
|
+
pass
|
|
19
18
|
else:
|
|
20
|
-
|
|
19
|
+
pass
|
|
21
20
|
|
|
22
21
|
|
|
23
22
|
class HTTPResult2(BaseModel):
|
|
@@ -124,7 +123,7 @@ _BODY_SERIALIZER = TypeAdapter(dict[str, JsonValue])
|
|
|
124
123
|
|
|
125
124
|
|
|
126
125
|
class ItemsResultMessage2(BaseModel):
|
|
127
|
-
ids: list[
|
|
126
|
+
ids: list[str]
|
|
128
127
|
|
|
129
128
|
|
|
130
129
|
class ItemsFailedRequest2(ItemsResultMessage2):
|
|
@@ -143,30 +142,6 @@ class ItemsFailedResponse2(ItemsResultMessage2):
|
|
|
143
142
|
body: str
|
|
144
143
|
|
|
145
144
|
|
|
146
|
-
class BaseModelObject(BaseModel):
|
|
147
|
-
"""Base class for all object. This includes resources and nested objects."""
|
|
148
|
-
|
|
149
|
-
# We allow extra fields to support forward compatibility.
|
|
150
|
-
model_config = ConfigDict(alias_generator=to_camel, extra="allow")
|
|
151
|
-
|
|
152
|
-
def dump(self, camel_case: bool = True) -> dict[str, Any]:
|
|
153
|
-
"""Dump the resource to a dictionary.
|
|
154
|
-
|
|
155
|
-
This is the default serialization method for request resources.
|
|
156
|
-
"""
|
|
157
|
-
return self.model_dump(mode="json", by_alias=camel_case, exclude_unset=True)
|
|
158
|
-
|
|
159
|
-
@classmethod
|
|
160
|
-
def _load(cls, resource: dict[str, Any]) -> "Self":
|
|
161
|
-
"""Load method to match CogniteResource signature."""
|
|
162
|
-
return cls.model_validate(resource)
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
class RequestResource(BaseModelObject, ABC):
|
|
166
|
-
@abstractmethod
|
|
167
|
-
def as_id(self) -> Hashable: ...
|
|
168
|
-
|
|
169
|
-
|
|
170
145
|
def _set_default_tracker(data: dict[str, Any]) -> ItemsRequestTracker:
|
|
171
146
|
if "tracker" not in data or data["tracker"] is None:
|
|
172
147
|
return ItemsRequestTracker(data.get("max_failures_before_abort", 50))
|
|
@@ -175,14 +150,16 @@ def _set_default_tracker(data: dict[str, Any]) -> ItemsRequestTracker:
|
|
|
175
150
|
|
|
176
151
|
class ItemsRequest2(BaseRequestMessage):
|
|
177
152
|
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
178
|
-
items: Sequence[
|
|
153
|
+
items: Sequence[BaseModel]
|
|
179
154
|
extra_body_fields: dict[str, JsonValue] | None = None
|
|
180
155
|
max_failures_before_abort: int = 50
|
|
181
156
|
tracker: ItemsRequestTracker = Field(init=False, default_factory=_set_default_tracker, exclude=True)
|
|
182
157
|
|
|
183
158
|
@property
|
|
184
159
|
def content(self) -> str | bytes | None:
|
|
185
|
-
body: dict[str, JsonValue] = {
|
|
160
|
+
body: dict[str, JsonValue] = {
|
|
161
|
+
"items": [item.model_dump(mode="json", by_alias=True, exclude_unset=True) for item in self.items]
|
|
162
|
+
}
|
|
186
163
|
if self.extra_body_fields:
|
|
187
164
|
body.update(self.extra_body_fields)
|
|
188
165
|
res = _BODY_SERIALIZER.dump_json(body)
|
|
@@ -12,6 +12,7 @@ from cognite.client.testing import CogniteClientMock
|
|
|
12
12
|
from rich.console import Console
|
|
13
13
|
|
|
14
14
|
from cognite_toolkit._cdf_tk.client._toolkit_client import ToolkitClient
|
|
15
|
+
from cognite_toolkit._cdf_tk.client.api.assets import AssetsAPI
|
|
15
16
|
from cognite_toolkit._cdf_tk.client.api.legacy.canvas import CanvasAPI, IndustrialCanvasAPI
|
|
16
17
|
from cognite_toolkit._cdf_tk.client.api.legacy.charts import ChartsAPI
|
|
17
18
|
from cognite_toolkit._cdf_tk.client.api.legacy.dml import DMLAPI
|
|
@@ -138,6 +139,7 @@ class ToolkitClientMock(CogniteClientMock):
|
|
|
138
139
|
self.tool = MagicMock(spec=ToolAPI)
|
|
139
140
|
self.tool.three_d = MagicMock(spec=ThreeDAPI)
|
|
140
141
|
self.tool.three_d.models = MagicMock(spec_set=ThreeDModelAPI)
|
|
142
|
+
self.tool.assets = MagicMock(spec_set=AssetsAPI)
|
|
141
143
|
|
|
142
144
|
self.streams = MagicMock(spec=StreamsAPI)
|
|
143
145
|
|
|
@@ -7,6 +7,7 @@ from rich.console import Console
|
|
|
7
7
|
from rich.table import Table
|
|
8
8
|
|
|
9
9
|
from cognite_toolkit._cdf_tk.client import ToolkitClient
|
|
10
|
+
from cognite_toolkit._cdf_tk.client.http_client import HTTPClient, HTTPMessage, ItemMessage, SuccessResponseItems
|
|
10
11
|
from cognite_toolkit._cdf_tk.commands._base import ToolkitCommand
|
|
11
12
|
from cognite_toolkit._cdf_tk.commands._migrate.creators import MigrationCreator
|
|
12
13
|
from cognite_toolkit._cdf_tk.commands._migrate.data_mapper import DataMapper
|
|
@@ -24,7 +25,6 @@ from cognite_toolkit._cdf_tk.storageio import T_Selector, UploadableStorageIO, U
|
|
|
24
25
|
from cognite_toolkit._cdf_tk.utils import humanize_collection, safe_write, sanitize_filename
|
|
25
26
|
from cognite_toolkit._cdf_tk.utils.file import yaml_safe_dump
|
|
26
27
|
from cognite_toolkit._cdf_tk.utils.fileio import Chunk, CSVWriter, NDJsonWriter, SchemaColumn, Uncompressed
|
|
27
|
-
from cognite_toolkit._cdf_tk.utils.http_client import HTTPClient, HTTPMessage, ItemMessage, SuccessResponseItems
|
|
28
28
|
from cognite_toolkit._cdf_tk.utils.producer_worker import ProducerWorkerExecutor
|
|
29
29
|
from cognite_toolkit._cdf_tk.utils.progress_tracker import AVAILABLE_STATUS, ProgressTracker, Status
|
|
30
30
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from collections.abc import Iterable, Mapping, Set
|
|
2
2
|
from typing import Any, ClassVar, cast
|
|
3
3
|
|
|
4
|
-
from cognite.client.data_classes import Annotation,
|
|
4
|
+
from cognite.client.data_classes import Annotation, Event, FileMetadata, TimeSeries
|
|
5
5
|
from cognite.client.data_classes.data_modeling import (
|
|
6
6
|
DirectRelation,
|
|
7
7
|
DirectRelationReference,
|
|
@@ -16,6 +16,7 @@ from cognite.client.data_classes.data_modeling.views import ViewProperty
|
|
|
16
16
|
from cognite.client.utils._identifier import InstanceId
|
|
17
17
|
|
|
18
18
|
from cognite_toolkit._cdf_tk.client import ToolkitClient
|
|
19
|
+
from cognite_toolkit._cdf_tk.client.data_classes.asset import AssetResponse
|
|
19
20
|
from cognite_toolkit._cdf_tk.client.data_classes.legacy.migration import (
|
|
20
21
|
AssetCentricId,
|
|
21
22
|
ResourceViewMappingApply,
|
|
@@ -25,10 +26,8 @@ from cognite_toolkit._cdf_tk.utils.dtype_conversion import (
|
|
|
25
26
|
asset_centric_convert_to_primary_property,
|
|
26
27
|
convert_to_primary_property,
|
|
27
28
|
)
|
|
28
|
-
from cognite_toolkit._cdf_tk.utils.useful_types import
|
|
29
|
-
|
|
30
|
-
AssetCentricTypeExtended,
|
|
31
|
-
)
|
|
29
|
+
from cognite_toolkit._cdf_tk.utils.useful_types import AssetCentricTypeExtended
|
|
30
|
+
from cognite_toolkit._cdf_tk.utils.useful_types2 import AssetCentricResourceExtended
|
|
32
31
|
|
|
33
32
|
from .data_model import COGNITE_MIGRATION_SPACE_ID, INSTANCE_SOURCE_VIEW_ID
|
|
34
33
|
from .issues import ConversionIssue, FailedConversion, InvalidPropertyDataType
|
|
@@ -111,7 +110,7 @@ class DirectRelationCache:
|
|
|
111
110
|
file_ids.add(file_id)
|
|
112
111
|
if isinstance(file_external_id := file_ref.get("externalId"), str):
|
|
113
112
|
file_external_ids.add(file_external_id)
|
|
114
|
-
elif isinstance(resource,
|
|
113
|
+
elif isinstance(resource, AssetResponse):
|
|
115
114
|
if resource.source:
|
|
116
115
|
source_ids.add(resource.source)
|
|
117
116
|
if resource.parent_id is not None:
|
|
@@ -245,7 +244,7 @@ def asset_centric_to_dm(
|
|
|
245
244
|
|
|
246
245
|
|
|
247
246
|
def _lookup_resource_type(resource_type: AssetCentricResourceExtended) -> AssetCentricTypeExtended:
|
|
248
|
-
if isinstance(resource_type,
|
|
247
|
+
if isinstance(resource_type, AssetResponse):
|
|
249
248
|
return "asset"
|
|
250
249
|
elif isinstance(resource_type, FileMetadata):
|
|
251
250
|
return "file"
|
|
@@ -12,6 +12,7 @@ from cognite.client.utils._text import to_camel_case
|
|
|
12
12
|
from pydantic import BaseModel, BeforeValidator, Field, field_validator, model_validator
|
|
13
13
|
|
|
14
14
|
from cognite_toolkit._cdf_tk.client.data_classes.base import BaseModelObject, RequestResource
|
|
15
|
+
from cognite_toolkit._cdf_tk.client.data_classes.identifiers import InternalId
|
|
15
16
|
from cognite_toolkit._cdf_tk.client.data_classes.instance_api import InstanceIdentifier
|
|
16
17
|
from cognite_toolkit._cdf_tk.client.data_classes.legacy.instances import InstanceApplyList
|
|
17
18
|
from cognite_toolkit._cdf_tk.client.data_classes.legacy.migration import AssetCentricId
|
|
@@ -26,8 +27,8 @@ from cognite_toolkit._cdf_tk.storageio._data_classes import ModelList
|
|
|
26
27
|
from cognite_toolkit._cdf_tk.utils.useful_types import (
|
|
27
28
|
AssetCentricKindExtended,
|
|
28
29
|
JsonVal,
|
|
29
|
-
T_AssetCentricResourceExtended,
|
|
30
30
|
)
|
|
31
|
+
from cognite_toolkit._cdf_tk.utils.useful_types2 import T_AssetCentricResourceExtended
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
class MigrationMapping(BaseModel, alias_generator=to_camel_case, extra="ignore", populate_by_name=True):
|
|
@@ -279,8 +280,8 @@ class ThreeDRevisionMigrationRequest(RequestResource):
|
|
|
279
280
|
revision_id: int
|
|
280
281
|
model: Model
|
|
281
282
|
|
|
282
|
-
def as_id(self) ->
|
|
283
|
-
return self.revision_id
|
|
283
|
+
def as_id(self) -> InternalId:
|
|
284
|
+
return InternalId(id=self.revision_id)
|
|
284
285
|
|
|
285
286
|
|
|
286
287
|
class ThreeDMigrationRequest(RequestResource):
|
|
@@ -290,5 +291,5 @@ class ThreeDMigrationRequest(RequestResource):
|
|
|
290
291
|
thumbnail: Thumbnail | None = None
|
|
291
292
|
revision: ThreeDRevisionMigrationRequest = Field(exclude=True)
|
|
292
293
|
|
|
293
|
-
def as_id(self) ->
|
|
294
|
-
return self.model_id
|
|
294
|
+
def as_id(self) -> InternalId:
|
|
295
|
+
return InternalId(id=self.model_id)
|
|
@@ -20,7 +20,7 @@ from cognite_toolkit._cdf_tk.client.data_classes.charts_data import (
|
|
|
20
20
|
ChartSource,
|
|
21
21
|
ChartTimeseries,
|
|
22
22
|
)
|
|
23
|
-
from cognite_toolkit._cdf_tk.client.data_classes.instance_api import InstanceIdentifier
|
|
23
|
+
from cognite_toolkit._cdf_tk.client.data_classes.instance_api import InstanceIdentifier, NodeReference
|
|
24
24
|
from cognite_toolkit._cdf_tk.client.data_classes.legacy.canvas import (
|
|
25
25
|
ContainerReferenceApply,
|
|
26
26
|
FdmInstanceContainerReferenceApply,
|
|
@@ -32,7 +32,6 @@ from cognite_toolkit._cdf_tk.client.data_classes.legacy.migration import Resourc
|
|
|
32
32
|
from cognite_toolkit._cdf_tk.client.data_classes.three_d import (
|
|
33
33
|
AssetMappingDMRequest,
|
|
34
34
|
AssetMappingResponse,
|
|
35
|
-
NodeReference,
|
|
36
35
|
RevisionStatus,
|
|
37
36
|
ThreeDModelResponse,
|
|
38
37
|
)
|
|
@@ -56,7 +55,7 @@ from cognite_toolkit._cdf_tk.protocols import T_ResourceRequest, T_ResourceRespo
|
|
|
56
55
|
from cognite_toolkit._cdf_tk.storageio._base import T_Selector
|
|
57
56
|
from cognite_toolkit._cdf_tk.storageio.selectors import CanvasSelector, ChartSelector, ThreeDSelector
|
|
58
57
|
from cognite_toolkit._cdf_tk.utils import humanize_collection
|
|
59
|
-
from cognite_toolkit._cdf_tk.utils.
|
|
58
|
+
from cognite_toolkit._cdf_tk.utils.useful_types2 import T_AssetCentricResourceExtended
|
|
60
59
|
|
|
61
60
|
from .data_classes import AssetCentricMapping
|
|
62
61
|
from .selectors import AssetCentricMigrationSelector
|
|
@@ -515,6 +514,9 @@ class ThreeDAssetMapper(DataMapper[ThreeDSelector, AssetMappingResponse, AssetMa
|
|
|
515
514
|
issue.error_message.append("Neither assetInstanceId nor assetId provided for mapping.")
|
|
516
515
|
return None, issue
|
|
517
516
|
mapped_request = AssetMappingDMRequest(
|
|
518
|
-
|
|
517
|
+
model_id=item.model_id,
|
|
518
|
+
revision_id=item.revision_id,
|
|
519
|
+
node_id=item.node_id,
|
|
520
|
+
asset_instance_id=asset_instance_id,
|
|
519
521
|
)
|
|
520
522
|
return mapped_request, issue
|
|
@@ -11,6 +11,15 @@ from cognite_toolkit._cdf_tk.client.data_classes.three_d import (
|
|
|
11
11
|
AssetMappingResponse,
|
|
12
12
|
ThreeDModelResponse,
|
|
13
13
|
)
|
|
14
|
+
from cognite_toolkit._cdf_tk.client.http_client import (
|
|
15
|
+
FailedResponse,
|
|
16
|
+
HTTPClient,
|
|
17
|
+
HTTPMessage,
|
|
18
|
+
ItemsRequest,
|
|
19
|
+
SimpleBodyRequest,
|
|
20
|
+
SuccessResponseItems,
|
|
21
|
+
ToolkitAPIError,
|
|
22
|
+
)
|
|
14
23
|
from cognite_toolkit._cdf_tk.commands._migrate.data_classes import ThreeDMigrationRequest
|
|
15
24
|
from cognite_toolkit._cdf_tk.constants import MISSING_EXTERNAL_ID, MISSING_INSTANCE_SPACE
|
|
16
25
|
from cognite_toolkit._cdf_tk.exceptions import ToolkitNotImplementedError, ToolkitValueError
|
|
@@ -29,21 +38,12 @@ from cognite_toolkit._cdf_tk.storageio.selectors import (
|
|
|
29
38
|
)
|
|
30
39
|
from cognite_toolkit._cdf_tk.tk_warnings import MediumSeverityWarning
|
|
31
40
|
from cognite_toolkit._cdf_tk.utils.collection import chunker_sequence
|
|
32
|
-
from cognite_toolkit._cdf_tk.utils.http_client import (
|
|
33
|
-
FailedResponse,
|
|
34
|
-
HTTPClient,
|
|
35
|
-
HTTPMessage,
|
|
36
|
-
ItemsRequest,
|
|
37
|
-
SimpleBodyRequest,
|
|
38
|
-
SuccessResponseItems,
|
|
39
|
-
ToolkitAPIError,
|
|
40
|
-
)
|
|
41
41
|
from cognite_toolkit._cdf_tk.utils.useful_types import (
|
|
42
42
|
AssetCentricKindExtended,
|
|
43
43
|
AssetCentricType,
|
|
44
44
|
JsonVal,
|
|
45
|
-
T_AssetCentricResource,
|
|
46
45
|
)
|
|
46
|
+
from cognite_toolkit._cdf_tk.utils.useful_types2 import T_AssetCentricResource
|
|
47
47
|
|
|
48
48
|
from .data_classes import (
|
|
49
49
|
AnnotationMapping,
|
|
@@ -17,6 +17,13 @@ from rich.panel import Panel
|
|
|
17
17
|
|
|
18
18
|
from cognite_toolkit._cdf_tk.client import ToolkitClient
|
|
19
19
|
from cognite_toolkit._cdf_tk.client.data_classes.instance_api import TypedInstanceIdentifier
|
|
20
|
+
from cognite_toolkit._cdf_tk.client.http_client import (
|
|
21
|
+
HTTPClient,
|
|
22
|
+
ItemsRequest,
|
|
23
|
+
ItemsRequest2,
|
|
24
|
+
ItemsSuccessResponse2,
|
|
25
|
+
SuccessResponseItems,
|
|
26
|
+
)
|
|
20
27
|
from cognite_toolkit._cdf_tk.cruds import (
|
|
21
28
|
AssetCRUD,
|
|
22
29
|
ContainerCRUD,
|
|
@@ -59,13 +66,6 @@ from cognite_toolkit._cdf_tk.utils.aggregators import (
|
|
|
59
66
|
SequenceAggregator,
|
|
60
67
|
TimeSeriesAggregator,
|
|
61
68
|
)
|
|
62
|
-
from cognite_toolkit._cdf_tk.utils.http_client import (
|
|
63
|
-
HTTPClient,
|
|
64
|
-
ItemsRequest,
|
|
65
|
-
ItemsRequest2,
|
|
66
|
-
ItemsSuccessResponse2,
|
|
67
|
-
SuccessResponseItems,
|
|
68
|
-
)
|
|
69
69
|
from cognite_toolkit._cdf_tk.utils.producer_worker import ProducerWorkerExecutor
|
|
70
70
|
from cognite_toolkit._cdf_tk.utils.useful_types import JsonVal
|
|
71
71
|
from cognite_toolkit._cdf_tk.utils.validate_access import ValidateAccess
|
|
@@ -9,6 +9,7 @@ from cognite.client.data_classes.data_modeling import (
|
|
|
9
9
|
from rich.console import Console
|
|
10
10
|
|
|
11
11
|
from cognite_toolkit._cdf_tk.client import ToolkitClient
|
|
12
|
+
from cognite_toolkit._cdf_tk.client.http_client import HTTPClient, ItemMessage, SuccessResponseItems
|
|
12
13
|
from cognite_toolkit._cdf_tk.constants import DATA_MANIFEST_SUFFIX, DATA_RESOURCE_DIR
|
|
13
14
|
from cognite_toolkit._cdf_tk.cruds import ViewCRUD
|
|
14
15
|
from cognite_toolkit._cdf_tk.exceptions import ToolkitValueError
|
|
@@ -24,7 +25,6 @@ from cognite_toolkit._cdf_tk.storageio.selectors._instances import InstanceSpace
|
|
|
24
25
|
from cognite_toolkit._cdf_tk.tk_warnings import HighSeverityWarning, MediumSeverityWarning, ToolkitWarning
|
|
25
26
|
from cognite_toolkit._cdf_tk.utils.auth import EnvironmentVariables
|
|
26
27
|
from cognite_toolkit._cdf_tk.utils.fileio import MultiFileReader
|
|
27
|
-
from cognite_toolkit._cdf_tk.utils.http_client import HTTPClient, ItemMessage, SuccessResponseItems
|
|
28
28
|
from cognite_toolkit._cdf_tk.utils.producer_worker import ProducerWorkerExecutor
|
|
29
29
|
from cognite_toolkit._cdf_tk.utils.progress_tracker import ProgressTracker
|
|
30
30
|
from cognite_toolkit._cdf_tk.utils.useful_types import JsonVal
|
|
@@ -6,10 +6,6 @@ from typing import Any, final
|
|
|
6
6
|
|
|
7
7
|
import pandas as pd
|
|
8
8
|
from cognite.client.data_classes import (
|
|
9
|
-
AggregateResultItem,
|
|
10
|
-
Asset,
|
|
11
|
-
AssetList,
|
|
12
|
-
AssetWrite,
|
|
13
9
|
Event,
|
|
14
10
|
EventList,
|
|
15
11
|
EventWrite,
|
|
@@ -24,6 +20,12 @@ from cognite.client.utils.useful_types import SequenceNotStr
|
|
|
24
20
|
from rich.console import Console
|
|
25
21
|
|
|
26
22
|
from cognite_toolkit._cdf_tk.client import ToolkitClient
|
|
23
|
+
from cognite_toolkit._cdf_tk.client.data_classes.asset import (
|
|
24
|
+
AssetAggregateItem,
|
|
25
|
+
AssetRequest,
|
|
26
|
+
AssetResponse,
|
|
27
|
+
)
|
|
28
|
+
from cognite_toolkit._cdf_tk.client.data_classes.identifiers import ExternalId, InternalOrExternalId
|
|
27
29
|
from cognite_toolkit._cdf_tk.client.data_classes.legacy.sequences import (
|
|
28
30
|
ToolkitSequenceRows,
|
|
29
31
|
ToolkitSequenceRowsList,
|
|
@@ -44,10 +46,10 @@ _DEPRECATION_WARNING_ISSUED = False
|
|
|
44
46
|
|
|
45
47
|
|
|
46
48
|
@final
|
|
47
|
-
class AssetCRUD(ResourceCRUD[
|
|
49
|
+
class AssetCRUD(ResourceCRUD[ExternalId, AssetRequest, AssetResponse]):
|
|
48
50
|
folder_name = "classic"
|
|
49
|
-
resource_cls =
|
|
50
|
-
resource_write_cls =
|
|
51
|
+
resource_cls = AssetResponse
|
|
52
|
+
resource_write_cls = AssetRequest
|
|
51
53
|
yaml_cls = AssetYAML
|
|
52
54
|
kind = "Asset"
|
|
53
55
|
dependencies = frozenset({DataSetsCRUD, LabelCRUD})
|
|
@@ -78,15 +80,15 @@ class AssetCRUD(ResourceCRUD[str, AssetWrite, Asset]):
|
|
|
78
80
|
return "assets"
|
|
79
81
|
|
|
80
82
|
@classmethod
|
|
81
|
-
def get_id(cls, item:
|
|
83
|
+
def get_id(cls, item: AssetRequest | AssetResponse | dict) -> ExternalId:
|
|
82
84
|
if isinstance(item, dict):
|
|
83
|
-
return item["externalId"]
|
|
85
|
+
return ExternalId(external_id=item["externalId"])
|
|
84
86
|
if not item.external_id:
|
|
85
87
|
raise KeyError("Asset must have external_id")
|
|
86
|
-
return item.external_id
|
|
88
|
+
return ExternalId(external_id=item.external_id)
|
|
87
89
|
|
|
88
90
|
@classmethod
|
|
89
|
-
def get_internal_id(cls, item:
|
|
91
|
+
def get_internal_id(cls, item: AssetResponse | dict) -> int:
|
|
90
92
|
if isinstance(item, dict):
|
|
91
93
|
return item["id"]
|
|
92
94
|
if not item.id:
|
|
@@ -94,12 +96,12 @@ class AssetCRUD(ResourceCRUD[str, AssetWrite, Asset]):
|
|
|
94
96
|
return item.id
|
|
95
97
|
|
|
96
98
|
@classmethod
|
|
97
|
-
def dump_id(cls, id:
|
|
98
|
-
return
|
|
99
|
+
def dump_id(cls, id: ExternalId) -> dict[str, Any]:
|
|
100
|
+
return id.dump()
|
|
99
101
|
|
|
100
102
|
@classmethod
|
|
101
103
|
def get_required_capability(
|
|
102
|
-
cls, items: collections.abc.Sequence[
|
|
104
|
+
cls, items: collections.abc.Sequence[AssetRequest] | None, read_only: bool
|
|
103
105
|
) -> Capability | list[Capability]:
|
|
104
106
|
if not items and items is not None:
|
|
105
107
|
return []
|
|
@@ -119,45 +121,39 @@ class AssetCRUD(ResourceCRUD[str, AssetWrite, Asset]):
|
|
|
119
121
|
|
|
120
122
|
return capabilities.AssetsAcl(actions, scope)
|
|
121
123
|
|
|
122
|
-
def create(self, items: Sequence[
|
|
123
|
-
return self.client.assets.create(items)
|
|
124
|
+
def create(self, items: collections.abc.Sequence[AssetRequest]) -> list[AssetResponse]:
|
|
125
|
+
return self.client.tool.assets.create(items)
|
|
124
126
|
|
|
125
|
-
def retrieve(self, ids: SequenceNotStr[
|
|
126
|
-
return self.client.assets.
|
|
127
|
+
def retrieve(self, ids: SequenceNotStr[ExternalId]) -> list[AssetResponse]:
|
|
128
|
+
return self.client.tool.assets.retrieve(list(ids), ignore_unknown_ids=True)
|
|
127
129
|
|
|
128
|
-
def update(self, items: Sequence[
|
|
129
|
-
return self.client.assets.update(items, mode="replace")
|
|
130
|
+
def update(self, items: collections.abc.Sequence[AssetRequest]) -> list[AssetResponse]:
|
|
131
|
+
return self.client.tool.assets.update(items, mode="replace")
|
|
130
132
|
|
|
131
|
-
def delete(self, ids: SequenceNotStr[
|
|
133
|
+
def delete(self, ids: SequenceNotStr[InternalOrExternalId]) -> int:
|
|
132
134
|
if not ids:
|
|
133
135
|
return 0
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
self.client.assets.delete(id=internal_ids, external_id=external_ids)
|
|
137
|
-
except CogniteNotFoundError as e:
|
|
138
|
-
# Do a CogniteNotFoundError instead of passing 'ignore_unknown_ids=True' to the delete method
|
|
139
|
-
# to obtain an accurate list of deleted assets.
|
|
140
|
-
non_existing = set(e.failed or [])
|
|
141
|
-
if existing := [id_ for id_ in ids if id_ not in non_existing]:
|
|
142
|
-
internal_ids, external_ids = self._split_ids(existing)
|
|
143
|
-
self.client.assets.delete(id=internal_ids, external_id=external_ids)
|
|
144
|
-
return len(existing)
|
|
145
|
-
else:
|
|
146
|
-
return len(ids)
|
|
136
|
+
self.client.tool.assets.delete(list(ids), ignore_unknown_ids=True)
|
|
137
|
+
return len(ids)
|
|
147
138
|
|
|
148
139
|
def _iterate(
|
|
149
140
|
self,
|
|
150
141
|
data_set_external_id: str | None = None,
|
|
151
142
|
space: str | None = None,
|
|
152
143
|
parent_ids: list[Hashable] | None = None,
|
|
153
|
-
) -> Iterable[
|
|
154
|
-
|
|
155
|
-
|
|
144
|
+
) -> Iterable[AssetResponse]:
|
|
145
|
+
cursor: str | None = None
|
|
146
|
+
while True:
|
|
147
|
+
page = self.client.tool.assets.iterate(
|
|
148
|
+
limit=1000,
|
|
149
|
+
cursor=cursor,
|
|
156
150
|
data_set_external_ids=[data_set_external_id] if data_set_external_id else None,
|
|
157
|
-
|
|
158
|
-
aggregated_properties=["depth", "child_count", "path"],
|
|
151
|
+
aggregated_properties=True,
|
|
159
152
|
)
|
|
160
|
-
|
|
153
|
+
yield from page.items
|
|
154
|
+
if not page.next_cursor or not page.items:
|
|
155
|
+
break
|
|
156
|
+
cursor = page.next_cursor
|
|
161
157
|
|
|
162
158
|
@classmethod
|
|
163
159
|
def get_dependent_items(cls, item: dict) -> Iterable[tuple[type[ResourceCRUD], Hashable]]:
|
|
@@ -202,7 +198,7 @@ class AssetCRUD(ResourceCRUD[str, AssetWrite, Asset]):
|
|
|
202
198
|
|
|
203
199
|
return resources
|
|
204
200
|
|
|
205
|
-
def load_resource(self, resource: dict[str, Any], is_dry_run: bool = False) ->
|
|
201
|
+
def load_resource(self, resource: dict[str, Any], is_dry_run: bool = False) -> AssetRequest:
|
|
206
202
|
# Unpack metadata keys from table formats (e.g. csv, parquet)
|
|
207
203
|
metadata: dict = resource.get("metadata", {})
|
|
208
204
|
for key, value in list(resource.items()):
|
|
@@ -219,10 +215,10 @@ class AssetCRUD(ResourceCRUD[str, AssetWrite, Asset]):
|
|
|
219
215
|
|
|
220
216
|
if ds_external_id := resource.pop("dataSetExternalId", None):
|
|
221
217
|
resource["dataSetId"] = self.client.lookup.data_sets.id(ds_external_id, is_dry_run)
|
|
222
|
-
return
|
|
218
|
+
return AssetRequest.model_validate(resource)
|
|
223
219
|
|
|
224
|
-
def dump_resource(self, resource:
|
|
225
|
-
dumped = resource.
|
|
220
|
+
def dump_resource(self, resource: AssetResponse, local: dict[str, Any] | None = None) -> dict[str, Any]:
|
|
221
|
+
dumped = resource.as_request_resource().dump()
|
|
226
222
|
local = local or {}
|
|
227
223
|
if data_set_id := dumped.pop("dataSetId", None):
|
|
228
224
|
dumped["dataSetExternalId"] = self.client.lookup.data_sets.external_id(data_set_id)
|
|
@@ -234,7 +230,7 @@ class AssetCRUD(ResourceCRUD[str, AssetWrite, Asset]):
|
|
|
234
230
|
# This is only included when the asset is downloaded/migrated with aggregated properties
|
|
235
231
|
aggregates = (
|
|
236
232
|
resource.aggregates.dump()
|
|
237
|
-
if isinstance(resource.aggregates,
|
|
233
|
+
if isinstance(resource.aggregates, AssetAggregateItem)
|
|
238
234
|
else resource.aggregates
|
|
239
235
|
)
|
|
240
236
|
if "path" in aggregates:
|
|
@@ -372,7 +368,7 @@ class SequenceCRUD(ResourceCRUD[str, SequenceWrite, CDFSequence]):
|
|
|
372
368
|
if "dataSetExternalId" in item:
|
|
373
369
|
yield DataSetsCRUD, item["dataSetExternalId"]
|
|
374
370
|
if "assetExternalId" in item:
|
|
375
|
-
yield AssetCRUD, item["assetExternalId"]
|
|
371
|
+
yield AssetCRUD, ExternalId(external_id=item["assetExternalId"])
|
|
376
372
|
|
|
377
373
|
|
|
378
374
|
@final
|
|
@@ -596,7 +592,7 @@ class EventCRUD(ResourceCRUD[str, EventWrite, Event]):
|
|
|
596
592
|
yield DataSetsCRUD, item["dataSetExternalId"]
|
|
597
593
|
for asset_id in item.get("assetExternalIds", []):
|
|
598
594
|
if isinstance(asset_id, str):
|
|
599
|
-
yield AssetCRUD, asset_id
|
|
595
|
+
yield AssetCRUD, ExternalId(external_id=asset_id)
|
|
600
596
|
|
|
601
597
|
def load_resource(self, resource: dict[str, Any], is_dry_run: bool = False) -> EventWrite:
|
|
602
598
|
if ds_external_id := resource.get("dataSetExternalId", None):
|
|
@@ -8,6 +8,7 @@ from cognite.client.data_classes.data_modeling import NodeApplyResultList, NodeI
|
|
|
8
8
|
from cognite.client.exceptions import CogniteAPIError
|
|
9
9
|
from cognite.client.utils.useful_types import SequenceNotStr
|
|
10
10
|
|
|
11
|
+
from cognite_toolkit._cdf_tk.client.data_classes.identifiers import ExternalId
|
|
11
12
|
from cognite_toolkit._cdf_tk.client.data_classes.infield import (
|
|
12
13
|
InFieldCDMLocationConfig,
|
|
13
14
|
InfieldLocationConfig,
|
|
@@ -139,7 +140,7 @@ class InfieldV1CRUD(ResourceCRUD[str, APMConfigWrite, APMConfig]):
|
|
|
139
140
|
yield SpaceCRUD, customer_data_space_id
|
|
140
141
|
for config in cls._get_root_location_configurations(item) or []:
|
|
141
142
|
if isinstance(asset_external_id := config.get("assetExternalId"), str):
|
|
142
|
-
yield AssetCRUD, asset_external_id
|
|
143
|
+
yield AssetCRUD, ExternalId(external_id=asset_external_id)
|
|
143
144
|
if isinstance(data_set_external_id := config.get("dataSetExternalId"), str):
|
|
144
145
|
yield DataSetsCRUD, data_set_external_id
|
|
145
146
|
if isinstance(app_data_instance_space := config.get("appDataInstanceSpace"), str):
|
|
@@ -162,7 +163,7 @@ class InfieldV1CRUD(ResourceCRUD[str, APMConfigWrite, APMConfig]):
|
|
|
162
163
|
yield DataSetsCRUD, data_set_external_id
|
|
163
164
|
for asset_external_id in filter_.get("assetSubtreeExternalIds", []):
|
|
164
165
|
if isinstance(asset_external_id, str):
|
|
165
|
-
yield AssetCRUD, asset_external_id
|
|
166
|
+
yield AssetCRUD, ExternalId(external_id=asset_external_id)
|
|
166
167
|
if app_data_instance_space := filter_.get("appDataInstanceSpace"):
|
|
167
168
|
if isinstance(app_data_instance_space, str):
|
|
168
169
|
yield SpaceCRUD, app_data_instance_space
|
|
@@ -267,7 +268,10 @@ class InFieldLocationConfigCRUD(ResourceCRUD[TypedNodeIdentifier, InfieldLocatio
|
|
|
267
268
|
|
|
268
269
|
@classmethod
|
|
269
270
|
def dump_id(cls, id: TypedNodeIdentifier) -> dict[str, Any]:
|
|
270
|
-
return
|
|
271
|
+
return {
|
|
272
|
+
"space": id.space,
|
|
273
|
+
"externalId": id.external_id,
|
|
274
|
+
}
|
|
271
275
|
|
|
272
276
|
@classmethod
|
|
273
277
|
def get_required_capability(
|
|
@@ -368,7 +372,10 @@ class InFieldCDMLocationConfigCRUD(
|
|
|
368
372
|
|
|
369
373
|
@classmethod
|
|
370
374
|
def dump_id(cls, id: TypedNodeIdentifier) -> dict[str, Any]:
|
|
371
|
-
return
|
|
375
|
+
return {
|
|
376
|
+
"space": id.space,
|
|
377
|
+
"externalId": id.external_id,
|
|
378
|
+
}
|
|
372
379
|
|
|
373
380
|
@classmethod
|
|
374
381
|
def get_required_capability(
|
|
@@ -33,6 +33,7 @@ from cognite.client.utils._time import convert_data_modelling_timestamp
|
|
|
33
33
|
from cognite.client.utils.useful_types import SequenceNotStr
|
|
34
34
|
from rich import print
|
|
35
35
|
|
|
36
|
+
from cognite_toolkit._cdf_tk.client.data_classes.identifiers import ExternalId
|
|
36
37
|
from cognite_toolkit._cdf_tk.client.data_classes.legacy.extendable_cognite_file import (
|
|
37
38
|
ExtendableCogniteFile,
|
|
38
39
|
ExtendableCogniteFileApply,
|
|
@@ -118,7 +119,7 @@ class FileMetadataCRUD(ResourceContainerCRUD[str, FileMetadataWrite, FileMetadat
|
|
|
118
119
|
elif isinstance(label, str):
|
|
119
120
|
yield LabelCRUD, label
|
|
120
121
|
for asset_external_id in item.get("assetExternalIds", []):
|
|
121
|
-
yield AssetCRUD, asset_external_id
|
|
122
|
+
yield AssetCRUD, ExternalId(external_id=asset_external_id)
|
|
122
123
|
|
|
123
124
|
def load_resource(self, resource: dict[str, Any], is_dry_run: bool = False) -> FileMetadataWrite:
|
|
124
125
|
if resource.get("dataSetExternalId") is not None:
|
|
@@ -7,6 +7,7 @@ from cognite.client.data_classes.capabilities import Capability, LocationFilters
|
|
|
7
7
|
from cognite.client.data_classes.data_modeling import DataModelId, ViewId
|
|
8
8
|
from cognite.client.utils.useful_types import SequenceNotStr
|
|
9
9
|
|
|
10
|
+
from cognite_toolkit._cdf_tk.client.data_classes.identifiers import ExternalId
|
|
10
11
|
from cognite_toolkit._cdf_tk.client.data_classes.legacy.location_filters import (
|
|
11
12
|
LocationFilter,
|
|
12
13
|
LocationFilterList,
|
|
@@ -239,14 +240,14 @@ class LocationFilterCRUD(ResourceCRUD[str, LocationFilterWrite, LocationFilter])
|
|
|
239
240
|
yield DataSetsCRUD, data_set_external_id
|
|
240
241
|
for asset in asset_centric.get("assetSubtreeIds", []):
|
|
241
242
|
if "externalId" in asset:
|
|
242
|
-
yield AssetCRUD, asset["externalId"]
|
|
243
|
+
yield AssetCRUD, ExternalId(external_id=asset["externalId"])
|
|
243
244
|
for subfilter_name in cls.subfilter_names:
|
|
244
245
|
subfilter = asset_centric.get(subfilter_name, {})
|
|
245
246
|
for data_set_external_id in subfilter.get("dataSetExternalIds", []):
|
|
246
247
|
yield DataSetsCRUD, data_set_external_id
|
|
247
248
|
for asset in subfilter.get("assetSubtreeIds", []):
|
|
248
249
|
if "externalId" in asset:
|
|
249
|
-
yield AssetCRUD, asset["externalId"]
|
|
250
|
+
yield AssetCRUD, ExternalId(external_id=asset["externalId"])
|
|
250
251
|
for view in item.get("views", []):
|
|
251
252
|
if in_dict(["space", "externalId", "version"], view):
|
|
252
253
|
yield ViewCRUD, ViewId(view["space"], view["externalId"], view["version"])
|
|
@@ -11,6 +11,7 @@ from cognite.client.data_classes.capabilities import Capability
|
|
|
11
11
|
from cognite.client.exceptions import CogniteAPIError, CogniteNotFoundError
|
|
12
12
|
from cognite.client.utils.useful_types import SequenceNotStr
|
|
13
13
|
|
|
14
|
+
from cognite_toolkit._cdf_tk.client.data_classes.identifiers import ExternalId
|
|
14
15
|
from cognite_toolkit._cdf_tk.cruds._base_cruds import ResourceCRUD
|
|
15
16
|
from cognite_toolkit._cdf_tk.resource_classes import RelationshipYAML
|
|
16
17
|
|
|
@@ -123,7 +124,7 @@ class RelationshipCRUD(ResourceCRUD[str, RelationshipWrite, Relationship]):
|
|
|
123
124
|
if isinstance(id_value, str) and isinstance(type_value, str):
|
|
124
125
|
type_value = type_value.strip().casefold()
|
|
125
126
|
if type_value == "asset":
|
|
126
|
-
yield AssetCRUD, id_value
|
|
127
|
+
yield AssetCRUD, ExternalId(external_id=id_value)
|
|
127
128
|
elif type_value == "sequence":
|
|
128
129
|
yield SequenceCRUD, id_value
|
|
129
130
|
elif type_value == "timeseries":
|
|
@@ -9,9 +9,9 @@ from cognite_toolkit._cdf_tk.client.data_classes.streams import (
|
|
|
9
9
|
StreamResponse,
|
|
10
10
|
StreamResponseList,
|
|
11
11
|
)
|
|
12
|
+
from cognite_toolkit._cdf_tk.client.http_client import ToolkitAPIError
|
|
12
13
|
from cognite_toolkit._cdf_tk.cruds._base_cruds import ResourceCRUD
|
|
13
14
|
from cognite_toolkit._cdf_tk.resource_classes import StreamYAML
|
|
14
|
-
from cognite_toolkit._cdf_tk.utils.http_client import ToolkitAPIError
|
|
15
15
|
|
|
16
16
|
from .datamodel import ContainerCRUD
|
|
17
17
|
|