iij-dag-client 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +174 -0
- data/Rakefile +43 -0
- data/config/settings.yml +11 -0
- data/iij-dag-client.gemspec +31 -0
- data/lib/dag.rb +33 -0
- data/lib/dag/client.rb +36 -0
- data/lib/dag/client/api.rb +295 -0
- data/lib/dag/client/api/cluster.rb +111 -0
- data/lib/dag/client/api/database.rb +58 -0
- data/lib/dag/client/api/job.rb +116 -0
- data/lib/dag/client/api/list_params.rb +36 -0
- data/lib/dag/client/api/rest_parameter.rb +149 -0
- data/lib/dag/client/api/storage.rb +354 -0
- data/lib/dag/client/api/storage_result.rb +52 -0
- data/lib/dag/client/api/table.rb +131 -0
- data/lib/dag/client/cluster.rb +26 -0
- data/lib/dag/client/cluster_validation.rb +59 -0
- data/lib/dag/client/database.rb +79 -0
- data/lib/dag/client/exception.rb +43 -0
- data/lib/dag/client/job.rb +56 -0
- data/lib/dag/client/job_validation.rb +22 -0
- data/lib/dag/client/model.rb +9 -0
- data/lib/dag/client/model/bucket.rb +20 -0
- data/lib/dag/client/model/bucket_collection.rb +34 -0
- data/lib/dag/client/model/cluster.rb +100 -0
- data/lib/dag/client/model/cluster_collection.rb +76 -0
- data/lib/dag/client/model/database.rb +34 -0
- data/lib/dag/client/model/database_collection.rb +51 -0
- data/lib/dag/client/model/job.rb +125 -0
- data/lib/dag/client/model/job_collection.rb +114 -0
- data/lib/dag/client/model/object.rb +56 -0
- data/lib/dag/client/model/object_collection.rb +64 -0
- data/lib/dag/client/model/table.rb +55 -0
- data/lib/dag/client/model/table_collection.rb +60 -0
- data/lib/dag/client/storage.rb +41 -0
- data/lib/dag/client/table.rb +16 -0
- data/lib/dag/client/version.rb +5 -0
- data/lib/dag/settings.rb +9 -0
- metadata +210 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
module Dag
|
2
|
+
class ObjectCollection < Model
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
def initialize(api, bucket_name)
|
6
|
+
super(api)
|
7
|
+
@bucket = bucket_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def [](object_name)
|
11
|
+
object_named(object_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
def where(prefix: nil, delimiter: nil)
|
15
|
+
@prefix = prefix
|
16
|
+
@delimiter = delimiter
|
17
|
+
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def each
|
22
|
+
options = {}
|
23
|
+
if @prefix
|
24
|
+
options = options.merge(prefix: @prefix)
|
25
|
+
end
|
26
|
+
|
27
|
+
if @delimiter
|
28
|
+
options = options.merge(delimiter: @delimiter)
|
29
|
+
end
|
30
|
+
|
31
|
+
marker = nil
|
32
|
+
truncated = false
|
33
|
+
begin
|
34
|
+
if marker.present?
|
35
|
+
options = options.merge(marker: marker)
|
36
|
+
end
|
37
|
+
objects_result = @api.objects(@bucket, options)
|
38
|
+
objects = objects_result.full_objects
|
39
|
+
|
40
|
+
truncated = objects_result.truncated?
|
41
|
+
next_marker = objects_result.next_marker
|
42
|
+
if next_marker.nil?
|
43
|
+
marker = objects.last['Key'][0] if objects.present?
|
44
|
+
else
|
45
|
+
marker = next_marker
|
46
|
+
end
|
47
|
+
|
48
|
+
objects.each do |object|
|
49
|
+
yield object_opts(object)
|
50
|
+
end
|
51
|
+
end while truncated
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def object_named(object_name)
|
57
|
+
Dag::Object.new(@api, @bucket, object_name.to_s)
|
58
|
+
end
|
59
|
+
|
60
|
+
def object_opts(object_opts)
|
61
|
+
Dag::Object.new(@api, @bucket, object_opts["Key"][0], object_opts)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Dag
|
2
|
+
class Table < Model
|
3
|
+
def initialize(api, cluster_name, db_name, params: {})
|
4
|
+
super(api)
|
5
|
+
@cluster_name = cluster_name
|
6
|
+
@db_name = db_name
|
7
|
+
load_table_info(params)
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :cluster_name, :db_name, :name, :format, :comment, :location, :created_at, :modified_at
|
11
|
+
|
12
|
+
def update(schema: nil, format: nil, comment: nil)
|
13
|
+
parameters = {
|
14
|
+
table: @name,
|
15
|
+
comment: comment || @comment,
|
16
|
+
format: format || @table_info['format'],
|
17
|
+
schema: schema || current_schema,
|
18
|
+
}
|
19
|
+
|
20
|
+
@api.create_table(@cluster_name, @db_name, params: parameters)
|
21
|
+
info = @api.table(@cluster_name, @db_name, @name)
|
22
|
+
load_table_info(info)
|
23
|
+
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete
|
28
|
+
@api.delete_table(@cluster_name, @db_name, @name)
|
29
|
+
end
|
30
|
+
|
31
|
+
def current_schema
|
32
|
+
@columns.map { |c| "#{c['name']} #{c['type']}" }.join(", ") if @columns.present?
|
33
|
+
end
|
34
|
+
|
35
|
+
alias :schema :current_schema
|
36
|
+
|
37
|
+
def self.json_agent_partition_keys?(partition)
|
38
|
+
(partition['name'] == 'date' && partition['type'] == 'string') ||
|
39
|
+
(partition['name'] == 'hour' && partition['type'] == 'string')
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def load_table_info(params)
|
45
|
+
@table_info = params
|
46
|
+
@name = @table_info["tableName"]
|
47
|
+
@format = @table_info["format"]
|
48
|
+
@comment = @table_info["comment"]
|
49
|
+
@location = @table_info["location"]
|
50
|
+
@created_at = Time.at(@table_info["createTime"])
|
51
|
+
@modified_at = Time.at(@table_info["modifiedTime"])
|
52
|
+
@columns = params['columns']
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Dag
|
2
|
+
class TableCollection < Model
|
3
|
+
include Enumerable
|
4
|
+
include Dag::Client::ClusterValidation
|
5
|
+
|
6
|
+
attr_reader :cluster_name
|
7
|
+
|
8
|
+
def initialize(api, cluster_name, db_name)
|
9
|
+
super(api)
|
10
|
+
|
11
|
+
@cluster_name = cluster_name
|
12
|
+
@db_name = db_name
|
13
|
+
end
|
14
|
+
|
15
|
+
def each
|
16
|
+
marker = nil
|
17
|
+
truncated = false
|
18
|
+
begin
|
19
|
+
table_info_list = @api.table_info_list(@cluster_name, @db_name, make_options(marker))
|
20
|
+
table_info_list['tables'].each do |table_info|
|
21
|
+
yield Dag::Table.new(@api, @cluster_name, @db_name, params: table_info)
|
22
|
+
end
|
23
|
+
truncated = table_info_list['isTruncated']
|
24
|
+
marker = table_info_list['nextMarker']
|
25
|
+
end while truncated
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# == parameters ==
|
30
|
+
# * <tt>table</tt> - table name
|
31
|
+
# * <tt>format</tt> - 'csv' or 'tsv' or 'json' or 'json_agent'
|
32
|
+
# * <tt>schema/tt> - schema
|
33
|
+
# * <tt>comment</tt> - comment
|
34
|
+
def create(table: '', format: nil, schema: nil, comment: nil)
|
35
|
+
params = {
|
36
|
+
table: table,
|
37
|
+
schema: schema,
|
38
|
+
create_api: true
|
39
|
+
}
|
40
|
+
params.merge!({ format: format }) if format
|
41
|
+
params.merge!({ comment: comment }) if comment
|
42
|
+
|
43
|
+
@api.create_table(@cluster_name, @db_name, params: params)
|
44
|
+
table_info = @api.table(@cluster_name, @db_name, table)
|
45
|
+
Dag::Table.new(@api, @cluster_name, @db_name, params: table_info)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def make_options(marker = nil)
|
51
|
+
options = { max: 100 }
|
52
|
+
|
53
|
+
if marker
|
54
|
+
options = options.merge(marker: marker)
|
55
|
+
end
|
56
|
+
|
57
|
+
options
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Dag
|
2
|
+
class Client
|
3
|
+
module Storage
|
4
|
+
def buckets
|
5
|
+
Dag::BucketCollection.new(@api)
|
6
|
+
end
|
7
|
+
|
8
|
+
def objects(bucket)
|
9
|
+
Dag::ObjectCollection.new(@api, bucket)
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_bucket(bucket)
|
13
|
+
@api.create_bucket(bucket)
|
14
|
+
|
15
|
+
Dag::Bucket.new(@api, bucket)
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete_bucket(bucket)
|
19
|
+
@api.delete_bucket(bucket)
|
20
|
+
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete_object(bucket, object)
|
25
|
+
@api.delete_object(bucket, object)
|
26
|
+
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# == options ==
|
32
|
+
# * <tt>label</tt> - label
|
33
|
+
# * <tt>jobs</tt> - count of executing pararell
|
34
|
+
def import(db_name, table, file_path, options = {})
|
35
|
+
@api.import(db_name, table, file_path, options)
|
36
|
+
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Dag
|
2
|
+
class Client
|
3
|
+
module Table
|
4
|
+
def tables
|
5
|
+
Dag::TableCollection.new(@api, @cluster_name, @db_name)
|
6
|
+
end
|
7
|
+
|
8
|
+
def table(tbl_name)
|
9
|
+
unless table_info = @api.table(@cluster_name, @db_name, tbl_name)
|
10
|
+
raise Dag::Client::TableNotFound.new('table not found')
|
11
|
+
end
|
12
|
+
Dag::Table.new(@api, @cluster_name, @db_name, params: table_info)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/dag/settings.rb
ADDED
metadata
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iij-dag-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- iij
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httpclient
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.6.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.6.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: settingslogic
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.0.9
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.0.9
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: oj
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.11.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.11.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mime-types
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.4.3
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.4.3
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: xml-simple
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.1.4
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.1.4
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bundler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.3'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.3'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 3.1.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 3.1.0
|
139
|
+
description: iij gio dag library for ruby
|
140
|
+
email:
|
141
|
+
- dag-info@iij.ad.jp
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- Gemfile
|
148
|
+
- LICENSE.txt
|
149
|
+
- Rakefile
|
150
|
+
- config/settings.yml
|
151
|
+
- iij-dag-client.gemspec
|
152
|
+
- lib/dag.rb
|
153
|
+
- lib/dag/client.rb
|
154
|
+
- lib/dag/client/api.rb
|
155
|
+
- lib/dag/client/api/cluster.rb
|
156
|
+
- lib/dag/client/api/database.rb
|
157
|
+
- lib/dag/client/api/job.rb
|
158
|
+
- lib/dag/client/api/list_params.rb
|
159
|
+
- lib/dag/client/api/rest_parameter.rb
|
160
|
+
- lib/dag/client/api/storage.rb
|
161
|
+
- lib/dag/client/api/storage_result.rb
|
162
|
+
- lib/dag/client/api/table.rb
|
163
|
+
- lib/dag/client/cluster.rb
|
164
|
+
- lib/dag/client/cluster_validation.rb
|
165
|
+
- lib/dag/client/database.rb
|
166
|
+
- lib/dag/client/exception.rb
|
167
|
+
- lib/dag/client/job.rb
|
168
|
+
- lib/dag/client/job_validation.rb
|
169
|
+
- lib/dag/client/model.rb
|
170
|
+
- lib/dag/client/model/bucket.rb
|
171
|
+
- lib/dag/client/model/bucket_collection.rb
|
172
|
+
- lib/dag/client/model/cluster.rb
|
173
|
+
- lib/dag/client/model/cluster_collection.rb
|
174
|
+
- lib/dag/client/model/database.rb
|
175
|
+
- lib/dag/client/model/database_collection.rb
|
176
|
+
- lib/dag/client/model/job.rb
|
177
|
+
- lib/dag/client/model/job_collection.rb
|
178
|
+
- lib/dag/client/model/object.rb
|
179
|
+
- lib/dag/client/model/object_collection.rb
|
180
|
+
- lib/dag/client/model/table.rb
|
181
|
+
- lib/dag/client/model/table_collection.rb
|
182
|
+
- lib/dag/client/storage.rb
|
183
|
+
- lib/dag/client/table.rb
|
184
|
+
- lib/dag/client/version.rb
|
185
|
+
- lib/dag/settings.rb
|
186
|
+
homepage: http://www.iij.ad.jp/biz/storage/
|
187
|
+
licenses:
|
188
|
+
- Apache License 2.0
|
189
|
+
metadata: {}
|
190
|
+
post_install_message:
|
191
|
+
rdoc_options: []
|
192
|
+
require_paths:
|
193
|
+
- lib
|
194
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
195
|
+
requirements:
|
196
|
+
- - ">="
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: '0'
|
199
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
|
+
requirements:
|
201
|
+
- - ">="
|
202
|
+
- !ruby/object:Gem::Version
|
203
|
+
version: '0'
|
204
|
+
requirements: []
|
205
|
+
rubyforge_project:
|
206
|
+
rubygems_version: 2.2.3
|
207
|
+
signing_key:
|
208
|
+
specification_version: 4
|
209
|
+
summary: iij gio dag library for ruby
|
210
|
+
test_files: []
|