cognite-toolkit 0.6.97__py3-none-any.whl → 0.7.39__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.py +21 -23
- cognite_toolkit/_cdf_tk/apps/__init__.py +4 -0
- cognite_toolkit/_cdf_tk/apps/_core_app.py +19 -5
- cognite_toolkit/_cdf_tk/apps/_data_app.py +1 -1
- cognite_toolkit/_cdf_tk/apps/_dev_app.py +86 -0
- cognite_toolkit/_cdf_tk/apps/_download_app.py +693 -25
- cognite_toolkit/_cdf_tk/apps/_dump_app.py +44 -102
- cognite_toolkit/_cdf_tk/apps/_import_app.py +41 -0
- cognite_toolkit/_cdf_tk/apps/_landing_app.py +18 -4
- cognite_toolkit/_cdf_tk/apps/_migrate_app.py +424 -9
- cognite_toolkit/_cdf_tk/apps/_modules_app.py +0 -3
- cognite_toolkit/_cdf_tk/apps/_purge.py +15 -43
- cognite_toolkit/_cdf_tk/apps/_run.py +11 -0
- cognite_toolkit/_cdf_tk/apps/_upload_app.py +45 -6
- cognite_toolkit/_cdf_tk/builders/__init__.py +2 -2
- cognite_toolkit/_cdf_tk/builders/_base.py +28 -42
- cognite_toolkit/_cdf_tk/builders/_raw.py +1 -1
- cognite_toolkit/_cdf_tk/cdf_toml.py +20 -1
- cognite_toolkit/_cdf_tk/client/_toolkit_client.py +32 -12
- cognite_toolkit/_cdf_tk/client/api/infield.py +114 -17
- cognite_toolkit/_cdf_tk/client/api/{canvas.py → legacy/canvas.py} +15 -7
- cognite_toolkit/_cdf_tk/client/api/{charts.py → legacy/charts.py} +1 -1
- cognite_toolkit/_cdf_tk/client/api/{extended_data_modeling.py → legacy/extended_data_modeling.py} +1 -1
- cognite_toolkit/_cdf_tk/client/api/{extended_files.py → legacy/extended_files.py} +2 -2
- cognite_toolkit/_cdf_tk/client/api/{extended_functions.py → legacy/extended_functions.py} +15 -18
- cognite_toolkit/_cdf_tk/client/api/{extended_raw.py → legacy/extended_raw.py} +1 -1
- cognite_toolkit/_cdf_tk/client/api/{extended_timeseries.py → legacy/extended_timeseries.py} +5 -2
- cognite_toolkit/_cdf_tk/client/api/{location_filters.py → legacy/location_filters.py} +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/robotics/__init__.py +8 -0
- cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/capabilities.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/data_postprocessing.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/frames.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/locations.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/maps.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/robots.py +2 -2
- cognite_toolkit/_cdf_tk/client/api/{search_config.py → legacy/search_config.py} +5 -1
- cognite_toolkit/_cdf_tk/client/api/migration.py +177 -4
- cognite_toolkit/_cdf_tk/client/api/project.py +9 -8
- cognite_toolkit/_cdf_tk/client/api/search.py +2 -2
- cognite_toolkit/_cdf_tk/client/api/streams.py +88 -0
- cognite_toolkit/_cdf_tk/client/api/three_d.py +384 -0
- cognite_toolkit/_cdf_tk/client/data_classes/api_classes.py +13 -0
- cognite_toolkit/_cdf_tk/client/data_classes/base.py +37 -33
- cognite_toolkit/_cdf_tk/client/data_classes/charts_data.py +95 -213
- cognite_toolkit/_cdf_tk/client/data_classes/infield.py +32 -18
- cognite_toolkit/_cdf_tk/client/data_classes/instance_api.py +18 -13
- cognite_toolkit/_cdf_tk/client/data_classes/legacy/__init__.py +0 -0
- cognite_toolkit/_cdf_tk/client/data_classes/{canvas.py → legacy/canvas.py} +47 -4
- cognite_toolkit/_cdf_tk/client/data_classes/{charts.py → legacy/charts.py} +3 -3
- cognite_toolkit/_cdf_tk/client/data_classes/{migration.py → legacy/migration.py} +10 -2
- cognite_toolkit/_cdf_tk/client/data_classes/streams.py +90 -0
- cognite_toolkit/_cdf_tk/client/data_classes/three_d.py +112 -0
- cognite_toolkit/_cdf_tk/client/testing.py +42 -18
- cognite_toolkit/_cdf_tk/commands/__init__.py +7 -6
- cognite_toolkit/_cdf_tk/commands/_changes.py +3 -42
- cognite_toolkit/_cdf_tk/commands/_download.py +21 -11
- cognite_toolkit/_cdf_tk/commands/_migrate/__init__.py +0 -2
- cognite_toolkit/_cdf_tk/commands/_migrate/command.py +22 -20
- cognite_toolkit/_cdf_tk/commands/_migrate/conversion.py +140 -92
- cognite_toolkit/_cdf_tk/commands/_migrate/creators.py +1 -1
- cognite_toolkit/_cdf_tk/commands/_migrate/data_classes.py +108 -26
- cognite_toolkit/_cdf_tk/commands/_migrate/data_mapper.py +448 -45
- cognite_toolkit/_cdf_tk/commands/_migrate/data_model.py +1 -0
- cognite_toolkit/_cdf_tk/commands/_migrate/default_mappings.py +6 -6
- cognite_toolkit/_cdf_tk/commands/_migrate/issues.py +52 -1
- cognite_toolkit/_cdf_tk/commands/_migrate/migration_io.py +377 -11
- cognite_toolkit/_cdf_tk/commands/_migrate/selectors.py +9 -4
- cognite_toolkit/_cdf_tk/commands/_profile.py +1 -1
- cognite_toolkit/_cdf_tk/commands/_purge.py +36 -39
- cognite_toolkit/_cdf_tk/commands/_questionary_style.py +16 -0
- cognite_toolkit/_cdf_tk/commands/_upload.py +109 -86
- cognite_toolkit/_cdf_tk/commands/about.py +221 -0
- cognite_toolkit/_cdf_tk/commands/auth.py +19 -12
- cognite_toolkit/_cdf_tk/commands/build_cmd.py +16 -62
- cognite_toolkit/_cdf_tk/commands/build_v2/__init__.py +0 -0
- cognite_toolkit/_cdf_tk/commands/build_v2/build_cmd.py +241 -0
- cognite_toolkit/_cdf_tk/commands/build_v2/build_input.py +85 -0
- cognite_toolkit/_cdf_tk/commands/build_v2/build_issues.py +27 -0
- cognite_toolkit/_cdf_tk/commands/clean.py +63 -16
- cognite_toolkit/_cdf_tk/commands/deploy.py +20 -17
- cognite_toolkit/_cdf_tk/commands/dump_resource.py +10 -8
- cognite_toolkit/_cdf_tk/commands/init.py +225 -3
- cognite_toolkit/_cdf_tk/commands/modules.py +20 -44
- cognite_toolkit/_cdf_tk/commands/pull.py +6 -19
- cognite_toolkit/_cdf_tk/commands/resources.py +179 -0
- cognite_toolkit/_cdf_tk/commands/run.py +1 -1
- cognite_toolkit/_cdf_tk/constants.py +20 -1
- cognite_toolkit/_cdf_tk/cruds/__init__.py +19 -5
- cognite_toolkit/_cdf_tk/cruds/_base_cruds.py +14 -70
- cognite_toolkit/_cdf_tk/cruds/_data_cruds.py +10 -19
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/__init__.py +4 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/agent.py +11 -9
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/auth.py +5 -15
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/classic.py +45 -44
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/configuration.py +5 -12
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/data_organization.py +4 -13
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/datamodel.py +206 -67
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/extraction_pipeline.py +6 -18
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/fieldops.py +126 -35
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/file.py +7 -28
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/function.py +23 -30
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/hosted_extractors.py +12 -30
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/industrial_tool.py +4 -8
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/location.py +4 -16
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/migration.py +5 -13
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/raw.py +5 -11
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/relationship.py +3 -8
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/robotics.py +16 -45
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/streams.py +94 -0
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/three_d_model.py +3 -7
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/timeseries.py +5 -15
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/transformation.py +75 -32
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/workflow.py +20 -40
- cognite_toolkit/_cdf_tk/cruds/_worker.py +24 -36
- cognite_toolkit/_cdf_tk/data_classes/_module_toml.py +1 -0
- cognite_toolkit/_cdf_tk/feature_flags.py +16 -36
- cognite_toolkit/_cdf_tk/plugins.py +2 -1
- cognite_toolkit/_cdf_tk/resource_classes/__init__.py +4 -0
- cognite_toolkit/_cdf_tk/resource_classes/capabilities.py +12 -0
- cognite_toolkit/_cdf_tk/resource_classes/functions.py +3 -1
- cognite_toolkit/_cdf_tk/resource_classes/infield_cdm_location_config.py +109 -0
- cognite_toolkit/_cdf_tk/resource_classes/migration.py +8 -17
- cognite_toolkit/_cdf_tk/resource_classes/search_config.py +1 -1
- cognite_toolkit/_cdf_tk/resource_classes/streams.py +29 -0
- cognite_toolkit/_cdf_tk/resource_classes/workflow_version.py +164 -5
- cognite_toolkit/_cdf_tk/storageio/__init__.py +9 -21
- cognite_toolkit/_cdf_tk/storageio/_annotations.py +19 -16
- cognite_toolkit/_cdf_tk/storageio/_applications.py +340 -28
- cognite_toolkit/_cdf_tk/storageio/_asset_centric.py +67 -104
- cognite_toolkit/_cdf_tk/storageio/_base.py +61 -29
- cognite_toolkit/_cdf_tk/storageio/_datapoints.py +276 -20
- cognite_toolkit/_cdf_tk/storageio/_file_content.py +435 -0
- cognite_toolkit/_cdf_tk/storageio/_instances.py +35 -3
- cognite_toolkit/_cdf_tk/storageio/_raw.py +26 -0
- cognite_toolkit/_cdf_tk/storageio/selectors/__init__.py +71 -4
- cognite_toolkit/_cdf_tk/storageio/selectors/_base.py +14 -2
- cognite_toolkit/_cdf_tk/storageio/selectors/_canvas.py +14 -0
- cognite_toolkit/_cdf_tk/storageio/selectors/_charts.py +14 -0
- cognite_toolkit/_cdf_tk/storageio/selectors/_datapoints.py +23 -3
- cognite_toolkit/_cdf_tk/storageio/selectors/_file_content.py +164 -0
- cognite_toolkit/_cdf_tk/storageio/selectors/_three_d.py +34 -0
- cognite_toolkit/_cdf_tk/tk_warnings/other.py +4 -0
- cognite_toolkit/_cdf_tk/tracker.py +2 -2
- cognite_toolkit/_cdf_tk/utils/cdf.py +1 -1
- cognite_toolkit/_cdf_tk/utils/dtype_conversion.py +9 -3
- cognite_toolkit/_cdf_tk/utils/fileio/__init__.py +2 -0
- cognite_toolkit/_cdf_tk/utils/fileio/_base.py +5 -1
- cognite_toolkit/_cdf_tk/utils/fileio/_readers.py +112 -20
- cognite_toolkit/_cdf_tk/utils/fileio/_writers.py +15 -15
- cognite_toolkit/_cdf_tk/utils/http_client/__init__.py +28 -0
- cognite_toolkit/_cdf_tk/utils/http_client/_client.py +285 -18
- cognite_toolkit/_cdf_tk/utils/http_client/_data_classes.py +56 -4
- cognite_toolkit/_cdf_tk/utils/http_client/_data_classes2.py +247 -0
- cognite_toolkit/_cdf_tk/utils/http_client/_tracker.py +5 -2
- cognite_toolkit/_cdf_tk/utils/interactive_select.py +60 -18
- cognite_toolkit/_cdf_tk/utils/sql_parser.py +2 -3
- cognite_toolkit/_cdf_tk/utils/useful_types.py +6 -2
- cognite_toolkit/_cdf_tk/validation.py +83 -1
- 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 +5 -4
- cognite_toolkit/_version.py +1 -1
- cognite_toolkit/config.dev.yaml +13 -0
- {cognite_toolkit-0.6.97.dist-info → cognite_toolkit-0.7.39.dist-info}/METADATA +24 -24
- cognite_toolkit-0.7.39.dist-info/RECORD +322 -0
- cognite_toolkit-0.7.39.dist-info/WHEEL +4 -0
- {cognite_toolkit-0.6.97.dist-info → cognite_toolkit-0.7.39.dist-info}/entry_points.txt +1 -0
- cognite_toolkit/_cdf_tk/client/api/robotics/__init__.py +0 -3
- cognite_toolkit/_cdf_tk/commands/_migrate/canvas.py +0 -201
- cognite_toolkit/_cdf_tk/commands/dump_data.py +0 -489
- cognite_toolkit/_cdf_tk/commands/featureflag.py +0 -27
- cognite_toolkit/_cdf_tk/prototypes/import_app.py +0 -41
- cognite_toolkit/_cdf_tk/utils/table_writers.py +0 -434
- cognite_toolkit-0.6.97.dist-info/RECORD +0 -306
- cognite_toolkit-0.6.97.dist-info/WHEEL +0 -4
- cognite_toolkit-0.6.97.dist-info/licenses/LICENSE +0 -18
- /cognite_toolkit/_cdf_tk/{prototypes/commands → client/api/legacy}/__init__.py +0 -0
- /cognite_toolkit/_cdf_tk/client/api/{dml.py → legacy/dml.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/api/{fixed_transformations.py → legacy/fixed_transformations.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/api.py +0 -0
- /cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/utlis.py +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{apm_config_v1.py → legacy/apm_config_v1.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{extendable_cognite_file.py → legacy/extendable_cognite_file.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{extended_filemetadata.py → legacy/extended_filemetadata.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{extended_filemetdata.py → legacy/extended_filemetdata.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{extended_timeseries.py → legacy/extended_timeseries.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{functions.py → legacy/functions.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{graphql_data_models.py → legacy/graphql_data_models.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{instances.py → legacy/instances.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{location_filters.py → legacy/location_filters.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{pending_instances_ids.py → legacy/pending_instances_ids.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{project.py → legacy/project.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{raw.py → legacy/raw.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{robotics.py → legacy/robotics.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{search_config.py → legacy/search_config.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{sequences.py → legacy/sequences.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{streamlit_.py → legacy/streamlit_.py} +0 -0
- /cognite_toolkit/_cdf_tk/{prototypes/commands/import_.py → commands/_import_cmd.py} +0 -0
|
@@ -16,7 +16,7 @@ from cognite.client.data_classes.data_modeling.instances import (
|
|
|
16
16
|
|
|
17
17
|
from cognite_toolkit._cdf_tk.constants import COGNITE_MIGRATION_SPACE
|
|
18
18
|
from cognite_toolkit._cdf_tk.tk_warnings import IgnoredValueWarning
|
|
19
|
-
from cognite_toolkit._cdf_tk.utils.useful_types import AssetCentricType
|
|
19
|
+
from cognite_toolkit._cdf_tk.utils.useful_types import AssetCentricType, AssetCentricTypeExtended
|
|
20
20
|
|
|
21
21
|
if sys.version_info >= (3, 11):
|
|
22
22
|
from typing import Self
|
|
@@ -26,7 +26,7 @@ else:
|
|
|
26
26
|
|
|
27
27
|
@dataclass(frozen=True)
|
|
28
28
|
class AssetCentricId(CogniteObject):
|
|
29
|
-
resource_type:
|
|
29
|
+
resource_type: AssetCentricTypeExtended
|
|
30
30
|
id_: int
|
|
31
31
|
|
|
32
32
|
@classmethod
|
|
@@ -114,6 +114,14 @@ class InstanceSource(_InstanceSourceProperties, TypedNode):
|
|
|
114
114
|
self.preferred_consumer_view_id = preferred_consumer_view_id
|
|
115
115
|
self.ingestion_view = DirectRelationReference.load(ingestion_view) if ingestion_view else None
|
|
116
116
|
|
|
117
|
+
def dump(self, camel_case: bool = True) -> dict[str, Any]:
|
|
118
|
+
output = super().dump(camel_case)
|
|
119
|
+
if self.preferred_consumer_view_id:
|
|
120
|
+
output["properties"]["cognite_migration"]["InstanceSource/v1"]["preferredConsumerViewId"] = (
|
|
121
|
+
self.preferred_consumer_view_id.dump(camel_case=camel_case)
|
|
122
|
+
)
|
|
123
|
+
return output
|
|
124
|
+
|
|
117
125
|
@classmethod
|
|
118
126
|
def _load_properties(cls, resource: dict[str, Any]) -> dict[str, Any]:
|
|
119
127
|
if "preferredConsumerViewId" in resource:
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
from typing import Literal
|
|
2
|
+
|
|
3
|
+
from cognite_toolkit._cdf_tk.constants import StreamTemplateName
|
|
4
|
+
from cognite_toolkit._cdf_tk.protocols import (
|
|
5
|
+
ResourceRequestListProtocol,
|
|
6
|
+
ResourceResponseListProtocol,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
from .base import BaseModelObject, BaseResourceList, RequestResource, ResponseResource
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class StreamRequest(RequestResource):
|
|
13
|
+
"""Stream request resource class."""
|
|
14
|
+
|
|
15
|
+
external_id: str
|
|
16
|
+
settings: dict[Literal["template"], dict[Literal["name"], StreamTemplateName]]
|
|
17
|
+
|
|
18
|
+
def as_id(self) -> str:
|
|
19
|
+
return self.external_id
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class StreamRequestList(BaseResourceList[StreamRequest], ResourceRequestListProtocol):
|
|
23
|
+
"""List of Stream request resources."""
|
|
24
|
+
|
|
25
|
+
_RESOURCE = StreamRequest
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class LifecycleObject(BaseModelObject):
|
|
29
|
+
"""Lifecycle object."""
|
|
30
|
+
|
|
31
|
+
hot_phase_duration: str | None = None
|
|
32
|
+
data_deleted_after: str | None = None
|
|
33
|
+
retained_after_soft_delete: str
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class ResourceUsage(BaseModelObject):
|
|
37
|
+
"""Resource quota with provisioned and consumed values."""
|
|
38
|
+
|
|
39
|
+
provisioned: int
|
|
40
|
+
consumed: int | None = None
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class LimitsObject(BaseModelObject):
|
|
44
|
+
"""Limits object."""
|
|
45
|
+
|
|
46
|
+
max_records_total: ResourceUsage
|
|
47
|
+
max_giga_bytes_total: ResourceUsage
|
|
48
|
+
max_filtering_interval: str | None = None
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class StreamSettings(BaseModelObject):
|
|
52
|
+
"""Stream settings object."""
|
|
53
|
+
|
|
54
|
+
lifecycle: LifecycleObject
|
|
55
|
+
limits: LimitsObject
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class StreamResponse(ResponseResource["StreamRequest"]):
|
|
59
|
+
"""Stream response resource class."""
|
|
60
|
+
|
|
61
|
+
external_id: str
|
|
62
|
+
created_time: int
|
|
63
|
+
created_from_template: StreamTemplateName
|
|
64
|
+
type: Literal["Mutable", "Immutable"]
|
|
65
|
+
settings: StreamSettings | None = None
|
|
66
|
+
|
|
67
|
+
def as_request_resource(self) -> StreamRequest:
|
|
68
|
+
return StreamRequest.model_validate(
|
|
69
|
+
{
|
|
70
|
+
"externalId": self.external_id,
|
|
71
|
+
"settings": {"template": {"name": self.created_from_template}},
|
|
72
|
+
}
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
def as_write(self) -> StreamRequest:
|
|
76
|
+
return StreamRequest.model_validate(
|
|
77
|
+
{
|
|
78
|
+
"externalId": self.external_id,
|
|
79
|
+
"settings": {"template": {"name": self.created_from_template}},
|
|
80
|
+
}
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class StreamResponseList(BaseResourceList[StreamResponse], ResourceResponseListProtocol):
|
|
85
|
+
"""List of Stream response resources."""
|
|
86
|
+
|
|
87
|
+
_RESOURCE = StreamResponse
|
|
88
|
+
|
|
89
|
+
def as_write(self) -> StreamRequestList:
|
|
90
|
+
return StreamRequestList([item.as_write() for item in self.data])
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
from collections.abc import Hashable
|
|
2
|
+
from typing import Literal
|
|
3
|
+
|
|
4
|
+
from pydantic import Field
|
|
5
|
+
|
|
6
|
+
from .base import BaseModelObject, RequestResource, ResponseResource
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class NodeReference(BaseModelObject):
|
|
10
|
+
space: str
|
|
11
|
+
external_id: str
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class RevisionStatus(BaseModelObject):
|
|
15
|
+
status: Literal["Queued", "Processing", "Done", "Failed"] | None = None
|
|
16
|
+
revision_id: int | None = None
|
|
17
|
+
created_time: int | None = None
|
|
18
|
+
revision_count: int | None = None
|
|
19
|
+
types: list[str] | None = None
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ThreeDModelRequest(RequestResource):
|
|
23
|
+
name: str
|
|
24
|
+
|
|
25
|
+
def as_id(self) -> str:
|
|
26
|
+
return self.name
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class ThreeDModelClassicRequest(ThreeDModelRequest):
|
|
30
|
+
data_set_id: int | None = None
|
|
31
|
+
metadata: dict[str, str] | None = None
|
|
32
|
+
|
|
33
|
+
def as_id(self) -> str:
|
|
34
|
+
return self.name
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class ThreeDModelDMSRequest(ThreeDModelRequest):
|
|
38
|
+
space: str
|
|
39
|
+
type: Literal["CAD", "PointCloud", "Image360"]
|
|
40
|
+
thumbnail_reference: NodeReference | None = None
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class ThreeDModelResponse(ResponseResource[ThreeDModelRequest]):
|
|
44
|
+
name: str
|
|
45
|
+
id: int
|
|
46
|
+
created_time: int
|
|
47
|
+
data_set_id: int | None = None
|
|
48
|
+
metadata: dict[str, str] | None = None
|
|
49
|
+
space: str | None = None
|
|
50
|
+
last_revision_info: RevisionStatus | None = None
|
|
51
|
+
|
|
52
|
+
def as_request_resource(self) -> ThreeDModelRequest:
|
|
53
|
+
if self.space is None:
|
|
54
|
+
return ThreeDModelClassicRequest._load(self.dump())
|
|
55
|
+
else:
|
|
56
|
+
return ThreeDModelDMSRequest._load(self.dump())
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class AssetMappingDMRequest(RequestResource):
|
|
60
|
+
node_id: int
|
|
61
|
+
asset_instance_id: NodeReference
|
|
62
|
+
# These fields are part of the path request and not the body schema.
|
|
63
|
+
model_id: int = Field(exclude=True)
|
|
64
|
+
revision_id: int = Field(exclude=True)
|
|
65
|
+
|
|
66
|
+
def as_id(self) -> Hashable:
|
|
67
|
+
return (
|
|
68
|
+
self.model_id,
|
|
69
|
+
self.revision_id,
|
|
70
|
+
self.node_id,
|
|
71
|
+
self.asset_instance_id.space,
|
|
72
|
+
self.asset_instance_id.external_id,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class AssetMappingClassicRequest(RequestResource):
|
|
77
|
+
node_id: int
|
|
78
|
+
asset_id: int | None = None
|
|
79
|
+
asset_instance_id: NodeReference | None = None
|
|
80
|
+
# These fields are part of the path request and not the body schema.
|
|
81
|
+
model_id: int = Field(exclude=True)
|
|
82
|
+
revision_id: int = Field(exclude=True)
|
|
83
|
+
|
|
84
|
+
def as_id(self) -> Hashable:
|
|
85
|
+
if self.asset_id:
|
|
86
|
+
return self.model_id, self.revision_id, self.node_id, self.asset_id
|
|
87
|
+
elif self.asset_instance_id:
|
|
88
|
+
return (
|
|
89
|
+
self.model_id,
|
|
90
|
+
self.revision_id,
|
|
91
|
+
self.node_id,
|
|
92
|
+
self.asset_instance_id.space,
|
|
93
|
+
self.asset_instance_id.external_id,
|
|
94
|
+
)
|
|
95
|
+
else:
|
|
96
|
+
raise AttributeError("asset_id or asset_instance_id is required")
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class AssetMappingResponse(ResponseResource[AssetMappingClassicRequest]):
|
|
100
|
+
node_id: int
|
|
101
|
+
asset_id: int | None = None
|
|
102
|
+
asset_instance_id: NodeReference | None = None
|
|
103
|
+
tree_index: int | None = None
|
|
104
|
+
subtree_size: int | None = None
|
|
105
|
+
# These fields are part of the path request and response, but they are included here for convenience.
|
|
106
|
+
model_id: int = Field(exclude=True)
|
|
107
|
+
revision_id: int = Field(exclude=True)
|
|
108
|
+
|
|
109
|
+
def as_request_resource(self) -> AssetMappingClassicRequest:
|
|
110
|
+
return AssetMappingClassicRequest.model_validate(
|
|
111
|
+
{**self.dump(), "modelId": self.model_id, "revisionId": self.revision_id}
|
|
112
|
+
)
|
|
@@ -12,17 +12,27 @@ 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.legacy.canvas import CanvasAPI, IndustrialCanvasAPI
|
|
16
|
+
from cognite_toolkit._cdf_tk.client.api.legacy.charts import ChartsAPI
|
|
17
|
+
from cognite_toolkit._cdf_tk.client.api.legacy.dml import DMLAPI
|
|
18
|
+
from cognite_toolkit._cdf_tk.client.api.legacy.extended_data_modeling import ExtendedInstancesAPI
|
|
19
|
+
from cognite_toolkit._cdf_tk.client.api.legacy.extended_files import ExtendedFileMetadataAPI
|
|
20
|
+
from cognite_toolkit._cdf_tk.client.api.legacy.extended_functions import ExtendedFunctionsAPI
|
|
21
|
+
from cognite_toolkit._cdf_tk.client.api.legacy.extended_raw import ExtendedRawAPI
|
|
22
|
+
from cognite_toolkit._cdf_tk.client.api.legacy.extended_timeseries import ExtendedTimeSeriesAPI
|
|
23
|
+
from cognite_toolkit._cdf_tk.client.api.legacy.location_filters import LocationFiltersAPI
|
|
24
|
+
from cognite_toolkit._cdf_tk.client.api.legacy.robotics import (
|
|
25
|
+
CapabilitiesAPI,
|
|
26
|
+
DataPostProcessingAPI,
|
|
27
|
+
FramesAPI,
|
|
28
|
+
MapsAPI,
|
|
29
|
+
RoboticsAPI,
|
|
30
|
+
)
|
|
31
|
+
from cognite_toolkit._cdf_tk.client.api.legacy.robotics import LocationsAPI as RoboticsLocationsAPI
|
|
32
|
+
from cognite_toolkit._cdf_tk.client.api.legacy.search_config import SearchConfigurationsAPI
|
|
15
33
|
|
|
16
|
-
from .
|
|
17
|
-
from .api.
|
|
18
|
-
from .api.dml import DMLAPI
|
|
19
|
-
from .api.extended_data_modeling import ExtendedInstancesAPI
|
|
20
|
-
from .api.extended_files import ExtendedFileMetadataAPI
|
|
21
|
-
from .api.extended_functions import ExtendedFunctionsAPI
|
|
22
|
-
from .api.extended_raw import ExtendedRawAPI
|
|
23
|
-
from .api.extended_timeseries import ExtendedTimeSeriesAPI
|
|
24
|
-
from .api.infield import InfieldAPI, InfieldConfigAPI
|
|
25
|
-
from .api.location_filters import LocationFiltersAPI
|
|
34
|
+
from ._toolkit_client import ToolAPI
|
|
35
|
+
from .api.infield import InfieldAPI, InFieldCDMConfigAPI, InfieldConfigAPI
|
|
26
36
|
from .api.lookup import (
|
|
27
37
|
AssetLookUpAPI,
|
|
28
38
|
DataSetLookUpAPI,
|
|
@@ -35,16 +45,18 @@ from .api.lookup import (
|
|
|
35
45
|
SecurityCategoriesLookUpAPI,
|
|
36
46
|
TimeSeriesLookUpAPI,
|
|
37
47
|
)
|
|
38
|
-
from .api.migration import
|
|
48
|
+
from .api.migration import (
|
|
49
|
+
CreatedSourceSystemAPI,
|
|
50
|
+
InstanceSourceAPI,
|
|
51
|
+
LookupAPI,
|
|
52
|
+
MigrationAPI,
|
|
53
|
+
MigrationLookupAPI,
|
|
54
|
+
ResourceViewMappingAPI,
|
|
55
|
+
)
|
|
39
56
|
from .api.project import ProjectAPI
|
|
40
|
-
from .api.robotics import RoboticsAPI
|
|
41
|
-
from .api.robotics.capabilities import CapabilitiesAPI
|
|
42
|
-
from .api.robotics.data_postprocessing import DataPostProcessingAPI
|
|
43
|
-
from .api.robotics.frames import FramesAPI
|
|
44
|
-
from .api.robotics.locations import LocationsAPI as RoboticsLocationsAPI
|
|
45
|
-
from .api.robotics.maps import MapsAPI
|
|
46
57
|
from .api.search import SearchAPI
|
|
47
|
-
from .api.
|
|
58
|
+
from .api.streams import StreamsAPI
|
|
59
|
+
from .api.three_d import ThreeDAPI, ThreeDModelAPI
|
|
48
60
|
from .api.token import TokenAPI
|
|
49
61
|
from .api.verify import VerifyAPI
|
|
50
62
|
|
|
@@ -76,6 +88,7 @@ class ToolkitClientMock(CogniteClientMock):
|
|
|
76
88
|
self.functions.schedules = MagicMock(spec_set=FunctionSchedulesAPI)
|
|
77
89
|
self.infield = MagicMock(spec=InfieldAPI)
|
|
78
90
|
self.infield.config = MagicMock(spec_set=InfieldConfigAPI)
|
|
91
|
+
self.infield.cdm_config = MagicMock(spec_set=InFieldCDMConfigAPI)
|
|
79
92
|
|
|
80
93
|
self.project = MagicMock(spec_set=ProjectAPI)
|
|
81
94
|
|
|
@@ -95,6 +108,11 @@ class ToolkitClientMock(CogniteClientMock):
|
|
|
95
108
|
self.lookup.functions = MagicMock(spec_set=FunctionLookUpAPI)
|
|
96
109
|
self.migration = MagicMock(spec=MigrationAPI)
|
|
97
110
|
self.migration.instance_source = MagicMock(spec_set=InstanceSourceAPI)
|
|
111
|
+
self.migration.lookup = MagicMock(spec=MigrationLookupAPI)
|
|
112
|
+
self.migration.lookup.assets = MagicMock(spec_set=LookupAPI)
|
|
113
|
+
self.migration.lookup.events = MagicMock(spec_set=LookupAPI)
|
|
114
|
+
self.migration.lookup.files = MagicMock(spec_set=LookupAPI)
|
|
115
|
+
self.migration.lookup.time_series = MagicMock(spec_set=LookupAPI)
|
|
98
116
|
self.migration.resource_view_mapping = MagicMock(spec_set=ResourceViewMappingAPI)
|
|
99
117
|
self.migration.created_source_system = MagicMock(spec_set=CreatedSourceSystemAPI)
|
|
100
118
|
self.raw = MagicMock(spec=ExtendedRawAPI)
|
|
@@ -117,6 +135,12 @@ class ToolkitClientMock(CogniteClientMock):
|
|
|
117
135
|
self.time_series.data.synthetic = MagicMock(spec_set=SyntheticDatapointsAPI)
|
|
118
136
|
self.time_series.subscriptions = MagicMock(spec_set=DatapointsSubscriptionAPI)
|
|
119
137
|
|
|
138
|
+
self.tool = MagicMock(spec=ToolAPI)
|
|
139
|
+
self.tool.three_d = MagicMock(spec=ThreeDAPI)
|
|
140
|
+
self.tool.three_d.models = MagicMock(spec_set=ThreeDModelAPI)
|
|
141
|
+
|
|
142
|
+
self.streams = MagicMock(spec=StreamsAPI)
|
|
143
|
+
|
|
120
144
|
# This is a helper API, not a real API.
|
|
121
145
|
self.token = TokenAPI(self)
|
|
122
146
|
self.verify = MagicMock(spec_set=VerifyAPI)
|
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
from ._download import DownloadCommand
|
|
2
2
|
from ._migrate import (
|
|
3
|
-
|
|
3
|
+
MigrationCommand,
|
|
4
4
|
MigrationPrepareCommand,
|
|
5
5
|
)
|
|
6
6
|
from ._profile import ProfileAssetCentricCommand, ProfileAssetCommand, ProfileRawCommand, ProfileTransformationCommand
|
|
7
7
|
from ._purge import PurgeCommand
|
|
8
8
|
from ._upload import UploadCommand
|
|
9
|
+
from .about import AboutCommand
|
|
9
10
|
from .auth import AuthCommand
|
|
10
11
|
from .build_cmd import BuildCommand
|
|
11
12
|
from .clean import CleanCommand
|
|
12
13
|
from .collect import CollectCommand
|
|
13
14
|
from .deploy import DeployCommand
|
|
14
|
-
from .dump_data import DumpDataCommand
|
|
15
15
|
from .dump_resource import DumpResourceCommand
|
|
16
|
-
from .featureflag import FeatureFlagCommand
|
|
17
16
|
from .init import InitCommand
|
|
18
17
|
from .modules import ModulesCommand
|
|
19
18
|
from .pull import PullCommand
|
|
20
19
|
from .repo import RepoCommand
|
|
20
|
+
from .resources import ResourcesCommand
|
|
21
21
|
from .run import RunFunctionCommand, RunTransformationCommand, RunWorkflowCommand
|
|
22
22
|
|
|
23
23
|
__all__ = [
|
|
24
|
+
"AboutCommand",
|
|
24
25
|
"AuthCommand",
|
|
25
26
|
"BuildCommand",
|
|
27
|
+
"BuildCommandV2",
|
|
26
28
|
"CleanCommand",
|
|
27
29
|
"CollectCommand",
|
|
28
30
|
"DeployCommand",
|
|
29
31
|
"DownloadCommand",
|
|
30
|
-
"DumpDataCommand",
|
|
31
32
|
"DumpResourceCommand",
|
|
32
|
-
"FeatureFlagCommand",
|
|
33
33
|
"InitCommand",
|
|
34
|
-
"
|
|
34
|
+
"MigrationCommand",
|
|
35
35
|
"MigrationPrepareCommand",
|
|
36
36
|
"ModulesCommand",
|
|
37
37
|
"ProfileAssetCentricCommand",
|
|
@@ -41,6 +41,7 @@ __all__ = [
|
|
|
41
41
|
"PullCommand",
|
|
42
42
|
"PurgeCommand",
|
|
43
43
|
"RepoCommand",
|
|
44
|
+
"ResourcesCommand",
|
|
44
45
|
"RunFunctionCommand",
|
|
45
46
|
"RunTransformationCommand",
|
|
46
47
|
"RunWorkflowCommand",
|
|
@@ -11,9 +11,8 @@ from packaging.version import Version
|
|
|
11
11
|
from packaging.version import parse as parse_version
|
|
12
12
|
from rich import print
|
|
13
13
|
|
|
14
|
-
from cognite_toolkit._cdf_tk.
|
|
14
|
+
from cognite_toolkit._cdf_tk.cdf_toml import CDFToml
|
|
15
15
|
from cognite_toolkit._cdf_tk.constants import DOCKER_IMAGE_NAME
|
|
16
|
-
from cognite_toolkit._cdf_tk.data_classes import ModuleDirectories
|
|
17
16
|
from cognite_toolkit._cdf_tk.utils import iterate_modules, read_yaml_file, safe_read, safe_write
|
|
18
17
|
from cognite_toolkit._version import __version__
|
|
19
18
|
|
|
@@ -51,40 +50,6 @@ class ManualChange(Change):
|
|
|
51
50
|
return ""
|
|
52
51
|
|
|
53
52
|
|
|
54
|
-
class SetKindOnFile(AutomaticChange):
|
|
55
|
-
"""Adds the kind to the filename of all resource files.
|
|
56
|
-
|
|
57
|
-
Before `your_file.yaml`:
|
|
58
|
-
After `your_file.FileMetadata.yaml`:
|
|
59
|
-
"""
|
|
60
|
-
|
|
61
|
-
deprecated_from = Version("0.4.0")
|
|
62
|
-
has_file_changes = True
|
|
63
|
-
|
|
64
|
-
def do(self) -> set[Path]:
|
|
65
|
-
module_directories = ModuleDirectories.load(self._organization_dir)
|
|
66
|
-
changed: set[Path] = set()
|
|
67
|
-
for module in module_directories:
|
|
68
|
-
for resource_folder, source_files in module.source_paths_by_resource_folder.items():
|
|
69
|
-
for source_file in source_files:
|
|
70
|
-
if source_file.suffix not in {".yaml", ".yml"}:
|
|
71
|
-
continue
|
|
72
|
-
loader, _ = get_loader(source_file, resource_folder, force_pattern=True)
|
|
73
|
-
if loader is None:
|
|
74
|
-
print(f"Could not find loader for {source_file}")
|
|
75
|
-
continue
|
|
76
|
-
if source_file.stem.casefold().endswith(loader.kind.casefold()):
|
|
77
|
-
continue
|
|
78
|
-
new_name = source_file.with_name(f"{source_file.stem}.{loader.kind}{source_file.suffix}")
|
|
79
|
-
source_file.rename(new_name)
|
|
80
|
-
changed.add(source_file)
|
|
81
|
-
for suffix in [".sql", ".csv", ".parquet"]:
|
|
82
|
-
if (adjacent_file := source_file.with_suffix(suffix)).exists():
|
|
83
|
-
adjacent_file.rename(new_name.with_suffix(suffix))
|
|
84
|
-
changed.add(adjacent_file)
|
|
85
|
-
|
|
86
|
-
return changed
|
|
87
|
-
|
|
88
53
|
|
|
89
54
|
class FixViewBasedLocationFilter(AutomaticChange):
|
|
90
55
|
"""The created view-based location filter has been fixed to be compatible with the CDF API.
|
|
@@ -362,7 +327,6 @@ After:
|
|
|
362
327
|
|
|
363
328
|
def do(self) -> set[Path]:
|
|
364
329
|
# Avoid circular import
|
|
365
|
-
from .modules import ModulesCommand
|
|
366
330
|
|
|
367
331
|
system_yaml = self._organization_dir / "_system.yaml"
|
|
368
332
|
if not system_yaml.exists():
|
|
@@ -372,11 +336,8 @@ After:
|
|
|
372
336
|
content = read_yaml_file(system_yaml)
|
|
373
337
|
current_version = content.get("cdf_toolkit_version", __version__)
|
|
374
338
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
cdf_toml_path = Path.cwd() / "cdf.toml"
|
|
379
|
-
cdf_toml_path.write_text(cdf_toml_content, encoding="utf-8")
|
|
339
|
+
CDFToml.write(self._organization_dir, version=current_version)
|
|
340
|
+
cdf_toml_path = Path.cwd() / CDFToml.file_name
|
|
380
341
|
system_yaml.unlink()
|
|
381
342
|
return {cdf_toml_path, system_yaml}
|
|
382
343
|
|
|
@@ -2,14 +2,24 @@ from collections.abc import Callable, Iterable
|
|
|
2
2
|
from functools import partial
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
|
|
5
|
-
from cognite.client.data_classes._base import T_CogniteResource
|
|
6
|
-
|
|
7
5
|
from cognite_toolkit._cdf_tk.constants import DATA_MANIFEST_STEM, DATA_RESOURCE_DIR
|
|
8
6
|
from cognite_toolkit._cdf_tk.exceptions import ToolkitValueError
|
|
9
|
-
from cognite_toolkit._cdf_tk.
|
|
7
|
+
from cognite_toolkit._cdf_tk.protocols import T_ResourceResponse
|
|
8
|
+
from cognite_toolkit._cdf_tk.storageio import (
|
|
9
|
+
ConfigurableStorageIO,
|
|
10
|
+
Page,
|
|
11
|
+
StorageIO,
|
|
12
|
+
T_Selector,
|
|
13
|
+
TableStorageIO,
|
|
14
|
+
)
|
|
10
15
|
from cognite_toolkit._cdf_tk.tk_warnings import LowSeverityWarning
|
|
11
16
|
from cognite_toolkit._cdf_tk.utils.file import safe_write, sanitize_filename, yaml_safe_dump
|
|
12
|
-
from cognite_toolkit._cdf_tk.utils.fileio import
|
|
17
|
+
from cognite_toolkit._cdf_tk.utils.fileio import (
|
|
18
|
+
TABLE_WRITE_CLS_BY_FORMAT,
|
|
19
|
+
Compression,
|
|
20
|
+
FileWriter,
|
|
21
|
+
SchemaColumn,
|
|
22
|
+
)
|
|
13
23
|
from cognite_toolkit._cdf_tk.utils.producer_worker import ProducerWorkerExecutor
|
|
14
24
|
from cognite_toolkit._cdf_tk.utils.useful_types import JsonVal
|
|
15
25
|
|
|
@@ -20,7 +30,7 @@ class DownloadCommand(ToolkitCommand):
|
|
|
20
30
|
def download(
|
|
21
31
|
self,
|
|
22
32
|
selectors: Iterable[T_Selector],
|
|
23
|
-
io: StorageIO[T_Selector,
|
|
33
|
+
io: StorageIO[T_Selector, T_ResourceResponse],
|
|
24
34
|
output_dir: Path,
|
|
25
35
|
verbose: bool,
|
|
26
36
|
file_format: str,
|
|
@@ -68,7 +78,7 @@ class DownloadCommand(ToolkitCommand):
|
|
|
68
78
|
with FileWriter.create_from_format(
|
|
69
79
|
file_format, target_dir, selector.kind, compression_cls, columns=columns
|
|
70
80
|
) as writer:
|
|
71
|
-
executor = ProducerWorkerExecutor[Page[
|
|
81
|
+
executor = ProducerWorkerExecutor[Page[T_ResourceResponse], list[dict[str, JsonVal]]](
|
|
72
82
|
download_iterable=io.stream_data(selector, limit),
|
|
73
83
|
process=self.create_data_process(io=io, selector=selector, is_table=is_table),
|
|
74
84
|
write=partial(writer.write_chunks, filestem=filestem),
|
|
@@ -95,7 +105,7 @@ class DownloadCommand(ToolkitCommand):
|
|
|
95
105
|
|
|
96
106
|
@staticmethod
|
|
97
107
|
def _get_iteration_count(
|
|
98
|
-
io: StorageIO[T_Selector,
|
|
108
|
+
io: StorageIO[T_Selector, T_ResourceResponse],
|
|
99
109
|
selector: T_Selector,
|
|
100
110
|
limit: int | None,
|
|
101
111
|
) -> int | None:
|
|
@@ -126,19 +136,19 @@ class DownloadCommand(ToolkitCommand):
|
|
|
126
136
|
|
|
127
137
|
@staticmethod
|
|
128
138
|
def create_data_process(
|
|
129
|
-
io: StorageIO[T_Selector,
|
|
139
|
+
io: StorageIO[T_Selector, T_ResourceResponse],
|
|
130
140
|
selector: T_Selector,
|
|
131
141
|
is_table: bool,
|
|
132
|
-
) -> Callable[[Page[
|
|
142
|
+
) -> Callable[[Page[T_ResourceResponse]], list[dict[str, JsonVal]]]:
|
|
133
143
|
"""Creates a data processing function based on the IO type and whether the output is a table."""
|
|
134
144
|
if is_table and isinstance(io, TableStorageIO):
|
|
135
145
|
|
|
136
|
-
def row_data_process(chunk: Page[
|
|
146
|
+
def row_data_process(chunk: Page[T_ResourceResponse]) -> list[dict[str, JsonVal]]:
|
|
137
147
|
return io.data_to_row(chunk.items, selector)
|
|
138
148
|
|
|
139
149
|
return row_data_process
|
|
140
150
|
|
|
141
|
-
def chunk_data_process(data_page: Page[
|
|
151
|
+
def chunk_data_process(data_page: Page[T_ResourceResponse]) -> list[dict[str, JsonVal]]:
|
|
142
152
|
return io.data_to_json_chunk(data_page.items, selector)
|
|
143
153
|
|
|
144
154
|
return chunk_data_process
|
|
@@ -2,7 +2,6 @@ from collections.abc import Callable, Iterable, Sequence
|
|
|
2
2
|
from enum import Enum
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
|
|
5
|
-
from cognite.client.data_classes._base import T_CogniteResource
|
|
6
5
|
from rich import print
|
|
7
6
|
from rich.console import Console
|
|
8
7
|
from rich.table import Table
|
|
@@ -20,6 +19,7 @@ from cognite_toolkit._cdf_tk.exceptions import (
|
|
|
20
19
|
ToolkitMigrationError,
|
|
21
20
|
ToolkitValueError,
|
|
22
21
|
)
|
|
22
|
+
from cognite_toolkit._cdf_tk.protocols import T_ResourceRequest, T_ResourceResponse
|
|
23
23
|
from cognite_toolkit._cdf_tk.storageio import T_Selector, UploadableStorageIO, UploadItem
|
|
24
24
|
from cognite_toolkit._cdf_tk.utils import humanize_collection, safe_write, sanitize_filename
|
|
25
25
|
from cognite_toolkit._cdf_tk.utils.file import yaml_safe_dump
|
|
@@ -27,7 +27,6 @@ from cognite_toolkit._cdf_tk.utils.fileio import Chunk, CSVWriter, NDJsonWriter,
|
|
|
27
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
|
-
from cognite_toolkit._cdf_tk.utils.useful_types import T_WriteCogniteResource
|
|
31
30
|
|
|
32
31
|
from .data_model import INSTANCE_SOURCE_VIEW_ID, MODEL_ID, RESOURCE_VIEW_MAPPING_VIEW_ID
|
|
33
32
|
|
|
@@ -45,8 +44,8 @@ class MigrationCommand(ToolkitCommand):
|
|
|
45
44
|
def migrate(
|
|
46
45
|
self,
|
|
47
46
|
selected: T_Selector,
|
|
48
|
-
data: UploadableStorageIO[T_Selector,
|
|
49
|
-
mapper: DataMapper[T_Selector,
|
|
47
|
+
data: UploadableStorageIO[T_Selector, T_ResourceResponse, T_ResourceRequest],
|
|
48
|
+
mapper: DataMapper[T_Selector, T_ResourceResponse, T_ResourceRequest],
|
|
50
49
|
log_dir: Path,
|
|
51
50
|
dry_run: bool = False,
|
|
52
51
|
verbose: bool = False,
|
|
@@ -71,9 +70,7 @@ class MigrationCommand(ToolkitCommand):
|
|
|
71
70
|
NDJsonWriter(log_dir, kind=f"{selected.kind}MigrationIssues", compression=Uncompressed) as log_file,
|
|
72
71
|
HTTPClient(config=data.client.config) as write_client,
|
|
73
72
|
):
|
|
74
|
-
executor = ProducerWorkerExecutor[
|
|
75
|
-
Sequence[T_CogniteResource], Sequence[UploadItem[T_WriteCogniteResource]]
|
|
76
|
-
](
|
|
73
|
+
executor = ProducerWorkerExecutor[Sequence[T_ResourceResponse], Sequence[UploadItem[T_ResourceRequest]]](
|
|
77
74
|
download_iterable=self._download_iterable(selected, data, tracker),
|
|
78
75
|
process=self._convert(mapper, data, tracker, log_file),
|
|
79
76
|
write=self._upload(selected, write_client, data, tracker, log_file, dry_run),
|
|
@@ -141,9 +138,9 @@ class MigrationCommand(ToolkitCommand):
|
|
|
141
138
|
def _download_iterable(
|
|
142
139
|
self,
|
|
143
140
|
selected: T_Selector,
|
|
144
|
-
data: UploadableStorageIO[T_Selector,
|
|
141
|
+
data: UploadableStorageIO[T_Selector, T_ResourceResponse, T_ResourceRequest],
|
|
145
142
|
tracker: ProgressTracker[str],
|
|
146
|
-
) -> Iterable[Sequence[
|
|
143
|
+
) -> Iterable[Sequence[T_ResourceResponse]]:
|
|
147
144
|
for page in data.stream_data(selected):
|
|
148
145
|
for item in page.items:
|
|
149
146
|
tracker.set_progress(data.as_id(item), self.Steps.DOWNLOAD, "success")
|
|
@@ -151,16 +148,17 @@ class MigrationCommand(ToolkitCommand):
|
|
|
151
148
|
|
|
152
149
|
def _convert(
|
|
153
150
|
self,
|
|
154
|
-
mapper: DataMapper[T_Selector,
|
|
155
|
-
data: UploadableStorageIO[T_Selector,
|
|
151
|
+
mapper: DataMapper[T_Selector, T_ResourceResponse, T_ResourceRequest],
|
|
152
|
+
data: UploadableStorageIO[T_Selector, T_ResourceResponse, T_ResourceRequest],
|
|
156
153
|
tracker: ProgressTracker[str],
|
|
157
154
|
log_file: NDJsonWriter,
|
|
158
|
-
) -> Callable[[Sequence[
|
|
159
|
-
def track_mapping(source: Sequence[
|
|
155
|
+
) -> Callable[[Sequence[T_ResourceResponse]], Sequence[UploadItem[T_ResourceRequest]]]:
|
|
156
|
+
def track_mapping(source: Sequence[T_ResourceResponse]) -> list[UploadItem[T_ResourceRequest]]:
|
|
157
|
+
mapped = mapper.map(source)
|
|
160
158
|
issues: list[Chunk] = []
|
|
161
|
-
targets: list[UploadItem[
|
|
162
|
-
|
|
163
|
-
|
|
159
|
+
targets: list[UploadItem[T_ResourceRequest]] = []
|
|
160
|
+
|
|
161
|
+
for (target, issue), item in zip(mapped, source):
|
|
164
162
|
id_ = data.as_id(item)
|
|
165
163
|
result: Status = "failed" if target is None else "success"
|
|
166
164
|
tracker.set_progress(id_, step=self.Steps.CONVERT, status=result)
|
|
@@ -180,17 +178,21 @@ class MigrationCommand(ToolkitCommand):
|
|
|
180
178
|
self,
|
|
181
179
|
selected: T_Selector,
|
|
182
180
|
write_client: HTTPClient,
|
|
183
|
-
target: UploadableStorageIO[T_Selector,
|
|
181
|
+
target: UploadableStorageIO[T_Selector, T_ResourceResponse, T_ResourceRequest],
|
|
184
182
|
tracker: ProgressTracker[str],
|
|
185
183
|
log_file: NDJsonWriter,
|
|
186
184
|
dry_run: bool,
|
|
187
|
-
) -> Callable[[Sequence[UploadItem[
|
|
188
|
-
def upload_items(data_item: Sequence[UploadItem[
|
|
185
|
+
) -> Callable[[Sequence[UploadItem[T_ResourceRequest]]], None]:
|
|
186
|
+
def upload_items(data_item: Sequence[UploadItem[T_ResourceRequest]]) -> None:
|
|
189
187
|
if not data_item:
|
|
190
188
|
return None
|
|
191
189
|
responses: Sequence[HTTPMessage]
|
|
192
190
|
if dry_run:
|
|
193
|
-
responses = [
|
|
191
|
+
responses = [
|
|
192
|
+
SuccessResponseItems(
|
|
193
|
+
status_code=200, body="", content=b"", ids=[item.source_id for item in data_item]
|
|
194
|
+
)
|
|
195
|
+
]
|
|
194
196
|
else:
|
|
195
197
|
responses = target.upload_items(data_chunk=data_item, http_client=write_client, selector=selected)
|
|
196
198
|
|