flydata 0.0.1.nc2 → 0.0.1.2011101801

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.1.nc2
1
+ 0.0.1.2011101801
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.1.nc2"
8
+ s.version = "0.0.1.2011101801"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
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 = "2012-10-29"
12
+ s.date = "2012-10-19"
13
13
  s.description = "FlyData Command Line Interface"
14
14
  s.email = "sysadmin@flydata.co"
15
15
  s.executables = ["flydata"]
@@ -29,18 +29,11 @@ Gem::Specification.new do |s|
29
29
  "lib/flydata/api_client.rb",
30
30
  "lib/flydata/cli.rb",
31
31
  "lib/flydata/command/base.rb",
32
- "lib/flydata/command/crontab.rb",
33
32
  "lib/flydata/command/login.rb",
34
- "lib/flydata/command/restart.rb",
35
33
  "lib/flydata/command/routine.rb",
36
34
  "lib/flydata/command/sender.rb",
37
- "lib/flydata/command/setlogdel.rb",
38
35
  "lib/flydata/command/setup.rb",
39
- "lib/flydata/command/start.rb",
40
- "lib/flydata/command/stop.rb",
41
36
  "lib/flydata/credentials.rb",
42
- "lib/flydata/cron.rb",
43
- "lib/flydata/flydata_crontab.sh",
44
37
  "lib/flydata/helpers.rb",
45
38
  "lib/flydata/log_monitor.rb",
46
39
  "lib/flydata/proxy.rb",
@@ -52,7 +45,7 @@ Gem::Specification.new do |s|
52
45
  s.homepage = "http://flydata.co/"
53
46
  s.licenses = ["All right reserved."]
54
47
  s.require_paths = ["lib"]
55
- s.rubygems_version = "1.8.23"
48
+ s.rubygems_version = "1.8.15"
56
49
  s.summary = "FlyData CLI"
57
50
 
58
51
  if s.respond_to? :specification_version then
@@ -5,7 +5,7 @@ module Flydata
5
5
  @client = api_client
6
6
  end
7
7
  def list(params={})
8
- @client.get(@url_path)
8
+ JSON.parse(@client.get(@url_path))
9
9
  end
10
10
  def create(params={})
11
11
  params.each {|k, v| @url_path.gsub!(/:#{k}/, v.to_s)}
@@ -1,16 +1,14 @@
1
1
  require 'rest_client'
2
- require 'singleton'
3
2
 
4
3
  module Flydata
5
4
  FLYDATA_API_HOST = ENV['FLYDATA_API_HOST'] || 'flydata.co'
6
5
 
7
6
  class ApiClient
8
- include Singleton
9
7
  attr_reader :response
10
8
  attr_accessor :credentials
11
9
 
12
- def initialize
13
- @credentials = Flydata::Credentials.new
10
+ def initialize(credentials=nil)
11
+ @credentials = credentials || Flydata::Credentials.new
14
12
  end
15
13
 
16
14
  # row level api
@@ -18,19 +16,11 @@ module Flydata
18
16
  uri = "http://#{FLYDATA_API_HOST}#{path}"
19
17
  resource = RestClient::Resource.new(uri, resource_opts)
20
18
  @response = resource.post(params, :accept => :json)
21
- handle_response response
22
- end
23
- def put(path, params=nil)
24
- uri = "http://#{FLYDATA_API_HOST}#{path}"
25
- resource = RestClient::Resource.new(uri, resource_opts)
26
- @response = resource.put(params, :accept => :json)
27
- handle_response response
28
19
  end
29
20
  def get(path)
30
21
  uri = "http://#{FLYDATA_API_HOST}#{path}"
31
22
  resource = RestClient::Resource.new(uri, resource_opts)
32
23
  @response = resource.get(:accept => :json)
33
- handle_response response
34
24
  end
35
25
 
36
26
  # high level api
@@ -42,14 +32,6 @@ module Flydata
42
32
  def respond_to_missing?(method_name, include_private=false); true end
43
33
 
44
34
  private
45
- def handle_response(response)
46
- json_response = JSON.parse(response)
47
- if json_response.class == Hash and json_response["success"] == false
48
- err_msg = json_response['errors'] ? json_response['errors'].to_s : "Unkown error."
49
- raise err_msg
50
- end
51
- json_response
52
- end
53
35
  def resource_opts
54
36
  {:user => @credentials.user, :password => @credentials.password}
55
37
  end
data/lib/flydata/cli.rb CHANGED
@@ -31,19 +31,6 @@ module Flydata
31
31
  puts <<-EOM
32
32
  Usage: flydata COMMAND
33
33
  setup # setup initially
34
- start # start flydata process
35
- stop # stop flydata process
36
- restart # restart flydata process
37
- setlogdel # show and change log deletion settting
38
-
39
- If you encountered login or any other errors during setup,
40
- please setup flydata again by following commands.
41
- source ~/.bashrc
42
- flydata setup
43
-
44
- You can check the logs of sender(flydata) process.
45
- Log path: ~/.flydata/flydata.log
46
-
47
34
  EOM
48
35
  end
49
36
  end
@@ -2,39 +2,9 @@ module Flydata
2
2
  module Command
3
3
  class Base
4
4
  def initialize
5
- @api_client = ApiClient.instance
5
+ @api_client = ApiClient.new
6
6
  end
7
7
  def flydata; @api_client end
8
-
9
- def retrieve_data_entries
10
- data_entries = flydata.get('/data_entries')
11
- unless flydata.response.code == 200
12
- raise "Failed to retrieve data_entries"
13
- end
14
- data_entries
15
- end
16
- def register_crontab
17
- data_entries = retrieve_data_entries
18
- if data_entries.any?{|e| e['log_deletion']}
19
- Flydata::Command::Crontab.new.run
20
- end
21
- end
22
-
23
- # print console
24
- def newline; puts end
25
- def ask_yes_no(message)
26
- loop do
27
- ans = ask("#{message} (yes/no): ")
28
- if ans.size > 0
29
- case ans[0].downcase
30
- when 'y'; return true
31
- when 'n'; return false
32
- end
33
- end
34
- say(" ! Please answer y[es] or n[o]")
35
- newline
36
- end
37
- end
38
8
  end
39
9
  end
40
10
  end
@@ -1,38 +1,21 @@
1
1
  module Flydata
2
2
  module Command
3
3
  class Login < Base
4
- LOGIN_TRIAL_TIMES=3
5
4
  def run
6
- ret = login(LOGIN_TRIAL_TIMES)
7
- raise "Login failed #{LOGIN_TRIAL_TIMES} times." unless ret
8
- ret
9
- end
10
-
11
- private
12
- def login(times=3)
13
- 1.upto(times) do |i|
14
- begin
15
- return true if login_once
16
- rescue Exception => e
17
- puts e
18
- end
19
- end
20
- false
21
- end
22
- def login_once
23
- # Ask login info
24
5
  email = ask("FlyData Email: ")
25
6
  password = ask("FlyData password: ") {|q| q.echo = false}
26
7
  flydata.credentials = Flydata::Credentials.new(email, password)
27
- # Auth request
8
+
9
+ login
10
+ end
11
+
12
+ private
13
+ def login
28
14
  flydata.post('/users/sign_in')
29
15
  if flydata.response.code == 201 # 201: Created
30
16
  say("Login succeeded!")
31
17
  flydata.credentials.authenticate!
32
- return true
33
18
  end
34
- say("Login failed!")
35
- false
36
19
  end
37
20
  end
38
21
  end
@@ -2,27 +2,26 @@ module Flydata
2
2
  module Command
3
3
  class Routine < Base
4
4
  def run
5
- print "#{Time.now} "
6
5
  unless flydata.credentials.authenticated?
7
6
  raise "Authentication error. Please login."
8
7
  end
9
8
  log_paths = retrieve_log_paths
10
9
  log_paths and log_paths.size() > 0 and log_paths.each { |path|
11
10
  if File.exist?(path) and File.writable?(path)
12
- puts "Start - #{path}. "
13
11
  Flydata::LogMonitor.new(path).setup.rotate
14
12
  else
15
- puts "Skip - #{path}. System cannot access this path."
13
+ puts "Skip - #{path}. System cannot access this path."
16
14
  end
17
15
  }
18
16
  end
19
17
 
20
18
  private
21
19
  def retrieve_log_paths
22
- data_entries = retrieve_data_entries
23
- data_entries.map {|e|
24
- e['log_path'] if e['log_deletion']
25
- }.compact
20
+ data_entries = JSON.parse(flydata.get('/data_entries'))
21
+ unless flydata.response.code == 200 && data_entries.size > 0
22
+ raise "Failed to retrieve data_ports ids"
23
+ end
24
+ data_entries.map {|e| e["log_path"]}
26
25
  end
27
26
  end
28
27
  end
@@ -3,92 +3,49 @@ module Flydata
3
3
  class Sender < Base
4
4
  FLYDATA_HOME=Flydata::HOME_DIR
5
5
  def start
6
- # Check if process exist
7
6
  if process_exist?
8
7
  say("Process exist. Please stop process first.")
9
8
  return
10
9
  end
11
10
 
12
- wait_until_server_ready
13
-
14
- # Start sender(fluentd) process
15
- say('Starting sender process.')
16
- Dir.chdir(FLYDATA_HOME){
17
- system("fluentd -d #{FLYDATA_HOME}/flydata.pid -l #{FLYDATA_HOME}/flydata.log -c #{FLYDATA_HOME}/flydata.conf")
18
- }
19
- sleep 5
20
-
21
- wait_until_client_ready
22
- wait_until_logs_uploaded
23
- say("Go to your Dashboard! http://#{Flydata::FLYDATA_API_HOST}")
24
- end
25
- def stop
26
- unless process_exist?
27
- say("Process doesn't exist.")
28
- return true
29
- end
30
-
31
- say('Stopping sender process.')
32
- if system("kill `cat #{FLYDATA_HOME}/flydata.pid`")
33
- say('Done.')
34
- return true
35
- end
36
- raise 'Something wrong..'
37
- end
38
- def restart
39
- if process_exist?
40
- say('Restarting sender process.')
41
- if system("kill -HUP `cat #{FLYDATA_HOME}/flydata.pid`")
42
- say('Done.')
43
- return true
44
- else
45
- raise 'Something wrong..'
46
- end
47
- else
48
- say("Process doesn't exist.")
49
- start
50
- end
51
- end
52
-
53
- private
54
- def wait_until_server_ready
55
11
  retry_count = 10
56
12
  1.upto(retry_count) do |i|
57
- return true if server_ready?
13
+ break if server_ready?
58
14
  say("Waiting server side active... (#{i}/#{retry_count})")
59
15
  sleep 30
60
16
  end
61
- false
62
- end
63
- def wait_until_client_ready
17
+
18
+ say('Starting sender process.')
19
+ system("fluentd -d #{FLYDATA_HOME}/flydata.pid -l #{FLYDATA_HOME}/flydata.log -c #{FLYDATA_HOME}/flydata.conf")
20
+
21
+ sleep 5
64
22
  retry_count = 10
65
23
  1.upto(retry_count) do |i|
66
24
  if client_ready?
67
- say("Done! Client is ready now.")
25
+ say('Done.')
68
26
  return true
69
27
  end
70
28
  say("Waiting client side active... (#{i}/#{retry_count})")
71
29
  sleep 30
72
30
  end
73
- raise "Somthing wrong... Please try setup command again."
74
- end
75
- def wait_until_logs_uploaded
76
- say('Starting to check uploading from your server.')
77
- data_port = flydata.data_port.get
78
- data_port_id = data_port['id']
79
31
 
80
- retry_count = 10
81
- 1.upto(retry_count) do |i|
82
- if uploaded_successfully?(data_port_id)
83
- say("Uploading your logs correctly.")
84
- return true
85
- end
86
- say("Waiting logs uploading... (#{i}/#{retry_count})")
87
- sleep 30
32
+ say('Something wrong..')
33
+ end
34
+ def stop
35
+ say('Stopping sender process.')
36
+ if system("kill `cat #{FLYDATA_HOME}/flydata.pid`")
37
+ say('Done.')
38
+ return true
39
+ else
40
+ say('Something wrong..')
88
41
  end
89
- raise 'Cannot confirm your logs on flydata server. Something wrong..'
42
+ end
43
+ def restart
44
+ say('Restarting sender process.')
45
+ stop and start
90
46
  end
91
47
 
48
+ private
92
49
  def server_ready?
93
50
  data_port = flydata.data_port.get
94
51
  data_port['server_status'] == 'active'
@@ -97,13 +54,9 @@ module Flydata
97
54
  process_exist?
98
55
  end
99
56
  def process_exist?
100
- process_count = `ps aux|grep -v grep|grep "\\.flydata/flydata\\.conf"|grep fluentd|wc -l`.to_i
57
+ process_count = `ps aux|grep -v grep|grep "\\.flydata/"|wc -l`.to_i
101
58
  process_count > 0
102
59
  end
103
- def uploaded_successfully?(data_port_id)
104
- res = flydata.get("/data_ports/#{data_port_id}/tail.json")
105
- res and res['logs'] and res['logs'].size > 0
106
- end
107
60
  end
108
61
  end
109
62
  end
@@ -18,48 +18,23 @@ module Flydata
18
18
  # login
19
19
  Flydata::Command::Login.new.run unless flydata.credentials.authenticated?
20
20
 
21
- # choose entries
22
- unless shown = show_registered_entries and not more_entry?
23
- begin
24
- show_registered_entries unless shown
25
- shown = false
26
- path = choose_log_path_from_examples
27
- case path
28
- when OTHER; ask_log_path
29
- else; create_log_entry(path, ask_log_deletion(path))
30
- end
31
- newline
32
- end while more_entry?
33
- end
34
-
35
- # register cron if registered log deletion
36
- register_crontab
21
+ begin
22
+ path = choose_log_path_from_examples
23
+ case path
24
+ when OTHER; ask_log_path
25
+ else; create_log_entry(path)
26
+ end
27
+ newline
28
+ end while more_entry?
37
29
 
38
30
  # start client process
39
- Flydata::Command::Sender.new.restart
31
+ sender = Flydata::Command::Sender.new
32
+ sender.start
40
33
  end
41
34
 
42
35
  private
43
- def show_registered_entries
44
- data_entries = retrieve_data_entries
45
- @last_fetched_entries = data_entries
46
- if data_entries and data_entries.size > 0
47
- puts('Registered entries. ')
48
- data_entries.each { |data_entry|
49
- say(" - #{data_entry['display_name']}\t#{data_entry['log_path']}")
50
- }
51
- true
52
- else
53
- false
54
- end
55
- end
56
36
  def choose_log_path_from_examples
57
37
  candidates = (`ls #{LOG_PATH_EXAMPLES.join(' ')} 2>/dev/null`).split(/\s+/)
58
- candidates = candidates.find_all{|path| File.readable?(path)}
59
- if @last_fetched_entries
60
- candidates = candidates - @last_fetched_entries.map{|v| v['log_path']}
61
- end
62
- return OTHER unless candidates.size > 0
63
38
  candidates << OTHER
64
39
  choice = nil
65
40
  say('Please select your log path for sending FlyData')
@@ -78,38 +53,31 @@ module Flydata
78
53
  loop do
79
54
  path = Readline.readline("Enter the absolute path of your log (return to cancel): ")
80
55
  return if path.empty?
81
- if not (FileTest.file?(path) and FileTest.readable?(path))
82
- say(" ! #{path} is not a readable file!")
83
- elsif @last_fetched_entries and @last_fetched_entries.any?{|e| e['log_path'] == path}
84
- say(" ! #{path} has been registered already.")
85
- else
86
- break
87
- end
56
+ break if FileTest.file?(path) and FileTest.readable?(path)
57
+ say(" ! #{path} is not a readable file!")
88
58
  newline
89
59
  end
90
- create_log_entry(path, ask_log_deletion(path))
60
+ create_log_entry(path)
91
61
  end
92
- def ask_log_deletion(path)
93
- unless File.writable?(path)
94
- say("Skip log deletion setting...")
95
- say(" This path is readonly for current user.")
96
- say(" Change user or permission, if you want to set log deletion option.")
97
- newline
98
- return
99
- end
100
- say("** Log deletion setting **")
101
- say("Flydata has a log deletion feature that flydata will delete old log archives uploaded by flydata automatically.")
102
- say("Flydata will delete logs whose last modified timestamp is 7 days ago.")
103
- ask_yes_no("Set auto log deletion mode?")
104
- end
105
- def create_log_entry(path, log_deletion)
62
+ def create_log_entry(path)
106
63
  data_port = flydata.data_port.get
107
- flydata.data_entry.create(data_port_id: data_port['id'], log_path: path, log_deletion: log_deletion)
64
+ flydata.data_entry.create(data_port_id: data_port['id'], log_path: path)
108
65
  say("Process successfuly!") if flydata.response.code == 200
109
66
  end
110
67
  def more_entry?
111
- ask_yes_no("Do you want to add more log path?")
68
+ loop do
69
+ ans = ask("Do you want to add more log path? (yes/no): ")
70
+ if ans.size > 0
71
+ case ans[0].downcase
72
+ when 'y'; return true
73
+ when 'n'; return false
74
+ end
75
+ end
76
+ say(" ! Please answer y[es] or n[o]")
77
+ newline
78
+ end
112
79
  end
80
+ def newline; puts end
113
81
  end
114
82
  end
115
83
  end
@@ -4,12 +4,9 @@ module Flydata
4
4
  attr_reader :user, :password
5
5
  def initialize(user=nil, password=nil)
6
6
  read_credentials
7
- if user && password
8
- @user = user
9
- @password = password
10
- elsif !(@authenticated)
11
- @user = ENV['FLYDATA_LOGIN']
12
- @password = ENV['FLYDATA_PASSWORD']
7
+ unless @authenticated
8
+ @user = user || ENV['FLYDATA_LOGIN']
9
+ @password = password || ENV['FLYDATA_PASSWORD']
13
10
  end
14
11
  end
15
12
  def authenticate!
@@ -28,7 +28,7 @@ module Flydata
28
28
  # initialize paths
29
29
  @flydata_path = File.join(File.dirname(@log_path),
30
30
  FLYDATA_DIR,
31
- File.basename(@log_path) + ".d")
31
+ File.basename(@log_path))
32
32
  @backup_path = File.join(@flydata_path, BACKUP_DIR)
33
33
  @trash_path = File.join(@flydata_path, TRASH_DIR)
34
34
  end
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flydata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.nc2
5
- prerelease: 6
4
+ version: 0.0.1.2011101801
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Koichi Fujikawa
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-29 00:00:00.000000000 Z
12
+ date: 2012-10-19 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &70220409278880 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,15 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
24
+ version_requirements: *70220409278880
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: i18n
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &70220409278380 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
30
  - - ! '>='
@@ -37,15 +32,10 @@ dependencies:
37
32
  version: '0'
38
33
  type: :runtime
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
35
+ version_requirements: *70220409278380
46
36
  - !ruby/object:Gem::Dependency
47
37
  name: activesupport
48
- requirement: !ruby/object:Gem::Requirement
38
+ requirement: &70220409277880 !ruby/object:Gem::Requirement
49
39
  none: false
50
40
  requirements:
51
41
  - - ! '>='
@@ -53,15 +43,10 @@ dependencies:
53
43
  version: '0'
54
44
  type: :runtime
55
45
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
46
+ version_requirements: *70220409277880
62
47
  - !ruby/object:Gem::Dependency
63
48
  name: json
64
- requirement: !ruby/object:Gem::Requirement
49
+ requirement: &70220409277360 !ruby/object:Gem::Requirement
65
50
  none: false
66
51
  requirements:
67
52
  - - ! '>='
@@ -69,15 +54,10 @@ dependencies:
69
54
  version: '0'
70
55
  type: :runtime
71
56
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
57
+ version_requirements: *70220409277360
78
58
  - !ruby/object:Gem::Dependency
79
59
  name: highline
80
- requirement: !ruby/object:Gem::Requirement
60
+ requirement: &70220409276860 !ruby/object:Gem::Requirement
81
61
  none: false
82
62
  requirements:
83
63
  - - ! '>='
@@ -85,15 +65,10 @@ dependencies:
85
65
  version: '0'
86
66
  type: :runtime
87
67
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
68
+ version_requirements: *70220409276860
94
69
  - !ruby/object:Gem::Dependency
95
70
  name: fluentd
96
- requirement: !ruby/object:Gem::Requirement
71
+ requirement: &70220409276380 !ruby/object:Gem::Requirement
97
72
  none: false
98
73
  requirements:
99
74
  - - ! '>='
@@ -101,15 +76,10 @@ dependencies:
101
76
  version: '0'
102
77
  type: :runtime
103
78
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
79
+ version_requirements: *70220409276380
110
80
  - !ruby/object:Gem::Dependency
111
81
  name: bundler
112
- requirement: !ruby/object:Gem::Requirement
82
+ requirement: &70220409275880 !ruby/object:Gem::Requirement
113
83
  none: false
114
84
  requirements:
115
85
  - - ! '>='
@@ -117,15 +87,10 @@ dependencies:
117
87
  version: '0'
118
88
  type: :development
119
89
  prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ! '>='
124
- - !ruby/object:Gem::Version
125
- version: '0'
90
+ version_requirements: *70220409275880
126
91
  - !ruby/object:Gem::Dependency
127
92
  name: jeweler
128
- requirement: !ruby/object:Gem::Requirement
93
+ requirement: &70220409275400 !ruby/object:Gem::Requirement
129
94
  none: false
130
95
  requirements:
131
96
  - - ! '>='
@@ -133,15 +98,10 @@ dependencies:
133
98
  version: '0'
134
99
  type: :development
135
100
  prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
- requirements:
139
- - - ! '>='
140
- - !ruby/object:Gem::Version
141
- version: '0'
101
+ version_requirements: *70220409275400
142
102
  - !ruby/object:Gem::Dependency
143
103
  name: rspec
144
- requirement: !ruby/object:Gem::Requirement
104
+ requirement: &70220409274900 !ruby/object:Gem::Requirement
145
105
  none: false
146
106
  requirements:
147
107
  - - ! '>='
@@ -149,15 +109,10 @@ dependencies:
149
109
  version: '0'
150
110
  type: :development
151
111
  prerelease: false
152
- version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
- requirements:
155
- - - ! '>='
156
- - !ruby/object:Gem::Version
157
- version: '0'
112
+ version_requirements: *70220409274900
158
113
  - !ruby/object:Gem::Dependency
159
114
  name: autotest
160
- requirement: !ruby/object:Gem::Requirement
115
+ requirement: &70220409274420 !ruby/object:Gem::Requirement
161
116
  none: false
162
117
  requirements:
163
118
  - - ! '>='
@@ -165,15 +120,10 @@ dependencies:
165
120
  version: '0'
166
121
  type: :development
167
122
  prerelease: false
168
- version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
- requirements:
171
- - - ! '>='
172
- - !ruby/object:Gem::Version
173
- version: '0'
123
+ version_requirements: *70220409274420
174
124
  - !ruby/object:Gem::Dependency
175
125
  name: autotest-standalone
176
- requirement: !ruby/object:Gem::Requirement
126
+ requirement: &70220409273940 !ruby/object:Gem::Requirement
177
127
  none: false
178
128
  requirements:
179
129
  - - ! '>='
@@ -181,15 +131,10 @@ dependencies:
181
131
  version: '0'
182
132
  type: :development
183
133
  prerelease: false
184
- version_requirements: !ruby/object:Gem::Requirement
185
- none: false
186
- requirements:
187
- - - ! '>='
188
- - !ruby/object:Gem::Version
189
- version: '0'
134
+ version_requirements: *70220409273940
190
135
  - !ruby/object:Gem::Dependency
191
136
  name: autotest-notification
192
- requirement: !ruby/object:Gem::Requirement
137
+ requirement: &70220409273460 !ruby/object:Gem::Requirement
193
138
  none: false
194
139
  requirements:
195
140
  - - ! '>='
@@ -197,15 +142,10 @@ dependencies:
197
142
  version: '0'
198
143
  type: :development
199
144
  prerelease: false
200
- version_requirements: !ruby/object:Gem::Requirement
201
- none: false
202
- requirements:
203
- - - ! '>='
204
- - !ruby/object:Gem::Version
205
- version: '0'
145
+ version_requirements: *70220409273460
206
146
  - !ruby/object:Gem::Dependency
207
147
  name: ZenTest
208
- requirement: !ruby/object:Gem::Requirement
148
+ requirement: &70220409272980 !ruby/object:Gem::Requirement
209
149
  none: false
210
150
  requirements:
211
151
  - - ! '>='
@@ -213,12 +153,7 @@ dependencies:
213
153
  version: '0'
214
154
  type: :development
215
155
  prerelease: false
216
- version_requirements: !ruby/object:Gem::Requirement
217
- none: false
218
- requirements:
219
- - - ! '>='
220
- - !ruby/object:Gem::Version
221
- version: '0'
156
+ version_requirements: *70220409272980
222
157
  description: FlyData Command Line Interface
223
158
  email: sysadmin@flydata.co
224
159
  executables:
@@ -241,18 +176,11 @@ files:
241
176
  - lib/flydata/api_client.rb
242
177
  - lib/flydata/cli.rb
243
178
  - lib/flydata/command/base.rb
244
- - lib/flydata/command/crontab.rb
245
179
  - lib/flydata/command/login.rb
246
- - lib/flydata/command/restart.rb
247
180
  - lib/flydata/command/routine.rb
248
181
  - lib/flydata/command/sender.rb
249
- - lib/flydata/command/setlogdel.rb
250
182
  - lib/flydata/command/setup.rb
251
- - lib/flydata/command/start.rb
252
- - lib/flydata/command/stop.rb
253
183
  - lib/flydata/credentials.rb
254
- - lib/flydata/cron.rb
255
- - lib/flydata/flydata_crontab.sh
256
184
  - lib/flydata/helpers.rb
257
185
  - lib/flydata/log_monitor.rb
258
186
  - lib/flydata/proxy.rb
@@ -275,16 +203,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
275
203
  version: '0'
276
204
  segments:
277
205
  - 0
278
- hash: 3903877029269313970
206
+ hash: 1202166163575531449
279
207
  required_rubygems_version: !ruby/object:Gem::Requirement
280
208
  none: false
281
209
  requirements:
282
- - - ! '>'
210
+ - - ! '>='
283
211
  - !ruby/object:Gem::Version
284
- version: 1.3.1
212
+ version: '0'
285
213
  requirements: []
286
214
  rubyforge_project:
287
- rubygems_version: 1.8.23
215
+ rubygems_version: 1.8.15
288
216
  signing_key:
289
217
  specification_version: 3
290
218
  summary: FlyData CLI
@@ -1,9 +0,0 @@
1
- module Flydata
2
- module Command
3
- class Crontab < Base
4
- def run(args='')
5
- Flydata::Cron.new.update args
6
- end
7
- end
8
- end
9
- end
@@ -1,10 +0,0 @@
1
- module Flydata
2
- module Command
3
- class Restart < Base
4
- def run
5
- sender = Flydata::Command::Sender.new
6
- sender.restart
7
- end
8
- end
9
- end
10
- end
@@ -1,82 +0,0 @@
1
- module Flydata
2
- module Command
3
- class Setlogdel < Base
4
- def run
5
- Flydata::Command::Login.new.run unless flydata.credentials.authenticated?
6
- # Choose target data_entry
7
- data_entry = choose_data_entry
8
- return unless data_entry
9
- # Confirm and update
10
- set_log_deletion data_entry if confirm_setting data_entry
11
- register_crontab
12
- end
13
-
14
- private
15
- def choose_data_entry
16
- data_entries = retrieve_data_entries
17
- if data_entries.size < 1
18
- puts("There are no registered entries.")
19
- puts("You need to create a data entry by flydata setup command.")
20
- return nil
21
- end
22
- choices = data_entries.map {|e|
23
- file_attr = File.writable?(e['log_path']) ? "" : "(read only)"
24
- "#{e['display_name']}\t#{e['log_path']}\t -- Log deletion:#{boolToOnOff e['log_deletion']} #{file_attr}"
25
- }
26
- choices << "Cancel"
27
-
28
- choice = nil
29
- say('Please select your log path for setting log deletion.')
30
- newline
31
- choose do |menu|
32
- menu.index = :letter
33
- menu.index_suffix = ") "
34
- menu.prompt = "Select item to change log deletion setting: "
35
- menu.choices(*choices) {|item| choice = item.split(' ')[0]}
36
- end
37
- newline
38
-
39
- data_entry = data_entries.select{|e| e['display_name'] == choice}.first
40
- return nil unless data_entry
41
-
42
- if not data_entry['log_deletion'] and not File.writable?(data_entry['log_path'])
43
- say("Failed to change setting...")
44
- say(" This path is readonly for current user.")
45
- say(" Change user or permission, if you want to set log deletion option.")
46
- return nil
47
- end
48
- data_entry
49
- end
50
- def confirm_setting(data_entry)
51
- cur_flag = data_entry['log_deletion']
52
- loop do
53
- say "Target log path: #{data_entry['log_path']}"
54
- say "Now changing log deletion setting: #{boolToOnOff cur_flag} -> #{boolToOnOff !cur_flag}"
55
- ans = ask "Are you sure? (yes/no): "
56
- if ans.size > 0
57
- case ans[0].downcase
58
- when 'y'; return true
59
- when 'n'; return false
60
- end
61
- end
62
- say " ! Please answer y[es] or n[o]"
63
- newline
64
- end
65
- end
66
- def boolToOnOff(bool)
67
- bool ? 'ON' : 'OFF'
68
- end
69
- def set_log_deletion(data_entry)
70
- param = {
71
- :data_entry => {
72
- 'log_deletion' => !data_entry['log_deletion']
73
- }
74
- }
75
- url = "/data_entries/#{data_entry['id']}"
76
- ret = flydata.put(url, param)
77
- raise 'Failed to update the log deletion setting.' unless ret['success']
78
- puts "Update succeeded!"
79
- end
80
- end
81
- end
82
- end
@@ -1,10 +0,0 @@
1
- module Flydata
2
- module Command
3
- class Start < Base
4
- def run
5
- sender = Flydata::Command::Sender.new
6
- sender.start
7
- end
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- module Flydata
2
- module Command
3
- class Stop < Base
4
- def run
5
- sender = Flydata::Command::Sender.new
6
- sender.stop
7
- end
8
- end
9
- end
10
- end
data/lib/flydata/cron.rb DELETED
@@ -1,88 +0,0 @@
1
- module Flydata
2
- class Cron
3
- FLYDATA_HOME=Flydata::HOME_DIR
4
- CRON_TMP_PATH="#{FLYDATA_HOME}/cron_list.tmp"
5
- CRON_BACKUP_PATH="#{FLYDATA_HOME}/cron_list.back"
6
- LOG_PATH="#{FLYDATA_HOME}/flydata_cron.log"
7
- ROUTINE_BASE_COMMAND="#{FLYDATA_HOME}/bin/flydata routine >> #{LOG_PATH} 2>&1"
8
- if ENV['FLYDATA_API_HOST'] and ENV['FLYDATA_API_HOST'] != ""
9
- ROUTINE_COMMAND="export FLYDATA_API_HOST=#{ENV['FLYDATA_API_HOST']} && #{ROUTINE_BASE_COMMAND}"
10
- else
11
- ROUTINE_COMMAND=ROUTINE_BASE_COMMAND
12
- end
13
-
14
- CRON_LINE="15 4 * * * #{ROUTINE_COMMAND}"
15
- #CRON_LINE="* * * * * #{ROUTINE_COMMAND}"
16
- REMOVE_OPTION="-r"
17
-
18
- def initialize
19
- end
20
- def update(option=nil)
21
- arg = option ? option : ''
22
-
23
- # Check condition
24
- check_crontab_command
25
- dump_cron_setting
26
- reagistered = check_cron_setting
27
-
28
- # Remove mode
29
- if arg == REMOVE_OPTION
30
- unless reagistered
31
- puts "Skip removing. There are no flydata jobs in crontab."
32
- else
33
- remove_cron_setting
34
- puts "Updated crontab to remove the deletion of your log data."
35
- end
36
- # Add mode
37
- else
38
- if reagistered
39
- puts "Skip register. Already cron setup done."
40
- else
41
- add_cron_setting
42
- puts "Updated crontab to manage the deletion of your log data."
43
- end
44
- end
45
- true
46
- end
47
-
48
- private
49
- def check_crontab_command
50
- raise "Failed to update. Crontab is not installed." unless system("which crontab > /dev/null")
51
- end
52
- def dump_cron_setting
53
- system("crontab -l > #{CRON_BACKUP_PATH}")
54
- end
55
- def check_cron_setting
56
- already_exist = false
57
- File.open(CRON_BACKUP_PATH, 'r') { |file|
58
- while l = file.gets
59
- if l =~ /#{ROUTINE_COMMAND}/
60
- already_exist = true
61
- break
62
- end
63
- end
64
- }
65
- already_exist
66
- end
67
- def add_cron_setting
68
- FileUtils.copy(CRON_BACKUP_PATH, CRON_TMP_PATH)
69
- File.open(CRON_TMP_PATH, "a") { |file|
70
- file.puts(CRON_LINE)
71
- }
72
- ret = system("crontab #{CRON_TMP_PATH}")
73
- raise "Failed to register flydata routine job to crontab." unless ret
74
- end
75
- def remove_cron_setting
76
- File.open(CRON_TMP_PATH, "w") { |dst|
77
- File.open(CRON_BACKUP_PATH, 'r') { |src|
78
- while l = src.gets
79
- dst.puts(l) unless l =~ /#{ROUTINE_COMMAND}/
80
- end
81
- }
82
- }
83
- ret = system("crontab #{CRON_TMP_PATH}")
84
- raise "Failed to remove flydata routine job from crontab." unless ret
85
- end
86
-
87
- end
88
- end
@@ -1,116 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Usage:
4
- # flydata_crontab
5
-
6
- ######## Parameters
7
- FLYDATA_HOME=~/".flydata"
8
- CRON_TMP_PATH="$FLYDATA_HOME/cron_list.tmp"
9
- CRON_BACKUP_PATH="$FLYDATA_HOME/cron_list.back"
10
- LOG_PATH="$FLYDATA_HOME/flydata_cron.log"
11
- ROUTINE_COMMAND="$FLYDATA_HOME/bin/flydata routine >> $LOG_PATH 2>&1"
12
- if [[ "$FLYDATA_API_HOST" != "" ]]; then
13
- ROUTINE_COMMAND="export FLYDATA_API_HOST=$FLYDATA_API_HOST && $ROUTINE_COMMAND"
14
- fi
15
- #CRON_LINE='15 4 * * *'" $ROUTINE_COMMAND"
16
- CRON_LINE='* * * * *'" $ROUTINE_COMMAND"
17
-
18
- ARG=$1
19
- REMOVE_OPTION="-r"
20
- CRON_SETTING_DONE=0 # flag
21
-
22
-
23
- ######## Functions
24
- check_flydata_setup_done()
25
- {
26
- which flydata > /dev/null
27
- if [ "$?" -ne "0" ]; then
28
- echo "flydata command not found. Flydata setup has not been done, yet."
29
- exit -1
30
- fi
31
- if [ ! -w $FLYDATA_HOME ]; then
32
- echo "Flydata setup has not been done, yet. Run setup command."
33
- echo " -> flydata setup"
34
- exit -1
35
- fi
36
- }
37
-
38
- check_crontab_commnad()
39
- {
40
- which crontab > /dev/null
41
- if [ "$?" -ne "0" ]; then
42
- echo "No crontab command. Please install cron."
43
- exit -2
44
- fi
45
- }
46
-
47
- check_crond_process()
48
- {
49
- crond_exist=`ps aux | grep crond | grep -v grep | wc -l`
50
- echo $crond_exist
51
- if [ "$crond_exist" -ne "1" ]; then
52
- echo "No crond process. Please start crond process."
53
- exit -3
54
- fi
55
- }
56
-
57
- dump_cron_setting()
58
- {
59
- crontab -l > $CRON_BACKUP_PATH
60
- }
61
-
62
- check_cron_setting()
63
- {
64
- CRON_SETTING_DONE=`cat $CRON_BACKUP_PATH | grep "flydata routine" | wc -l`
65
- if [ "$?" -ne "0" ]; then
66
- echo "Failed to check cron setting file."
67
- exit -5
68
- fi
69
- }
70
-
71
- add_cron_setting()
72
- {
73
- cat $CRON_BACKUP_PATH > $CRON_TMP_PATH
74
- echo "$CRON_LINE" >> $CRON_TMP_PATH
75
- crontab $CRON_TMP_PATH
76
- if [ "$?" -ne "0" ]; then
77
- echo "Failed to register flydata routine job to crontab."
78
- exit -6
79
- fi
80
- }
81
-
82
- remove_cron_setting()
83
- {
84
- cat "$CRON_BACKUP_PATH" | grep -v "flydata routine" > $CRON_TMP_PATH
85
- crontab $CRON_TMP_PATH
86
- if [ "$?" -ne "0" ]; then
87
- echo "Failed to remove flydata routine job from crontab."
88
- exit -7
89
- fi
90
- }
91
-
92
-
93
- ######## Main
94
- ARG="$1"
95
- check_flydata_setup_done
96
- check_crontab_commnad
97
- # check_crond_process
98
- dump_cron_setting
99
- check_cron_setting
100
-
101
- # Skip If add mode and registered
102
- if [[ "$ARG" != "$REMOVE_OPTION" && $CRON_SETTING_DONE -gt 0 ]]; then
103
- echo "Skip. Already cron setup done."
104
- exit 0
105
- fi
106
-
107
- # Remove mode -> remove setting
108
- if [ "$ARG" == "$REMOVE_OPTION" ]; then
109
- remove_cron_setting
110
- exit 0
111
- fi
112
-
113
- # Add mode -> add setting
114
- add_cron_setting
115
- echo "Updated crontab to manage the deletion of your log data."
116
- exit 0