選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

596 行
23 KiB

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