Skip to content

Commit c113d83

Browse files
[Datalake] Fixed session closure of filesystem (Azure#14910)
* Fixed session closure of filesystem * used wrapper * used wrapper * added unit test * fixed all clients * removed check * removed check * recorded test * recorded async test
1 parent 45d512b commit c113d83

10 files changed

+479
-16
lines changed

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
from urllib.parse import quote, unquote
88
except ImportError:
99
from urllib2 import quote, unquote # type: ignore
10+
from azure.core.pipeline import Pipeline
1011
from ._deserialize import deserialize_dir_properties
11-
from ._shared.base_client import parse_connection_str
12+
from ._shared.base_client import TransportWrapper, parse_connection_str
1213
from ._data_lake_file_client import DataLakeFileClient
1314
from ._models import DirectoryProperties
1415
from ._path_client import PathClient
@@ -505,6 +506,10 @@ def get_file_client(self, file # type: Union[FileProperties, str]
505506
except AttributeError:
506507
file_path = self.path_name + '/' + file
507508

509+
_pipeline = Pipeline(
510+
transport=TransportWrapper(self._pipeline._transport), # pylint: disable = protected-access
511+
policies=self._pipeline._impl_policies # pylint: disable = protected-access
512+
)
508513
return DataLakeFileClient(
509514
self.url, self.file_system_name, file_path=file_path, credential=self._raw_credential,
510515
_hosts=self._hosts, _configuration=self._config, _pipeline=self._pipeline,
@@ -531,6 +536,10 @@ def get_sub_directory_client(self, sub_directory # type: Union[DirectoryPropert
531536
except AttributeError:
532537
subdir_path = self.path_name + '/' + sub_directory
533538

539+
_pipeline = Pipeline(
540+
transport=TransportWrapper(self._pipeline._transport), # pylint: disable = protected-access
541+
policies=self._pipeline._impl_policies # pylint: disable = protected-access
542+
)
534543
return DataLakeDirectoryClient(
535544
self.url, self.file_system_name, directory_name=subdir_path, credential=self._raw_credential,
536545
_hosts=self._hosts, _configuration=self._config, _pipeline=self._pipeline,

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_service_client.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
from urlparse import urlparse # type: ignore
1111

1212
from azure.core.paging import ItemPaged
13+
from azure.core.pipeline import Pipeline
1314

1415
from azure.storage.blob import BlobServiceClient
15-
from ._shared.base_client import StorageAccountHostsMixin, parse_query, parse_connection_str
16+
from ._shared.base_client import TransportWrapper, StorageAccountHostsMixin, parse_query, parse_connection_str
1617
from ._file_system_client import FileSystemClient
1718
from ._data_lake_directory_client import DataLakeDirectoryClient
1819
from ._data_lake_file_client import DataLakeFileClient
@@ -325,9 +326,13 @@ def get_file_system_client(self, file_system # type: Union[FileSystemProperties
325326
except AttributeError:
326327
file_system_name = file_system
327328

329+
_pipeline = Pipeline(
330+
transport=TransportWrapper(self._pipeline._transport), # pylint: disable = protected-access
331+
policies=self._pipeline._impl_policies # pylint: disable = protected-access
332+
)
328333
return FileSystemClient(self.url, file_system_name, credential=self._raw_credential,
329334
_configuration=self._config,
330-
_pipeline=self._pipeline, _hosts=self._hosts,
335+
_pipeline=_pipeline, _hosts=self._hosts,
331336
require_encryption=self.require_encryption, key_encryption_key=self.key_encryption_key,
332337
key_resolver_function=self.key_resolver_function)
333338

@@ -367,9 +372,14 @@ def get_directory_client(self, file_system, # type: Union[FileSystemProperties,
367372
directory_name = directory.name
368373
except AttributeError:
369374
directory_name = directory
375+
376+
_pipeline = Pipeline(
377+
transport=TransportWrapper(self._pipeline._transport), # pylint: disable = protected-access
378+
policies=self._pipeline._impl_policies # pylint: disable = protected-access
379+
)
370380
return DataLakeDirectoryClient(self.url, file_system_name, directory_name=directory_name,
371381
credential=self._raw_credential,
372-
_configuration=self._config, _pipeline=self._pipeline,
382+
_configuration=self._config, _pipeline=_pipeline,
373383
_hosts=self._hosts,
374384
require_encryption=self.require_encryption,
375385
key_encryption_key=self.key_encryption_key,
@@ -413,9 +423,13 @@ def get_file_client(self, file_system, # type: Union[FileSystemProperties, str]
413423
except AttributeError:
414424
pass
415425

426+
_pipeline = Pipeline(
427+
transport=TransportWrapper(self._pipeline._transport), # pylint: disable = protected-access
428+
policies=self._pipeline._impl_policies # pylint: disable = protected-access
429+
)
416430
return DataLakeFileClient(
417431
self.url, file_system_name, file_path=file_path, credential=self._raw_credential,
418-
_hosts=self._hosts, _configuration=self._config, _pipeline=self._pipeline,
432+
_hosts=self._hosts, _configuration=self._config, _pipeline=_pipeline,
419433
require_encryption=self.require_encryption,
420434
key_encryption_key=self.key_encryption_key,
421435
key_resolver_function=self.key_resolver_function)

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
from urllib2 import quote # type: ignore
1313

1414
import six
15+
from azure.core.pipeline import Pipeline
1516
from azure.core.paging import ItemPaged
1617
from azure.storage.blob import ContainerClient
17-
from ._shared.base_client import StorageAccountHostsMixin, parse_query, parse_connection_str
18+
from ._shared.base_client import TransportWrapper, StorageAccountHostsMixin, parse_query, parse_connection_str
1819
from ._serialize import convert_dfs_url_to_blob_url
1920
from ._models import LocationMode, FileSystemProperties, PublicAccess
2021
from ._list_paths_helper import PathPropertiesPaged
@@ -737,10 +738,13 @@ def get_directory_client(self, directory # type: Union[DirectoryProperties, str
737738
directory_name = directory.name
738739
except AttributeError:
739740
directory_name = directory
740-
741+
_pipeline = Pipeline(
742+
transport=TransportWrapper(self._pipeline._transport), # pylint: disable = protected-access
743+
policies=self._pipeline._impl_policies # pylint: disable = protected-access
744+
)
741745
return DataLakeDirectoryClient(self.url, self.file_system_name, directory_name=directory_name,
742746
credential=self._raw_credential,
743-
_configuration=self._config, _pipeline=self._pipeline,
747+
_configuration=self._config, _pipeline=_pipeline,
744748
_hosts=self._hosts,
745749
require_encryption=self.require_encryption,
746750
key_encryption_key=self.key_encryption_key,
@@ -774,10 +778,13 @@ def get_file_client(self, file_path # type: Union[FileProperties, str]
774778
file_path = file_path.name
775779
except AttributeError:
776780
pass
777-
781+
_pipeline = Pipeline(
782+
transport=TransportWrapper(self._pipeline._transport), # pylint: disable = protected-access
783+
policies=self._pipeline._impl_policies # pylint: disable = protected-access
784+
)
778785
return DataLakeFileClient(
779786
self.url, self.file_system_name, file_path=file_path, credential=self._raw_credential,
780-
_hosts=self._hosts, _configuration=self._config, _pipeline=self._pipeline,
787+
_hosts=self._hosts, _configuration=self._config, _pipeline=_pipeline,
781788
require_encryption=self.require_encryption,
782789
key_encryption_key=self.key_encryption_key,
783790
key_resolver_function=self.key_resolver_function)

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
from urllib.parse import quote, unquote
99
except ImportError:
1010
from urllib2 import quote, unquote # type: ignore
11+
from azure.core.pipeline import AsyncPipeline
1112
from ._data_lake_file_client_async import DataLakeFileClient
1213
from .._data_lake_directory_client import DataLakeDirectoryClient as DataLakeDirectoryClientBase
1314
from .._models import DirectoryProperties
1415
from .._deserialize import deserialize_dir_properties
1516
from ._path_client_async import PathClient
17+
from .._shared.base_client_async import AsyncTransportWrapper
1618

1719

1820
class DataLakeDirectoryClient(PathClient, DataLakeDirectoryClientBase):
@@ -483,6 +485,10 @@ def get_file_client(self, file # type: Union[FileProperties, str]
483485
except AttributeError:
484486
file_path = self.path_name + '/' + file
485487

488+
_pipeline = AsyncPipeline(
489+
transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable = protected-access
490+
policies=self._pipeline._impl_policies # pylint: disable = protected-access
491+
)
486492
return DataLakeFileClient(
487493
self.url, self.file_system_name, file_path=file_path, credential=self._raw_credential,
488494
_hosts=self._hosts, _configuration=self._config, _pipeline=self._pipeline,
@@ -518,6 +524,10 @@ def get_sub_directory_client(self, sub_directory # type: Union[DirectoryPropert
518524
except AttributeError:
519525
subdir_path = self.path_name + '/' + sub_directory
520526

527+
_pipeline = AsyncPipeline(
528+
transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable = protected-access
529+
policies=self._pipeline._impl_policies # pylint: disable = protected-access
530+
)
521531
return DataLakeDirectoryClient(
522532
self.url, self.file_system_name, directory_name=subdir_path, credential=self._raw_credential,
523533
_hosts=self._hosts, _configuration=self._config, _pipeline=self._pipeline,

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_service_client_async.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
# pylint: disable=invalid-overridden-method
77

88
from azure.core.paging import ItemPaged
9+
from azure.core.pipeline import AsyncPipeline
910

1011
from azure.storage.blob.aio import BlobServiceClient
1112
from .._generated.aio import DataLakeStorageClient
12-
from .._shared.base_client_async import AsyncStorageAccountHostsMixin
13+
from .._shared.base_client_async import AsyncTransportWrapper, AsyncStorageAccountHostsMixin
1314
from ._file_system_client_async import FileSystemClient
1415
from .._data_lake_service_client import DataLakeServiceClient as DataLakeServiceClientBase
1516
from .._shared.policies_async import ExponentialRetry
@@ -276,6 +277,10 @@ def get_file_system_client(self, file_system # type: Union[FileSystemProperties
276277
except AttributeError:
277278
file_system_name = file_system
278279

280+
_pipeline = AsyncPipeline(
281+
transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable = protected-access
282+
policies=self._pipeline._impl_policies # pylint: disable = protected-access
283+
)
279284
return FileSystemClient(self.url, file_system_name, credential=self._raw_credential,
280285
_configuration=self._config,
281286
_pipeline=self._pipeline, _hosts=self._hosts,
@@ -318,6 +323,11 @@ def get_directory_client(self, file_system, # type: Union[FileSystemProperties,
318323
directory_name = directory.name
319324
except AttributeError:
320325
directory_name = directory
326+
327+
_pipeline = AsyncPipeline(
328+
transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable = protected-access
329+
policies=self._pipeline._impl_policies # pylint: disable = protected-access
330+
)
321331
return DataLakeDirectoryClient(self.url, file_system_name, directory_name=directory_name,
322332
credential=self._raw_credential,
323333
_configuration=self._config, _pipeline=self._pipeline,
@@ -364,6 +374,10 @@ def get_file_client(self, file_system, # type: Union[FileSystemProperties, str]
364374
except AttributeError:
365375
pass
366376

377+
_pipeline = AsyncPipeline(
378+
transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable = protected-access
379+
policies=self._pipeline._impl_policies # pylint: disable = protected-access
380+
)
367381
return DataLakeFileClient(
368382
self.url, file_system_name, file_path=file_path, credential=self._raw_credential,
369383
_hosts=self._hosts, _configuration=self._config, _pipeline=self._pipeline,

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from azure.core.tracing.decorator import distributed_trace
1515

16+
from azure.core.pipeline import AsyncPipeline
1617
from azure.core.async_paging import AsyncItemPaged
1718

1819
from azure.core.tracing.decorator_async import distributed_trace_async
@@ -24,7 +25,7 @@
2425
from ._data_lake_lease_async import DataLakeLeaseClient
2526
from .._file_system_client import FileSystemClient as FileSystemClientBase
2627
from .._generated.aio import DataLakeStorageClient
27-
from .._shared.base_client_async import AsyncStorageAccountHostsMixin
28+
from .._shared.base_client_async import AsyncTransportWrapper, AsyncStorageAccountHostsMixin
2829
from .._shared.policies_async import ExponentialRetry
2930
from .._models import FileSystemProperties, PublicAccess
3031

@@ -698,10 +699,13 @@ def get_directory_client(self, directory # type: Union[DirectoryProperties, str
698699
directory_name = directory.name
699700
except AttributeError:
700701
directory_name = directory
701-
702+
_pipeline = AsyncPipeline(
703+
transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable = protected-access
704+
policies=self._pipeline._impl_policies # pylint: disable = protected-access
705+
)
702706
return DataLakeDirectoryClient(self.url, self.file_system_name, directory_name=directory_name,
703707
credential=self._raw_credential,
704-
_configuration=self._config, _pipeline=self._pipeline,
708+
_configuration=self._config, _pipeline=_pipeline,
705709
_hosts=self._hosts,
706710
require_encryption=self.require_encryption,
707711
key_encryption_key=self.key_encryption_key,
@@ -736,10 +740,13 @@ def get_file_client(self, file_path # type: Union[FileProperties, str]
736740
file_path = file_path.name
737741
except AttributeError:
738742
pass
739-
743+
_pipeline = AsyncPipeline(
744+
transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable = protected-access
745+
policies=self._pipeline._impl_policies # pylint: disable = protected-access
746+
)
740747
return DataLakeFileClient(
741748
self.url, self.file_system_name, file_path=file_path, credential=self._raw_credential,
742-
_hosts=self._hosts, _configuration=self._config, _pipeline=self._pipeline,
749+
_hosts=self._hosts, _configuration=self._config, _pipeline=_pipeline,
743750
require_encryption=self.require_encryption,
744751
key_encryption_key=self.key_encryption_key,
745752
key_resolver_function=self.key_resolver_function, loop=self._loop)

0 commit comments

Comments
 (0)