-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Event Hubs] Port azure storage blob code into checkpointstore #9950
Merged
Merged
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
cb13bd8
Increment version
38e9f65
Update Development Status
aa30bc0
Merge branch 'master' of github.com:Azure/azure-sdk-for-python
c4710ea
Merge branch 'master' of github.com:Azure/azure-sdk-for-python
1e2d6a6
Vendor storage blob code into checkpointstore
c0db2d4
Disable eventhub checkpointstore mypy check because storage code isn'…
053f073
Merge branch 'master' of github.com:Azure/azure-sdk-for-python
fb61190
Add storage aio stuffs to keep storage the same as the sync version
7a7e36f
change import azure.storage to relative path
09b381f
Comment setup dependency for vendored storage blob
6f34562
Remove storage and added msrest to checkpointstoreblob in shared requ…
ebad9a2
Add extra require to vendored storage
0260763
override azure-core for checkpointstoreblob
e60e3cd
Merge branch 'master' into eventhubs_vendor_strg
d6bcb6e
override azure-core for checkpointstoreblob
b72463d
Update change log
856e829
Update README
2043ea8
Update README for different version of storage service api
cfb9939
Update sample for different version of storage service api
c776c5f
Update docstring
83ce82c
Restore to storage original version
8eb3fe1
Remove api_version in docstring
7f59a05
Add x-ms-version in sample code
8a1b7d8
Update Change Log
7e69ba8
use x-ms-version instead of api_version
da4a1b2
Update README back to use api_version
2f21f2a
Add api_version param
b456078
Update api_version to change log
c9f9f86
Remove storage version
08cccd5
Add storage api version sample
f15bb72
small grammar fix
fbe82e6
Fixes from code review
a50a002
Fixes from code review
76e26c3
Correct BlobPartitionManager to BlobCheckpointStore
ab1d4ab
put headers into kwargs
defe600
Remove "Azure Stack" from readme
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...ckpointstoreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# ----------------------------------------------------------------------------------- |
1 change: 1 addition & 0 deletions
1
...toreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: str |
210 changes: 210 additions & 0 deletions
210
...lob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/blob/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
# ------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# -------------------------------------------------------------------------- | ||
|
||
import os | ||
|
||
from typing import Union, Iterable, AnyStr, IO, Any, Dict # pylint: disable=unused-import | ||
from ._version import VERSION | ||
from ._blob_client import BlobClient | ||
from ._container_client import ContainerClient | ||
from ._blob_service_client import BlobServiceClient | ||
from ._lease import BlobLeaseClient | ||
from ._download import StorageStreamDownloader | ||
from ._shared_access_signature import generate_account_sas, generate_container_sas, generate_blob_sas | ||
from ._shared.policies import ExponentialRetry, LinearRetry | ||
from ._shared.response_handlers import PartialBatchErrorException | ||
from ._shared.models import( | ||
LocationMode, | ||
ResourceTypes, | ||
AccountSasPermissions, | ||
StorageErrorCode, | ||
UserDelegationKey | ||
) | ||
from ._generated.models import ( | ||
RehydratePriority | ||
) | ||
from ._models import ( | ||
BlobType, | ||
BlockState, | ||
StandardBlobTier, | ||
PremiumPageBlobTier, | ||
SequenceNumberAction, | ||
PublicAccess, | ||
BlobAnalyticsLogging, | ||
Metrics, | ||
RetentionPolicy, | ||
StaticWebsite, | ||
CorsRule, | ||
ContainerProperties, | ||
BlobProperties, | ||
LeaseProperties, | ||
ContentSettings, | ||
CopyProperties, | ||
BlobBlock, | ||
PageRange, | ||
AccessPolicy, | ||
ContainerSasPermissions, | ||
BlobSasPermissions, | ||
CustomerProvidedEncryptionKey, | ||
ContainerEncryptionScope | ||
) | ||
|
||
__version__ = VERSION | ||
|
||
|
||
def upload_blob_to_url( | ||
blob_url, # type: str | ||
data, # type: Union[Iterable[AnyStr], IO[AnyStr]] | ||
credential=None, # type: Any | ||
**kwargs): | ||
# type: (...) -> Dict[str, Any] | ||
"""Upload data to a given URL | ||
|
||
The data will be uploaded as a block blob. | ||
|
||
:param str blob_url: | ||
The full URI to the blob. This can also include a SAS token. | ||
:param data: | ||
The data to upload. This can be bytes, text, an iterable or a file-like object. | ||
:type data: bytes or str or Iterable | ||
:param credential: | ||
The credentials with which to authenticate. This is optional if the | ||
blob URL already has a SAS token. The value can be a SAS token string, an account | ||
shared access key, or an instance of a TokenCredentials class from azure.identity. | ||
If the URL already has a SAS token, specifying an explicit credential will take priority. | ||
:keyword bool overwrite: | ||
Whether the blob to be uploaded should overwrite the current data. | ||
If True, upload_blob_to_url will overwrite any existing data. If set to False, the | ||
operation will fail with a ResourceExistsError. | ||
:keyword int max_concurrency: | ||
The number of parallel connections with which to download. | ||
:keyword int length: | ||
Number of bytes to read from the stream. This is optional, but | ||
should be supplied for optimal performance. | ||
:keyword dict(str,str) metadata: | ||
Name-value pairs associated with the blob as metadata. | ||
:keyword bool validate_content: | ||
If true, calculates an MD5 hash for each chunk of the blob. The storage | ||
service checks the hash of the content that has arrived with the hash | ||
that was sent. This is primarily valuable for detecting bitflips on | ||
the wire if using http instead of https as https (the default) will | ||
already validate. Note that this MD5 hash is not stored with the | ||
blob. Also note that if enabled, the memory-efficient upload algorithm | ||
will not be used, because computing the MD5 hash requires buffering | ||
entire blocks, and doing so defeats the purpose of the memory-efficient algorithm. | ||
:keyword str encoding: | ||
Encoding to use if text is supplied as input. Defaults to UTF-8. | ||
:returns: Blob-updated property dict (Etag and last modified) | ||
:rtype: dict(str, Any) | ||
""" | ||
with BlobClient.from_blob_url(blob_url, credential=credential) as client: | ||
return client.upload_blob(data=data, blob_type=BlobType.BlockBlob, **kwargs) | ||
|
||
|
||
def _download_to_stream(client, handle, **kwargs): | ||
"""Download data to specified open file-handle.""" | ||
stream = client.download_blob(**kwargs) | ||
stream.readinto(handle) | ||
|
||
|
||
def download_blob_from_url( | ||
blob_url, # type: str | ||
output, # type: str | ||
credential=None, # type: Any | ||
**kwargs): | ||
# type: (...) -> None | ||
"""Download the contents of a blob to a local file or stream. | ||
|
||
:param str blob_url: | ||
The full URI to the blob. This can also include a SAS token. | ||
:param output: | ||
Where the data should be downloaded to. This could be either a file path to write to, | ||
or an open IO handle to write to. | ||
:type output: str or writable stream. | ||
:param credential: | ||
The credentials with which to authenticate. This is optional if the | ||
blob URL already has a SAS token or the blob is public. The value can be a SAS token string, | ||
an account shared access key, or an instance of a TokenCredentials class from azure.identity. | ||
If the URL already has a SAS token, specifying an explicit credential will take priority. | ||
:keyword bool overwrite: | ||
Whether the local file should be overwritten if it already exists. The default value is | ||
`False` - in which case a ValueError will be raised if the file already exists. If set to | ||
`True`, an attempt will be made to write to the existing file. If a stream handle is passed | ||
in, this value is ignored. | ||
:keyword int max_concurrency: | ||
The number of parallel connections with which to download. | ||
:keyword int offset: | ||
Start of byte range to use for downloading a section of the blob. | ||
Must be set if length is provided. | ||
:keyword int length: | ||
Number of bytes to read from the stream. This is optional, but | ||
should be supplied for optimal performance. | ||
:keyword bool validate_content: | ||
If true, calculates an MD5 hash for each chunk of the blob. The storage | ||
service checks the hash of the content that has arrived with the hash | ||
that was sent. This is primarily valuable for detecting bitflips on | ||
the wire if using http instead of https as https (the default) will | ||
already validate. Note that this MD5 hash is not stored with the | ||
blob. Also note that if enabled, the memory-efficient upload algorithm | ||
will not be used, because computing the MD5 hash requires buffering | ||
entire blocks, and doing so defeats the purpose of the memory-efficient algorithm. | ||
:rtype: None | ||
""" | ||
overwrite = kwargs.pop('overwrite', False) | ||
with BlobClient.from_blob_url(blob_url, credential=credential) as client: | ||
if hasattr(output, 'write'): | ||
_download_to_stream(client, output, **kwargs) | ||
else: | ||
if not overwrite and os.path.isfile(output): | ||
raise ValueError("The file '{}' already exists.".format(output)) | ||
with open(output, 'wb') as file_handle: | ||
_download_to_stream(client, file_handle, **kwargs) | ||
|
||
|
||
__all__ = [ | ||
'upload_blob_to_url', | ||
'download_blob_from_url', | ||
'BlobServiceClient', | ||
'ContainerClient', | ||
'BlobClient', | ||
'BlobType', | ||
'BlobLeaseClient', | ||
'StorageErrorCode', | ||
'UserDelegationKey', | ||
'ExponentialRetry', | ||
'LinearRetry', | ||
'LocationMode', | ||
'BlockState', | ||
'StandardBlobTier', | ||
'PremiumPageBlobTier', | ||
'SequenceNumberAction', | ||
'PublicAccess', | ||
'BlobAnalyticsLogging', | ||
'Metrics', | ||
'RetentionPolicy', | ||
'StaticWebsite', | ||
'CorsRule', | ||
'ContainerProperties', | ||
'BlobProperties', | ||
'LeaseProperties', | ||
'ContentSettings', | ||
'CopyProperties', | ||
'BlobBlock', | ||
'PageRange', | ||
'AccessPolicy', | ||
'ContainerSasPermissions', | ||
'BlobSasPermissions', | ||
'ResourceTypes', | ||
'AccountSasPermissions', | ||
'StorageStreamDownloader', | ||
'CustomerProvidedEncryptionKey', | ||
'RehydratePriority', | ||
'generate_account_sas', | ||
'generate_container_sas', | ||
'generate_blob_sas', | ||
'PartialBatchErrorException', | ||
'ContainerEncryptionScope' | ||
] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could simplify:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to this