right_chimp 2.1.10 → 2.1.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c13ca370025ded4b38f888ea6be7d9b6120c0f3
4
- data.tar.gz: 5cf9d33faf1b2ac7770c45f594e170c8f95dad8b
3
+ metadata.gz: cc15b41e6fcc5ea1696d6255206015000f9a31ee
4
+ data.tar.gz: 462e82c8dc41dfb152fa2218be76f8dbe04b1c1c
5
5
  SHA512:
6
- metadata.gz: 818b7ba69f19e685093bc6ce134e334f504d24177adb822d70e6bbc287506e93cc4969c1ea85da8800c62e9e4e376cc6f5b1f79edb41f7828abace034120181f
7
- data.tar.gz: 4ff2cf25b23b3c8ef9196d89ffd6c1b8daef67d0e708e798e72da94bf3b79993d4b55037b8396ce16cb018d7971a2187a0064487e34f2b8f07181bf74b94f1be
6
+ metadata.gz: f0a8baa2ba2a7b35585d4d6c73a339d03d59cd21b7d02cb576f2f25f0f1fd502ee9d059f619b19d88628611563566de1fad78eddcdf02d274c19aab14df76d82
7
+ data.tar.gz: 7cc171141adc3b7c1204489c234e22e3e13ad6461591a47f68910ff31c5e87cbaa32c7d12b28d5e7cc7fbd669ed953a7fde5aedfd5d892ff73154d6a7520b70c
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  pkg/*
2
+ .bundle/*
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- right_chimp (2.1.10)
4
+ right_chimp (2.1.12)
5
5
  highline (~> 1.7.2)
6
6
  nokogiri (~> 1.6.7.1)
7
7
  progressbar (~> 0.11.0)
@@ -11,19 +11,31 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
+ binding_of_caller (0.7.2)
15
+ debug_inspector (>= 0.0.1)
16
+ coderay (1.1.0)
17
+ debug_inspector (0.0.2)
14
18
  diff-lcs (1.1.3)
15
- domain_name (0.5.25)
19
+ domain_name (0.5.20160128)
16
20
  unf (>= 0.0.5, < 1.0.0)
17
21
  highline (1.7.8)
18
22
  http-cookie (1.0.2)
19
23
  domain_name (~> 0.5)
20
24
  json (1.8.3)
25
+ method_source (0.8.2)
21
26
  mime-types (1.25.1)
22
27
  mini_portile2 (2.0.0)
23
28
  netrc (0.11.0)
24
- nokogiri (1.6.7.1)
29
+ nokogiri (1.6.7.2)
25
30
  mini_portile2 (~> 2.0.0.rc2)
26
31
  progressbar (0.11.0)
32
+ pry (0.10.3)
33
+ coderay (~> 1.1.0)
34
+ method_source (~> 0.8.1)
35
+ slop (~> 3.4)
36
+ pry-stack_explorer (0.4.9.2)
37
+ binding_of_caller (>= 0.7)
38
+ pry (>= 0.9.11)
27
39
  rake (10.4.2)
28
40
  rest-client (1.8.0)
29
41
  http-cookie (>= 1.0.2, < 2.0)
@@ -41,14 +53,17 @@ GEM
41
53
  rspec-expectations (2.6.0)
42
54
  diff-lcs (~> 1.1.2)
43
55
  rspec-mocks (2.6.0)
56
+ slop (3.6.0)
44
57
  unf (0.1.4)
45
58
  unf_ext
46
- unf_ext (0.0.7.1)
59
+ unf_ext (0.0.7.2)
47
60
 
48
61
  PLATFORMS
49
62
  ruby
50
63
 
51
64
  DEPENDENCIES
65
+ pry
66
+ pry-stack_explorer
52
67
  right_chimp!
53
68
  rspec (~> 2.6.0)
54
69
 
data/chimp.gemspec CHANGED
@@ -27,4 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.add_dependency "highline", "~> 1.7.2"
28
28
 
29
29
  s.add_development_dependency "rspec", "~> 2.6.0"
30
+ s.add_development_dependency "pry"
31
+ s.add_development_dependency "pry-stack_explorer"
32
+
30
33
  end
@@ -223,7 +223,7 @@ module Chimp
223
223
  }
224
224
  }
225
225
 
226
- Log.debug "[#{Chimp.get_job_uuid}] Found #{@servers.count} servers for that array query"
226
+ Log.debug "[#{Chimp.get_job_uuid}] Found #{@servers.count} servers for that array query"
227
227
 
228
228
  end
229
229
  # The result will be stored (not returned) into @servers
@@ -332,7 +332,8 @@ module Chimp
332
332
  [ '--group-concurrency', '-3', GetoptLong::REQUIRED_ARGUMENT ],
333
333
  [ '--timing-log', '-4', GetoptLong::REQUIRED_ARGUMENT ],
334
334
  [ '--timeout', '-5', GetoptLong::REQUIRED_ARGUMENT ],
335
- [ '--noverify', '-6', GetoptLong::NO_ARGUMENT ]
335
+ [ '--noverify', '-6', GetoptLong::NO_ARGUMENT ],
336
+ [ '--exact-matching', '-8', GetoptLong::NO_ARGUMENT ]
336
337
  )
337
338
 
338
339
  opts.each do |opt, arg|
@@ -433,6 +434,8 @@ module Chimp
433
434
  @timeout = arg
434
435
  when '--noverify'
435
436
  @verify = false
437
+ when '--exact-matching'
438
+ @exact = true
436
439
  end
437
440
  end
438
441
 
@@ -556,7 +559,11 @@ module Chimp
556
559
  servers = []
557
560
  all_instances = Connection.all_instances
558
561
 
559
- result = all_instances.select {|i| names.any? {|n| i['links']['deployment']['name'] =~ /#{n}/ }}
562
+ if @exact
563
+ result = all_instances.select {|i| names.any? {|n| i['links']['deployment']['name'].eql? n }}
564
+ else
565
+ result = all_instances.select {|i| names.any? {|n| i['links']['deployment']['name'] =~ /#{n}/ }}
566
+ end
560
567
  servers = result
561
568
 
562
569
  return(servers)
@@ -577,7 +584,16 @@ module Chimp
577
584
  result = Connection.client.server_arrays.index(:filter => ["name==#{array_name}"])
578
585
  # Result is an array with all the server arrays
579
586
  if result.size != 0
580
- arrays_hrefs += result.collect(&:href)
587
+ if @exact
588
+ #remove results that do not exactly match
589
+ result.each{ |r|
590
+ if array_names.include?(r.raw['name'])
591
+ arrays_hrefs += [ r.href ]
592
+ end
593
+ }
594
+ else
595
+ arrays_hrefs += result.collect(&:href)
596
+ end
581
597
  else
582
598
  if @ignore_errors
583
599
  Log.debug "[#{Chimp.get_job_uuid}] Could not find array \"#{array_name}\""
@@ -199,6 +199,7 @@ module Chimp
199
199
  def install_signal_handlers
200
200
  ['INT', 'TERM'].each do |signal|
201
201
  trap(signal) do
202
+ puts "Terminating..."
202
203
  self.quit
203
204
  end
204
205
  end
@@ -587,6 +588,34 @@ module Chimp
587
588
  raise WEBrick::HTTPStatus::OK
588
589
  end
589
590
 
591
+ #
592
+ # Attempt to return just 1 job data
593
+ #
594
+ if req.request_uri.path =~ /jobs\.json\/id\/*\w{6}$/
595
+
596
+ job_uid = File.basename(req.request_uri.path)
597
+ #instance the queue
598
+ queue = ChimpQueue.instance
599
+
600
+ my_hash = {}
601
+
602
+ #! Multiple servers WILL match for the same job_uuid
603
+ queue.group.each { |group|
604
+ #per each group, locate all jobs
605
+ group[1].get_jobs.each {|job|
606
+ my_hash[job.job_uuid] = { job.job_id => { "state" => job.results,
607
+ "server" => job.server.params["name"],
608
+ "audit_entry" => job.audit_entry_data,
609
+ }
610
+ }
611
+ }
612
+ }
613
+
614
+ resp.body = my_hash[job_uid].to_json
615
+
616
+ raise WEBrick::HTTPStatus::OK
617
+ end
618
+
590
619
 
591
620
  #
592
621
  # Check for static CSS files and serve them
@@ -3,34 +3,37 @@
3
3
  #
4
4
  module Chimp
5
5
  class ExecRightScript < Executor
6
-
6
+
7
+ attr_accessor :audit_entry_data
8
+
7
9
  def run
8
10
  options = {:ignore_lock => true}.merge(@inputs)
9
-
11
+
10
12
  if @timeout < 300
11
13
  Log.error "timeout was less than 5 minutes! resetting to 5 minutes"
12
14
  @timeout = 300
13
15
  end
14
-
16
+
15
17
  run_with_retry do
16
18
  task=Task.new
17
19
  task.tasker = @server.run_executable(@exec, options)
18
20
  task.wait_for_state("completed", @timeout)
19
- @results = task.tasker.show.summary
21
+ @results = task.state
22
+ @audit_entry_data = task.details
20
23
  end
21
24
  end
22
-
25
+
23
26
  def describe_work
24
27
  return "[#{@job_uuid}] ExecRightScript job_id=#{@job_id} script=\"#{@exec.params['right_script']['name']}\" server=\"#{@server.nickname}\""
25
28
  end
26
-
29
+
27
30
  def info
28
31
  return @exec.params['right_script']['name']
29
32
  end
30
-
33
+
31
34
  def target
32
35
  return @server.nickname
33
36
  end
34
-
37
+
35
38
  end
36
39
  end
@@ -7,9 +7,9 @@ module Chimp
7
7
  attr_accessor :server, :array, :exec, :inputs, :template, :owner, :group,
8
8
  :job_id, :job_uuid, :status, :dry_run, :verbose, :quiet, :timeout,
9
9
  :retry_count, :retry_sleep, :time_start, :time_end, :error
10
-
10
+
11
11
  attr_reader :results
12
-
12
+
13
13
  STATUS_NONE = :none
14
14
  STATUS_HOLDING = :holding
15
15
  STATUS_RUNNING = :running
@@ -29,20 +29,19 @@ module Chimp
29
29
  @inputs = h[:inputs] || nil
30
30
 
31
31
  @verbose = h[:verbose] || false
32
-
32
+
33
33
  @retry_count = h[:retry_count].to_i || 0
34
34
  @retry_sleep = h[:retry_sleep].to_i || 30
35
35
  @timeout = h[:timeout].to_i || 3600
36
-
36
+
37
37
  @error = nil
38
38
  @status = STATUS_NONE
39
39
  @owner = nil
40
40
  @dry_run = false
41
41
  @quiet = false
42
-
42
+
43
43
  @time_start = nil
44
44
  @time_end = nil
45
- @results = nil
46
45
  end
47
46
 
48
47
  #
@@ -57,21 +56,21 @@ module Chimp
57
56
  return @time_end.to_i- @time_start.to_i
58
57
  end
59
58
  end
60
-
59
+
61
60
  #
62
61
  # Convenience method to queue a held job
63
62
  #
64
63
  def queue
65
64
  @group.queue(self.job_id)
66
65
  end
67
-
66
+
68
67
  #
69
68
  # Convenience method to requeue
70
69
  #
71
70
  def requeue
72
71
  @group.requeue(self.job_id)
73
72
  end
74
-
73
+
75
74
  #
76
75
  # Convenience method to cancel
77
76
  #
@@ -82,21 +81,21 @@ module Chimp
82
81
  def run
83
82
  raise "run method must be overridden"
84
83
  end
85
-
84
+
86
85
  #
87
86
  # return info on what this executor does -- eg name of script or command
88
87
  #
89
88
  def info
90
89
  raise "unimplemented"
91
90
  end
92
-
91
+
93
92
  def target
94
93
  return "UNKNOWN"
95
94
  end
96
95
 
97
-
96
+
98
97
  protected
99
-
98
+
100
99
  #
101
100
  # Run a unit of work with retries
102
101
  # This is called from the subclass with a code block to yield to
@@ -108,36 +107,36 @@ module Chimp
108
107
  @time_start = Time.now
109
108
 
110
109
  Log.info self.describe_work_start unless @quiet
111
-
110
+
112
111
  #
113
112
  # The inner level of exception handling here tries to catch anything
114
113
  # that can be easily retired or failed-- normal exceptions.
115
114
  #
116
115
  # The outer level of exception handling handles weird stuff; for example,
117
- # sometimes rest_connection raises RuntimeError exceptions...
116
+ # sometimes rest_connection raises RuntimeError exceptions...
118
117
  #
119
118
  # This fixes acu75562.
120
119
  #
121
120
  begin
122
121
  begin
123
122
  yield if not @dry_run
124
-
123
+
125
124
  if @owner != nil
126
125
  @status = STATUS_DONE
127
126
  @group.job_completed
128
127
  else
129
128
  Log.warn "[#{@job_uuid}] Ownership of job_id #{job_id} lost. User cancelled operation?"
130
129
  end
131
-
130
+
132
131
  rescue SystemExit, Interrupt => ex
133
132
  $stderr.puts "Exiting!"
134
133
  raise ex
135
-
134
+
136
135
  rescue Interrupt => ex
137
136
  name = @array['name'] if @array
138
137
  name = @server['name'] || @server['nickname'] if @server
139
138
  Log.error self.describe_work_error
140
-
139
+
141
140
  if @retry_count > 0
142
141
  @status = STATUS_RETRYING
143
142
  Log.error "[#{@job_uuid}] Error executing on \"#{name}\". Retrying in #{@retry_sleep} seconds..."
@@ -145,16 +144,16 @@ module Chimp
145
144
  sleep @retry_sleep
146
145
  retry
147
146
  end
148
-
147
+
149
148
  @status = STATUS_ERROR
150
149
  @error = ex
151
150
  Log.error "[#{@job_uuid}] Error executing on \"#{name}\": #{ex}"
152
-
153
- ensure
151
+
152
+ ensure
154
153
  @time_end = Time.now
155
154
  Log.info self.describe_work_done unless @quiet
156
155
  end
157
-
156
+
158
157
  rescue RuntimeError => ex
159
158
  Log.error "[#{@job_uuid}] Caught RuntimeError: #{ex}. Aborting job."
160
159
  Log.error ex.inspect
@@ -163,7 +162,7 @@ module Chimp
163
162
  @error = ex
164
163
  end
165
164
  end
166
-
165
+
167
166
  #
168
167
  # This method should be overridden on Executor subclasses
169
168
  # to provide a human readable description of the work
@@ -172,7 +171,7 @@ module Chimp
172
171
  def describe_work
173
172
  return "#{self.class.name} job_id=#{@job_id}"
174
173
  end
175
-
174
+
176
175
  def describe_work_start
177
176
  return("#{self.describe_work} status=START")
178
177
  end
@@ -180,13 +179,13 @@ module Chimp
180
179
  def describe_work_done
181
180
  return("#{self.describe_work} status=END time=#{@time_end.to_i-@time_start.to_i}s")
182
181
  end
183
-
182
+
184
183
  def describe_work_done_long
185
184
  return("#{self.describe_work} status=END time_start=#{@time_start.to_i} time_end=#{@time_end.to_i} time_total=#{@time_end.to_i-@time_start.to_i}")
186
185
  end
187
-
186
+
188
187
  def describe_work_error
189
188
  return("#{self.describe_work} status=ERROR")
190
- end
189
+ end
191
190
  end
192
191
  end
@@ -45,6 +45,8 @@ module Chimp
45
45
  # Figure out url to hit:
46
46
  creds[:api_url] = "https://"+URI.parse(creds[:api_url]).host
47
47
 
48
+ @audit_url = creds[:api_url] + "/acct/" + creds[:account]
49
+
48
50
  @endpoint = URI.parse(creds[:api_url]).host
49
51
 
50
52
  Log.debug "Logging into Api 1.5 right_api_client"
@@ -71,6 +73,10 @@ module Chimp
71
73
  @endpoint
72
74
  end
73
75
 
76
+ def self.audit_url
77
+ @audit_url
78
+ end
79
+
74
80
  #
75
81
  # Returns every single operational instance in the account
76
82
  #
@@ -283,10 +289,9 @@ module Chimp
283
289
  while(timeout > 0)
284
290
  state=self.tasker.show.summary
285
291
  return true if self.state.match(desired_state)
286
- friendly_url = "https://"+Connection.endpoint+"/audit_entries/"
292
+ friendly_url = Connection.audit_url+"/audit_entries/"
287
293
  friendly_url += self.href.split(/\//).last
288
294
  friendly_url = friendly_url.gsub("ae-","")
289
- # raise "FATAL error, #{self.tasker.show.summary}\n See Audit: API:#{self.href}, WWW:<a href='#{friendly_url}'>#{friendly_url}</a>\n " if self.state.match("failed")
290
295
  raise "FATAL error, #{self.tasker.show.summary}\n See Audit: #{friendly_url}'\n " if self.state.match("failed")
291
296
  sleep 30
292
297
  timeout -= 30
@@ -305,6 +310,10 @@ module Chimp
305
310
  def href
306
311
  self.tasker.href
307
312
  end
313
+
314
+ def details
315
+ self.tasker.show(:view => "extended").detail
316
+ end
308
317
  end
309
318
 
310
319
  #
@@ -1,7 +1,6 @@
1
1
  <html><head>
2
2
  <title>chimpd</title>
3
3
  <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
4
- <meta http-equiv="refresh" content="5">
5
4
  <link rel="stylesheet" href="default.css" title="default" />
6
5
  <link rel="alternate stylesheet" href="greenscreen.css" title="greenscreen" />
7
6
  <link rel="alternate stylesheet" href="hotdogstand.css" title="hotdogstand" />
@@ -19,16 +18,30 @@
19
18
  xmlhttp.send();
20
19
  }
21
20
 
21
+ var myRefreshTimeout;
22
+
23
+ /** Function to refresh the page at specified interval. **/
24
+ function startRefresh(refreshPeriod) {
25
+ myRefreshTimeout = setTimeout("window.location.reload();",refreshPeriod);
26
+ }
27
+
28
+ /** Function to stop refreshing the page. **/
29
+ function stopRefresh() {
30
+ clearTimeout(myRefreshTimeout);
31
+ window.location.hash = 'stop'
32
+ }
33
+
22
34
  </script>
23
35
 
24
- </head><body>
36
+ </head>
37
+ <body onload="startRefresh(5000);">
38
+
25
39
 
26
40
  <div id="stats">
27
41
 
28
42
  <h1>chimpd <%=VERSION%> console</h1>
29
43
  <p style="font-size: 90%; padding-left: 10px">FEATURING CUTTING EDGE META REFRESH<br/> TECHNOLOGY
30
44
  SINCE 2012</p>
31
-
32
45
  <h3>Queue Status</h3>
33
46
 
34
47
  <table>
@@ -93,6 +106,15 @@ SINCE 2012</p>
93
106
  <li> <a href="#" onclick="setActiveStyleSheet('invertedhotdogstand')">inverted hot dog stand</a></li>
94
107
  </ol>
95
108
 
109
+ <h3>Auto Refresh</h3>
110
+ <ol>
111
+ <div class="btn-group">
112
+ <a class="btn btn-success" onclick="startRefresh()" id="start">Enable</a>
113
+ <a class="btn btn-danger" onclick="stopRefresh()" id="stop">Disable</a>
114
+ <p id="console"></p>
115
+ </div>
116
+ </ol>
117
+
96
118
  </div>
97
119
 
98
120
  <div id="jobs">
@@ -152,6 +174,9 @@ jobs.each do |j|
152
174
  <li>Time: <%= time %></li>
153
175
  <% if status != Executor::STATUS_RUNNING %>
154
176
  <li>Results: <span style="color:#777"><%= j.results %></span></li>
177
+ <!-- HACK HERE THE LOOP CODE TO INJECT CSS TO HIDE/EXPAND-->
178
+ <li><label for="<%= id%>">Details (click to expand):</label> <input type="checkbox" id="<%= id%>"><span style="color:#777"><div id="d<%= id%>" class="job_details"><%= j.audit_entry_data %></div></span></li>
179
+ <!-- HACK HERE THE LOOP CODE TO INJECT CSS TO HIDE/EXPAND-->
155
180
  <% end %>
156
181
 
157
182
  <li> <span class="action">
@@ -79,3 +79,28 @@ a {
79
79
  a:hover, ol a:hover {
80
80
  text-decoration: underline;
81
81
  }
82
+
83
+
84
+ /* Checkbox Hack */
85
+ li {
86
+ list-style-type: none;
87
+ }
88
+ input[type=checkbox] {
89
+ position: absolute;
90
+ top: -9999px;
91
+ left: -9999px;
92
+ }
93
+ label {
94
+ display: inline-block;
95
+ cursor: pointer;
96
+ }
97
+
98
+ /* Default State */
99
+ span div.job_details {
100
+ display: none;
101
+ }
102
+
103
+ /* Toggled State */
104
+ input[type=checkbox]:checked ~ span div.job_details {
105
+ display: block;
106
+ }
@@ -1,3 +1,3 @@
1
1
  module Chimp
2
- VERSION = "2.1.10"
2
+ VERSION = "2.1.12"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_chimp
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.10
4
+ version: 2.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - RightScale Operations
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-12 00:00:00.000000000 Z
11
+ date: 2016-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -94,6 +94,34 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 2.6.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-stack_explorer
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
97
125
  description: The Chimp is a tool for managing servers using the RightScale platform.
98
126
  email:
99
127
  - ops@rightscale.com
@@ -166,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
194
  version: '0'
167
195
  requirements: []
168
196
  rubyforge_project:
169
- rubygems_version: 2.4.5.1
197
+ rubygems_version: 2.5.1
170
198
  signing_key:
171
199
  specification_version: 4
172
200
  summary: RightScale platform command-line tool