iij-dag 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1c7e0f6d32d600f1ab6d4d58f4ddc7f4cabccdfc
4
+ data.tar.gz: b05f864faab066b3d22342e9055efd0e5e9c64a5
5
+ SHA512:
6
+ metadata.gz: 28108a90f7aba294fae6a1c6adc82302122d32ec8621cf50c509f39356feed2d69fa7333042a9e7b52e2a6eb74c820cc610fb0e026b5338796e90e0bcd46ff5e
7
+ data.tar.gz: 604962e5d56e69b8af3f1b4f1ba5fd98f96cce731304f9f2a6208d8cb29236fa3d3bcce7e37e22f817b411a1dfdc324d16fa803aec192ea38ba0e2e85ebfd8cd
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'timecop'
7
+ gem 'pry', '< 0.10.0'
8
+ gem 'pry-byebug'
9
+ gem 'webmock'
10
+ gem 'simplecov'
11
+ gem 'simplecov-rcov'
12
+ end
13
+
14
+ group :doc do
15
+ gem 'yard'
16
+ end
@@ -0,0 +1,174 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
@@ -0,0 +1,27 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
6
+
7
+ namespace :spec do
8
+ [:cli, :command, :sub_command].each do |dir|
9
+ desc "Run #{dir} spec"
10
+ RSpec::Core::RakeTask.new(dir) do |t|
11
+ t.pattern = "spec/#{dir}/*_spec.rb"
12
+ end
13
+ end
14
+ end
15
+
16
+ namespace :document do
17
+ task :build do
18
+ docpath = "../documents/parser"
19
+ if Dir.exist? docpath
20
+ pid = spawn("yard", "-o", docpath, STDERR => STDOUT)
21
+ Process.waitpid pid
22
+ else
23
+ puts "You don't have #{docpath} directory."
24
+ puts "Can't create a new document."
25
+ end
26
+ end
27
+ end
data/bin/dag ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.join(File.dirname(__FILE__), *%w{ .. lib })
3
+
4
+ require 'thor'
5
+ require 'dag/cli'
6
+
7
+ Dag::CLI::Command.start
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'dag/cli/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "iij-dag"
9
+ spec.version = Dag::CLI::VERSION
10
+ spec.authors = ["iij"]
11
+ spec.email = ["dag-info@iij.ad.jp"]
12
+ spec.description = %q{iij gio dag command line tool}
13
+ spec.summary = %q{iij gio dag command line tool}
14
+ spec.homepage = "http://www.iij.ad.jp/biz/storage/"
15
+ spec.license = "Apache License 2.0"
16
+
17
+ spec.files = `git ls-files`.split($/).reject {|item| item =~ /^(examples|README|spec|.drone.yml)/ }
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "thor", "~> 0.19.1"
23
+ spec.add_dependency "ruby-progressbar", ">= 1.1.0"
24
+ spec.add_dependency "iij-dag-client", "~> 1.0.0"
25
+ spec.add_dependency "hirb", "~> 0.7.3"
26
+ spec.add_dependency "hirb-unicode", "~> 0.0.5"
27
+ spec.add_dependency "anbt-sql-formatter", "~> 0.0.3"
28
+ spec.add_dependency "oj", "~> 2.11.2"
29
+ spec.add_dependency "activesupport", "~> 4.2.0"
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.3"
32
+ spec.add_development_dependency "rake"
33
+ spec.add_development_dependency "rspec", "~> 3.1.0"
34
+ end
@@ -0,0 +1,17 @@
1
+ module Dag
2
+ module CLI
3
+ autoload :Base, 'dag/cli/base'
4
+ autoload :Utils, 'dag/cli/utils'
5
+
6
+ autoload :Command, 'dag/cli/command'
7
+ autoload :Import, 'dag/cli/command/import'
8
+ autoload :Query, 'dag/cli/command/query'
9
+
10
+ autoload :SubCommand, 'dag/cli/sub_command'
11
+ autoload :Cluster, 'dag/cli/sub_command/cluster'
12
+ autoload :Db, 'dag/cli/sub_command/db'
13
+ autoload :Table, 'dag/cli/sub_command/table'
14
+ autoload :Job, 'dag/cli/sub_command/job'
15
+ autoload :Bucket, 'dag/cli/sub_command/bucket'
16
+ end
17
+ end
@@ -0,0 +1,128 @@
1
+ module Dag
2
+ module CLI
3
+ class Base < Thor
4
+ include Dag::CLI::Utils::TerminalTable
5
+
6
+ private
7
+
8
+ attr_accessor :debug, :trace
9
+
10
+ def local_store(&block)
11
+ require "yaml/store"
12
+ db = YAML::Store.new("#{File.dirname(options[:config])}/.cstore")
13
+ db.transaction { block.call(db) }
14
+ end
15
+
16
+ def open_client(&block)
17
+ cluster = block_given? ? block.call : local_store { |db| db[:cluster] }
18
+ client.open(cluster)
19
+ end
20
+
21
+ def client(path = options[:config])
22
+ require 'oj'
23
+ require 'dag'
24
+
25
+ Oj.default_options = { mode: :compat }
26
+ # create_config_directory
27
+
28
+ if File.exist?(path)
29
+ begin
30
+ config = Oj.load(File.open(path, &:read))
31
+ rescue Oj::ParseError => ex
32
+ abort "Error: Json format is invalid.\n #{ex.message}"
33
+ end
34
+ end
35
+
36
+ if !config.nil? && valid?(config)
37
+ self.debug = config["debug"]
38
+ self.debug = options["debug"] unless options["debug"].nil?
39
+ self.trace = options["trace"]
40
+
41
+ options = {
42
+ force_path_style: config["force_path_style"] || false,
43
+ debug: self.debug || false
44
+ }
45
+
46
+ options.merge!(analysis_api: config["analysis_api"]) if config["analysis_api"]
47
+ options.merge!(storage_api: config["storage_api"]) if config["storage_api"]
48
+
49
+ return Dag::Client.new(config["access_key_id"], config["secret_access_key"], options)
50
+ else
51
+ error "Error: Please create config file to '#{path}'" if config.nil?
52
+ abort <<-EOS
53
+ {
54
+ "access_key_id" : "YOUR ACCESS KEY ID",
55
+ "secret_access_key" : "YOUR SECRET ACCESS KEY",
56
+ "analysis_api" : "ANALYSIS API ENDPOINT",
57
+ "storage_api" : "STORAGE API ENDPOINT"
58
+ }
59
+ EOS
60
+ end
61
+ end
62
+
63
+ # def create_config_directory
64
+ # begin
65
+ # Dir.mkdir("#{Dir.home}/.dag")
66
+ # rescue Errno::EEXIST
67
+ # rescue => ex
68
+ # error "Error: #{ex.message}"
69
+ # exit 1
70
+ # end
71
+ # end
72
+
73
+ def valid?(config)
74
+ unless config.key?("access_key_id")
75
+ error "Error: Missing access_key_id. Please check your configuration."
76
+ return false
77
+ end
78
+
79
+ unless config.key?("secret_access_key")
80
+ error "Error: Missing secret_access_key. Please check your configuration."
81
+ return false
82
+ end
83
+
84
+ true
85
+ end
86
+
87
+ def handle_api_failure(&block)
88
+ begin
89
+ block.call
90
+ rescue Dag::Client::APIFailure => ex
91
+ if self.debug
92
+ require 'pp'
93
+ PP.pp({
94
+ api_code: ex.api_code,
95
+ api_message: ex.api_message,
96
+ api_status: ex.api_status,
97
+ api_request_id: ex.api_request_id,
98
+ api_resource: ex.api_resource,
99
+ message: ex.message
100
+ },
101
+ STDERR
102
+ )
103
+ end
104
+
105
+ if ex.api_code && ex.api_message
106
+ say_status(ex.api_code, "#{ex.api_message} (RequestId: #{ex.api_request_id})", :red)
107
+ if ex.api_status == 500
108
+ error "An unexpected error has occurred. Please contact customer support."
109
+ end
110
+
111
+ else
112
+ say_status(
113
+ ex.cause,
114
+ "#{ex.cause}: An unexpected error has occurred. Please contact customer support.",
115
+ :red
116
+ )
117
+ end
118
+
119
+ exit 1
120
+ rescue => ex
121
+ say_status("ERROR", ex.message, :red)
122
+ error ex.backtrace * "\n" if self.trace
123
+ exit 1
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,83 @@
1
+ # coding: utf-8
2
+
3
+ module Dag
4
+ module CLI
5
+ class Command < Base
6
+ class_option :version, type: :string, banner: '', aliases: '-v', desc: "Show version"
7
+ class_option :config, type: :string, default: "#{Dir.home}/.dag/credential.json",
8
+ aliases: '-C', desc: "Path to the config file", banner: "/path/to/file"
9
+ class_option :debug, type: :boolean, desc: "Show debug message"
10
+ class_option :trace, type: :boolean, desc: "Show error stacktrace", hide: true
11
+
12
+ def initialize(args = [], local_options = {}, config = {})
13
+ super
14
+ handle_version_request! if options.key?("version")
15
+ end
16
+
17
+ desc 'account', 'Show account info'
18
+ def account
19
+ fields = [:apikey, :analysis_api, :storage_api]
20
+ terminal_table([client], fields: fields)
21
+ end
22
+
23
+ desc 'import [DB] [TABLE]', 'Upload files and convert into analysis format'
24
+ option 'import-files', type: :array, aliases: '-i', desc: 'import files', required: true
25
+ option :format, type: :string, aliases: '-f', desc: 'file format [json_agent/json/csv/tsv]', required: true
26
+ option :label, type: :string, aliases: '-l', desc: 'label'
27
+ option :jobs, type: :numeric, aliases: '-j', desc: 'jobs'
28
+ def import(db, table)
29
+ params = {}
30
+ params.merge!({ label: options[:label] }) if options[:label]
31
+ params.merge!({ jobs: options[:jobs] }) if options[:jobs]
32
+
33
+ import = Import.new(open_client, db, table, options['import-files'], options[:format], params)
34
+ handle_api_failure { import.execute }
35
+ end
36
+
37
+ desc 'query "[QUERY_STRING]"', 'Execute Hive Query'
38
+ option :output, type: :string, aliases: '-o', desc: 'output storage path', required: true
39
+ option :format, type: :string, aliases: '-f', desc: 'output format [csv/tsv]', default: 'csv'
40
+ option :label, type: :string, aliases: '-l', desc: 'job label'
41
+ option :wait, type: :boolean, aliases: '-w', desc: 'wait job finish'
42
+ def query(query_string)
43
+ if File.exists? query_string
44
+ query_string = open(query_string).read
45
+ puts "Query: #{query_string}"
46
+ end
47
+ params = {
48
+ query: query_string,
49
+ output_format: options[:format],
50
+ output_resource_path: options[:output]
51
+ }
52
+ params.merge!(label: options[:label]) if options[:label]
53
+ query = Query.new(open_client, params)
54
+ job = handle_api_failure { query.execute }
55
+ say_status "accepted job", "job_id: #{job.id}"
56
+ if options[:wait]
57
+ CLI::Command.start(["job", "log", job.id.to_s, "-t"])
58
+ CLI::Command.start(["job", "result", job.id.to_s])
59
+ end
60
+ end
61
+
62
+ %w(cluster db table job bucket).each do |cmd|
63
+ desc "#{cmd} [COMMAND]", "Management command for #{cmd}"
64
+ subcommand cmd, Dag::CLI.const_get(cmd.capitalize)
65
+ end
66
+
67
+ desc 'help [COMMAND]', 'Describe available commands or one specific command'
68
+ def help(command = nil, subcommand = false)
69
+ super
70
+ shell.say "Type 'dag help [COMMAND]' for more information on a specific command"
71
+ end
72
+
73
+ private
74
+
75
+ def handle_version_request!
76
+ require 'dag/cli/version'
77
+ require 'dag/client/version'
78
+ print_table [["dag-ruby", VERSION], ["dag-client-ruby", Dag::Client::VERSION]]
79
+ exit 0
80
+ end
81
+ end
82
+ end
83
+ end