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

800 行
31 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 redis
  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. redispb "google.golang.org/genproto/googleapis/cloud/redis/v1"
  28. longrunningpb "google.golang.org/genproto/googleapis/longrunning"
  29. "google.golang.org/grpc"
  30. "google.golang.org/grpc/metadata"
  31. )
  32. // CloudRedisCallOptions contains the retry settings for each method of CloudRedisClient.
  33. type CloudRedisCallOptions struct {
  34. ListInstances []gax.CallOption
  35. GetInstance []gax.CallOption
  36. CreateInstance []gax.CallOption
  37. UpdateInstance []gax.CallOption
  38. DeleteInstance []gax.CallOption
  39. ImportInstance []gax.CallOption
  40. ExportInstance []gax.CallOption
  41. FailoverInstance []gax.CallOption
  42. }
  43. func defaultCloudRedisClientOptions() []option.ClientOption {
  44. return []option.ClientOption{
  45. option.WithEndpoint("redis.googleapis.com:443"),
  46. option.WithScopes(DefaultAuthScopes()...),
  47. }
  48. }
  49. func defaultCloudRedisCallOptions() *CloudRedisCallOptions {
  50. retry := map[[2]string][]gax.CallOption{}
  51. return &CloudRedisCallOptions{
  52. ListInstances: retry[[2]string{"default", "non_idempotent"}],
  53. GetInstance: retry[[2]string{"default", "non_idempotent"}],
  54. CreateInstance: retry[[2]string{"default", "non_idempotent"}],
  55. UpdateInstance: retry[[2]string{"default", "non_idempotent"}],
  56. DeleteInstance: retry[[2]string{"default", "non_idempotent"}],
  57. ImportInstance: retry[[2]string{"default", "non_idempotent"}],
  58. ExportInstance: retry[[2]string{"default", "non_idempotent"}],
  59. FailoverInstance: retry[[2]string{"default", "non_idempotent"}],
  60. }
  61. }
  62. // CloudRedisClient is a client for interacting with Google Cloud Memorystore for Redis API.
  63. //
  64. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  65. type CloudRedisClient struct {
  66. // The connection to the service.
  67. conn *grpc.ClientConn
  68. // The gRPC API client.
  69. cloudRedisClient redispb.CloudRedisClient
  70. // LROClient is used internally to handle longrunning operations.
  71. // It is exposed so that its CallOptions can be modified if required.
  72. // Users should not Close this client.
  73. LROClient *lroauto.OperationsClient
  74. // The call options for this service.
  75. CallOptions *CloudRedisCallOptions
  76. // The x-goog-* metadata to be sent with each request.
  77. xGoogMetadata metadata.MD
  78. }
  79. // NewCloudRedisClient creates a new cloud redis client.
  80. //
  81. // Configures and manages Cloud Memorystore for Redis instances
  82. //
  83. // Google Cloud Memorystore for Redis v1
  84. //
  85. // The redis.googleapis.com service implements the Google Cloud Memorystore
  86. // for Redis API and defines the following resource model for managing Redis
  87. // instances:
  88. //
  89. // The service works with a collection of cloud projects, named: /projects/*
  90. //
  91. // Each project has a collection of available locations, named: /locations/*
  92. //
  93. // Each location has a collection of Redis instances, named: /instances/*
  94. //
  95. // As such, Redis instances are resources of the form:
  96. // /projects/{project_id}/locations/{location_id}/instances/{instance_id}
  97. //
  98. // Note that location_id must be refering to a GCP region; for example:
  99. //
  100. // projects/redpepper-1290/locations/us-central1/instances/my-redis
  101. func NewCloudRedisClient(ctx context.Context, opts ...option.ClientOption) (*CloudRedisClient, error) {
  102. conn, err := transport.DialGRPC(ctx, append(defaultCloudRedisClientOptions(), opts...)...)
  103. if err != nil {
  104. return nil, err
  105. }
  106. c := &CloudRedisClient{
  107. conn: conn,
  108. CallOptions: defaultCloudRedisCallOptions(),
  109. cloudRedisClient: redispb.NewCloudRedisClient(conn),
  110. }
  111. c.setGoogleClientInfo()
  112. c.LROClient, err = lroauto.NewOperationsClient(ctx, option.WithGRPCConn(conn))
  113. if err != nil {
  114. // This error "should not happen", since we are just reusing old connection
  115. // and never actually need to dial.
  116. // If this does happen, we could leak conn. However, we cannot close conn:
  117. // If the user invoked the function with option.WithGRPCConn,
  118. // we would close a connection that's still in use.
  119. // TODO(pongad): investigate error conditions.
  120. return nil, err
  121. }
  122. return c, nil
  123. }
  124. // Connection returns the client's connection to the API service.
  125. func (c *CloudRedisClient) Connection() *grpc.ClientConn {
  126. return c.conn
  127. }
  128. // Close closes the connection to the API service. The user should invoke this when
  129. // the client is no longer required.
  130. func (c *CloudRedisClient) Close() error {
  131. return c.conn.Close()
  132. }
  133. // setGoogleClientInfo sets the name and version of the application in
  134. // the `x-goog-api-client` header passed on each request. Intended for
  135. // use by Google-written clients.
  136. func (c *CloudRedisClient) setGoogleClientInfo(keyval ...string) {
  137. kv := append([]string{"gl-go", versionGo()}, keyval...)
  138. kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
  139. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  140. }
  141. // ListInstances lists all Redis instances owned by a project in either the specified
  142. // location (region) or all locations.
  143. //
  144. // The location should have the following format:
  145. //
  146. // projects/{project_id}/locations/{location_id}
  147. //
  148. // If location_id is specified as - (wildcard), then all regions
  149. // available to the project are queried, and the results are aggregated.
  150. func (c *CloudRedisClient) ListInstances(ctx context.Context, req *redispb.ListInstancesRequest, opts ...gax.CallOption) *InstanceIterator {
  151. ctx = insertMetadata(ctx, c.xGoogMetadata)
  152. opts = append(c.CallOptions.ListInstances[0:len(c.CallOptions.ListInstances):len(c.CallOptions.ListInstances)], opts...)
  153. it := &InstanceIterator{}
  154. req = proto.Clone(req).(*redispb.ListInstancesRequest)
  155. it.InternalFetch = func(pageSize int, pageToken string) ([]*redispb.Instance, string, error) {
  156. var resp *redispb.ListInstancesResponse
  157. req.PageToken = pageToken
  158. if pageSize > math.MaxInt32 {
  159. req.PageSize = math.MaxInt32
  160. } else {
  161. req.PageSize = int32(pageSize)
  162. }
  163. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  164. var err error
  165. resp, err = c.cloudRedisClient.ListInstances(ctx, req, settings.GRPC...)
  166. return err
  167. }, opts...)
  168. if err != nil {
  169. return nil, "", err
  170. }
  171. return resp.Instances, resp.NextPageToken, nil
  172. }
  173. fetch := func(pageSize int, pageToken string) (string, error) {
  174. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  175. if err != nil {
  176. return "", err
  177. }
  178. it.items = append(it.items, items...)
  179. return nextPageToken, nil
  180. }
  181. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  182. it.pageInfo.MaxSize = int(req.PageSize)
  183. return it
  184. }
  185. // GetInstance gets the details of a specific Redis instance.
  186. func (c *CloudRedisClient) GetInstance(ctx context.Context, req *redispb.GetInstanceRequest, opts ...gax.CallOption) (*redispb.Instance, error) {
  187. ctx = insertMetadata(ctx, c.xGoogMetadata)
  188. opts = append(c.CallOptions.GetInstance[0:len(c.CallOptions.GetInstance):len(c.CallOptions.GetInstance)], opts...)
  189. var resp *redispb.Instance
  190. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  191. var err error
  192. resp, err = c.cloudRedisClient.GetInstance(ctx, req, settings.GRPC...)
  193. return err
  194. }, opts...)
  195. if err != nil {
  196. return nil, err
  197. }
  198. return resp, nil
  199. }
  200. // CreateInstance creates a Redis instance based on the specified tier and memory size.
  201. //
  202. // By default, the instance is accessible from the project's
  203. // default network (at /compute/docs/networks-and-firewalls#networks).
  204. //
  205. // The creation is executed asynchronously and callers may check the returned
  206. // operation to track its progress. Once the operation is completed the Redis
  207. // instance will be fully functional. Completed longrunning.Operation will
  208. // contain the new instance object in the response field.
  209. //
  210. // The returned operation is automatically deleted after a few hours, so there
  211. // is no need to call DeleteOperation.
  212. func (c *CloudRedisClient) CreateInstance(ctx context.Context, req *redispb.CreateInstanceRequest, opts ...gax.CallOption) (*CreateInstanceOperation, error) {
  213. ctx = insertMetadata(ctx, c.xGoogMetadata)
  214. opts = append(c.CallOptions.CreateInstance[0:len(c.CallOptions.CreateInstance):len(c.CallOptions.CreateInstance)], opts...)
  215. var resp *longrunningpb.Operation
  216. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  217. var err error
  218. resp, err = c.cloudRedisClient.CreateInstance(ctx, req, settings.GRPC...)
  219. return err
  220. }, opts...)
  221. if err != nil {
  222. return nil, err
  223. }
  224. return &CreateInstanceOperation{
  225. lro: longrunning.InternalNewOperation(c.LROClient, resp),
  226. }, nil
  227. }
  228. // UpdateInstance updates the metadata and configuration of a specific Redis instance.
  229. //
  230. // Completed longrunning.Operation will contain the new instance object
  231. // in the response field. The returned operation is automatically deleted
  232. // after a few hours, so there is no need to call DeleteOperation.
  233. func (c *CloudRedisClient) UpdateInstance(ctx context.Context, req *redispb.UpdateInstanceRequest, opts ...gax.CallOption) (*UpdateInstanceOperation, error) {
  234. ctx = insertMetadata(ctx, c.xGoogMetadata)
  235. opts = append(c.CallOptions.UpdateInstance[0:len(c.CallOptions.UpdateInstance):len(c.CallOptions.UpdateInstance)], opts...)
  236. var resp *longrunningpb.Operation
  237. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  238. var err error
  239. resp, err = c.cloudRedisClient.UpdateInstance(ctx, req, settings.GRPC...)
  240. return err
  241. }, opts...)
  242. if err != nil {
  243. return nil, err
  244. }
  245. return &UpdateInstanceOperation{
  246. lro: longrunning.InternalNewOperation(c.LROClient, resp),
  247. }, nil
  248. }
  249. // DeleteInstance deletes a specific Redis instance. Instance stops serving and data is
  250. // deleted.
  251. func (c *CloudRedisClient) DeleteInstance(ctx context.Context, req *redispb.DeleteInstanceRequest, opts ...gax.CallOption) (*DeleteInstanceOperation, error) {
  252. ctx = insertMetadata(ctx, c.xGoogMetadata)
  253. opts = append(c.CallOptions.DeleteInstance[0:len(c.CallOptions.DeleteInstance):len(c.CallOptions.DeleteInstance)], opts...)
  254. var resp *longrunningpb.Operation
  255. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  256. var err error
  257. resp, err = c.cloudRedisClient.DeleteInstance(ctx, req, settings.GRPC...)
  258. return err
  259. }, opts...)
  260. if err != nil {
  261. return nil, err
  262. }
  263. return &DeleteInstanceOperation{
  264. lro: longrunning.InternalNewOperation(c.LROClient, resp),
  265. }, nil
  266. }
  267. // ImportInstance import a Redis RDB snapshot file from GCS into a Redis instance.
  268. //
  269. // Redis may stop serving during this operation. Instance state will be
  270. // IMPORTING for entire operation. When complete, the instance will contain
  271. // only data from the imported file.
  272. //
  273. // The returned operation is automatically deleted after a few hours, so
  274. // there is no need to call DeleteOperation.
  275. func (c *CloudRedisClient) ImportInstance(ctx context.Context, req *redispb.ImportInstanceRequest, opts ...gax.CallOption) (*ImportInstanceOperation, error) {
  276. ctx = insertMetadata(ctx, c.xGoogMetadata)
  277. opts = append(c.CallOptions.ImportInstance[0:len(c.CallOptions.ImportInstance):len(c.CallOptions.ImportInstance)], opts...)
  278. var resp *longrunningpb.Operation
  279. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  280. var err error
  281. resp, err = c.cloudRedisClient.ImportInstance(ctx, req, settings.GRPC...)
  282. return err
  283. }, opts...)
  284. if err != nil {
  285. return nil, err
  286. }
  287. return &ImportInstanceOperation{
  288. lro: longrunning.InternalNewOperation(c.LROClient, resp),
  289. }, nil
  290. }
  291. // ExportInstance export Redis instance data into a Redis RDB format file in GCS.
  292. //
  293. // Redis will continue serving during this operation.
  294. //
  295. // The returned operation is automatically deleted after a few hours, so
  296. // there is no need to call DeleteOperation.
  297. func (c *CloudRedisClient) ExportInstance(ctx context.Context, req *redispb.ExportInstanceRequest, opts ...gax.CallOption) (*ExportInstanceOperation, error) {
  298. ctx = insertMetadata(ctx, c.xGoogMetadata)
  299. opts = append(c.CallOptions.ExportInstance[0:len(c.CallOptions.ExportInstance):len(c.CallOptions.ExportInstance)], opts...)
  300. var resp *longrunningpb.Operation
  301. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  302. var err error
  303. resp, err = c.cloudRedisClient.ExportInstance(ctx, req, settings.GRPC...)
  304. return err
  305. }, opts...)
  306. if err != nil {
  307. return nil, err
  308. }
  309. return &ExportInstanceOperation{
  310. lro: longrunning.InternalNewOperation(c.LROClient, resp),
  311. }, nil
  312. }
  313. // FailoverInstance failover the master role to current replica node against a specific
  314. // STANDARD tier redis instance.
  315. func (c *CloudRedisClient) FailoverInstance(ctx context.Context, req *redispb.FailoverInstanceRequest, opts ...gax.CallOption) (*FailoverInstanceOperation, error) {
  316. ctx = insertMetadata(ctx, c.xGoogMetadata)
  317. opts = append(c.CallOptions.FailoverInstance[0:len(c.CallOptions.FailoverInstance):len(c.CallOptions.FailoverInstance)], opts...)
  318. var resp *longrunningpb.Operation
  319. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  320. var err error
  321. resp, err = c.cloudRedisClient.FailoverInstance(ctx, req, settings.GRPC...)
  322. return err
  323. }, opts...)
  324. if err != nil {
  325. return nil, err
  326. }
  327. return &FailoverInstanceOperation{
  328. lro: longrunning.InternalNewOperation(c.LROClient, resp),
  329. }, nil
  330. }
  331. // InstanceIterator manages a stream of *redispb.Instance.
  332. type InstanceIterator struct {
  333. items []*redispb.Instance
  334. pageInfo *iterator.PageInfo
  335. nextFunc func() error
  336. // InternalFetch is for use by the Google Cloud Libraries only.
  337. // It is not part of the stable interface of this package.
  338. //
  339. // InternalFetch returns results from a single call to the underlying RPC.
  340. // The number of results is no greater than pageSize.
  341. // If there are no more results, nextPageToken is empty and err is nil.
  342. InternalFetch func(pageSize int, pageToken string) (results []*redispb.Instance, nextPageToken string, err error)
  343. }
  344. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  345. func (it *InstanceIterator) PageInfo() *iterator.PageInfo {
  346. return it.pageInfo
  347. }
  348. // Next returns the next result. Its second return value is iterator.Done if there are no more
  349. // results. Once Next returns Done, all subsequent calls will return Done.
  350. func (it *InstanceIterator) Next() (*redispb.Instance, error) {
  351. var item *redispb.Instance
  352. if err := it.nextFunc(); err != nil {
  353. return item, err
  354. }
  355. item = it.items[0]
  356. it.items = it.items[1:]
  357. return item, nil
  358. }
  359. func (it *InstanceIterator) bufLen() int {
  360. return len(it.items)
  361. }
  362. func (it *InstanceIterator) takeBuf() interface{} {
  363. b := it.items
  364. it.items = nil
  365. return b
  366. }
  367. // CreateInstanceOperation manages a long-running operation from CreateInstance.
  368. type CreateInstanceOperation struct {
  369. lro *longrunning.Operation
  370. }
  371. // CreateInstanceOperation returns a new CreateInstanceOperation from a given name.
  372. // The name must be that of a previously created CreateInstanceOperation, possibly from a different process.
  373. func (c *CloudRedisClient) CreateInstanceOperation(name string) *CreateInstanceOperation {
  374. return &CreateInstanceOperation{
  375. lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
  376. }
  377. }
  378. // Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
  379. //
  380. // See documentation of Poll for error-handling information.
  381. func (op *CreateInstanceOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*redispb.Instance, error) {
  382. var resp redispb.Instance
  383. if err := op.lro.WaitWithInterval(ctx, &resp, 360000*time.Millisecond, opts...); err != nil {
  384. return nil, err
  385. }
  386. return &resp, nil
  387. }
  388. // Poll fetches the latest state of the long-running operation.
  389. //
  390. // Poll also fetches the latest metadata, which can be retrieved by Metadata.
  391. //
  392. // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
  393. // the operation has completed with failure, the error is returned and op.Done will return true.
  394. // If Poll succeeds and the operation has completed successfully,
  395. // op.Done will return true, and the response of the operation is returned.
  396. // If Poll succeeds and the operation has not completed, the returned response and error are both nil.
  397. func (op *CreateInstanceOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*redispb.Instance, error) {
  398. var resp redispb.Instance
  399. if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
  400. return nil, err
  401. }
  402. if !op.Done() {
  403. return nil, nil
  404. }
  405. return &resp, nil
  406. }
  407. // Metadata returns metadata associated with the long-running operation.
  408. // Metadata itself does not contact the server, but Poll does.
  409. // To get the latest metadata, call this method after a successful call to Poll.
  410. // If the metadata is not available, the returned metadata and error are both nil.
  411. func (op *CreateInstanceOperation) Metadata() (*redispb.OperationMetadata, error) {
  412. var meta redispb.OperationMetadata
  413. if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
  414. return nil, nil
  415. } else if err != nil {
  416. return nil, err
  417. }
  418. return &meta, nil
  419. }
  420. // Done reports whether the long-running operation has completed.
  421. func (op *CreateInstanceOperation) Done() bool {
  422. return op.lro.Done()
  423. }
  424. // Name returns the name of the long-running operation.
  425. // The name is assigned by the server and is unique within the service from which the operation is created.
  426. func (op *CreateInstanceOperation) Name() string {
  427. return op.lro.Name()
  428. }
  429. // DeleteInstanceOperation manages a long-running operation from DeleteInstance.
  430. type DeleteInstanceOperation struct {
  431. lro *longrunning.Operation
  432. }
  433. // DeleteInstanceOperation returns a new DeleteInstanceOperation from a given name.
  434. // The name must be that of a previously created DeleteInstanceOperation, possibly from a different process.
  435. func (c *CloudRedisClient) DeleteInstanceOperation(name string) *DeleteInstanceOperation {
  436. return &DeleteInstanceOperation{
  437. lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
  438. }
  439. }
  440. // Wait blocks until the long-running operation is completed, returning any error encountered.
  441. //
  442. // See documentation of Poll for error-handling information.
  443. func (op *DeleteInstanceOperation) Wait(ctx context.Context, opts ...gax.CallOption) error {
  444. return op.lro.WaitWithInterval(ctx, nil, 360000*time.Millisecond, opts...)
  445. }
  446. // Poll fetches the latest state of the long-running operation.
  447. //
  448. // Poll also fetches the latest metadata, which can be retrieved by Metadata.
  449. //
  450. // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
  451. // the operation has completed with failure, the error is returned and op.Done will return true.
  452. // If Poll succeeds and the operation has completed successfully, op.Done will return true.
  453. func (op *DeleteInstanceOperation) Poll(ctx context.Context, opts ...gax.CallOption) error {
  454. return op.lro.Poll(ctx, nil, opts...)
  455. }
  456. // Metadata returns metadata associated with the long-running operation.
  457. // Metadata itself does not contact the server, but Poll does.
  458. // To get the latest metadata, call this method after a successful call to Poll.
  459. // If the metadata is not available, the returned metadata and error are both nil.
  460. func (op *DeleteInstanceOperation) Metadata() (*redispb.OperationMetadata, error) {
  461. var meta redispb.OperationMetadata
  462. if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
  463. return nil, nil
  464. } else if err != nil {
  465. return nil, err
  466. }
  467. return &meta, nil
  468. }
  469. // Done reports whether the long-running operation has completed.
  470. func (op *DeleteInstanceOperation) Done() bool {
  471. return op.lro.Done()
  472. }
  473. // Name returns the name of the long-running operation.
  474. // The name is assigned by the server and is unique within the service from which the operation is created.
  475. func (op *DeleteInstanceOperation) Name() string {
  476. return op.lro.Name()
  477. }
  478. // ExportInstanceOperation manages a long-running operation from ExportInstance.
  479. type ExportInstanceOperation struct {
  480. lro *longrunning.Operation
  481. }
  482. // ExportInstanceOperation returns a new ExportInstanceOperation from a given name.
  483. // The name must be that of a previously created ExportInstanceOperation, possibly from a different process.
  484. func (c *CloudRedisClient) ExportInstanceOperation(name string) *ExportInstanceOperation {
  485. return &ExportInstanceOperation{
  486. lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
  487. }
  488. }
  489. // Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
  490. //
  491. // See documentation of Poll for error-handling information.
  492. func (op *ExportInstanceOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*redispb.Instance, error) {
  493. var resp redispb.Instance
  494. if err := op.lro.WaitWithInterval(ctx, &resp, 360000*time.Millisecond, opts...); err != nil {
  495. return nil, err
  496. }
  497. return &resp, nil
  498. }
  499. // Poll fetches the latest state of the long-running operation.
  500. //
  501. // Poll also fetches the latest metadata, which can be retrieved by Metadata.
  502. //
  503. // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
  504. // the operation has completed with failure, the error is returned and op.Done will return true.
  505. // If Poll succeeds and the operation has completed successfully,
  506. // op.Done will return true, and the response of the operation is returned.
  507. // If Poll succeeds and the operation has not completed, the returned response and error are both nil.
  508. func (op *ExportInstanceOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*redispb.Instance, error) {
  509. var resp redispb.Instance
  510. if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
  511. return nil, err
  512. }
  513. if !op.Done() {
  514. return nil, nil
  515. }
  516. return &resp, nil
  517. }
  518. // Metadata returns metadata associated with the long-running operation.
  519. // Metadata itself does not contact the server, but Poll does.
  520. // To get the latest metadata, call this method after a successful call to Poll.
  521. // If the metadata is not available, the returned metadata and error are both nil.
  522. func (op *ExportInstanceOperation) Metadata() (*redispb.OperationMetadata, error) {
  523. var meta redispb.OperationMetadata
  524. if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
  525. return nil, nil
  526. } else if err != nil {
  527. return nil, err
  528. }
  529. return &meta, nil
  530. }
  531. // Done reports whether the long-running operation has completed.
  532. func (op *ExportInstanceOperation) Done() bool {
  533. return op.lro.Done()
  534. }
  535. // Name returns the name of the long-running operation.
  536. // The name is assigned by the server and is unique within the service from which the operation is created.
  537. func (op *ExportInstanceOperation) Name() string {
  538. return op.lro.Name()
  539. }
  540. // FailoverInstanceOperation manages a long-running operation from FailoverInstance.
  541. type FailoverInstanceOperation struct {
  542. lro *longrunning.Operation
  543. }
  544. // FailoverInstanceOperation returns a new FailoverInstanceOperation from a given name.
  545. // The name must be that of a previously created FailoverInstanceOperation, possibly from a different process.
  546. func (c *CloudRedisClient) FailoverInstanceOperation(name string) *FailoverInstanceOperation {
  547. return &FailoverInstanceOperation{
  548. lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
  549. }
  550. }
  551. // Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
  552. //
  553. // See documentation of Poll for error-handling information.
  554. func (op *FailoverInstanceOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*redispb.Instance, error) {
  555. var resp redispb.Instance
  556. if err := op.lro.WaitWithInterval(ctx, &resp, 360000*time.Millisecond, opts...); err != nil {
  557. return nil, err
  558. }
  559. return &resp, nil
  560. }
  561. // Poll fetches the latest state of the long-running operation.
  562. //
  563. // Poll also fetches the latest metadata, which can be retrieved by Metadata.
  564. //
  565. // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
  566. // the operation has completed with failure, the error is returned and op.Done will return true.
  567. // If Poll succeeds and the operation has completed successfully,
  568. // op.Done will return true, and the response of the operation is returned.
  569. // If Poll succeeds and the operation has not completed, the returned response and error are both nil.
  570. func (op *FailoverInstanceOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*redispb.Instance, error) {
  571. var resp redispb.Instance
  572. if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
  573. return nil, err
  574. }
  575. if !op.Done() {
  576. return nil, nil
  577. }
  578. return &resp, nil
  579. }
  580. // Metadata returns metadata associated with the long-running operation.
  581. // Metadata itself does not contact the server, but Poll does.
  582. // To get the latest metadata, call this method after a successful call to Poll.
  583. // If the metadata is not available, the returned metadata and error are both nil.
  584. func (op *FailoverInstanceOperation) Metadata() (*redispb.OperationMetadata, error) {
  585. var meta redispb.OperationMetadata
  586. if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
  587. return nil, nil
  588. } else if err != nil {
  589. return nil, err
  590. }
  591. return &meta, nil
  592. }
  593. // Done reports whether the long-running operation has completed.
  594. func (op *FailoverInstanceOperation) Done() bool {
  595. return op.lro.Done()
  596. }
  597. // Name returns the name of the long-running operation.
  598. // The name is assigned by the server and is unique within the service from which the operation is created.
  599. func (op *FailoverInstanceOperation) Name() string {
  600. return op.lro.Name()
  601. }
  602. // ImportInstanceOperation manages a long-running operation from ImportInstance.
  603. type ImportInstanceOperation struct {
  604. lro *longrunning.Operation
  605. }
  606. // ImportInstanceOperation returns a new ImportInstanceOperation from a given name.
  607. // The name must be that of a previously created ImportInstanceOperation, possibly from a different process.
  608. func (c *CloudRedisClient) ImportInstanceOperation(name string) *ImportInstanceOperation {
  609. return &ImportInstanceOperation{
  610. lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
  611. }
  612. }
  613. // Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
  614. //
  615. // See documentation of Poll for error-handling information.
  616. func (op *ImportInstanceOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*redispb.Instance, error) {
  617. var resp redispb.Instance
  618. if err := op.lro.WaitWithInterval(ctx, &resp, 360000*time.Millisecond, opts...); err != nil {
  619. return nil, err
  620. }
  621. return &resp, nil
  622. }
  623. // Poll fetches the latest state of the long-running operation.
  624. //
  625. // Poll also fetches the latest metadata, which can be retrieved by Metadata.
  626. //
  627. // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
  628. // the operation has completed with failure, the error is returned and op.Done will return true.
  629. // If Poll succeeds and the operation has completed successfully,
  630. // op.Done will return true, and the response of the operation is returned.
  631. // If Poll succeeds and the operation has not completed, the returned response and error are both nil.
  632. func (op *ImportInstanceOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*redispb.Instance, error) {
  633. var resp redispb.Instance
  634. if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
  635. return nil, err
  636. }
  637. if !op.Done() {
  638. return nil, nil
  639. }
  640. return &resp, nil
  641. }
  642. // Metadata returns metadata associated with the long-running operation.
  643. // Metadata itself does not contact the server, but Poll does.
  644. // To get the latest metadata, call this method after a successful call to Poll.
  645. // If the metadata is not available, the returned metadata and error are both nil.
  646. func (op *ImportInstanceOperation) Metadata() (*redispb.OperationMetadata, error) {
  647. var meta redispb.OperationMetadata
  648. if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
  649. return nil, nil
  650. } else if err != nil {
  651. return nil, err
  652. }
  653. return &meta, nil
  654. }
  655. // Done reports whether the long-running operation has completed.
  656. func (op *ImportInstanceOperation) Done() bool {
  657. return op.lro.Done()
  658. }
  659. // Name returns the name of the long-running operation.
  660. // The name is assigned by the server and is unique within the service from which the operation is created.
  661. func (op *ImportInstanceOperation) Name() string {
  662. return op.lro.Name()
  663. }
  664. // UpdateInstanceOperation manages a long-running operation from UpdateInstance.
  665. type UpdateInstanceOperation struct {
  666. lro *longrunning.Operation
  667. }
  668. // UpdateInstanceOperation returns a new UpdateInstanceOperation from a given name.
  669. // The name must be that of a previously created UpdateInstanceOperation, possibly from a different process.
  670. func (c *CloudRedisClient) UpdateInstanceOperation(name string) *UpdateInstanceOperation {
  671. return &UpdateInstanceOperation{
  672. lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
  673. }
  674. }
  675. // Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
  676. //
  677. // See documentation of Poll for error-handling information.
  678. func (op *UpdateInstanceOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*redispb.Instance, error) {
  679. var resp redispb.Instance
  680. if err := op.lro.WaitWithInterval(ctx, &resp, 360000*time.Millisecond, opts...); err != nil {
  681. return nil, err
  682. }
  683. return &resp, nil
  684. }
  685. // Poll fetches the latest state of the long-running operation.
  686. //
  687. // Poll also fetches the latest metadata, which can be retrieved by Metadata.
  688. //
  689. // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
  690. // the operation has completed with failure, the error is returned and op.Done will return true.
  691. // If Poll succeeds and the operation has completed successfully,
  692. // op.Done will return true, and the response of the operation is returned.
  693. // If Poll succeeds and the operation has not completed, the returned response and error are both nil.
  694. func (op *UpdateInstanceOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*redispb.Instance, error) {
  695. var resp redispb.Instance
  696. if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
  697. return nil, err
  698. }
  699. if !op.Done() {
  700. return nil, nil
  701. }
  702. return &resp, nil
  703. }
  704. // Metadata returns metadata associated with the long-running operation.
  705. // Metadata itself does not contact the server, but Poll does.
  706. // To get the latest metadata, call this method after a successful call to Poll.
  707. // If the metadata is not available, the returned metadata and error are both nil.
  708. func (op *UpdateInstanceOperation) Metadata() (*redispb.OperationMetadata, error) {
  709. var meta redispb.OperationMetadata
  710. if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
  711. return nil, nil
  712. } else if err != nil {
  713. return nil, err
  714. }
  715. return &meta, nil
  716. }
  717. // Done reports whether the long-running operation has completed.
  718. func (op *UpdateInstanceOperation) Done() bool {
  719. return op.lro.Done()
  720. }
  721. // Name returns the name of the long-running operation.
  722. // The name is assigned by the server and is unique within the service from which the operation is created.
  723. func (op *UpdateInstanceOperation) Name() string {
  724. return op.lro.Name()
  725. }