| 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 storagetransfer |
| 18 | |
| 19 | import ( |
| 20 | "context" |
| 21 | "time" |
| 22 | |
| 23 | "cloud.google.com/go/longrunning" |
| 24 | longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" |
| 25 | storagetransferpb "cloud.google.com/go/storagetransfer/apiv1/storagetransferpb" |
| 26 | gax "github.com/googleapis/gax-go/v2" |
| 27 | "google.golang.org/api/iterator" |
| 28 | ) |
| 29 | |
| 30 | // RunTransferJobOperation manages a long-running operation from RunTransferJob. |
| 31 | type RunTransferJobOperation struct { |
| 32 | lro *longrunning.Operation |
| 33 | pollPath string |
| 34 | } |
| 35 | |
| 36 | // Wait blocks until the long-running operation is completed, returning the response and any errors encountered. |
| 37 | // |
| 38 | // See documentation of Poll for error-handling information. |
| 39 | func (op *RunTransferJobOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { |
| 40 | opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...) |
| 41 | return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) |
| 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 *RunTransferJobOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { |
| 54 | opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...) |
| 55 | return op.lro.Poll(ctx, nil, opts...) |
| 56 | } |
| 57 | |
| 58 | // Metadata returns metadata associated with the long-running operation. |
| 59 | // Metadata itself does not contact the server, but Poll does. |
| 60 | // To get the latest metadata, call this method after a successful call to Poll. |
| 61 | // If the metadata is not available, the returned metadata and error are both nil. |
| 62 | func (op *RunTransferJobOperation) Metadata() (*storagetransferpb.TransferOperation, error) { |
| 63 | var meta storagetransferpb.TransferOperation |
| 64 | if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { |
| 65 | return nil, nil |
| 66 | } else if err != nil { |
| 67 | return nil, err |
| 68 | } |
| 69 | return &meta, nil |
| 70 | } |
| 71 | |
| 72 | // Done reports whether the long-running operation has completed. |
| 73 | func (op *RunTransferJobOperation) Done() bool { |
| 74 | return op.lro.Done() |
| 75 | } |
| 76 | |
| 77 | // Name returns the name of the long-running operation. |
| 78 | // The name is assigned by the server and is unique within the service from which the operation is created. |
| 79 | func (op *RunTransferJobOperation) Name() string { |
| 80 | return op.lro.Name() |
| 81 | } |
| 82 | |
| 83 | // AgentPoolIterator manages a stream of *storagetransferpb.AgentPool. |
| 84 | type AgentPoolIterator struct { |
| 85 | items []*storagetransferpb.AgentPool |
| 86 | pageInfo *iterator.PageInfo |
| 87 | nextFunc func() error |
| 88 | |
| 89 | // Response is the raw response for the current page. |
| 90 | // It must be cast to the RPC response type. |
| 91 | // Calling Next() or InternalFetch() updates this value. |
| 92 | Response interface{} |
| 93 | |
| 94 | // InternalFetch is for use by the Google Cloud Libraries only. |
| 95 | // It is not part of the stable interface of this package. |
| 96 | // |
| 97 | // InternalFetch returns results from a single call to the underlying RPC. |
| 98 | // The number of results is no greater than pageSize. |
| 99 | // If there are no more results, nextPageToken is empty and err is nil. |
| 100 | InternalFetch func(pageSize int, pageToken string) (results []*storagetransferpb.AgentPool, nextPageToken string, err error) |
| 101 | } |
| 102 | |
| 103 | // PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details. |
| 104 | func (it *AgentPoolIterator) PageInfo() *iterator.PageInfo { |
| 105 | return it.pageInfo |
| 106 | } |
| 107 | |
| 108 | // Next returns the next result. Its second return value is iterator.Done if there are no more |
| 109 | // results. Once Next returns Done, all subsequent calls will return Done. |
| 110 | func (it *AgentPoolIterator) Next() (*storagetransferpb.AgentPool, error) { |
| 111 | var item *storagetransferpb.AgentPool |
| 112 | if err := it.nextFunc(); err != nil { |
| 113 | return item, err |
| 114 | } |
| 115 | item = it.items[0] |
| 116 | it.items = it.items[1:] |
| 117 | return item, nil |
| 118 | } |
| 119 | |
| 120 | func (it *AgentPoolIterator) bufLen() int { |
| 121 | return len(it.items) |
| 122 | } |
| 123 | |
| 124 | func (it *AgentPoolIterator) takeBuf() interface{} { |
| 125 | b := it.items |
| 126 | it.items = nil |
| 127 | return b |
| 128 | } |
| 129 | |
| 130 | // OperationIterator manages a stream of *longrunningpb.Operation. |
| 131 | type OperationIterator struct { |
| 132 | items []*longrunningpb.Operation |
| 133 | pageInfo *iterator.PageInfo |
| 134 | nextFunc func() error |
| 135 | |
| 136 | // Response is the raw response for the current page. |
| 137 | // It must be cast to the RPC response type. |
| 138 | // Calling Next() or InternalFetch() updates this value. |
| 139 | Response interface{} |
| 140 | |
| 141 | // InternalFetch is for use by the Google Cloud Libraries only. |
| 142 | // It is not part of the stable interface of this package. |
| 143 | // |
| 144 | // InternalFetch returns results from a single call to the underlying RPC. |
| 145 | // The number of results is no greater than pageSize. |
| 146 | // If there are no more results, nextPageToken is empty and err is nil. |
| 147 | InternalFetch func(pageSize int, pageToken string) (results []*longrunningpb.Operation, nextPageToken string, err error) |
| 148 | } |
| 149 | |
| 150 | // PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details. |
| 151 | func (it *OperationIterator) PageInfo() *iterator.PageInfo { |
| 152 | return it.pageInfo |
| 153 | } |
| 154 | |
| 155 | // Next returns the next result. Its second return value is iterator.Done if there are no more |
| 156 | // results. Once Next returns Done, all subsequent calls will return Done. |
| 157 | func (it *OperationIterator) Next() (*longrunningpb.Operation, error) { |
| 158 | var item *longrunningpb.Operation |
| 159 | if err := it.nextFunc(); err != nil { |
| 160 | return item, err |
| 161 | } |
| 162 | item = it.items[0] |
| 163 | it.items = it.items[1:] |
| 164 | return item, nil |
| 165 | } |
| 166 | |
| 167 | func (it *OperationIterator) bufLen() int { |
| 168 | return len(it.items) |
| 169 | } |
| 170 | |
| 171 | func (it *OperationIterator) takeBuf() interface{} { |
| 172 | b := it.items |
| 173 | it.items = nil |
| 174 | return b |
| 175 | } |
| 176 | |
| 177 | // TransferJobIterator manages a stream of *storagetransferpb.TransferJob. |
| 178 | type TransferJobIterator struct { |
| 179 | items []*storagetransferpb.TransferJob |
| 180 | pageInfo *iterator.PageInfo |
| 181 | nextFunc func() error |
| 182 | |
| 183 | // Response is the raw response for the current page. |
| 184 | // It must be cast to the RPC response type. |
| 185 | // Calling Next() or InternalFetch() updates this value. |
| 186 | Response interface{} |
| 187 | |
| 188 | // InternalFetch is for use by the Google Cloud Libraries only. |
| 189 | // It is not part of the stable interface of this package. |
| 190 | // |
| 191 | // InternalFetch returns results from a single call to the underlying RPC. |
| 192 | // The number of results is no greater than pageSize. |
| 193 | // If there are no more results, nextPageToken is empty and err is nil. |
| 194 | InternalFetch func(pageSize int, pageToken string) (results []*storagetransferpb.TransferJob, nextPageToken string, err error) |
| 195 | } |
| 196 | |
| 197 | // PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details. |
| 198 | func (it *TransferJobIterator) PageInfo() *iterator.PageInfo { |
| 199 | return it.pageInfo |
| 200 | } |
| 201 | |
| 202 | // Next returns the next result. Its second return value is iterator.Done if there are no more |
| 203 | // results. Once Next returns Done, all subsequent calls will return Done. |
| 204 | func (it *TransferJobIterator) Next() (*storagetransferpb.TransferJob, error) { |
| 205 | var item *storagetransferpb.TransferJob |
| 206 | if err := it.nextFunc(); err != nil { |
| 207 | return item, err |
| 208 | } |
| 209 | item = it.items[0] |
| 210 | it.items = it.items[1:] |
| 211 | return item, nil |
| 212 | } |
| 213 | |
| 214 | func (it *TransferJobIterator) bufLen() int { |
| 215 | return len(it.items) |
| 216 | } |
| 217 | |
| 218 | func (it *TransferJobIterator) takeBuf() interface{} { |
| 219 | b := it.items |
| 220 | it.items = nil |
| 221 | return b |
| 222 | } |