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