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