wobble 1.0.6 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  A command-line interface for Hadoop’s JobTracker.
6
6
 
7
- ![](http://i.imgur.com/jcks5.jpg)
7
+ ![](http://i.imgur.com/kFAD3.jpg)
8
8
 
9
9
  ## Installation
10
10
 
data/bin/wobble CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'gli'
4
+ require 'rainbow'
4
5
  require 'terminal-table'
5
6
 
6
7
  require 'wobble'
@@ -19,31 +20,59 @@ desc "retrieve job statuses from Hadoop's JobTracker"
19
20
  arg_name 'jobs'
20
21
 
21
22
  command :jobs do |c|
22
- c.desc 'specify status type (i.e. running, completed, failed, or retired)'
23
+ c.desc 'specify status type (i.e. running, completed, or failed)'
23
24
  c.flag :status
24
25
  c.action do |global_options, options, args|
25
- types = %w(running completed failed retired)
26
+ types = %w(running completed failed)
26
27
 
27
28
  if options['status']
28
29
  if types.include? options['status']
29
- format_table options['status']
30
+ @tracker.status = options['status']
31
+
32
+ format_table @tracker.jobs
30
33
  end
31
34
  else
32
- types.each do |status|
33
- format_table status
34
- end
35
+ format_table @tracker.jobs
35
36
  end
36
37
  end
37
38
 
38
- def format_table(status)
39
- @tracker.status = status
39
+ def headings
40
+ %w(ID Created Priority User Name Mapped Reduced).map { |h| h.bright }
41
+ end
40
42
 
41
- table = Terminal::Table.new do |t|
42
- t.title = "#{status.capitalize} Jobs"
43
- t.headings = %w(ID Priority User Name)
44
- t.rows = @tracker.jobs
43
+ def color_rows(jobs)
44
+ if @tracker.status
45
+ case @tracker.status
46
+ when 'running'
47
+ jobs.map do |job|
48
+ job.map do |value|
49
+ value.color :yellow
50
+ end
51
+ end
52
+ when 'completed'
53
+ jobs.map do |job|
54
+ job.map do |value|
55
+ value.color :green
56
+ end
57
+ end
58
+ when 'failed'
59
+ jobs.map do |job|
60
+ job.map do |value|
61
+ value.color :red
62
+ end
63
+ end
64
+ end
45
65
  end
66
+ end
46
67
 
68
+ def format_table(jobs)
69
+ table = Terminal::Table.new do |t|
70
+ t.headings = headings
71
+ t.rows = color_rows(jobs)
72
+ end
73
+
74
+ table.align_column 0, :right
75
+
47
76
  puts table
48
77
  end
49
78
  end
@@ -1,56 +1,93 @@
1
1
  require 'net/http'
2
2
  require 'nokogiri'
3
+ require 'rainbow'
3
4
 
4
5
  module Wobble
5
6
  class Tracker
6
7
  attr_accessor :host
7
8
  attr_accessor :status
9
+ attr_accessor :xpath_prefix
8
10
 
9
11
  def initialize(host)
10
12
  @host = Nokogiri::HTML(Net::HTTP.get(URI(host)))
13
+ @xpath_prefix = "//html/body/table[@class='datatable']"
11
14
  end
12
15
 
13
16
  def jobs
14
- ids.zip(priorities, users, names)
17
+ ids.zip(timestamps, priorities, users, names, mapped, reduced)
15
18
  end
16
19
 
17
- def find_jobs
18
- xpath_stub = "//html/body/table[@class='datatable']"
19
-
20
+ def find_jobs
20
21
  case status
21
22
  when 'running'
22
- host.xpath("#{xpath_stub}[1]/tbody").first.search('tr')
23
+ running_jobs
23
24
  when 'completed'
24
- host.xpath("#{xpath_stub}[2]/tbody").first.search('tr')
25
+ completed_jobs
25
26
  when 'failed'
26
- host.xpath("#{xpath_stub}[3]/tbody").first.search('tr')
27
- when 'retired'
28
- host.xpath("/html/body/table[@class='sortable'][2]/tbody").first.search('tr')
27
+ failed_jobs
29
28
  else
30
- host.xpath("#{xpath_stub}/tbody").first.search('tr')
29
+ find_by_table_index
31
30
  end
32
31
  end
33
32
 
34
- def find_by_id_prefix(id_prefix)
35
- find_jobs.xpath("td[starts-with(@id, '#{id_prefix}_')]").map do |job|
36
- job.content
33
+ def find_by_table_index(table_index=nil)
34
+ if table_index
35
+ table = host.xpath("#{xpath_prefix}[#{table_index}]/tbody")
36
+ else
37
+ table = host.xpath("#{xpath_prefix}/tbody")
37
38
  end
39
+
40
+ table.first.search('tr')
41
+ end
42
+
43
+ def running_jobs
44
+ find_by_table_index 1
45
+ end
46
+
47
+ def completed_jobs
48
+ find_by_table_index 2
49
+ end
50
+
51
+ def failed_jobs
52
+ find_by_table_index 3
53
+ end
54
+
55
+ def find_by_column_index(index)
56
+ find_jobs.xpath("td[#{index}]").map { |c| c.content }.reject(&:empty?)
57
+ end
58
+
59
+ def timestamps
60
+ find_by_column_index(1).map { |timestamp| edit_timestamp timestamp }
38
61
  end
39
62
 
40
63
  def ids
41
- find_by_id_prefix('job').map { |id| edit_id id }
64
+ find_by_column_index(1).map { |name| edit_id name }
42
65
  end
43
66
 
44
67
  def priorities
45
- find_by_id_prefix 'priority'
68
+ find_by_column_index 2
46
69
  end
47
70
 
48
71
  def users
49
- find_by_id_prefix 'user'
72
+ find_by_column_index 3
50
73
  end
51
74
 
52
75
  def names
53
- find_by_id_prefix('name').map { |name| edit_name name }
76
+ find_by_column_index(4).map { |name| edit_name name }
77
+ end
78
+
79
+ def mapped
80
+ find_by_column_index 5
81
+ end
82
+
83
+ def reduced
84
+ find_by_column_index 8
85
+ end
86
+
87
+ def edit_timestamp(id)
88
+ DateTime.parse(id.gsub(/job_/, '').gsub(/_\d+/, ''))
89
+ .to_time
90
+ .to_s
54
91
  end
55
92
 
56
93
  def edit_id(id)
@@ -1,3 +1,3 @@
1
1
  module Wobble
2
- VERSION = '1.0.6'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,194 +1,207 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: wobble
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 6
10
- version: 1.0.6
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Allen Goodman
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-11-16 00:00:00 -08:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- requirement: &id001 !ruby/object:Gem::Requirement
23
- none: false
24
- requirements:
25
- - - ~>
26
- - !ruby/object:Gem::Version
27
- hash: 3
28
- segments:
29
- - 0
30
- version: "0"
31
- version_requirements: *id001
12
+ date: 2012-11-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
32
15
  name: aruba
33
- prerelease: false
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
34
22
  type: :development
35
- - !ruby/object:Gem::Dependency
36
- requirement: &id002 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
37
25
  none: false
38
- requirements:
26
+ requirements:
39
27
  - - ~>
40
- - !ruby/object:Gem::Version
41
- hash: 23
42
- segments:
43
- - 10
44
- version: "10"
45
- version_requirements: *id002
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
46
31
  name: rake
47
- prerelease: false
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '10'
48
38
  type: :development
49
- - !ruby/object:Gem::Dependency
50
- requirement: &id003 !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
51
41
  none: false
52
- requirements:
42
+ requirements:
53
43
  - - ~>
54
- - !ruby/object:Gem::Version
55
- hash: 7
56
- segments:
57
- - 2
58
- version: "2"
59
- version_requirements: *id003
44
+ - !ruby/object:Gem::Version
45
+ version: '10'
46
+ - !ruby/object:Gem::Dependency
60
47
  name: rspec
61
- prerelease: false
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2'
62
54
  type: :development
63
- - !ruby/object:Gem::Dependency
64
- requirement: &id004 !ruby/object:Gem::Requirement
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
65
57
  none: false
66
- requirements:
58
+ requirements:
67
59
  - - ~>
68
- - !ruby/object:Gem::Version
69
- hash: 51
70
- segments:
71
- - 1
72
- - 9
73
- - 0
74
- version: 1.9.0
75
- version_requirements: *id004
60
+ - !ruby/object:Gem::Version
61
+ version: '2'
62
+ - !ruby/object:Gem::Dependency
76
63
  name: webmock
77
- prerelease: false
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.9.0
78
70
  type: :development
79
- - !ruby/object:Gem::Dependency
80
- requirement: &id005 !ruby/object:Gem::Requirement
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
81
73
  none: false
82
- requirements:
74
+ requirements:
83
75
  - - ~>
84
- - !ruby/object:Gem::Version
85
- hash: 3
86
- segments:
87
- - 0
88
- version: "0"
89
- version_requirements: *id005
76
+ - !ruby/object:Gem::Version
77
+ version: 1.9.0
78
+ - !ruby/object:Gem::Dependency
90
79
  name: yard
91
- prerelease: false
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
92
86
  type: :development
93
- - !ruby/object:Gem::Dependency
94
- requirement: &id006 !ruby/object:Gem::Requirement
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
95
89
  none: false
96
- requirements:
90
+ requirements:
97
91
  - - ~>
98
- - !ruby/object:Gem::Version
99
- hash: 9
100
- segments:
101
- - 1
102
- - 5
103
- - 5
104
- version: 1.5.5
105
- version_requirements: *id006
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
106
95
  name: nokogiri
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 1.5.5
102
+ type: :runtime
107
103
  prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.5.5
110
+ - !ruby/object:Gem::Dependency
111
+ name: rainbow
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
108
118
  type: :runtime
109
- - !ruby/object:Gem::Dependency
110
- requirement: &id007 !ruby/object:Gem::Requirement
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: terminal-table
128
+ requirement: !ruby/object:Gem::Requirement
111
129
  none: false
112
- requirements:
130
+ requirements:
113
131
  - - ~>
114
- - !ruby/object:Gem::Version
115
- hash: 13
116
- segments:
117
- - 1
118
- - 4
119
- - 5
132
+ - !ruby/object:Gem::Version
120
133
  version: 1.4.5
121
- version_requirements: *id007
122
- name: terminal-table
123
- prerelease: false
124
134
  type: :runtime
125
- - !ruby/object:Gem::Dependency
126
- requirement: &id008 !ruby/object:Gem::Requirement
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
127
137
  none: false
128
- requirements:
138
+ requirements:
129
139
  - - ~>
130
- - !ruby/object:Gem::Version
131
- hash: 29
132
- segments:
133
- - 2
134
- - 4
135
- - 1
136
- version: 2.4.1
137
- version_requirements: *id008
140
+ - !ruby/object:Gem::Version
141
+ version: 1.4.5
142
+ - !ruby/object:Gem::Dependency
138
143
  name: gli
139
- prerelease: false
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: 2.4.1
140
150
  type: :runtime
141
- description: "A command-line interface for Hadoop\xE2\x80\x99s JobTracker."
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: 2.4.1
158
+ description: A command-line interface for Hadoop’s JobTracker.
142
159
  email: allen.goodman@me.com
143
- executables:
160
+ executables:
144
161
  - wobble
145
162
  extensions: []
146
-
147
- extra_rdoc_files:
163
+ extra_rdoc_files:
148
164
  - README.md
149
- files:
165
+ files:
150
166
  - bin/wobble
151
167
  - lib/wobble/version.rb
152
168
  - lib/wobble.rb
153
169
  - lib/wobble/tracker.rb
154
170
  - README.md
155
- has_rdoc: true
156
171
  homepage: https://github.com/2a6U37Nn/wobble
157
172
  licenses: []
158
-
159
173
  post_install_message:
160
- rdoc_options:
174
+ rdoc_options:
161
175
  - --title
162
176
  - wobble
163
177
  - --main
164
178
  - README.md
165
179
  - -ri
166
- require_paths:
180
+ require_paths:
167
181
  - lib
168
- required_ruby_version: !ruby/object:Gem::Requirement
182
+ required_ruby_version: !ruby/object:Gem::Requirement
169
183
  none: false
170
- requirements:
171
- - - ">="
172
- - !ruby/object:Gem::Version
173
- hash: 3
174
- segments:
184
+ requirements:
185
+ - - ! '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ segments:
175
189
  - 0
176
- version: "0"
177
- required_rubygems_version: !ruby/object:Gem::Requirement
190
+ hash: -453464498335322200
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
192
  none: false
179
- requirements:
180
- - - ">="
181
- - !ruby/object:Gem::Version
182
- hash: 3
183
- segments:
193
+ requirements:
194
+ - - ! '>='
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ segments:
184
198
  - 0
185
- version: "0"
199
+ hash: -453464498335322200
186
200
  requirements: []
187
-
188
201
  rubyforge_project:
189
- rubygems_version: 1.6.2
202
+ rubygems_version: 1.8.23
190
203
  signing_key:
191
204
  specification_version: 3
192
- summary: "A command-line interface for Hadoop\xE2\x80\x99s JobTracker."
205
+ summary: A command-line interface for Hadoop’s JobTracker.
193
206
  test_files: []
194
-
207
+ has_rdoc: true