cloud.google.com/go/aiplatform@v1.106.0/apiv1beta1/persistent_resource_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 ExampleNewPersistentResourceClient() {
    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.NewPersistentResourceClient(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 ExampleNewPersistentResourceRESTClient() {
    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.NewPersistentResourceRESTClient(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 ExamplePersistentResourceClient_CreatePersistentResource() {
    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.NewPersistentResourceClient(ctx)
    72  	if err != nil {
    73  		// TODO: Handle error.
    74  	}
    75  	defer c.Close()
    76  
    77  	req := &aiplatformpb.CreatePersistentResourceRequest{
    78  		// TODO: Fill request struct fields.
    79  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#CreatePersistentResourceRequest.
    80  	}
    81  	op, err := c.CreatePersistentResource(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 ExamplePersistentResourceClient_DeletePersistentResource() {
    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.NewPersistentResourceClient(ctx)
   102  	if err != nil {
   103  		// TODO: Handle error.
   104  	}
   105  	defer c.Close()
   106  
   107  	req := &aiplatformpb.DeletePersistentResourceRequest{
   108  		// TODO: Fill request struct fields.
   109  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#DeletePersistentResourceRequest.
   110  	}
   111  	op, err := c.DeletePersistentResource(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 ExamplePersistentResourceClient_GetPersistentResource() {
   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.NewPersistentResourceClient(ctx)
   130  	if err != nil {
   131  		// TODO: Handle error.
   132  	}
   133  	defer c.Close()
   134  
   135  	req := &aiplatformpb.GetPersistentResourceRequest{
   136  		// TODO: Fill request struct fields.
   137  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#GetPersistentResourceRequest.
   138  	}
   139  	resp, err := c.GetPersistentResource(ctx, req)
   140  	if err != nil {
   141  		// TODO: Handle error.
   142  	}
   143  	// TODO: Use resp.
   144  	_ = resp
   145  }
   146  
   147  func ExamplePersistentResourceClient_ListPersistentResources() {
   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.NewPersistentResourceClient(ctx)
   155  	if err != nil {
   156  		// TODO: Handle error.
   157  	}
   158  	defer c.Close()
   159  
   160  	req := &aiplatformpb.ListPersistentResourcesRequest{
   161  		// TODO: Fill request struct fields.
   162  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#ListPersistentResourcesRequest.
   163  	}
   164  	it := c.ListPersistentResources(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.ListPersistentResourcesResponse)
   181  	}
   182  }
   183  
   184  func ExamplePersistentResourceClient_RebootPersistentResource() {
   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.NewPersistentResourceClient(ctx)
   192  	if err != nil {
   193  		// TODO: Handle error.
   194  	}
   195  	defer c.Close()
   196  
   197  	req := &aiplatformpb.RebootPersistentResourceRequest{
   198  		// TODO: Fill request struct fields.
   199  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#RebootPersistentResourceRequest.
   200  	}
   201  	op, err := c.RebootPersistentResource(ctx, req)
   202  	if err != nil {
   203  		// TODO: Handle error.
   204  	}
   205  
   206  	resp, err := op.Wait(ctx)
   207  	if err != nil {
   208  		// TODO: Handle error.
   209  	}
   210  	// TODO: Use resp.
   211  	_ = resp
   212  }
   213  
   214  func ExamplePersistentResourceClient_UpdatePersistentResource() {
   215  	ctx := context.Background()
   216  	// This snippet has been automatically generated and should be regarded as a code template only.
   217  	// It will require modifications to work:
   218  	// - It may require correct/in-range values for request initialization.
   219  	// - It may require specifying regional endpoints when creating the service client as shown in:
   220  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   221  	c, err := aiplatform.NewPersistentResourceClient(ctx)
   222  	if err != nil {
   223  		// TODO: Handle error.
   224  	}
   225  	defer c.Close()
   226  
   227  	req := &aiplatformpb.UpdatePersistentResourceRequest{
   228  		// TODO: Fill request struct fields.
   229  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#UpdatePersistentResourceRequest.
   230  	}
   231  	op, err := c.UpdatePersistentResource(ctx, req)
   232  	if err != nil {
   233  		// TODO: Handle error.
   234  	}
   235  
   236  	resp, err := op.Wait(ctx)
   237  	if err != nil {
   238  		// TODO: Handle error.
   239  	}
   240  	// TODO: Use resp.
   241  	_ = resp
   242  }
   243  
   244  func ExamplePersistentResourceClient_GetLocation() {
   245  	ctx := context.Background()
   246  	// This snippet has been automatically generated and should be regarded as a code template only.
   247  	// It will require modifications to work:
   248  	// - It may require correct/in-range values for request initialization.
   249  	// - It may require specifying regional endpoints when creating the service client as shown in:
   250  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   251  	c, err := aiplatform.NewPersistentResourceClient(ctx)
   252  	if err != nil {
   253  		// TODO: Handle error.
   254  	}
   255  	defer c.Close()
   256  
   257  	req := &locationpb.GetLocationRequest{
   258  		// TODO: Fill request struct fields.
   259  		// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest.
   260  	}
   261  	resp, err := c.GetLocation(ctx, req)
   262  	if err != nil {
   263  		// TODO: Handle error.
   264  	}
   265  	// TODO: Use resp.
   266  	_ = resp
   267  }
   268  
   269  func ExamplePersistentResourceClient_ListLocations() {
   270  	ctx := context.Background()
   271  	// This snippet has been automatically generated and should be regarded as a code template only.
   272  	// It will require modifications to work:
   273  	// - It may require correct/in-range values for request initialization.
   274  	// - It may require specifying regional endpoints when creating the service client as shown in:
   275  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   276  	c, err := aiplatform.NewPersistentResourceClient(ctx)
   277  	if err != nil {
   278  		// TODO: Handle error.
   279  	}
   280  	defer c.Close()
   281  
   282  	req := &locationpb.ListLocationsRequest{
   283  		// TODO: Fill request struct fields.
   284  		// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest.
   285  	}
   286  	it := c.ListLocations(ctx, req)
   287  	for {
   288  		resp, err := it.Next()
   289  		if err == iterator.Done {
   290  			break
   291  		}
   292  		if err != nil {
   293  			// TODO: Handle error.
   294  		}
   295  		// TODO: Use resp.
   296  		_ = resp
   297  
   298  		// If you need to access the underlying RPC response,
   299  		// you can do so by casting the `Response` as below.
   300  		// Otherwise, remove this line. Only populated after
   301  		// first call to Next(). Not safe for concurrent access.
   302  		_ = it.Response.(*locationpb.ListLocationsResponse)
   303  	}
   304  }
   305  
   306  func ExamplePersistentResourceClient_GetIamPolicy() {
   307  	ctx := context.Background()
   308  	// This snippet has been automatically generated and should be regarded as a code template only.
   309  	// It will require modifications to work:
   310  	// - It may require correct/in-range values for request initialization.
   311  	// - It may require specifying regional endpoints when creating the service client as shown in:
   312  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   313  	c, err := aiplatform.NewPersistentResourceClient(ctx)
   314  	if err != nil {
   315  		// TODO: Handle error.
   316  	}
   317  	defer c.Close()
   318  
   319  	req := &iampb.GetIamPolicyRequest{
   320  		// TODO: Fill request struct fields.
   321  		// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest.
   322  	}
   323  	resp, err := c.GetIamPolicy(ctx, req)
   324  	if err != nil {
   325  		// TODO: Handle error.
   326  	}
   327  	// TODO: Use resp.
   328  	_ = resp
   329  }
   330  
   331  func ExamplePersistentResourceClient_SetIamPolicy() {
   332  	ctx := context.Background()
   333  	// This snippet has been automatically generated and should be regarded as a code template only.
   334  	// It will require modifications to work:
   335  	// - It may require correct/in-range values for request initialization.
   336  	// - It may require specifying regional endpoints when creating the service client as shown in:
   337  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   338  	c, err := aiplatform.NewPersistentResourceClient(ctx)
   339  	if err != nil {
   340  		// TODO: Handle error.
   341  	}
   342  	defer c.Close()
   343  
   344  	req := &iampb.SetIamPolicyRequest{
   345  		// TODO: Fill request struct fields.
   346  		// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest.
   347  	}
   348  	resp, err := c.SetIamPolicy(ctx, req)
   349  	if err != nil {
   350  		// TODO: Handle error.
   351  	}
   352  	// TODO: Use resp.
   353  	_ = resp
   354  }
   355  
   356  func ExamplePersistentResourceClient_TestIamPermissions() {
   357  	ctx := context.Background()
   358  	// This snippet has been automatically generated and should be regarded as a code template only.
   359  	// It will require modifications to work:
   360  	// - It may require correct/in-range values for request initialization.
   361  	// - It may require specifying regional endpoints when creating the service client as shown in:
   362  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   363  	c, err := aiplatform.NewPersistentResourceClient(ctx)
   364  	if err != nil {
   365  		// TODO: Handle error.
   366  	}
   367  	defer c.Close()
   368  
   369  	req := &iampb.TestIamPermissionsRequest{
   370  		// TODO: Fill request struct fields.
   371  		// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest.
   372  	}
   373  	resp, err := c.TestIamPermissions(ctx, req)
   374  	if err != nil {
   375  		// TODO: Handle error.
   376  	}
   377  	// TODO: Use resp.
   378  	_ = resp
   379  }
   380  
   381  func ExamplePersistentResourceClient_CancelOperation() {
   382  	ctx := context.Background()
   383  	// This snippet has been automatically generated and should be regarded as a code template only.
   384  	// It will require modifications to work:
   385  	// - It may require correct/in-range values for request initialization.
   386  	// - It may require specifying regional endpoints when creating the service client as shown in:
   387  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   388  	c, err := aiplatform.NewPersistentResourceClient(ctx)
   389  	if err != nil {
   390  		// TODO: Handle error.
   391  	}
   392  	defer c.Close()
   393  
   394  	req := &longrunningpb.CancelOperationRequest{
   395  		// TODO: Fill request struct fields.
   396  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest.
   397  	}
   398  	err = c.CancelOperation(ctx, req)
   399  	if err != nil {
   400  		// TODO: Handle error.
   401  	}
   402  }
   403  
   404  func ExamplePersistentResourceClient_DeleteOperation() {
   405  	ctx := context.Background()
   406  	// This snippet has been automatically generated and should be regarded as a code template only.
   407  	// It will require modifications to work:
   408  	// - It may require correct/in-range values for request initialization.
   409  	// - It may require specifying regional endpoints when creating the service client as shown in:
   410  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   411  	c, err := aiplatform.NewPersistentResourceClient(ctx)
   412  	if err != nil {
   413  		// TODO: Handle error.
   414  	}
   415  	defer c.Close()
   416  
   417  	req := &longrunningpb.DeleteOperationRequest{
   418  		// TODO: Fill request struct fields.
   419  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest.
   420  	}
   421  	err = c.DeleteOperation(ctx, req)
   422  	if err != nil {
   423  		// TODO: Handle error.
   424  	}
   425  }
   426  
   427  func ExamplePersistentResourceClient_GetOperation() {
   428  	ctx := context.Background()
   429  	// This snippet has been automatically generated and should be regarded as a code template only.
   430  	// It will require modifications to work:
   431  	// - It may require correct/in-range values for request initialization.
   432  	// - It may require specifying regional endpoints when creating the service client as shown in:
   433  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   434  	c, err := aiplatform.NewPersistentResourceClient(ctx)
   435  	if err != nil {
   436  		// TODO: Handle error.
   437  	}
   438  	defer c.Close()
   439  
   440  	req := &longrunningpb.GetOperationRequest{
   441  		// TODO: Fill request struct fields.
   442  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest.
   443  	}
   444  	resp, err := c.GetOperation(ctx, req)
   445  	if err != nil {
   446  		// TODO: Handle error.
   447  	}
   448  	// TODO: Use resp.
   449  	_ = resp
   450  }
   451  
   452  func ExamplePersistentResourceClient_ListOperations() {
   453  	ctx := context.Background()
   454  	// This snippet has been automatically generated and should be regarded as a code template only.
   455  	// It will require modifications to work:
   456  	// - It may require correct/in-range values for request initialization.
   457  	// - It may require specifying regional endpoints when creating the service client as shown in:
   458  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   459  	c, err := aiplatform.NewPersistentResourceClient(ctx)
   460  	if err != nil {
   461  		// TODO: Handle error.
   462  	}
   463  	defer c.Close()
   464  
   465  	req := &longrunningpb.ListOperationsRequest{
   466  		// TODO: Fill request struct fields.
   467  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest.
   468  	}
   469  	it := c.ListOperations(ctx, req)
   470  	for {
   471  		resp, err := it.Next()
   472  		if err == iterator.Done {
   473  			break
   474  		}
   475  		if err != nil {
   476  			// TODO: Handle error.
   477  		}
   478  		// TODO: Use resp.
   479  		_ = resp
   480  
   481  		// If you need to access the underlying RPC response,
   482  		// you can do so by casting the `Response` as below.
   483  		// Otherwise, remove this line. Only populated after
   484  		// first call to Next(). Not safe for concurrent access.
   485  		_ = it.Response.(*longrunningpb.ListOperationsResponse)
   486  	}
   487  }
   488  
   489  func ExamplePersistentResourceClient_WaitOperation() {
   490  	ctx := context.Background()
   491  	// This snippet has been automatically generated and should be regarded as a code template only.
   492  	// It will require modifications to work:
   493  	// - It may require correct/in-range values for request initialization.
   494  	// - It may require specifying regional endpoints when creating the service client as shown in:
   495  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   496  	c, err := aiplatform.NewPersistentResourceClient(ctx)
   497  	if err != nil {
   498  		// TODO: Handle error.
   499  	}
   500  	defer c.Close()
   501  
   502  	req := &longrunningpb.WaitOperationRequest{
   503  		// TODO: Fill request struct fields.
   504  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#WaitOperationRequest.
   505  	}
   506  	resp, err := c.WaitOperation(ctx, req)
   507  	if err != nil {
   508  		// TODO: Handle error.
   509  	}
   510  	// TODO: Use resp.
   511  	_ = resp
   512  }