From da24c93a2f78c8475d86102f27191f69164e9023 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Sat, 15 Apr 2023 10:14:12 -0400 Subject: [PATCH] feat: added ScalingConfig (v1) (#214) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: added ScalingConfig (v1) feat: added Auxiliary Versions Config (v1) feat: added Dataplex and BQ metastore types for federation (v1alpa, v1beta) PiperOrigin-RevId: 524313740 Source-Link: https://github.com/googleapis/googleapis/commit/63d1a0e8129e36cda6efe701181bb032a28e3c75 Source-Link: https://github.com/googleapis/googleapis-gen/commit/400e991cfd3730a363adfb387444e5a6c624a411 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNDAwZTk5MWNmZDM3MzBhMzYzYWRmYjM4NzQ0NGU1YTZjNjI0YTQxMSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot --- .../google/cloud/metastore/__init__.py | 4 + .../google/cloud/metastore_v1/__init__.py | 4 + .../dataproc_metastore/async_client.py | 60 ++++- .../services/dataproc_metastore/client.py | 60 ++++- .../dataproc_metastore/transports/base.py | 6 + .../dataproc_metastore/transports/grpc.py | 17 ++ .../transports/grpc_asyncio.py | 17 ++ .../dataproc_metastore/transports/rest.py | 94 ++++++++ .../async_client.py | 54 +++++ .../dataproc_metastore_federation/client.py | 54 +++++ .../transports/base.py | 6 + .../transports/grpc.py | 17 ++ .../transports/grpc_asyncio.py | 17 ++ .../transports/rest.py | 94 ++++++++ .../cloud/metastore_v1/types/__init__.py | 4 + .../cloud/metastore_v1/types/metastore.py | 132 +++++++++++ .../types/metastore_federation.py | 4 - .../cloud/metastore_v1alpha/__init__.py | 2 + .../dataproc_metastore/async_client.py | 54 +++++ .../services/dataproc_metastore/client.py | 54 +++++ .../dataproc_metastore/transports/base.py | 6 + .../dataproc_metastore/transports/grpc.py | 17 ++ .../transports/grpc_asyncio.py | 17 ++ .../dataproc_metastore/transports/rest.py | 94 ++++++++ .../async_client.py | 54 +++++ .../dataproc_metastore_federation/client.py | 54 +++++ .../transports/base.py | 6 + .../transports/grpc.py | 17 ++ .../transports/grpc_asyncio.py | 17 ++ .../transports/rest.py | 94 ++++++++ .../cloud/metastore_v1alpha/types/__init__.py | 2 + .../metastore_v1alpha/types/metastore.py | 84 +++++++ .../types/metastore_federation.py | 7 +- .../google/cloud/metastore_v1beta/__init__.py | 2 + .../dataproc_metastore/async_client.py | 54 +++++ .../services/dataproc_metastore/client.py | 54 +++++ .../dataproc_metastore/transports/base.py | 6 + .../dataproc_metastore/transports/grpc.py | 17 ++ .../transports/grpc_asyncio.py | 17 ++ .../dataproc_metastore/transports/rest.py | 94 ++++++++ .../async_client.py | 54 +++++ .../dataproc_metastore_federation/client.py | 54 +++++ .../transports/base.py | 6 + .../transports/grpc.py | 17 ++ .../transports/grpc_asyncio.py | 17 ++ .../transports/rest.py | 94 ++++++++ .../cloud/metastore_v1beta/types/__init__.py | 2 + .../cloud/metastore_v1beta/types/metastore.py | 84 +++++++ .../types/metastore_federation.py | 7 +- ...et_metadata_google.cloud.metastore.v1.json | 2 +- ...tadata_google.cloud.metastore.v1alpha.json | 2 +- ...etadata_google.cloud.metastore.v1beta.json | 2 +- .../metastore_v1/test_dataproc_metastore.py | 210 +++++++++++++++++ .../test_dataproc_metastore_federation.py | 198 ++++++++++++++++ .../test_dataproc_metastore.py | 222 +++++++++++++++++- .../test_dataproc_metastore_federation.py | 198 ++++++++++++++++ .../test_dataproc_metastore.py | 222 +++++++++++++++++- .../test_dataproc_metastore_federation.py | 198 ++++++++++++++++ 58 files changed, 3023 insertions(+), 33 deletions(-) diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore/__init__.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore/__init__.py index 7a01a0efe8e8..8553234a09c0 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore/__init__.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore/__init__.py @@ -31,6 +31,7 @@ DataprocMetastoreFederationClient, ) from google.cloud.metastore_v1.types.metastore import ( + AuxiliaryVersionConfig, Backup, CreateBackupRequest, CreateMetadataImportRequest, @@ -60,6 +61,7 @@ OperationMetadata, Restore, RestoreServiceRequest, + ScalingConfig, Secret, Service, TelemetryConfig, @@ -82,6 +84,7 @@ "DataprocMetastoreAsyncClient", "DataprocMetastoreFederationClient", "DataprocMetastoreFederationAsyncClient", + "AuxiliaryVersionConfig", "Backup", "CreateBackupRequest", "CreateMetadataImportRequest", @@ -111,6 +114,7 @@ "OperationMetadata", "Restore", "RestoreServiceRequest", + "ScalingConfig", "Secret", "Service", "TelemetryConfig", diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/__init__.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/__init__.py index 2e2bc1ce2b09..1ecee4a34c34 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/__init__.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/__init__.py @@ -27,6 +27,7 @@ DataprocMetastoreFederationClient, ) from .types.metastore import ( + AuxiliaryVersionConfig, Backup, CreateBackupRequest, CreateMetadataImportRequest, @@ -56,6 +57,7 @@ OperationMetadata, Restore, RestoreServiceRequest, + ScalingConfig, Secret, Service, TelemetryConfig, @@ -76,6 +78,7 @@ __all__ = ( "DataprocMetastoreAsyncClient", "DataprocMetastoreFederationAsyncClient", + "AuxiliaryVersionConfig", "BackendMetastore", "Backup", "CreateBackupRequest", @@ -114,6 +117,7 @@ "OperationMetadata", "Restore", "RestoreServiceRequest", + "ScalingConfig", "Secret", "Service", "TelemetryConfig", diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/async_client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/async_client.py index 55b711af74e2..2a4e1f93e56c 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/async_client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/async_client.py @@ -316,7 +316,7 @@ async def sample_list_services(): Returns: google.cloud.metastore_v1.services.dataproc_metastore.pagers.ListServicesAsyncPager: Response message for - [DataprocMetastore.ListServices][google.cloud.metastore.v1.DataprocMetastore.ListServices]. + [DataprocMetastore.ListServices][google.cloud.metastore.v1.DataprocMetastore.ListServices]. Iterating over this object will yield results and resolve additional pages automatically. @@ -949,7 +949,7 @@ async def sample_list_metadata_imports(): Returns: google.cloud.metastore_v1.services.dataproc_metastore.pagers.ListMetadataImportsAsyncPager: Response message for - [DataprocMetastore.ListMetadataImports][google.cloud.metastore.v1.DataprocMetastore.ListMetadataImports]. + [DataprocMetastore.ListMetadataImports][google.cloud.metastore.v1.DataprocMetastore.ListMetadataImports]. Iterating over this object will yield results and resolve additional pages automatically. @@ -1684,7 +1684,7 @@ async def sample_list_backups(): Returns: google.cloud.metastore_v1.services.dataproc_metastore.pagers.ListBackupsAsyncPager: Response message for - [DataprocMetastore.ListBackups][google.cloud.metastore.v1.DataprocMetastore.ListBackups]. + [DataprocMetastore.ListBackups][google.cloud.metastore.v1.DataprocMetastore.ListBackups]. Iterating over this object will yield results and resolve additional pages automatically. @@ -2279,6 +2279,60 @@ async def delete_operation( metadata=metadata, ) + async def cancel_operation( + self, + request: Optional[operations_pb2.CancelOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + async def set_iam_policy( self, request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/client.py index d91a9cd6599d..ef13dd104bb6 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/client.py @@ -624,7 +624,7 @@ def sample_list_services(): Returns: google.cloud.metastore_v1.services.dataproc_metastore.pagers.ListServicesPager: Response message for - [DataprocMetastore.ListServices][google.cloud.metastore.v1.DataprocMetastore.ListServices]. + [DataprocMetastore.ListServices][google.cloud.metastore.v1.DataprocMetastore.ListServices]. Iterating over this object will yield results and resolve additional pages automatically. @@ -1257,7 +1257,7 @@ def sample_list_metadata_imports(): Returns: google.cloud.metastore_v1.services.dataproc_metastore.pagers.ListMetadataImportsPager: Response message for - [DataprocMetastore.ListMetadataImports][google.cloud.metastore.v1.DataprocMetastore.ListMetadataImports]. + [DataprocMetastore.ListMetadataImports][google.cloud.metastore.v1.DataprocMetastore.ListMetadataImports]. Iterating over this object will yield results and resolve additional pages automatically. @@ -1993,7 +1993,7 @@ def sample_list_backups(): Returns: google.cloud.metastore_v1.services.dataproc_metastore.pagers.ListBackupsPager: Response message for - [DataprocMetastore.ListBackups][google.cloud.metastore.v1.DataprocMetastore.ListBackups]. + [DataprocMetastore.ListBackups][google.cloud.metastore.v1.DataprocMetastore.ListBackups]. Iterating over this object will yield results and resolve additional pages automatically. @@ -2601,6 +2601,60 @@ def delete_operation( metadata=metadata, ) + def cancel_operation( + self, + request: Optional[operations_pb2.CancelOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + def set_iam_policy( self, request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/base.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/base.py index 413dec218977..ec1b56c62195 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/base.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/base.py @@ -378,6 +378,12 @@ def get_operation( ]: raise NotImplementedError() + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + @property def delete_operation( self, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc.py index fe34cd534595..865236b51726 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc.py @@ -680,6 +680,23 @@ def delete_operation( ) return self._stubs["delete_operation"] + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + @property def get_operation( self, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc_asyncio.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc_asyncio.py index bb75d4b0fd1c..ea55e52437e7 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc_asyncio.py @@ -710,6 +710,23 @@ def delete_operation( ) return self._stubs["delete_operation"] + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + @property def get_operation( self, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/rest.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/rest.py index 39460d5309b9..8c6d7fc9a055 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/rest.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore/transports/rest.py @@ -647,6 +647,27 @@ def post_test_iam_permissions( """ return response + def pre_cancel_operation( + self, + request: operations_pb2.CancelOperationRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[operations_pb2.CancelOperationRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for cancel_operation + + Override in a subclass to manipulate the request or metadata + before they are sent to the DataprocMetastore server. + """ + return request, metadata + + def post_cancel_operation(self, response: None) -> None: + """Post-rpc interceptor for cancel_operation + + Override in a subclass to manipulate the response + after it is returned by the DataprocMetastore server but before + it is returned to user code. + """ + return response + def pre_delete_operation( self, request: operations_pb2.DeleteOperationRequest, @@ -843,6 +864,13 @@ def operations_client(self) -> operations_v1.AbstractOperationsClient: # Only create a new client if we do not already have one. if self._operations_client is None: http_options: Dict[str, List[Dict[str, str]]] = { + "google.longrunning.Operations.CancelOperation": [ + { + "method": "post", + "uri": "/v1/{name=projects/*/locations/*/operations/*}:cancel", + "body": "*", + }, + ], "google.longrunning.Operations.DeleteOperation": [ { "method": "delete", @@ -2767,6 +2795,72 @@ def __call__( resp = self._interceptor.post_test_iam_permissions(resp) return resp + @property + def cancel_operation(self): + return self._CancelOperation(self._session, self._host, self._interceptor) # type: ignore + + class _CancelOperation(DataprocMetastoreRestStub): + def __call__( + self, + request: operations_pb2.CancelOperationRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + + r"""Call the cancel operation method over HTTP. + + Args: + request (operations_pb2.CancelOperationRequest): + The request object for CancelOperation method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v1/{name=projects/*/locations/*/operations/*}:cancel", + "body": "*", + }, + ] + + request, metadata = self._interceptor.pre_cancel_operation( + request, metadata + ) + request_kwargs = json_format.MessageToDict(request) + transcoded_request = path_template.transcode(http_options, **request_kwargs) + + body = json.loads(json.dumps(transcoded_request["body"])) + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads(json.dumps(transcoded_request["query_params"])) + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + return self._interceptor.post_cancel_operation(None) + @property def delete_operation(self): return self._DeleteOperation(self._session, self._host, self._interceptor) # type: ignore diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/async_client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/async_client.py index 0dcf390e77a9..a8dd28b3865b 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/async_client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/async_client.py @@ -1047,6 +1047,60 @@ async def delete_operation( metadata=metadata, ) + async def cancel_operation( + self, + request: Optional[operations_pb2.CancelOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + async def set_iam_policy( self, request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/client.py index 7f03a4615146..d14964780832 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/client.py @@ -1286,6 +1286,60 @@ def delete_operation( metadata=metadata, ) + def cancel_operation( + self, + request: Optional[operations_pb2.CancelOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + def set_iam_policy( self, request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/base.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/base.py index 68a6e8090357..c07a4edf6e77 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/base.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/base.py @@ -238,6 +238,12 @@ def get_operation( ]: raise NotImplementedError() + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + @property def delete_operation( self, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/grpc.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/grpc.py index ee1486e04cbb..cb03550e0559 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/grpc.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/grpc.py @@ -423,6 +423,23 @@ def delete_operation( ) return self._stubs["delete_operation"] + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + @property def get_operation( self, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/grpc_asyncio.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/grpc_asyncio.py index dcf7457293fc..ec866256284a 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/grpc_asyncio.py @@ -434,6 +434,23 @@ def delete_operation( ) return self._stubs["delete_operation"] + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + @property def get_operation( self, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/rest.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/rest.py index b81f127c87da..a4b3ee048fcf 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/rest.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/services/dataproc_metastore_federation/transports/rest.py @@ -347,6 +347,27 @@ def post_test_iam_permissions( """ return response + def pre_cancel_operation( + self, + request: operations_pb2.CancelOperationRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[operations_pb2.CancelOperationRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for cancel_operation + + Override in a subclass to manipulate the request or metadata + before they are sent to the DataprocMetastoreFederation server. + """ + return request, metadata + + def post_cancel_operation(self, response: None) -> None: + """Post-rpc interceptor for cancel_operation + + Override in a subclass to manipulate the response + after it is returned by the DataprocMetastoreFederation server but before + it is returned to user code. + """ + return response + def pre_delete_operation( self, request: operations_pb2.DeleteOperationRequest, @@ -536,6 +557,13 @@ def operations_client(self) -> operations_v1.AbstractOperationsClient: # Only create a new client if we do not already have one. if self._operations_client is None: http_options: Dict[str, List[Dict[str, str]]] = { + "google.longrunning.Operations.CancelOperation": [ + { + "method": "post", + "uri": "/v1/{name=projects/*/locations/*/operations/*}:cancel", + "body": "*", + }, + ], "google.longrunning.Operations.DeleteOperation": [ { "method": "delete", @@ -1454,6 +1482,72 @@ def __call__( resp = self._interceptor.post_test_iam_permissions(resp) return resp + @property + def cancel_operation(self): + return self._CancelOperation(self._session, self._host, self._interceptor) # type: ignore + + class _CancelOperation(DataprocMetastoreFederationRestStub): + def __call__( + self, + request: operations_pb2.CancelOperationRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + + r"""Call the cancel operation method over HTTP. + + Args: + request (operations_pb2.CancelOperationRequest): + The request object for CancelOperation method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v1/{name=projects/*/locations/*/operations/*}:cancel", + "body": "*", + }, + ] + + request, metadata = self._interceptor.pre_cancel_operation( + request, metadata + ) + request_kwargs = json_format.MessageToDict(request) + transcoded_request = path_template.transcode(http_options, **request_kwargs) + + body = json.loads(json.dumps(transcoded_request["body"])) + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads(json.dumps(transcoded_request["query_params"])) + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + return self._interceptor.post_cancel_operation(None) + @property def delete_operation(self): return self._DeleteOperation(self._session, self._host, self._interceptor) # type: ignore diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/types/__init__.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/types/__init__.py index 528f1b7a6a0d..8de0a203086a 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/types/__init__.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/types/__init__.py @@ -14,6 +14,7 @@ # limitations under the License. # from .metastore import ( + AuxiliaryVersionConfig, Backup, CreateBackupRequest, CreateMetadataImportRequest, @@ -43,6 +44,7 @@ OperationMetadata, Restore, RestoreServiceRequest, + ScalingConfig, Secret, Service, TelemetryConfig, @@ -61,6 +63,7 @@ ) __all__ = ( + "AuxiliaryVersionConfig", "Backup", "CreateBackupRequest", "CreateMetadataImportRequest", @@ -90,6 +93,7 @@ "OperationMetadata", "Restore", "RestoreServiceRequest", + "ScalingConfig", "Secret", "Service", "TelemetryConfig", diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/types/metastore.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/types/metastore.py index 29d3578f21cd..7fc18e0020a0 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/types/metastore.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/types/metastore.py @@ -32,6 +32,7 @@ "KerberosConfig", "Secret", "EncryptionConfig", + "AuxiliaryVersionConfig", "NetworkConfig", "TelemetryConfig", "MetadataManagementActivity", @@ -39,6 +40,7 @@ "MetadataExport", "Backup", "Restore", + "ScalingConfig", "ListServicesRequest", "ListServicesResponse", "GetServiceRequest", @@ -145,6 +147,9 @@ class Service(proto.Message): The configuration specifying telemetry settings for the Dataproc Metastore service. If unspecified defaults to ``JSON``. + scaling_config (google.cloud.metastore_v1.types.ScalingConfig): + Scaling configuration of the metastore + service. """ class State(proto.Enum): @@ -340,6 +345,11 @@ class DatabaseType(proto.Enum): number=23, message="TelemetryConfig", ) + scaling_config: "ScalingConfig" = proto.Field( + proto.MESSAGE, + number=24, + message="ScalingConfig", + ) class MaintenanceWindow(proto.Message): @@ -387,6 +397,17 @@ class HiveMetastoreConfig(proto.Message): field's path (``hive_metastore_config.kerberos_config``) in the request's ``update_mask`` while omitting this field from the request's ``service``. + auxiliary_versions (MutableMapping[str, google.cloud.metastore_v1.types.AuxiliaryVersionConfig]): + A mapping of Hive metastore version to the auxiliary version + configuration. When specified, a secondary Hive metastore + service is created along with the primary service. All + auxiliary versions must be less than the service's primary + version. The key is the auxiliary service name and it must + match the regular expression `a-z <[-a-z0-9]*[a-z0-9]>`__?. + This means that the first character must be a lowercase + letter, and all the following characters must be hyphens, + lowercase letters, or digits, except the last character, + which cannot be a hyphen. """ version: str = proto.Field( @@ -403,6 +424,12 @@ class HiveMetastoreConfig(proto.Message): number=3, message="KerberosConfig", ) + auxiliary_versions: MutableMapping[str, "AuxiliaryVersionConfig"] = proto.MapField( + proto.STRING, + proto.MESSAGE, + number=5, + message="AuxiliaryVersionConfig", + ) class KerberosConfig(proto.Message): @@ -478,6 +505,44 @@ class EncryptionConfig(proto.Message): ) +class AuxiliaryVersionConfig(proto.Message): + r"""Configuration information for the auxiliary service versions. + + Attributes: + version (str): + The Hive metastore version of the auxiliary + service. It must be less than the primary Hive + metastore service's version. + config_overrides (MutableMapping[str, str]): + A mapping of Hive metastore configuration key-value pairs to + apply to the auxiliary Hive metastore (configured in + ``hive-site.xml``) in addition to the primary version's + overrides. If keys are present in both the auxiliary + version's overrides and the primary version's overrides, the + value from the auxiliary version's overrides takes + precedence. + network_config (google.cloud.metastore_v1.types.NetworkConfig): + Output only. The network configuration + contains the endpoint URI(s) of the auxiliary + Hive metastore service. + """ + + version: str = proto.Field( + proto.STRING, + number=1, + ) + config_overrides: MutableMapping[str, str] = proto.MapField( + proto.STRING, + proto.STRING, + number=2, + ) + network_config: "NetworkConfig" = proto.Field( + proto.MESSAGE, + number=3, + message="NetworkConfig", + ) + + class NetworkConfig(proto.Message): r"""Network configuration for the Dataproc Metastore service. @@ -967,6 +1032,73 @@ class RestoreType(proto.Enum): ) +class ScalingConfig(proto.Message): + r"""Represents the scaling configuration of a metastore service. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + instance_size (google.cloud.metastore_v1.types.ScalingConfig.InstanceSize): + An enum of readable instance sizes, with each instance size + mapping to a float value (e.g. InstanceSize.EXTRA_SMALL = + scaling_factor(0.1)) + + This field is a member of `oneof`_ ``scaling_model``. + scaling_factor (float): + Scaling factor, increments of 0.1 for values + less than 1.0, and increments of 1.0 for values + greater than 1.0. + + This field is a member of `oneof`_ ``scaling_model``. + """ + + class InstanceSize(proto.Enum): + r"""Metastore instance sizes. + + Values: + INSTANCE_SIZE_UNSPECIFIED (0): + Unspecified instance size + EXTRA_SMALL (1): + Extra small instance size, maps to a scaling + factor of 0.1. + SMALL (2): + Small instance size, maps to a scaling factor + of 0.5. + MEDIUM (3): + Medium instance size, maps to a scaling + factor of 1.0. + LARGE (4): + Large instance size, maps to a scaling factor + of 3.0. + EXTRA_LARGE (5): + Extra large instance size, maps to a scaling + factor of 6.0. + """ + INSTANCE_SIZE_UNSPECIFIED = 0 + EXTRA_SMALL = 1 + SMALL = 2 + MEDIUM = 3 + LARGE = 4 + EXTRA_LARGE = 5 + + instance_size: InstanceSize = proto.Field( + proto.ENUM, + number=1, + oneof="scaling_model", + enum=InstanceSize, + ) + scaling_factor: float = proto.Field( + proto.FLOAT, + number=2, + oneof="scaling_model", + ) + + class ListServicesRequest(proto.Message): r"""Request message for [DataprocMetastore.ListServices][google.cloud.metastore.v1.DataprocMetastore.ListServices]. diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/types/metastore_federation.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/types/metastore_federation.py index e362ed715efb..5bee962ed5e9 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/types/metastore_federation.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1/types/metastore_federation.py @@ -170,10 +170,6 @@ class BackendMetastore(proto.Message): federated. The formats of the relative resource names for the currently supported metastores are listed below: - - Dataplex - - - ``projects/{project_id}/locations/{location}/lakes/{lake_id}`` - - BigQuery - ``projects/{project_id}`` diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/__init__.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/__init__.py index aafeb29950fe..c0e9c32b0b28 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/__init__.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/__init__.py @@ -69,6 +69,7 @@ RemoveIamPolicyResponse, Restore, RestoreServiceRequest, + ScalingConfig, Secret, Service, TelemetryConfig, @@ -140,6 +141,7 @@ "RemoveIamPolicyResponse", "Restore", "RestoreServiceRequest", + "ScalingConfig", "Secret", "Service", "TelemetryConfig", diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/async_client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/async_client.py index e5e9153f5ef5..2f04d535a432 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/async_client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/async_client.py @@ -2655,6 +2655,60 @@ async def delete_operation( metadata=metadata, ) + async def cancel_operation( + self, + request: Optional[operations_pb2.CancelOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + async def set_iam_policy( self, request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/client.py index 073f139a04fc..b877e14b9cc6 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/client.py @@ -3003,6 +3003,60 @@ def delete_operation( metadata=metadata, ) + def cancel_operation( + self, + request: Optional[operations_pb2.CancelOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + def set_iam_policy( self, request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/base.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/base.py index 0739193c2e05..c17cf81cb83c 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/base.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/base.py @@ -437,6 +437,12 @@ def get_operation( ]: raise NotImplementedError() + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + @property def delete_operation( self, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc.py index ff1e3d3934cf..f7d25c1fab15 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc.py @@ -795,6 +795,23 @@ def delete_operation( ) return self._stubs["delete_operation"] + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + @property def get_operation( self, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc_asyncio.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc_asyncio.py index d01059f76e00..bb2444334101 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc_asyncio.py @@ -830,6 +830,23 @@ def delete_operation( ) return self._stubs["delete_operation"] + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + @property def get_operation( self, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/rest.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/rest.py index 7a10fedd8d3e..bebfe9a281b6 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/rest.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/rest.py @@ -773,6 +773,27 @@ def post_test_iam_permissions( """ return response + def pre_cancel_operation( + self, + request: operations_pb2.CancelOperationRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[operations_pb2.CancelOperationRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for cancel_operation + + Override in a subclass to manipulate the request or metadata + before they are sent to the DataprocMetastore server. + """ + return request, metadata + + def post_cancel_operation(self, response: None) -> None: + """Post-rpc interceptor for cancel_operation + + Override in a subclass to manipulate the response + after it is returned by the DataprocMetastore server but before + it is returned to user code. + """ + return response + def pre_delete_operation( self, request: operations_pb2.DeleteOperationRequest, @@ -969,6 +990,13 @@ def operations_client(self) -> operations_v1.AbstractOperationsClient: # Only create a new client if we do not already have one. if self._operations_client is None: http_options: Dict[str, List[Dict[str, str]]] = { + "google.longrunning.Operations.CancelOperation": [ + { + "method": "post", + "uri": "/v1alpha/{name=projects/*/locations/*/operations/*}:cancel", + "body": "*", + }, + ], "google.longrunning.Operations.DeleteOperation": [ { "method": "delete", @@ -3358,6 +3386,72 @@ def __call__( resp = self._interceptor.post_test_iam_permissions(resp) return resp + @property + def cancel_operation(self): + return self._CancelOperation(self._session, self._host, self._interceptor) # type: ignore + + class _CancelOperation(DataprocMetastoreRestStub): + def __call__( + self, + request: operations_pb2.CancelOperationRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + + r"""Call the cancel operation method over HTTP. + + Args: + request (operations_pb2.CancelOperationRequest): + The request object for CancelOperation method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v1alpha/{name=projects/*/locations/*/operations/*}:cancel", + "body": "*", + }, + ] + + request, metadata = self._interceptor.pre_cancel_operation( + request, metadata + ) + request_kwargs = json_format.MessageToDict(request) + transcoded_request = path_template.transcode(http_options, **request_kwargs) + + body = json.loads(json.dumps(transcoded_request["body"])) + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads(json.dumps(transcoded_request["query_params"])) + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + return self._interceptor.post_cancel_operation(None) + @property def delete_operation(self): return self._DeleteOperation(self._session, self._host, self._interceptor) # type: ignore diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/async_client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/async_client.py index 75a55ab816cf..a12f94743a83 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/async_client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/async_client.py @@ -1047,6 +1047,60 @@ async def delete_operation( metadata=metadata, ) + async def cancel_operation( + self, + request: Optional[operations_pb2.CancelOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + async def set_iam_policy( self, request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/client.py index 2a5bd4110552..73dc18fdc71c 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/client.py @@ -1286,6 +1286,60 @@ def delete_operation( metadata=metadata, ) + def cancel_operation( + self, + request: Optional[operations_pb2.CancelOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + def set_iam_policy( self, request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/base.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/base.py index 5540ab2fcc02..0d3aecdd7f24 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/base.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/base.py @@ -238,6 +238,12 @@ def get_operation( ]: raise NotImplementedError() + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + @property def delete_operation( self, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/grpc.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/grpc.py index 93be95198d2c..2cf957078ab2 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/grpc.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/grpc.py @@ -423,6 +423,23 @@ def delete_operation( ) return self._stubs["delete_operation"] + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + @property def get_operation( self, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/grpc_asyncio.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/grpc_asyncio.py index aa1cf67671f6..47994563b8d6 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/grpc_asyncio.py @@ -434,6 +434,23 @@ def delete_operation( ) return self._stubs["delete_operation"] + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + @property def get_operation( self, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/rest.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/rest.py index d5d2f098d17d..4753ce72f135 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/rest.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/services/dataproc_metastore_federation/transports/rest.py @@ -347,6 +347,27 @@ def post_test_iam_permissions( """ return response + def pre_cancel_operation( + self, + request: operations_pb2.CancelOperationRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[operations_pb2.CancelOperationRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for cancel_operation + + Override in a subclass to manipulate the request or metadata + before they are sent to the DataprocMetastoreFederation server. + """ + return request, metadata + + def post_cancel_operation(self, response: None) -> None: + """Post-rpc interceptor for cancel_operation + + Override in a subclass to manipulate the response + after it is returned by the DataprocMetastoreFederation server but before + it is returned to user code. + """ + return response + def pre_delete_operation( self, request: operations_pb2.DeleteOperationRequest, @@ -536,6 +557,13 @@ def operations_client(self) -> operations_v1.AbstractOperationsClient: # Only create a new client if we do not already have one. if self._operations_client is None: http_options: Dict[str, List[Dict[str, str]]] = { + "google.longrunning.Operations.CancelOperation": [ + { + "method": "post", + "uri": "/v1alpha/{name=projects/*/locations/*/operations/*}:cancel", + "body": "*", + }, + ], "google.longrunning.Operations.DeleteOperation": [ { "method": "delete", @@ -1487,6 +1515,72 @@ def __call__( resp = self._interceptor.post_test_iam_permissions(resp) return resp + @property + def cancel_operation(self): + return self._CancelOperation(self._session, self._host, self._interceptor) # type: ignore + + class _CancelOperation(DataprocMetastoreFederationRestStub): + def __call__( + self, + request: operations_pb2.CancelOperationRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + + r"""Call the cancel operation method over HTTP. + + Args: + request (operations_pb2.CancelOperationRequest): + The request object for CancelOperation method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v1alpha/{name=projects/*/locations/*/operations/*}:cancel", + "body": "*", + }, + ] + + request, metadata = self._interceptor.pre_cancel_operation( + request, metadata + ) + request_kwargs = json_format.MessageToDict(request) + transcoded_request = path_template.transcode(http_options, **request_kwargs) + + body = json.loads(json.dumps(transcoded_request["body"])) + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads(json.dumps(transcoded_request["query_params"])) + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + return self._interceptor.post_cancel_operation(None) + @property def delete_operation(self): return self._DeleteOperation(self._session, self._host, self._interceptor) # type: ignore diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/types/__init__.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/types/__init__.py index 0a3441cae69d..b843ec17ebcb 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/types/__init__.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/types/__init__.py @@ -56,6 +56,7 @@ RemoveIamPolicyResponse, Restore, RestoreServiceRequest, + ScalingConfig, Secret, Service, TelemetryConfig, @@ -116,6 +117,7 @@ "RemoveIamPolicyResponse", "Restore", "RestoreServiceRequest", + "ScalingConfig", "Secret", "Service", "TelemetryConfig", diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/types/metastore.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/types/metastore.py index f2626fe5e45d..71118c90e5e0 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/types/metastore.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/types/metastore.py @@ -44,6 +44,7 @@ "MetadataExport", "Backup", "Restore", + "ScalingConfig", "ListServicesRequest", "ListServicesResponse", "GetServiceRequest", @@ -162,6 +163,9 @@ class Service(proto.Message): The configuration specifying telemetry settings for the Dataproc Metastore service. If unspecified defaults to ``JSON``. + scaling_config (google.cloud.metastore_v1alpha.types.ScalingConfig): + Scaling configuration of the metastore + service. """ class State(proto.Enum): @@ -362,6 +366,11 @@ class DatabaseType(proto.Enum): number=23, message="TelemetryConfig", ) + scaling_config: "ScalingConfig" = proto.Field( + proto.MESSAGE, + number=24, + message="ScalingConfig", + ) class MetadataIntegration(proto.Message): @@ -667,6 +676,10 @@ class NetworkConfig(proto.Message): Immutable. The consumer-side network configuration for the Dataproc Metastore instance. + custom_routes_enabled (bool): + Enables custom routes to be imported and + exported for the Dataproc Metastore service's + peered VPC network. """ class Consumer(proto.Message): @@ -709,6 +722,10 @@ class Consumer(proto.Message): number=1, message=Consumer, ) + custom_routes_enabled: bool = proto.Field( + proto.BOOL, + number=2, + ) class TelemetryConfig(proto.Message): @@ -1154,6 +1171,73 @@ class RestoreType(proto.Enum): ) +class ScalingConfig(proto.Message): + r"""Represents the scaling configuration of a metastore service. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + instance_size (google.cloud.metastore_v1alpha.types.ScalingConfig.InstanceSize): + An enum of readable instance sizes, with each instance size + mapping to a float value (e.g. InstanceSize.EXTRA_SMALL = + scaling_factor(0.1)) + + This field is a member of `oneof`_ ``scaling_model``. + scaling_factor (float): + Scaling factor, increments of 0.1 for values + less than 1.0, and increments of 1.0 for values + greater than 1.0. + + This field is a member of `oneof`_ ``scaling_model``. + """ + + class InstanceSize(proto.Enum): + r"""Metastore instance sizes. + + Values: + INSTANCE_SIZE_UNSPECIFIED (0): + Unspecified instance size + EXTRA_SMALL (1): + Extra small instance size, maps to a scaling + factor of 0.1. + SMALL (2): + Small instance size, maps to a scaling factor + of 0.5. + MEDIUM (3): + Medium instance size, maps to a scaling + factor of 1.0. + LARGE (4): + Large instance size, maps to a scaling factor + of 3.0. + EXTRA_LARGE (5): + Extra large instance size, maps to a scaling + factor of 6.0. + """ + INSTANCE_SIZE_UNSPECIFIED = 0 + EXTRA_SMALL = 1 + SMALL = 2 + MEDIUM = 3 + LARGE = 4 + EXTRA_LARGE = 5 + + instance_size: InstanceSize = proto.Field( + proto.ENUM, + number=1, + oneof="scaling_model", + enum=InstanceSize, + ) + scaling_factor: float = proto.Field( + proto.FLOAT, + number=2, + oneof="scaling_model", + ) + + class ListServicesRequest(proto.Message): r"""Request message for [DataprocMetastore.ListServices][google.cloud.metastore.v1alpha.DataprocMetastore.ListServices]. diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/types/metastore_federation.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/types/metastore_federation.py index 92566acc4d1f..41bd4c6b4da1 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/types/metastore_federation.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1alpha/types/metastore_federation.py @@ -170,10 +170,6 @@ class BackendMetastore(proto.Message): federated. The formats of the relative resource names for the currently supported metastores are listed below: - - Dataplex - - - ``projects/{project_id}/locations/{location}/lakes/{lake_id}`` - - BigQuery - ``projects/{project_id}`` @@ -191,12 +187,15 @@ class MetastoreType(proto.Enum): Values: METASTORE_TYPE_UNSPECIFIED (0): The metastore type is not set. + DATAPLEX (1): + The backend metastore is Dataplex. BIGQUERY (2): The backend metastore is BigQuery. DATAPROC_METASTORE (3): The backend metastore is Dataproc Metastore. """ METASTORE_TYPE_UNSPECIFIED = 0 + DATAPLEX = 1 BIGQUERY = 2 DATAPROC_METASTORE = 3 diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/__init__.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/__init__.py index 50d6455fb747..8204a459d464 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/__init__.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/__init__.py @@ -69,6 +69,7 @@ RemoveIamPolicyResponse, Restore, RestoreServiceRequest, + ScalingConfig, Secret, Service, TelemetryConfig, @@ -140,6 +141,7 @@ "RemoveIamPolicyResponse", "Restore", "RestoreServiceRequest", + "ScalingConfig", "Secret", "Service", "TelemetryConfig", diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/async_client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/async_client.py index 7a1eda056081..67b567cf0a84 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/async_client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/async_client.py @@ -2655,6 +2655,60 @@ async def delete_operation( metadata=metadata, ) + async def cancel_operation( + self, + request: Optional[operations_pb2.CancelOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + async def set_iam_policy( self, request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/client.py index ab5002af8886..e01708fc2fff 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/client.py @@ -3003,6 +3003,60 @@ def delete_operation( metadata=metadata, ) + def cancel_operation( + self, + request: Optional[operations_pb2.CancelOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + def set_iam_policy( self, request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/base.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/base.py index dc591d4c8e22..de226364ced8 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/base.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/base.py @@ -437,6 +437,12 @@ def get_operation( ]: raise NotImplementedError() + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + @property def delete_operation( self, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc.py index ab9425fbfd56..ce81fc59426e 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc.py @@ -795,6 +795,23 @@ def delete_operation( ) return self._stubs["delete_operation"] + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + @property def get_operation( self, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc_asyncio.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc_asyncio.py index a9f1e769ff64..335ffdbdbc56 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc_asyncio.py @@ -830,6 +830,23 @@ def delete_operation( ) return self._stubs["delete_operation"] + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + @property def get_operation( self, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/rest.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/rest.py index 624b1200d7d0..229aa72bb70f 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/rest.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/rest.py @@ -773,6 +773,27 @@ def post_test_iam_permissions( """ return response + def pre_cancel_operation( + self, + request: operations_pb2.CancelOperationRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[operations_pb2.CancelOperationRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for cancel_operation + + Override in a subclass to manipulate the request or metadata + before they are sent to the DataprocMetastore server. + """ + return request, metadata + + def post_cancel_operation(self, response: None) -> None: + """Post-rpc interceptor for cancel_operation + + Override in a subclass to manipulate the response + after it is returned by the DataprocMetastore server but before + it is returned to user code. + """ + return response + def pre_delete_operation( self, request: operations_pb2.DeleteOperationRequest, @@ -969,6 +990,13 @@ def operations_client(self) -> operations_v1.AbstractOperationsClient: # Only create a new client if we do not already have one. if self._operations_client is None: http_options: Dict[str, List[Dict[str, str]]] = { + "google.longrunning.Operations.CancelOperation": [ + { + "method": "post", + "uri": "/v1beta/{name=projects/*/locations/*/operations/*}:cancel", + "body": "*", + }, + ], "google.longrunning.Operations.DeleteOperation": [ { "method": "delete", @@ -3358,6 +3386,72 @@ def __call__( resp = self._interceptor.post_test_iam_permissions(resp) return resp + @property + def cancel_operation(self): + return self._CancelOperation(self._session, self._host, self._interceptor) # type: ignore + + class _CancelOperation(DataprocMetastoreRestStub): + def __call__( + self, + request: operations_pb2.CancelOperationRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + + r"""Call the cancel operation method over HTTP. + + Args: + request (operations_pb2.CancelOperationRequest): + The request object for CancelOperation method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v1beta/{name=projects/*/locations/*/operations/*}:cancel", + "body": "*", + }, + ] + + request, metadata = self._interceptor.pre_cancel_operation( + request, metadata + ) + request_kwargs = json_format.MessageToDict(request) + transcoded_request = path_template.transcode(http_options, **request_kwargs) + + body = json.loads(json.dumps(transcoded_request["body"])) + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads(json.dumps(transcoded_request["query_params"])) + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + return self._interceptor.post_cancel_operation(None) + @property def delete_operation(self): return self._DeleteOperation(self._session, self._host, self._interceptor) # type: ignore diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/async_client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/async_client.py index 41bfeca01e54..c4a600e458fb 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/async_client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/async_client.py @@ -1047,6 +1047,60 @@ async def delete_operation( metadata=metadata, ) + async def cancel_operation( + self, + request: Optional[operations_pb2.CancelOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + async def set_iam_policy( self, request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/client.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/client.py index f22e56701a45..affee423bc9d 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/client.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/client.py @@ -1286,6 +1286,60 @@ def delete_operation( metadata=metadata, ) + def cancel_operation( + self, + request: Optional[operations_pb2.CancelOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + def set_iam_policy( self, request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/base.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/base.py index e44c99c8c23e..4ba677772a5f 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/base.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/base.py @@ -238,6 +238,12 @@ def get_operation( ]: raise NotImplementedError() + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + @property def delete_operation( self, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/grpc.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/grpc.py index 60b904d49718..415230a6531a 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/grpc.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/grpc.py @@ -423,6 +423,23 @@ def delete_operation( ) return self._stubs["delete_operation"] + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + @property def get_operation( self, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/grpc_asyncio.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/grpc_asyncio.py index 80ec4c495f17..4856d3d9e2c2 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/grpc_asyncio.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/grpc_asyncio.py @@ -434,6 +434,23 @@ def delete_operation( ) return self._stubs["delete_operation"] + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + @property def get_operation( self, diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/rest.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/rest.py index 7dcdafefc51c..18030fbb2611 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/rest.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/services/dataproc_metastore_federation/transports/rest.py @@ -347,6 +347,27 @@ def post_test_iam_permissions( """ return response + def pre_cancel_operation( + self, + request: operations_pb2.CancelOperationRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[operations_pb2.CancelOperationRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for cancel_operation + + Override in a subclass to manipulate the request or metadata + before they are sent to the DataprocMetastoreFederation server. + """ + return request, metadata + + def post_cancel_operation(self, response: None) -> None: + """Post-rpc interceptor for cancel_operation + + Override in a subclass to manipulate the response + after it is returned by the DataprocMetastoreFederation server but before + it is returned to user code. + """ + return response + def pre_delete_operation( self, request: operations_pb2.DeleteOperationRequest, @@ -536,6 +557,13 @@ def operations_client(self) -> operations_v1.AbstractOperationsClient: # Only create a new client if we do not already have one. if self._operations_client is None: http_options: Dict[str, List[Dict[str, str]]] = { + "google.longrunning.Operations.CancelOperation": [ + { + "method": "post", + "uri": "/v1beta/{name=projects/*/locations/*/operations/*}:cancel", + "body": "*", + }, + ], "google.longrunning.Operations.DeleteOperation": [ { "method": "delete", @@ -1487,6 +1515,72 @@ def __call__( resp = self._interceptor.post_test_iam_permissions(resp) return resp + @property + def cancel_operation(self): + return self._CancelOperation(self._session, self._host, self._interceptor) # type: ignore + + class _CancelOperation(DataprocMetastoreFederationRestStub): + def __call__( + self, + request: operations_pb2.CancelOperationRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + + r"""Call the cancel operation method over HTTP. + + Args: + request (operations_pb2.CancelOperationRequest): + The request object for CancelOperation method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v1beta/{name=projects/*/locations/*/operations/*}:cancel", + "body": "*", + }, + ] + + request, metadata = self._interceptor.pre_cancel_operation( + request, metadata + ) + request_kwargs = json_format.MessageToDict(request) + transcoded_request = path_template.transcode(http_options, **request_kwargs) + + body = json.loads(json.dumps(transcoded_request["body"])) + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads(json.dumps(transcoded_request["query_params"])) + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + return self._interceptor.post_cancel_operation(None) + @property def delete_operation(self): return self._DeleteOperation(self._session, self._host, self._interceptor) # type: ignore diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/types/__init__.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/types/__init__.py index 0a3441cae69d..b843ec17ebcb 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/types/__init__.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/types/__init__.py @@ -56,6 +56,7 @@ RemoveIamPolicyResponse, Restore, RestoreServiceRequest, + ScalingConfig, Secret, Service, TelemetryConfig, @@ -116,6 +117,7 @@ "RemoveIamPolicyResponse", "Restore", "RestoreServiceRequest", + "ScalingConfig", "Secret", "Service", "TelemetryConfig", diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/types/metastore.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/types/metastore.py index e98f7d1d5b63..d4a46504a712 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/types/metastore.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/types/metastore.py @@ -44,6 +44,7 @@ "MetadataExport", "Backup", "Restore", + "ScalingConfig", "ListServicesRequest", "ListServicesResponse", "GetServiceRequest", @@ -162,6 +163,9 @@ class Service(proto.Message): The configuration specifying telemetry settings for the Dataproc Metastore service. If unspecified defaults to ``JSON``. + scaling_config (google.cloud.metastore_v1beta.types.ScalingConfig): + Scaling configuration of the metastore + service. """ class State(proto.Enum): @@ -362,6 +366,11 @@ class DatabaseType(proto.Enum): number=23, message="TelemetryConfig", ) + scaling_config: "ScalingConfig" = proto.Field( + proto.MESSAGE, + number=24, + message="ScalingConfig", + ) class MetadataIntegration(proto.Message): @@ -667,6 +676,10 @@ class NetworkConfig(proto.Message): Immutable. The consumer-side network configuration for the Dataproc Metastore instance. + custom_routes_enabled (bool): + Enables custom routes to be imported and + exported for the Dataproc Metastore service's + peered VPC network. """ class Consumer(proto.Message): @@ -709,6 +722,10 @@ class Consumer(proto.Message): number=1, message=Consumer, ) + custom_routes_enabled: bool = proto.Field( + proto.BOOL, + number=2, + ) class TelemetryConfig(proto.Message): @@ -1154,6 +1171,73 @@ class RestoreType(proto.Enum): ) +class ScalingConfig(proto.Message): + r"""Represents the scaling configuration of a metastore service. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + instance_size (google.cloud.metastore_v1beta.types.ScalingConfig.InstanceSize): + An enum of readable instance sizes, with each instance size + mapping to a float value (e.g. InstanceSize.EXTRA_SMALL = + scaling_factor(0.1)) + + This field is a member of `oneof`_ ``scaling_model``. + scaling_factor (float): + Scaling factor, increments of 0.1 for values + less than 1.0, and increments of 1.0 for values + greater than 1.0. + + This field is a member of `oneof`_ ``scaling_model``. + """ + + class InstanceSize(proto.Enum): + r"""Metastore instance sizes. + + Values: + INSTANCE_SIZE_UNSPECIFIED (0): + Unspecified instance size + EXTRA_SMALL (1): + Extra small instance size, maps to a scaling + factor of 0.1. + SMALL (2): + Small instance size, maps to a scaling factor + of 0.5. + MEDIUM (3): + Medium instance size, maps to a scaling + factor of 1.0. + LARGE (4): + Large instance size, maps to a scaling factor + of 3.0. + EXTRA_LARGE (5): + Extra large instance size, maps to a scaling + factor of 6.0. + """ + INSTANCE_SIZE_UNSPECIFIED = 0 + EXTRA_SMALL = 1 + SMALL = 2 + MEDIUM = 3 + LARGE = 4 + EXTRA_LARGE = 5 + + instance_size: InstanceSize = proto.Field( + proto.ENUM, + number=1, + oneof="scaling_model", + enum=InstanceSize, + ) + scaling_factor: float = proto.Field( + proto.FLOAT, + number=2, + oneof="scaling_model", + ) + + class ListServicesRequest(proto.Message): r"""Request message for [DataprocMetastore.ListServices][google.cloud.metastore.v1beta.DataprocMetastore.ListServices]. diff --git a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/types/metastore_federation.py b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/types/metastore_federation.py index 924169638f3d..681f1ec271c1 100644 --- a/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/types/metastore_federation.py +++ b/packages/google-cloud-dataproc-metastore/google/cloud/metastore_v1beta/types/metastore_federation.py @@ -170,10 +170,6 @@ class BackendMetastore(proto.Message): federated. The formats of the relative resource names for the currently supported metastores are listed below: - - Dataplex - - - ``projects/{project_id}/locations/{location}/lakes/{lake_id}`` - - BigQuery - ``projects/{project_id}`` @@ -191,12 +187,15 @@ class MetastoreType(proto.Enum): Values: METASTORE_TYPE_UNSPECIFIED (0): The metastore type is not set. + DATAPLEX (1): + The backend metastore is Dataplex. BIGQUERY (2): The backend metastore is BigQuery. DATAPROC_METASTORE (3): The backend metastore is Dataproc Metastore. """ METASTORE_TYPE_UNSPECIFIED = 0 + DATAPLEX = 1 BIGQUERY = 2 DATAPROC_METASTORE = 3 diff --git a/packages/google-cloud-dataproc-metastore/samples/generated_samples/snippet_metadata_google.cloud.metastore.v1.json b/packages/google-cloud-dataproc-metastore/samples/generated_samples/snippet_metadata_google.cloud.metastore.v1.json index 0868d772ed5f..f1638aa8e399 100644 --- a/packages/google-cloud-dataproc-metastore/samples/generated_samples/snippet_metadata_google.cloud.metastore.v1.json +++ b/packages/google-cloud-dataproc-metastore/samples/generated_samples/snippet_metadata_google.cloud.metastore.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-dataproc-metastore", - "version": "1.10.1" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-dataproc-metastore/samples/generated_samples/snippet_metadata_google.cloud.metastore.v1alpha.json b/packages/google-cloud-dataproc-metastore/samples/generated_samples/snippet_metadata_google.cloud.metastore.v1alpha.json index 003ddbc4dc36..96abac734738 100644 --- a/packages/google-cloud-dataproc-metastore/samples/generated_samples/snippet_metadata_google.cloud.metastore.v1alpha.json +++ b/packages/google-cloud-dataproc-metastore/samples/generated_samples/snippet_metadata_google.cloud.metastore.v1alpha.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-dataproc-metastore", - "version": "1.10.1" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-dataproc-metastore/samples/generated_samples/snippet_metadata_google.cloud.metastore.v1beta.json b/packages/google-cloud-dataproc-metastore/samples/generated_samples/snippet_metadata_google.cloud.metastore.v1beta.json index 34a68cee41c9..4a03aa222378 100644 --- a/packages/google-cloud-dataproc-metastore/samples/generated_samples/snippet_metadata_google.cloud.metastore.v1beta.json +++ b/packages/google-cloud-dataproc-metastore/samples/generated_samples/snippet_metadata_google.cloud.metastore.v1beta.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-dataproc-metastore", - "version": "1.10.1" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1/test_dataproc_metastore.py b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1/test_dataproc_metastore.py index ed1c2ca84ddd..14d4d7d5096b 100644 --- a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1/test_dataproc_metastore.py +++ b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1/test_dataproc_metastore.py @@ -5618,6 +5618,7 @@ def test_create_service_rest(request_type): "principal": "principal_value", "krb5_config_gcs_uri": "krb5_config_gcs_uri_value", }, + "auxiliary_versions": {}, }, "name": "name_value", "create_time": {"seconds": 751, "nanos": 543}, @@ -5662,6 +5663,7 @@ def test_create_service_rest(request_type): }, "database_type": 1, "telemetry_config": {"log_format": 1}, + "scaling_config": {"instance_size": 1, "scaling_factor": 0.1471}, } request = request_type(**request_init) @@ -5878,6 +5880,7 @@ def test_create_service_rest_bad_request( "principal": "principal_value", "krb5_config_gcs_uri": "krb5_config_gcs_uri_value", }, + "auxiliary_versions": {}, }, "name": "name_value", "create_time": {"seconds": 751, "nanos": 543}, @@ -5922,6 +5925,7 @@ def test_create_service_rest_bad_request( }, "database_type": 1, "telemetry_config": {"log_format": 1}, + "scaling_config": {"instance_size": 1, "scaling_factor": 0.1471}, } request = request_type(**request_init) @@ -6035,6 +6039,7 @@ def test_update_service_rest(request_type): "principal": "principal_value", "krb5_config_gcs_uri": "krb5_config_gcs_uri_value", }, + "auxiliary_versions": {}, }, "name": "projects/sample1/locations/sample2/services/sample3", "create_time": {"seconds": 751, "nanos": 543}, @@ -6079,6 +6084,7 @@ def test_update_service_rest(request_type): }, "database_type": 1, "telemetry_config": {"log_format": 1}, + "scaling_config": {"instance_size": 1, "scaling_factor": 0.1471}, } request = request_type(**request_init) @@ -6278,6 +6284,7 @@ def test_update_service_rest_bad_request( "principal": "principal_value", "krb5_config_gcs_uri": "krb5_config_gcs_uri_value", }, + "auxiliary_versions": {}, }, "name": "projects/sample1/locations/sample2/services/sample3", "create_time": {"seconds": 751, "nanos": 543}, @@ -6322,6 +6329,7 @@ def test_update_service_rest_bad_request( }, "database_type": 1, "telemetry_config": {"log_format": 1}, + "scaling_config": {"instance_size": 1, "scaling_factor": 0.1471}, } request = request_type(**request_init) @@ -9088,6 +9096,7 @@ def test_create_backup_rest(request_type): "principal": "principal_value", "krb5_config_gcs_uri": "krb5_config_gcs_uri_value", }, + "auxiliary_versions": {}, }, "name": "name_value", "create_time": {}, @@ -9135,6 +9144,7 @@ def test_create_backup_rest(request_type): }, "database_type": 1, "telemetry_config": {"log_format": 1}, + "scaling_config": {"instance_size": 1, "scaling_factor": 0.1471}, }, "description": "description_value", "restoring_services": [ @@ -9360,6 +9370,7 @@ def test_create_backup_rest_bad_request( "principal": "principal_value", "krb5_config_gcs_uri": "krb5_config_gcs_uri_value", }, + "auxiliary_versions": {}, }, "name": "name_value", "create_time": {}, @@ -9407,6 +9418,7 @@ def test_create_backup_rest_bad_request( }, "database_type": 1, "telemetry_config": {"log_format": 1}, + "scaling_config": {"instance_size": 1, "scaling_factor": 0.1471}, }, "description": "description_value", "restoring_services": [ @@ -9922,6 +9934,7 @@ def test_dataproc_metastore_base_transport(): "get_location", "list_locations", "get_operation", + "cancel_operation", "delete_operation", "list_operations", ) @@ -10974,6 +10987,64 @@ def test_test_iam_permissions_rest(request_type): assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) +def test_cancel_operation_rest_bad_request( + transport: str = "rest", request_type=operations_pb2.CancelOperationRequest +): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + request = request_type() + request = json_format.ParseDict( + {"name": "projects/sample1/locations/sample2/operations/sample3"}, request + ) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.cancel_operation(request) + + +@pytest.mark.parametrize( + "request_type", + [ + operations_pb2.CancelOperationRequest, + dict, + ], +) +def test_cancel_operation_rest(request_type): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} + request = request_type(**request_init) + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = None + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = "{}" + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.cancel_operation(request) + + # Establish that the response is the type that we expect. + assert response is None + + def test_delete_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.DeleteOperationRequest ): @@ -11287,6 +11358,145 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_cancel_operation(transport: str = "grpc"): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation_async(transport: str = "grpc"): + client = DataprocMetastoreAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = DataprocMetastoreAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = DataprocMetastoreAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + def test_get_operation(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), diff --git a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1/test_dataproc_metastore_federation.py b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1/test_dataproc_metastore_federation.py index 671f9edd6def..007c10dff021 100644 --- a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1/test_dataproc_metastore_federation.py +++ b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1/test_dataproc_metastore_federation.py @@ -3891,6 +3891,7 @@ def test_dataproc_metastore_federation_base_transport(): "get_location", "list_locations", "get_operation", + "cancel_operation", "delete_operation", "list_operations", ) @@ -4819,6 +4820,64 @@ def test_test_iam_permissions_rest(request_type): assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) +def test_cancel_operation_rest_bad_request( + transport: str = "rest", request_type=operations_pb2.CancelOperationRequest +): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + request = request_type() + request = json_format.ParseDict( + {"name": "projects/sample1/locations/sample2/operations/sample3"}, request + ) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.cancel_operation(request) + + +@pytest.mark.parametrize( + "request_type", + [ + operations_pb2.CancelOperationRequest, + dict, + ], +) +def test_cancel_operation_rest(request_type): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} + request = request_type(**request_init) + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = None + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = "{}" + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.cancel_operation(request) + + # Establish that the response is the type that we expect. + assert response is None + + def test_delete_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.DeleteOperationRequest ): @@ -5132,6 +5191,145 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_cancel_operation(transport: str = "grpc"): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation_async(transport: str = "grpc"): + client = DataprocMetastoreFederationAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + def test_get_operation(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), diff --git a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1alpha/test_dataproc_metastore.py b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1alpha/test_dataproc_metastore.py index d802e08a1b41..00b0b756006c 100644 --- a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1alpha/test_dataproc_metastore.py +++ b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1alpha/test_dataproc_metastore.py @@ -6279,10 +6279,12 @@ def test_create_service_rest(request_type): "network_config": { "consumers": [ {"subnetwork": "subnetwork_value", "endpoint_uri": "endpoint_uri_value"} - ] + ], + "custom_routes_enabled": True, }, "database_type": 1, "telemetry_config": {"log_format": 1}, + "scaling_config": {"instance_size": 1, "scaling_factor": 0.1471}, } request = request_type(**request_init) @@ -6545,10 +6547,12 @@ def test_create_service_rest_bad_request( "network_config": { "consumers": [ {"subnetwork": "subnetwork_value", "endpoint_uri": "endpoint_uri_value"} - ] + ], + "custom_routes_enabled": True, }, "database_type": 1, "telemetry_config": {"log_format": 1}, + "scaling_config": {"instance_size": 1, "scaling_factor": 0.1471}, } request = request_type(**request_init) @@ -6709,10 +6713,12 @@ def test_update_service_rest(request_type): "network_config": { "consumers": [ {"subnetwork": "subnetwork_value", "endpoint_uri": "endpoint_uri_value"} - ] + ], + "custom_routes_enabled": True, }, "database_type": 1, "telemetry_config": {"log_format": 1}, + "scaling_config": {"instance_size": 1, "scaling_factor": 0.1471}, } request = request_type(**request_init) @@ -6958,10 +6964,12 @@ def test_update_service_rest_bad_request( "network_config": { "consumers": [ {"subnetwork": "subnetwork_value", "endpoint_uri": "endpoint_uri_value"} - ] + ], + "custom_routes_enabled": True, }, "database_type": 1, "telemetry_config": {"log_format": 1}, + "scaling_config": {"instance_size": 1, "scaling_factor": 0.1471}, } request = request_type(**request_init) @@ -9798,10 +9806,12 @@ def test_create_backup_rest(request_type): "subnetwork": "subnetwork_value", "endpoint_uri": "endpoint_uri_value", } - ] + ], + "custom_routes_enabled": True, }, "database_type": 1, "telemetry_config": {"log_format": 1}, + "scaling_config": {"instance_size": 1, "scaling_factor": 0.1471}, }, "description": "description_value", "restoring_services": [ @@ -10076,10 +10086,12 @@ def test_create_backup_rest_bad_request( "subnetwork": "subnetwork_value", "endpoint_uri": "endpoint_uri_value", } - ] + ], + "custom_routes_enabled": True, }, "database_type": 1, "telemetry_config": {"log_format": 1}, + "scaling_config": {"instance_size": 1, "scaling_factor": 0.1471}, }, "description": "description_value", "restoring_services": [ @@ -11496,6 +11508,7 @@ def test_dataproc_metastore_base_transport(): "get_location", "list_locations", "get_operation", + "cancel_operation", "delete_operation", "list_operations", ) @@ -12586,6 +12599,64 @@ def test_test_iam_permissions_rest(request_type): assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) +def test_cancel_operation_rest_bad_request( + transport: str = "rest", request_type=operations_pb2.CancelOperationRequest +): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + request = request_type() + request = json_format.ParseDict( + {"name": "projects/sample1/locations/sample2/operations/sample3"}, request + ) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.cancel_operation(request) + + +@pytest.mark.parametrize( + "request_type", + [ + operations_pb2.CancelOperationRequest, + dict, + ], +) +def test_cancel_operation_rest(request_type): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} + request = request_type(**request_init) + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = None + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = "{}" + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.cancel_operation(request) + + # Establish that the response is the type that we expect. + assert response is None + + def test_delete_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.DeleteOperationRequest ): @@ -12899,6 +12970,145 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_cancel_operation(transport: str = "grpc"): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation_async(transport: str = "grpc"): + client = DataprocMetastoreAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = DataprocMetastoreAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = DataprocMetastoreAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + def test_get_operation(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), diff --git a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1alpha/test_dataproc_metastore_federation.py b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1alpha/test_dataproc_metastore_federation.py index 9c865050dee0..9700f50e3f0c 100644 --- a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1alpha/test_dataproc_metastore_federation.py +++ b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1alpha/test_dataproc_metastore_federation.py @@ -3891,6 +3891,7 @@ def test_dataproc_metastore_federation_base_transport(): "get_location", "list_locations", "get_operation", + "cancel_operation", "delete_operation", "list_operations", ) @@ -4819,6 +4820,64 @@ def test_test_iam_permissions_rest(request_type): assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) +def test_cancel_operation_rest_bad_request( + transport: str = "rest", request_type=operations_pb2.CancelOperationRequest +): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + request = request_type() + request = json_format.ParseDict( + {"name": "projects/sample1/locations/sample2/operations/sample3"}, request + ) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.cancel_operation(request) + + +@pytest.mark.parametrize( + "request_type", + [ + operations_pb2.CancelOperationRequest, + dict, + ], +) +def test_cancel_operation_rest(request_type): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} + request = request_type(**request_init) + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = None + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = "{}" + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.cancel_operation(request) + + # Establish that the response is the type that we expect. + assert response is None + + def test_delete_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.DeleteOperationRequest ): @@ -5132,6 +5191,145 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_cancel_operation(transport: str = "grpc"): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation_async(transport: str = "grpc"): + client = DataprocMetastoreFederationAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + def test_get_operation(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(), diff --git a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1beta/test_dataproc_metastore.py b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1beta/test_dataproc_metastore.py index c8ff02af55c6..96275a4cfe6e 100644 --- a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1beta/test_dataproc_metastore.py +++ b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1beta/test_dataproc_metastore.py @@ -6279,10 +6279,12 @@ def test_create_service_rest(request_type): "network_config": { "consumers": [ {"subnetwork": "subnetwork_value", "endpoint_uri": "endpoint_uri_value"} - ] + ], + "custom_routes_enabled": True, }, "database_type": 1, "telemetry_config": {"log_format": 1}, + "scaling_config": {"instance_size": 1, "scaling_factor": 0.1471}, } request = request_type(**request_init) @@ -6545,10 +6547,12 @@ def test_create_service_rest_bad_request( "network_config": { "consumers": [ {"subnetwork": "subnetwork_value", "endpoint_uri": "endpoint_uri_value"} - ] + ], + "custom_routes_enabled": True, }, "database_type": 1, "telemetry_config": {"log_format": 1}, + "scaling_config": {"instance_size": 1, "scaling_factor": 0.1471}, } request = request_type(**request_init) @@ -6709,10 +6713,12 @@ def test_update_service_rest(request_type): "network_config": { "consumers": [ {"subnetwork": "subnetwork_value", "endpoint_uri": "endpoint_uri_value"} - ] + ], + "custom_routes_enabled": True, }, "database_type": 1, "telemetry_config": {"log_format": 1}, + "scaling_config": {"instance_size": 1, "scaling_factor": 0.1471}, } request = request_type(**request_init) @@ -6958,10 +6964,12 @@ def test_update_service_rest_bad_request( "network_config": { "consumers": [ {"subnetwork": "subnetwork_value", "endpoint_uri": "endpoint_uri_value"} - ] + ], + "custom_routes_enabled": True, }, "database_type": 1, "telemetry_config": {"log_format": 1}, + "scaling_config": {"instance_size": 1, "scaling_factor": 0.1471}, } request = request_type(**request_init) @@ -9798,10 +9806,12 @@ def test_create_backup_rest(request_type): "subnetwork": "subnetwork_value", "endpoint_uri": "endpoint_uri_value", } - ] + ], + "custom_routes_enabled": True, }, "database_type": 1, "telemetry_config": {"log_format": 1}, + "scaling_config": {"instance_size": 1, "scaling_factor": 0.1471}, }, "description": "description_value", "restoring_services": [ @@ -10076,10 +10086,12 @@ def test_create_backup_rest_bad_request( "subnetwork": "subnetwork_value", "endpoint_uri": "endpoint_uri_value", } - ] + ], + "custom_routes_enabled": True, }, "database_type": 1, "telemetry_config": {"log_format": 1}, + "scaling_config": {"instance_size": 1, "scaling_factor": 0.1471}, }, "description": "description_value", "restoring_services": [ @@ -11496,6 +11508,7 @@ def test_dataproc_metastore_base_transport(): "get_location", "list_locations", "get_operation", + "cancel_operation", "delete_operation", "list_operations", ) @@ -12586,6 +12599,64 @@ def test_test_iam_permissions_rest(request_type): assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) +def test_cancel_operation_rest_bad_request( + transport: str = "rest", request_type=operations_pb2.CancelOperationRequest +): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + request = request_type() + request = json_format.ParseDict( + {"name": "projects/sample1/locations/sample2/operations/sample3"}, request + ) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.cancel_operation(request) + + +@pytest.mark.parametrize( + "request_type", + [ + operations_pb2.CancelOperationRequest, + dict, + ], +) +def test_cancel_operation_rest(request_type): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} + request = request_type(**request_init) + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = None + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = "{}" + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.cancel_operation(request) + + # Establish that the response is the type that we expect. + assert response is None + + def test_delete_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.DeleteOperationRequest ): @@ -12899,6 +12970,145 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_cancel_operation(transport: str = "grpc"): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation_async(transport: str = "grpc"): + client = DataprocMetastoreAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = DataprocMetastoreAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = DataprocMetastoreClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = DataprocMetastoreAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + def test_get_operation(transport: str = "grpc"): client = DataprocMetastoreClient( credentials=ga_credentials.AnonymousCredentials(), diff --git a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1beta/test_dataproc_metastore_federation.py b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1beta/test_dataproc_metastore_federation.py index 53699dd71ea0..8761cd45836a 100644 --- a/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1beta/test_dataproc_metastore_federation.py +++ b/packages/google-cloud-dataproc-metastore/tests/unit/gapic/metastore_v1beta/test_dataproc_metastore_federation.py @@ -3891,6 +3891,7 @@ def test_dataproc_metastore_federation_base_transport(): "get_location", "list_locations", "get_operation", + "cancel_operation", "delete_operation", "list_operations", ) @@ -4819,6 +4820,64 @@ def test_test_iam_permissions_rest(request_type): assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) +def test_cancel_operation_rest_bad_request( + transport: str = "rest", request_type=operations_pb2.CancelOperationRequest +): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + request = request_type() + request = json_format.ParseDict( + {"name": "projects/sample1/locations/sample2/operations/sample3"}, request + ) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.cancel_operation(request) + + +@pytest.mark.parametrize( + "request_type", + [ + operations_pb2.CancelOperationRequest, + dict, + ], +) +def test_cancel_operation_rest(request_type): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} + request = request_type(**request_init) + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = None + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = "{}" + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.cancel_operation(request) + + # Establish that the response is the type that we expect. + assert response is None + + def test_delete_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.DeleteOperationRequest ): @@ -5132,6 +5191,145 @@ async def test_delete_operation_from_dict_async(): call.assert_called() +def test_cancel_operation(transport: str = "grpc"): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation_async(transport: str = "grpc"): + client = DataprocMetastoreFederationAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = DataprocMetastoreFederationClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = DataprocMetastoreFederationAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + def test_get_operation(transport: str = "grpc"): client = DataprocMetastoreFederationClient( credentials=ga_credentials.AnonymousCredentials(),