flydata 0.0.4.1 → 0.0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4.1
1
+ 0.0.4.2
data/flydata.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "flydata"
8
- s.version = "0.0.4.1"
8
+ s.version = "0.0.4.2"
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 = "2013-02-15"
12
+ s.date = "2013-06-05"
13
13
  s.description = "FlyData Command Line Interface"
14
14
  s.email = "sysadmin@flydata.co"
15
15
  s.executables = ["flydata"]
@@ -57,9 +57,7 @@ module Flydata
57
57
  # delete the '/'
58
58
  @flydata_api_host = @flydata_api_host[0..-2] if @flydata_api_host =~ /\/$/
59
59
  end
60
- def flydata_api_host_file
61
- File.join(home_directory, '.flydata', 'flydata_api_host')
62
- end
60
+
63
61
  def handle_response(response)
64
62
  json_response = JSON.parse(response)
65
63
  if json_response.class == Hash and json_response["success"] == false
data/lib/flydata/cli.rb CHANGED
@@ -1,10 +1,15 @@
1
1
  module Flydata
2
2
  class Cli
3
+ include Helpers
3
4
  def initialize(args)
4
5
  @args = args
5
6
  end
6
7
 
7
8
  def run
9
+ unless check_environment
10
+ puts "Sorry, you have to run the installation command to use flydata. Please go to https://secure.flydata.co/ and sign up."
11
+ return
12
+ end
8
13
  begin
9
14
  if @args.size > 0
10
15
  first_arg = @args.shift
@@ -20,33 +25,16 @@ module Flydata
20
25
  puts "! #{e.to_s}"
21
26
  puts
22
27
  puts
23
- puts '-' * 64
24
28
  print_usage
25
- puts '-' * 64
26
29
  end
27
30
  end
28
31
 
29
32
  private
33
+ def check_environment
34
+ FileTest.file?(flydata_api_host_file)
35
+ end
30
36
  def parse_command(cmd)
31
37
  cmd.split(':')
32
38
  end
33
- def print_usage
34
- puts <<-EOM
35
- Usage: flydata COMMAND
36
- setup # setup initially
37
- start # start flydata process
38
- stop # stop flydata process
39
- restart # restart flydata process
40
- setlogdel # show and change log deletion settting
41
-
42
- If you encountered login or any other errors during setup,
43
- please setup flydata again by following commands.
44
- source ~/.bashrc
45
- flydata setup
46
-
47
- You can check the logs of sender(flydata) process.
48
- Log path: ~/.flydata/flydata.log
49
- EOM
50
- end
51
39
  end
52
40
  end
@@ -47,6 +47,7 @@ module Flydata
47
47
  choose do |menu|
48
48
  menu.index = :number
49
49
  menu.index_suffix = ") "
50
+ menu.select_by = :index
50
51
  menu.prompt = prompt ? prompt : ">> "
51
52
  menu.choices(*menu_list) {|item| choice = value_list[menu_list.index(item)]}
52
53
  end
@@ -5,7 +5,7 @@ module Flydata
5
5
  def start
6
6
  # Check if process exist
7
7
  if process_exist?
8
- say("Process exist. Please stop process first.")
8
+ say("Process is still running. Please stop process first.")
9
9
  return
10
10
  end
11
11
 
@@ -24,7 +24,7 @@ module Flydata
24
24
  data_port = flydata.data_port.get
25
25
  say("Go to your Dashboard! #{flydata.flydata_api_host}/data_ports/#{data_port['id']}")
26
26
  say <<EOF
27
- Please Note: Records and Total Size are updated every 5 minutes. You can download logs one hour after they are generated as they are sent to s3 once per hour.
27
+ Please Note: Records and Total Size are updated every 10 minutes. You can download logs one hour after they are generated as they are sent to s3 once per hour.
28
28
  EOF
29
29
  end
30
30
  def stop
@@ -38,7 +38,7 @@ EOF
38
38
  say('Done.')
39
39
  return true
40
40
  end
41
- raise 'Something wrong..'
41
+ raise 'Something has gone wrong..'
42
42
  end
43
43
  def restart
44
44
  if process_exist?
@@ -47,7 +47,7 @@ EOF
47
47
  say('Done.')
48
48
  return true
49
49
  else
50
- raise 'Something wrong..'
50
+ raise 'Something has gone wrong..'
51
51
  end
52
52
  else
53
53
  say("Process doesn't exist.")
@@ -60,7 +60,7 @@ EOF
60
60
  retry_count = 10
61
61
  1.upto(retry_count) do |i|
62
62
  return true if server_ready?
63
- say("Waiting server side active... (#{i}/#{retry_count})")
63
+ say("Waiting for the server side to become active... (#{i}/#{retry_count})")
64
64
  sleep 30
65
65
  end
66
66
  false
@@ -72,13 +72,13 @@ EOF
72
72
  say("Done! Client is ready now.")
73
73
  return true
74
74
  end
75
- say("Waiting client side active... (#{i}/#{retry_count})")
75
+ say("Waiting for the client side to become active... (#{i}/#{retry_count})")
76
76
  sleep 30
77
77
  end
78
- raise "Somthing wrong... Please try setup command again."
78
+ raise "Somthing has gone wrong... Please try setup command again."
79
79
  end
80
80
  def wait_until_logs_uploaded
81
- say('Starting to check uploading from your server.')
81
+ say('Starting to check the upload from your server.')
82
82
  data_port = flydata.data_port.get
83
83
  data_port_id = data_port['id']
84
84
 
@@ -91,7 +91,7 @@ EOF
91
91
  say("Waiting logs uploading... (#{i}/#{retry_count})")
92
92
  sleep 30
93
93
  end
94
- raise 'Cannot confirm your logs on flydata server. Something wrong..'
94
+ raise 'Cannot confirm that your logs exist on the FlyData server. Something has gone wrong..'
95
95
  end
96
96
 
97
97
  def server_ready?
@@ -1,6 +1,7 @@
1
1
  module Flydata
2
2
  module Command
3
3
  class Setup < Base
4
+ include Helpers
4
5
  LOG_PATH_EXAMPLES=
5
6
  %w(/var/log/httpd/access_log /var/log/apache2/access.log
6
7
  /var/log/httpd-access.log /var/log/apache2/access_log
@@ -14,51 +15,72 @@ module Flydata
14
15
  Dir[str+'*'].grep( /^#{Regexp.escape(str)}/ )
15
16
  end
16
17
 
17
- def run
18
+ def initial_run
19
+ run do
20
+ puts
21
+ shown = show_registered_redshift_entries
22
+ if shown
23
+ true
24
+ else
25
+ _run
26
+ end
27
+ end
28
+ puts
29
+ print_usage
30
+ puts "Completed setup of FlyData!"
31
+ end
32
+
33
+ def run(&block)
18
34
  Flydata::Command::Login.new.run unless flydata.credentials.authenticated?
19
- ret = _run
35
+ ret = block_given? ? yield : _run
20
36
  Flydata::Command::Sender.new.restart if ret
21
37
  end
22
38
 
23
39
  private
24
40
  def _run
25
- ret = nil
26
41
  #ask redshift
27
42
  case ask_data_entry_type
28
43
  when :redshift
29
- ret = start_redshift_mode
44
+ start_redshift_mode
45
+ when :s3backup
46
+ start_s3_backup_mode
47
+ when :restart_flydata
48
+ true
30
49
  else
31
- ret = start_s3_backup_mode
50
+ false
32
51
  end
33
- ret
34
52
  end
35
53
  def ask_data_entry_type
36
- choose_one('Please select a setup type', nil,
37
- ["Redshift and S3 Backup", "S3 Buckup only"],
38
- [:redshift, :s3backup])
54
+ choose_one('Choose an option', nil,
55
+ ["Setup Redshift and S3 Backup", "Setup S3 Backup only", "Restart FlyData", "Cancel"],
56
+ [:redshift, :s3backup, :restart_flydata, :cancel])
39
57
  end
40
58
 
41
- #### redshift buckup mode
59
+ #### redshift backup mode
42
60
  def start_redshift_mode
43
61
  newline
44
- shown = show_registered_entries('RedshiftFileDataEntry') do |de|
45
- say(" - #{de['display_name']}: \t#{de['log_path']} -> #{de['redshift_table_name']}")
46
- end
62
+ show_registered_redshift_entries
47
63
  newline
48
64
  ask_adding_new_redshift
49
65
  end
50
66
 
67
+ def show_registered_redshift_entries
68
+ show_registered_entries('RedshiftFileDataEntry') do |de|
69
+ say(" - #{de['display_name']}: #{de['log_path']} -> #{de['redshift_table_name']} (#{de['redshift_table_name']}_dev)")
70
+ end
71
+ end
72
+
51
73
  def ask_adding_new_redshift
52
- puts "Start to register a new entry."
74
+ puts "Start registration of a new entry:"
53
75
  newline
54
76
  # select table on redshift
55
- puts "[Select a Table Name on Redshift]"
77
+ puts "[Select a Table from your Redshift cluster]"
56
78
  table_name = ask_redshift_table_name
57
79
  return unless table_name
58
80
  newline
59
81
  # enter the log path
60
82
  puts "[Enter a Local Log Path]"
61
- puts "Enter the absolute path of your local log for uploading to '#{table_name}' table on Redshift."
83
+ puts "Enter the absolute path of your local log that you want to upload to the '#{table_name}' table on Redshift."
62
84
  log_path = ask_log_path("Log path (tab:completion, return:cancel) >> ")
63
85
  return unless log_path and not log_path.empty?
64
86
  newline
@@ -69,25 +91,59 @@ module Flydata
69
91
  newline
70
92
  puts "[Confirm]"
71
93
  separator
72
- puts " table(redshift) -> #{table_name}"
73
- puts " local log path -> #{log_path}"
94
+ puts " table(redshift) -> #{table_name} (#{table_name}_dev)"
95
+ puts " local log path -> #{log_path}"
74
96
  puts " log file format -> #{log_file_type}"
75
97
  separator
76
- return unless ask_yes_no("Register a new entry?", true)
98
+ return unless ask_yes_no("Are you sure you want to register this new entry?", true)
77
99
  create_redshift_log_entry(log_path, log_file_type, table_name)
78
100
  end
79
101
 
80
102
  def choose_log_file_type(target_path)
81
- choose_one("Please select your log file format of (#{target_path})", nil,
103
+ choose_one("Please select the log file format of (#{target_path})", nil,
82
104
  %w(csv tsv json))
83
105
  end
84
106
 
85
107
  def ask_redshift_table_name
86
108
  ret = flydata.data_port.redshift_table_list
87
- if ret['table_list'].size < 1
88
- raise "Could not find tables on Redshift. Please create tables on your Redshift cluster."
109
+
110
+ all_tables = ret['table_list'].collect {|tn| tn.gsub(/_dev$/, '')}.uniq
111
+ prod_tables = ret['table_list'].select {|tn| not tn.end_with?('_dev')}
112
+ dev_tables = ret['table_list'].select {|tn| tn.end_with?('_dev')}
113
+
114
+ if all_tables.size < 1
115
+ raise "Could not find tables on Redshift. Please create some tables on your Redshift cluster."
116
+ end
117
+
118
+ if development?
119
+ menu_list = all_tables.collect do |tn|
120
+ menu = ["#{tn}", "( #{tn}_dev )"]
121
+ if dev_tables.index("#{tn}_dev").nil?
122
+ menu << "!WARN The '#{tn}_dev' table does not exist on your Redshift cluster"
123
+ else
124
+ menu << "OK"
125
+ end
126
+ menu
127
+ end
128
+ menu_str_list = format_menu_list(menu_list)
129
+ message = " !DEVELOPMENT MODE! FlyData will only upload to tables with '_dev' suffix in the name."
130
+ else
131
+ menu_list = all_tables.collect do |tn|
132
+ menu = ["#{tn}", "( #{tn}_dev )"]
133
+ if prod_tables.index("#{tn}").nil?
134
+ menu << "!WARN '#{tn}' table does not exist"
135
+ else
136
+ menu << "OK"
137
+ end
138
+ menu
139
+ end
140
+ menu_str_list = format_menu_list(menu_list)
141
+ message = " !PRODUCTION MODE!"
142
+ end
143
+ menu_str = choose_one("Please select the table on Redshift that you want to use to store your local data. \n#{message}", nil, menu_str_list)
144
+ if menu_str
145
+ menu_str.split.first
89
146
  end
90
- choose_one("Please select the table name on Redshift to store your local data.", nil, ret['table_list'])
91
147
  end
92
148
 
93
149
  def create_redshift_log_entry(log_path, log_file_type, redshift_table_name)
@@ -101,7 +157,7 @@ module Flydata
101
157
  return true
102
158
  end
103
159
 
104
- #### s3 buckup mode
160
+ #### s3 backup mode
105
161
  def start_s3_backup_mode
106
162
  # choose entries
107
163
  unless (shown = show_registered_entries)
@@ -125,7 +181,7 @@ module Flydata
125
181
  @last_fetched_entries = data_entries
126
182
  data_entries = data_entries.select {|de| de['type'] == type}
127
183
  if data_entries and data_entries.size > 0
128
- puts('Registered entries on FlyData. ')
184
+ puts('Registered entries on FlyData: ')
129
185
  separator
130
186
  data_entries.each { |data_entry|
131
187
  if block_given?
@@ -10,11 +10,66 @@ module Flydata
10
10
  end
11
11
  [klass, method]
12
12
  end
13
+
14
+ def print_usage
15
+ puts '-' * 64
16
+ puts <<-EOM
17
+ Usage: flydata COMMAND
18
+ setup # setup initially
19
+ start # start flydata process
20
+ stop # stop flydata process
21
+ restart # restart flydata process
22
+
23
+ If you encountered login or any other errors during setup,
24
+ please setup flydata again by following commands.
25
+ source ~/.bashrc
26
+ flydata setup
27
+
28
+ You can check the logs of sender(flydata) process.
29
+ Log path: ~/.flydata/flydata.log
30
+ EOM
31
+ puts '-' * 64
32
+ end
33
+
13
34
  def to_command_class(class_name)
14
35
  eval("Flydata::Command::#{class_name.camelcase}")
15
36
  end
37
+
38
+ def development?
39
+ File.open(flydata_conf_file).first.strip.end_with?('dev')
40
+ end
41
+
42
+ # format text
43
+ def format_menu_list(menu_list)
44
+ max_length_list = menu_list.inject(Array.new(menu_list.first.size, 0)) do |ml, menu|
45
+ 0.upto(menu.size - 1) do |i|
46
+ ml[i] = menu[i].length if ml[i] < menu[i].length
47
+ end
48
+ ml
49
+ end
50
+
51
+ menu_list = menu_list.collect do |menu|
52
+ 0.upto(menu.size - 1).inject("") do |str, i|
53
+ str = "#{str}#{menu[i].ljust(max_length_list[i] + 1, ' ')}"
54
+ end
55
+ end
56
+ end
57
+
58
+ # file paths
16
59
  def home_directory
17
60
  ENV['HOME'] || Dir.pwd
18
61
  end
62
+
63
+ def flydata_home_directory
64
+ File.join(home_directory, '.flydata')
65
+ end
66
+
67
+ def flydata_api_host_file
68
+ File.join(flydata_home_directory, 'flydata_api_host')
69
+ end
70
+
71
+ def flydata_conf_file
72
+ File.join(flydata_home_directory, 'flydata.conf')
73
+ end
19
74
  end
20
75
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flydata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4.1
4
+ version: 0.0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-15 00:00:00.000000000 Z
12
+ date: 2013-06-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -275,7 +275,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
275
275
  version: '0'
276
276
  segments:
277
277
  - 0
278
- hash: -1830851473606011270
278
+ hash: 258014642818965093
279
279
  required_rubygems_version: !ruby/object:Gem::Requirement
280
280
  none: false
281
281
  requirements: