diff --git a/AiPlatform/metadata/V1/ModelGardenService.php b/AiPlatform/metadata/V1/ModelGardenService.php index 91c775a1b381..bda3e9d3397d 100644 Binary files a/AiPlatform/metadata/V1/ModelGardenService.php and b/AiPlatform/metadata/V1/ModelGardenService.php differ diff --git a/AiPlatform/samples/V1/ModelGardenServiceClient/deploy.php b/AiPlatform/samples/V1/ModelGardenServiceClient/deploy.php new file mode 100644 index 000000000000..68c7dd7b6df6 --- /dev/null +++ b/AiPlatform/samples/V1/ModelGardenServiceClient/deploy.php @@ -0,0 +1,84 @@ +setDestination($formattedDestination); + + // Call the API and handle any network failures. + try { + /** @var OperationResponse $response */ + $response = $modelGardenServiceClient->deploy($request); + $response->pollUntilComplete(); + + if ($response->operationSucceeded()) { + /** @var DeployResponse $result */ + $result = $response->getResult(); + printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString()); + } else { + /** @var Status $error */ + $error = $response->getError(); + printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString()); + } + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} + +/** + * Helper to execute the sample. + * + * This sample 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, + * please see the apiEndpoint client configuration option for more details. + */ +function callSample(): void +{ + $formattedDestination = ModelGardenServiceClient::locationName('[PROJECT]', '[LOCATION]'); + + deploy_sample($formattedDestination); +} +// [END aiplatform_v1_generated_ModelGardenService_Deploy_sync] diff --git a/AiPlatform/src/V1/Client/ModelGardenServiceClient.php b/AiPlatform/src/V1/Client/ModelGardenServiceClient.php index ffbf1cdfa902..f261b3501918 100644 --- a/AiPlatform/src/V1/Client/ModelGardenServiceClient.php +++ b/AiPlatform/src/V1/Client/ModelGardenServiceClient.php @@ -27,12 +27,14 @@ use Google\ApiCore\ApiException; use Google\ApiCore\CredentialsWrapper; use Google\ApiCore\GapicClientTrait; +use Google\ApiCore\OperationResponse; use Google\ApiCore\PagedListResponse; use Google\ApiCore\ResourceHelperTrait; use Google\ApiCore\RetrySettings; use Google\ApiCore\Transport\TransportInterface; use Google\ApiCore\ValidationException; use Google\Auth\FetchAuthTokenInterface; +use Google\Cloud\AIPlatform\V1\DeployRequest; use Google\Cloud\AIPlatform\V1\GetPublisherModelRequest; use Google\Cloud\AIPlatform\V1\PublisherModel; use Google\Cloud\Iam\V1\GetIamPolicyRequest; @@ -43,6 +45,8 @@ use Google\Cloud\Location\GetLocationRequest; use Google\Cloud\Location\ListLocationsRequest; use Google\Cloud\Location\Location; +use Google\LongRunning\Client\OperationsClient; +use Google\LongRunning\Operation; use GuzzleHttp\Promise\PromiseInterface; use Psr\Log\LoggerInterface; @@ -57,6 +61,7 @@ * name, and additionally a parseName method to extract the individual identifiers * contained within formatted names that are returned by the API. * + * @method PromiseInterface deployAsync(DeployRequest $request, array $optionalArgs = []) * @method PromiseInterface getPublisherModelAsync(GetPublisherModelRequest $request, array $optionalArgs = []) * @method PromiseInterface getLocationAsync(GetLocationRequest $request, array $optionalArgs = []) * @method PromiseInterface listLocationsAsync(ListLocationsRequest $request, array $optionalArgs = []) @@ -91,6 +96,8 @@ final class ModelGardenServiceClient /** The default scopes required by the service. */ public static $serviceScopes = ['https://www.googleapis.com/auth/cloud-platform']; + private $operationsClient; + private static function getClientDefaults() { return [ @@ -110,6 +117,73 @@ private static function getClientDefaults() ]; } + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started by a long + * running API method. If $methodName is not provided, or does not match a long + * running API method, then the operation can still be resumed, but the + * OperationResponse object will not deserialize the final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return OperationResponse + */ + public function resumeOperation($operationName, $methodName = null) + { + $options = isset($this->descriptors[$methodName]['longRunning']) + ? $this->descriptors[$methodName]['longRunning'] + : []; + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + /** + * Create the default operation client for the service. + * + * @param array $options ClientOptions for the client. + * + * @return OperationsClient + */ + private function createOperationsClient(array $options) + { + // Unset client-specific configuration options + unset($options['serviceName'], $options['clientConfig'], $options['descriptorsConfigPath']); + + if (isset($options['operationsClient'])) { + return $options['operationsClient']; + } + + return new OperationsClient($options); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + /** * Formats a string containing the fully-qualified path to represent a * publisher_model resource. @@ -127,11 +201,32 @@ public static function publisherModelName(string $publisher, string $model): str ]); } + /** + * Formats a string containing the fully-qualified path to represent a reservation + * resource. + * + * @param string $projectIdOrNumber + * @param string $zone + * @param string $reservationName + * + * @return string The formatted reservation resource. + */ + public static function reservationName(string $projectIdOrNumber, string $zone, string $reservationName): string + { + return self::getPathTemplate('reservation')->render([ + 'project_id_or_number' => $projectIdOrNumber, + 'zone' => $zone, + 'reservation_name' => $reservationName, + ]); + } + /** * Parses a formatted name string and returns an associative array of the components in the name. * The following name formats are supported: * Template: Pattern + * - location: projects/{project}/locations/{location} * - publisherModel: publishers/{publisher}/models/{model} + * - reservation: projects/{project_id_or_number}/zones/{zone}/reservations/{reservation_name} * * The optional $template argument can be supplied to specify a particular pattern, * and must match one of the templates listed above. If no $template argument is @@ -218,6 +313,7 @@ public function __construct(array $options = []) { $clientOptions = $this->buildClientOptions($options); $this->setClientOptions($clientOptions); + $this->operationsClient = $this->createOperationsClient($clientOptions); } /** Handles execution of the async variants for each documented method. */ @@ -231,6 +327,32 @@ public function __call($method, $args) return call_user_func_array([$this, 'startAsyncCall'], $args); } + /** + * Deploys a model to a new endpoint. + * + * The async variant is {@see ModelGardenServiceClient::deployAsync()} . + * + * @example samples/V1/ModelGardenServiceClient/deploy.php + * + * @param DeployRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deploy(DeployRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('Deploy', $request, $callOptions)->wait(); + } + /** * Gets a Model Garden publisher model. * diff --git a/AiPlatform/src/V1/DeployOperationMetadata.php b/AiPlatform/src/V1/DeployOperationMetadata.php new file mode 100644 index 000000000000..22ca9d0cc087 --- /dev/null +++ b/AiPlatform/src/V1/DeployOperationMetadata.php @@ -0,0 +1,218 @@ +google.cloud.aiplatform.v1.DeployOperationMetadata + */ +class DeployOperationMetadata extends \Google\Protobuf\Internal\Message +{ + /** + * The operation generic information. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.GenericOperationMetadata generic_metadata = 1; + */ + protected $generic_metadata = null; + /** + * Output only. The name of the model resource. + * + * Generated from protobuf field string publisher_model = 2 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { + */ + protected $publisher_model = ''; + /** + * Output only. The resource name of the Location to deploy the model in. + * Format: `projects/{project}/locations/{location}` + * + * Generated from protobuf field string destination = 3 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { + */ + protected $destination = ''; + /** + * Output only. The project number where the deploy model request is sent. + * + * Generated from protobuf field int64 project_number = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $project_number = 0; + /** + * Output only. The model id to be used at query time. + * + * Generated from protobuf field string model_id = 5 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $model_id = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Cloud\AIPlatform\V1\GenericOperationMetadata $generic_metadata + * The operation generic information. + * @type string $publisher_model + * Output only. The name of the model resource. + * @type string $destination + * Output only. The resource name of the Location to deploy the model in. + * Format: `projects/{project}/locations/{location}` + * @type int|string $project_number + * Output only. The project number where the deploy model request is sent. + * @type string $model_id + * Output only. The model id to be used at query time. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Aiplatform\V1\ModelGardenService::initOnce(); + parent::__construct($data); + } + + /** + * The operation generic information. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.GenericOperationMetadata generic_metadata = 1; + * @return \Google\Cloud\AIPlatform\V1\GenericOperationMetadata|null + */ + public function getGenericMetadata() + { + return $this->generic_metadata; + } + + public function hasGenericMetadata() + { + return isset($this->generic_metadata); + } + + public function clearGenericMetadata() + { + unset($this->generic_metadata); + } + + /** + * The operation generic information. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.GenericOperationMetadata generic_metadata = 1; + * @param \Google\Cloud\AIPlatform\V1\GenericOperationMetadata $var + * @return $this + */ + public function setGenericMetadata($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\AIPlatform\V1\GenericOperationMetadata::class); + $this->generic_metadata = $var; + + return $this; + } + + /** + * Output only. The name of the model resource. + * + * Generated from protobuf field string publisher_model = 2 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { + * @return string + */ + public function getPublisherModel() + { + return $this->publisher_model; + } + + /** + * Output only. The name of the model resource. + * + * Generated from protobuf field string publisher_model = 2 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setPublisherModel($var) + { + GPBUtil::checkString($var, True); + $this->publisher_model = $var; + + return $this; + } + + /** + * Output only. The resource name of the Location to deploy the model in. + * Format: `projects/{project}/locations/{location}` + * + * Generated from protobuf field string destination = 3 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { + * @return string + */ + public function getDestination() + { + return $this->destination; + } + + /** + * Output only. The resource name of the Location to deploy the model in. + * Format: `projects/{project}/locations/{location}` + * + * Generated from protobuf field string destination = 3 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setDestination($var) + { + GPBUtil::checkString($var, True); + $this->destination = $var; + + return $this; + } + + /** + * Output only. The project number where the deploy model request is sent. + * + * Generated from protobuf field int64 project_number = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return int|string + */ + public function getProjectNumber() + { + return $this->project_number; + } + + /** + * Output only. The project number where the deploy model request is sent. + * + * Generated from protobuf field int64 project_number = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param int|string $var + * @return $this + */ + public function setProjectNumber($var) + { + GPBUtil::checkInt64($var); + $this->project_number = $var; + + return $this; + } + + /** + * Output only. The model id to be used at query time. + * + * Generated from protobuf field string model_id = 5 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getModelId() + { + return $this->model_id; + } + + /** + * Output only. The model id to be used at query time. + * + * Generated from protobuf field string model_id = 5 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setModelId($var) + { + GPBUtil::checkString($var, True); + $this->model_id = $var; + + return $this; + } + +} + diff --git a/AiPlatform/src/V1/DeployRequest.php b/AiPlatform/src/V1/DeployRequest.php new file mode 100644 index 000000000000..02805b06d8db --- /dev/null +++ b/AiPlatform/src/V1/DeployRequest.php @@ -0,0 +1,303 @@ +google.cloud.aiplatform.v1.DeployRequest + */ +class DeployRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The resource name of the Location to deploy the model in. + * Format: `projects/{project}/locations/{location}` + * + * Generated from protobuf field string destination = 4 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + protected $destination = ''; + /** + * Optional. The model config to use for the deployment. + * If not specified, the default model config will be used. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.DeployRequest.ModelConfig model_config = 5 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $model_config = null; + /** + * Optional. The endpoint config to use for the deployment. + * If not specified, the default endpoint config will be used. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.DeployRequest.EndpointConfig endpoint_config = 6 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $endpoint_config = null; + /** + * Optional. The deploy config to use for the deployment. + * If not specified, the default deploy config will be used. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.DeployRequest.DeployConfig deploy_config = 7 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $deploy_config = null; + protected $artifacts; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $publisher_model_name + * The Model Garden model to deploy. + * Format: + * `publishers/{publisher}/models/{publisher_model}@{version_id}`, or + * `publishers/hf-{hugging-face-author}/models/{hugging-face-model-name}@001`. + * @type string $hugging_face_model_id + * The Hugging Face model to deploy. + * Format: Hugging Face model ID like `google/gemma-2-2b-it`. + * @type string $destination + * Required. The resource name of the Location to deploy the model in. + * Format: `projects/{project}/locations/{location}` + * @type \Google\Cloud\AIPlatform\V1\DeployRequest\ModelConfig $model_config + * Optional. The model config to use for the deployment. + * If not specified, the default model config will be used. + * @type \Google\Cloud\AIPlatform\V1\DeployRequest\EndpointConfig $endpoint_config + * Optional. The endpoint config to use for the deployment. + * If not specified, the default endpoint config will be used. + * @type \Google\Cloud\AIPlatform\V1\DeployRequest\DeployConfig $deploy_config + * Optional. The deploy config to use for the deployment. + * If not specified, the default deploy config will be used. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Aiplatform\V1\ModelGardenService::initOnce(); + parent::__construct($data); + } + + /** + * The Model Garden model to deploy. + * Format: + * `publishers/{publisher}/models/{publisher_model}@{version_id}`, or + * `publishers/hf-{hugging-face-author}/models/{hugging-face-model-name}@001`. + * + * Generated from protobuf field string publisher_model_name = 1 [(.google.api.resource_reference) = { + * @return string + */ + public function getPublisherModelName() + { + return $this->readOneof(1); + } + + public function hasPublisherModelName() + { + return $this->hasOneof(1); + } + + /** + * The Model Garden model to deploy. + * Format: + * `publishers/{publisher}/models/{publisher_model}@{version_id}`, or + * `publishers/hf-{hugging-face-author}/models/{hugging-face-model-name}@001`. + * + * Generated from protobuf field string publisher_model_name = 1 [(.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setPublisherModelName($var) + { + GPBUtil::checkString($var, True); + $this->writeOneof(1, $var); + + return $this; + } + + /** + * The Hugging Face model to deploy. + * Format: Hugging Face model ID like `google/gemma-2-2b-it`. + * + * Generated from protobuf field string hugging_face_model_id = 2; + * @return string + */ + public function getHuggingFaceModelId() + { + return $this->readOneof(2); + } + + public function hasHuggingFaceModelId() + { + return $this->hasOneof(2); + } + + /** + * The Hugging Face model to deploy. + * Format: Hugging Face model ID like `google/gemma-2-2b-it`. + * + * Generated from protobuf field string hugging_face_model_id = 2; + * @param string $var + * @return $this + */ + public function setHuggingFaceModelId($var) + { + GPBUtil::checkString($var, True); + $this->writeOneof(2, $var); + + return $this; + } + + /** + * Required. The resource name of the Location to deploy the model in. + * Format: `projects/{project}/locations/{location}` + * + * Generated from protobuf field string destination = 4 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @return string + */ + public function getDestination() + { + return $this->destination; + } + + /** + * Required. The resource name of the Location to deploy the model in. + * Format: `projects/{project}/locations/{location}` + * + * Generated from protobuf field string destination = 4 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setDestination($var) + { + GPBUtil::checkString($var, True); + $this->destination = $var; + + return $this; + } + + /** + * Optional. The model config to use for the deployment. + * If not specified, the default model config will be used. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.DeployRequest.ModelConfig model_config = 5 [(.google.api.field_behavior) = OPTIONAL]; + * @return \Google\Cloud\AIPlatform\V1\DeployRequest\ModelConfig|null + */ + public function getModelConfig() + { + return $this->model_config; + } + + public function hasModelConfig() + { + return isset($this->model_config); + } + + public function clearModelConfig() + { + unset($this->model_config); + } + + /** + * Optional. The model config to use for the deployment. + * If not specified, the default model config will be used. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.DeployRequest.ModelConfig model_config = 5 [(.google.api.field_behavior) = OPTIONAL]; + * @param \Google\Cloud\AIPlatform\V1\DeployRequest\ModelConfig $var + * @return $this + */ + public function setModelConfig($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\AIPlatform\V1\DeployRequest\ModelConfig::class); + $this->model_config = $var; + + return $this; + } + + /** + * Optional. The endpoint config to use for the deployment. + * If not specified, the default endpoint config will be used. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.DeployRequest.EndpointConfig endpoint_config = 6 [(.google.api.field_behavior) = OPTIONAL]; + * @return \Google\Cloud\AIPlatform\V1\DeployRequest\EndpointConfig|null + */ + public function getEndpointConfig() + { + return $this->endpoint_config; + } + + public function hasEndpointConfig() + { + return isset($this->endpoint_config); + } + + public function clearEndpointConfig() + { + unset($this->endpoint_config); + } + + /** + * Optional. The endpoint config to use for the deployment. + * If not specified, the default endpoint config will be used. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.DeployRequest.EndpointConfig endpoint_config = 6 [(.google.api.field_behavior) = OPTIONAL]; + * @param \Google\Cloud\AIPlatform\V1\DeployRequest\EndpointConfig $var + * @return $this + */ + public function setEndpointConfig($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\AIPlatform\V1\DeployRequest\EndpointConfig::class); + $this->endpoint_config = $var; + + return $this; + } + + /** + * Optional. The deploy config to use for the deployment. + * If not specified, the default deploy config will be used. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.DeployRequest.DeployConfig deploy_config = 7 [(.google.api.field_behavior) = OPTIONAL]; + * @return \Google\Cloud\AIPlatform\V1\DeployRequest\DeployConfig|null + */ + public function getDeployConfig() + { + return $this->deploy_config; + } + + public function hasDeployConfig() + { + return isset($this->deploy_config); + } + + public function clearDeployConfig() + { + unset($this->deploy_config); + } + + /** + * Optional. The deploy config to use for the deployment. + * If not specified, the default deploy config will be used. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.DeployRequest.DeployConfig deploy_config = 7 [(.google.api.field_behavior) = OPTIONAL]; + * @param \Google\Cloud\AIPlatform\V1\DeployRequest\DeployConfig $var + * @return $this + */ + public function setDeployConfig($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\AIPlatform\V1\DeployRequest\DeployConfig::class); + $this->deploy_config = $var; + + return $this; + } + + /** + * @return string + */ + public function getArtifacts() + { + return $this->whichOneof("artifacts"); + } + +} + diff --git a/AiPlatform/src/V1/DeployRequest/DeployConfig.php b/AiPlatform/src/V1/DeployRequest/DeployConfig.php new file mode 100644 index 000000000000..016cc1de8056 --- /dev/null +++ b/AiPlatform/src/V1/DeployRequest/DeployConfig.php @@ -0,0 +1,158 @@ +google.cloud.aiplatform.v1.DeployRequest.DeployConfig + */ +class DeployConfig extends \Google\Protobuf\Internal\Message +{ + /** + * Optional. The dedicated resources to use for the endpoint. If not set, + * the default resources will be used. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.DedicatedResources dedicated_resources = 1 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $dedicated_resources = null; + /** + * Optional. If true, enable the QMT fast tryout feature for this model if + * possible. + * + * Generated from protobuf field bool fast_tryout_enabled = 2 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $fast_tryout_enabled = false; + /** + * Optional. System labels for Model Garden deployments. + * These labels are managed by Google and for tracking purposes only. + * + * Generated from protobuf field map system_labels = 3 [(.google.api.field_behavior) = OPTIONAL]; + */ + private $system_labels; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Cloud\AIPlatform\V1\DedicatedResources $dedicated_resources + * Optional. The dedicated resources to use for the endpoint. If not set, + * the default resources will be used. + * @type bool $fast_tryout_enabled + * Optional. If true, enable the QMT fast tryout feature for this model if + * possible. + * @type array|\Google\Protobuf\Internal\MapField $system_labels + * Optional. System labels for Model Garden deployments. + * These labels are managed by Google and for tracking purposes only. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Aiplatform\V1\ModelGardenService::initOnce(); + parent::__construct($data); + } + + /** + * Optional. The dedicated resources to use for the endpoint. If not set, + * the default resources will be used. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.DedicatedResources dedicated_resources = 1 [(.google.api.field_behavior) = OPTIONAL]; + * @return \Google\Cloud\AIPlatform\V1\DedicatedResources|null + */ + public function getDedicatedResources() + { + return $this->dedicated_resources; + } + + public function hasDedicatedResources() + { + return isset($this->dedicated_resources); + } + + public function clearDedicatedResources() + { + unset($this->dedicated_resources); + } + + /** + * Optional. The dedicated resources to use for the endpoint. If not set, + * the default resources will be used. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.DedicatedResources dedicated_resources = 1 [(.google.api.field_behavior) = OPTIONAL]; + * @param \Google\Cloud\AIPlatform\V1\DedicatedResources $var + * @return $this + */ + public function setDedicatedResources($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\AIPlatform\V1\DedicatedResources::class); + $this->dedicated_resources = $var; + + return $this; + } + + /** + * Optional. If true, enable the QMT fast tryout feature for this model if + * possible. + * + * Generated from protobuf field bool fast_tryout_enabled = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @return bool + */ + public function getFastTryoutEnabled() + { + return $this->fast_tryout_enabled; + } + + /** + * Optional. If true, enable the QMT fast tryout feature for this model if + * possible. + * + * Generated from protobuf field bool fast_tryout_enabled = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @param bool $var + * @return $this + */ + public function setFastTryoutEnabled($var) + { + GPBUtil::checkBool($var); + $this->fast_tryout_enabled = $var; + + return $this; + } + + /** + * Optional. System labels for Model Garden deployments. + * These labels are managed by Google and for tracking purposes only. + * + * Generated from protobuf field map system_labels = 3 [(.google.api.field_behavior) = OPTIONAL]; + * @return \Google\Protobuf\Internal\MapField + */ + public function getSystemLabels() + { + return $this->system_labels; + } + + /** + * Optional. System labels for Model Garden deployments. + * These labels are managed by Google and for tracking purposes only. + * + * Generated from protobuf field map system_labels = 3 [(.google.api.field_behavior) = OPTIONAL]; + * @param array|\Google\Protobuf\Internal\MapField $var + * @return $this + */ + public function setSystemLabels($var) + { + $arr = GPBUtil::checkMapField($var, \Google\Protobuf\Internal\GPBType::STRING, \Google\Protobuf\Internal\GPBType::STRING); + $this->system_labels = $arr; + + return $this; + } + +} + + diff --git a/AiPlatform/src/V1/DeployRequest/EndpointConfig.php b/AiPlatform/src/V1/DeployRequest/EndpointConfig.php new file mode 100644 index 000000000000..8ddb4a98062c --- /dev/null +++ b/AiPlatform/src/V1/DeployRequest/EndpointConfig.php @@ -0,0 +1,126 @@ +google.cloud.aiplatform.v1.DeployRequest.EndpointConfig + */ +class EndpointConfig extends \Google\Protobuf\Internal\Message +{ + /** + * Optional. The user-specified display name of the endpoint. If not set, a + * default name will be used. + * + * Generated from protobuf field string endpoint_display_name = 1 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $endpoint_display_name = ''; + /** + * Optional. If true, the endpoint will be exposed through a dedicated + * DNS [Endpoint.dedicated_endpoint_dns]. Your request to the dedicated DNS + * will be isolated from other users' traffic and will have better + * performance and reliability. Note: Once you enabled dedicated endpoint, + * you won't be able to send request to the shared DNS + * {region}-aiplatform.googleapis.com. The limitations will be removed soon. + * + * Generated from protobuf field bool dedicated_endpoint_enabled = 2 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $dedicated_endpoint_enabled = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $endpoint_display_name + * Optional. The user-specified display name of the endpoint. If not set, a + * default name will be used. + * @type bool $dedicated_endpoint_enabled + * Optional. If true, the endpoint will be exposed through a dedicated + * DNS [Endpoint.dedicated_endpoint_dns]. Your request to the dedicated DNS + * will be isolated from other users' traffic and will have better + * performance and reliability. Note: Once you enabled dedicated endpoint, + * you won't be able to send request to the shared DNS + * {region}-aiplatform.googleapis.com. The limitations will be removed soon. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Aiplatform\V1\ModelGardenService::initOnce(); + parent::__construct($data); + } + + /** + * Optional. The user-specified display name of the endpoint. If not set, a + * default name will be used. + * + * Generated from protobuf field string endpoint_display_name = 1 [(.google.api.field_behavior) = OPTIONAL]; + * @return string + */ + public function getEndpointDisplayName() + { + return $this->endpoint_display_name; + } + + /** + * Optional. The user-specified display name of the endpoint. If not set, a + * default name will be used. + * + * Generated from protobuf field string endpoint_display_name = 1 [(.google.api.field_behavior) = OPTIONAL]; + * @param string $var + * @return $this + */ + public function setEndpointDisplayName($var) + { + GPBUtil::checkString($var, True); + $this->endpoint_display_name = $var; + + return $this; + } + + /** + * Optional. If true, the endpoint will be exposed through a dedicated + * DNS [Endpoint.dedicated_endpoint_dns]. Your request to the dedicated DNS + * will be isolated from other users' traffic and will have better + * performance and reliability. Note: Once you enabled dedicated endpoint, + * you won't be able to send request to the shared DNS + * {region}-aiplatform.googleapis.com. The limitations will be removed soon. + * + * Generated from protobuf field bool dedicated_endpoint_enabled = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @return bool + */ + public function getDedicatedEndpointEnabled() + { + return $this->dedicated_endpoint_enabled; + } + + /** + * Optional. If true, the endpoint will be exposed through a dedicated + * DNS [Endpoint.dedicated_endpoint_dns]. Your request to the dedicated DNS + * will be isolated from other users' traffic and will have better + * performance and reliability. Note: Once you enabled dedicated endpoint, + * you won't be able to send request to the shared DNS + * {region}-aiplatform.googleapis.com. The limitations will be removed soon. + * + * Generated from protobuf field bool dedicated_endpoint_enabled = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @param bool $var + * @return $this + */ + public function setDedicatedEndpointEnabled($var) + { + GPBUtil::checkBool($var); + $this->dedicated_endpoint_enabled = $var; + + return $this; + } + +} + + diff --git a/AiPlatform/src/V1/DeployRequest/ModelConfig.php b/AiPlatform/src/V1/DeployRequest/ModelConfig.php new file mode 100644 index 000000000000..fe5ca85e1f91 --- /dev/null +++ b/AiPlatform/src/V1/DeployRequest/ModelConfig.php @@ -0,0 +1,238 @@ +google.cloud.aiplatform.v1.DeployRequest.ModelConfig + */ +class ModelConfig extends \Google\Protobuf\Internal\Message +{ + /** + * Optional. Whether the user accepts the End User License Agreement (EULA) + * for the model. + * + * Generated from protobuf field bool accept_eula = 1 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $accept_eula = false; + /** + * Optional. The Hugging Face read access token used to access the model + * artifacts of gated models. + * + * Generated from protobuf field string hugging_face_access_token = 2 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $hugging_face_access_token = ''; + /** + * Optional. If true, the model will deploy with a cached version instead of + * directly downloading the model artifacts from Hugging Face. This is + * suitable for VPC-SC users with limited internet access. + * + * Generated from protobuf field bool hugging_face_cache_enabled = 3 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $hugging_face_cache_enabled = false; + /** + * Optional. The user-specified display name of the uploaded model. If not + * set, a default name will be used. + * + * Generated from protobuf field string model_display_name = 4 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $model_display_name = ''; + /** + * Optional. The specification of the container that is to be used when + * deploying. If not set, the default container spec will be used. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.ModelContainerSpec container_spec = 5 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $container_spec = null; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type bool $accept_eula + * Optional. Whether the user accepts the End User License Agreement (EULA) + * for the model. + * @type string $hugging_face_access_token + * Optional. The Hugging Face read access token used to access the model + * artifacts of gated models. + * @type bool $hugging_face_cache_enabled + * Optional. If true, the model will deploy with a cached version instead of + * directly downloading the model artifacts from Hugging Face. This is + * suitable for VPC-SC users with limited internet access. + * @type string $model_display_name + * Optional. The user-specified display name of the uploaded model. If not + * set, a default name will be used. + * @type \Google\Cloud\AIPlatform\V1\ModelContainerSpec $container_spec + * Optional. The specification of the container that is to be used when + * deploying. If not set, the default container spec will be used. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Aiplatform\V1\ModelGardenService::initOnce(); + parent::__construct($data); + } + + /** + * Optional. Whether the user accepts the End User License Agreement (EULA) + * for the model. + * + * Generated from protobuf field bool accept_eula = 1 [(.google.api.field_behavior) = OPTIONAL]; + * @return bool + */ + public function getAcceptEula() + { + return $this->accept_eula; + } + + /** + * Optional. Whether the user accepts the End User License Agreement (EULA) + * for the model. + * + * Generated from protobuf field bool accept_eula = 1 [(.google.api.field_behavior) = OPTIONAL]; + * @param bool $var + * @return $this + */ + public function setAcceptEula($var) + { + GPBUtil::checkBool($var); + $this->accept_eula = $var; + + return $this; + } + + /** + * Optional. The Hugging Face read access token used to access the model + * artifacts of gated models. + * + * Generated from protobuf field string hugging_face_access_token = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @return string + */ + public function getHuggingFaceAccessToken() + { + return $this->hugging_face_access_token; + } + + /** + * Optional. The Hugging Face read access token used to access the model + * artifacts of gated models. + * + * Generated from protobuf field string hugging_face_access_token = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @param string $var + * @return $this + */ + public function setHuggingFaceAccessToken($var) + { + GPBUtil::checkString($var, True); + $this->hugging_face_access_token = $var; + + return $this; + } + + /** + * Optional. If true, the model will deploy with a cached version instead of + * directly downloading the model artifacts from Hugging Face. This is + * suitable for VPC-SC users with limited internet access. + * + * Generated from protobuf field bool hugging_face_cache_enabled = 3 [(.google.api.field_behavior) = OPTIONAL]; + * @return bool + */ + public function getHuggingFaceCacheEnabled() + { + return $this->hugging_face_cache_enabled; + } + + /** + * Optional. If true, the model will deploy with a cached version instead of + * directly downloading the model artifacts from Hugging Face. This is + * suitable for VPC-SC users with limited internet access. + * + * Generated from protobuf field bool hugging_face_cache_enabled = 3 [(.google.api.field_behavior) = OPTIONAL]; + * @param bool $var + * @return $this + */ + public function setHuggingFaceCacheEnabled($var) + { + GPBUtil::checkBool($var); + $this->hugging_face_cache_enabled = $var; + + return $this; + } + + /** + * Optional. The user-specified display name of the uploaded model. If not + * set, a default name will be used. + * + * Generated from protobuf field string model_display_name = 4 [(.google.api.field_behavior) = OPTIONAL]; + * @return string + */ + public function getModelDisplayName() + { + return $this->model_display_name; + } + + /** + * Optional. The user-specified display name of the uploaded model. If not + * set, a default name will be used. + * + * Generated from protobuf field string model_display_name = 4 [(.google.api.field_behavior) = OPTIONAL]; + * @param string $var + * @return $this + */ + public function setModelDisplayName($var) + { + GPBUtil::checkString($var, True); + $this->model_display_name = $var; + + return $this; + } + + /** + * Optional. The specification of the container that is to be used when + * deploying. If not set, the default container spec will be used. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.ModelContainerSpec container_spec = 5 [(.google.api.field_behavior) = OPTIONAL]; + * @return \Google\Cloud\AIPlatform\V1\ModelContainerSpec|null + */ + public function getContainerSpec() + { + return $this->container_spec; + } + + public function hasContainerSpec() + { + return isset($this->container_spec); + } + + public function clearContainerSpec() + { + unset($this->container_spec); + } + + /** + * Optional. The specification of the container that is to be used when + * deploying. If not set, the default container spec will be used. + * + * Generated from protobuf field .google.cloud.aiplatform.v1.ModelContainerSpec container_spec = 5 [(.google.api.field_behavior) = OPTIONAL]; + * @param \Google\Cloud\AIPlatform\V1\ModelContainerSpec $var + * @return $this + */ + public function setContainerSpec($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\AIPlatform\V1\ModelContainerSpec::class); + $this->container_spec = $var; + + return $this; + } + +} + + diff --git a/AiPlatform/src/V1/DeployResponse.php b/AiPlatform/src/V1/DeployResponse.php new file mode 100644 index 000000000000..aaaec11c4a6e --- /dev/null +++ b/AiPlatform/src/V1/DeployResponse.php @@ -0,0 +1,156 @@ +google.cloud.aiplatform.v1.DeployResponse + */ +class DeployResponse extends \Google\Protobuf\Internal\Message +{ + /** + * Output only. The name of the PublisherModel resource. + * Format: + * `publishers/{publisher}/models/{publisher_model}@{version_id}`, or + * `publishers/hf-{hugging-face-author}/models/{hugging-face-model-name}@001` + * + * Generated from protobuf field string publisher_model = 1 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { + */ + protected $publisher_model = ''; + /** + * Output only. The name of the Endpoint created. + * Format: `projects/{project}/locations/{location}/endpoints/{endpoint}` + * + * Generated from protobuf field string endpoint = 2 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { + */ + protected $endpoint = ''; + /** + * Output only. The name of the Model created. + * Format: `projects/{project}/locations/{location}/models/{model}` + * + * Generated from protobuf field string model = 3 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { + */ + protected $model = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $publisher_model + * Output only. The name of the PublisherModel resource. + * Format: + * `publishers/{publisher}/models/{publisher_model}@{version_id}`, or + * `publishers/hf-{hugging-face-author}/models/{hugging-face-model-name}@001` + * @type string $endpoint + * Output only. The name of the Endpoint created. + * Format: `projects/{project}/locations/{location}/endpoints/{endpoint}` + * @type string $model + * Output only. The name of the Model created. + * Format: `projects/{project}/locations/{location}/models/{model}` + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Aiplatform\V1\ModelGardenService::initOnce(); + parent::__construct($data); + } + + /** + * Output only. The name of the PublisherModel resource. + * Format: + * `publishers/{publisher}/models/{publisher_model}@{version_id}`, or + * `publishers/hf-{hugging-face-author}/models/{hugging-face-model-name}@001` + * + * Generated from protobuf field string publisher_model = 1 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { + * @return string + */ + public function getPublisherModel() + { + return $this->publisher_model; + } + + /** + * Output only. The name of the PublisherModel resource. + * Format: + * `publishers/{publisher}/models/{publisher_model}@{version_id}`, or + * `publishers/hf-{hugging-face-author}/models/{hugging-face-model-name}@001` + * + * Generated from protobuf field string publisher_model = 1 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setPublisherModel($var) + { + GPBUtil::checkString($var, True); + $this->publisher_model = $var; + + return $this; + } + + /** + * Output only. The name of the Endpoint created. + * Format: `projects/{project}/locations/{location}/endpoints/{endpoint}` + * + * Generated from protobuf field string endpoint = 2 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { + * @return string + */ + public function getEndpoint() + { + return $this->endpoint; + } + + /** + * Output only. The name of the Endpoint created. + * Format: `projects/{project}/locations/{location}/endpoints/{endpoint}` + * + * Generated from protobuf field string endpoint = 2 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setEndpoint($var) + { + GPBUtil::checkString($var, True); + $this->endpoint = $var; + + return $this; + } + + /** + * Output only. The name of the Model created. + * Format: `projects/{project}/locations/{location}/models/{model}` + * + * Generated from protobuf field string model = 3 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { + * @return string + */ + public function getModel() + { + return $this->model; + } + + /** + * Output only. The name of the Model created. + * Format: `projects/{project}/locations/{location}/models/{model}` + * + * Generated from protobuf field string model = 3 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setModel($var) + { + GPBUtil::checkString($var, True); + $this->model = $var; + + return $this; + } + +} + diff --git a/AiPlatform/src/V1/gapic_metadata.json b/AiPlatform/src/V1/gapic_metadata.json index 79ae04635b5c..ac6ead23c67f 100644 --- a/AiPlatform/src/V1/gapic_metadata.json +++ b/AiPlatform/src/V1/gapic_metadata.json @@ -1636,6 +1636,11 @@ "grpc": { "libraryClient": "ModelGardenServiceGapicClient", "rpcs": { + "Deploy": { + "methods": [ + "deploy" + ] + }, "GetPublisherModel": { "methods": [ "getPublisherModel" diff --git a/AiPlatform/src/V1/resources/model_garden_service_client_config.json b/AiPlatform/src/V1/resources/model_garden_service_client_config.json index 31f470f9158c..4b3b9fab1f09 100644 --- a/AiPlatform/src/V1/resources/model_garden_service_client_config.json +++ b/AiPlatform/src/V1/resources/model_garden_service_client_config.json @@ -16,6 +16,11 @@ } }, "methods": { + "Deploy": { + "timeout_millis": 60000, + "retry_codes_name": "no_retry_codes", + "retry_params_name": "no_retry_params" + }, "GetPublisherModel": { "timeout_millis": 60000, "retry_codes_name": "no_retry_codes", diff --git a/AiPlatform/src/V1/resources/model_garden_service_descriptor_config.php b/AiPlatform/src/V1/resources/model_garden_service_descriptor_config.php index 20822a5b1b2d..e2b7daa2fcd9 100644 --- a/AiPlatform/src/V1/resources/model_garden_service_descriptor_config.php +++ b/AiPlatform/src/V1/resources/model_garden_service_descriptor_config.php @@ -23,6 +23,25 @@ return [ 'interfaces' => [ 'google.cloud.aiplatform.v1.ModelGardenService' => [ + 'Deploy' => [ + 'longRunning' => [ + 'operationReturnType' => '\Google\Cloud\AIPlatform\V1\DeployResponse', + 'metadataReturnType' => '\Google\Cloud\AIPlatform\V1\DeployOperationMetadata', + 'initialPollDelayMillis' => '500', + 'pollDelayMultiplier' => '1.5', + 'maxPollDelayMillis' => '5000', + 'totalPollTimeoutMillis' => '300000', + ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'destination', + 'fieldAccessors' => [ + 'getDestination', + ], + ], + ], + ], 'GetPublisherModel' => [ 'callType' => \Google\ApiCore\Call::UNARY_CALL, 'responseType' => 'Google\Cloud\AIPlatform\V1\PublisherModel', @@ -109,7 +128,9 @@ 'interfaceOverride' => 'google.iam.v1.IAMPolicy', ], 'templateMap' => [ + 'location' => 'projects/{project}/locations/{location}', 'publisherModel' => 'publishers/{publisher}/models/{model}', + 'reservation' => 'projects/{project_id_or_number}/zones/{zone}/reservations/{reservation_name}', ], ], ], diff --git a/AiPlatform/src/V1/resources/model_garden_service_rest_client_config.php b/AiPlatform/src/V1/resources/model_garden_service_rest_client_config.php index 0f5eea183fb7..c9f247a352b0 100644 --- a/AiPlatform/src/V1/resources/model_garden_service_rest_client_config.php +++ b/AiPlatform/src/V1/resources/model_garden_service_rest_client_config.php @@ -23,6 +23,18 @@ return [ 'interfaces' => [ 'google.cloud.aiplatform.v1.ModelGardenService' => [ + 'Deploy' => [ + 'method' => 'post', + 'uriTemplate' => '/v1/{destination=projects/*/locations/*}:deploy', + 'body' => '*', + 'placeholders' => [ + 'destination' => [ + 'getters' => [ + 'getDestination', + ], + ], + ], + ], 'GetPublisherModel' => [ 'method' => 'get', 'uriTemplate' => '/v1/{name=publishers/*/models/*}', diff --git a/AiPlatform/tests/Unit/V1/Client/ModelGardenServiceClientTest.php b/AiPlatform/tests/Unit/V1/Client/ModelGardenServiceClientTest.php index 330de89e4e88..06d13f7bf4ff 100644 --- a/AiPlatform/tests/Unit/V1/Client/ModelGardenServiceClientTest.php +++ b/AiPlatform/tests/Unit/V1/Client/ModelGardenServiceClientTest.php @@ -27,6 +27,8 @@ use Google\ApiCore\Testing\GeneratedTest; use Google\ApiCore\Testing\MockTransport; use Google\Cloud\AIPlatform\V1\Client\ModelGardenServiceClient; +use Google\Cloud\AIPlatform\V1\DeployRequest; +use Google\Cloud\AIPlatform\V1\DeployResponse; use Google\Cloud\AIPlatform\V1\GetPublisherModelRequest; use Google\Cloud\AIPlatform\V1\PublisherModel; use Google\Cloud\Iam\V1\GetIamPolicyRequest; @@ -38,6 +40,10 @@ use Google\Cloud\Location\ListLocationsRequest; use Google\Cloud\Location\ListLocationsResponse; use Google\Cloud\Location\Location; +use Google\LongRunning\Client\OperationsClient; +use Google\LongRunning\GetOperationRequest; +use Google\LongRunning\Operation; +use Google\Protobuf\Any; use Google\Rpc\Code; use stdClass; @@ -71,6 +77,134 @@ private function createClient(array $options = []) return new ModelGardenServiceClient($options); } + /** @test */ + public function deployTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deployTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $publisherModel = 'publisherModel1421579046'; + $endpoint = 'endpoint1741102485'; + $model = 'model104069929'; + $expectedResponse = new DeployResponse(); + $expectedResponse->setPublisherModel($publisherModel); + $expectedResponse->setEndpoint($endpoint); + $expectedResponse->setModel($model); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deployTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedDestination = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new DeployRequest())->setDestination($formattedDestination); + $response = $gapicClient->deploy($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.aiplatform.v1.ModelGardenService/Deploy', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getDestination(); + $this->assertProtobufEquals($formattedDestination, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deployTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deployExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deployTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); + $operationsTransport->addResponse(null, $status); + // Mock request + $formattedDestination = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new DeployRequest())->setDestination($formattedDestination); + $response = $gapicClient->deploy($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deployTest'); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + /** @test */ public function getPublisherModelTest() { @@ -474,34 +608,71 @@ public function testIamPermissionsExceptionTest() } /** @test */ - public function getPublisherModelAsyncTest() + public function deployAsyncTest() { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); $transport = $this->createTransport(); $gapicClient = $this->createClient([ 'transport' => $transport, + 'operationsClient' => $operationsClient, ]); $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); // Mock response - $name2 = 'name2-1052831874'; - $versionId = 'versionId-670497310'; - $publisherModelTemplate = 'publisherModelTemplate-215968397'; - $expectedResponse = new PublisherModel(); - $expectedResponse->setName($name2); - $expectedResponse->setVersionId($versionId); - $expectedResponse->setPublisherModelTemplate($publisherModelTemplate); - $transport->addResponse($expectedResponse); + $incompleteOperation = new Operation(); + $incompleteOperation->setName('operations/deployTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $publisherModel = 'publisherModel1421579046'; + $endpoint = 'endpoint1741102485'; + $model = 'model104069929'; + $expectedResponse = new DeployResponse(); + $expectedResponse->setPublisherModel($publisherModel); + $expectedResponse->setEndpoint($endpoint); + $expectedResponse->setModel($model); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deployTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); // Mock request - $formattedName = $gapicClient->publisherModelName('[PUBLISHER]', '[MODEL]'); - $request = (new GetPublisherModelRequest())->setName($formattedName); - $response = $gapicClient->getPublisherModelAsync($request)->wait(); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.aiplatform.v1.ModelGardenService/GetPublisherModel', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); + $formattedDestination = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new DeployRequest())->setDestination($formattedDestination); + $response = $gapicClient->deployAsync($request)->wait(); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.aiplatform.v1.ModelGardenService/Deploy', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getDestination(); + $this->assertProtobufEquals($formattedDestination, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deployTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); } }