diff --git a/.kokoro/samples/python3.10/common.cfg b/.kokoro/samples/python3.10/common.cfg index 17abca148a..a49138fd0a 100644 --- a/.kokoro/samples/python3.10/common.cfg +++ b/.kokoro/samples/python3.10/common.cfg @@ -14,7 +14,7 @@ env_vars: { } # Declare build specific Cloud project. -env_vars: { +env_vars: { key: "BUILD_SPECIFIC_GCLOUD_PROJECT" value: "ucaip-sample-tests" } diff --git a/.kokoro/samples/python3.11/common.cfg b/.kokoro/samples/python3.11/common.cfg index 1166f2c317..c870d5b2c7 100644 --- a/.kokoro/samples/python3.11/common.cfg +++ b/.kokoro/samples/python3.11/common.cfg @@ -14,7 +14,7 @@ env_vars: { } # Declare build specific Cloud project. -env_vars: { +env_vars: { key: "BUILD_SPECIFIC_GCLOUD_PROJECT" value: "ucaip-sample-tests" } diff --git a/.kokoro/samples/python3.7/common.cfg b/.kokoro/samples/python3.7/common.cfg index eed23ad9bc..cc8296c89d 100644 --- a/.kokoro/samples/python3.7/common.cfg +++ b/.kokoro/samples/python3.7/common.cfg @@ -14,7 +14,7 @@ env_vars: { } # Declare build specific Cloud project. -env_vars: { +env_vars: { key: "BUILD_SPECIFIC_GCLOUD_PROJECT" value: "ucaip-sample-tests" } diff --git a/.kokoro/samples/python3.8/common.cfg b/.kokoro/samples/python3.8/common.cfg index 26e513823e..a118253a82 100644 --- a/.kokoro/samples/python3.8/common.cfg +++ b/.kokoro/samples/python3.8/common.cfg @@ -14,7 +14,7 @@ env_vars: { } # Declare build specific Cloud project. -env_vars: { +env_vars: { key: "BUILD_SPECIFIC_GCLOUD_PROJECT" value: "ucaip-sample-tests" } diff --git a/.kokoro/samples/python3.9/common.cfg b/.kokoro/samples/python3.9/common.cfg index abda08ed27..5a549c80fc 100644 --- a/.kokoro/samples/python3.9/common.cfg +++ b/.kokoro/samples/python3.9/common.cfg @@ -14,7 +14,7 @@ env_vars: { } # Declare build specific Cloud project. -env_vars: { +env_vars: { key: "BUILD_SPECIFIC_GCLOUD_PROJECT" value: "ucaip-sample-tests" } diff --git a/google/cloud/aiplatform_v1beta1/__init__.py b/google/cloud/aiplatform_v1beta1/__init__.py index 06c852162f..491021d0c3 100644 --- a/google/cloud/aiplatform_v1beta1/__init__.py +++ b/google/cloud/aiplatform_v1beta1/__init__.py @@ -479,6 +479,8 @@ from .types.persistent_resource_service import GetPersistentResourceRequest from .types.persistent_resource_service import ListPersistentResourcesRequest from .types.persistent_resource_service import ListPersistentResourcesResponse +from .types.persistent_resource_service import UpdatePersistentResourceOperationMetadata +from .types.persistent_resource_service import UpdatePersistentResourceRequest from .types.pipeline_failure_policy import PipelineFailurePolicy from .types.pipeline_job import PipelineJob from .types.pipeline_job import PipelineJobDetail @@ -1188,6 +1190,8 @@ "UpdateModelDeploymentMonitoringJobOperationMetadata", "UpdateModelDeploymentMonitoringJobRequest", "UpdateModelRequest", + "UpdatePersistentResourceOperationMetadata", + "UpdatePersistentResourceRequest", "UpdateScheduleRequest", "UpdateSpecialistPoolOperationMetadata", "UpdateSpecialistPoolRequest", diff --git a/google/cloud/aiplatform_v1beta1/gapic_metadata.json b/google/cloud/aiplatform_v1beta1/gapic_metadata.json index 530f02ee15..6952840eb4 100644 --- a/google/cloud/aiplatform_v1beta1/gapic_metadata.json +++ b/google/cloud/aiplatform_v1beta1/gapic_metadata.json @@ -1761,6 +1761,11 @@ "methods": [ "list_persistent_resources" ] + }, + "UpdatePersistentResource": { + "methods": [ + "update_persistent_resource" + ] } } }, @@ -1786,6 +1791,11 @@ "methods": [ "list_persistent_resources" ] + }, + "UpdatePersistentResource": { + "methods": [ + "update_persistent_resource" + ] } } } diff --git a/google/cloud/aiplatform_v1beta1/services/persistent_resource_service/async_client.py b/google/cloud/aiplatform_v1beta1/services/persistent_resource_service/async_client.py index ad59d81337..da32e70a7b 100644 --- a/google/cloud/aiplatform_v1beta1/services/persistent_resource_service/async_client.py +++ b/google/cloud/aiplatform_v1beta1/services/persistent_resource_service/async_client.py @@ -57,6 +57,7 @@ from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore from google.rpc import status_pb2 # type: ignore from .transports.base import PersistentResourceServiceTransport, DEFAULT_CLIENT_INFO @@ -748,6 +749,143 @@ async def sample_delete_persistent_resource(): # Done; return the response. return response + async def update_persistent_resource( + self, + request: Optional[ + Union[persistent_resource_service.UpdatePersistentResourceRequest, dict] + ] = None, + *, + persistent_resource: Optional[ + gca_persistent_resource.PersistentResource + ] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Updates a PersistentResource. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import aiplatform_v1beta1 + + async def sample_update_persistent_resource(): + # Create a client + client = aiplatform_v1beta1.PersistentResourceServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdatePersistentResourceRequest( + ) + + # Make the request + operation = client.update_persistent_resource(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.aiplatform_v1beta1.types.UpdatePersistentResourceRequest, dict]]): + The request object. Request message for + UpdatePersistentResource method. + persistent_resource (:class:`google.cloud.aiplatform_v1beta1.types.PersistentResource`): + Required. The PersistentResource to update. + + The PersistentResource's ``name`` field is used to + identify the PersistentResource to update. Format: + ``projects/{project}/locations/{location}/persistentResources/{persistent_resource}`` + + This corresponds to the ``persistent_resource`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Required. Specify the fields to be + overwritten in the PersistentResource by + the update method. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1beta1.types.PersistentResource` Represents long-lasting resources that are dedicated to users to runs custom + workloads. A PersistentResource can have multiple + node pools and each node pool can have its own + machine spec. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([persistent_resource, update_mask]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = persistent_resource_service.UpdatePersistentResourceRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if persistent_resource is not None: + request.persistent_resource = persistent_resource + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.update_persistent_resource, + 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( + (("persistent_resource.name", request.persistent_resource.name),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + gca_persistent_resource.PersistentResource, + metadata_type=persistent_resource_service.UpdatePersistentResourceOperationMetadata, + ) + + # Done; return the response. + return response + async def list_operations( self, request: Optional[operations_pb2.ListOperationsRequest] = None, diff --git a/google/cloud/aiplatform_v1beta1/services/persistent_resource_service/client.py b/google/cloud/aiplatform_v1beta1/services/persistent_resource_service/client.py index 61cb1f217e..57d4e685d7 100644 --- a/google/cloud/aiplatform_v1beta1/services/persistent_resource_service/client.py +++ b/google/cloud/aiplatform_v1beta1/services/persistent_resource_service/client.py @@ -61,6 +61,7 @@ from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore from google.rpc import status_pb2 # type: ignore from .transports.base import PersistentResourceServiceTransport, DEFAULT_CLIENT_INFO @@ -999,6 +1000,149 @@ def sample_delete_persistent_resource(): # Done; return the response. return response + def update_persistent_resource( + self, + request: Optional[ + Union[persistent_resource_service.UpdatePersistentResourceRequest, dict] + ] = None, + *, + persistent_resource: Optional[ + gca_persistent_resource.PersistentResource + ] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Updates a PersistentResource. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import aiplatform_v1beta1 + + def sample_update_persistent_resource(): + # Create a client + client = aiplatform_v1beta1.PersistentResourceServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdatePersistentResourceRequest( + ) + + # Make the request + operation = client.update_persistent_resource(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.UpdatePersistentResourceRequest, dict]): + The request object. Request message for + UpdatePersistentResource method. + persistent_resource (google.cloud.aiplatform_v1beta1.types.PersistentResource): + Required. The PersistentResource to update. + + The PersistentResource's ``name`` field is used to + identify the PersistentResource to update. Format: + ``projects/{project}/locations/{location}/persistentResources/{persistent_resource}`` + + This corresponds to the ``persistent_resource`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. Specify the fields to be + overwritten in the PersistentResource by + the update method. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1beta1.types.PersistentResource` Represents long-lasting resources that are dedicated to users to runs custom + workloads. A PersistentResource can have multiple + node pools and each node pool can have its own + machine spec. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([persistent_resource, update_mask]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a persistent_resource_service.UpdatePersistentResourceRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, persistent_resource_service.UpdatePersistentResourceRequest + ): + request = persistent_resource_service.UpdatePersistentResourceRequest( + request + ) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if persistent_resource is not None: + request.persistent_resource = persistent_resource + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.update_persistent_resource + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("persistent_resource.name", request.persistent_resource.name),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + gca_persistent_resource.PersistentResource, + metadata_type=persistent_resource_service.UpdatePersistentResourceOperationMetadata, + ) + + # Done; return the response. + return response + def __enter__(self) -> "PersistentResourceServiceClient": return self diff --git a/google/cloud/aiplatform_v1beta1/services/persistent_resource_service/transports/base.py b/google/cloud/aiplatform_v1beta1/services/persistent_resource_service/transports/base.py index 36321f83d3..209b00f077 100644 --- a/google/cloud/aiplatform_v1beta1/services/persistent_resource_service/transports/base.py +++ b/google/cloud/aiplatform_v1beta1/services/persistent_resource_service/transports/base.py @@ -150,6 +150,11 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), + self.update_persistent_resource: gapic_v1.method.wrap_method( + self.update_persistent_resource, + default_timeout=None, + client_info=client_info, + ), } def close(self): @@ -208,6 +213,15 @@ def delete_persistent_resource( ]: raise NotImplementedError() + @property + def update_persistent_resource( + self, + ) -> Callable[ + [persistent_resource_service.UpdatePersistentResourceRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + @property def list_operations( self, diff --git a/google/cloud/aiplatform_v1beta1/services/persistent_resource_service/transports/grpc.py b/google/cloud/aiplatform_v1beta1/services/persistent_resource_service/transports/grpc.py index ab8a369deb..846eb412f6 100644 --- a/google/cloud/aiplatform_v1beta1/services/persistent_resource_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1beta1/services/persistent_resource_service/transports/grpc.py @@ -368,6 +368,35 @@ def delete_persistent_resource( ) return self._stubs["delete_persistent_resource"] + @property + def update_persistent_resource( + self, + ) -> Callable[ + [persistent_resource_service.UpdatePersistentResourceRequest], + operations_pb2.Operation, + ]: + r"""Return a callable for the update persistent resource method over gRPC. + + Updates a PersistentResource. + + Returns: + Callable[[~.UpdatePersistentResourceRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # 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 "update_persistent_resource" not in self._stubs: + self._stubs["update_persistent_resource"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.PersistentResourceService/UpdatePersistentResource", + request_serializer=persistent_resource_service.UpdatePersistentResourceRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_persistent_resource"] + def close(self): self.grpc_channel.close() diff --git a/google/cloud/aiplatform_v1beta1/services/persistent_resource_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1beta1/services/persistent_resource_service/transports/grpc_asyncio.py index 765266b821..dc78aff0d9 100644 --- a/google/cloud/aiplatform_v1beta1/services/persistent_resource_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1beta1/services/persistent_resource_service/transports/grpc_asyncio.py @@ -373,6 +373,35 @@ def delete_persistent_resource( ) return self._stubs["delete_persistent_resource"] + @property + def update_persistent_resource( + self, + ) -> Callable[ + [persistent_resource_service.UpdatePersistentResourceRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the update persistent resource method over gRPC. + + Updates a PersistentResource. + + Returns: + Callable[[~.UpdatePersistentResourceRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # 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 "update_persistent_resource" not in self._stubs: + self._stubs["update_persistent_resource"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.PersistentResourceService/UpdatePersistentResource", + request_serializer=persistent_resource_service.UpdatePersistentResourceRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_persistent_resource"] + def close(self): return self.grpc_channel.close() diff --git a/google/cloud/aiplatform_v1beta1/types/__init__.py b/google/cloud/aiplatform_v1beta1/types/__init__.py index 6340923f22..bab8c61a98 100644 --- a/google/cloud/aiplatform_v1beta1/types/__init__.py +++ b/google/cloud/aiplatform_v1beta1/types/__init__.py @@ -528,6 +528,8 @@ GetPersistentResourceRequest, ListPersistentResourcesRequest, ListPersistentResourcesResponse, + UpdatePersistentResourceOperationMetadata, + UpdatePersistentResourceRequest, ) from .pipeline_job import ( PipelineJob, @@ -1121,6 +1123,8 @@ "GetPersistentResourceRequest", "ListPersistentResourcesRequest", "ListPersistentResourcesResponse", + "UpdatePersistentResourceOperationMetadata", + "UpdatePersistentResourceRequest", "PipelineFailurePolicy", "PipelineJob", "PipelineJobDetail", diff --git a/google/cloud/aiplatform_v1beta1/types/persistent_resource.py b/google/cloud/aiplatform_v1beta1/types/persistent_resource.py index 4425c86407..eda6633171 100644 --- a/google/cloud/aiplatform_v1beta1/types/persistent_resource.py +++ b/google/cloud/aiplatform_v1beta1/types/persistent_resource.py @@ -353,12 +353,35 @@ class RaySpec(proto.Message): this field if you need all the resource pools to have the same Ray image, Otherwise, use the {@code resource_pool_images} field. + resource_pool_images (MutableMapping[str, str]): + Optional. Required if image_uri is not set. A map of + resource_pool_id to prebuild Ray image if user need to use + different images for different head/worker pools. This map + needs to cover all the resource pool ids. Example: { + "ray_head_node_pool": "head image" "ray_worker_node_pool1": + "worker image" "ray_worker_node_pool2": "another worker + image" } + head_node_resource_pool_id (str): + Optional. This will be used to indicate which + resource pool will serve as the Ray head + node(the first node within that pool). Will use + the machine from the first workerpool as the + head node by default if this field is not set. """ image_uri: str = proto.Field( proto.STRING, number=1, ) + resource_pool_images: MutableMapping[str, str] = proto.MapField( + proto.STRING, + proto.STRING, + number=6, + ) + head_node_resource_pool_id: str = proto.Field( + proto.STRING, + number=7, + ) class ResourceRuntime(proto.Message): diff --git a/google/cloud/aiplatform_v1beta1/types/persistent_resource_service.py b/google/cloud/aiplatform_v1beta1/types/persistent_resource_service.py index 07ee437df8..ae19898f07 100644 --- a/google/cloud/aiplatform_v1beta1/types/persistent_resource_service.py +++ b/google/cloud/aiplatform_v1beta1/types/persistent_resource_service.py @@ -23,6 +23,7 @@ from google.cloud.aiplatform_v1beta1.types import ( persistent_resource as gca_persistent_resource, ) +from google.protobuf import field_mask_pb2 # type: ignore __protobuf__ = proto.module( @@ -30,10 +31,12 @@ manifest={ "CreatePersistentResourceRequest", "CreatePersistentResourceOperationMetadata", + "UpdatePersistentResourceOperationMetadata", "GetPersistentResourceRequest", "ListPersistentResourcesRequest", "ListPersistentResourcesResponse", "DeletePersistentResourceRequest", + "UpdatePersistentResourceRequest", }, ) @@ -88,6 +91,21 @@ class CreatePersistentResourceOperationMetadata(proto.Message): ) +class UpdatePersistentResourceOperationMetadata(proto.Message): + r"""Details of operations that perform update PersistentResource. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1beta1.types.GenericOperationMetadata): + Operation metadata for PersistentResource. + """ + + generic_metadata: operation.GenericOperationMetadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + + class GetPersistentResourceRequest(proto.Message): r"""Request message for [PersistentResourceService.GetPersistentResource][google.cloud.aiplatform.v1beta1.PersistentResourceService.GetPersistentResource]. @@ -184,4 +202,32 @@ class DeletePersistentResourceRequest(proto.Message): ) +class UpdatePersistentResourceRequest(proto.Message): + r"""Request message for UpdatePersistentResource method. + + Attributes: + persistent_resource (google.cloud.aiplatform_v1beta1.types.PersistentResource): + Required. The PersistentResource to update. + + The PersistentResource's ``name`` field is used to identify + the PersistentResource to update. Format: + ``projects/{project}/locations/{location}/persistentResources/{persistent_resource}`` + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. Specify the fields to be + overwritten in the PersistentResource by the + update method. + """ + + persistent_resource: gca_persistent_resource.PersistentResource = proto.Field( + proto.MESSAGE, + number=1, + message=gca_persistent_resource.PersistentResource, + ) + update_mask: field_mask_pb2.FieldMask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + + __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_persistent_resource_service_update_persistent_resource_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_persistent_resource_service_update_persistent_resource_async.py new file mode 100644 index 0000000000..3f327bd7d8 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_persistent_resource_service_update_persistent_resource_async.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdatePersistentResource +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PersistentResourceService_UpdatePersistentResource_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_persistent_resource(): + # Create a client + client = aiplatform_v1beta1.PersistentResourceServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdatePersistentResourceRequest( + ) + + # Make the request + operation = client.update_persistent_resource(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_PersistentResourceService_UpdatePersistentResource_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_persistent_resource_service_update_persistent_resource_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_persistent_resource_service_update_persistent_resource_sync.py new file mode 100644 index 0000000000..3a482e0972 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_persistent_resource_service_update_persistent_resource_sync.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdatePersistentResource +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PersistentResourceService_UpdatePersistentResource_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import aiplatform_v1beta1 + + +def sample_update_persistent_resource(): + # Create a client + client = aiplatform_v1beta1.PersistentResourceServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdatePersistentResourceRequest( + ) + + # Make the request + operation = client.update_persistent_resource(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_PersistentResourceService_UpdatePersistentResource_sync] diff --git a/samples/generated_samples/snippet_metadata_google.cloud.aiplatform.v1beta1.json b/samples/generated_samples/snippet_metadata_google.cloud.aiplatform.v1beta1.json index 5e2f664a7f..17646f2fac 100644 --- a/samples/generated_samples/snippet_metadata_google.cloud.aiplatform.v1beta1.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.aiplatform.v1beta1.json @@ -26112,6 +26112,175 @@ ], "title": "aiplatform_v1beta1_generated_persistent_resource_service_list_persistent_resources_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PersistentResourceServiceAsyncClient", + "shortName": "PersistentResourceServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PersistentResourceServiceAsyncClient.update_persistent_resource", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PersistentResourceService.UpdatePersistentResource", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PersistentResourceService", + "shortName": "PersistentResourceService" + }, + "shortName": "UpdatePersistentResource" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdatePersistentResourceRequest" + }, + { + "name": "persistent_resource", + "type": "google.cloud.aiplatform_v1beta1.types.PersistentResource" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "update_persistent_resource" + }, + "description": "Sample for UpdatePersistentResource", + "file": "aiplatform_v1beta1_generated_persistent_resource_service_update_persistent_resource_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PersistentResourceService_UpdatePersistentResource_async", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 51, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 52, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_persistent_resource_service_update_persistent_resource_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PersistentResourceServiceClient", + "shortName": "PersistentResourceServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PersistentResourceServiceClient.update_persistent_resource", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PersistentResourceService.UpdatePersistentResource", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PersistentResourceService", + "shortName": "PersistentResourceService" + }, + "shortName": "UpdatePersistentResource" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdatePersistentResourceRequest" + }, + { + "name": "persistent_resource", + "type": "google.cloud.aiplatform_v1beta1.types.PersistentResource" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "update_persistent_resource" + }, + "description": "Sample for UpdatePersistentResource", + "file": "aiplatform_v1beta1_generated_persistent_resource_service_update_persistent_resource_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PersistentResourceService_UpdatePersistentResource_sync", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 51, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 52, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_persistent_resource_service_update_persistent_resource_sync.py" + }, { "canonical": true, "clientMethod": { diff --git a/tests/unit/gapic/aiplatform_v1beta1/test_persistent_resource_service.py b/tests/unit/gapic/aiplatform_v1beta1/test_persistent_resource_service.py index 4a44c56cde..635ee666a6 100644 --- a/tests/unit/gapic/aiplatform_v1beta1/test_persistent_resource_service.py +++ b/tests/unit/gapic/aiplatform_v1beta1/test_persistent_resource_service.py @@ -68,6 +68,7 @@ from google.oauth2 import service_account from google.protobuf import any_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore from google.rpc import status_pb2 # type: ignore import google.auth @@ -1967,6 +1968,265 @@ async def test_delete_persistent_resource_flattened_error_async(): ) +@pytest.mark.parametrize( + "request_type", + [ + persistent_resource_service.UpdatePersistentResourceRequest, + dict, + ], +) +def test_update_persistent_resource(request_type, transport: str = "grpc"): + client = PersistentResourceServiceClient( + 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 = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_persistent_resource), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.update_persistent_resource(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == persistent_resource_service.UpdatePersistentResourceRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_update_persistent_resource_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = PersistentResourceServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_persistent_resource), "__call__" + ) as call: + client.update_persistent_resource() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == persistent_resource_service.UpdatePersistentResourceRequest() + + +@pytest.mark.asyncio +async def test_update_persistent_resource_async( + transport: str = "grpc_asyncio", + request_type=persistent_resource_service.UpdatePersistentResourceRequest, +): + client = PersistentResourceServiceAsyncClient( + 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 = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_persistent_resource), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.update_persistent_resource(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == persistent_resource_service.UpdatePersistentResourceRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_update_persistent_resource_async_from_dict(): + await test_update_persistent_resource_async(request_type=dict) + + +def test_update_persistent_resource_field_headers(): + client = PersistentResourceServiceClient( + 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 = persistent_resource_service.UpdatePersistentResourceRequest() + + request.persistent_resource.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_persistent_resource), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_persistent_resource(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", + "persistent_resource.name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_persistent_resource_field_headers_async(): + client = PersistentResourceServiceAsyncClient( + 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 = persistent_resource_service.UpdatePersistentResourceRequest() + + request.persistent_resource.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_persistent_resource), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.update_persistent_resource(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, 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", + "persistent_resource.name=name_value", + ) in kw["metadata"] + + +def test_update_persistent_resource_flattened(): + client = PersistentResourceServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_persistent_resource), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_persistent_resource( + persistent_resource=gca_persistent_resource.PersistentResource( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].persistent_resource + mock_val = gca_persistent_resource.PersistentResource(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +def test_update_persistent_resource_flattened_error(): + client = PersistentResourceServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_persistent_resource( + persistent_resource_service.UpdatePersistentResourceRequest(), + persistent_resource=gca_persistent_resource.PersistentResource( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_persistent_resource_flattened_async(): + client = PersistentResourceServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_persistent_resource), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_persistent_resource( + persistent_resource=gca_persistent_resource.PersistentResource( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].persistent_resource + mock_val = gca_persistent_resource.PersistentResource(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_update_persistent_resource_flattened_error_async(): + client = PersistentResourceServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_persistent_resource( + persistent_resource_service.UpdatePersistentResourceRequest(), + persistent_resource=gca_persistent_resource.PersistentResource( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.PersistentResourceServiceGrpcTransport( @@ -2108,6 +2368,7 @@ def test_persistent_resource_service_base_transport(): "get_persistent_resource", "list_persistent_resources", "delete_persistent_resource", + "update_persistent_resource", "set_iam_policy", "get_iam_policy", "test_iam_permissions",