gcloud 0.12.2 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/gcloud.rb +27 -456
- data/lib/gcloud/bigquery.rb +2 -382
- data/lib/gcloud/datastore.rb +2 -576
- data/lib/gcloud/dns.rb +2 -321
- data/lib/gcloud/logging.rb +1 -322
- data/lib/gcloud/pubsub.rb +2 -476
- data/lib/gcloud/resource_manager.rb +2 -273
- data/lib/gcloud/storage.rb +2 -440
- data/lib/gcloud/translate.rb +1 -250
- data/lib/gcloud/version.rb +2 -2
- data/lib/gcloud/vision.rb +1 -501
- metadata +36 -332
- data/AUTHENTICATION.md +0 -75
- data/CHANGELOG.md +0 -382
- data/OVERVIEW.md +0 -259
- data/lib/gcloud/backoff.rb +0 -150
- data/lib/gcloud/bigquery/copy_job.rb +0 -97
- data/lib/gcloud/bigquery/credentials.rb +0 -29
- data/lib/gcloud/bigquery/data.rb +0 -239
- data/lib/gcloud/bigquery/dataset.rb +0 -753
- data/lib/gcloud/bigquery/dataset/access.rb +0 -507
- data/lib/gcloud/bigquery/dataset/list.rb +0 -169
- data/lib/gcloud/bigquery/extract_job.rb +0 -117
- data/lib/gcloud/bigquery/insert_response.rb +0 -81
- data/lib/gcloud/bigquery/job.rb +0 -299
- data/lib/gcloud/bigquery/job/list.rb +0 -172
- data/lib/gcloud/bigquery/load_job.rb +0 -202
- data/lib/gcloud/bigquery/project.rb +0 -475
- data/lib/gcloud/bigquery/query_data.rb +0 -234
- data/lib/gcloud/bigquery/query_job.rb +0 -137
- data/lib/gcloud/bigquery/schema.rb +0 -359
- data/lib/gcloud/bigquery/service.rb +0 -506
- data/lib/gcloud/bigquery/table.rb +0 -1141
- data/lib/gcloud/bigquery/table/list.rb +0 -180
- data/lib/gcloud/bigquery/view.rb +0 -475
- data/lib/gcloud/credentials.rb +0 -129
- data/lib/gcloud/datastore/commit.rb +0 -148
- data/lib/gcloud/datastore/credentials.rb +0 -35
- data/lib/gcloud/datastore/cursor.rb +0 -76
- data/lib/gcloud/datastore/dataset.rb +0 -660
- data/lib/gcloud/datastore/dataset/lookup_results.rb +0 -219
- data/lib/gcloud/datastore/dataset/query_results.rb +0 -386
- data/lib/gcloud/datastore/entity.rb +0 -449
- data/lib/gcloud/datastore/errors.rb +0 -41
- data/lib/gcloud/datastore/gql_query.rb +0 -211
- data/lib/gcloud/datastore/grpc_utils.rb +0 -132
- data/lib/gcloud/datastore/key.rb +0 -281
- data/lib/gcloud/datastore/properties.rb +0 -128
- data/lib/gcloud/datastore/query.rb +0 -348
- data/lib/gcloud/datastore/service.rb +0 -167
- data/lib/gcloud/datastore/transaction.rb +0 -362
- data/lib/gcloud/dns/change.rb +0 -158
- data/lib/gcloud/dns/change/list.rb +0 -173
- data/lib/gcloud/dns/credentials.rb +0 -29
- data/lib/gcloud/dns/importer.rb +0 -183
- data/lib/gcloud/dns/project.rb +0 -247
- data/lib/gcloud/dns/record.rb +0 -170
- data/lib/gcloud/dns/record/list.rb +0 -174
- data/lib/gcloud/dns/service.rb +0 -167
- data/lib/gcloud/dns/zone.rb +0 -759
- data/lib/gcloud/dns/zone/list.rb +0 -168
- data/lib/gcloud/dns/zone/transaction.rb +0 -176
- data/lib/gcloud/errors.rb +0 -206
- data/lib/gcloud/gce.rb +0 -56
- data/lib/gcloud/grpc_utils.rb +0 -87
- data/lib/gcloud/logging/credentials.rb +0 -29
- data/lib/gcloud/logging/entry.rb +0 -465
- data/lib/gcloud/logging/entry/http_request.rb +0 -141
- data/lib/gcloud/logging/entry/list.rb +0 -177
- data/lib/gcloud/logging/entry/operation.rb +0 -90
- data/lib/gcloud/logging/logger.rb +0 -307
- data/lib/gcloud/logging/metric.rb +0 -169
- data/lib/gcloud/logging/metric/list.rb +0 -172
- data/lib/gcloud/logging/project.rb +0 -642
- data/lib/gcloud/logging/resource.rb +0 -84
- data/lib/gcloud/logging/resource_descriptor.rb +0 -137
- data/lib/gcloud/logging/resource_descriptor/list.rb +0 -174
- data/lib/gcloud/logging/service.rb +0 -267
- data/lib/gcloud/logging/sink.rb +0 -227
- data/lib/gcloud/logging/sink/list.rb +0 -171
- data/lib/gcloud/pubsub/credentials.rb +0 -29
- data/lib/gcloud/pubsub/message.rb +0 -94
- data/lib/gcloud/pubsub/policy.rb +0 -204
- data/lib/gcloud/pubsub/project.rb +0 -482
- data/lib/gcloud/pubsub/received_message.rb +0 -160
- data/lib/gcloud/pubsub/service.rb +0 -334
- data/lib/gcloud/pubsub/subscription.rb +0 -565
- data/lib/gcloud/pubsub/subscription/list.rb +0 -208
- data/lib/gcloud/pubsub/topic.rb +0 -511
- data/lib/gcloud/pubsub/topic/list.rb +0 -174
- data/lib/gcloud/pubsub/topic/publisher.rb +0 -85
- data/lib/gcloud/resource_manager/credentials.rb +0 -30
- data/lib/gcloud/resource_manager/manager.rb +0 -266
- data/lib/gcloud/resource_manager/policy.rb +0 -211
- data/lib/gcloud/resource_manager/project.rb +0 -484
- data/lib/gcloud/resource_manager/project/list.rb +0 -167
- data/lib/gcloud/resource_manager/project/updater.rb +0 -130
- data/lib/gcloud/resource_manager/service.rb +0 -127
- data/lib/gcloud/storage/bucket.rb +0 -775
- data/lib/gcloud/storage/bucket/acl.rb +0 -810
- data/lib/gcloud/storage/bucket/cors.rb +0 -153
- data/lib/gcloud/storage/bucket/list.rb +0 -172
- data/lib/gcloud/storage/credentials.rb +0 -29
- data/lib/gcloud/storage/errors.rb +0 -65
- data/lib/gcloud/storage/file.rb +0 -842
- data/lib/gcloud/storage/file/acl.rb +0 -425
- data/lib/gcloud/storage/file/list.rb +0 -191
- data/lib/gcloud/storage/file/verifier.rb +0 -67
- data/lib/gcloud/storage/project.rb +0 -316
- data/lib/gcloud/storage/service.rb +0 -347
- data/lib/gcloud/translate/api.rb +0 -241
- data/lib/gcloud/translate/detection.rb +0 -137
- data/lib/gcloud/translate/language.rb +0 -69
- data/lib/gcloud/translate/service.rb +0 -80
- data/lib/gcloud/translate/translation.rb +0 -112
- data/lib/gcloud/vision/annotate.rb +0 -224
- data/lib/gcloud/vision/annotation.rb +0 -455
- data/lib/gcloud/vision/annotation/entity.rb +0 -234
- data/lib/gcloud/vision/annotation/face.rb +0 -1750
- data/lib/gcloud/vision/annotation/properties.rb +0 -245
- data/lib/gcloud/vision/annotation/safe_search.rb +0 -161
- data/lib/gcloud/vision/annotation/text.rb +0 -236
- data/lib/gcloud/vision/annotation/vertex.rb +0 -108
- data/lib/gcloud/vision/credentials.rb +0 -29
- data/lib/gcloud/vision/image.rb +0 -590
- data/lib/gcloud/vision/location.rb +0 -115
- data/lib/gcloud/vision/project.rb +0 -278
- data/lib/gcloud/vision/service.rb +0 -66
- data/lib/google/api/annotations.rb +0 -14
- data/lib/google/api/http.rb +0 -30
- data/lib/google/api/label.rb +0 -24
- data/lib/google/api/monitored_resource.rb +0 -25
- data/lib/google/datastore/v1beta3/datastore.rb +0 -115
- data/lib/google/datastore/v1beta3/datastore_services.rb +0 -33
- data/lib/google/datastore/v1beta3/entity.rb +0 -63
- data/lib/google/datastore/v1beta3/query.rb +0 -128
- data/lib/google/devtools/cloudtrace/v1/trace.rb +0 -78
- data/lib/google/devtools/cloudtrace/v1/trace_services.rb +0 -32
- data/lib/google/example/library/v1/library.rb +0 -91
- data/lib/google/example/library/v1/library_services.rb +0 -40
- data/lib/google/iam/v1/iam_policy.rb +0 -33
- data/lib/google/iam/v1/iam_policy_services.rb +0 -30
- data/lib/google/iam/v1/policy.rb +0 -25
- data/lib/google/logging/type/http_request.rb +0 -28
- data/lib/google/logging/type/log_severity.rb +0 -27
- data/lib/google/logging/v2/log_entry.rb +0 -44
- data/lib/google/logging/v2/logging.rb +0 -56
- data/lib/google/logging/v2/logging_config.rb +0 -59
- data/lib/google/logging/v2/logging_config_services.rb +0 -32
- data/lib/google/logging/v2/logging_metrics.rb +0 -51
- data/lib/google/logging/v2/logging_metrics_services.rb +0 -32
- data/lib/google/logging/v2/logging_services.rb +0 -31
- data/lib/google/longrunning/operations.rb +0 -50
- data/lib/google/longrunning/operations_services.rb +0 -29
- data/lib/google/protobuf/descriptor.rb +0 -0
- data/lib/google/pubsub/v1/pubsub.rb +0 -129
- data/lib/google/pubsub/v1/pubsub_services.rb +0 -56
- data/lib/google/pubsub/v1beta2/pubsub.rb +0 -126
- data/lib/google/pubsub/v1beta2/pubsub_services.rb +0 -56
- data/lib/google/rpc/code.rb +0 -32
- data/lib/google/rpc/error_details.rb +0 -61
- data/lib/google/rpc/status.rb +0 -19
- data/lib/google/type/color.rb +0 -20
- data/lib/google/type/date.rb +0 -18
- data/lib/google/type/dayofweek.rb +0 -23
- data/lib/google/type/latlng.rb +0 -17
- data/lib/google/type/money.rb +0 -18
- data/lib/google/type/timeofday.rb +0 -19
data/OVERVIEW.md
DELETED
@@ -1,259 +0,0 @@
|
|
1
|
-
# Getting started
|
2
|
-
|
3
|
-
The gcloud-ruby library is installable through rubygems:
|
4
|
-
|
5
|
-
```sh
|
6
|
-
$ gem install gcloud
|
7
|
-
```
|
8
|
-
|
9
|
-
The gcloud-ruby library aims to make authentication as simple as possible. Google Cloud requires a **Project ID** and **Service Account Credentials** to connect to the APIs. You can learn more about various options for connection on the [Authentication Guide](https://googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).
|
10
|
-
|
11
|
-
# BigQuery
|
12
|
-
|
13
|
-
[Google Cloud BigQuery](https://cloud.google.com/bigquery/) ([docs](https://cloud.google.com/bigquery/docs)) enables super-fast, SQL-like queries against append-only tables, using the processing power of Google's infrastructure. Simply move your data into BigQuery and let it handle the hard work. You can control access to both the project and your data based on your business needs, such as giving others the ability to view or query your data.
|
14
|
-
|
15
|
-
See the {Gcloud::Bigquery gcloud-ruby BigQuery API documentation} to learn how to connect to Cloud BigQuery using this library.
|
16
|
-
|
17
|
-
```ruby
|
18
|
-
require "gcloud"
|
19
|
-
|
20
|
-
gcloud = Gcloud.new
|
21
|
-
bigquery = gcloud.bigquery
|
22
|
-
|
23
|
-
# Create a new table to archive todos
|
24
|
-
dataset = bigquery.dataset "my-todo-archive"
|
25
|
-
table = dataset.create_table "todos",
|
26
|
-
name: "Todos Archive",
|
27
|
-
description: "Archive for completed TODO records"
|
28
|
-
|
29
|
-
# Load data into the table
|
30
|
-
file = File.open "/archive/todos/completed-todos.csv"
|
31
|
-
load_job = table.load file
|
32
|
-
|
33
|
-
# Run a query for the number of completed todos by owner
|
34
|
-
count_sql = "SELECT owner, COUNT(*) AS complete_count FROM todos GROUP BY owner"
|
35
|
-
data = bigquery.query count_sql
|
36
|
-
data.each do |row|
|
37
|
-
puts row["name"]
|
38
|
-
end
|
39
|
-
```
|
40
|
-
|
41
|
-
# Datastore
|
42
|
-
|
43
|
-
[Google Cloud Datastore](https://cloud.google.com/datastore/) ([docs](https://cloud.google.com/datastore/docs)) is a fully managed, schemaless database for storing non-relational data. Cloud Datastore automatically scales with your users and supports ACID transactions, high availability of reads and writes, strong consistency for reads and ancestor queries, and eventual consistency for all other queries.
|
44
|
-
|
45
|
-
Follow the [activation instructions](https://cloud.google.com/datastore/docs/activate) to use the Google Cloud Datastore API with your project.
|
46
|
-
|
47
|
-
See the {Gcloud::Bigquery gcloud-ruby Datastore API documentation} to learn how to interact with the Cloud Datastore using this library.
|
48
|
-
|
49
|
-
```ruby
|
50
|
-
require "gcloud"
|
51
|
-
|
52
|
-
gcloud = Gcloud.new
|
53
|
-
datastore = gcloud.datastore
|
54
|
-
|
55
|
-
# Create a new task to demo datastore
|
56
|
-
task = datastore.entity "Task", "sampleTask" do |t|
|
57
|
-
t["type"] = "Personal"
|
58
|
-
t["done"] = false
|
59
|
-
t["priority"] = 4
|
60
|
-
t["description"] = "Learn Cloud Datastore"
|
61
|
-
end
|
62
|
-
|
63
|
-
# Save the new task
|
64
|
-
datastore.save task
|
65
|
-
|
66
|
-
# Run a query for all completed tasks
|
67
|
-
query = datastore.query("Task").
|
68
|
-
where("done", "=", false)
|
69
|
-
tasks = datastore.run query
|
70
|
-
```
|
71
|
-
|
72
|
-
# DNS
|
73
|
-
|
74
|
-
[Google Cloud DNS](https://cloud.google.com/dns/) ([docs](https://cloud.google.com/dns/docs)) is a high-performance, resilient, global DNS service that provides a cost-effective way to make your applications and services available to your users. This programmable, authoritative DNS service can be used to easily publish and manage DNS records using the same infrastructure relied upon by Google. To learn more, read [What is Google Cloud DNS?](https://cloud.google.com/dns/what-is-cloud-dns).
|
75
|
-
|
76
|
-
See the {Gcloud::Dns gcloud-ruby DNS API documentation} to learn how to connect to Cloud DNS using this library.
|
77
|
-
|
78
|
-
```ruby
|
79
|
-
require "gcloud"
|
80
|
-
|
81
|
-
gcloud = Gcloud.new
|
82
|
-
dns = gcloud.dns
|
83
|
-
|
84
|
-
# Retrieve a zone
|
85
|
-
zone = dns.zone "example-com"
|
86
|
-
|
87
|
-
# Update records in the zone
|
88
|
-
change = zone.update do |tx|
|
89
|
-
tx.add "www", "A", 86400, "1.2.3.4"
|
90
|
-
tx.remove "example.com.", "TXT"
|
91
|
-
tx.replace "example.com.", "MX", 86400, ["10 mail1.example.com.",
|
92
|
-
"20 mail2.example.com."]
|
93
|
-
tx.modify "www.example.com.", "CNAME" do |r|
|
94
|
-
r.ttl = 86400 # only change the TTL
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
```
|
99
|
-
|
100
|
-
# Logging
|
101
|
-
|
102
|
-
[Stackdriver Logging](https://cloud.google.com/logging/) collects and stores logs from applications and services on the Google Cloud Platform, giving you fine-grained, programmatic control over your projects' logs. With this API you can do the following:
|
103
|
-
|
104
|
-
* Read and filter log entries
|
105
|
-
* Export your log entries to Cloud Storage,
|
106
|
-
BigQuery, or Cloud Pub/Sub
|
107
|
-
* Create logs-based metrics for use in Cloud
|
108
|
-
Monitoring
|
109
|
-
* Write log entries
|
110
|
-
|
111
|
-
See the {Gcloud::Logging gcloud-ruby Logging API documentation} to learn how to connect to Cloud Loging using this library.
|
112
|
-
|
113
|
-
```ruby
|
114
|
-
require "gcloud"
|
115
|
-
|
116
|
-
gcloud = Gcloud.new
|
117
|
-
logging = gcloud.logging
|
118
|
-
|
119
|
-
# List all log entries
|
120
|
-
logging.entries.each do |e|
|
121
|
-
puts "[#{e.timestamp}] #{e.log_name} #{e.payload.inspect}"
|
122
|
-
end
|
123
|
-
|
124
|
-
# List only entries from a single log
|
125
|
-
entries = logging.entries filter: "log:syslog"
|
126
|
-
|
127
|
-
# Write a log entry
|
128
|
-
entry = logging.entry
|
129
|
-
entry.payload = "Job started."
|
130
|
-
entry.log_name = "my_app_log"
|
131
|
-
entry.resource.type = "gae_app"
|
132
|
-
entry.resource.labels[:module_id] = "1"
|
133
|
-
entry.resource.labels[:version_id] = "20150925t173233"
|
134
|
-
|
135
|
-
logging.write_entries entry
|
136
|
-
```
|
137
|
-
|
138
|
-
# Pub/Sub
|
139
|
-
|
140
|
-
[Google Cloud Pub/Sub](https://cloud.google.com/pubsub/) ([docs](https://cloud.google.com/pubsub/reference/rest/)) is designed to provide reliable, many-to-many, asynchronous messaging between applications. Publisher applications can send messages to a “topic” and other applications can subscribe to that topic to receive the messages. By decoupling senders and receivers, Google Cloud Pub/Sub allows developers to communicate between independently written applications.
|
141
|
-
|
142
|
-
See the {Gcloud::Pubsub gcloud-ruby Pub/Sub API documentation} to learn how to connect to Cloud Pub/Sub using this library.
|
143
|
-
|
144
|
-
```ruby
|
145
|
-
require "gcloud"
|
146
|
-
|
147
|
-
gcloud = Gcloud.new
|
148
|
-
pubsub = gcloud.pubsub
|
149
|
-
|
150
|
-
# Retrieve a topic
|
151
|
-
topic = pubsub.topic "my-topic"
|
152
|
-
|
153
|
-
# Publish a new message
|
154
|
-
msg = topic.publish "new-message"
|
155
|
-
|
156
|
-
# Retrieve a subscription
|
157
|
-
sub = pubsub.subscription "my-topic-sub"
|
158
|
-
|
159
|
-
# Pull available messages
|
160
|
-
msgs = sub.pull
|
161
|
-
```
|
162
|
-
|
163
|
-
# Resource Manager
|
164
|
-
|
165
|
-
[Google Cloud Resource Manager](https://cloud.google.com/resource-manager/) ([docs](https://cloud.google.com/resource-manager/reference/rest/)) provides methods that you can use to programmatically manage your projects in the Google Cloud Platform. You may be familiar with managing projects in the [Developers Console](https://developers.google.com/console/help/new/). With this API you can do the following:
|
166
|
-
|
167
|
-
* Get a list of all projects associated with an account
|
168
|
-
* Create new projects
|
169
|
-
* Update existing projects
|
170
|
-
* Delete projects
|
171
|
-
* Undelete, or recover, projects that you don't want to delete
|
172
|
-
|
173
|
-
See the {Gcloud::ResourceManager gcloud-ruby Resource Manager API documentation} to learn how to connect to Cloud Resource Manager using this library.
|
174
|
-
|
175
|
-
```ruby
|
176
|
-
require "gcloud"
|
177
|
-
|
178
|
-
gcloud = Gcloud.new
|
179
|
-
resource_manager = gcloud.resource_manager
|
180
|
-
|
181
|
-
# List all projects
|
182
|
-
resource_manager.projects.each do |project|
|
183
|
-
puts projects.project_id
|
184
|
-
end
|
185
|
-
|
186
|
-
# Label a project as production
|
187
|
-
project = resource_manager.project "tokyo-rain-123"
|
188
|
-
project.update do |p|
|
189
|
-
p.labels["env"] = "production"
|
190
|
-
end
|
191
|
-
|
192
|
-
# List only projects with the "production" label
|
193
|
-
projects = resource_manager.projects filter: "labels.env:production"
|
194
|
-
```
|
195
|
-
|
196
|
-
# Storage
|
197
|
-
|
198
|
-
[Google Cloud Storage](https://cloud.google.com/storage/) ([docs](https://cloud.google.com/storage/docs/json_api/)) allows you to store data on Google infrastructure with very high reliability, performance and availability, and can be used to distribute large data objects to users via direct download.
|
199
|
-
|
200
|
-
See the {Gcloud::Storage gcloud-ruby Storage API documentation} to learn how to connect to Cloud Storage using this library.
|
201
|
-
|
202
|
-
```ruby
|
203
|
-
require "gcloud"
|
204
|
-
|
205
|
-
gcloud = Gcloud.new
|
206
|
-
storage = gcloud.storage
|
207
|
-
|
208
|
-
bucket = storage.bucket "task-attachments"
|
209
|
-
|
210
|
-
file = bucket.file "path/to/my-file.ext"
|
211
|
-
|
212
|
-
# Download the file to the local file system
|
213
|
-
file.download "/tasks/attachments/#{file.name}"
|
214
|
-
|
215
|
-
# Copy the file to a backup bucket
|
216
|
-
backup = storage.bucket "task-attachment-backups"
|
217
|
-
file.copy backup, file.name
|
218
|
-
```
|
219
|
-
|
220
|
-
# Translate
|
221
|
-
|
222
|
-
[Google Translate](https://cloud.google.com/translate/) ([docs](https://cloud.google.com/translate/docs)) provides a simple, programmatic interface for translating an arbitrary string into any supported language. It is highly responsive, so websites and applications can integrate with Translate API for fast, dynamic translation of source text. Language detection is also available in cases where the source language is unknown.
|
223
|
-
|
224
|
-
See the {Gcloud::Translate gcloud-ruby Translate API documentation} to learn how to connect to Google Translate using this library.
|
225
|
-
|
226
|
-
```ruby
|
227
|
-
require "gcloud"
|
228
|
-
|
229
|
-
gcloud = Gcloud.new
|
230
|
-
translate = gcloud.translate
|
231
|
-
|
232
|
-
translation = translate.translate "Hello world!", to: "la"
|
233
|
-
|
234
|
-
puts translation #=> Salve mundi!
|
235
|
-
|
236
|
-
translation.from #=> "en"
|
237
|
-
translation.origin #=> "Hello world!"
|
238
|
-
translation.to #=> "la"
|
239
|
-
translation.text #=> "Salve mundi!"
|
240
|
-
```
|
241
|
-
|
242
|
-
# Vision
|
243
|
-
|
244
|
-
[Google Cloud Vision](https://cloud.google.com/vision/) ([docs](https://cloud.google.com/vision/docs)) allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content.
|
245
|
-
|
246
|
-
See the {Gcloud::Vision gcloud-ruby Cloud Vision API documentation} to learn how to connect to Google Cloud Vision using this library.
|
247
|
-
|
248
|
-
```ruby
|
249
|
-
require "gcloud"
|
250
|
-
|
251
|
-
gcloud = Gcloud.new
|
252
|
-
vision = gcloud.vision
|
253
|
-
|
254
|
-
image = vision.image "path/to/landmark.jpg"
|
255
|
-
|
256
|
-
landmark = image.landmark
|
257
|
-
landmark.description #=> "Mount Rushmore"
|
258
|
-
```
|
259
|
-
|
data/lib/gcloud/backoff.rb
DELETED
@@ -1,150 +0,0 @@
|
|
1
|
-
# Copyright 2014 Google Inc. All rights reserved.
|
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
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
|
16
|
-
module Gcloud
|
17
|
-
##
|
18
|
-
# @private
|
19
|
-
# Backoff allows users to control how Google API calls are retried.
|
20
|
-
# If an API call fails the response will be checked to see if the
|
21
|
-
# call can be retried. If the response matches the criteria, then it
|
22
|
-
# will be retried with an incremental backoff. This means that an
|
23
|
-
# increasing delay will be added between each retried call. The first
|
24
|
-
# retry will be delayed one second, the second retry will be delayed
|
25
|
-
# two seconds, and so on.
|
26
|
-
#
|
27
|
-
# @example
|
28
|
-
# require "gcloud/backoff"
|
29
|
-
#
|
30
|
-
# Gcloud::Backoff.retries = 5 # Set a maximum of five retries per call
|
31
|
-
#
|
32
|
-
class Backoff
|
33
|
-
class << self
|
34
|
-
##
|
35
|
-
# The number of times a retriable API call should be retried.
|
36
|
-
#
|
37
|
-
# The default value is `3`.
|
38
|
-
attr_reader :retries
|
39
|
-
def retries= new_retries
|
40
|
-
@retries = new_retries
|
41
|
-
end
|
42
|
-
|
43
|
-
##
|
44
|
-
# The GRPC Status Codes that should be retried.
|
45
|
-
#
|
46
|
-
# The default values are `14`.
|
47
|
-
attr_accessor :grpc_codes
|
48
|
-
|
49
|
-
##
|
50
|
-
# The HTTP Status Codes that should be retried.
|
51
|
-
#
|
52
|
-
# The default values are `500` and `503`.
|
53
|
-
attr_accessor :http_codes
|
54
|
-
|
55
|
-
##
|
56
|
-
# The Google API error reasons that should be retried.
|
57
|
-
#
|
58
|
-
# The default values are `rateLimitExceeded` and
|
59
|
-
# `userRateLimitExceeded`.
|
60
|
-
attr_accessor :reasons
|
61
|
-
|
62
|
-
##
|
63
|
-
# The code to run when a backoff is handled.
|
64
|
-
# This must be a Proc and must take the number of
|
65
|
-
# retries as an argument.
|
66
|
-
#
|
67
|
-
# Note: This method is undocumented and may change.
|
68
|
-
attr_accessor :backoff # :nodoc:
|
69
|
-
end
|
70
|
-
# Set the default values
|
71
|
-
self.retries = 3
|
72
|
-
self.grpc_codes = [14]
|
73
|
-
self.http_codes = [500, 503]
|
74
|
-
self.reasons = %w(rateLimitExceeded userRateLimitExceeded)
|
75
|
-
self.backoff = ->(retries) { sleep retries.to_i }
|
76
|
-
|
77
|
-
##
|
78
|
-
# @private
|
79
|
-
# Creates a new Backoff object to catch common errors when calling
|
80
|
-
# the Google API and handle the error by retrying the call.
|
81
|
-
#
|
82
|
-
# Gcloud::Backoff.new(options).execute_gapi do
|
83
|
-
# client.execute api_method: service.things.insert,
|
84
|
-
# parameters: { thing: @thing },
|
85
|
-
# body_object: { name: thing_name }
|
86
|
-
# end
|
87
|
-
def initialize options = {}
|
88
|
-
@retries = (options[:retries] || Backoff.retries).to_i
|
89
|
-
@grpc_codes = (options[:grpc_codes] || Backoff.grpc_codes).to_a
|
90
|
-
@http_codes = (options[:http_codes] || Backoff.http_codes).to_a
|
91
|
-
@reasons = (options[:reasons] || Backoff.reasons).to_a
|
92
|
-
@backoff = options[:backoff] || Backoff.backoff
|
93
|
-
end
|
94
|
-
|
95
|
-
# @private
|
96
|
-
def execute_gapi
|
97
|
-
current_retries = 0
|
98
|
-
loop do
|
99
|
-
result = yield
|
100
|
-
return result unless result.is_a? Google::APIClient::Result
|
101
|
-
break result if result.success? || !retry?(result, current_retries)
|
102
|
-
current_retries += 1
|
103
|
-
@backoff.call current_retries
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
# @private
|
108
|
-
def execute_grpc
|
109
|
-
current_retries = 0
|
110
|
-
loop do
|
111
|
-
begin
|
112
|
-
return yield
|
113
|
-
rescue GRPC::BadStatus => e
|
114
|
-
raise e unless @grpc_codes.include?(e.code) &&
|
115
|
-
(current_retries < @retries)
|
116
|
-
current_retries += 1
|
117
|
-
@backoff.call current_retries
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
protected
|
123
|
-
|
124
|
-
# @private
|
125
|
-
def retry? result, current_retries #:nodoc:
|
126
|
-
if current_retries < @retries
|
127
|
-
return true if retry_http_code? result
|
128
|
-
return true if retry_error_reason? result
|
129
|
-
end
|
130
|
-
false
|
131
|
-
end
|
132
|
-
|
133
|
-
# @private
|
134
|
-
def retry_http_code? result #:nodoc:
|
135
|
-
@http_codes.include? result.response.status
|
136
|
-
end
|
137
|
-
|
138
|
-
# @private
|
139
|
-
def retry_error_reason? result
|
140
|
-
if result.data &&
|
141
|
-
result.data["error"] &&
|
142
|
-
result.data["error"]["errors"]
|
143
|
-
Array(result.data["error"]["errors"]).each do |error|
|
144
|
-
return true if error["reason"] && @reasons.include?(error["reason"])
|
145
|
-
end
|
146
|
-
end
|
147
|
-
false
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
# Copyright 2015 Google Inc. All rights reserved.
|
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
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
|
16
|
-
module Gcloud
|
17
|
-
module Bigquery
|
18
|
-
##
|
19
|
-
# # CopyJob
|
20
|
-
#
|
21
|
-
# A {Job} subclass representing a copy operation that may be performed on a
|
22
|
-
# {Table}. A CopyJob instance is created when you call {Table#copy}.
|
23
|
-
#
|
24
|
-
# @see https://cloud.google.com/bigquery/docs/tables#copyingtable Copying an
|
25
|
-
# Existing Table
|
26
|
-
# @see https://cloud.google.com/bigquery/docs/reference/v2/jobs Jobs API
|
27
|
-
# reference
|
28
|
-
#
|
29
|
-
class CopyJob < Job
|
30
|
-
##
|
31
|
-
# The table from which data is copied. This is the table on
|
32
|
-
# which {Table#copy} was called. Returns a {Table} instance.
|
33
|
-
def source
|
34
|
-
table = @gapi.configuration.copy.source_table
|
35
|
-
return nil unless table
|
36
|
-
retrieve_table table.project_id,
|
37
|
-
table.dataset_id,
|
38
|
-
table.table_id
|
39
|
-
end
|
40
|
-
|
41
|
-
##
|
42
|
-
# The table to which data is copied. Returns a {Table} instance.
|
43
|
-
def destination
|
44
|
-
table = @gapi.configuration.copy.destination_table
|
45
|
-
return nil unless table
|
46
|
-
retrieve_table table.project_id,
|
47
|
-
table.dataset_id,
|
48
|
-
table.table_id
|
49
|
-
end
|
50
|
-
|
51
|
-
##
|
52
|
-
# Checks if the create disposition for the job is `CREATE_IF_NEEDED`,
|
53
|
-
# which provides the following behavior: If the table does not exist,
|
54
|
-
# the copy operation creates the table. This is the default.
|
55
|
-
def create_if_needed?
|
56
|
-
disp = @gapi.configuration.copy.create_disposition
|
57
|
-
disp == "CREATE_IF_NEEDED"
|
58
|
-
end
|
59
|
-
|
60
|
-
##
|
61
|
-
# Checks if the create disposition for the job is `CREATE_NEVER`, which
|
62
|
-
# provides the following behavior: The table must already exist; if it
|
63
|
-
# does not, an error is returned in the job result.
|
64
|
-
def create_never?
|
65
|
-
disp = @gapi.configuration.copy.create_disposition
|
66
|
-
disp == "CREATE_NEVER"
|
67
|
-
end
|
68
|
-
|
69
|
-
##
|
70
|
-
# Checks if the write disposition for the job is `WRITE_TRUNCATE`, which
|
71
|
-
# provides the following behavior: If the table already exists, the copy
|
72
|
-
# operation overwrites the table data.
|
73
|
-
def write_truncate?
|
74
|
-
disp = @gapi.configuration.copy.write_disposition
|
75
|
-
disp == "WRITE_TRUNCATE"
|
76
|
-
end
|
77
|
-
|
78
|
-
##
|
79
|
-
# Checks if the write disposition for the job is `WRITE_APPEND`, which
|
80
|
-
# provides the following behavior: If the table already exists, the copy
|
81
|
-
# operation appends the data to the table.
|
82
|
-
def write_append?
|
83
|
-
disp = @gapi.configuration.copy.write_disposition
|
84
|
-
disp == "WRITE_APPEND"
|
85
|
-
end
|
86
|
-
|
87
|
-
##
|
88
|
-
# Checks if the write disposition for the job is `WRITE_EMPTY`, which
|
89
|
-
# provides the following behavior: If the table already exists and
|
90
|
-
# contains data, the job will have an error. This is the default.
|
91
|
-
def write_empty?
|
92
|
-
disp = @gapi.configuration.copy.write_disposition
|
93
|
-
disp == "WRITE_EMPTY"
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|