From 80f94c177e0beb65b798ba6ec71c9cd0b1ba9f5f Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Thu, 4 Mar 2021 15:06:19 -0800 Subject: [PATCH 1/2] Fix dup cloud error --- .../accesscontrol/_access_control_client.py | 19 +++ .../aio/_access_control_client.py | 18 +++ .../synapse/artifacts/_artifacts_client.py | 19 +++ .../artifacts/aio/_artifacts_client.py | 18 +++ .../aio/operations/_library_operations.py | 127 ++++++----------- .../synapse/artifacts/models/__init__.py | 3 - .../azure/synapse/artifacts/models/_models.py | 42 +----- .../synapse/artifacts/models/_models_py3.py | 49 +------ .../operations/_library_operations.py | 128 ++++++------------ .../_managed_private_endpoints_client.py | 19 +++ .../aio/_managed_private_endpoints_client.py | 18 +++ .../synapse/monitoring/_monitoring_client.py | 19 +++ .../monitoring/aio/_monitoring_client.py | 18 +++ .../azure/synapse/spark/_spark_client.py | 21 +++ .../azure/synapse/spark/aio/_spark_client.py | 20 +++ 15 files changed, 280 insertions(+), 258 deletions(-) diff --git a/sdk/synapse/azure-synapse-accesscontrol/azure/synapse/accesscontrol/_access_control_client.py b/sdk/synapse/azure-synapse-accesscontrol/azure/synapse/accesscontrol/_access_control_client.py index c4b8f7690a65..bda2c8e3ed15 100644 --- a/sdk/synapse/azure-synapse-accesscontrol/azure/synapse/accesscontrol/_access_control_client.py +++ b/sdk/synapse/azure-synapse-accesscontrol/azure/synapse/accesscontrol/_access_control_client.py @@ -16,6 +16,7 @@ from typing import Any from azure.core.credentials import TokenCredential + from azure.core.pipeline.transport import HttpRequest, HttpResponse from ._configuration import AccessControlClientConfiguration from .operations import RoleAssignmentsOperations @@ -57,6 +58,24 @@ def __init__( self.role_definitions = RoleDefinitionsOperations( self._client, self._config, self._serialize, self._deserialize) + def _send_request(self, http_request, **kwargs): + # type: (HttpRequest, Any) -> HttpResponse + """Runs the network request through the client's chained policies. + + :param http_request: The network request you want to make. Required. + :type http_request: ~azure.core.pipeline.transport.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to True. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.pipeline.transport.HttpResponse + """ + path_format_arguments = { + 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), + } + http_request.url = self._client.format_url(http_request.url, **path_format_arguments) + stream = kwargs.pop("stream", True) + pipeline_response = self._client._pipeline.run(http_request, stream=stream, **kwargs) + return pipeline_response.http_response + def close(self): # type: () -> None self._client.close() diff --git a/sdk/synapse/azure-synapse-accesscontrol/azure/synapse/accesscontrol/aio/_access_control_client.py b/sdk/synapse/azure-synapse-accesscontrol/azure/synapse/accesscontrol/aio/_access_control_client.py index 5a9dce9bbbd9..eb39ac127e65 100644 --- a/sdk/synapse/azure-synapse-accesscontrol/azure/synapse/accesscontrol/aio/_access_control_client.py +++ b/sdk/synapse/azure-synapse-accesscontrol/azure/synapse/accesscontrol/aio/_access_control_client.py @@ -9,6 +9,7 @@ from typing import Any, TYPE_CHECKING from azure.core import AsyncPipelineClient +from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest from msrest import Deserializer, Serializer if TYPE_CHECKING: @@ -54,6 +55,23 @@ def __init__( self.role_definitions = RoleDefinitionsOperations( self._client, self._config, self._serialize, self._deserialize) + async def _send_request(self, http_request: HttpRequest, **kwargs: Any) -> AsyncHttpResponse: + """Runs the network request through the client's chained policies. + + :param http_request: The network request you want to make. Required. + :type http_request: ~azure.core.pipeline.transport.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to True. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.pipeline.transport.AsyncHttpResponse + """ + path_format_arguments = { + 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), + } + http_request.url = self._client.format_url(http_request.url, **path_format_arguments) + stream = kwargs.pop("stream", True) + pipeline_response = await self._client._pipeline.run(http_request, stream=stream, **kwargs) + return pipeline_response.http_response + async def close(self) -> None: await self._client.close() diff --git a/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/_artifacts_client.py b/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/_artifacts_client.py index 5c93dad0d85a..994f4fc3312f 100644 --- a/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/_artifacts_client.py +++ b/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/_artifacts_client.py @@ -16,6 +16,7 @@ from typing import Any from azure.core.credentials import TokenCredential + from azure.core.pipeline.transport import HttpRequest, HttpResponse from ._configuration import ArtifactsClientConfiguration from .operations import LinkedServiceOperations @@ -133,6 +134,24 @@ def __init__( self.workspace_git_repo_management = WorkspaceGitRepoManagementOperations( self._client, self._config, self._serialize, self._deserialize) + def _send_request(self, http_request, **kwargs): + # type: (HttpRequest, Any) -> HttpResponse + """Runs the network request through the client's chained policies. + + :param http_request: The network request you want to make. Required. + :type http_request: ~azure.core.pipeline.transport.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to True. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.pipeline.transport.HttpResponse + """ + path_format_arguments = { + 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), + } + http_request.url = self._client.format_url(http_request.url, **path_format_arguments) + stream = kwargs.pop("stream", True) + pipeline_response = self._client._pipeline.run(http_request, stream=stream, **kwargs) + return pipeline_response.http_response + def close(self): # type: () -> None self._client.close() diff --git a/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/aio/_artifacts_client.py b/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/aio/_artifacts_client.py index 8bc04b0ad0e5..40d425d7c972 100644 --- a/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/aio/_artifacts_client.py +++ b/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/aio/_artifacts_client.py @@ -9,6 +9,7 @@ from typing import Any, TYPE_CHECKING from azure.core import AsyncPipelineClient +from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest from msrest import Deserializer, Serializer if TYPE_CHECKING: @@ -130,6 +131,23 @@ def __init__( self.workspace_git_repo_management = WorkspaceGitRepoManagementOperations( self._client, self._config, self._serialize, self._deserialize) + async def _send_request(self, http_request: HttpRequest, **kwargs: Any) -> AsyncHttpResponse: + """Runs the network request through the client's chained policies. + + :param http_request: The network request you want to make. Required. + :type http_request: ~azure.core.pipeline.transport.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to True. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.pipeline.transport.AsyncHttpResponse + """ + path_format_arguments = { + 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), + } + http_request.url = self._client.format_url(http_request.url, **path_format_arguments) + stream = kwargs.pop("stream", True) + pipeline_response = await self._client._pipeline.run(http_request, stream=stream, **kwargs) + return pipeline_response.http_response + async def close(self) -> None: await self._client.close() diff --git a/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/aio/operations/_library_operations.py b/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/aio/operations/_library_operations.py index 781a29e35314..8f83f4d7a7d2 100644 --- a/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/aio/operations/_library_operations.py +++ b/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/aio/operations/_library_operations.py @@ -102,7 +102,7 @@ async def get_next(next_link=None): response = pipeline_response.http_response if response.status_code not in [200]: - error = self._deserialize.failsafe_deserialize(_models.CloudErrorAutoGenerated, response) + error = self._deserialize.failsafe_deserialize(_models.CloudError, response) map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, model=error) @@ -148,7 +148,7 @@ async def _flush_initial( if response.status_code not in [200, 202]: map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.CloudErrorAutoGenerated, response) + error = self._deserialize.failsafe_deserialize(_models.CloudError, response) raise HttpResponseError(response=response, model=error) deserialized = None @@ -268,7 +268,7 @@ async def get_operation_result( if response.status_code not in [200, 202]: map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.CloudErrorAutoGenerated, response) + error = self._deserialize.failsafe_deserialize(_models.CloudError, response) raise HttpResponseError(response=response, model=error) if response.status_code == 200: @@ -318,7 +318,7 @@ async def _delete_initial( if response.status_code not in [200, 202, 409]: map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.CloudErrorAutoGenerated, response) + error = self._deserialize.failsafe_deserialize(_models.CloudError, response) raise HttpResponseError(response=response, model=error) deserialized = None @@ -439,7 +439,7 @@ async def get( if response.status_code not in [200, 304]: map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.CloudErrorAutoGenerated, response) + error = self._deserialize.failsafe_deserialize(_models.CloudError, response) raise HttpResponseError(response=response, model=error) deserialized = None @@ -452,9 +452,12 @@ async def get( return deserialized get.metadata = {'url': '/libraries/{libraryName}'} # type: ignore - async def _create_initial( + async def _create_or_append_initial( self, library_name: str, + comp: Optional[str] = None, + x_ms_blob_condition_appendpos: Optional[int] = None, + content: Optional[IO] = None, **kwargs ) -> Optional["_models.LibraryResourceInfo"]: cls = kwargs.pop('cls', None) # type: ClsType[Optional["_models.LibraryResourceInfo"]] @@ -463,10 +466,11 @@ async def _create_initial( } error_map.update(kwargs.pop('error_map', {})) api_version = "2019-06-01-preview" + content_type = kwargs.pop("content_type", "application/octet-stream") accept = "application/json" # Construct URL - url = self._create_initial.metadata['url'] # type: ignore + url = self._create_or_append_initial.metadata['url'] # type: ignore path_format_arguments = { 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), 'libraryName': self._serialize.url("library_name", library_name, 'str', max_length=100, min_length=0), @@ -476,18 +480,25 @@ async def _create_initial( # Construct parameters query_parameters = {} # type: Dict[str, Any] query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if comp is not None: + query_parameters['comp'] = self._serialize.query("comp", comp, 'str') # Construct headers header_parameters = {} # type: Dict[str, Any] + if x_ms_blob_condition_appendpos is not None: + header_parameters['x-ms-blob-condition-appendpos'] = self._serialize.header("x_ms_blob_condition_appendpos", x_ms_blob_condition_appendpos, 'long') + header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - request = self._client.put(url, query_parameters, header_parameters) + body_content_kwargs = {} # type: Dict[str, Any] + body_content_kwargs['stream_content'] = content + request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) response = pipeline_response.http_response - if response.status_code not in [200, 202]: + if response.status_code not in [200, 201, 202, 412]: map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.CloudErrorAutoGenerated, response) + error = self._deserialize.failsafe_deserialize(_models.CloudError, response) raise HttpResponseError(response=response, model=error) deserialized = None @@ -498,18 +509,32 @@ async def _create_initial( return cls(pipeline_response, deserialized, {}) return deserialized - _create_initial.metadata = {'url': '/libraries/{libraryName}'} # type: ignore + _create_or_append_initial.metadata = {'url': '/libraries/{libraryName}'} # type: ignore - async def begin_create( + async def begin_create_or_append( self, library_name: str, + comp: Optional[str] = None, + x_ms_blob_condition_appendpos: Optional[int] = None, + content: Optional[IO] = None, **kwargs ) -> AsyncLROPoller["_models.LibraryResourceInfo"]: - """Creates a library with the library name. + """Creates a library with the library name. Use query param 'comp=appendblock' to append the data + to the library resource created using the create operation. :param library_name: file name to upload. Minimum length of the filename should be 1 excluding the extension length. :type library_name: str + :param comp: If this param is specified with value appendblock, the api will append the data + chunk provided in body to the library created. + :type comp: str + :param x_ms_blob_condition_appendpos: Set this header to a byte offset at which the block is + expected to be appended. The request succeeds only if the current offset matches this value. + Otherwise, the request fails with the AppendPositionConditionNotMet error (HTTP status code 412 + – Precondition Failed). + :type x_ms_blob_condition_appendpos: long + :param content: Library file chunk. Use this content in with append operation. + :type content: IO :keyword callable cls: A custom type or function that will be passed the direct response :keyword str continuation_token: A continuation token to restart a poller from a saved state. :keyword polling: Pass in True if you'd like the AsyncLROBasePolling polling method, @@ -528,8 +553,11 @@ async def begin_create( ) cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] if cont_token is None: - raw_result = await self._create_initial( + raw_result = await self._create_or_append_initial( library_name=library_name, + comp=comp, + x_ms_blob_condition_appendpos=x_ms_blob_condition_appendpos, + content=content, cls=lambda x,y,z: x, **kwargs ) @@ -561,73 +589,4 @@ def get_long_running_output(pipeline_response): ) else: return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_create.metadata = {'url': '/libraries/{libraryName}'} # type: ignore - - async def append( - self, - library_name: str, - content: IO, - x_ms_blob_condition_appendpos: Optional[int] = None, - **kwargs - ) -> None: - """Append the content to the library resource created using the create operation. The maximum - content size is 4MiB. Content larger than 4MiB must be appended in 4MiB chunks. - - :param library_name: file name to upload. Minimum length of the filename should be 1 excluding - the extension length. - :type library_name: str - :param content: Library file chunk. - :type content: IO - :param x_ms_blob_condition_appendpos: Set this header to a byte offset at which the block is - expected to be appended. The request succeeds only if the current offset matches this value. - Otherwise, the request fails with the AppendPositionConditionNotMet error (HTTP status code 412 - – Precondition Failed). - :type x_ms_blob_condition_appendpos: long - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) - :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError - """ - cls = kwargs.pop('cls', None) # type: ClsType[None] - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {})) - api_version = "2019-06-01-preview" - content_type = kwargs.pop("content_type", "application/octet-stream") - accept = "application/json" - - # Construct URL - url = self.append.metadata['url'] # type: ignore - path_format_arguments = { - 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), - 'libraryName': self._serialize.url("library_name", library_name, 'str', max_length=100, min_length=0), - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') - - # Construct headers - header_parameters = {} # type: Dict[str, Any] - if x_ms_blob_condition_appendpos is not None: - header_parameters['x-ms-blob-condition-appendpos'] = self._serialize.header("x_ms_blob_condition_appendpos", x_ms_blob_condition_appendpos, 'long') - header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - - body_content_kwargs = {} # type: Dict[str, Any] - body_content_kwargs['stream_content'] = content - request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) - pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) - response = pipeline_response.http_response - - if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.CloudErrorAutoGenerated, response) - raise HttpResponseError(response=response, model=error) - - if cls: - return cls(pipeline_response, None, {}) - - append.metadata = {'url': '/libraries/{libraryName}'} # type: ignore + begin_create_or_append.metadata = {'url': '/libraries/{libraryName}'} # type: ignore diff --git a/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/models/__init__.py b/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/models/__init__.py index b132229bdfa9..08f76e9320ef 100644 --- a/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/models/__init__.py +++ b/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/models/__init__.py @@ -112,7 +112,6 @@ from ._models_py3 import CassandraTableDataset from ._models_py3 import ChainingTrigger from ._models_py3 import CloudError - from ._models_py3 import CloudErrorAutoGenerated from ._models_py3 import CommonDataServiceForAppsEntityDataset from ._models_py3 import CommonDataServiceForAppsLinkedService from ._models_py3 import CommonDataServiceForAppsSink @@ -718,7 +717,6 @@ from ._models import CassandraTableDataset # type: ignore from ._models import ChainingTrigger # type: ignore from ._models import CloudError # type: ignore - from ._models import CloudErrorAutoGenerated # type: ignore from ._models import CommonDataServiceForAppsEntityDataset # type: ignore from ._models import CommonDataServiceForAppsLinkedService # type: ignore from ._models import CommonDataServiceForAppsSink # type: ignore @@ -1427,7 +1425,6 @@ 'CassandraTableDataset', 'ChainingTrigger', 'CloudError', - 'CloudErrorAutoGenerated', 'CommonDataServiceForAppsEntityDataset', 'CommonDataServiceForAppsLinkedService', 'CommonDataServiceForAppsSink', diff --git a/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/models/_models.py b/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/models/_models.py index 4ec085b56406..15aa2697503b 100644 --- a/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/models/_models.py +++ b/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/models/_models.py @@ -6963,44 +6963,6 @@ def __init__( self.details = kwargs.get('details', None) -class CloudErrorAutoGenerated(msrest.serialization.Model): - """The object that defines the structure of an Azure Synapse error response. - - All required parameters must be populated in order to send to Azure. - - :param code: Required. Error code. - :type code: str - :param message: Required. Error message. - :type message: str - :param target: Property name/path in request associated with error. - :type target: str - :param details: Array with additional error details. - :type details: list[~azure.synapse.artifacts.models.CloudErrorAutoGenerated] - """ - - _validation = { - 'code': {'required': True}, - 'message': {'required': True}, - } - - _attribute_map = { - 'code': {'key': 'error.code', 'type': 'str'}, - 'message': {'key': 'error.message', 'type': 'str'}, - 'target': {'key': 'error.target', 'type': 'str'}, - 'details': {'key': 'error.details', 'type': '[CloudErrorAutoGenerated]'}, - } - - def __init__( - self, - **kwargs - ): - super(CloudErrorAutoGenerated, self).__init__(**kwargs) - self.code = kwargs['code'] - self.message = kwargs['message'] - self.target = kwargs.get('target', None) - self.details = kwargs.get('details', None) - - class CommonDataServiceForAppsEntityDataset(Dataset): """The Common Data Service for Apps entity dataset. @@ -20617,7 +20579,7 @@ class OperationResult(msrest.serialization.Model): :param target: Property name/path in request associated with error. :type target: str :param details: Array with additional error details. - :type details: list[~azure.synapse.artifacts.models.CloudErrorAutoGenerated] + :type details: list[~azure.synapse.artifacts.models.CloudError] """ _validation = { @@ -20629,7 +20591,7 @@ class OperationResult(msrest.serialization.Model): 'code': {'key': 'error.code', 'type': 'str'}, 'message': {'key': 'error.message', 'type': 'str'}, 'target': {'key': 'error.target', 'type': 'str'}, - 'details': {'key': 'error.details', 'type': '[CloudErrorAutoGenerated]'}, + 'details': {'key': 'error.details', 'type': '[CloudError]'}, } def __init__( diff --git a/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/models/_models_py3.py b/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/models/_models_py3.py index a09237c67c71..891f75314d1e 100644 --- a/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/models/_models_py3.py +++ b/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/models/_models_py3.py @@ -7961,49 +7961,6 @@ def __init__( self.details = details -class CloudErrorAutoGenerated(msrest.serialization.Model): - """The object that defines the structure of an Azure Synapse error response. - - All required parameters must be populated in order to send to Azure. - - :param code: Required. Error code. - :type code: str - :param message: Required. Error message. - :type message: str - :param target: Property name/path in request associated with error. - :type target: str - :param details: Array with additional error details. - :type details: list[~azure.synapse.artifacts.models.CloudErrorAutoGenerated] - """ - - _validation = { - 'code': {'required': True}, - 'message': {'required': True}, - } - - _attribute_map = { - 'code': {'key': 'error.code', 'type': 'str'}, - 'message': {'key': 'error.message', 'type': 'str'}, - 'target': {'key': 'error.target', 'type': 'str'}, - 'details': {'key': 'error.details', 'type': '[CloudErrorAutoGenerated]'}, - } - - def __init__( - self, - *, - code: str, - message: str, - target: Optional[str] = None, - details: Optional[List["CloudErrorAutoGenerated"]] = None, - **kwargs - ): - super(CloudErrorAutoGenerated, self).__init__(**kwargs) - self.code = code - self.message = message - self.target = target - self.details = details - - class CommonDataServiceForAppsEntityDataset(Dataset): """The Common Data Service for Apps entity dataset. @@ -23598,7 +23555,7 @@ class OperationResult(msrest.serialization.Model): :param target: Property name/path in request associated with error. :type target: str :param details: Array with additional error details. - :type details: list[~azure.synapse.artifacts.models.CloudErrorAutoGenerated] + :type details: list[~azure.synapse.artifacts.models.CloudError] """ _validation = { @@ -23610,7 +23567,7 @@ class OperationResult(msrest.serialization.Model): 'code': {'key': 'error.code', 'type': 'str'}, 'message': {'key': 'error.message', 'type': 'str'}, 'target': {'key': 'error.target', 'type': 'str'}, - 'details': {'key': 'error.details', 'type': '[CloudErrorAutoGenerated]'}, + 'details': {'key': 'error.details', 'type': '[CloudError]'}, } def __init__( @@ -23619,7 +23576,7 @@ def __init__( code: Optional[str] = None, message: Optional[str] = None, target: Optional[str] = None, - details: Optional[List["CloudErrorAutoGenerated"]] = None, + details: Optional[List["CloudError"]] = None, **kwargs ): super(OperationResult, self).__init__(**kwargs) diff --git a/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/operations/_library_operations.py b/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/operations/_library_operations.py index 19964a31957f..3b92bd4f8e9e 100644 --- a/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/operations/_library_operations.py +++ b/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/operations/_library_operations.py @@ -107,7 +107,7 @@ def get_next(next_link=None): response = pipeline_response.http_response if response.status_code not in [200]: - error = self._deserialize.failsafe_deserialize(_models.CloudErrorAutoGenerated, response) + error = self._deserialize.failsafe_deserialize(_models.CloudError, response) map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, model=error) @@ -154,7 +154,7 @@ def _flush_initial( if response.status_code not in [200, 202]: map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.CloudErrorAutoGenerated, response) + error = self._deserialize.failsafe_deserialize(_models.CloudError, response) raise HttpResponseError(response=response, model=error) deserialized = None @@ -276,7 +276,7 @@ def get_operation_result( if response.status_code not in [200, 202]: map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.CloudErrorAutoGenerated, response) + error = self._deserialize.failsafe_deserialize(_models.CloudError, response) raise HttpResponseError(response=response, model=error) if response.status_code == 200: @@ -327,7 +327,7 @@ def _delete_initial( if response.status_code not in [200, 202, 409]: map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.CloudErrorAutoGenerated, response) + error = self._deserialize.failsafe_deserialize(_models.CloudError, response) raise HttpResponseError(response=response, model=error) deserialized = None @@ -450,7 +450,7 @@ def get( if response.status_code not in [200, 304]: map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.CloudErrorAutoGenerated, response) + error = self._deserialize.failsafe_deserialize(_models.CloudError, response) raise HttpResponseError(response=response, model=error) deserialized = None @@ -463,9 +463,12 @@ def get( return deserialized get.metadata = {'url': '/libraries/{libraryName}'} # type: ignore - def _create_initial( + def _create_or_append_initial( self, library_name, # type: str + comp=None, # type: Optional[str] + x_ms_blob_condition_appendpos=None, # type: Optional[int] + content=None, # type: Optional[IO] **kwargs # type: Any ): # type: (...) -> Optional["_models.LibraryResourceInfo"] @@ -475,10 +478,11 @@ def _create_initial( } error_map.update(kwargs.pop('error_map', {})) api_version = "2019-06-01-preview" + content_type = kwargs.pop("content_type", "application/octet-stream") accept = "application/json" # Construct URL - url = self._create_initial.metadata['url'] # type: ignore + url = self._create_or_append_initial.metadata['url'] # type: ignore path_format_arguments = { 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), 'libraryName': self._serialize.url("library_name", library_name, 'str', max_length=100, min_length=0), @@ -488,18 +492,25 @@ def _create_initial( # Construct parameters query_parameters = {} # type: Dict[str, Any] query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if comp is not None: + query_parameters['comp'] = self._serialize.query("comp", comp, 'str') # Construct headers header_parameters = {} # type: Dict[str, Any] + if x_ms_blob_condition_appendpos is not None: + header_parameters['x-ms-blob-condition-appendpos'] = self._serialize.header("x_ms_blob_condition_appendpos", x_ms_blob_condition_appendpos, 'long') + header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - request = self._client.put(url, query_parameters, header_parameters) + body_content_kwargs = {} # type: Dict[str, Any] + body_content_kwargs['stream_content'] = content + request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) response = pipeline_response.http_response - if response.status_code not in [200, 202]: + if response.status_code not in [200, 201, 202, 412]: map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.CloudErrorAutoGenerated, response) + error = self._deserialize.failsafe_deserialize(_models.CloudError, response) raise HttpResponseError(response=response, model=error) deserialized = None @@ -510,19 +521,33 @@ def _create_initial( return cls(pipeline_response, deserialized, {}) return deserialized - _create_initial.metadata = {'url': '/libraries/{libraryName}'} # type: ignore + _create_or_append_initial.metadata = {'url': '/libraries/{libraryName}'} # type: ignore - def begin_create( + def begin_create_or_append( self, library_name, # type: str + comp=None, # type: Optional[str] + x_ms_blob_condition_appendpos=None, # type: Optional[int] + content=None, # type: Optional[IO] **kwargs # type: Any ): # type: (...) -> LROPoller["_models.LibraryResourceInfo"] - """Creates a library with the library name. + """Creates a library with the library name. Use query param 'comp=appendblock' to append the data + to the library resource created using the create operation. :param library_name: file name to upload. Minimum length of the filename should be 1 excluding the extension length. :type library_name: str + :param comp: If this param is specified with value appendblock, the api will append the data + chunk provided in body to the library created. + :type comp: str + :param x_ms_blob_condition_appendpos: Set this header to a byte offset at which the block is + expected to be appended. The request succeeds only if the current offset matches this value. + Otherwise, the request fails with the AppendPositionConditionNotMet error (HTTP status code 412 + – Precondition Failed). + :type x_ms_blob_condition_appendpos: long + :param content: Library file chunk. Use this content in with append operation. + :type content: IO :keyword callable cls: A custom type or function that will be passed the direct response :keyword str continuation_token: A continuation token to restart a poller from a saved state. :keyword polling: Pass in True if you'd like the LROBasePolling polling method, @@ -541,8 +566,11 @@ def begin_create( ) cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] if cont_token is None: - raw_result = self._create_initial( + raw_result = self._create_or_append_initial( library_name=library_name, + comp=comp, + x_ms_blob_condition_appendpos=x_ms_blob_condition_appendpos, + content=content, cls=lambda x,y,z: x, **kwargs ) @@ -574,74 +602,4 @@ def get_long_running_output(pipeline_response): ) else: return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_create.metadata = {'url': '/libraries/{libraryName}'} # type: ignore - - def append( - self, - library_name, # type: str - content, # type: IO - x_ms_blob_condition_appendpos=None, # type: Optional[int] - **kwargs # type: Any - ): - # type: (...) -> None - """Append the content to the library resource created using the create operation. The maximum - content size is 4MiB. Content larger than 4MiB must be appended in 4MiB chunks. - - :param library_name: file name to upload. Minimum length of the filename should be 1 excluding - the extension length. - :type library_name: str - :param content: Library file chunk. - :type content: IO - :param x_ms_blob_condition_appendpos: Set this header to a byte offset at which the block is - expected to be appended. The request succeeds only if the current offset matches this value. - Otherwise, the request fails with the AppendPositionConditionNotMet error (HTTP status code 412 - – Precondition Failed). - :type x_ms_blob_condition_appendpos: long - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) - :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError - """ - cls = kwargs.pop('cls', None) # type: ClsType[None] - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {})) - api_version = "2019-06-01-preview" - content_type = kwargs.pop("content_type", "application/octet-stream") - accept = "application/json" - - # Construct URL - url = self.append.metadata['url'] # type: ignore - path_format_arguments = { - 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), - 'libraryName': self._serialize.url("library_name", library_name, 'str', max_length=100, min_length=0), - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') - - # Construct headers - header_parameters = {} # type: Dict[str, Any] - if x_ms_blob_condition_appendpos is not None: - header_parameters['x-ms-blob-condition-appendpos'] = self._serialize.header("x_ms_blob_condition_appendpos", x_ms_blob_condition_appendpos, 'long') - header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - - body_content_kwargs = {} # type: Dict[str, Any] - body_content_kwargs['stream_content'] = content - request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) - pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) - response = pipeline_response.http_response - - if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.CloudErrorAutoGenerated, response) - raise HttpResponseError(response=response, model=error) - - if cls: - return cls(pipeline_response, None, {}) - - append.metadata = {'url': '/libraries/{libraryName}'} # type: ignore + begin_create_or_append.metadata = {'url': '/libraries/{libraryName}'} # type: ignore diff --git a/sdk/synapse/azure-synapse-managedprivateendpoints/azure/synapse/managedprivateendpoints/_managed_private_endpoints_client.py b/sdk/synapse/azure-synapse-managedprivateendpoints/azure/synapse/managedprivateendpoints/_managed_private_endpoints_client.py index 8a44f57739e1..f0c44e88f026 100644 --- a/sdk/synapse/azure-synapse-managedprivateendpoints/azure/synapse/managedprivateendpoints/_managed_private_endpoints_client.py +++ b/sdk/synapse/azure-synapse-managedprivateendpoints/azure/synapse/managedprivateendpoints/_managed_private_endpoints_client.py @@ -16,6 +16,7 @@ from typing import Any from azure.core.credentials import TokenCredential + from azure.core.pipeline.transport import HttpRequest, HttpResponse from ._configuration import ManagedPrivateEndpointsClientConfiguration from .operations import ManagedPrivateEndpointsOperations @@ -52,6 +53,24 @@ def __init__( self.managed_private_endpoints = ManagedPrivateEndpointsOperations( self._client, self._config, self._serialize, self._deserialize) + def _send_request(self, http_request, **kwargs): + # type: (HttpRequest, Any) -> HttpResponse + """Runs the network request through the client's chained policies. + + :param http_request: The network request you want to make. Required. + :type http_request: ~azure.core.pipeline.transport.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to True. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.pipeline.transport.HttpResponse + """ + path_format_arguments = { + 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), + } + http_request.url = self._client.format_url(http_request.url, **path_format_arguments) + stream = kwargs.pop("stream", True) + pipeline_response = self._client._pipeline.run(http_request, stream=stream, **kwargs) + return pipeline_response.http_response + def close(self): # type: () -> None self._client.close() diff --git a/sdk/synapse/azure-synapse-managedprivateendpoints/azure/synapse/managedprivateendpoints/aio/_managed_private_endpoints_client.py b/sdk/synapse/azure-synapse-managedprivateendpoints/azure/synapse/managedprivateendpoints/aio/_managed_private_endpoints_client.py index 6eca787d39d4..dd956f8768c8 100644 --- a/sdk/synapse/azure-synapse-managedprivateendpoints/azure/synapse/managedprivateendpoints/aio/_managed_private_endpoints_client.py +++ b/sdk/synapse/azure-synapse-managedprivateendpoints/azure/synapse/managedprivateendpoints/aio/_managed_private_endpoints_client.py @@ -9,6 +9,7 @@ from typing import Any, TYPE_CHECKING from azure.core import AsyncPipelineClient +from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest from msrest import Deserializer, Serializer if TYPE_CHECKING: @@ -49,6 +50,23 @@ def __init__( self.managed_private_endpoints = ManagedPrivateEndpointsOperations( self._client, self._config, self._serialize, self._deserialize) + async def _send_request(self, http_request: HttpRequest, **kwargs: Any) -> AsyncHttpResponse: + """Runs the network request through the client's chained policies. + + :param http_request: The network request you want to make. Required. + :type http_request: ~azure.core.pipeline.transport.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to True. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.pipeline.transport.AsyncHttpResponse + """ + path_format_arguments = { + 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), + } + http_request.url = self._client.format_url(http_request.url, **path_format_arguments) + stream = kwargs.pop("stream", True) + pipeline_response = await self._client._pipeline.run(http_request, stream=stream, **kwargs) + return pipeline_response.http_response + async def close(self) -> None: await self._client.close() diff --git a/sdk/synapse/azure-synapse-monitoring/azure/synapse/monitoring/_monitoring_client.py b/sdk/synapse/azure-synapse-monitoring/azure/synapse/monitoring/_monitoring_client.py index ff7bfce3ece9..47359ad22311 100644 --- a/sdk/synapse/azure-synapse-monitoring/azure/synapse/monitoring/_monitoring_client.py +++ b/sdk/synapse/azure-synapse-monitoring/azure/synapse/monitoring/_monitoring_client.py @@ -16,6 +16,7 @@ from typing import Any from azure.core.credentials import TokenCredential + from azure.core.pipeline.transport import HttpRequest, HttpResponse from ._configuration import MonitoringClientConfiguration from .operations import MonitoringOperations @@ -52,6 +53,24 @@ def __init__( self.monitoring = MonitoringOperations( self._client, self._config, self._serialize, self._deserialize) + def _send_request(self, http_request, **kwargs): + # type: (HttpRequest, Any) -> HttpResponse + """Runs the network request through the client's chained policies. + + :param http_request: The network request you want to make. Required. + :type http_request: ~azure.core.pipeline.transport.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to True. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.pipeline.transport.HttpResponse + """ + path_format_arguments = { + 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), + } + http_request.url = self._client.format_url(http_request.url, **path_format_arguments) + stream = kwargs.pop("stream", True) + pipeline_response = self._client._pipeline.run(http_request, stream=stream, **kwargs) + return pipeline_response.http_response + def close(self): # type: () -> None self._client.close() diff --git a/sdk/synapse/azure-synapse-monitoring/azure/synapse/monitoring/aio/_monitoring_client.py b/sdk/synapse/azure-synapse-monitoring/azure/synapse/monitoring/aio/_monitoring_client.py index c701405325df..2f32cf93a724 100644 --- a/sdk/synapse/azure-synapse-monitoring/azure/synapse/monitoring/aio/_monitoring_client.py +++ b/sdk/synapse/azure-synapse-monitoring/azure/synapse/monitoring/aio/_monitoring_client.py @@ -9,6 +9,7 @@ from typing import Any, TYPE_CHECKING from azure.core import AsyncPipelineClient +from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest from msrest import Deserializer, Serializer if TYPE_CHECKING: @@ -49,6 +50,23 @@ def __init__( self.monitoring = MonitoringOperations( self._client, self._config, self._serialize, self._deserialize) + async def _send_request(self, http_request: HttpRequest, **kwargs: Any) -> AsyncHttpResponse: + """Runs the network request through the client's chained policies. + + :param http_request: The network request you want to make. Required. + :type http_request: ~azure.core.pipeline.transport.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to True. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.pipeline.transport.AsyncHttpResponse + """ + path_format_arguments = { + 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), + } + http_request.url = self._client.format_url(http_request.url, **path_format_arguments) + stream = kwargs.pop("stream", True) + pipeline_response = await self._client._pipeline.run(http_request, stream=stream, **kwargs) + return pipeline_response.http_response + async def close(self) -> None: await self._client.close() diff --git a/sdk/synapse/azure-synapse-spark/azure/synapse/spark/_spark_client.py b/sdk/synapse/azure-synapse-spark/azure/synapse/spark/_spark_client.py index a3dfa46c408d..9cfba62b6e9f 100644 --- a/sdk/synapse/azure-synapse-spark/azure/synapse/spark/_spark_client.py +++ b/sdk/synapse/azure-synapse-spark/azure/synapse/spark/_spark_client.py @@ -16,6 +16,7 @@ from typing import Any from azure.core.credentials import TokenCredential + from azure.core.pipeline.transport import HttpRequest, HttpResponse from ._configuration import SparkClientConfiguration from .operations import SparkBatchOperations @@ -63,6 +64,26 @@ def __init__( self.spark_session = SparkSessionOperations( self._client, self._config, self._serialize, self._deserialize) + def _send_request(self, http_request, **kwargs): + # type: (HttpRequest, Any) -> HttpResponse + """Runs the network request through the client's chained policies. + + :param http_request: The network request you want to make. Required. + :type http_request: ~azure.core.pipeline.transport.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to True. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.pipeline.transport.HttpResponse + """ + path_format_arguments = { + 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), + 'livyApiVersion': self._serialize.url("self._config.livy_api_version", self._config.livy_api_version, 'str', skip_quote=True), + 'sparkPoolName': self._serialize.url("self._config.spark_pool_name", self._config.spark_pool_name, 'str', skip_quote=True), + } + http_request.url = self._client.format_url(http_request.url, **path_format_arguments) + stream = kwargs.pop("stream", True) + pipeline_response = self._client._pipeline.run(http_request, stream=stream, **kwargs) + return pipeline_response.http_response + def close(self): # type: () -> None self._client.close() diff --git a/sdk/synapse/azure-synapse-spark/azure/synapse/spark/aio/_spark_client.py b/sdk/synapse/azure-synapse-spark/azure/synapse/spark/aio/_spark_client.py index 94b34fd756b0..c4f08ca43aad 100644 --- a/sdk/synapse/azure-synapse-spark/azure/synapse/spark/aio/_spark_client.py +++ b/sdk/synapse/azure-synapse-spark/azure/synapse/spark/aio/_spark_client.py @@ -9,6 +9,7 @@ from typing import Any, TYPE_CHECKING from azure.core import AsyncPipelineClient +from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest from msrest import Deserializer, Serializer if TYPE_CHECKING: @@ -60,6 +61,25 @@ def __init__( self.spark_session = SparkSessionOperations( self._client, self._config, self._serialize, self._deserialize) + async def _send_request(self, http_request: HttpRequest, **kwargs: Any) -> AsyncHttpResponse: + """Runs the network request through the client's chained policies. + + :param http_request: The network request you want to make. Required. + :type http_request: ~azure.core.pipeline.transport.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to True. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.pipeline.transport.AsyncHttpResponse + """ + path_format_arguments = { + 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), + 'livyApiVersion': self._serialize.url("self._config.livy_api_version", self._config.livy_api_version, 'str', skip_quote=True), + 'sparkPoolName': self._serialize.url("self._config.spark_pool_name", self._config.spark_pool_name, 'str', skip_quote=True), + } + http_request.url = self._client.format_url(http_request.url, **path_format_arguments) + stream = kwargs.pop("stream", True) + pipeline_response = await self._client._pipeline.run(http_request, stream=stream, **kwargs) + return pipeline_response.http_response + async def close(self) -> None: await self._client.close() From 77b73ea80a3778e89550631ee0dd10ae56647aca Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Fri, 5 Mar 2021 14:39:31 -0800 Subject: [PATCH 2/2] update --- .../aio/operations/_library_operations.py | 115 +++++++++++------ .../operations/_library_operations.py | 116 ++++++++++++------ 2 files changed, 157 insertions(+), 74 deletions(-) diff --git a/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/aio/operations/_library_operations.py b/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/aio/operations/_library_operations.py index 8f83f4d7a7d2..a259933f1470 100644 --- a/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/aio/operations/_library_operations.py +++ b/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/aio/operations/_library_operations.py @@ -452,12 +452,9 @@ async def get( return deserialized get.metadata = {'url': '/libraries/{libraryName}'} # type: ignore - async def _create_or_append_initial( + async def _create_initial( self, library_name: str, - comp: Optional[str] = None, - x_ms_blob_condition_appendpos: Optional[int] = None, - content: Optional[IO] = None, **kwargs ) -> Optional["_models.LibraryResourceInfo"]: cls = kwargs.pop('cls', None) # type: ClsType[Optional["_models.LibraryResourceInfo"]] @@ -466,11 +463,10 @@ async def _create_or_append_initial( } error_map.update(kwargs.pop('error_map', {})) api_version = "2019-06-01-preview" - content_type = kwargs.pop("content_type", "application/octet-stream") accept = "application/json" # Construct URL - url = self._create_or_append_initial.metadata['url'] # type: ignore + url = self._create_initial.metadata['url'] # type: ignore path_format_arguments = { 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), 'libraryName': self._serialize.url("library_name", library_name, 'str', max_length=100, min_length=0), @@ -480,23 +476,16 @@ async def _create_or_append_initial( # Construct parameters query_parameters = {} # type: Dict[str, Any] query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') - if comp is not None: - query_parameters['comp'] = self._serialize.query("comp", comp, 'str') # Construct headers header_parameters = {} # type: Dict[str, Any] - if x_ms_blob_condition_appendpos is not None: - header_parameters['x-ms-blob-condition-appendpos'] = self._serialize.header("x_ms_blob_condition_appendpos", x_ms_blob_condition_appendpos, 'long') - header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - body_content_kwargs = {} # type: Dict[str, Any] - body_content_kwargs['stream_content'] = content - request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) + request = self._client.put(url, query_parameters, header_parameters) pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) response = pipeline_response.http_response - if response.status_code not in [200, 201, 202, 412]: + if response.status_code not in [200, 202]: map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.CloudError, response) raise HttpResponseError(response=response, model=error) @@ -509,32 +498,18 @@ async def _create_or_append_initial( return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_append_initial.metadata = {'url': '/libraries/{libraryName}'} # type: ignore + _create_initial.metadata = {'url': '/libraries/{libraryName}'} # type: ignore - async def begin_create_or_append( + async def begin_create( self, library_name: str, - comp: Optional[str] = None, - x_ms_blob_condition_appendpos: Optional[int] = None, - content: Optional[IO] = None, **kwargs ) -> AsyncLROPoller["_models.LibraryResourceInfo"]: - """Creates a library with the library name. Use query param 'comp=appendblock' to append the data - to the library resource created using the create operation. + """Creates a library with the library name. :param library_name: file name to upload. Minimum length of the filename should be 1 excluding the extension length. :type library_name: str - :param comp: If this param is specified with value appendblock, the api will append the data - chunk provided in body to the library created. - :type comp: str - :param x_ms_blob_condition_appendpos: Set this header to a byte offset at which the block is - expected to be appended. The request succeeds only if the current offset matches this value. - Otherwise, the request fails with the AppendPositionConditionNotMet error (HTTP status code 412 - – Precondition Failed). - :type x_ms_blob_condition_appendpos: long - :param content: Library file chunk. Use this content in with append operation. - :type content: IO :keyword callable cls: A custom type or function that will be passed the direct response :keyword str continuation_token: A continuation token to restart a poller from a saved state. :keyword polling: Pass in True if you'd like the AsyncLROBasePolling polling method, @@ -553,11 +528,8 @@ async def begin_create_or_append( ) cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] if cont_token is None: - raw_result = await self._create_or_append_initial( + raw_result = await self._create_initial( library_name=library_name, - comp=comp, - x_ms_blob_condition_appendpos=x_ms_blob_condition_appendpos, - content=content, cls=lambda x,y,z: x, **kwargs ) @@ -589,4 +561,73 @@ def get_long_running_output(pipeline_response): ) else: return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_create_or_append.metadata = {'url': '/libraries/{libraryName}'} # type: ignore + begin_create.metadata = {'url': '/libraries/{libraryName}'} # type: ignore + + async def append( + self, + library_name: str, + content: IO, + x_ms_blob_condition_appendpos: Optional[int] = None, + **kwargs + ) -> None: + """Append the content to the library resource created using the create operation. The maximum + content size is 4MiB. Content larger than 4MiB must be appended in 4MiB chunks. + + :param library_name: file name to upload. Minimum length of the filename should be 1 excluding + the extension length. + :type library_name: str + :param content: Library file chunk. + :type content: IO + :param x_ms_blob_condition_appendpos: Set this header to a byte offset at which the block is + expected to be appended. The request succeeds only if the current offset matches this value. + Otherwise, the request fails with the AppendPositionConditionNotMet error (HTTP status code 412 + – Precondition Failed). + :type x_ms_blob_condition_appendpos: long + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None, or the result of cls(response) + :rtype: None + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-06-01-preview" + content_type = kwargs.pop("content_type", "application/octet-stream") + accept = "application/json" + + # Construct URL + url = self.append.metadata['url'] # type: ignore + path_format_arguments = { + 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), + 'libraryName': self._serialize.url("library_name", library_name, 'str', max_length=100, min_length=0), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + if x_ms_blob_condition_appendpos is not None: + header_parameters['x-ms-blob-condition-appendpos'] = self._serialize.header("x_ms_blob_condition_appendpos", x_ms_blob_condition_appendpos, 'long') + header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + body_content_kwargs = {} # type: Dict[str, Any] + body_content_kwargs['stream_content'] = content + request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.CloudError, response) + raise HttpResponseError(response=response, model=error) + + if cls: + return cls(pipeline_response, None, {}) + + append.metadata = {'url': '/libraries/{libraryName}'} # type: ignore diff --git a/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/operations/_library_operations.py b/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/operations/_library_operations.py index 3b92bd4f8e9e..c09fc5027797 100644 --- a/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/operations/_library_operations.py +++ b/sdk/synapse/azure-synapse-artifacts/azure/synapse/artifacts/operations/_library_operations.py @@ -463,12 +463,9 @@ def get( return deserialized get.metadata = {'url': '/libraries/{libraryName}'} # type: ignore - def _create_or_append_initial( + def _create_initial( self, library_name, # type: str - comp=None, # type: Optional[str] - x_ms_blob_condition_appendpos=None, # type: Optional[int] - content=None, # type: Optional[IO] **kwargs # type: Any ): # type: (...) -> Optional["_models.LibraryResourceInfo"] @@ -478,11 +475,10 @@ def _create_or_append_initial( } error_map.update(kwargs.pop('error_map', {})) api_version = "2019-06-01-preview" - content_type = kwargs.pop("content_type", "application/octet-stream") accept = "application/json" # Construct URL - url = self._create_or_append_initial.metadata['url'] # type: ignore + url = self._create_initial.metadata['url'] # type: ignore path_format_arguments = { 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), 'libraryName': self._serialize.url("library_name", library_name, 'str', max_length=100, min_length=0), @@ -492,23 +488,16 @@ def _create_or_append_initial( # Construct parameters query_parameters = {} # type: Dict[str, Any] query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') - if comp is not None: - query_parameters['comp'] = self._serialize.query("comp", comp, 'str') # Construct headers header_parameters = {} # type: Dict[str, Any] - if x_ms_blob_condition_appendpos is not None: - header_parameters['x-ms-blob-condition-appendpos'] = self._serialize.header("x_ms_blob_condition_appendpos", x_ms_blob_condition_appendpos, 'long') - header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - body_content_kwargs = {} # type: Dict[str, Any] - body_content_kwargs['stream_content'] = content - request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) + request = self._client.put(url, query_parameters, header_parameters) pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) response = pipeline_response.http_response - if response.status_code not in [200, 201, 202, 412]: + if response.status_code not in [200, 202]: map_error(status_code=response.status_code, response=response, error_map=error_map) error = self._deserialize.failsafe_deserialize(_models.CloudError, response) raise HttpResponseError(response=response, model=error) @@ -521,33 +510,19 @@ def _create_or_append_initial( return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_append_initial.metadata = {'url': '/libraries/{libraryName}'} # type: ignore + _create_initial.metadata = {'url': '/libraries/{libraryName}'} # type: ignore - def begin_create_or_append( + def begin_create( self, library_name, # type: str - comp=None, # type: Optional[str] - x_ms_blob_condition_appendpos=None, # type: Optional[int] - content=None, # type: Optional[IO] **kwargs # type: Any ): # type: (...) -> LROPoller["_models.LibraryResourceInfo"] - """Creates a library with the library name. Use query param 'comp=appendblock' to append the data - to the library resource created using the create operation. + """Creates a library with the library name. :param library_name: file name to upload. Minimum length of the filename should be 1 excluding the extension length. :type library_name: str - :param comp: If this param is specified with value appendblock, the api will append the data - chunk provided in body to the library created. - :type comp: str - :param x_ms_blob_condition_appendpos: Set this header to a byte offset at which the block is - expected to be appended. The request succeeds only if the current offset matches this value. - Otherwise, the request fails with the AppendPositionConditionNotMet error (HTTP status code 412 - – Precondition Failed). - :type x_ms_blob_condition_appendpos: long - :param content: Library file chunk. Use this content in with append operation. - :type content: IO :keyword callable cls: A custom type or function that will be passed the direct response :keyword str continuation_token: A continuation token to restart a poller from a saved state. :keyword polling: Pass in True if you'd like the LROBasePolling polling method, @@ -566,11 +541,8 @@ def begin_create_or_append( ) cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] if cont_token is None: - raw_result = self._create_or_append_initial( + raw_result = self._create_initial( library_name=library_name, - comp=comp, - x_ms_blob_condition_appendpos=x_ms_blob_condition_appendpos, - content=content, cls=lambda x,y,z: x, **kwargs ) @@ -602,4 +574,74 @@ def get_long_running_output(pipeline_response): ) else: return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_create_or_append.metadata = {'url': '/libraries/{libraryName}'} # type: ignore + begin_create.metadata = {'url': '/libraries/{libraryName}'} # type: ignore + + def append( + self, + library_name, # type: str + content, # type: IO + x_ms_blob_condition_appendpos=None, # type: Optional[int] + **kwargs # type: Any + ): + # type: (...) -> None + """Append the content to the library resource created using the create operation. The maximum + content size is 4MiB. Content larger than 4MiB must be appended in 4MiB chunks. + + :param library_name: file name to upload. Minimum length of the filename should be 1 excluding + the extension length. + :type library_name: str + :param content: Library file chunk. + :type content: IO + :param x_ms_blob_condition_appendpos: Set this header to a byte offset at which the block is + expected to be appended. The request succeeds only if the current offset matches this value. + Otherwise, the request fails with the AppendPositionConditionNotMet error (HTTP status code 412 + – Precondition Failed). + :type x_ms_blob_condition_appendpos: long + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None, or the result of cls(response) + :rtype: None + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-06-01-preview" + content_type = kwargs.pop("content_type", "application/octet-stream") + accept = "application/json" + + # Construct URL + url = self.append.metadata['url'] # type: ignore + path_format_arguments = { + 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), + 'libraryName': self._serialize.url("library_name", library_name, 'str', max_length=100, min_length=0), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + if x_ms_blob_condition_appendpos is not None: + header_parameters['x-ms-blob-condition-appendpos'] = self._serialize.header("x_ms_blob_condition_appendpos", x_ms_blob_condition_appendpos, 'long') + header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + body_content_kwargs = {} # type: Dict[str, Any] + body_content_kwargs['stream_content'] = content + request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.CloudError, response) + raise HttpResponseError(response=response, model=error) + + if cls: + return cls(pipeline_response, None, {}) + + append.metadata = {'url': '/libraries/{libraryName}'} # type: ignore