2727use Google \ApiCore \ApiException ;
2828use Google \ApiCore \CredentialsWrapper ;
2929use Google \ApiCore \GapicClientTrait ;
30+ use Google \ApiCore \OperationResponse ;
3031use Google \ApiCore \PagedListResponse ;
3132use Google \ApiCore \ResourceHelperTrait ;
3233use Google \ApiCore \RetrySettings ;
3334use Google \ApiCore \Transport \TransportInterface ;
3435use Google \ApiCore \ValidationException ;
3536use Google \Auth \FetchAuthTokenInterface ;
37+ use Google \Cloud \AIPlatform \V1 \DeployRequest ;
3638use Google \Cloud \AIPlatform \V1 \GetPublisherModelRequest ;
3739use Google \Cloud \AIPlatform \V1 \PublisherModel ;
3840use Google \Cloud \Iam \V1 \GetIamPolicyRequest ;
4345use Google \Cloud \Location \GetLocationRequest ;
4446use Google \Cloud \Location \ListLocationsRequest ;
4547use Google \Cloud \Location \Location ;
48+ use Google \LongRunning \Client \OperationsClient ;
49+ use Google \LongRunning \Operation ;
4650use GuzzleHttp \Promise \PromiseInterface ;
4751use Psr \Log \LoggerInterface ;
4852
5761 * name, and additionally a parseName method to extract the individual identifiers
5862 * contained within formatted names that are returned by the API.
5963 *
64+ * @method PromiseInterface<OperationResponse> deployAsync(DeployRequest $request, array $optionalArgs = [])
6065 * @method PromiseInterface<PublisherModel> getPublisherModelAsync(GetPublisherModelRequest $request, array $optionalArgs = [])
6166 * @method PromiseInterface<Location> getLocationAsync(GetLocationRequest $request, array $optionalArgs = [])
6267 * @method PromiseInterface<PagedListResponse> listLocationsAsync(ListLocationsRequest $request, array $optionalArgs = [])
@@ -91,6 +96,8 @@ final class ModelGardenServiceClient
9196 /** The default scopes required by the service. */
9297 public static $ serviceScopes = ['https://www.googleapis.com/auth/cloud-platform ' ];
9398
99+ private $ operationsClient ;
100+
94101 private static function getClientDefaults ()
95102 {
96103 return [
@@ -110,6 +117,73 @@ private static function getClientDefaults()
110117 ];
111118 }
112119
120+ /**
121+ * Return an OperationsClient object with the same endpoint as $this.
122+ *
123+ * @return OperationsClient
124+ */
125+ public function getOperationsClient ()
126+ {
127+ return $ this ->operationsClient ;
128+ }
129+
130+ /**
131+ * Resume an existing long running operation that was previously started by a long
132+ * running API method. If $methodName is not provided, or does not match a long
133+ * running API method, then the operation can still be resumed, but the
134+ * OperationResponse object will not deserialize the final response.
135+ *
136+ * @param string $operationName The name of the long running operation
137+ * @param string $methodName The name of the method used to start the operation
138+ *
139+ * @return OperationResponse
140+ */
141+ public function resumeOperation ($ operationName , $ methodName = null )
142+ {
143+ $ options = isset ($ this ->descriptors [$ methodName ]['longRunning ' ])
144+ ? $ this ->descriptors [$ methodName ]['longRunning ' ]
145+ : [];
146+ $ operation = new OperationResponse ($ operationName , $ this ->getOperationsClient (), $ options );
147+ $ operation ->reload ();
148+ return $ operation ;
149+ }
150+
151+ /**
152+ * Create the default operation client for the service.
153+ *
154+ * @param array $options ClientOptions for the client.
155+ *
156+ * @return OperationsClient
157+ */
158+ private function createOperationsClient (array $ options )
159+ {
160+ // Unset client-specific configuration options
161+ unset($ options ['serviceName ' ], $ options ['clientConfig ' ], $ options ['descriptorsConfigPath ' ]);
162+
163+ if (isset ($ options ['operationsClient ' ])) {
164+ return $ options ['operationsClient ' ];
165+ }
166+
167+ return new OperationsClient ($ options );
168+ }
169+
170+ /**
171+ * Formats a string containing the fully-qualified path to represent a location
172+ * resource.
173+ *
174+ * @param string $project
175+ * @param string $location
176+ *
177+ * @return string The formatted location resource.
178+ */
179+ public static function locationName (string $ project , string $ location ): string
180+ {
181+ return self ::getPathTemplate ('location ' )->render ([
182+ 'project ' => $ project ,
183+ 'location ' => $ location ,
184+ ]);
185+ }
186+
113187 /**
114188 * Formats a string containing the fully-qualified path to represent a
115189 * publisher_model resource.
@@ -127,11 +201,32 @@ public static function publisherModelName(string $publisher, string $model): str
127201 ]);
128202 }
129203
204+ /**
205+ * Formats a string containing the fully-qualified path to represent a reservation
206+ * resource.
207+ *
208+ * @param string $projectIdOrNumber
209+ * @param string $zone
210+ * @param string $reservationName
211+ *
212+ * @return string The formatted reservation resource.
213+ */
214+ public static function reservationName (string $ projectIdOrNumber , string $ zone , string $ reservationName ): string
215+ {
216+ return self ::getPathTemplate ('reservation ' )->render ([
217+ 'project_id_or_number ' => $ projectIdOrNumber ,
218+ 'zone ' => $ zone ,
219+ 'reservation_name ' => $ reservationName ,
220+ ]);
221+ }
222+
130223 /**
131224 * Parses a formatted name string and returns an associative array of the components in the name.
132225 * The following name formats are supported:
133226 * Template: Pattern
227+ * - location: projects/{project}/locations/{location}
134228 * - publisherModel: publishers/{publisher}/models/{model}
229+ * - reservation: projects/{project_id_or_number}/zones/{zone}/reservations/{reservation_name}
135230 *
136231 * The optional $template argument can be supplied to specify a particular pattern,
137232 * and must match one of the templates listed above. If no $template argument is
@@ -218,6 +313,7 @@ public function __construct(array $options = [])
218313 {
219314 $ clientOptions = $ this ->buildClientOptions ($ options );
220315 $ this ->setClientOptions ($ clientOptions );
316+ $ this ->operationsClient = $ this ->createOperationsClient ($ clientOptions );
221317 }
222318
223319 /** Handles execution of the async variants for each documented method. */
@@ -231,6 +327,32 @@ public function __call($method, $args)
231327 return call_user_func_array ([$ this , 'startAsyncCall ' ], $ args );
232328 }
233329
330+ /**
331+ * Deploys a model to a new endpoint.
332+ *
333+ * The async variant is {@see ModelGardenServiceClient::deployAsync()} .
334+ *
335+ * @example samples/V1/ModelGardenServiceClient/deploy.php
336+ *
337+ * @param DeployRequest $request A request to house fields associated with the call.
338+ * @param array $callOptions {
339+ * Optional.
340+ *
341+ * @type RetrySettings|array $retrySettings
342+ * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an
343+ * associative array of retry settings parameters. See the documentation on
344+ * {@see RetrySettings} for example usage.
345+ * }
346+ *
347+ * @return OperationResponse
348+ *
349+ * @throws ApiException Thrown if the API call fails.
350+ */
351+ public function deploy (DeployRequest $ request , array $ callOptions = []): OperationResponse
352+ {
353+ return $ this ->startApiCall ('Deploy ' , $ request , $ callOptions )->wait ();
354+ }
355+
234356 /**
235357 * Gets a Model Garden publisher model.
236358 *
0 commit comments