cognite-toolkit 0.7.25__py3-none-any.whl → 0.7.27__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/apps/_migrate_app.py +38 -11
- cognite_toolkit/_cdf_tk/commands/__init__.py +2 -2
- cognite_toolkit/_cdf_tk/commands/_migrate/__init__.py +0 -2
- cognite_toolkit/_cdf_tk/commands/_migrate/data_mapper.py +144 -4
- cognite_toolkit/_cdf_tk/commands/_migrate/issues.py +12 -0
- cognite_toolkit/_cdf_tk/cruds/_base_cruds.py +5 -27
- cognite_toolkit/_cdf_tk/cruds/_data_cruds.py +5 -7
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/classic.py +25 -3
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/fieldops.py +0 -3
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/migration.py +0 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/relationship.py +0 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/streams.py +0 -1
- cognite_toolkit/_cdf_tk/cruds/_worker.py +11 -6
- cognite_toolkit/_cdf_tk/storageio/_applications.py +22 -1
- cognite_toolkit/_cdf_tk/tk_warnings/other.py +4 -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.25.dist-info → cognite_toolkit-0.7.27.dist-info}/METADATA +1 -1
- {cognite_toolkit-0.7.25.dist-info → cognite_toolkit-0.7.27.dist-info}/RECORD +23 -24
- cognite_toolkit/_cdf_tk/commands/_migrate/canvas.py +0 -201
- {cognite_toolkit-0.7.25.dist-info → cognite_toolkit-0.7.27.dist-info}/WHEEL +0 -0
- {cognite_toolkit-0.7.25.dist-info → cognite_toolkit-0.7.27.dist-info}/entry_points.txt +0 -0
|
@@ -8,17 +8,14 @@ from cognite.client.data_classes import Annotation
|
|
|
8
8
|
from cognite.client.data_classes.data_modeling import ContainerId
|
|
9
9
|
|
|
10
10
|
from cognite_toolkit._cdf_tk.client import ToolkitClient
|
|
11
|
-
from cognite_toolkit._cdf_tk.commands import
|
|
12
|
-
MigrationCanvasCommand,
|
|
13
|
-
MigrationPrepareCommand,
|
|
14
|
-
)
|
|
11
|
+
from cognite_toolkit._cdf_tk.commands import MigrationPrepareCommand
|
|
15
12
|
from cognite_toolkit._cdf_tk.commands._migrate import MigrationCommand
|
|
16
13
|
from cognite_toolkit._cdf_tk.commands._migrate.creators import (
|
|
17
14
|
InfieldV2ConfigCreator,
|
|
18
15
|
InstanceSpaceCreator,
|
|
19
16
|
SourceSystemCreator,
|
|
20
17
|
)
|
|
21
|
-
from cognite_toolkit._cdf_tk.commands._migrate.data_mapper import AssetCentricMapper, ChartMapper
|
|
18
|
+
from cognite_toolkit._cdf_tk.commands._migrate.data_mapper import AssetCentricMapper, CanvasMapper, ChartMapper
|
|
22
19
|
from cognite_toolkit._cdf_tk.commands._migrate.migration_io import (
|
|
23
20
|
AnnotationMigrationIO,
|
|
24
21
|
AssetCentricMigrationIO,
|
|
@@ -28,14 +25,15 @@ from cognite_toolkit._cdf_tk.commands._migrate.selectors import (
|
|
|
28
25
|
MigrateDataSetSelector,
|
|
29
26
|
MigrationCSVFileSelector,
|
|
30
27
|
)
|
|
31
|
-
from cognite_toolkit._cdf_tk.storageio import ChartIO
|
|
32
|
-
from cognite_toolkit._cdf_tk.storageio.selectors import ChartExternalIdSelector
|
|
28
|
+
from cognite_toolkit._cdf_tk.storageio import CanvasIO, ChartIO
|
|
29
|
+
from cognite_toolkit._cdf_tk.storageio.selectors import CanvasExternalIdSelector, ChartExternalIdSelector
|
|
33
30
|
from cognite_toolkit._cdf_tk.utils.auth import EnvironmentVariables
|
|
34
31
|
from cognite_toolkit._cdf_tk.utils.cli_args import parse_view_str
|
|
35
32
|
from cognite_toolkit._cdf_tk.utils.interactive_select import (
|
|
36
33
|
AssetInteractiveSelect,
|
|
37
34
|
DataModelingSelect,
|
|
38
35
|
FileMetadataInteractiveSelect,
|
|
36
|
+
InteractiveCanvasSelect,
|
|
39
37
|
InteractiveChartSelect,
|
|
40
38
|
ResourceViewMappingInteractiveSelect,
|
|
41
39
|
)
|
|
@@ -855,6 +853,23 @@ class MigrateApp(typer.Typer):
|
|
|
855
853
|
"performed to select the Canvas to migrate."
|
|
856
854
|
),
|
|
857
855
|
] = None,
|
|
856
|
+
skip_on_missing_ref: Annotated[
|
|
857
|
+
bool,
|
|
858
|
+
typer.Option(
|
|
859
|
+
"--skip-on-missing-ref",
|
|
860
|
+
"-s",
|
|
861
|
+
help="If set, the migration will skip Canvases that reference resources that have not been migrated to data modeling. "
|
|
862
|
+
"If not set, the migration will continue but the result will exclude the missing references.",
|
|
863
|
+
),
|
|
864
|
+
] = False,
|
|
865
|
+
log_dir: Annotated[
|
|
866
|
+
Path,
|
|
867
|
+
typer.Option(
|
|
868
|
+
"--log-dir",
|
|
869
|
+
"-l",
|
|
870
|
+
help="Path to the directory where migration logs will be stored.",
|
|
871
|
+
),
|
|
872
|
+
] = Path(f"migration_logs_{TODAY}"),
|
|
858
873
|
dry_run: Annotated[
|
|
859
874
|
bool,
|
|
860
875
|
typer.Option(
|
|
@@ -880,12 +895,24 @@ class MigrateApp(typer.Typer):
|
|
|
880
895
|
is populated with the mapping from Asset-Centric resources to the new data modeling resources.
|
|
881
896
|
"""
|
|
882
897
|
client = EnvironmentVariables.create_from_environment().get_client()
|
|
898
|
+
if external_id is None:
|
|
899
|
+
interactive = InteractiveCanvasSelect(client)
|
|
900
|
+
external_id = interactive.select_external_ids()
|
|
901
|
+
log_dir = questionary.path("Specify log directory for migration logs:", default=str(log_dir)).ask()
|
|
902
|
+
dry_run = questionary.confirm("Do you want to perform a dry run?", default=dry_run).ask()
|
|
903
|
+
verbose = questionary.confirm("Do you want verbose output?", default=verbose).ask()
|
|
904
|
+
if any(res is None for res in [log_dir, dry_run, verbose]):
|
|
905
|
+
raise typer.Abort()
|
|
906
|
+
log_dir = Path(log_dir)
|
|
883
907
|
|
|
884
|
-
cmd =
|
|
908
|
+
cmd = MigrationCommand()
|
|
909
|
+
selector = CanvasExternalIdSelector(external_ids=tuple(external_id))
|
|
885
910
|
cmd.run(
|
|
886
|
-
lambda: cmd.
|
|
887
|
-
|
|
888
|
-
|
|
911
|
+
lambda: cmd.migrate(
|
|
912
|
+
selected=selector,
|
|
913
|
+
data=CanvasIO(client, exclude_existing_version=True),
|
|
914
|
+
mapper=CanvasMapper(client, dry_run=dry_run, skip_on_missing_ref=skip_on_missing_ref),
|
|
915
|
+
log_dir=log_dir,
|
|
889
916
|
dry_run=dry_run,
|
|
890
917
|
verbose=verbose,
|
|
891
918
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
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
|
|
@@ -30,7 +30,7 @@ __all__ = [
|
|
|
30
30
|
"DownloadCommand",
|
|
31
31
|
"DumpResourceCommand",
|
|
32
32
|
"InitCommand",
|
|
33
|
-
"
|
|
33
|
+
"MigrationCommand",
|
|
34
34
|
"MigrationPrepareCommand",
|
|
35
35
|
"ModulesCommand",
|
|
36
36
|
"ProfileAssetCentricCommand",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from abc import ABC, abstractmethod
|
|
2
|
-
from collections
|
|
2
|
+
from collections import defaultdict
|
|
3
|
+
from collections.abc import Callable, Sequence
|
|
3
4
|
from typing import Generic, cast
|
|
4
5
|
from uuid import uuid4
|
|
5
6
|
|
|
@@ -11,8 +12,15 @@ from cognite.client.data_classes.data_modeling import (
|
|
|
11
12
|
View,
|
|
12
13
|
ViewId,
|
|
13
14
|
)
|
|
15
|
+
from cognite.client.exceptions import CogniteException
|
|
14
16
|
|
|
15
17
|
from cognite_toolkit._cdf_tk.client import ToolkitClient
|
|
18
|
+
from cognite_toolkit._cdf_tk.client.data_classes.canvas import (
|
|
19
|
+
ContainerReferenceApply,
|
|
20
|
+
FdmInstanceContainerReferenceApply,
|
|
21
|
+
IndustrialCanvas,
|
|
22
|
+
IndustrialCanvasApply,
|
|
23
|
+
)
|
|
16
24
|
from cognite_toolkit._cdf_tk.client.data_classes.charts import Chart, ChartWrite
|
|
17
25
|
from cognite_toolkit._cdf_tk.client.data_classes.charts_data import (
|
|
18
26
|
ChartCoreTimeseries,
|
|
@@ -23,13 +31,18 @@ from cognite_toolkit._cdf_tk.client.data_classes.migration import ResourceViewMa
|
|
|
23
31
|
from cognite_toolkit._cdf_tk.commands._migrate.conversion import DirectRelationCache, asset_centric_to_dm
|
|
24
32
|
from cognite_toolkit._cdf_tk.commands._migrate.data_classes import AssetCentricMapping
|
|
25
33
|
from cognite_toolkit._cdf_tk.commands._migrate.default_mappings import create_default_mappings
|
|
26
|
-
from cognite_toolkit._cdf_tk.commands._migrate.issues import
|
|
34
|
+
from cognite_toolkit._cdf_tk.commands._migrate.issues import (
|
|
35
|
+
CanvasMigrationIssue,
|
|
36
|
+
ChartMigrationIssue,
|
|
37
|
+
ConversionIssue,
|
|
38
|
+
MigrationIssue,
|
|
39
|
+
)
|
|
27
40
|
from cognite_toolkit._cdf_tk.commands._migrate.selectors import AssetCentricMigrationSelector
|
|
28
41
|
from cognite_toolkit._cdf_tk.constants import MISSING_INSTANCE_SPACE
|
|
29
|
-
from cognite_toolkit._cdf_tk.exceptions import ToolkitValueError
|
|
42
|
+
from cognite_toolkit._cdf_tk.exceptions import ToolkitMigrationError, ToolkitValueError
|
|
30
43
|
from cognite_toolkit._cdf_tk.protocols import T_ResourceRequest, T_ResourceResponse
|
|
31
44
|
from cognite_toolkit._cdf_tk.storageio._base import T_Selector
|
|
32
|
-
from cognite_toolkit._cdf_tk.storageio.selectors import ChartSelector
|
|
45
|
+
from cognite_toolkit._cdf_tk.storageio.selectors import CanvasSelector, ChartSelector
|
|
33
46
|
from cognite_toolkit._cdf_tk.utils import humanize_collection
|
|
34
47
|
from cognite_toolkit._cdf_tk.utils.useful_types import (
|
|
35
48
|
T_AssetCentricResourceExtended,
|
|
@@ -245,3 +258,130 @@ class ChartMapper(DataMapper[ChartSelector, Chart, ChartWrite]):
|
|
|
245
258
|
new_source_item = ChartSource(id=cast(str, core_ts_item.id), type=cast(str, core_ts_item.type))
|
|
246
259
|
updated_source_collection.append(new_source_item)
|
|
247
260
|
return updated_source_collection
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
class CanvasMapper(DataMapper[CanvasSelector, IndustrialCanvas, IndustrialCanvasApply]):
|
|
264
|
+
# Note sequences are not supported in Canvas, so we do not include them here.
|
|
265
|
+
asset_centric_resource_types = tuple(("asset", "event", "timeseries", "file"))
|
|
266
|
+
DEFAULT_ASSET_VIEW = ViewId("cdf_cdm", "CogniteAsset", "v1")
|
|
267
|
+
DEFAULT_EVENT_VIEW = ViewId("cdf_cdm", "CogniteActivity", "v1")
|
|
268
|
+
DEFAULT_FILE_VIEW = ViewId("cdf_cdm", "CogniteFile", "v1")
|
|
269
|
+
DEFAULT_TIMESERIES_VIEW = ViewId("cdf_cdm", "CogniteTimeSeries", "v1")
|
|
270
|
+
|
|
271
|
+
def __init__(self, client: ToolkitClient, dry_run: bool, skip_on_missing_ref: bool = False) -> None:
|
|
272
|
+
self.client = client
|
|
273
|
+
self.dry_run = dry_run
|
|
274
|
+
self.skip_on_missing_ref = skip_on_missing_ref
|
|
275
|
+
|
|
276
|
+
def map(self, source: Sequence[IndustrialCanvas]) -> Sequence[tuple[IndustrialCanvasApply | None, MigrationIssue]]:
|
|
277
|
+
self._populate_cache(source)
|
|
278
|
+
output: list[tuple[IndustrialCanvasApply | None, MigrationIssue]] = []
|
|
279
|
+
for item in source:
|
|
280
|
+
mapped_item, issue = self._map_single_item(item)
|
|
281
|
+
output.append((mapped_item, issue))
|
|
282
|
+
return output
|
|
283
|
+
|
|
284
|
+
@property
|
|
285
|
+
def lookup_methods(self) -> dict[str, Callable]:
|
|
286
|
+
return {
|
|
287
|
+
"asset": self.client.migration.lookup.assets,
|
|
288
|
+
"event": self.client.migration.lookup.events,
|
|
289
|
+
"timeseries": self.client.migration.lookup.time_series,
|
|
290
|
+
"file": self.client.migration.lookup.files,
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
def _populate_cache(self, source: Sequence[IndustrialCanvas]) -> None:
|
|
294
|
+
"""Populate the internal cache with references from the source canvases.
|
|
295
|
+
|
|
296
|
+
Note that the consumption views are also cached as part of the timeseries lookup.
|
|
297
|
+
"""
|
|
298
|
+
ids_by_type: dict[str, set[int]] = defaultdict(set)
|
|
299
|
+
for canvas in source:
|
|
300
|
+
for ref in canvas.container_references or []:
|
|
301
|
+
if ref.container_reference_type in self.asset_centric_resource_types:
|
|
302
|
+
ids_by_type[ref.container_reference_type].add(ref.resource_id)
|
|
303
|
+
|
|
304
|
+
for resource_type, lookup_method in self.lookup_methods.items():
|
|
305
|
+
ids = ids_by_type.get(resource_type)
|
|
306
|
+
if ids:
|
|
307
|
+
lookup_method(list(ids))
|
|
308
|
+
|
|
309
|
+
def _get_node_id(self, resource_id: int, resource_type: str) -> NodeId | None:
|
|
310
|
+
"""Look up the node ID for a given resource ID and type."""
|
|
311
|
+
try:
|
|
312
|
+
return self.lookup_methods[resource_type](resource_id)
|
|
313
|
+
except KeyError:
|
|
314
|
+
raise ToolkitValueError(f"Unsupported resource type '{resource_type}' for container reference migration.")
|
|
315
|
+
|
|
316
|
+
def _get_consumer_view_id(self, resource_id: int, resource_type: str) -> ViewId:
|
|
317
|
+
"""Look up the consumer view ID for a given resource ID and type."""
|
|
318
|
+
lookup_map = {
|
|
319
|
+
"asset": (self.client.migration.lookup.assets.consumer_view, self.DEFAULT_ASSET_VIEW),
|
|
320
|
+
"event": (self.client.migration.lookup.events.consumer_view, self.DEFAULT_EVENT_VIEW),
|
|
321
|
+
"timeseries": (self.client.migration.lookup.time_series.consumer_view, self.DEFAULT_TIMESERIES_VIEW),
|
|
322
|
+
"file": (self.client.migration.lookup.files.consumer_view, self.DEFAULT_FILE_VIEW),
|
|
323
|
+
}
|
|
324
|
+
if lookup_tuple := lookup_map.get(resource_type):
|
|
325
|
+
method, fallback = lookup_tuple
|
|
326
|
+
return method(resource_id) or fallback
|
|
327
|
+
|
|
328
|
+
raise ToolkitValueError(f"Unsupported resource type '{resource_type}' for container reference migration.")
|
|
329
|
+
|
|
330
|
+
def _map_single_item(self, canvas: IndustrialCanvas) -> tuple[IndustrialCanvasApply | None, CanvasMigrationIssue]:
|
|
331
|
+
update = canvas.as_write()
|
|
332
|
+
issue = CanvasMigrationIssue(canvas_external_id=canvas.canvas.external_id, canvas_name=canvas.canvas.name)
|
|
333
|
+
|
|
334
|
+
remaining_container_references: list[ContainerReferenceApply] = []
|
|
335
|
+
new_fdm_references: list[FdmInstanceContainerReferenceApply] = []
|
|
336
|
+
for ref in update.container_references or []:
|
|
337
|
+
if ref.container_reference_type not in self.asset_centric_resource_types:
|
|
338
|
+
remaining_container_references.append(ref)
|
|
339
|
+
continue
|
|
340
|
+
node_id = self._get_node_id(ref.resource_id, ref.container_reference_type)
|
|
341
|
+
if node_id is None:
|
|
342
|
+
issue.missing_reference_ids.append(ref.as_asset_centric_id())
|
|
343
|
+
else:
|
|
344
|
+
consumer_view = self._get_consumer_view_id(ref.resource_id, ref.container_reference_type)
|
|
345
|
+
fdm_ref = self.migrate_container_reference(ref, canvas.canvas.external_id, node_id, consumer_view)
|
|
346
|
+
new_fdm_references.append(fdm_ref)
|
|
347
|
+
if issue.missing_reference_ids and self.skip_on_missing_ref:
|
|
348
|
+
return None, issue
|
|
349
|
+
|
|
350
|
+
update.container_references = remaining_container_references
|
|
351
|
+
update.fdm_instance_container_references.extend(new_fdm_references)
|
|
352
|
+
if not self.dry_run:
|
|
353
|
+
backup = canvas.as_write().create_backup()
|
|
354
|
+
try:
|
|
355
|
+
self.client.canvas.industrial.create(backup)
|
|
356
|
+
except CogniteException as e:
|
|
357
|
+
raise ToolkitMigrationError(
|
|
358
|
+
f"Failed to create backup for canvas '{canvas.canvas.name}': {e!s}. "
|
|
359
|
+
) from e
|
|
360
|
+
|
|
361
|
+
return update, issue
|
|
362
|
+
|
|
363
|
+
@classmethod
|
|
364
|
+
def migrate_container_reference(
|
|
365
|
+
cls, reference: ContainerReferenceApply, canvas_external_id: str, instance_id: NodeId, consumer_view: ViewId
|
|
366
|
+
) -> FdmInstanceContainerReferenceApply:
|
|
367
|
+
"""Migrate a single container reference by replacing the asset-centric ID with the data model instance ID."""
|
|
368
|
+
new_id = str(uuid4())
|
|
369
|
+
new_external_id = f"{canvas_external_id}_{new_id}"
|
|
370
|
+
return FdmInstanceContainerReferenceApply(
|
|
371
|
+
external_id=new_external_id,
|
|
372
|
+
id_=new_id,
|
|
373
|
+
container_reference_type="fdmInstance",
|
|
374
|
+
instance_space=instance_id.space,
|
|
375
|
+
instance_external_id=instance_id.external_id,
|
|
376
|
+
view_space=consumer_view.space,
|
|
377
|
+
view_external_id=consumer_view.external_id,
|
|
378
|
+
view_version=consumer_view.version,
|
|
379
|
+
label=reference.label,
|
|
380
|
+
properties_=reference.properties_,
|
|
381
|
+
x=reference.x,
|
|
382
|
+
y=reference.y,
|
|
383
|
+
width=reference.width,
|
|
384
|
+
height=reference.height,
|
|
385
|
+
max_width=reference.max_width,
|
|
386
|
+
max_height=reference.max_height,
|
|
387
|
+
)
|
|
@@ -51,6 +51,18 @@ class ChartMigrationIssue(MigrationIssue):
|
|
|
51
51
|
)
|
|
52
52
|
|
|
53
53
|
|
|
54
|
+
class CanvasMigrationIssue(MigrationIssue):
|
|
55
|
+
type: ClassVar[str] = "canvasMigration"
|
|
56
|
+
canvas_external_id: str
|
|
57
|
+
canvas_name: str
|
|
58
|
+
missing_reference_ids: list[AssetCentricId] = Field(default_factory=list)
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def has_issues(self) -> bool:
|
|
62
|
+
"""Check if there are any issues recorded in this CanvasMigrationIssue."""
|
|
63
|
+
return bool(self.missing_reference_ids)
|
|
64
|
+
|
|
65
|
+
|
|
54
66
|
class ReadIssue(MigrationIssue):
|
|
55
67
|
"""Represents a read issue encountered during migration."""
|
|
56
68
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import sys
|
|
2
2
|
from abc import ABC, abstractmethod
|
|
3
|
-
from collections.abc import Hashable, Iterable, Sequence,
|
|
3
|
+
from collections.abc import Hashable, Iterable, Sequence, Sized
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
from typing import TYPE_CHECKING, Any, Generic, TypeVar
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@ from cognite.client.utils.useful_types import SequenceNotStr
|
|
|
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.constants import BUILD_FOLDER_ENCODING,
|
|
12
|
+
from cognite_toolkit._cdf_tk.constants import BUILD_FOLDER_ENCODING, YAML_SUFFIX
|
|
13
13
|
from cognite_toolkit._cdf_tk.protocols import T_ResourceRequest, T_ResourceResponse
|
|
14
14
|
from cognite_toolkit._cdf_tk.resource_classes import ToolkitResource
|
|
15
15
|
from cognite_toolkit._cdf_tk.tk_warnings import ToolkitWarning
|
|
@@ -39,11 +39,9 @@ class Loader(ABC):
|
|
|
39
39
|
exclude_filetypes: A set of filetypes that should be excluded from the supported filetypes.
|
|
40
40
|
"""
|
|
41
41
|
|
|
42
|
-
filetypes: frozenset[str]
|
|
43
42
|
folder_name: str
|
|
44
43
|
kind: str
|
|
45
44
|
dependencies: "frozenset[type[ResourceCRUD]]" = frozenset()
|
|
46
|
-
exclude_filetypes: frozenset[str] = frozenset()
|
|
47
45
|
_doc_base_url: str = "https://api-docs.cognite.com/20230101/tag/"
|
|
48
46
|
_doc_url: str = ""
|
|
49
47
|
sub_folder_name: str | None = None
|
|
@@ -74,13 +72,12 @@ class Loader(ABC):
|
|
|
74
72
|
def doc_url(cls) -> str:
|
|
75
73
|
return cls._doc_base_url + cls._doc_url
|
|
76
74
|
|
|
77
|
-
def find_files(self, dir_or_file: Path | None = None
|
|
75
|
+
def find_files(self, dir_or_file: Path | None = None) -> list[Path]:
|
|
78
76
|
"""Find all files that are supported by this loader in the given directory or file.
|
|
79
77
|
|
|
80
78
|
Args:
|
|
81
79
|
dir_or_file (Path): The directory or file to search in. If no path is given,
|
|
82
80
|
the build directory is used.
|
|
83
|
-
include_formats (set[str]): A set of file formats to include. If not set, all formats are included.
|
|
84
81
|
|
|
85
82
|
Returns:
|
|
86
83
|
list[Path]: A sorted list of all files that are supported by this loader.
|
|
@@ -94,12 +91,7 @@ class Loader(ABC):
|
|
|
94
91
|
raise ValueError("Invalid file type")
|
|
95
92
|
return [dir_or_file]
|
|
96
93
|
elif dir_or_file.is_dir():
|
|
97
|
-
|
|
98
|
-
file
|
|
99
|
-
for file in dir_or_file.glob("**/*")
|
|
100
|
-
if self.is_supported_file(file) and (include_formats is None or file.suffix in include_formats)
|
|
101
|
-
]
|
|
102
|
-
return sorted(file_paths)
|
|
94
|
+
return sorted([file for file in dir_or_file.rglob("*") if self.is_supported_file(file)])
|
|
103
95
|
else:
|
|
104
96
|
return []
|
|
105
97
|
|
|
@@ -118,11 +110,7 @@ class Loader(ABC):
|
|
|
118
110
|
bool: True if the file is supported, False otherwise.
|
|
119
111
|
|
|
120
112
|
"""
|
|
121
|
-
|
|
122
|
-
return False
|
|
123
|
-
if cls.exclude_filetypes and file.suffix[1:] in cls.exclude_filetypes:
|
|
124
|
-
return False
|
|
125
|
-
return file.stem.casefold().endswith(cls.kind.casefold())
|
|
113
|
+
return file.suffix in YAML_SUFFIX and file.stem.casefold().endswith(cls.kind.casefold())
|
|
126
114
|
|
|
127
115
|
|
|
128
116
|
T_Loader = TypeVar("T_Loader", bound=Loader)
|
|
@@ -144,8 +132,6 @@ class ResourceCRUD(Loader, ABC, Generic[T_ID, T_ResourceRequest, T_ResourceRespo
|
|
|
144
132
|
yaml_cls: The File format for this resource. This is used to validate the user input.
|
|
145
133
|
support_drop: Whether the resource supports the drop flag.
|
|
146
134
|
support_update: Whether the resource supports the update operation.
|
|
147
|
-
filetypes: The filetypes that are supported by this crud. This should not be set in the subclass, it
|
|
148
|
-
should always be yaml and yml.
|
|
149
135
|
dependencies: A set of other resource cruds that must be loaded before this crud.
|
|
150
136
|
parent_resource: A set of other resource cruds that are parent resources to this resource. This is used
|
|
151
137
|
to determine if the iterate method should return any resources when filtering by parent ids.
|
|
@@ -158,7 +144,6 @@ class ResourceCRUD(Loader, ABC, Generic[T_ID, T_ResourceRequest, T_ResourceRespo
|
|
|
158
144
|
# Optional to set in the subclass
|
|
159
145
|
support_drop = True
|
|
160
146
|
support_update = True
|
|
161
|
-
filetypes = frozenset({"yaml", "yml"})
|
|
162
147
|
dependencies: "frozenset[type[ResourceCRUD]]" = frozenset()
|
|
163
148
|
# For example, TransformationNotification and Schedule has Transformation as the parent resource
|
|
164
149
|
# This is used in the iterate method to ensure that nothing is returned if
|
|
@@ -437,10 +422,3 @@ class DataCRUD(Loader, ABC):
|
|
|
437
422
|
@abstractmethod
|
|
438
423
|
def upload(self, state: "BuildEnvironment", dry_run: bool) -> Iterable[tuple[str, int]]:
|
|
439
424
|
raise NotImplementedError
|
|
440
|
-
|
|
441
|
-
def _find_data_files(self, directory: Path) -> list[Path]:
|
|
442
|
-
return [
|
|
443
|
-
path
|
|
444
|
-
for path in directory.rglob("*")
|
|
445
|
-
if path.is_file() and path.name not in EXCL_FILES and self.is_supported_file(path)
|
|
446
|
-
]
|
|
@@ -28,7 +28,6 @@ class DatapointsCRUD(DataCRUD):
|
|
|
28
28
|
item_name = "datapoints"
|
|
29
29
|
folder_name = "timeseries"
|
|
30
30
|
kind = "Datapoints"
|
|
31
|
-
filetypes = frozenset({"csv", "parquet"})
|
|
32
31
|
dependencies = frozenset({TimeSeriesCRUD})
|
|
33
32
|
_doc_url = "Time-series/operation/postMultiTimeSeriesDatapoints"
|
|
34
33
|
|
|
@@ -43,7 +42,9 @@ class DatapointsCRUD(DataCRUD):
|
|
|
43
42
|
resource_directories = state.built_resources[self.folder_name].get_resource_directories(self.folder_name)
|
|
44
43
|
|
|
45
44
|
for resource_dir in resource_directories:
|
|
46
|
-
for datafile in
|
|
45
|
+
for datafile in resource_dir.rglob("*"):
|
|
46
|
+
if not datafile.stem.casefold().endswith(self.kind.casefold()):
|
|
47
|
+
continue
|
|
47
48
|
if datafile.suffix == ".csv":
|
|
48
49
|
# The replacement is used to ensure that we read exactly the same file on Windows and Linux
|
|
49
50
|
file_content = datafile.read_bytes().replace(b"\r\n", b"\n").decode("utf-8")
|
|
@@ -52,7 +53,7 @@ class DatapointsCRUD(DataCRUD):
|
|
|
52
53
|
elif datafile.suffix == ".parquet":
|
|
53
54
|
data = pd.read_parquet(datafile, engine="pyarrow")
|
|
54
55
|
else:
|
|
55
|
-
|
|
56
|
+
continue
|
|
56
57
|
timeseries_ids = list(data.columns)
|
|
57
58
|
if len(timeseries_ids) == 1:
|
|
58
59
|
ts_str = timeseries_ids[0]
|
|
@@ -87,8 +88,6 @@ class FileCRUD(DataCRUD):
|
|
|
87
88
|
item_name = "file contents"
|
|
88
89
|
folder_name = "files"
|
|
89
90
|
kind = "File"
|
|
90
|
-
filetypes = frozenset()
|
|
91
|
-
exclude_filetype: frozenset[str] = frozenset({})
|
|
92
91
|
dependencies = frozenset({FileMetadataCRUD, CogniteFileCRUD})
|
|
93
92
|
_doc_url = "Files/operation/initFileUpload"
|
|
94
93
|
|
|
@@ -149,7 +148,6 @@ class FileCRUD(DataCRUD):
|
|
|
149
148
|
class RawFileCRUD(DataCRUD):
|
|
150
149
|
item_name = "rows"
|
|
151
150
|
folder_name = "raw"
|
|
152
|
-
filetypes = frozenset({"csv", "parquet"})
|
|
153
151
|
kind = "Raw"
|
|
154
152
|
dependencies = frozenset({RawTableCRUD})
|
|
155
153
|
_doc_url = "Raw/operation/postRows"
|
|
@@ -169,7 +167,7 @@ class RawFileCRUD(DataCRUD):
|
|
|
169
167
|
datafile = next(
|
|
170
168
|
(
|
|
171
169
|
resource.source.path.with_suffix(f".{file_type}")
|
|
172
|
-
for file_type in
|
|
170
|
+
for file_type in ["csv", "parquet"]
|
|
173
171
|
if (resource.source.path.with_suffix(f".{file_type}").exists())
|
|
174
172
|
),
|
|
175
173
|
None,
|
|
@@ -29,20 +29,23 @@ from cognite_toolkit._cdf_tk.client.data_classes.sequences import (
|
|
|
29
29
|
ToolkitSequenceRowsList,
|
|
30
30
|
ToolkitSequenceRowsWrite,
|
|
31
31
|
)
|
|
32
|
+
from cognite_toolkit._cdf_tk.constants import TABLE_FORMATS, YAML_SUFFIX
|
|
32
33
|
from cognite_toolkit._cdf_tk.cruds._base_cruds import ResourceCRUD
|
|
34
|
+
from cognite_toolkit._cdf_tk.feature_flags import Flags
|
|
33
35
|
from cognite_toolkit._cdf_tk.resource_classes import AssetYAML, EventYAML, SequenceRowYAML, SequenceYAML
|
|
34
|
-
from cognite_toolkit._cdf_tk.tk_warnings import LowSeverityWarning
|
|
36
|
+
from cognite_toolkit._cdf_tk.tk_warnings import LowSeverityWarning, ToolkitDeprecationWarning
|
|
35
37
|
from cognite_toolkit._cdf_tk.utils import load_yaml_inject_variables
|
|
36
38
|
from cognite_toolkit._cdf_tk.utils.diff_list import diff_list_hashable, diff_list_identifiable
|
|
37
39
|
from cognite_toolkit._cdf_tk.utils.file import read_csv
|
|
38
40
|
|
|
39
41
|
from .data_organization import DataSetsCRUD, LabelCRUD
|
|
40
42
|
|
|
43
|
+
_DEPRECATION_WARNING_ISSUED = False
|
|
44
|
+
|
|
41
45
|
|
|
42
46
|
@final
|
|
43
47
|
class AssetCRUD(ResourceCRUD[str, AssetWrite, Asset]):
|
|
44
48
|
folder_name = "classic"
|
|
45
|
-
filetypes = frozenset({"yaml", "yml", "csv", "parquet"})
|
|
46
49
|
resource_cls = Asset
|
|
47
50
|
resource_write_cls = AssetWrite
|
|
48
51
|
yaml_cls = AssetYAML
|
|
@@ -50,6 +53,26 @@ class AssetCRUD(ResourceCRUD[str, AssetWrite, Asset]):
|
|
|
50
53
|
dependencies = frozenset({DataSetsCRUD, LabelCRUD})
|
|
51
54
|
_doc_url = "Assets/operation/createAssets"
|
|
52
55
|
|
|
56
|
+
@classmethod
|
|
57
|
+
def is_supported_file(cls, file: Path) -> bool:
|
|
58
|
+
if Flags.v08.is_enabled():
|
|
59
|
+
return super().is_supported_file(file)
|
|
60
|
+
global _DEPRECATION_WARNING_ISSUED
|
|
61
|
+
if not file.stem.casefold().endswith(cls.kind.casefold()):
|
|
62
|
+
return False
|
|
63
|
+
if file.suffix in YAML_SUFFIX:
|
|
64
|
+
return True
|
|
65
|
+
if file.suffix in TABLE_FORMATS:
|
|
66
|
+
if not _DEPRECATION_WARNING_ISSUED:
|
|
67
|
+
ToolkitDeprecationWarning(
|
|
68
|
+
feature="deployment of asset from CSV or Parquet files",
|
|
69
|
+
alternative="data plugin and cdf data upload commands",
|
|
70
|
+
removal_version="0.8",
|
|
71
|
+
).print_warning()
|
|
72
|
+
_DEPRECATION_WARNING_ISSUED = True
|
|
73
|
+
return True
|
|
74
|
+
return False
|
|
75
|
+
|
|
53
76
|
@property
|
|
54
77
|
def display_name(self) -> str:
|
|
55
78
|
return "assets"
|
|
@@ -479,7 +502,6 @@ class SequenceRowCRUD(ResourceCRUD[str, ToolkitSequenceRowsWrite, ToolkitSequenc
|
|
|
479
502
|
@final
|
|
480
503
|
class EventCRUD(ResourceCRUD[str, EventWrite, Event]):
|
|
481
504
|
folder_name = "classic"
|
|
482
|
-
filetypes = frozenset({"yaml", "yml"})
|
|
483
505
|
resource_cls = Event
|
|
484
506
|
resource_write_cls = EventWrite
|
|
485
507
|
yaml_cls = EventYAML
|
|
@@ -40,7 +40,6 @@ from .group_scoped import GroupResourceScopedCRUD
|
|
|
40
40
|
@final
|
|
41
41
|
class InfieldV1CRUD(ResourceCRUD[str, APMConfigWrite, APMConfig]):
|
|
42
42
|
folder_name = "cdf_applications"
|
|
43
|
-
filetypes = frozenset({"yaml", "yml"})
|
|
44
43
|
resource_cls = APMConfig
|
|
45
44
|
resource_write_cls = APMConfigWrite
|
|
46
45
|
kind = "InfieldV1"
|
|
@@ -249,7 +248,6 @@ class InfieldV1CRUD(ResourceCRUD[str, APMConfigWrite, APMConfig]):
|
|
|
249
248
|
@final
|
|
250
249
|
class InFieldLocationConfigCRUD(ResourceCRUD[NodeIdentifier, InfieldLocationConfig, InfieldLocationConfig]):
|
|
251
250
|
folder_name = "cdf_applications"
|
|
252
|
-
filetypes = frozenset({"yaml", "yml"})
|
|
253
251
|
resource_cls = InfieldLocationConfig
|
|
254
252
|
resource_write_cls = InfieldLocationConfig
|
|
255
253
|
kind = "InFieldLocationConfig"
|
|
@@ -349,7 +347,6 @@ class InFieldLocationConfigCRUD(ResourceCRUD[NodeIdentifier, InfieldLocationConf
|
|
|
349
347
|
@final
|
|
350
348
|
class InFieldCDMLocationConfigCRUD(ResourceCRUD[NodeIdentifier, InFieldCDMLocationConfig, InFieldCDMLocationConfig]):
|
|
351
349
|
folder_name = "cdf_applications"
|
|
352
|
-
filetypes = frozenset({"yaml", "yml"})
|
|
353
350
|
resource_cls = InFieldCDMLocationConfig
|
|
354
351
|
resource_write_cls = InFieldCDMLocationConfig
|
|
355
352
|
kind = "InFieldCDMLocationConfig"
|
|
@@ -21,7 +21,6 @@ from .datamodel import SpaceCRUD, ViewCRUD
|
|
|
21
21
|
@final
|
|
22
22
|
class ResourceViewMappingCRUD(ResourceCRUD[str, ResourceViewMappingApply, ResourceViewMapping]):
|
|
23
23
|
folder_name = "migration"
|
|
24
|
-
filetypes = frozenset({"yaml", "yml"})
|
|
25
24
|
resource_cls = ResourceViewMapping
|
|
26
25
|
resource_write_cls = ResourceViewMappingApply
|
|
27
26
|
kind = "ResourceViewMapping"
|
|
@@ -23,7 +23,6 @@ from .timeseries import TimeSeriesCRUD
|
|
|
23
23
|
@final
|
|
24
24
|
class RelationshipCRUD(ResourceCRUD[str, RelationshipWrite, Relationship]):
|
|
25
25
|
folder_name = "classic"
|
|
26
|
-
filetypes = frozenset({"yaml", "yml"})
|
|
27
26
|
resource_cls = Relationship
|
|
28
27
|
resource_write_cls = RelationshipWrite
|
|
29
28
|
kind = "Relationship"
|
|
@@ -19,7 +19,6 @@ from .datamodel import ContainerCRUD
|
|
|
19
19
|
@final
|
|
20
20
|
class StreamCRUD(ResourceCRUD[str, StreamRequest, StreamResponse]):
|
|
21
21
|
folder_name = "streams"
|
|
22
|
-
filetypes = frozenset({"yaml", "yml"})
|
|
23
22
|
resource_cls = StreamResponse
|
|
24
23
|
resource_write_cls = StreamRequest
|
|
25
24
|
kind = "Streams"
|
|
@@ -14,6 +14,7 @@ from yaml import YAMLError
|
|
|
14
14
|
|
|
15
15
|
from cognite_toolkit._cdf_tk.constants import TABLE_FORMATS
|
|
16
16
|
from cognite_toolkit._cdf_tk.exceptions import ToolkitWrongResourceError, ToolkitYAMLFormatError
|
|
17
|
+
from cognite_toolkit._cdf_tk.feature_flags import Flags
|
|
17
18
|
from cognite_toolkit._cdf_tk.tk_warnings import EnvironmentVariableMissingWarning, catch_warnings
|
|
18
19
|
from cognite_toolkit._cdf_tk.utils import to_diff
|
|
19
20
|
|
|
@@ -47,12 +48,16 @@ class ResourceWorker(Generic[T_ID, T_ResourceRequest, T_ResourceResponse]):
|
|
|
47
48
|
) -> list[Path]:
|
|
48
49
|
filepaths = self.loader.find_files(directory)
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
if not Flags.v08.is_enabled():
|
|
52
|
+
for read_module in read_modules or []:
|
|
53
|
+
if resource_dir := read_module.resource_dir_path(self.loader.folder_name):
|
|
54
|
+
# As of 05/11/24, Asset support csv and parquet files in addition to YAML.
|
|
55
|
+
# These table formats are not built, i.e., no variable replacement is done,
|
|
56
|
+
# so we load them directly from the source module.
|
|
57
|
+
table_files = [
|
|
58
|
+
file for file in self.loader.find_files(resource_dir) if file.suffix in TABLE_FORMATS
|
|
59
|
+
]
|
|
60
|
+
filepaths.extend(table_files)
|
|
56
61
|
|
|
57
62
|
if not sort:
|
|
58
63
|
return filepaths
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from collections.abc import Iterable, Sequence
|
|
2
2
|
from typing import Any
|
|
3
3
|
|
|
4
|
+
from cognite_toolkit._cdf_tk.client import ToolkitClient
|
|
4
5
|
from cognite_toolkit._cdf_tk.client.data_classes.canvas import (
|
|
5
6
|
IndustrialCanvas,
|
|
6
7
|
IndustrialCanvasApply,
|
|
@@ -127,6 +128,15 @@ class ChartIO(UploadableStorageIO[ChartSelector, Chart, ChartWrite]):
|
|
|
127
128
|
|
|
128
129
|
|
|
129
130
|
class CanvasIO(UploadableStorageIO[CanvasSelector, IndustrialCanvas, IndustrialCanvasApply]):
|
|
131
|
+
"""Download and upload Industrial Canvases to/from CDF.
|
|
132
|
+
|
|
133
|
+
Args:
|
|
134
|
+
client (ToolkitClient): The Cognite Toolkit client to use for API interactions.
|
|
135
|
+
exclude_existing_version (bool): Whether to exclude the 'existingVersion' field when uploading canvases.
|
|
136
|
+
Defaults to True. If you set this to False, the upload may fail if the existing version in CDF is
|
|
137
|
+
lower or equal to the one in the uploaded data.
|
|
138
|
+
"""
|
|
139
|
+
|
|
130
140
|
KIND = "IndustrialCanvas"
|
|
131
141
|
SUPPORTED_DOWNLOAD_FORMATS = frozenset({".ndjson"})
|
|
132
142
|
SUPPORTED_COMPRESSIONS = frozenset({".gz"})
|
|
@@ -134,6 +144,10 @@ class CanvasIO(UploadableStorageIO[CanvasSelector, IndustrialCanvas, IndustrialC
|
|
|
134
144
|
CHUNK_SIZE = 10
|
|
135
145
|
BASE_SELECTOR = CanvasSelector
|
|
136
146
|
|
|
147
|
+
def __init__(self, client: ToolkitClient, exclude_existing_version: bool = True) -> None:
|
|
148
|
+
super().__init__(client)
|
|
149
|
+
self.exclude_existing_version = exclude_existing_version
|
|
150
|
+
|
|
137
151
|
def as_id(self, item: IndustrialCanvas) -> str:
|
|
138
152
|
return item.as_id()
|
|
139
153
|
|
|
@@ -171,12 +185,19 @@ class CanvasIO(UploadableStorageIO[CanvasSelector, IndustrialCanvas, IndustrialC
|
|
|
171
185
|
results: list[HTTPMessage] = []
|
|
172
186
|
for item in data_chunk:
|
|
173
187
|
instances = item.item.as_instances()
|
|
188
|
+
items: list[dict[str, JsonVal]] = []
|
|
189
|
+
for instance in instances:
|
|
190
|
+
dumped = instance.dump()
|
|
191
|
+
if self.exclude_existing_version:
|
|
192
|
+
dumped.pop("existingVersion", None)
|
|
193
|
+
items.append(dumped)
|
|
194
|
+
|
|
174
195
|
responses = http_client.request_with_retries(
|
|
175
196
|
message=SimpleBodyRequest(
|
|
176
197
|
endpoint_url=config.create_api_url("/models/instances"),
|
|
177
198
|
method="POST",
|
|
178
199
|
# MyPy does not understand that .dump is valid json
|
|
179
|
-
body_content={"items":
|
|
200
|
+
body_content={"items": items}, # type: ignore[dict-item]
|
|
180
201
|
)
|
|
181
202
|
)
|
|
182
203
|
results.extend(responses.as_item_responses(item.source_id))
|
|
@@ -136,15 +136,19 @@ class MissingCapabilityWarning(GeneralWarning):
|
|
|
136
136
|
|
|
137
137
|
@dataclass(frozen=True)
|
|
138
138
|
class ToolkitDeprecationWarning(ToolkitWarning, DeprecationWarning):
|
|
139
|
+
severity = SeverityLevel.HIGH
|
|
139
140
|
message: ClassVar[str] = "The '{feature}' is deprecated and will be removed in a future version."
|
|
140
141
|
|
|
141
142
|
feature: str
|
|
142
143
|
alternative: str | None = None
|
|
144
|
+
removal_version: str | None = None
|
|
143
145
|
|
|
144
146
|
def get_message(self) -> str:
|
|
145
147
|
msg = self.message.format(feature=self.feature)
|
|
146
148
|
if self.alternative:
|
|
147
149
|
msg += f"\nUse {self.alternative!r} instead."
|
|
150
|
+
if self.removal_version:
|
|
151
|
+
msg += f"\nIt will be removed in version {self.removal_version}."
|
|
148
152
|
|
|
149
153
|
return msg
|
|
150
154
|
|
cognite_toolkit/_version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.7.
|
|
1
|
+
__version__ = "0.7.27"
|
|
@@ -9,7 +9,7 @@ cognite_toolkit/_cdf_tk/apps/_dev_app.py,sha256=FaY67PFdKwdiMKgJbTcjHT1X2Xfbog2P
|
|
|
9
9
|
cognite_toolkit/_cdf_tk/apps/_download_app.py,sha256=2nPn9P_9br9poynSpKKSZF7WYTYT--BfxlxXkSEeH-8,41156
|
|
10
10
|
cognite_toolkit/_cdf_tk/apps/_dump_app.py,sha256=EPq6fWSaScj9ncKfRY253rRJ37er47PIM60IFgkQK_k,37127
|
|
11
11
|
cognite_toolkit/_cdf_tk/apps/_landing_app.py,sha256=YR9z83OY7PhhgBVC5gmRLgo9iTXoGoZfRhOU3gd_r2o,888
|
|
12
|
-
cognite_toolkit/_cdf_tk/apps/_migrate_app.py,sha256=
|
|
12
|
+
cognite_toolkit/_cdf_tk/apps/_migrate_app.py,sha256=_woM0D2j6VzuYC0LJKteALbQ4U8vGj0B1LSBj_WszKQ,41198
|
|
13
13
|
cognite_toolkit/_cdf_tk/apps/_modules_app.py,sha256=t0SPvulgbgkF_OO2E68mQ_ZUcJ6HoaurYe0IkmXie0o,7449
|
|
14
14
|
cognite_toolkit/_cdf_tk/apps/_profile_app.py,sha256=vSRJW54bEvIul8_4rOqyOYA7ztXx7TFOvZRZWZTxMbg,7007
|
|
15
15
|
cognite_toolkit/_cdf_tk/apps/_purge.py,sha256=KYI1wFy7yHFEM1qJnTYc4_8E2FVGu4QhPsWsxop1sZA,14242
|
|
@@ -93,21 +93,20 @@ cognite_toolkit/_cdf_tk/client/testing.py,sha256=mXqEXPMZcbETrXBn6D-SiAcjD7xAkuu
|
|
|
93
93
|
cognite_toolkit/_cdf_tk/client/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
94
94
|
cognite_toolkit/_cdf_tk/client/utils/_concurrency.py,sha256=3GtQbKDaosyKHEt-KzxKK9Yie4TvZPdoou2vUk6dUa8,2298
|
|
95
95
|
cognite_toolkit/_cdf_tk/client/utils/_http_client.py,sha256=oXNKrIaizG4WiSAhL_kSCHAuL4aaaEhCU4pOJGxh6Xs,483
|
|
96
|
-
cognite_toolkit/_cdf_tk/commands/__init__.py,sha256=
|
|
96
|
+
cognite_toolkit/_cdf_tk/commands/__init__.py,sha256=wXRbOwMyhGjMj83_bXTOUXtCh70YS4-eiYzzCMN_YOs,1390
|
|
97
97
|
cognite_toolkit/_cdf_tk/commands/_base.py,sha256=1gl8Y-yqfedRMfdbwM3iPTIUIZriX1UvC1deLsJSJwM,2667
|
|
98
98
|
cognite_toolkit/_cdf_tk/commands/_changes.py,sha256=sU0KaTtPVSJgAZcaZ1Tkcajj36pmhd13kh7V8QbIED8,22987
|
|
99
99
|
cognite_toolkit/_cdf_tk/commands/_cli_commands.py,sha256=TK6U_rm6VZT_V941kTyHMoulWgJzbDC8YIIQDPJ5x3w,1011
|
|
100
100
|
cognite_toolkit/_cdf_tk/commands/_download.py,sha256=dVddH9t7oGx1kdQ3CCYYQb96Uxxy-xC8Opph98lo46U,6869
|
|
101
|
-
cognite_toolkit/_cdf_tk/commands/_migrate/__init__.py,sha256=
|
|
102
|
-
cognite_toolkit/_cdf_tk/commands/_migrate/canvas.py,sha256=R-z0yfOFcJZj-zRLhN-7z_-SLxqzSmONMgrbzNF9dGs,8843
|
|
101
|
+
cognite_toolkit/_cdf_tk/commands/_migrate/__init__.py,sha256=8ki04tJGH1dHdF2NtVF4HyhaC0XDDS7onrH_nvd9KtE,153
|
|
103
102
|
cognite_toolkit/_cdf_tk/commands/_migrate/command.py,sha256=l2P0Em05aEJvNZH4WkEIm-QfO3TAjG1rc_YxELuQIQM,14214
|
|
104
103
|
cognite_toolkit/_cdf_tk/commands/_migrate/conversion.py,sha256=Ew9JRYrd-Ol9G9csTzpnhXAgCFnX67MwDYOTsdJLP3E,16803
|
|
105
104
|
cognite_toolkit/_cdf_tk/commands/_migrate/creators.py,sha256=FTu7w3G8KyPY8pagG3KdPpOmpLcjehaAg2auEy6iM7A,9605
|
|
106
105
|
cognite_toolkit/_cdf_tk/commands/_migrate/data_classes.py,sha256=_vMS_qAPj4yup1VnmmojPVigAZtyPQH7PM0Raby5tao,10619
|
|
107
|
-
cognite_toolkit/_cdf_tk/commands/_migrate/data_mapper.py,sha256=
|
|
106
|
+
cognite_toolkit/_cdf_tk/commands/_migrate/data_mapper.py,sha256=vixRnB-4sjDCE2DafMJs_oApVe5HgwOrzSPt49ypUgM,18491
|
|
108
107
|
cognite_toolkit/_cdf_tk/commands/_migrate/data_model.py,sha256=i1eUsNX6Dueol9STIEwyksBnBsWUk13O8qHIjW964pM,7860
|
|
109
108
|
cognite_toolkit/_cdf_tk/commands/_migrate/default_mappings.py,sha256=ERn3qFrJFXdtXaMjHq3Gk7MxH03MGFk3FrtWCOBJQts,5544
|
|
110
|
-
cognite_toolkit/_cdf_tk/commands/_migrate/issues.py,sha256=
|
|
109
|
+
cognite_toolkit/_cdf_tk/commands/_migrate/issues.py,sha256=n8en744-r7GL9eUyxEojFes1yk69V04SnlpVXHrdPOQ,6972
|
|
111
110
|
cognite_toolkit/_cdf_tk/commands/_migrate/migration_io.py,sha256=wrdBH5P6NgiZQSYLR0iJ3ZvqfQ5fY-_Ne2yKv9E1g4o,16277
|
|
112
111
|
cognite_toolkit/_cdf_tk/commands/_migrate/prepare.py,sha256=RfqaNoso5CyBwc-p6ckwcYqBfZXKhdJgdGIyd0TATaI,2635
|
|
113
112
|
cognite_toolkit/_cdf_tk/commands/_migrate/selectors.py,sha256=N1H_-rBpPUD6pbrlcofn1uEK1bA694EUXEe1zIXeqyo,2489
|
|
@@ -132,33 +131,33 @@ cognite_toolkit/_cdf_tk/commands/resources.py,sha256=NeHVA1b1TMsP-2wgd5u1vif_N6n
|
|
|
132
131
|
cognite_toolkit/_cdf_tk/commands/run.py,sha256=JyX9jLEQej9eRrHVCCNlw4GuF80qETSol3-T5CCofgw,37331
|
|
133
132
|
cognite_toolkit/_cdf_tk/constants.py,sha256=TplKm2J9pGRHq7nAnLI0caTMHetS04OIz3hfq-jvGzo,7236
|
|
134
133
|
cognite_toolkit/_cdf_tk/cruds/__init__.py,sha256=noZQvCaAe6u67NSuJahil5Q44_tk5aGFWKyi9wBot1U,6675
|
|
135
|
-
cognite_toolkit/_cdf_tk/cruds/_base_cruds.py,sha256=
|
|
136
|
-
cognite_toolkit/_cdf_tk/cruds/_data_cruds.py,sha256=
|
|
134
|
+
cognite_toolkit/_cdf_tk/cruds/_base_cruds.py,sha256=6I1P0kZKxX7CDHM3_xPNnMJQi_QEviE_XnhpM_PAULc,17652
|
|
135
|
+
cognite_toolkit/_cdf_tk/cruds/_data_cruds.py,sha256=ggV8Hao5CzJvWkbVEm1u3DgSL7yQwxfMlsTe2TKLnYA,8746
|
|
137
136
|
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/__init__.py,sha256=diUM4kSbOw3YfdkmByy20BgzJcEM5ylYrnnEIoQEddk,2945
|
|
138
137
|
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/agent.py,sha256=2UjX0m85fw_zt4EpCm5Ihz2gE1AlgOgR8-7Pr8M2c4g,5128
|
|
139
138
|
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/auth.py,sha256=mswG-Fp_nfgociGTJ_aIG18we2nFNurcyObPxD9WKlA,24540
|
|
140
|
-
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/classic.py,sha256=
|
|
139
|
+
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/classic.py,sha256=k1PPjCq8XyuD2SZoU40ffMenboivO2sSJvYvbZljQzo,26562
|
|
141
140
|
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/configuration.py,sha256=plVGY-hvT01XC96C6hrabL07NaLphNWUq2iNI3m2Oyw,5811
|
|
142
141
|
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/data_organization.py,sha256=U0ItuoNr1KEtoFQAiIe-K19_72ht9-kGndFVgF-iC10,9524
|
|
143
142
|
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/datamodel.py,sha256=SagiSp3JERgEU3SnkjQ76vrxSM7gRA17lvoh0BW4KeQ,64867
|
|
144
143
|
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/extraction_pipeline.py,sha256=a2HywkruYNJGLZxqOjlp8mrpRGtJDPqIb6qY00eUbEI,17701
|
|
145
|
-
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/fieldops.py,sha256=
|
|
144
|
+
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/fieldops.py,sha256=dcC850Vyvc5Hfi9Z3MfXE8s_q14Hqq4EqegFz_V6aCI,20662
|
|
146
145
|
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/file.py,sha256=vyeRsiIOEbUeYslBsgXoyCk5hozDsubUilA7bdjqS5c,14855
|
|
147
146
|
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/function.py,sha256=v3kjn3igwTF53LJ6pp0O8d4S1XFJ1eXQGCchWAcaAx0,28439
|
|
148
147
|
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/group_scoped.py,sha256=WEg8-CxMP64WfE_XXIlH114zM51K0uLaYa4atd992zI,1690
|
|
149
148
|
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/hosted_extractors.py,sha256=P0hlXK0_FmO86U-gDHMHz8N0vpDtPoKupiQfhNP5KLE,14619
|
|
150
149
|
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/industrial_tool.py,sha256=QrgSCcLN0NtpQuP7zcCUYaWoiq3JiUB2j0A15d8MNNc,7856
|
|
151
150
|
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/location.py,sha256=-FDfZ-iPsWh_65HCze8M3-5Ijo3sr_n-AT-6FENSjpk,12076
|
|
152
|
-
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/migration.py,sha256=
|
|
151
|
+
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/migration.py,sha256=rlgi9_4c0Yyhx6m22He3bOenpw46nO-zBxoMrpjcHVs,4456
|
|
153
152
|
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/raw.py,sha256=rKTmIYD2_nm7LeIBa10iMZreNvw00OuQu-wC0gyiGQg,12072
|
|
154
|
-
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/relationship.py,sha256=
|
|
153
|
+
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/relationship.py,sha256=90HVz6KR_hOIsbOBFbt2oORWJ2lWsaQ7TAiPtFmzTi0,6151
|
|
155
154
|
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/robotics.py,sha256=IeDks5yJFta8Tp4SmikWjVxn0kyeCv44Pf3Jw9y5zQc,16074
|
|
156
|
-
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/streams.py,sha256=
|
|
155
|
+
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/streams.py,sha256=1GAIn6G3ZC11ZAgRW-HKaJltMhIqSKH6_ttdEMGgFN0,3054
|
|
157
156
|
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/three_d_model.py,sha256=5jIRF2JqosVHyAi2Ek6H38K2FWcNqrbPOR6MTSIEAQI,7320
|
|
158
157
|
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/timeseries.py,sha256=rMkA78K9CZqUu7YBDiLgnaZgPcIsWdT-J3nB4xwCJWw,23032
|
|
159
158
|
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/transformation.py,sha256=ndhoGIC6tBjNmwI0wDfg8v_6dJfCnHUnTienYOtKwC8,33876
|
|
160
159
|
cognite_toolkit/_cdf_tk/cruds/_resource_cruds/workflow.py,sha256=dVkf7OpZHV2H7V3zRU4BzUqDxgAudiWBJPvGeydATCg,26035
|
|
161
|
-
cognite_toolkit/_cdf_tk/cruds/_worker.py,sha256=
|
|
160
|
+
cognite_toolkit/_cdf_tk/cruds/_worker.py,sha256=QeZjziBCePilyI4WfTZvLfSHGT3qJGCMhugsoO1SVtU,9285
|
|
162
161
|
cognite_toolkit/_cdf_tk/data_classes/__init__.py,sha256=4zL-zR3lgQTCWfcy28LK0HEcukQOndPEFXVqfYfdKHU,1720
|
|
163
162
|
cognite_toolkit/_cdf_tk/data_classes/_base.py,sha256=0jy9VrYIO6iRgOZIcRASv-xIQjU3QbMICffEEIqzx6A,2673
|
|
164
163
|
cognite_toolkit/_cdf_tk/data_classes/_build_files.py,sha256=ARZpzcpmcbtG5Jg391d7A-7MJCFeUqqiDfJlO14cvvI,953
|
|
@@ -240,7 +239,7 @@ cognite_toolkit/_cdf_tk/resource_classes/workflow_trigger.py,sha256=aSN0WFPupQ38
|
|
|
240
239
|
cognite_toolkit/_cdf_tk/resource_classes/workflow_version.py,sha256=ui724EaM9Nlm3wTnm7Givgv6GLQ-xbsfZgidyRKv09U,2991
|
|
241
240
|
cognite_toolkit/_cdf_tk/storageio/__init__.py,sha256=h5Wr4i7zNIgsslrsRJxmp7ls4bNRKl0uZzQ7GLRMP7g,1920
|
|
242
241
|
cognite_toolkit/_cdf_tk/storageio/_annotations.py,sha256=JI_g18_Y9S7pbc9gm6dZMyo3Z-bCndJXF9C2lOva0bQ,4848
|
|
243
|
-
cognite_toolkit/_cdf_tk/storageio/_applications.py,sha256=
|
|
242
|
+
cognite_toolkit/_cdf_tk/storageio/_applications.py,sha256=M7FEK4xC0BjP2i6FyYs1589zEA3afJiOKCzY56RV6NU,19685
|
|
244
243
|
cognite_toolkit/_cdf_tk/storageio/_asset_centric.py,sha256=TirKLSNPoLqKjczsw0djWAsR0VvopwmU23aUxrBOJN8,32464
|
|
245
244
|
cognite_toolkit/_cdf_tk/storageio/_base.py,sha256=ElvqhIEBnhcz0yY1Ds164wVN0_7CFNK-uT0-z7LcR9U,13067
|
|
246
245
|
cognite_toolkit/_cdf_tk/storageio/_data_classes.py,sha256=s3TH04BJ1q7rXndRhEbVMEnoOXjxrGg4n-w9Z5uUL-o,3480
|
|
@@ -260,7 +259,7 @@ cognite_toolkit/_cdf_tk/storageio/selectors/_raw.py,sha256=sZq9C4G9DMe3S46_usKet
|
|
|
260
259
|
cognite_toolkit/_cdf_tk/tk_warnings/__init__.py,sha256=U9bT-G2xKrX6mmtZ7nZ1FfQeCjNKfKP_p7pev90dwOE,2316
|
|
261
260
|
cognite_toolkit/_cdf_tk/tk_warnings/base.py,sha256=cX8TCmb56gqx3lc7dankXuqpm5HGASJ4wTb07-MCJWs,4401
|
|
262
261
|
cognite_toolkit/_cdf_tk/tk_warnings/fileread.py,sha256=d2Kx6YyLmCkyFNjK8MO6eKGceCIEaFLZ4LYcG-EjnuM,8947
|
|
263
|
-
cognite_toolkit/_cdf_tk/tk_warnings/other.py,sha256=
|
|
262
|
+
cognite_toolkit/_cdf_tk/tk_warnings/other.py,sha256=D8EubXyW4qigscBEiedQJuT5c6yYoFIEhBPa1DggD3I,5808
|
|
264
263
|
cognite_toolkit/_cdf_tk/tracker.py,sha256=jhxzI8LOSZw3zDBPsTLW3zC2YcQK2abp_aVtRKcUIwE,5913
|
|
265
264
|
cognite_toolkit/_cdf_tk/utils/__init__.py,sha256=-X01eYNwz3l0W2jby0DZzlDIe9HEhUUj-dK8DBhYki8,1413
|
|
266
265
|
cognite_toolkit/_cdf_tk/utils/_auxiliary.py,sha256=tvvgFiWwLOCVDkPg83U5XqBLfOOt_gI3697EQr7-GSE,1198
|
|
@@ -303,14 +302,14 @@ cognite_toolkit/_repo_files/.gitignore,sha256=ip9kf9tcC5OguF4YF4JFEApnKYw0nG0vPi
|
|
|
303
302
|
cognite_toolkit/_repo_files/AzureDevOps/.devops/README.md,sha256=OLA0D7yCX2tACpzvkA0IfkgQ4_swSd-OlJ1tYcTBpsA,240
|
|
304
303
|
cognite_toolkit/_repo_files/AzureDevOps/.devops/deploy-pipeline.yml,sha256=brULcs8joAeBC_w_aoWjDDUHs3JheLMIR9ajPUK96nc,693
|
|
305
304
|
cognite_toolkit/_repo_files/AzureDevOps/.devops/dry-run-pipeline.yml,sha256=OBFDhFWK1mlT4Dc6mDUE2Es834l8sAlYG50-5RxRtHk,723
|
|
306
|
-
cognite_toolkit/_repo_files/GitHub/.github/workflows/deploy.yaml,sha256=
|
|
307
|
-
cognite_toolkit/_repo_files/GitHub/.github/workflows/dry-run.yaml,sha256=
|
|
308
|
-
cognite_toolkit/_resources/cdf.toml,sha256=
|
|
309
|
-
cognite_toolkit/_version.py,sha256=
|
|
305
|
+
cognite_toolkit/_repo_files/GitHub/.github/workflows/deploy.yaml,sha256=zf9hdCJ3SerGDrnmBTLTn3CMH0hGGYTh-hdVh3A115M,667
|
|
306
|
+
cognite_toolkit/_repo_files/GitHub/.github/workflows/dry-run.yaml,sha256=mRRQGQOYBRdXpgyuC1O1rEH5owcwsLVI_CvEyq3iqnk,2430
|
|
307
|
+
cognite_toolkit/_resources/cdf.toml,sha256=xSpuqW3POVKkqGWVtHMIiLc2dQZeGZpdqh1sJPHKC8A,475
|
|
308
|
+
cognite_toolkit/_version.py,sha256=fHi3FiqQRMkjl3o8ATyV9gZrBSNTVvt5m0WxJ-NYHTA,23
|
|
310
309
|
cognite_toolkit/config.dev.yaml,sha256=M33FiIKdS3XKif-9vXniQ444GTZ-bLXV8aFH86u9iUQ,332
|
|
311
310
|
cognite_toolkit/demo/__init__.py,sha256=-m1JoUiwRhNCL18eJ6t7fZOL7RPfowhCuqhYFtLgrss,72
|
|
312
311
|
cognite_toolkit/demo/_base.py,sha256=6xKBUQpXZXGQ3fJ5f7nj7oT0s2n7OTAGIa17ZlKHZ5U,8052
|
|
313
|
-
cognite_toolkit-0.7.
|
|
314
|
-
cognite_toolkit-0.7.
|
|
315
|
-
cognite_toolkit-0.7.
|
|
316
|
-
cognite_toolkit-0.7.
|
|
312
|
+
cognite_toolkit-0.7.27.dist-info/WHEEL,sha256=93kfTGt3a0Dykt_T-gsjtyS5_p8F_d6CE1NwmBOirzo,79
|
|
313
|
+
cognite_toolkit-0.7.27.dist-info/entry_points.txt,sha256=EtZ17K2mUjh-AY0QNU1CPIB_aDSSOdmtNI_4Fj967mA,84
|
|
314
|
+
cognite_toolkit-0.7.27.dist-info/METADATA,sha256=OoJ1UzFNOjp3Tja-1bdSe8LrbCq167Bq0lBnRGugbc8,4507
|
|
315
|
+
cognite_toolkit-0.7.27.dist-info/RECORD,,
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
from uuid import uuid4
|
|
2
|
-
|
|
3
|
-
from cognite.client.data_classes.capabilities import (
|
|
4
|
-
Capability,
|
|
5
|
-
DataModelInstancesAcl,
|
|
6
|
-
DataModelsAcl,
|
|
7
|
-
SpaceIDScope,
|
|
8
|
-
)
|
|
9
|
-
from cognite.client.exceptions import CogniteException
|
|
10
|
-
|
|
11
|
-
from cognite_toolkit._cdf_tk.client import ToolkitClient
|
|
12
|
-
from cognite_toolkit._cdf_tk.client.data_classes.canvas import (
|
|
13
|
-
CANVAS_INSTANCE_SPACE,
|
|
14
|
-
Canvas,
|
|
15
|
-
ContainerReferenceApply,
|
|
16
|
-
FdmInstanceContainerReferenceApply,
|
|
17
|
-
)
|
|
18
|
-
from cognite_toolkit._cdf_tk.client.data_classes.migration import InstanceSource
|
|
19
|
-
from cognite_toolkit._cdf_tk.commands._base import ToolkitCommand
|
|
20
|
-
from cognite_toolkit._cdf_tk.commands._migrate.data_model import (
|
|
21
|
-
INSTANCE_SOURCE_VIEW_ID,
|
|
22
|
-
MODEL_ID,
|
|
23
|
-
RESOURCE_VIEW_MAPPING_VIEW_ID,
|
|
24
|
-
)
|
|
25
|
-
from cognite_toolkit._cdf_tk.exceptions import AuthenticationError, ToolkitMigrationError
|
|
26
|
-
from cognite_toolkit._cdf_tk.tk_warnings import HighSeverityWarning, LowSeverityWarning, MediumSeverityWarning
|
|
27
|
-
from cognite_toolkit._cdf_tk.utils import humanize_collection
|
|
28
|
-
from cognite_toolkit._cdf_tk.utils.interactive_select import InteractiveCanvasSelect
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
class MigrationCanvasCommand(ToolkitCommand):
|
|
32
|
-
canvas_schema_space = Canvas.get_source().space
|
|
33
|
-
# Note sequences are not supported in Canvas, so we do not include them here.
|
|
34
|
-
asset_centric_resource_types = frozenset({"asset", "event", "file", "timeseries"})
|
|
35
|
-
|
|
36
|
-
def migrate_canvas(
|
|
37
|
-
self,
|
|
38
|
-
client: ToolkitClient,
|
|
39
|
-
external_ids: list[str] | None = None,
|
|
40
|
-
dry_run: bool = False,
|
|
41
|
-
verbose: bool = False,
|
|
42
|
-
) -> None:
|
|
43
|
-
self.validate_access(
|
|
44
|
-
client,
|
|
45
|
-
instance_spaces=[CANVAS_INSTANCE_SPACE],
|
|
46
|
-
schema_spaces=[self.canvas_schema_space, INSTANCE_SOURCE_VIEW_ID.space],
|
|
47
|
-
)
|
|
48
|
-
self.validate_migration_model_available(client)
|
|
49
|
-
external_ids = external_ids or InteractiveCanvasSelect(client).select_external_ids()
|
|
50
|
-
if external_ids is None or not external_ids:
|
|
51
|
-
self.console("No canvases selected for migration.")
|
|
52
|
-
return
|
|
53
|
-
action = "Would migrate" if dry_run else "Migrating"
|
|
54
|
-
self.console(f"{action} {len(external_ids)} canvases.")
|
|
55
|
-
for external_id in external_ids:
|
|
56
|
-
self._migrate_single_canvas(client, external_id, dry_run=dry_run, verbose=verbose)
|
|
57
|
-
|
|
58
|
-
def _migrate_single_canvas(
|
|
59
|
-
self,
|
|
60
|
-
client: ToolkitClient,
|
|
61
|
-
external_id: str,
|
|
62
|
-
dry_run: bool = False,
|
|
63
|
-
verbose: bool = False,
|
|
64
|
-
) -> None:
|
|
65
|
-
canvas = client.canvas.industrial.retrieve(external_id=external_id)
|
|
66
|
-
if canvas is None:
|
|
67
|
-
self.warn(MediumSeverityWarning(f"Canvas with external ID '{external_id}' not found. Skipping.. "))
|
|
68
|
-
return
|
|
69
|
-
update = canvas.as_write()
|
|
70
|
-
to_migrate = [
|
|
71
|
-
ref
|
|
72
|
-
for ref in update.container_references
|
|
73
|
-
if ref.container_reference_type in self.asset_centric_resource_types
|
|
74
|
-
]
|
|
75
|
-
if not to_migrate:
|
|
76
|
-
self.warn(
|
|
77
|
-
LowSeverityWarning(
|
|
78
|
-
f"Canvas with name '{canvas.canvas.name}' does not have any asset-centric references. Skipping.. "
|
|
79
|
-
)
|
|
80
|
-
)
|
|
81
|
-
if verbose:
|
|
82
|
-
self.console(f"Found canvas: {canvas.canvas.name}")
|
|
83
|
-
reference_ids = [ref.as_asset_centric_id() for ref in to_migrate]
|
|
84
|
-
instance_sources = client.migration.instance_source.retrieve(reference_ids)
|
|
85
|
-
source_by_reference_id = {source.as_asset_centric_id(): source for source in instance_sources}
|
|
86
|
-
missing = set(reference_ids) - set(source_by_reference_id.keys())
|
|
87
|
-
if missing:
|
|
88
|
-
self.warn(
|
|
89
|
-
HighSeverityWarning(
|
|
90
|
-
f"Canvas '{canvas.canvas.name}' has references to resources that are not been migrated: {humanize_collection(missing)}. Skipping.. "
|
|
91
|
-
)
|
|
92
|
-
)
|
|
93
|
-
return
|
|
94
|
-
if dry_run:
|
|
95
|
-
self.console(
|
|
96
|
-
f"Canvas '{canvas.canvas.name}' is ready for migration all {len(instance_sources)} references asset-centric resources found."
|
|
97
|
-
)
|
|
98
|
-
return
|
|
99
|
-
if verbose:
|
|
100
|
-
self.console(
|
|
101
|
-
f"Migrating canvas '{canvas.canvas.name}' with {len(instance_sources)} references to asset-centric resources."
|
|
102
|
-
)
|
|
103
|
-
backup = canvas.as_write().create_backup()
|
|
104
|
-
|
|
105
|
-
update.container_references = [
|
|
106
|
-
ref
|
|
107
|
-
for ref in update.container_references
|
|
108
|
-
if ref.container_reference_type not in self.asset_centric_resource_types
|
|
109
|
-
]
|
|
110
|
-
for ref in to_migrate:
|
|
111
|
-
source = source_by_reference_id[ref.as_asset_centric_id()]
|
|
112
|
-
fdm_ref = self.migrate_container_reference(ref, source, canvas.canvas.external_id)
|
|
113
|
-
update.fdm_instance_container_references.append(fdm_ref)
|
|
114
|
-
|
|
115
|
-
try:
|
|
116
|
-
client.canvas.industrial.create(backup)
|
|
117
|
-
except CogniteException as e:
|
|
118
|
-
raise ToolkitMigrationError(f"Failed to create backup for canvas '{canvas.canvas.name}': {e!s}. ") from e
|
|
119
|
-
try:
|
|
120
|
-
client.canvas.industrial.update(update)
|
|
121
|
-
except CogniteException as e:
|
|
122
|
-
raise ToolkitMigrationError(
|
|
123
|
-
f"Failed to migrate canvas '{canvas.canvas.name}': {e!s}. A backup was created with external ID '{backup.canvas.external_id}'."
|
|
124
|
-
) from e
|
|
125
|
-
else:
|
|
126
|
-
self.console(
|
|
127
|
-
f'Canvas "{canvas.canvas.name}" migrated successfully with {len(to_migrate)} references to data model instances.'
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
@classmethod
|
|
131
|
-
def migrate_container_reference(
|
|
132
|
-
cls, reference: ContainerReferenceApply, source: InstanceSource, canvas_external_id: str
|
|
133
|
-
) -> FdmInstanceContainerReferenceApply:
|
|
134
|
-
"""Migrate a single container reference by replacing the asset-centric ID with the data model instance ID."""
|
|
135
|
-
consumer_view = source.consumer_view()
|
|
136
|
-
new_id = str(uuid4())
|
|
137
|
-
new_external_id = f"{canvas_external_id}_{new_id}"
|
|
138
|
-
return FdmInstanceContainerReferenceApply(
|
|
139
|
-
external_id=new_external_id,
|
|
140
|
-
id_=new_id,
|
|
141
|
-
container_reference_type="fdmInstance",
|
|
142
|
-
instance_space=source.space,
|
|
143
|
-
instance_external_id=source.external_id,
|
|
144
|
-
view_space=consumer_view.space,
|
|
145
|
-
view_external_id=consumer_view.external_id,
|
|
146
|
-
view_version=consumer_view.version,
|
|
147
|
-
label=reference.label,
|
|
148
|
-
properties_=reference.properties_,
|
|
149
|
-
x=reference.x,
|
|
150
|
-
y=reference.y,
|
|
151
|
-
width=reference.width,
|
|
152
|
-
height=reference.height,
|
|
153
|
-
max_width=reference.max_width,
|
|
154
|
-
max_height=reference.max_height,
|
|
155
|
-
)
|
|
156
|
-
|
|
157
|
-
@staticmethod
|
|
158
|
-
def validate_access(
|
|
159
|
-
client: ToolkitClient,
|
|
160
|
-
instance_spaces: list[str] | None = None,
|
|
161
|
-
schema_spaces: list[str] | None = None,
|
|
162
|
-
) -> None:
|
|
163
|
-
required_capabilities: list[Capability] = []
|
|
164
|
-
if instance_spaces is not None:
|
|
165
|
-
required_capabilities.append(
|
|
166
|
-
DataModelInstancesAcl(
|
|
167
|
-
actions=[
|
|
168
|
-
DataModelInstancesAcl.Action.Read,
|
|
169
|
-
DataModelInstancesAcl.Action.Write,
|
|
170
|
-
DataModelInstancesAcl.Action.Write_Properties,
|
|
171
|
-
],
|
|
172
|
-
scope=SpaceIDScope(instance_spaces),
|
|
173
|
-
)
|
|
174
|
-
)
|
|
175
|
-
if schema_spaces is not None:
|
|
176
|
-
required_capabilities.append(
|
|
177
|
-
DataModelsAcl(actions=[DataModelsAcl.Action.Read], scope=SpaceIDScope(schema_spaces)),
|
|
178
|
-
)
|
|
179
|
-
if missing := client.iam.verify_capabilities(required_capabilities):
|
|
180
|
-
raise AuthenticationError(f"Missing required capabilities: {humanize_collection(missing)}.", missing)
|
|
181
|
-
|
|
182
|
-
@staticmethod
|
|
183
|
-
def validate_migration_model_available(client: ToolkitClient) -> None:
|
|
184
|
-
models = client.data_modeling.data_models.retrieve([MODEL_ID], inline_views=False)
|
|
185
|
-
if not models:
|
|
186
|
-
raise ToolkitMigrationError(
|
|
187
|
-
f"The migration data model {MODEL_ID!r} does not exist. "
|
|
188
|
-
"Please run the `cdf migrate prepare` command to deploy the migration data model."
|
|
189
|
-
)
|
|
190
|
-
elif len(models) > 1:
|
|
191
|
-
raise ToolkitMigrationError(
|
|
192
|
-
f"Multiple migration models {MODEL_ID!r}. "
|
|
193
|
-
"Please delete the duplicate models before proceeding with the migration."
|
|
194
|
-
)
|
|
195
|
-
model = models[0]
|
|
196
|
-
missing_views = {INSTANCE_SOURCE_VIEW_ID, RESOURCE_VIEW_MAPPING_VIEW_ID} - set(model.views or [])
|
|
197
|
-
if missing_views:
|
|
198
|
-
raise ToolkitMigrationError(
|
|
199
|
-
f"Invalid migration model. Missing views {humanize_collection(missing_views)}. "
|
|
200
|
-
f"Please run the `cdf migrate prepare` command to deploy the migration data model."
|
|
201
|
-
)
|
|
File without changes
|
|
File without changes
|