cloud.google.com/go/aiplatform@v1.106.0/apiv1/deployment_resource_pool_client_example_test.go (about) 1 // Copyright 2025 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Code generated by protoc-gen-go_gapic. DO NOT EDIT. 16 17 package aiplatform_test 18 19 import ( 20 "context" 21 22 aiplatform "cloud.google.com/go/aiplatform/apiv1" 23 aiplatformpb "cloud.google.com/go/aiplatform/apiv1/aiplatformpb" 24 iampb "cloud.google.com/go/iam/apiv1/iampb" 25 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" 26 "google.golang.org/api/iterator" 27 locationpb "google.golang.org/genproto/googleapis/cloud/location" 28 ) 29 30 func ExampleNewDeploymentResourcePoolClient() { 31 ctx := context.Background() 32 // This snippet has been automatically generated and should be regarded as a code template only. 33 // It will require modifications to work: 34 // - It may require correct/in-range values for request initialization. 35 // - It may require specifying regional endpoints when creating the service client as shown in: 36 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 37 c, err := aiplatform.NewDeploymentResourcePoolClient(ctx) 38 if err != nil { 39 // TODO: Handle error. 40 } 41 defer c.Close() 42 43 // TODO: Use client. 44 _ = c 45 } 46 47 func ExampleDeploymentResourcePoolClient_CreateDeploymentResourcePool() { 48 ctx := context.Background() 49 // This snippet has been automatically generated and should be regarded as a code template only. 50 // It will require modifications to work: 51 // - It may require correct/in-range values for request initialization. 52 // - It may require specifying regional endpoints when creating the service client as shown in: 53 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 54 c, err := aiplatform.NewDeploymentResourcePoolClient(ctx) 55 if err != nil { 56 // TODO: Handle error. 57 } 58 defer c.Close() 59 60 req := &aiplatformpb.CreateDeploymentResourcePoolRequest{ 61 // TODO: Fill request struct fields. 62 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#CreateDeploymentResourcePoolRequest. 63 } 64 op, err := c.CreateDeploymentResourcePool(ctx, req) 65 if err != nil { 66 // TODO: Handle error. 67 } 68 69 resp, err := op.Wait(ctx) 70 if err != nil { 71 // TODO: Handle error. 72 } 73 // TODO: Use resp. 74 _ = resp 75 } 76 77 func ExampleDeploymentResourcePoolClient_DeleteDeploymentResourcePool() { 78 ctx := context.Background() 79 // This snippet has been automatically generated and should be regarded as a code template only. 80 // It will require modifications to work: 81 // - It may require correct/in-range values for request initialization. 82 // - It may require specifying regional endpoints when creating the service client as shown in: 83 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 84 c, err := aiplatform.NewDeploymentResourcePoolClient(ctx) 85 if err != nil { 86 // TODO: Handle error. 87 } 88 defer c.Close() 89 90 req := &aiplatformpb.DeleteDeploymentResourcePoolRequest{ 91 // TODO: Fill request struct fields. 92 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#DeleteDeploymentResourcePoolRequest. 93 } 94 op, err := c.DeleteDeploymentResourcePool(ctx, req) 95 if err != nil { 96 // TODO: Handle error. 97 } 98 99 err = op.Wait(ctx) 100 if err != nil { 101 // TODO: Handle error. 102 } 103 } 104 105 func ExampleDeploymentResourcePoolClient_GetDeploymentResourcePool() { 106 ctx := context.Background() 107 // This snippet has been automatically generated and should be regarded as a code template only. 108 // It will require modifications to work: 109 // - It may require correct/in-range values for request initialization. 110 // - It may require specifying regional endpoints when creating the service client as shown in: 111 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 112 c, err := aiplatform.NewDeploymentResourcePoolClient(ctx) 113 if err != nil { 114 // TODO: Handle error. 115 } 116 defer c.Close() 117 118 req := &aiplatformpb.GetDeploymentResourcePoolRequest{ 119 // TODO: Fill request struct fields. 120 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#GetDeploymentResourcePoolRequest. 121 } 122 resp, err := c.GetDeploymentResourcePool(ctx, req) 123 if err != nil { 124 // TODO: Handle error. 125 } 126 // TODO: Use resp. 127 _ = resp 128 } 129 130 func ExampleDeploymentResourcePoolClient_ListDeploymentResourcePools() { 131 ctx := context.Background() 132 // This snippet has been automatically generated and should be regarded as a code template only. 133 // It will require modifications to work: 134 // - It may require correct/in-range values for request initialization. 135 // - It may require specifying regional endpoints when creating the service client as shown in: 136 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 137 c, err := aiplatform.NewDeploymentResourcePoolClient(ctx) 138 if err != nil { 139 // TODO: Handle error. 140 } 141 defer c.Close() 142 143 req := &aiplatformpb.ListDeploymentResourcePoolsRequest{ 144 // TODO: Fill request struct fields. 145 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#ListDeploymentResourcePoolsRequest. 146 } 147 it := c.ListDeploymentResourcePools(ctx, req) 148 for { 149 resp, err := it.Next() 150 if err == iterator.Done { 151 break 152 } 153 if err != nil { 154 // TODO: Handle error. 155 } 156 // TODO: Use resp. 157 _ = resp 158 159 // If you need to access the underlying RPC response, 160 // you can do so by casting the `Response` as below. 161 // Otherwise, remove this line. Only populated after 162 // first call to Next(). Not safe for concurrent access. 163 _ = it.Response.(*aiplatformpb.ListDeploymentResourcePoolsResponse) 164 } 165 } 166 167 func ExampleDeploymentResourcePoolClient_QueryDeployedModels() { 168 ctx := context.Background() 169 // This snippet has been automatically generated and should be regarded as a code template only. 170 // It will require modifications to work: 171 // - It may require correct/in-range values for request initialization. 172 // - It may require specifying regional endpoints when creating the service client as shown in: 173 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 174 c, err := aiplatform.NewDeploymentResourcePoolClient(ctx) 175 if err != nil { 176 // TODO: Handle error. 177 } 178 defer c.Close() 179 180 req := &aiplatformpb.QueryDeployedModelsRequest{ 181 // TODO: Fill request struct fields. 182 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#QueryDeployedModelsRequest. 183 } 184 it := c.QueryDeployedModels(ctx, req) 185 for { 186 resp, err := it.Next() 187 if err == iterator.Done { 188 break 189 } 190 if err != nil { 191 // TODO: Handle error. 192 } 193 // TODO: Use resp. 194 _ = resp 195 196 // If you need to access the underlying RPC response, 197 // you can do so by casting the `Response` as below. 198 // Otherwise, remove this line. Only populated after 199 // first call to Next(). Not safe for concurrent access. 200 _ = it.Response.(*aiplatformpb.QueryDeployedModelsResponse) 201 } 202 } 203 204 func ExampleDeploymentResourcePoolClient_UpdateDeploymentResourcePool() { 205 ctx := context.Background() 206 // This snippet has been automatically generated and should be regarded as a code template only. 207 // It will require modifications to work: 208 // - It may require correct/in-range values for request initialization. 209 // - It may require specifying regional endpoints when creating the service client as shown in: 210 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 211 c, err := aiplatform.NewDeploymentResourcePoolClient(ctx) 212 if err != nil { 213 // TODO: Handle error. 214 } 215 defer c.Close() 216 217 req := &aiplatformpb.UpdateDeploymentResourcePoolRequest{ 218 // TODO: Fill request struct fields. 219 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#UpdateDeploymentResourcePoolRequest. 220 } 221 op, err := c.UpdateDeploymentResourcePool(ctx, req) 222 if err != nil { 223 // TODO: Handle error. 224 } 225 226 resp, err := op.Wait(ctx) 227 if err != nil { 228 // TODO: Handle error. 229 } 230 // TODO: Use resp. 231 _ = resp 232 } 233 234 func ExampleDeploymentResourcePoolClient_GetLocation() { 235 ctx := context.Background() 236 // This snippet has been automatically generated and should be regarded as a code template only. 237 // It will require modifications to work: 238 // - It may require correct/in-range values for request initialization. 239 // - It may require specifying regional endpoints when creating the service client as shown in: 240 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 241 c, err := aiplatform.NewDeploymentResourcePoolClient(ctx) 242 if err != nil { 243 // TODO: Handle error. 244 } 245 defer c.Close() 246 247 req := &locationpb.GetLocationRequest{ 248 // TODO: Fill request struct fields. 249 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest. 250 } 251 resp, err := c.GetLocation(ctx, req) 252 if err != nil { 253 // TODO: Handle error. 254 } 255 // TODO: Use resp. 256 _ = resp 257 } 258 259 func ExampleDeploymentResourcePoolClient_ListLocations() { 260 ctx := context.Background() 261 // This snippet has been automatically generated and should be regarded as a code template only. 262 // It will require modifications to work: 263 // - It may require correct/in-range values for request initialization. 264 // - It may require specifying regional endpoints when creating the service client as shown in: 265 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 266 c, err := aiplatform.NewDeploymentResourcePoolClient(ctx) 267 if err != nil { 268 // TODO: Handle error. 269 } 270 defer c.Close() 271 272 req := &locationpb.ListLocationsRequest{ 273 // TODO: Fill request struct fields. 274 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest. 275 } 276 it := c.ListLocations(ctx, req) 277 for { 278 resp, err := it.Next() 279 if err == iterator.Done { 280 break 281 } 282 if err != nil { 283 // TODO: Handle error. 284 } 285 // TODO: Use resp. 286 _ = resp 287 288 // If you need to access the underlying RPC response, 289 // you can do so by casting the `Response` as below. 290 // Otherwise, remove this line. Only populated after 291 // first call to Next(). Not safe for concurrent access. 292 _ = it.Response.(*locationpb.ListLocationsResponse) 293 } 294 } 295 296 func ExampleDeploymentResourcePoolClient_GetIamPolicy() { 297 ctx := context.Background() 298 // This snippet has been automatically generated and should be regarded as a code template only. 299 // It will require modifications to work: 300 // - It may require correct/in-range values for request initialization. 301 // - It may require specifying regional endpoints when creating the service client as shown in: 302 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 303 c, err := aiplatform.NewDeploymentResourcePoolClient(ctx) 304 if err != nil { 305 // TODO: Handle error. 306 } 307 defer c.Close() 308 309 req := &iampb.GetIamPolicyRequest{ 310 // TODO: Fill request struct fields. 311 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest. 312 } 313 resp, err := c.GetIamPolicy(ctx, req) 314 if err != nil { 315 // TODO: Handle error. 316 } 317 // TODO: Use resp. 318 _ = resp 319 } 320 321 func ExampleDeploymentResourcePoolClient_SetIamPolicy() { 322 ctx := context.Background() 323 // This snippet has been automatically generated and should be regarded as a code template only. 324 // It will require modifications to work: 325 // - It may require correct/in-range values for request initialization. 326 // - It may require specifying regional endpoints when creating the service client as shown in: 327 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 328 c, err := aiplatform.NewDeploymentResourcePoolClient(ctx) 329 if err != nil { 330 // TODO: Handle error. 331 } 332 defer c.Close() 333 334 req := &iampb.SetIamPolicyRequest{ 335 // TODO: Fill request struct fields. 336 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest. 337 } 338 resp, err := c.SetIamPolicy(ctx, req) 339 if err != nil { 340 // TODO: Handle error. 341 } 342 // TODO: Use resp. 343 _ = resp 344 } 345 346 func ExampleDeploymentResourcePoolClient_TestIamPermissions() { 347 ctx := context.Background() 348 // This snippet has been automatically generated and should be regarded as a code template only. 349 // It will require modifications to work: 350 // - It may require correct/in-range values for request initialization. 351 // - It may require specifying regional endpoints when creating the service client as shown in: 352 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 353 c, err := aiplatform.NewDeploymentResourcePoolClient(ctx) 354 if err != nil { 355 // TODO: Handle error. 356 } 357 defer c.Close() 358 359 req := &iampb.TestIamPermissionsRequest{ 360 // TODO: Fill request struct fields. 361 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest. 362 } 363 resp, err := c.TestIamPermissions(ctx, req) 364 if err != nil { 365 // TODO: Handle error. 366 } 367 // TODO: Use resp. 368 _ = resp 369 } 370 371 func ExampleDeploymentResourcePoolClient_CancelOperation() { 372 ctx := context.Background() 373 // This snippet has been automatically generated and should be regarded as a code template only. 374 // It will require modifications to work: 375 // - It may require correct/in-range values for request initialization. 376 // - It may require specifying regional endpoints when creating the service client as shown in: 377 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 378 c, err := aiplatform.NewDeploymentResourcePoolClient(ctx) 379 if err != nil { 380 // TODO: Handle error. 381 } 382 defer c.Close() 383 384 req := &longrunningpb.CancelOperationRequest{ 385 // TODO: Fill request struct fields. 386 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest. 387 } 388 err = c.CancelOperation(ctx, req) 389 if err != nil { 390 // TODO: Handle error. 391 } 392 } 393 394 func ExampleDeploymentResourcePoolClient_DeleteOperation() { 395 ctx := context.Background() 396 // This snippet has been automatically generated and should be regarded as a code template only. 397 // It will require modifications to work: 398 // - It may require correct/in-range values for request initialization. 399 // - It may require specifying regional endpoints when creating the service client as shown in: 400 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 401 c, err := aiplatform.NewDeploymentResourcePoolClient(ctx) 402 if err != nil { 403 // TODO: Handle error. 404 } 405 defer c.Close() 406 407 req := &longrunningpb.DeleteOperationRequest{ 408 // TODO: Fill request struct fields. 409 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest. 410 } 411 err = c.DeleteOperation(ctx, req) 412 if err != nil { 413 // TODO: Handle error. 414 } 415 } 416 417 func ExampleDeploymentResourcePoolClient_GetOperation() { 418 ctx := context.Background() 419 // This snippet has been automatically generated and should be regarded as a code template only. 420 // It will require modifications to work: 421 // - It may require correct/in-range values for request initialization. 422 // - It may require specifying regional endpoints when creating the service client as shown in: 423 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 424 c, err := aiplatform.NewDeploymentResourcePoolClient(ctx) 425 if err != nil { 426 // TODO: Handle error. 427 } 428 defer c.Close() 429 430 req := &longrunningpb.GetOperationRequest{ 431 // TODO: Fill request struct fields. 432 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest. 433 } 434 resp, err := c.GetOperation(ctx, req) 435 if err != nil { 436 // TODO: Handle error. 437 } 438 // TODO: Use resp. 439 _ = resp 440 } 441 442 func ExampleDeploymentResourcePoolClient_ListOperations() { 443 ctx := context.Background() 444 // This snippet has been automatically generated and should be regarded as a code template only. 445 // It will require modifications to work: 446 // - It may require correct/in-range values for request initialization. 447 // - It may require specifying regional endpoints when creating the service client as shown in: 448 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 449 c, err := aiplatform.NewDeploymentResourcePoolClient(ctx) 450 if err != nil { 451 // TODO: Handle error. 452 } 453 defer c.Close() 454 455 req := &longrunningpb.ListOperationsRequest{ 456 // TODO: Fill request struct fields. 457 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest. 458 } 459 it := c.ListOperations(ctx, req) 460 for { 461 resp, err := it.Next() 462 if err == iterator.Done { 463 break 464 } 465 if err != nil { 466 // TODO: Handle error. 467 } 468 // TODO: Use resp. 469 _ = resp 470 471 // If you need to access the underlying RPC response, 472 // you can do so by casting the `Response` as below. 473 // Otherwise, remove this line. Only populated after 474 // first call to Next(). Not safe for concurrent access. 475 _ = it.Response.(*longrunningpb.ListOperationsResponse) 476 } 477 } 478 479 func ExampleDeploymentResourcePoolClient_WaitOperation() { 480 ctx := context.Background() 481 // This snippet has been automatically generated and should be regarded as a code template only. 482 // It will require modifications to work: 483 // - It may require correct/in-range values for request initialization. 484 // - It may require specifying regional endpoints when creating the service client as shown in: 485 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 486 c, err := aiplatform.NewDeploymentResourcePoolClient(ctx) 487 if err != nil { 488 // TODO: Handle error. 489 } 490 defer c.Close() 491 492 req := &longrunningpb.WaitOperationRequest{ 493 // TODO: Fill request struct fields. 494 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#WaitOperationRequest. 495 } 496 resp, err := c.WaitOperation(ctx, req) 497 if err != nil { 498 // TODO: Handle error. 499 } 500 // TODO: Use resp. 501 _ = resp 502 }