cognite-extractor-utils 7.4.2__py3-none-any.whl → 7.4.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cognite-extractor-utils might be problematic. Click here for more details.
- cognite/extractorutils/__init__.py +1 -1
- cognite/extractorutils/uploader/files.py +34 -41
- {cognite_extractor_utils-7.4.2.dist-info → cognite_extractor_utils-7.4.3.dist-info}/METADATA +1 -1
- {cognite_extractor_utils-7.4.2.dist-info → cognite_extractor_utils-7.4.3.dist-info}/RECORD +6 -6
- {cognite_extractor_utils-7.4.2.dist-info → cognite_extractor_utils-7.4.3.dist-info}/LICENSE +0 -0
- {cognite_extractor_utils-7.4.2.dist-info → cognite_extractor_utils-7.4.3.dist-info}/WHEEL +0 -0
|
@@ -251,43 +251,38 @@ class IOFileUploadQueue(AbstractUploadQueue):
|
|
|
251
251
|
return node.as_id()
|
|
252
252
|
|
|
253
253
|
def _upload_empty(
|
|
254
|
-
self,
|
|
254
|
+
self, file_meta: FileMetadataOrCogniteExtractorFile
|
|
255
255
|
) -> tuple[FileMetadataOrCogniteExtractorFile, str]:
|
|
256
|
-
if isinstance(
|
|
257
|
-
node_id = self._apply_cognite_file(
|
|
258
|
-
|
|
256
|
+
if isinstance(file_meta, CogniteExtractorFileApply):
|
|
257
|
+
node_id = self._apply_cognite_file(file_meta)
|
|
258
|
+
file_meta, url = self._create_cdm(instance_id=node_id)
|
|
259
259
|
else:
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
)
|
|
263
|
-
return meta_or_apply, url
|
|
260
|
+
file_meta, url = self.cdf_client.files.create(file_metadata=file_meta, overwrite=self.overwrite_existing)
|
|
261
|
+
return file_meta, url
|
|
264
262
|
|
|
265
|
-
def _upload_bytes(self, size: int, file: BinaryIO,
|
|
266
|
-
|
|
267
|
-
resp = self._httpx_client.send(self._get_file_upload_request(url, file, size,
|
|
263
|
+
def _upload_bytes(self, size: int, file: BinaryIO, file_meta: FileMetadataOrCogniteExtractorFile) -> None:
|
|
264
|
+
file_meta, url = self._upload_empty(file_meta)
|
|
265
|
+
resp = self._httpx_client.send(self._get_file_upload_request(url, file, size, file_meta.mime_type))
|
|
268
266
|
resp.raise_for_status()
|
|
269
267
|
|
|
270
|
-
def _upload_multipart(self, size: int, file: BinaryIO,
|
|
268
|
+
def _upload_multipart(self, size: int, file: BinaryIO, file_meta: FileMetadataOrCogniteExtractorFile) -> None:
|
|
271
269
|
chunks = ChunkedStream(file, self.max_file_chunk_size, size)
|
|
272
270
|
self.logger.debug(
|
|
273
|
-
f"File {
|
|
274
|
-
f", uploading in {chunks.chunk_count} chunks"
|
|
271
|
+
f"File {file_meta.external_id} is larger than 5GiB ({size})" f", uploading in {chunks.chunk_count} chunks"
|
|
275
272
|
)
|
|
276
273
|
|
|
277
|
-
returned_file_metadata = self._create_multi_part(
|
|
274
|
+
returned_file_metadata = self._create_multi_part(file_meta, chunks)
|
|
278
275
|
upload_urls = returned_file_metadata["uploadUrls"]
|
|
279
276
|
upload_id = returned_file_metadata["uploadId"]
|
|
280
277
|
file_meta = FileMetadata.load(returned_file_metadata)
|
|
281
278
|
|
|
282
279
|
for url in upload_urls:
|
|
283
280
|
chunks.next_chunk()
|
|
284
|
-
resp = self._httpx_client.send(
|
|
285
|
-
self._get_file_upload_request(url, chunks, len(chunks), meta_or_apply.mime_type)
|
|
286
|
-
)
|
|
281
|
+
resp = self._httpx_client.send(self._get_file_upload_request(url, chunks, len(chunks), file_meta.mime_type))
|
|
287
282
|
resp.raise_for_status()
|
|
288
283
|
|
|
289
284
|
completed_headers = (
|
|
290
|
-
_CDF_ALPHA_VERSION_HEADER if isinstance(
|
|
285
|
+
_CDF_ALPHA_VERSION_HEADER if isinstance(file_meta, CogniteExtractorFileApply) is not None else None
|
|
291
286
|
)
|
|
292
287
|
|
|
293
288
|
res = self.cdf_client.files._post(
|
|
@@ -297,9 +292,9 @@ class IOFileUploadQueue(AbstractUploadQueue):
|
|
|
297
292
|
)
|
|
298
293
|
res.raise_for_status()
|
|
299
294
|
|
|
300
|
-
def _create_multi_part(self,
|
|
301
|
-
if isinstance(
|
|
302
|
-
node_id = self._apply_cognite_file(
|
|
295
|
+
def _create_multi_part(self, file_meta: FileMetadataOrCogniteExtractorFile, chunks: ChunkedStream) -> dict:
|
|
296
|
+
if isinstance(file_meta, CogniteExtractorFileApply):
|
|
297
|
+
node_id = self._apply_cognite_file(file_meta)
|
|
303
298
|
identifiers = IdentifierSequence.load(instance_ids=node_id).as_singleton()
|
|
304
299
|
self.cdf_client.files._warn_alpha()
|
|
305
300
|
res = self.cdf_client.files._post(
|
|
@@ -313,7 +308,7 @@ class IOFileUploadQueue(AbstractUploadQueue):
|
|
|
313
308
|
else:
|
|
314
309
|
res = self.cdf_client.files._post(
|
|
315
310
|
url_path="/files/initmultipartupload",
|
|
316
|
-
json=
|
|
311
|
+
json=file_meta.dump(camel_case=True),
|
|
317
312
|
params={"overwrite": self.overwrite_existing, "parts": chunks.chunk_count},
|
|
318
313
|
)
|
|
319
314
|
res.raise_for_status()
|
|
@@ -321,7 +316,7 @@ class IOFileUploadQueue(AbstractUploadQueue):
|
|
|
321
316
|
|
|
322
317
|
def add_io_to_upload_queue(
|
|
323
318
|
self,
|
|
324
|
-
|
|
319
|
+
file_meta: FileMetadataOrCogniteExtractorFile,
|
|
325
320
|
read_file: Callable[[], BinaryIO],
|
|
326
321
|
extra_retries: Optional[
|
|
327
322
|
Union[Tuple[Type[Exception], ...], Dict[Type[Exception], Callable[[Any], bool]]]
|
|
@@ -351,36 +346,34 @@ class IOFileUploadQueue(AbstractUploadQueue):
|
|
|
351
346
|
max_delay=RETRY_MAX_DELAY,
|
|
352
347
|
backoff=RETRY_BACKOFF_FACTOR,
|
|
353
348
|
)
|
|
354
|
-
def upload_file(read_file: Callable[[], BinaryIO],
|
|
349
|
+
def upload_file(read_file: Callable[[], BinaryIO], file_meta: FileMetadataOrCogniteExtractorFile) -> None:
|
|
355
350
|
with read_file() as file:
|
|
356
351
|
size = super_len(file)
|
|
357
352
|
if size == 0:
|
|
358
353
|
# upload just the file metadata witout data
|
|
359
|
-
|
|
354
|
+
file_meta, _ = self._upload_empty(file_meta)
|
|
360
355
|
elif size >= self.max_single_chunk_file_size:
|
|
361
356
|
# The minimum chunk size is 4000MiB.
|
|
362
|
-
self._upload_multipart(size, file,
|
|
357
|
+
self._upload_multipart(size, file, file_meta)
|
|
363
358
|
|
|
364
359
|
else:
|
|
365
|
-
self._upload_bytes(size, file,
|
|
360
|
+
self._upload_bytes(size, file, file_meta)
|
|
366
361
|
|
|
367
|
-
if isinstance(
|
|
368
|
-
|
|
362
|
+
if isinstance(file_meta, CogniteExtractorFileApply):
|
|
363
|
+
file_meta.is_uploaded = True
|
|
369
364
|
|
|
370
365
|
if self.post_upload_function:
|
|
371
366
|
try:
|
|
372
|
-
self.post_upload_function([
|
|
367
|
+
self.post_upload_function([file_meta])
|
|
373
368
|
except Exception as e:
|
|
374
369
|
self.logger.error("Error in upload callback: %s", str(e))
|
|
375
370
|
|
|
376
|
-
def wrapped_upload(
|
|
377
|
-
read_file: Callable[[], BinaryIO], meta_or_apply: FileMetadataOrCogniteExtractorFile
|
|
378
|
-
) -> None:
|
|
371
|
+
def wrapped_upload(read_file: Callable[[], BinaryIO], file_meta: FileMetadataOrCogniteExtractorFile) -> None:
|
|
379
372
|
try:
|
|
380
|
-
upload_file(read_file,
|
|
373
|
+
upload_file(read_file, file_meta)
|
|
381
374
|
|
|
382
375
|
except Exception as e:
|
|
383
|
-
self.logger.exception(f"Unexpected error while uploading file: {
|
|
376
|
+
self.logger.exception(f"Unexpected error while uploading file: {file_meta.external_id}")
|
|
384
377
|
self.errors.append(e)
|
|
385
378
|
|
|
386
379
|
finally:
|
|
@@ -397,7 +390,7 @@ class IOFileUploadQueue(AbstractUploadQueue):
|
|
|
397
390
|
pass
|
|
398
391
|
|
|
399
392
|
with self.lock:
|
|
400
|
-
self.upload_queue.append(self._pool.submit(wrapped_upload, read_file,
|
|
393
|
+
self.upload_queue.append(self._pool.submit(wrapped_upload, read_file, file_meta))
|
|
401
394
|
self.upload_queue_size += 1
|
|
402
395
|
self.files_queued.inc()
|
|
403
396
|
self.queue_size.set(self.upload_queue_size)
|
|
@@ -522,7 +515,7 @@ class FileUploadQueue(IOFileUploadQueue):
|
|
|
522
515
|
)
|
|
523
516
|
|
|
524
517
|
def add_to_upload_queue(
|
|
525
|
-
self,
|
|
518
|
+
self, file_meta: FileMetadataOrCogniteExtractorFile, file_name: Union[str, PathLike]
|
|
526
519
|
) -> None:
|
|
527
520
|
"""
|
|
528
521
|
Add file to upload queue. The queue will be uploaded if the queue size is larger than the threshold
|
|
@@ -537,7 +530,7 @@ class FileUploadQueue(IOFileUploadQueue):
|
|
|
537
530
|
def load_file_from_path() -> BinaryIO:
|
|
538
531
|
return open(file_name, "rb")
|
|
539
532
|
|
|
540
|
-
self.add_io_to_upload_queue(
|
|
533
|
+
self.add_io_to_upload_queue(file_meta, load_file_from_path)
|
|
541
534
|
|
|
542
535
|
|
|
543
536
|
class BytesUploadQueue(IOFileUploadQueue):
|
|
@@ -574,7 +567,7 @@ class BytesUploadQueue(IOFileUploadQueue):
|
|
|
574
567
|
cancellation_token,
|
|
575
568
|
)
|
|
576
569
|
|
|
577
|
-
def add_to_upload_queue(self, content: bytes,
|
|
570
|
+
def add_to_upload_queue(self, content: bytes, file_meta: FileMetadataOrCogniteExtractorFile) -> None:
|
|
578
571
|
"""
|
|
579
572
|
Add object to upload queue. The queue will be uploaded if the queue size is larger than the threshold
|
|
580
573
|
specified in the __init__.
|
|
@@ -586,4 +579,4 @@ class BytesUploadQueue(IOFileUploadQueue):
|
|
|
586
579
|
def get_byte_io() -> BinaryIO:
|
|
587
580
|
return BytesIO(content)
|
|
588
581
|
|
|
589
|
-
self.add_io_to_upload_queue(
|
|
582
|
+
self.add_io_to_upload_queue(file_meta, get_byte_io)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
cognite/extractorutils/__init__.py,sha256=
|
|
1
|
+
cognite/extractorutils/__init__.py,sha256=piRKiXLS1XurR0Hwyz9mKGaicqhmzSvu3q1yPTE87ro,739
|
|
2
2
|
cognite/extractorutils/_inner_util.py,sha256=gmz6aqS7jDNsg8z4RHgJjMFohDLOMiaU4gMWBhg3xcE,1558
|
|
3
3
|
cognite/extractorutils/base.py,sha256=q6NU2bPec3WOasVnnIFoh-aUJudVZWZ2R6emz3IRj8Q,16391
|
|
4
4
|
cognite/extractorutils/configtools/__init__.py,sha256=L-daaqInIsmHcjb2forJeY0fW8tz1mlteOUo7IsWnrU,3059
|
|
@@ -20,13 +20,13 @@ cognite/extractorutils/uploader/_metrics.py,sha256=J2LJXb19L_SLSJ_voNIQHYLp0pjxU
|
|
|
20
20
|
cognite/extractorutils/uploader/assets.py,sha256=2E90N1kxsaA6Ah4h0_r_dTVhDYY_68ItRWrHYkkltJw,5628
|
|
21
21
|
cognite/extractorutils/uploader/data_modeling.py,sha256=w35Ix5mu0Cgfn4ywnDyif4VVjo04LVTlkMEevk6ztUs,3639
|
|
22
22
|
cognite/extractorutils/uploader/events.py,sha256=NZP2tMoU_rh_rb-EZiUBsOT5KdNABHN4c9Oddk0OsdE,5680
|
|
23
|
-
cognite/extractorutils/uploader/files.py,sha256=
|
|
23
|
+
cognite/extractorutils/uploader/files.py,sha256=yGi3Sk-k_6dD8FdxGuj33X1nxlKQkC10xBeVFP-aFhI,21741
|
|
24
24
|
cognite/extractorutils/uploader/raw.py,sha256=wFjF90PFTjmByOWx_Y4_YfDJ2w2jl0EQJ2Tjx2MP2PM,6738
|
|
25
25
|
cognite/extractorutils/uploader/time_series.py,sha256=HBtQdsQoIOaL-EG5lMsaY-ORwVb0kGiXG86VjE5-_Bg,26815
|
|
26
26
|
cognite/extractorutils/uploader_extractor.py,sha256=E-mpVvbPg_Tk90U4S9JybV0duptJ2SXE88HB6npE3zI,7732
|
|
27
27
|
cognite/extractorutils/uploader_types.py,sha256=wxfrsiKPTzG5lmoYtQsxt8Xyj-s5HnaLl8WDzJNrazg,1020
|
|
28
28
|
cognite/extractorutils/util.py,sha256=T6ef5b7aYJ8yq9swQwybYaLe3YGr3hElsJQy8E-d5Rs,17469
|
|
29
|
-
cognite_extractor_utils-7.4.
|
|
30
|
-
cognite_extractor_utils-7.4.
|
|
31
|
-
cognite_extractor_utils-7.4.
|
|
32
|
-
cognite_extractor_utils-7.4.
|
|
29
|
+
cognite_extractor_utils-7.4.3.dist-info/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
|
|
30
|
+
cognite_extractor_utils-7.4.3.dist-info/METADATA,sha256=XjJEfPowEj6H8hx77yT9OljKGfREA8ilNPaWVTAAPlI,5476
|
|
31
|
+
cognite_extractor_utils-7.4.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
32
|
+
cognite_extractor_utils-7.4.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|