You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

610 lines
24 KiB

  1. // Copyright 2019 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. // Code generated by gapic-generator. DO NOT EDIT.
  15. package dataproc
  16. import (
  17. "context"
  18. "math"
  19. "time"
  20. "cloud.google.com/go/longrunning"
  21. lroauto "cloud.google.com/go/longrunning/autogen"
  22. "github.com/golang/protobuf/proto"
  23. gax "github.com/googleapis/gax-go/v2"
  24. "google.golang.org/api/iterator"
  25. "google.golang.org/api/option"
  26. "google.golang.org/api/transport"
  27. dataprocpb "google.golang.org/genproto/googleapis/cloud/dataproc/v1"
  28. longrunningpb "google.golang.org/genproto/googleapis/longrunning"
  29. "google.golang.org/grpc"
  30. "google.golang.org/grpc/codes"
  31. "google.golang.org/grpc/metadata"
  32. )
  33. // ClusterControllerCallOptions contains the retry settings for each method of ClusterControllerClient.
  34. type ClusterControllerCallOptions struct {
  35. CreateCluster []gax.CallOption
  36. UpdateCluster []gax.CallOption
  37. DeleteCluster []gax.CallOption
  38. GetCluster []gax.CallOption
  39. ListClusters []gax.CallOption
  40. DiagnoseCluster []gax.CallOption
  41. }
  42. func defaultClusterControllerClientOptions() []option.ClientOption {
  43. return []option.ClientOption{
  44. option.WithEndpoint("dataproc.googleapis.com:443"),
  45. option.WithScopes(DefaultAuthScopes()...),
  46. }
  47. }
  48. func defaultClusterControllerCallOptions() *ClusterControllerCallOptions {
  49. retry := map[[2]string][]gax.CallOption{
  50. {"default", "idempotent"}: {
  51. gax.WithRetry(func() gax.Retryer {
  52. return gax.OnCodes([]codes.Code{
  53. codes.DeadlineExceeded,
  54. codes.Internal,
  55. codes.Unavailable,
  56. }, gax.Backoff{
  57. Initial: 100 * time.Millisecond,
  58. Max: 60000 * time.Millisecond,
  59. Multiplier: 1.3,
  60. })
  61. }),
  62. },
  63. {"default", "non_idempotent"}: {
  64. gax.WithRetry(func() gax.Retryer {
  65. return gax.OnCodes([]codes.Code{
  66. codes.Unavailable,
  67. }, gax.Backoff{
  68. Initial: 100 * time.Millisecond,
  69. Max: 60000 * time.Millisecond,
  70. Multiplier: 1.3,
  71. })
  72. }),
  73. },
  74. }
  75. return &ClusterControllerCallOptions{
  76. CreateCluster: retry[[2]string{"default", "non_idempotent"}],
  77. UpdateCluster: retry[[2]string{"default", "non_idempotent"}],
  78. DeleteCluster: retry[[2]string{"default", "non_idempotent"}],
  79. GetCluster: retry[[2]string{"default", "idempotent"}],
  80. ListClusters: retry[[2]string{"default", "idempotent"}],
  81. DiagnoseCluster: retry[[2]string{"default", "non_idempotent"}],
  82. }
  83. }
  84. // ClusterControllerClient is a client for interacting with Google Cloud Dataproc API.
  85. //
  86. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  87. type ClusterControllerClient struct {
  88. // The connection to the service.
  89. conn *grpc.ClientConn
  90. // The gRPC API client.
  91. clusterControllerClient dataprocpb.ClusterControllerClient
  92. // LROClient is used internally to handle longrunning operations.
  93. // It is exposed so that its CallOptions can be modified if required.
  94. // Users should not Close this client.
  95. LROClient *lroauto.OperationsClient
  96. // The call options for this service.
  97. CallOptions *ClusterControllerCallOptions
  98. // The x-goog-* metadata to be sent with each request.
  99. xGoogMetadata metadata.MD
  100. }
  101. // NewClusterControllerClient creates a new cluster controller client.
  102. //
  103. // The ClusterControllerService provides methods to manage clusters
  104. // of Compute Engine instances.
  105. func NewClusterControllerClient(ctx context.Context, opts ...option.ClientOption) (*ClusterControllerClient, error) {
  106. conn, err := transport.DialGRPC(ctx, append(defaultClusterControllerClientOptions(), opts...)...)
  107. if err != nil {
  108. return nil, err
  109. }
  110. c := &ClusterControllerClient{
  111. conn: conn,
  112. CallOptions: defaultClusterControllerCallOptions(),
  113. clusterControllerClient: dataprocpb.NewClusterControllerClient(conn),
  114. }
  115. c.setGoogleClientInfo()
  116. c.LROClient, err = lroauto.NewOperationsClient(ctx, option.WithGRPCConn(conn))
  117. if err != nil {
  118. // This error "should not happen", since we are just reusing old connection
  119. // and never actually need to dial.
  120. // If this does happen, we could leak conn. However, we cannot close conn:
  121. // If the user invoked the function with option.WithGRPCConn,
  122. // we would close a connection that's still in use.
  123. // TODO(pongad): investigate error conditions.
  124. return nil, err
  125. }
  126. return c, nil
  127. }
  128. // Connection returns the client's connection to the API service.
  129. func (c *ClusterControllerClient) Connection() *grpc.ClientConn {
  130. return c.conn
  131. }
  132. // Close closes the connection to the API service. The user should invoke this when
  133. // the client is no longer required.
  134. func (c *ClusterControllerClient) Close() error {
  135. return c.conn.Close()
  136. }
  137. // setGoogleClientInfo sets the name and version of the application in
  138. // the `x-goog-api-client` header passed on each request. Intended for
  139. // use by Google-written clients.
  140. func (c *ClusterControllerClient) setGoogleClientInfo(keyval ...string) {
  141. kv := append([]string{"gl-go", versionGo()}, keyval...)
  142. kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
  143. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  144. }
  145. // CreateCluster creates a cluster in a project.
  146. func (c *ClusterControllerClient) CreateCluster(ctx context.Context, req *dataprocpb.CreateClusterRequest, opts ...gax.CallOption) (*CreateClusterOperation, error) {
  147. ctx = insertMetadata(ctx, c.xGoogMetadata)
  148. opts = append(c.CallOptions.CreateCluster[0:len(c.CallOptions.CreateCluster):len(c.CallOptions.CreateCluster)], opts...)
  149. var resp *longrunningpb.Operation
  150. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  151. var err error
  152. resp, err = c.clusterControllerClient.CreateCluster(ctx, req, settings.GRPC...)
  153. return err
  154. }, opts...)
  155. if err != nil {
  156. return nil, err
  157. }
  158. return &CreateClusterOperation{
  159. lro: longrunning.InternalNewOperation(c.LROClient, resp),
  160. }, nil
  161. }
  162. // UpdateCluster updates a cluster in a project.
  163. func (c *ClusterControllerClient) UpdateCluster(ctx context.Context, req *dataprocpb.UpdateClusterRequest, opts ...gax.CallOption) (*UpdateClusterOperation, error) {
  164. ctx = insertMetadata(ctx, c.xGoogMetadata)
  165. opts = append(c.CallOptions.UpdateCluster[0:len(c.CallOptions.UpdateCluster):len(c.CallOptions.UpdateCluster)], opts...)
  166. var resp *longrunningpb.Operation
  167. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  168. var err error
  169. resp, err = c.clusterControllerClient.UpdateCluster(ctx, req, settings.GRPC...)
  170. return err
  171. }, opts...)
  172. if err != nil {
  173. return nil, err
  174. }
  175. return &UpdateClusterOperation{
  176. lro: longrunning.InternalNewOperation(c.LROClient, resp),
  177. }, nil
  178. }
  179. // DeleteCluster deletes a cluster in a project.
  180. func (c *ClusterControllerClient) DeleteCluster(ctx context.Context, req *dataprocpb.DeleteClusterRequest, opts ...gax.CallOption) (*DeleteClusterOperation, error) {
  181. ctx = insertMetadata(ctx, c.xGoogMetadata)
  182. opts = append(c.CallOptions.DeleteCluster[0:len(c.CallOptions.DeleteCluster):len(c.CallOptions.DeleteCluster)], opts...)
  183. var resp *longrunningpb.Operation
  184. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  185. var err error
  186. resp, err = c.clusterControllerClient.DeleteCluster(ctx, req, settings.GRPC...)
  187. return err
  188. }, opts...)
  189. if err != nil {
  190. return nil, err
  191. }
  192. return &DeleteClusterOperation{
  193. lro: longrunning.InternalNewOperation(c.LROClient, resp),
  194. }, nil
  195. }
  196. // GetCluster gets the resource representation for a cluster in a project.
  197. func (c *ClusterControllerClient) GetCluster(ctx context.Context, req *dataprocpb.GetClusterRequest, opts ...gax.CallOption) (*dataprocpb.Cluster, error) {
  198. ctx = insertMetadata(ctx, c.xGoogMetadata)
  199. opts = append(c.CallOptions.GetCluster[0:len(c.CallOptions.GetCluster):len(c.CallOptions.GetCluster)], opts...)
  200. var resp *dataprocpb.Cluster
  201. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  202. var err error
  203. resp, err = c.clusterControllerClient.GetCluster(ctx, req, settings.GRPC...)
  204. return err
  205. }, opts...)
  206. if err != nil {
  207. return nil, err
  208. }
  209. return resp, nil
  210. }
  211. // ListClusters lists all regions/{region}/clusters in a project.
  212. func (c *ClusterControllerClient) ListClusters(ctx context.Context, req *dataprocpb.ListClustersRequest, opts ...gax.CallOption) *ClusterIterator {
  213. ctx = insertMetadata(ctx, c.xGoogMetadata)
  214. opts = append(c.CallOptions.ListClusters[0:len(c.CallOptions.ListClusters):len(c.CallOptions.ListClusters)], opts...)
  215. it := &ClusterIterator{}
  216. req = proto.Clone(req).(*dataprocpb.ListClustersRequest)
  217. it.InternalFetch = func(pageSize int, pageToken string) ([]*dataprocpb.Cluster, string, error) {
  218. var resp *dataprocpb.ListClustersResponse
  219. req.PageToken = pageToken
  220. if pageSize > math.MaxInt32 {
  221. req.PageSize = math.MaxInt32
  222. } else {
  223. req.PageSize = int32(pageSize)
  224. }
  225. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  226. var err error
  227. resp, err = c.clusterControllerClient.ListClusters(ctx, req, settings.GRPC...)
  228. return err
  229. }, opts...)
  230. if err != nil {
  231. return nil, "", err
  232. }
  233. return resp.Clusters, resp.NextPageToken, nil
  234. }
  235. fetch := func(pageSize int, pageToken string) (string, error) {
  236. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  237. if err != nil {
  238. return "", err
  239. }
  240. it.items = append(it.items, items...)
  241. return nextPageToken, nil
  242. }
  243. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  244. it.pageInfo.MaxSize = int(req.PageSize)
  245. return it
  246. }
  247. // DiagnoseCluster gets cluster diagnostic information.
  248. // After the operation completes, the Operation.response field
  249. // contains DiagnoseClusterOutputLocation.
  250. func (c *ClusterControllerClient) DiagnoseCluster(ctx context.Context, req *dataprocpb.DiagnoseClusterRequest, opts ...gax.CallOption) (*DiagnoseClusterOperation, error) {
  251. ctx = insertMetadata(ctx, c.xGoogMetadata)
  252. opts = append(c.CallOptions.DiagnoseCluster[0:len(c.CallOptions.DiagnoseCluster):len(c.CallOptions.DiagnoseCluster)], opts...)
  253. var resp *longrunningpb.Operation
  254. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  255. var err error
  256. resp, err = c.clusterControllerClient.DiagnoseCluster(ctx, req, settings.GRPC...)
  257. return err
  258. }, opts...)
  259. if err != nil {
  260. return nil, err
  261. }
  262. return &DiagnoseClusterOperation{
  263. lro: longrunning.InternalNewOperation(c.LROClient, resp),
  264. }, nil
  265. }
  266. // ClusterIterator manages a stream of *dataprocpb.Cluster.
  267. type ClusterIterator struct {
  268. items []*dataprocpb.Cluster
  269. pageInfo *iterator.PageInfo
  270. nextFunc func() error
  271. // InternalFetch is for use by the Google Cloud Libraries only.
  272. // It is not part of the stable interface of this package.
  273. //
  274. // InternalFetch returns results from a single call to the underlying RPC.
  275. // The number of results is no greater than pageSize.
  276. // If there are no more results, nextPageToken is empty and err is nil.
  277. InternalFetch func(pageSize int, pageToken string) (results []*dataprocpb.Cluster, nextPageToken string, err error)
  278. }
  279. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  280. func (it *ClusterIterator) PageInfo() *iterator.PageInfo {
  281. return it.pageInfo
  282. }
  283. // Next returns the next result. Its second return value is iterator.Done if there are no more
  284. // results. Once Next returns Done, all subsequent calls will return Done.
  285. func (it *ClusterIterator) Next() (*dataprocpb.Cluster, error) {
  286. var item *dataprocpb.Cluster
  287. if err := it.nextFunc(); err != nil {
  288. return item, err
  289. }
  290. item = it.items[0]
  291. it.items = it.items[1:]
  292. return item, nil
  293. }
  294. func (it *ClusterIterator) bufLen() int {
  295. return len(it.items)
  296. }
  297. func (it *ClusterIterator) takeBuf() interface{} {
  298. b := it.items
  299. it.items = nil
  300. return b
  301. }
  302. // CreateClusterOperation manages a long-running operation from CreateCluster.
  303. type CreateClusterOperation struct {
  304. lro *longrunning.Operation
  305. }
  306. // CreateClusterOperation returns a new CreateClusterOperation from a given name.
  307. // The name must be that of a previously created CreateClusterOperation, possibly from a different process.
  308. func (c *ClusterControllerClient) CreateClusterOperation(name string) *CreateClusterOperation {
  309. return &CreateClusterOperation{
  310. lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
  311. }
  312. }
  313. // Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
  314. //
  315. // See documentation of Poll for error-handling information.
  316. func (op *CreateClusterOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*dataprocpb.Cluster, error) {
  317. var resp dataprocpb.Cluster
  318. if err := op.lro.WaitWithInterval(ctx, &resp, 10000*time.Millisecond, opts...); err != nil {
  319. return nil, err
  320. }
  321. return &resp, nil
  322. }
  323. // Poll fetches the latest state of the long-running operation.
  324. //
  325. // Poll also fetches the latest metadata, which can be retrieved by Metadata.
  326. //
  327. // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
  328. // the operation has completed with failure, the error is returned and op.Done will return true.
  329. // If Poll succeeds and the operation has completed successfully,
  330. // op.Done will return true, and the response of the operation is returned.
  331. // If Poll succeeds and the operation has not completed, the returned response and error are both nil.
  332. func (op *CreateClusterOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*dataprocpb.Cluster, error) {
  333. var resp dataprocpb.Cluster
  334. if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
  335. return nil, err
  336. }
  337. if !op.Done() {
  338. return nil, nil
  339. }
  340. return &resp, nil
  341. }
  342. // Metadata returns metadata associated with the long-running operation.
  343. // Metadata itself does not contact the server, but Poll does.
  344. // To get the latest metadata, call this method after a successful call to Poll.
  345. // If the metadata is not available, the returned metadata and error are both nil.
  346. func (op *CreateClusterOperation) Metadata() (*dataprocpb.ClusterOperationMetadata, error) {
  347. var meta dataprocpb.ClusterOperationMetadata
  348. if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
  349. return nil, nil
  350. } else if err != nil {
  351. return nil, err
  352. }
  353. return &meta, nil
  354. }
  355. // Done reports whether the long-running operation has completed.
  356. func (op *CreateClusterOperation) Done() bool {
  357. return op.lro.Done()
  358. }
  359. // Name returns the name of the long-running operation.
  360. // The name is assigned by the server and is unique within the service from which the operation is created.
  361. func (op *CreateClusterOperation) Name() string {
  362. return op.lro.Name()
  363. }
  364. // Delete deletes a long-running operation.
  365. // This method indicates that the client is no longer interested in the operation result.
  366. // It does not cancel the operation.
  367. func (op *CreateClusterOperation) Delete(ctx context.Context, opts ...gax.CallOption) error {
  368. return op.lro.Delete(ctx, opts...)
  369. }
  370. // DeleteClusterOperation manages a long-running operation from DeleteCluster.
  371. type DeleteClusterOperation struct {
  372. lro *longrunning.Operation
  373. }
  374. // DeleteClusterOperation returns a new DeleteClusterOperation from a given name.
  375. // The name must be that of a previously created DeleteClusterOperation, possibly from a different process.
  376. func (c *ClusterControllerClient) DeleteClusterOperation(name string) *DeleteClusterOperation {
  377. return &DeleteClusterOperation{
  378. lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
  379. }
  380. }
  381. // Wait blocks until the long-running operation is completed, returning any error encountered.
  382. //
  383. // See documentation of Poll for error-handling information.
  384. func (op *DeleteClusterOperation) Wait(ctx context.Context, opts ...gax.CallOption) error {
  385. return op.lro.WaitWithInterval(ctx, nil, 10000*time.Millisecond, opts...)
  386. }
  387. // Poll fetches the latest state of the long-running operation.
  388. //
  389. // Poll also fetches the latest metadata, which can be retrieved by Metadata.
  390. //
  391. // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
  392. // the operation has completed with failure, the error is returned and op.Done will return true.
  393. // If Poll succeeds and the operation has completed successfully, op.Done will return true.
  394. func (op *DeleteClusterOperation) Poll(ctx context.Context, opts ...gax.CallOption) error {
  395. return op.lro.Poll(ctx, nil, opts...)
  396. }
  397. // Metadata returns metadata associated with the long-running operation.
  398. // Metadata itself does not contact the server, but Poll does.
  399. // To get the latest metadata, call this method after a successful call to Poll.
  400. // If the metadata is not available, the returned metadata and error are both nil.
  401. func (op *DeleteClusterOperation) Metadata() (*dataprocpb.ClusterOperationMetadata, error) {
  402. var meta dataprocpb.ClusterOperationMetadata
  403. if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
  404. return nil, nil
  405. } else if err != nil {
  406. return nil, err
  407. }
  408. return &meta, nil
  409. }
  410. // Done reports whether the long-running operation has completed.
  411. func (op *DeleteClusterOperation) Done() bool {
  412. return op.lro.Done()
  413. }
  414. // Name returns the name of the long-running operation.
  415. // The name is assigned by the server and is unique within the service from which the operation is created.
  416. func (op *DeleteClusterOperation) Name() string {
  417. return op.lro.Name()
  418. }
  419. // Delete deletes a long-running operation.
  420. // This method indicates that the client is no longer interested in the operation result.
  421. // It does not cancel the operation.
  422. func (op *DeleteClusterOperation) Delete(ctx context.Context, opts ...gax.CallOption) error {
  423. return op.lro.Delete(ctx, opts...)
  424. }
  425. // DiagnoseClusterOperation manages a long-running operation from DiagnoseCluster.
  426. type DiagnoseClusterOperation struct {
  427. lro *longrunning.Operation
  428. }
  429. // DiagnoseClusterOperation returns a new DiagnoseClusterOperation from a given name.
  430. // The name must be that of a previously created DiagnoseClusterOperation, possibly from a different process.
  431. func (c *ClusterControllerClient) DiagnoseClusterOperation(name string) *DiagnoseClusterOperation {
  432. return &DiagnoseClusterOperation{
  433. lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
  434. }
  435. }
  436. // Wait blocks until the long-running operation is completed, returning any error encountered.
  437. //
  438. // See documentation of Poll for error-handling information.
  439. func (op *DiagnoseClusterOperation) Wait(ctx context.Context, opts ...gax.CallOption) error {
  440. return op.lro.WaitWithInterval(ctx, nil, 10000*time.Millisecond, opts...)
  441. }
  442. // Poll fetches the latest state of the long-running operation.
  443. //
  444. // Poll also fetches the latest metadata, which can be retrieved by Metadata.
  445. //
  446. // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
  447. // the operation has completed with failure, the error is returned and op.Done will return true.
  448. // If Poll succeeds and the operation has completed successfully, op.Done will return true.
  449. func (op *DiagnoseClusterOperation) Poll(ctx context.Context, opts ...gax.CallOption) error {
  450. return op.lro.Poll(ctx, nil, opts...)
  451. }
  452. // Metadata returns metadata associated with the long-running operation.
  453. // Metadata itself does not contact the server, but Poll does.
  454. // To get the latest metadata, call this method after a successful call to Poll.
  455. // If the metadata is not available, the returned metadata and error are both nil.
  456. func (op *DiagnoseClusterOperation) Metadata() (*dataprocpb.DiagnoseClusterResults, error) {
  457. var meta dataprocpb.DiagnoseClusterResults
  458. if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
  459. return nil, nil
  460. } else if err != nil {
  461. return nil, err
  462. }
  463. return &meta, nil
  464. }
  465. // Done reports whether the long-running operation has completed.
  466. func (op *DiagnoseClusterOperation) Done() bool {
  467. return op.lro.Done()
  468. }
  469. // Name returns the name of the long-running operation.
  470. // The name is assigned by the server and is unique within the service from which the operation is created.
  471. func (op *DiagnoseClusterOperation) Name() string {
  472. return op.lro.Name()
  473. }
  474. // Delete deletes a long-running operation.
  475. // This method indicates that the client is no longer interested in the operation result.
  476. // It does not cancel the operation.
  477. func (op *DiagnoseClusterOperation) Delete(ctx context.Context, opts ...gax.CallOption) error {
  478. return op.lro.Delete(ctx, opts...)
  479. }
  480. // UpdateClusterOperation manages a long-running operation from UpdateCluster.
  481. type UpdateClusterOperation struct {
  482. lro *longrunning.Operation
  483. }
  484. // UpdateClusterOperation returns a new UpdateClusterOperation from a given name.
  485. // The name must be that of a previously created UpdateClusterOperation, possibly from a different process.
  486. func (c *ClusterControllerClient) UpdateClusterOperation(name string) *UpdateClusterOperation {
  487. return &UpdateClusterOperation{
  488. lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
  489. }
  490. }
  491. // Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
  492. //
  493. // See documentation of Poll for error-handling information.
  494. func (op *UpdateClusterOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*dataprocpb.Cluster, error) {
  495. var resp dataprocpb.Cluster
  496. if err := op.lro.WaitWithInterval(ctx, &resp, 10000*time.Millisecond, opts...); err != nil {
  497. return nil, err
  498. }
  499. return &resp, nil
  500. }
  501. // Poll fetches the latest state of the long-running operation.
  502. //
  503. // Poll also fetches the latest metadata, which can be retrieved by Metadata.
  504. //
  505. // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
  506. // the operation has completed with failure, the error is returned and op.Done will return true.
  507. // If Poll succeeds and the operation has completed successfully,
  508. // op.Done will return true, and the response of the operation is returned.
  509. // If Poll succeeds and the operation has not completed, the returned response and error are both nil.
  510. func (op *UpdateClusterOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*dataprocpb.Cluster, error) {
  511. var resp dataprocpb.Cluster
  512. if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
  513. return nil, err
  514. }
  515. if !op.Done() {
  516. return nil, nil
  517. }
  518. return &resp, nil
  519. }
  520. // Metadata returns metadata associated with the long-running operation.
  521. // Metadata itself does not contact the server, but Poll does.
  522. // To get the latest metadata, call this method after a successful call to Poll.
  523. // If the metadata is not available, the returned metadata and error are both nil.
  524. func (op *UpdateClusterOperation) Metadata() (*dataprocpb.ClusterOperationMetadata, error) {
  525. var meta dataprocpb.ClusterOperationMetadata
  526. if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
  527. return nil, nil
  528. } else if err != nil {
  529. return nil, err
  530. }
  531. return &meta, nil
  532. }
  533. // Done reports whether the long-running operation has completed.
  534. func (op *UpdateClusterOperation) Done() bool {
  535. return op.lro.Done()
  536. }
  537. // Name returns the name of the long-running operation.
  538. // The name is assigned by the server and is unique within the service from which the operation is created.
  539. func (op *UpdateClusterOperation) Name() string {
  540. return op.lro.Name()
  541. }
  542. // Delete deletes a long-running operation.
  543. // This method indicates that the client is no longer interested in the operation result.
  544. // It does not cancel the operation.
  545. func (op *UpdateClusterOperation) Delete(ctx context.Context, opts ...gax.CallOption) error {
  546. return op.lro.Delete(ctx, opts...)
  547. }