flydata 0.0.5.6 → 0.1.0

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.
data/Gemfile CHANGED
@@ -6,6 +6,9 @@ gem "activesupport", "~> 4.0.0"
6
6
  gem "json", "~> 1.8.0"
7
7
  gem "highline", "~> 1.6.19"
8
8
  gem "fluentd", "0.10.35"
9
+ gem "ruby-binlog", ">= 1.0.0", :git => "https://github.com/hapyrus/ruby-binlog.git"
10
+ gem "fluent-plugin-mysql-binlog", "~> 0.0.2"
11
+ gem "mysql2", "~> 0.3.11"
9
12
 
10
13
  group :development do
11
14
  gem "bundler"
@@ -14,5 +17,10 @@ group :development do
14
17
  #gem "autotest"
15
18
  #gem "autotest-standalone"
16
19
  #gem "autotest-notification"
20
+ gem 'timecop'
17
21
  gem "sqlite3"
22
+ gem 'ruby-prof'
23
+ gem 'activemodel', '~> 4.0.0'
24
+ gem 'activerecord', '~> 4.0.0'
25
+ gem 'protected_attributes'
18
26
  end
data/Gemfile.lock CHANGED
@@ -1,6 +1,21 @@
1
+ GIT
2
+ remote: https://github.com/hapyrus/ruby-binlog.git
3
+ revision: e381b4fc411ca2c2402aefc25809ac3c97d75f94
4
+ specs:
5
+ ruby-binlog (1.0.0)
6
+
1
7
  GEM
2
8
  remote: http://rubygems.org/
3
9
  specs:
10
+ activemodel (4.0.0)
11
+ activesupport (= 4.0.0)
12
+ builder (~> 3.1.0)
13
+ activerecord (4.0.0)
14
+ activemodel (= 4.0.0)
15
+ activerecord-deprecated_finders (~> 1.0.2)
16
+ activesupport (= 4.0.0)
17
+ arel (~> 4.0.0)
18
+ activerecord-deprecated_finders (1.0.3)
4
19
  activesupport (4.0.0)
5
20
  i18n (~> 0.6, >= 0.6.4)
6
21
  minitest (~> 4.2)
@@ -8,13 +23,18 @@ GEM
8
23
  thread_safe (~> 0.1)
9
24
  tzinfo (~> 0.3.37)
10
25
  addressable (2.3.5)
26
+ arel (4.0.2)
11
27
  atomic (1.1.14)
12
- builder (3.2.2)
28
+ builder (3.1.4)
13
29
  cool.io (1.1.1)
14
30
  iobuffer (>= 1.0.0)
15
31
  diff-lcs (1.2.4)
16
32
  faraday (0.8.8)
17
33
  multipart-post (~> 1.2.0)
34
+ fluent-plugin-mysql-binlog (0.0.2)
35
+ activesupport
36
+ fluentd
37
+ kodama
18
38
  fluentd (0.10.35)
19
39
  cool.io (~> 1.1.0)
20
40
  http_parser.rb (~> 0.5.1)
@@ -47,12 +67,15 @@ GEM
47
67
  json (1.8.0)
48
68
  jwt (0.1.8)
49
69
  multi_json (>= 1.5)
70
+ kodama (0.1.1)
71
+ ruby-binlog (>= 0.1.9)
50
72
  mime-types (1.25)
51
73
  minitest (4.7.5)
52
74
  msgpack (0.5.6)
53
75
  multi_json (1.8.2)
54
76
  multi_xml (0.5.5)
55
77
  multipart-post (1.2.0)
78
+ mysql2 (0.3.11)
56
79
  nokogiri (1.5.10)
57
80
  oauth2 (0.9.2)
58
81
  faraday (~> 0.8)
@@ -61,6 +84,8 @@ GEM
61
84
  multi_json (~> 1.0)
62
85
  multi_xml (~> 0.5)
63
86
  rack (~> 1.2)
87
+ protected_attributes (1.0.3)
88
+ activemodel (>= 4.0.0, < 5.0)
64
89
  rack (1.5.2)
65
90
  rake (10.1.0)
66
91
  rdoc (4.0.1)
@@ -75,9 +100,11 @@ GEM
75
100
  rspec-expectations (2.14.3)
76
101
  diff-lcs (>= 1.1.3, < 2.0)
77
102
  rspec-mocks (2.14.3)
103
+ ruby-prof (0.14.2)
78
104
  sqlite3 (1.3.8)
79
105
  thread_safe (0.1.3)
80
106
  atomic
107
+ timecop (0.7.1)
81
108
  tzinfo (0.3.38)
82
109
  yajl-ruby (1.1.0)
83
110
 
@@ -85,13 +112,21 @@ PLATFORMS
85
112
  ruby
86
113
 
87
114
  DEPENDENCIES
115
+ activemodel (~> 4.0.0)
116
+ activerecord (~> 4.0.0)
88
117
  activesupport (~> 4.0.0)
89
118
  bundler
119
+ fluent-plugin-mysql-binlog (~> 0.0.2)
90
120
  fluentd (= 0.10.35)
91
121
  highline (~> 1.6.19)
92
122
  i18n (~> 0.6.5)
93
123
  jeweler
94
124
  json (~> 1.8.0)
125
+ mysql2 (~> 0.3.11)
126
+ protected_attributes
95
127
  rest-client (~> 1.6.7)
96
128
  rspec
129
+ ruby-binlog (>= 1.0.0)!
130
+ ruby-prof
97
131
  sqlite3
132
+ timecop
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5.6
1
+ 0.1.0
data/bin/fdmysqldump ADDED
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #require 'optparse'
4
+
5
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
6
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
+
8
+ require 'flydata/table_def'
9
+
10
+ if `which mysqldump`.empty?
11
+ abort "mysqldump is not installed."
12
+ end
13
+
14
+ # TODO Implement options instead of passing all to mysqldump.
15
+ =begin
16
+ opts = {}
17
+
18
+ op = OptionParser.new do |o|
19
+ o.on('-h', '--host NAME', 'Connect to host.') do |v|
20
+ opts[:host] = v
21
+ end
22
+ o.on('-P', '--port NUMBER', 'Port number to use for connection.') do |v|
23
+ opts[:port] = v
24
+ end
25
+ o.on('-u', '--user NAME', 'User for login if not current user.') do |v|
26
+ opts[:user] = v
27
+ end
28
+ o.on('-p', '--password [TEXT]', "Password to use when connecting to server. If password is not given it's solicited on the tty.") do |v|
29
+ opts[:password] = v
30
+ end
31
+ end
32
+
33
+ op.parse!
34
+
35
+ =end
36
+ command = "mysqldump -d"
37
+
38
+ =begin
39
+ command += " -u#{opts[:user]}" if opts[:user]
40
+ command += " -h#{opts[:host]}" if opts[:host]
41
+ command += " -P#{opts[:port]}" if opts[:port]
42
+ command += " -p#{opts[:password]}" if opts[:password]
43
+ =end
44
+ command += " " + ARGV.join(' ')
45
+
46
+ IO.popen(command, 'r') do |io|
47
+ create_flydata_ctl_table = true
48
+ while !io.eof?
49
+ mysql_tabledef = Flydata::Sync::MysqlTableDef.create(io)
50
+ if mysql_tabledef.nil?
51
+ # stream had no more create table definition
52
+ break
53
+ end
54
+ flydata_tabledef = mysql_tabledef.to_flydata_tabledef
55
+ puts Flydata::Sync::RedshiftTableDef.from_flydata_tabledef(flydata_tabledef, flydata_ctl_table: create_flydata_ctl_table)
56
+ create_flydata_ctl_table = false
57
+ end
58
+ end
59
+
data/flydata.gemspec CHANGED
@@ -5,14 +5,14 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "flydata"
8
- s.version = "0.0.5.6"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Koichi Fujikawa"]
12
- s.date = "2014-02-25"
12
+ s.date = "2014-04-18"
13
13
  s.description = "FlyData Command Line Interface"
14
14
  s.email = "sysadmin@flydata.co"
15
- s.executables = ["flydata"]
15
+ s.executables = ["fdmysqldump", "flydata"]
16
16
  s.files = [
17
17
  ".gitignore",
18
18
  ".rspec",
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  "Gemfile.lock",
21
21
  "Rakefile",
22
22
  "VERSION",
23
+ "bin/fdmysqldump",
23
24
  "bin/flydata",
24
25
  "flydata.gemspec",
25
26
  "lib/fly_data_model.rb",
@@ -27,10 +28,13 @@ Gem::Specification.new do |s|
27
28
  "lib/flydata/api/base.rb",
28
29
  "lib/flydata/api/data_entry.rb",
29
30
  "lib/flydata/api/data_port.rb",
31
+ "lib/flydata/api/redshift_cluster.rb",
30
32
  "lib/flydata/api_client.rb",
31
33
  "lib/flydata/cli.rb",
32
34
  "lib/flydata/command/base.rb",
35
+ "lib/flydata/command/conf.rb",
33
36
  "lib/flydata/command/crontab.rb",
37
+ "lib/flydata/command/encrypt.rb",
34
38
  "lib/flydata/command/kill_all.rb",
35
39
  "lib/flydata/command/login.rb",
36
40
  "lib/flydata/command/restart.rb",
@@ -40,26 +44,42 @@ Gem::Specification.new do |s|
40
44
  "lib/flydata/command/setup.rb",
41
45
  "lib/flydata/command/start.rb",
42
46
  "lib/flydata/command/stop.rb",
47
+ "lib/flydata/command/sync.rb",
48
+ "lib/flydata/command/version.rb",
43
49
  "lib/flydata/credentials.rb",
44
50
  "lib/flydata/cron.rb",
51
+ "lib/flydata/fluent-plugins/in_mysql_binlog_flydata.rb",
52
+ "lib/flydata/fluent-plugins/out_forward_ssl.rb",
53
+ "lib/flydata/fluent-plugins/preference.rb",
45
54
  "lib/flydata/flydata_crontab.sh",
46
55
  "lib/flydata/helpers.rb",
47
56
  "lib/flydata/heroku.rb",
48
57
  "lib/flydata/heroku/configuration_methods.rb",
49
58
  "lib/flydata/heroku/instance_methods.rb",
50
59
  "lib/flydata/log_monitor.rb",
60
+ "lib/flydata/preference/data_entry_preference.rb",
51
61
  "lib/flydata/proxy.rb",
62
+ "lib/flydata/sync_file_manager.rb",
63
+ "lib/flydata/table_def.rb",
64
+ "lib/flydata/table_def/mysql_table_def.rb",
65
+ "lib/flydata/table_def/redshift_table_def.rb",
66
+ "lib/flydata/util/encryptor.rb",
67
+ "spec/fluent_plugins_spec_helper.rb",
52
68
  "spec/fly_data_model_spec.rb",
53
69
  "spec/flydata/api/data_entry_spec.rb",
54
70
  "spec/flydata/command/sender_spec.rb",
71
+ "spec/flydata/command/sync_spec.rb",
72
+ "spec/flydata/fluent-plugins/in_mysql_binlog_flydata_spec.rb",
55
73
  "spec/flydata/heroku_spec.rb",
74
+ "spec/flydata/util/encryptor_spec.rb",
56
75
  "spec/flydata_spec.rb",
57
- "spec/spec_helper.rb"
76
+ "spec/spec_helper.rb",
77
+ "tmpl/redshift_mysql_data_entry.conf.tmpl"
58
78
  ]
59
79
  s.homepage = "http://flydata.co/"
60
80
  s.licenses = ["All right reserved."]
61
81
  s.require_paths = ["lib"]
62
- s.rubygems_version = "1.8.28"
82
+ s.rubygems_version = "1.8.24"
63
83
  s.summary = "FlyData CLI"
64
84
 
65
85
  if s.respond_to? :specification_version then
@@ -72,10 +92,18 @@ Gem::Specification.new do |s|
72
92
  s.add_runtime_dependency(%q<json>, ["~> 1.8.0"])
73
93
  s.add_runtime_dependency(%q<highline>, ["~> 1.6.19"])
74
94
  s.add_runtime_dependency(%q<fluentd>, ["= 0.10.35"])
95
+ s.add_runtime_dependency(%q<ruby-binlog>, [">= 1.0.0"])
96
+ s.add_runtime_dependency(%q<fluent-plugin-mysql-binlog>, ["~> 0.0.2"])
97
+ s.add_runtime_dependency(%q<mysql2>, ["~> 0.3.11"])
75
98
  s.add_development_dependency(%q<bundler>, [">= 0"])
76
99
  s.add_development_dependency(%q<jeweler>, [">= 0"])
77
100
  s.add_development_dependency(%q<rspec>, [">= 0"])
101
+ s.add_development_dependency(%q<timecop>, [">= 0"])
78
102
  s.add_development_dependency(%q<sqlite3>, [">= 0"])
103
+ s.add_development_dependency(%q<ruby-prof>, [">= 0"])
104
+ s.add_development_dependency(%q<activemodel>, ["~> 4.0.0"])
105
+ s.add_development_dependency(%q<activerecord>, ["~> 4.0.0"])
106
+ s.add_development_dependency(%q<protected_attributes>, [">= 0"])
79
107
  else
80
108
  s.add_dependency(%q<rest-client>, ["~> 1.6.7"])
81
109
  s.add_dependency(%q<i18n>, ["~> 0.6.5"])
@@ -83,10 +111,18 @@ Gem::Specification.new do |s|
83
111
  s.add_dependency(%q<json>, ["~> 1.8.0"])
84
112
  s.add_dependency(%q<highline>, ["~> 1.6.19"])
85
113
  s.add_dependency(%q<fluentd>, ["= 0.10.35"])
114
+ s.add_dependency(%q<ruby-binlog>, [">= 1.0.0"])
115
+ s.add_dependency(%q<fluent-plugin-mysql-binlog>, ["~> 0.0.2"])
116
+ s.add_dependency(%q<mysql2>, ["~> 0.3.11"])
86
117
  s.add_dependency(%q<bundler>, [">= 0"])
87
118
  s.add_dependency(%q<jeweler>, [">= 0"])
88
119
  s.add_dependency(%q<rspec>, [">= 0"])
120
+ s.add_dependency(%q<timecop>, [">= 0"])
89
121
  s.add_dependency(%q<sqlite3>, [">= 0"])
122
+ s.add_dependency(%q<ruby-prof>, [">= 0"])
123
+ s.add_dependency(%q<activemodel>, ["~> 4.0.0"])
124
+ s.add_dependency(%q<activerecord>, ["~> 4.0.0"])
125
+ s.add_dependency(%q<protected_attributes>, [">= 0"])
90
126
  end
91
127
  else
92
128
  s.add_dependency(%q<rest-client>, ["~> 1.6.7"])
@@ -95,10 +131,18 @@ Gem::Specification.new do |s|
95
131
  s.add_dependency(%q<json>, ["~> 1.8.0"])
96
132
  s.add_dependency(%q<highline>, ["~> 1.6.19"])
97
133
  s.add_dependency(%q<fluentd>, ["= 0.10.35"])
134
+ s.add_dependency(%q<ruby-binlog>, [">= 1.0.0"])
135
+ s.add_dependency(%q<fluent-plugin-mysql-binlog>, ["~> 0.0.2"])
136
+ s.add_dependency(%q<mysql2>, ["~> 0.3.11"])
98
137
  s.add_dependency(%q<bundler>, [">= 0"])
99
138
  s.add_dependency(%q<jeweler>, [">= 0"])
100
139
  s.add_dependency(%q<rspec>, [">= 0"])
140
+ s.add_dependency(%q<timecop>, [">= 0"])
101
141
  s.add_dependency(%q<sqlite3>, [">= 0"])
142
+ s.add_dependency(%q<ruby-prof>, [">= 0"])
143
+ s.add_dependency(%q<activemodel>, ["~> 4.0.0"])
144
+ s.add_dependency(%q<activerecord>, ["~> 4.0.0"])
145
+ s.add_dependency(%q<protected_attributes>, [">= 0"])
102
146
  end
103
147
  end
104
148
 
data/lib/flydata.rb CHANGED
@@ -12,7 +12,9 @@ lib_dir = File.expand_path(File.dirname(__FILE__))
12
12
  ActiveSupport::Dependencies.autoload_paths << lib_dir
13
13
 
14
14
  module Flydata
15
+ FLYDATA_DEBUG = !!(ENV['FLYDATA_DEBUG'])
15
16
  FLYDATA_HOME = ENV['FLYDATA_HOME'] || "#{ENV['HOME']}/.flydata"
16
-
17
+ FLYDATA_GEM_HOME = File.expand_path(File.join(File.dirname(__FILE__), '..'))
18
+ FLYDATA_TMPL_DIR = File.join(FLYDATA_GEM_HOME, 'tmpl')
17
19
  include Flydata::Heroku
18
20
  end
@@ -6,6 +6,10 @@ module Flydata
6
6
  @url_path = "/data_ports/:data_port_id/#{@model_name.pluralize}"
7
7
  super
8
8
  end
9
+
10
+ def buffer_stat(data_entry_id, mode = nil)
11
+ @client.get("/#{@model_name.pluralize}/#{data_entry_id}/buffer_stat/#{mode}")
12
+ end
9
13
  end
10
14
  end
11
15
  end
@@ -0,0 +1,15 @@
1
+ module Flydata
2
+ module Api
3
+ class RedshiftCluster < Base
4
+ def initialize(api_client)
5
+ @model_name = 'redshift_cluster'
6
+ @url_path = "/#{@model_name.pluralize}"
7
+ super
8
+ end
9
+
10
+ def run_query(sql)
11
+ @client.post("#{@url_path}/query", nil, {redshift_query: {body: sql}})
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/flydata/cli.rb CHANGED
@@ -26,6 +26,7 @@ module Flydata
26
26
  puts
27
27
  puts
28
28
  print_usage
29
+ raise e if FLYDATA_DEBUG
29
30
  end
30
31
  end
31
32
 
@@ -8,10 +8,16 @@ module Flydata
8
8
 
9
9
  def retrieve_data_entries
10
10
  data_entries = flydata.get('/data_entries')
11
- unless flydata.response.code == 200
11
+ unless flydata.response.code == 200 and data_entries
12
12
  raise "Failed to retrieve data_entries"
13
13
  end
14
- data_entries
14
+ data_entries.collect do |de|
15
+ if Flydata::Preference::DataEntryPreference.conf_exists?(de)
16
+ Flydata::Preference::DataEntryPreference.load_conf(de)
17
+ else
18
+ de
19
+ end
20
+ end
15
21
  end
16
22
  def register_crontab
17
23
  data_entries = retrieve_data_entries
@@ -0,0 +1,48 @@
1
+ module Flydata
2
+ module Command
3
+ class Conf < Base
4
+ def run
5
+ data_entries = retrieve_data_entries
6
+ copy_conf_tmpl(data_entries)
7
+ usage(data_entries)
8
+ end
9
+
10
+ def copy_templates
11
+ copy_conf_tmpl(retrieve_data_entries)
12
+ end
13
+
14
+ def help
15
+ usage(retrieve_data_entries)
16
+ end
17
+
18
+ private
19
+
20
+ def copy_conf_tmpl(data_entries)
21
+ data_entries.each { |de| Flydata::Preference::DataEntryPreference.copy_template(de) }
22
+ end
23
+
24
+ def usage(data_entries)
25
+ puts "Data Entry Configuration"
26
+ puts "=" * 64
27
+ cnt = 0
28
+ data_entries.each do |de|
29
+ name = "#{de['display_name']}" || de['name']
30
+ file = if Flydata::Preference::DataEntryPreference.configurable?(de)
31
+ cnt += 1
32
+ Flydata::Preference::DataEntryPreference.conf_path(de)
33
+ else
34
+ "(not supported)"
35
+ end
36
+ puts "#{name.ljust(24)} -> #{file}"
37
+ end
38
+ puts "=" * 64
39
+ puts
40
+ if cnt < 1
41
+ puts "There are no configurable data entries."
42
+ else
43
+ puts "Edit above files to change the configuration."
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,18 @@
1
+ module Flydata
2
+ module Command
3
+ class Encrypt < Base
4
+ def run
5
+ dp = flydata.data_port.get
6
+ key = dp['key']
7
+ text = ask_password
8
+ encrypted_text = Flydata::Util::Encryptor.encrypt(text, key)
9
+ puts "Encrypted text: #{encrypted_text}"
10
+ end
11
+
12
+ private
13
+ def ask_password
14
+ ask("Enter text: ") { |x| x.echo = "*" }
15
+ end
16
+ end
17
+ end
18
+ end