...

Source file src/cloud.google.com/go/monitoring/metricsscope/apiv1/auxiliary.go

Documentation: cloud.google.com/go/monitoring/metricsscope/apiv1

     1  // Copyright 2024 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 metricsscope
    18  
    19  import (
    20  	"context"
    21  	"time"
    22  
    23  	"cloud.google.com/go/longrunning"
    24  	metricsscopepb "cloud.google.com/go/monitoring/metricsscope/apiv1/metricsscopepb"
    25  	gax "github.com/googleapis/gax-go/v2"
    26  )
    27  
    28  // CreateMonitoredProjectOperation manages a long-running operation from CreateMonitoredProject.
    29  type CreateMonitoredProjectOperation struct {
    30  	lro *longrunning.Operation
    31  }
    32  
    33  // Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
    34  //
    35  // See documentation of Poll for error-handling information.
    36  func (op *CreateMonitoredProjectOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*metricsscopepb.MonitoredProject, error) {
    37  	var resp metricsscopepb.MonitoredProject
    38  	if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
    39  		return nil, err
    40  	}
    41  	return &resp, nil
    42  }
    43  
    44  // Poll fetches the latest state of the long-running operation.
    45  //
    46  // Poll also fetches the latest metadata, which can be retrieved by Metadata.
    47  //
    48  // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
    49  // the operation has completed with failure, the error is returned and op.Done will return true.
    50  // If Poll succeeds and the operation has completed successfully,
    51  // op.Done will return true, and the response of the operation is returned.
    52  // If Poll succeeds and the operation has not completed, the returned response and error are both nil.
    53  func (op *CreateMonitoredProjectOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*metricsscopepb.MonitoredProject, error) {
    54  	var resp metricsscopepb.MonitoredProject
    55  	if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
    56  		return nil, err
    57  	}
    58  	if !op.Done() {
    59  		return nil, nil
    60  	}
    61  	return &resp, nil
    62  }
    63  
    64  // Metadata returns metadata associated with the long-running operation.
    65  // Metadata itself does not contact the server, but Poll does.
    66  // To get the latest metadata, call this method after a successful call to Poll.
    67  // If the metadata is not available, the returned metadata and error are both nil.
    68  func (op *CreateMonitoredProjectOperation) Metadata() (*metricsscopepb.OperationMetadata, error) {
    69  	var meta metricsscopepb.OperationMetadata
    70  	if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
    71  		return nil, nil
    72  	} else if err != nil {
    73  		return nil, err
    74  	}
    75  	return &meta, nil
    76  }
    77  
    78  // Done reports whether the long-running operation has completed.
    79  func (op *CreateMonitoredProjectOperation) Done() bool {
    80  	return op.lro.Done()
    81  }
    82  
    83  // Name returns the name of the long-running operation.
    84  // The name is assigned by the server and is unique within the service from which the operation is created.
    85  func (op *CreateMonitoredProjectOperation) Name() string {
    86  	return op.lro.Name()
    87  }
    88  
    89  // DeleteMonitoredProjectOperation manages a long-running operation from DeleteMonitoredProject.
    90  type DeleteMonitoredProjectOperation struct {
    91  	lro *longrunning.Operation
    92  }
    93  
    94  // Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
    95  //
    96  // See documentation of Poll for error-handling information.
    97  func (op *DeleteMonitoredProjectOperation) Wait(ctx context.Context, opts ...gax.CallOption) error {
    98  	return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...)
    99  }
   100  
   101  // Poll fetches the latest state of the long-running operation.
   102  //
   103  // Poll also fetches the latest metadata, which can be retrieved by Metadata.
   104  //
   105  // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
   106  // the operation has completed with failure, the error is returned and op.Done will return true.
   107  // If Poll succeeds and the operation has completed successfully,
   108  // op.Done will return true, and the response of the operation is returned.
   109  // If Poll succeeds and the operation has not completed, the returned response and error are both nil.
   110  func (op *DeleteMonitoredProjectOperation) Poll(ctx context.Context, opts ...gax.CallOption) error {
   111  	return op.lro.Poll(ctx, nil, opts...)
   112  }
   113  
   114  // Metadata returns metadata associated with the long-running operation.
   115  // Metadata itself does not contact the server, but Poll does.
   116  // To get the latest metadata, call this method after a successful call to Poll.
   117  // If the metadata is not available, the returned metadata and error are both nil.
   118  func (op *DeleteMonitoredProjectOperation) Metadata() (*metricsscopepb.OperationMetadata, error) {
   119  	var meta metricsscopepb.OperationMetadata
   120  	if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
   121  		return nil, nil
   122  	} else if err != nil {
   123  		return nil, err
   124  	}
   125  	return &meta, nil
   126  }
   127  
   128  // Done reports whether the long-running operation has completed.
   129  func (op *DeleteMonitoredProjectOperation) Done() bool {
   130  	return op.lro.Done()
   131  }
   132  
   133  // Name returns the name of the long-running operation.
   134  // The name is assigned by the server and is unique within the service from which the operation is created.
   135  func (op *DeleteMonitoredProjectOperation) Name() string {
   136  	return op.lro.Name()
   137  }
   138  

View as plain text