gcloud 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +8 -8
  2. data/AUTHENTICATION.md +3 -3
  3. data/CHANGELOG.md +92 -0
  4. data/OVERVIEW.md +3 -3
  5. data/lib/gcloud.rb +75 -25
  6. data/lib/gcloud/backoff.rb +5 -1
  7. data/lib/gcloud/bigquery.rb +25 -43
  8. data/lib/gcloud/bigquery/copy_job.rb +13 -13
  9. data/lib/gcloud/bigquery/data.rb +20 -16
  10. data/lib/gcloud/bigquery/dataset.rb +202 -177
  11. data/lib/gcloud/bigquery/dataset/access.rb +118 -104
  12. data/lib/gcloud/bigquery/dataset/list.rb +14 -18
  13. data/lib/gcloud/bigquery/extract_job.rb +12 -12
  14. data/lib/gcloud/bigquery/insert_response.rb +12 -14
  15. data/lib/gcloud/bigquery/job.rb +45 -57
  16. data/lib/gcloud/bigquery/job/list.rb +18 -24
  17. data/lib/gcloud/bigquery/load_job.rb +35 -27
  18. data/lib/gcloud/bigquery/project.rb +53 -73
  19. data/lib/gcloud/bigquery/query_data.rb +28 -35
  20. data/lib/gcloud/bigquery/query_job.rb +18 -18
  21. data/lib/gcloud/bigquery/schema.rb +359 -0
  22. data/lib/gcloud/bigquery/service.rb +506 -0
  23. data/lib/gcloud/bigquery/table.rb +185 -266
  24. data/lib/gcloud/bigquery/table/list.rb +15 -19
  25. data/lib/gcloud/bigquery/view.rb +126 -81
  26. data/lib/gcloud/datastore.rb +39 -27
  27. data/lib/gcloud/datastore/commit.rb +2 -2
  28. data/lib/gcloud/datastore/dataset.rb +8 -19
  29. data/lib/gcloud/datastore/dataset/lookup_results.rb +2 -4
  30. data/lib/gcloud/datastore/dataset/query_results.rb +0 -2
  31. data/lib/gcloud/datastore/entity.rb +7 -1
  32. data/lib/gcloud/datastore/errors.rb +5 -27
  33. data/lib/gcloud/datastore/grpc_utils.rb +4 -3
  34. data/lib/gcloud/datastore/key.rb +6 -0
  35. data/lib/gcloud/datastore/service.rb +18 -12
  36. data/lib/gcloud/datastore/transaction.rb +0 -10
  37. data/lib/gcloud/dns.rb +29 -19
  38. data/lib/gcloud/dns/change.rb +10 -15
  39. data/lib/gcloud/dns/change/list.rb +4 -4
  40. data/lib/gcloud/dns/importer.rb +1 -1
  41. data/lib/gcloud/dns/project.rb +32 -49
  42. data/lib/gcloud/dns/record.rb +8 -2
  43. data/lib/gcloud/dns/record/list.rb +4 -4
  44. data/lib/gcloud/dns/service.rb +167 -0
  45. data/lib/gcloud/dns/zone.rb +33 -52
  46. data/lib/gcloud/dns/zone/list.rb +12 -16
  47. data/lib/gcloud/errors.rb +31 -19
  48. data/lib/gcloud/logging.rb +50 -39
  49. data/lib/gcloud/logging/entry.rb +197 -24
  50. data/lib/gcloud/logging/entry/list.rb +0 -2
  51. data/lib/gcloud/logging/logger.rb +1 -1
  52. data/lib/gcloud/logging/metric.rb +3 -9
  53. data/lib/gcloud/logging/metric/list.rb +0 -2
  54. data/lib/gcloud/logging/project.rb +58 -54
  55. data/lib/gcloud/logging/resource_descriptor.rb +2 -2
  56. data/lib/gcloud/logging/resource_descriptor/list.rb +0 -2
  57. data/lib/gcloud/logging/service.rb +32 -23
  58. data/lib/gcloud/logging/sink.rb +8 -14
  59. data/lib/gcloud/logging/sink/list.rb +0 -2
  60. data/lib/gcloud/pubsub.rb +21 -16
  61. data/lib/gcloud/pubsub/policy.rb +204 -0
  62. data/lib/gcloud/pubsub/project.rb +26 -38
  63. data/lib/gcloud/pubsub/service.rb +39 -31
  64. data/lib/gcloud/pubsub/subscription.rb +56 -59
  65. data/lib/gcloud/pubsub/subscription/list.rb +4 -4
  66. data/lib/gcloud/pubsub/topic.rb +69 -66
  67. data/lib/gcloud/pubsub/topic/list.rb +0 -2
  68. data/lib/gcloud/pubsub/topic/{batch.rb → publisher.rb} +15 -2
  69. data/lib/gcloud/resource_manager.rb +27 -26
  70. data/lib/gcloud/resource_manager/manager.rb +19 -39
  71. data/lib/gcloud/resource_manager/policy.rb +211 -0
  72. data/lib/gcloud/resource_manager/project.rb +97 -121
  73. data/lib/gcloud/resource_manager/project/list.rb +7 -7
  74. data/lib/gcloud/resource_manager/project/updater.rb +4 -9
  75. data/lib/gcloud/resource_manager/service.rb +127 -0
  76. data/lib/gcloud/storage.rb +24 -42
  77. data/lib/gcloud/storage/bucket.rb +104 -192
  78. data/lib/gcloud/storage/bucket/acl.rb +47 -143
  79. data/lib/gcloud/storage/bucket/cors.rb +55 -11
  80. data/lib/gcloud/storage/bucket/list.rb +14 -14
  81. data/lib/gcloud/storage/errors.rb +3 -43
  82. data/lib/gcloud/storage/file.rb +114 -111
  83. data/lib/gcloud/storage/file/acl.rb +27 -113
  84. data/lib/gcloud/storage/file/list.rb +21 -21
  85. data/lib/gcloud/storage/project.rb +49 -59
  86. data/lib/gcloud/storage/service.rb +347 -0
  87. data/lib/gcloud/translate.rb +24 -14
  88. data/lib/gcloud/translate/api.rb +12 -21
  89. data/lib/gcloud/translate/detection.rb +5 -5
  90. data/lib/gcloud/translate/language.rb +1 -1
  91. data/lib/gcloud/translate/service.rb +80 -0
  92. data/lib/gcloud/translate/translation.rb +6 -6
  93. data/lib/gcloud/version.rb +1 -1
  94. data/lib/gcloud/vision.rb +24 -15
  95. data/lib/gcloud/vision/annotate.rb +24 -21
  96. data/lib/gcloud/vision/annotation.rb +9 -9
  97. data/lib/gcloud/vision/annotation/entity.rb +11 -11
  98. data/lib/gcloud/vision/annotation/face.rb +25 -25
  99. data/lib/gcloud/vision/annotation/properties.rb +8 -8
  100. data/lib/gcloud/vision/annotation/safe_search.rb +4 -4
  101. data/lib/gcloud/vision/annotation/text.rb +7 -7
  102. data/lib/gcloud/vision/annotation/vertex.rb +1 -1
  103. data/lib/gcloud/vision/image.rb +11 -11
  104. data/lib/gcloud/vision/location.rb +5 -2
  105. data/lib/gcloud/vision/project.rb +14 -16
  106. data/lib/gcloud/vision/service.rb +66 -0
  107. data/lib/google/api_client.rb +0 -0
  108. metadata +27 -24
  109. data/lib/gcloud/bigquery/connection.rb +0 -624
  110. data/lib/gcloud/bigquery/errors.rb +0 -68
  111. data/lib/gcloud/bigquery/table/schema.rb +0 -234
  112. data/lib/gcloud/dns/connection.rb +0 -173
  113. data/lib/gcloud/dns/errors.rb +0 -68
  114. data/lib/gcloud/resource_manager/connection.rb +0 -134
  115. data/lib/gcloud/resource_manager/errors.rb +0 -68
  116. data/lib/gcloud/storage/connection.rb +0 -444
  117. data/lib/gcloud/translate/connection.rb +0 -85
  118. data/lib/gcloud/translate/errors.rb +0 -68
  119. data/lib/gcloud/upload.rb +0 -95
  120. data/lib/gcloud/vision/connection.rb +0 -63
  121. data/lib/gcloud/vision/errors.rb +0 -69
@@ -39,6 +39,9 @@ module Gcloud
39
39
  # The default scope is:
40
40
  #
41
41
  # * `https://www.googleapis.com/auth/datastore`
42
+ # @param [Integer] retries Number of times to retry requests on server error.
43
+ # The default value is `3`. Optional.
44
+ # @param [Integer] timeout Default timeout to use in requests. Optional.
42
45
  #
43
46
  # @return [Gcloud::Datastore::Dataset]
44
47
  #
@@ -57,19 +60,28 @@ module Gcloud
57
60
  #
58
61
  # datastore.save task
59
62
  #
60
- def self.datastore project = nil, keyfile = nil, scope: nil
63
+ def self.datastore project = nil, keyfile = nil, scope: nil, retries: nil,
64
+ timeout: nil
61
65
  project ||= Gcloud::Datastore::Dataset.default_project
66
+ project = project.to_s # Always cast to a string
67
+ fail ArgumentError, "project is missing" if project.empty?
68
+
62
69
  if ENV["DATASTORE_EMULATOR_HOST"]
63
- ds = Gcloud::Datastore::Dataset.new project, :this_channel_is_insecure
64
- ds.service.host = ENV["DATASTORE_EMULATOR_HOST"]
65
- return ds
70
+ return Gcloud::Datastore::Dataset.new(
71
+ Gcloud::Datastore::Service.new(
72
+ project, :this_channel_is_insecure,
73
+ host: ENV["DATASTORE_EMULATOR_HOST"], retries: retries))
66
74
  end
75
+
67
76
  if keyfile.nil?
68
77
  credentials = Gcloud::Datastore::Credentials.default scope: scope
69
78
  else
70
79
  credentials = Gcloud::Datastore::Credentials.new keyfile, scope: scope
71
80
  end
72
- Gcloud::Datastore::Dataset.new project, credentials
81
+
82
+ Gcloud::Datastore::Dataset.new(
83
+ Gcloud::Datastore::Service.new(
84
+ project, credentials, retries: retries, timeout: timeout))
73
85
  end
74
86
 
75
87
  ##
@@ -80,7 +92,7 @@ module Gcloud
80
92
  # relational databases, but there are some key differences to be aware of to
81
93
  # make the most of using Datastore.
82
94
  #
83
- # Gcloud's goal is to provide a API that is familiar and comfortable to
95
+ # The goal of gcloud-ruby is to provide a API that is comfortable to
84
96
  # Rubyists. Authentication is handled by {Gcloud#datastore}. You can provide
85
97
  # the project and credential information to connect to the Datastore service,
86
98
  # or if you are running on Google Compute Engine this configuration is taken
@@ -507,43 +519,43 @@ module Gcloud
507
519
  # end
508
520
  # ```
509
521
  #
510
- # ## Configuring Backoff
522
+ # ## Configuring retries and timeout
511
523
  #
512
- # The {Gcloud::Backoff} class allows users to globally configure how Cloud API
513
- # requests are automatically retried in the case of some errors, such as a
514
- # `500` or `503` status code, or a specific internal error code such as
515
- # `rateLimitExceeded`.
524
+ # You can configure how many times API requests may be automatically retried.
525
+ # When an API request fails, the response will be inspected to see if the
526
+ # request meets criteria indicating that it may succeed on retry, such as
527
+ # `500` and `503` status codes or a specific internal error code such as
528
+ # `rateLimitExceeded`. If it meets the criteria, the request will be retried
529
+ # after a delay. If another error occurs, the delay will be increased before a
530
+ # subsequent attempt, until the `retries` limit is reached.
516
531
  #
517
- # If an API call fails, the response will be inspected to see if the call
518
- # should be retried. If the response matches the criteria, then the request
519
- # will be retried after a delay. If another error occurs, the delay will be
520
- # increased incrementally before a subsequent attempt. The first retry will be
521
- # delayed one second, the second retry two seconds, and so on.
532
+ # You can also set the request `timeout` value in seconds.
522
533
  #
523
534
  # ```ruby
524
535
  # require "gcloud"
525
- # require "gcloud/backoff"
526
536
  #
527
- # Gcloud::Backoff.retries = 5 # Raise the maximum number of retries from 3
537
+ # gcloud = Gcloud.new
538
+ # datastore = gcloud.datastore retries: 10, timeout: 120
528
539
  # ```
529
540
  #
530
541
  # See the [Datastore error
531
542
  # codes](https://cloud.google.com/datastore/docs/concepts/errors#error_codes)
532
543
  # for a list of error conditions.
533
544
  #
534
- # ## The Datastore Emulator
545
+ # ## The Cloud Datastore Emulator
535
546
  #
536
- # As of this release, the Datastore emulator that is part of the gcloud SDK is
537
- # no longer compatible with gcloud-ruby. This is because the gcloud SDK's
538
- # Datastore emulator does not yet support gRPC as a transport layer.
547
+ # As of this release, the Cloud Datastore emulator that is part of the gcloud
548
+ # SDK is no longer compatible with gcloud-ruby. This is because the gcloud
549
+ # SDK's Cloud Datastore emulator does not yet support gRPC as a transport
550
+ # layer.
539
551
  #
540
- # A gRPC-compatible emulator is available until the gcloud SDK Datastore
552
+ # A gRPC-compatible emulator is available until the gcloud SDK Cloud Datastore
541
553
  # emulator supports gRPC. To use it you must [download the gRPC
542
- # emulator](https://storage.googleapis.com/gcd/tools/gcd-grpc-1.0.0.zip) and
543
- # use the `gcd.sh` script.
554
+ # emulator](https://storage.googleapis.com/gcd/tools/cloud-datastore-emulator-1.1.1.zip)
555
+ # and use the `cloud_datastore_emulator` script.
544
556
  #
545
- # When you run the gRPC emulator you will see a message similar to the
546
- # following printed:
557
+ # When you run the Cloud Datastore emulator you will see a message similar to
558
+ # the following printed:
547
559
  #
548
560
  # ```
549
561
  # If you are using a library that supports the DATASTORE_EMULATOR_HOST
@@ -29,8 +29,8 @@ module Gcloud
29
29
  # c.delete entity1, entity2
30
30
  # end
31
31
  #
32
- # @see {Gcloud::Datastore::Dataset#commit}
33
- # @see {Gcloud::Datastore::Transaction#commit}
32
+ # See {Gcloud::Datastore::Dataset#commit} and
33
+ # {Gcloud::Datastore::Transaction#commit}.
34
34
  class Commit
35
35
  ##
36
36
  # @private Create a new Commit object.
@@ -60,10 +60,8 @@ module Gcloud
60
60
  # @private Creates a new Dataset instance.
61
61
  #
62
62
  # See {Gcloud#datastore}
63
- def initialize project, credentials
64
- project = project.to_s # Always cast to a string
65
- fail ArgumentError, "project is missing" if project.empty?
66
- @service = Service.new project, credentials
63
+ def initialize service
64
+ @service = service
67
65
  end
68
66
 
69
67
  ##
@@ -106,15 +104,14 @@ module Gcloud
106
104
  #
107
105
  def allocate_ids incomplete_key, count = 1
108
106
  if incomplete_key.complete?
109
- fail Gcloud::Datastore::Error, "An incomplete key must be provided."
107
+ fail Gcloud::Datastore::KeyError,
108
+ "An incomplete key must be provided."
110
109
  end
111
110
 
112
111
  ensure_service!
113
112
  incomplete_keys = count.times.map { incomplete_key.to_grpc }
114
113
  allocate_res = service.allocate_ids(*incomplete_keys)
115
114
  allocate_res.keys.map { |key| Key.from_grpc key }
116
- rescue GRPC::BadStatus => e
117
- raise Gcloud::Error.from_error(e)
118
115
  end
119
116
 
120
117
  ##
@@ -275,8 +272,6 @@ module Gcloud
275
272
  end
276
273
  entities.each { |e| e.key.freeze unless e.persisted? }
277
274
  entities
278
- rescue GRPC::BadStatus => e
279
- raise Gcloud::Error.from_error(e)
280
275
  end
281
276
 
282
277
  ##
@@ -342,8 +337,6 @@ module Gcloud
342
337
  lookup_res = service.lookup(*Array(keys).flatten.map(&:to_grpc),
343
338
  consistency: consistency)
344
339
  LookupResults.from_grpc lookup_res, service, consistency
345
- rescue GRPC::BadStatus => e
346
- raise Gcloud::Error.from_error(e)
347
340
  end
348
341
  alias_method :lookup, :find_all
349
342
 
@@ -399,8 +392,6 @@ module Gcloud
399
392
  query_res = service.run_query query.to_grpc, namespace,
400
393
  consistency: consistency
401
394
  QueryResults.from_grpc query_res, service, namespace, query.to_grpc.dup
402
- rescue GRPC::BadStatus => e
403
- raise Gcloud::Error.from_error(e)
404
395
  end
405
396
  alias_method :run_query, :run
406
397
 
@@ -459,15 +450,13 @@ module Gcloud
459
450
  begin
460
451
  yield tx
461
452
  tx.commit
462
- rescue => e
453
+ rescue
463
454
  begin
464
455
  tx.rollback
465
- rescue => re
466
- msg = "Transaction failed to commit and rollback."
467
- raise TransactionError.new(msg, commit_error: e, rollback_error: re)
456
+ rescue
457
+ raise TransactionError, "Transaction failed to commit and rollback."
468
458
  end
469
- raise TransactionError.new("Transaction failed to commit.",
470
- commit_error: e)
459
+ raise TransactionError, "Transaction failed to commit."
471
460
  end
472
461
  end
473
462
 
@@ -101,8 +101,6 @@ module Gcloud
101
101
  consistency: @consistency,
102
102
  transaction: @transaction)
103
103
  self.class.from_grpc lookup_res, @service, @consistency
104
- rescue GRPC::BadStatus => e
105
- raise Gcloud::Error.from_error(e)
106
104
  end
107
105
 
108
106
  ##
@@ -200,7 +198,7 @@ module Gcloud
200
198
  end
201
199
 
202
200
  ##
203
- # Convenience method to convert GRPC entities to Gcloud entities.
201
+ # Convenience method to convert GRPC entities to gcloud-ruby entities.
204
202
  def self.to_gcloud_entities grpc_entity_results
205
203
  # Entities are nested in an object.
206
204
  Array(grpc_entity_results).map do |result|
@@ -210,7 +208,7 @@ module Gcloud
210
208
  end
211
209
 
212
210
  ##
213
- # Convenience method to convert GRPC keys to Gcloud keys.
211
+ # Convenience method to convert GRPC keys to gcloud-ruby keys.
214
212
  def self.to_gcloud_keys grpc_keys
215
213
  # Keys are not nested in an object like entities are.
216
214
  Array(grpc_keys).map { |key| Key.from_grpc key }
@@ -160,8 +160,6 @@ module Gcloud
160
160
  query.start_cursor = cursor.to_grpc # should always be a Cursor...
161
161
  query_res = service.run_query query, namespace
162
162
  self.class.from_grpc query_res, service, namespace, query
163
- rescue GRPC::BadStatus => e
164
- raise Gcloud::Error.from_error(e)
165
163
  end
166
164
 
167
165
  ##
@@ -350,6 +350,12 @@ module Gcloud
350
350
  end
351
351
  end
352
352
 
353
+ ##
354
+ # The number of bytes the Entity will take to serialize during API calls.
355
+ def serialized_size
356
+ to_grpc.to_proto.length
357
+ end
358
+
353
359
  ##
354
360
  # @private Convert the Entity to a Google::Datastore::V1beta3::Entity
355
361
  # object.
@@ -415,7 +421,7 @@ module Gcloud
415
421
  next if value.nil?
416
422
  @_exclude_indexes[name] = value.exclude_from_indexes
417
423
  unless value.array_value.nil?
418
- exclude = value.array_value.values.map &:exclude_from_indexes
424
+ exclude = value.array_value.values.map(&:exclude_from_indexes)
419
425
  @_exclude_indexes[name] = exclude
420
426
  end
421
427
  end
@@ -18,46 +18,24 @@ require "gcloud/errors"
18
18
  module Gcloud
19
19
  module Datastore
20
20
  ##
21
- # # Datastore Error
21
+ # # KeyError
22
22
  #
23
- # Base Datastore exception class.
24
- class Error < Gcloud::Error
25
- end
26
-
27
- ##
28
- # # KeyfileError
29
- #
30
- # Raised when a keyfile is not correct.
31
- class KeyfileError < Gcloud::Datastore::Error
23
+ # Raised when a key is not correct.
24
+ class KeyError < Gcloud::Error
32
25
  end
33
26
 
34
27
  ##
35
28
  # # PropertyError
36
29
  #
37
30
  # Raised when a property is not correct.
38
- class PropertyError < Gcloud::Datastore::Error
31
+ class PropertyError < Gcloud::Error
39
32
  end
40
33
 
41
34
  ##
42
35
  # # TransactionError
43
36
  #
44
37
  # General error for Transaction problems.
45
- class TransactionError < Gcloud::Datastore::Error
46
- ##
47
- # An error that occurred within the transaction. (optional)
48
- attr_reader :commit_error
49
- alias_method :inner, :commit_error # backwards compatibility
50
-
51
- ##
52
- # An error that occurred within the transaction. (optional)
53
- attr_reader :rollback_error
54
-
55
- # @private
56
- def initialize message, commit_error: nil, rollback_error: nil
57
- super(message)
58
- @commit_error = commit_error
59
- @rollback_error = rollback_error
60
- end
38
+ class TransactionError < Gcloud::Error
61
39
  end
62
40
  end
63
41
  end
@@ -16,6 +16,7 @@
16
16
  require "gcloud/grpc_utils"
17
17
  require "gcloud/datastore/errors"
18
18
  require "stringio"
19
+ require "base64"
19
20
 
20
21
  module Gcloud
21
22
  ##
@@ -102,7 +103,7 @@ module Gcloud
102
103
  v.string_value = value
103
104
  elsif Array === value
104
105
  v.array_value = Google::Datastore::V1beta3::ArrayValue.new(
105
- values: value.map { |v| to_value v }
106
+ values: value.map { |val| to_value val }
106
107
  )
107
108
  elsif value.respond_to? :to_time
108
109
  v.timestamp_value = Google::Protobuf::Timestamp.new(
@@ -120,11 +121,11 @@ module Gcloud
120
121
  end
121
122
 
122
123
  def self.encode_bytes bytes
123
- Array(bytes.to_s).pack("m").chomp.encode("ASCII-8BIT")
124
+ Base64.strict_encode64(bytes.to_s).encode("ASCII-8BIT")
124
125
  end
125
126
 
126
127
  def self.decode_bytes bytes
127
- bytes.to_s.unpack("m").first.force_encoding Encoding::ASCII_8BIT
128
+ Base64.decode64(bytes.to_s).force_encoding Encoding::ASCII_8BIT
128
129
  end
129
130
  # rubocop:enable all
130
131
  end
@@ -232,6 +232,12 @@ module Gcloud
232
232
  kind.nil? || (id.nil? && (name.nil? || name.empty?))
233
233
  end
234
234
 
235
+ ##
236
+ # The number of bytes the Key will take to serialize during API calls.
237
+ def serialized_size
238
+ to_grpc.to_proto.length
239
+ end
240
+
235
241
  ##
236
242
  # @private Convert the Key to a Google::Datastore::V1beta3::Key object.
237
243
  def to_grpc
@@ -23,14 +23,16 @@ module Gcloud
23
23
  # @private Represents the gRPC Datastore service, including all the API
24
24
  # methods.
25
25
  class Service
26
- attr_accessor :project, :credentials, :host
26
+ attr_accessor :project, :credentials, :host, :retries, :timeout
27
27
 
28
28
  ##
29
29
  # Creates a new Service instance.
30
- def initialize project, credentials
30
+ def initialize project, credentials, host: nil, retries: nil, timeout: nil
31
31
  @project = project
32
32
  @credentials = credentials
33
- @host = "datastore.googleapis.com"
33
+ @host = host || "datastore.googleapis.com"
34
+ @retries = retries
35
+ @timeout = timeout
34
36
  end
35
37
 
36
38
  def creds
@@ -42,7 +44,7 @@ module Gcloud
42
44
  def datastore
43
45
  return mocked_datastore if mocked_datastore
44
46
  @datastore ||= Google::Datastore::V1beta3::Datastore::Stub.new(
45
- host, creds)
47
+ host, creds, timeout: timeout)
46
48
  end
47
49
  attr_accessor :mocked_datastore
48
50
 
@@ -59,7 +61,7 @@ module Gcloud
59
61
  keys: incomplete_keys
60
62
  )
61
63
 
62
- backoff { datastore.allocate_ids allocate_req }
64
+ execute { datastore.allocate_ids allocate_req }
63
65
  end
64
66
 
65
67
  ##
@@ -71,7 +73,7 @@ module Gcloud
71
73
  )
72
74
  lookup_req.read_options = generate_read_options consistency, transaction
73
75
 
74
- backoff { datastore.lookup lookup_req }
76
+ execute { datastore.lookup lookup_req }
75
77
  end
76
78
 
77
79
  # Query for entities.
@@ -90,7 +92,7 @@ module Gcloud
90
92
  run_req.partition_id = Google::Datastore::V1beta3::PartitionId.new(
91
93
  namespace_id: namespace) if namespace
92
94
 
93
- backoff { datastore.run_query run_req }
95
+ execute { datastore.run_query run_req }
94
96
  end
95
97
 
96
98
  ##
@@ -100,7 +102,7 @@ module Gcloud
100
102
  project_id: project
101
103
  )
102
104
 
103
- backoff { datastore.begin_transaction tx_req }
105
+ execute { datastore.begin_transaction tx_req }
104
106
  end
105
107
 
106
108
  ##
@@ -117,7 +119,7 @@ module Gcloud
117
119
  commit_req.transaction = transaction
118
120
  end
119
121
 
120
- backoff { datastore.commit commit_req }
122
+ execute { datastore.commit commit_req }
121
123
  end
122
124
 
123
125
  ##
@@ -128,17 +130,21 @@ module Gcloud
128
130
  transaction: transaction
129
131
  )
130
132
 
131
- backoff { datastore.rollback rb_req }
133
+ execute { datastore.rollback rb_req }
132
134
  end
133
135
 
134
136
  def inspect
135
137
  "#{self.class}(#{@project})"
136
138
  end
137
139
 
138
- def backoff options = {}
139
- Gcloud::Backoff.new(options).execute_grpc do
140
+ ##
141
+ # Performs backoff and error handling
142
+ def execute
143
+ Gcloud::Backoff.new(retries: retries).execute_grpc do
140
144
  yield
141
145
  end
146
+ rescue GRPC::BadStatus => e
147
+ raise Gcloud::Error.from_error(e)
142
148
  end
143
149
 
144
150
  protected