right_chimp 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.
@@ -0,0 +1,214 @@
1
+ <html><head>
2
+ <title>chimpd</title>
3
+ <meta http-equiv="refresh" content="5">
4
+ <style type="text/css">
5
+ body {
6
+ color: #088A29;
7
+ background-color: black;
8
+ font-family: monospace;
9
+ font-size: 10px;
10
+ margin: 0;
11
+ }
12
+
13
+ h3 {
14
+ font-weight: bold;
15
+ border-bottom: 2px solid #088A29;
16
+ }
17
+
18
+ ol, ul {
19
+ list-style-type: none;
20
+ }
21
+
22
+ ol {
23
+ padding-left: 10px;
24
+ }
25
+
26
+ ul {
27
+ padding-bottom: 5px;
28
+ border-bottom: solid #088A29 2px;
29
+ }
30
+
31
+ div#stats {
32
+ background-color: black; /* #002A5C */
33
+ color: #088A29;
34
+ float: left;
35
+ border-right: solid 2px #088A29;
36
+ position: fixed;
37
+ height: 100%;
38
+ padding: 5px;
39
+ padding-right: 15px;
40
+ }
41
+
42
+ div#jobs {
43
+ position: absolute;
44
+ left: 375px;
45
+ top: 10px;
46
+ width: 500px;
47
+ padding-left: 20px;
48
+ color: #088A29;
49
+ }
50
+
51
+ div#groups {
52
+ color: #088A29;
53
+ background-color: black;
54
+ }
55
+
56
+ div#groups a {
57
+ color: #088A29;
58
+ background-color: black;
59
+ }
60
+
61
+ .highlight {
62
+ background-color: #088A29;
63
+ color: black;
64
+ }
65
+
66
+ td {
67
+ padding-right: 10px;
68
+ }
69
+
70
+ a {
71
+ text-decoration: underline;
72
+ color: #088A29;
73
+ font-weight: bold;
74
+ }
75
+
76
+ a:hover, ol a:hover {
77
+ text-decoration: underline;
78
+ }
79
+
80
+ </style>
81
+
82
+ </head><body>
83
+
84
+ <div id="stats">
85
+
86
+ <h1>chimpd <%=VERSION%> console</h1>
87
+ <p style="font-size: 90%; padding-left: 10px">FEATURING CUTTING EDGE META REFRESH<br/> TECHNOLOGY
88
+ SINCE 2012</p>
89
+
90
+ <h3>Queue Status</h3>
91
+
92
+ <table>
93
+ <tr>
94
+ <td>Jobs running:</td>
95
+ <td><%= count_jobs_running %>
96
+ </tr><tr>
97
+ <td>Jobs waiting:</td>
98
+ <td><%= count_jobs_queued %>
99
+ </tr><tr>
100
+ <td>Jobs failed:</td>
101
+ <td><%= count_jobs_failed %>
102
+ </tr><tr>
103
+ <td>Jobs completed:</td>
104
+ <td><%= count_jobs_done %>
105
+ </tr>
106
+ </table>
107
+
108
+ <h3>Job Groups</h3>
109
+ <div id="groups" width="90%" style="border: solid 1px #088A29; overflow-y: auto; height: 150px; background: black; color: #088A29;">
110
+ <ol style="margin: 0; padding: 3px;">
111
+ <% queue.group.values.each do |g| %>
112
+ <li>
113
+ [<%= sprintf( "%03d", g.get_jobs_by_status(:running).size) %>/<%= sprintf( "%03d", g.get_job_ids.size) %> <%= g.short_name %>] <% if group_name == g.group_id %><span class="highlight"><%=g.group_id%></span><% else %><a href="/display/group/<%=g.group_id%>"><%= g.group_id %></a><% end %>
114
+
115
+ </li>
116
+ <% end %>
117
+ </ol>
118
+ </div>
119
+
120
+
121
+ <h3>Filter Results</h3>
122
+
123
+ <p>[
124
+ <% if job_filter == 'running' or job_filter == nil %>running jobs <% else %><a href="/display/running">running jobs</a><% end %> |
125
+ <% if job_filter == 'all' %>all jobs <% else %><a href="/display/all">all jobs</a> <% end %> |
126
+ <% if job_filter == 'done' %>complete jobs <% else %><a href="/display/done">complete jobs</a><% end %> |
127
+ <% if job_filter == 'error' %>failed jobs <% else %><a href="/display/error">failed jobs</a><% end %>
128
+ ]
129
+ </p>
130
+
131
+ <h3>Commands</h3>
132
+ <ol>
133
+ <li><a href="/job/running/cancel">cancel running jobs</a></li>
134
+ <li><a href="/job/error/retry">retry failed jobs </a></li>
135
+ <li><a href="/job/all/report">download execution report</a></li>
136
+ </ol>
137
+
138
+ </div>
139
+
140
+ <div id="jobs">
141
+ <% if group_name == nil %>
142
+ <h1>Job Information</h1>
143
+ <% else %>
144
+ <h1>Job Group: <%=CGI::escapeHTML(group_name)%></h1>
145
+ <% end %>
146
+
147
+ <%
148
+ #
149
+ # Print out all the jobs
150
+ #
151
+ jobs.sort! do |a,b|
152
+ a.job_id <=> b.job_id
153
+ end
154
+
155
+ jobs.each do |j|
156
+ next unless j
157
+
158
+ status = j.status
159
+ id = j.job_id
160
+
161
+ server_name = CGI::escapeHTML(j.server['nickname']) if j.server
162
+
163
+ if j.exec
164
+ action = j.exec.to_s
165
+ action = j.exec['right_script']['name'] if j.exec['right_script']
166
+ else
167
+ action = "unknown"
168
+ end
169
+
170
+ if job_filter and not (job_filter == 'all' or job_filter == 'group' )
171
+ next unless status == job_filter.to_sym
172
+ end
173
+
174
+ execution_time_seconds = j.get_total_exec_time
175
+ h = (execution_time_seconds/3600).to_i
176
+ m = (execution_time_seconds/60 - h*60).to_i
177
+ s = (execution_time_seconds - (m*60 + h*3600))
178
+ time = sprintf("%02d:%02d:%02d", h, m, s)
179
+
180
+ %>
181
+
182
+ <h2 style="float: left; color: #088A29">#<%= id %></h2>
183
+ <%
184
+ color = "#088A29"
185
+ color = "brightgreen" if status == Executor::STATUS_RUNNING
186
+ color = "orange" if status == Executor::STATUS_RETRYING
187
+ color = "red" if status == Executor::STATUS_ERROR
188
+ %>
189
+ <ul style="color: <%= color %>">
190
+ <li>Server: <b><%= server_name %></b></li>
191
+ <li>Group: <b><%= j.group.group_id %></b></li>
192
+ <li>Action: <%= action %></li>
193
+ <li>Status: <%= status %></li>
194
+ <li>Time: <%= time %></li>
195
+ <% if status != Executor::STATUS_RUNNING %>
196
+ <li>Results: <span style="color:#777"><%= j.results %></span></li>
197
+ <% end %>
198
+
199
+ <li> <span class="action">
200
+ <% if status == Executor::STATUS_ERROR %>
201
+ <a href="/job/<%=id%>/ack">ack</a> |
202
+ <a href="/job/<%=id%>/retry">retry</a>
203
+ <% elsif status == Executor::STATUS_RUNNING %>
204
+ <a href="/job/<%=id%>/cancel">cancel</a>
205
+ <% else %>
206
+ <a href="/job/<%=id%>/retry">requeue</a>
207
+ <% end %>
208
+ </li>
209
+ </ul>
210
+
211
+ <% end %>
212
+ </div>
213
+
214
+ </body></html>
@@ -0,0 +1,3 @@
1
+ module Chimp
2
+ VERSION = "1.0"
3
+ end
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ require 'getoptlong'
5
+ require 'thread'
6
+ require 'webrick'
7
+ require 'singleton'
8
+ require 'base64'
9
+ require 'rake'
10
+
11
+ require 'rest_connection'
12
+ require 'rest-client'
13
+ require 'progressbar'
14
+ require 'json'
15
+
16
+ module Chimp
17
+ require 'right_chimp/version'
18
+ require 'right_chimp/Chimp'
19
+ require 'right_chimp/Log'
20
+ require 'right_chimp/IDManager'
21
+ require 'right_chimp/daemon/ChimpDaemon'
22
+ require 'right_chimp/daemon/ChimpDaemonClient'
23
+ require 'right_chimp/queue/ChimpQueue'
24
+ require 'right_chimp/queue/QueueWorker'
25
+ require 'right_chimp/queue/ExecutionGroup'
26
+ require 'right_chimp/exec/Executor'
27
+ require 'right_chimp/exec/ExecArray'
28
+ require 'right_chimp/exec/ExecRightScript'
29
+ require 'right_chimp/exec/ExecSSH'
30
+ require 'right_chimp/exec/ExecReport'
31
+ require 'right_chimp/exec/ExecNoop'
32
+ end
@@ -0,0 +1,20 @@
1
+ #
2
+ # Test chimpd client
3
+ #
4
+ $LOAD_PATH << File.dirname(__FILE__) + "/.."
5
+
6
+ require 'lib/right_chimp.rb'
7
+ require 'rspec'
8
+ require 'pp'
9
+
10
+ include Chimp
11
+
12
+ describe Chimp::ExecRightScript do
13
+ it "can select servers with a tag query" do
14
+ c = Chimp::Chimp.new
15
+ c.tags = ["info:deployment=moo:localring91"]
16
+ c.script = "SYS DNSMadeEasy Register Addresses"
17
+ c.dry_run = false
18
+ c.run
19
+ end
20
+ end
@@ -0,0 +1,55 @@
1
+ #
2
+ # Test chimpd client
3
+ #
4
+ $LOAD_PATH << File.dirname(__FILE__) + "/.."
5
+ require 'lib/right_chimp.rb'
6
+ require 'rspec'
7
+ require 'pp'
8
+
9
+ include Chimp
10
+
11
+ chimp_command = "CHIMP_TEST=true bundle exec bin/chimp --noprompt"
12
+ test_tag = "--tag='info:deployment=moo:localring91'"
13
+ test_script = "--script='SYS DNSMadeEasy Register Addresses'"
14
+
15
+ describe Chimp::Chimp do
16
+ #
17
+ # Selection options
18
+ #
19
+ #it "should not prompt when there is no action" do
20
+ # data =`CHIMP_TEST=true bundle exec bin/chimp #{test_tag}`
21
+ # $?.should == 0
22
+ # data.match("No actions to perform.").should != nil
23
+ #end
24
+
25
+ #
26
+ # RightScript execution
27
+ #
28
+ it "should run a rightscript with a tag query" do
29
+ system("#{chimp_command} #{test_tag} #{test_script}")
30
+ $?.should == 0
31
+ end
32
+
33
+ it "should run scripts on an array with a concurrency of 1 and a delay of 5" do
34
+ system("#{chimp_command} --array='Core91' --concurrency=1 --delay=5 --script='SYS MAIL postfix configuration'")
35
+ $?.should == 0
36
+ end
37
+
38
+ it "should run scripts on an array with a concurrency of 4 and a delay of 0" do
39
+ system("#{chimp_command} --array='Core94' --array='Core91' --concurrency=4 --delay=0 --script='SYS MAIL postfix configuration'")
40
+ $?.should == 0
41
+ end
42
+
43
+ #
44
+ # chimpd submission
45
+ #
46
+
47
+ #it "should run a rightscript with a tag query via chimpd" do
48
+ # system('CHIMP_TEST=true bundle exec bin/chimpd')
49
+ # system('CHIMP_TEST=true bundle exec bin/chimp --chimpd --dry-run --noprompt --tag="info:deployment=moo:localring91" --script="SYS DNSMadeEasy Register Addresses"')
50
+ # $?.should == 0
51
+ # system('CHIMP_TEST=true bundle exec bin/chimpd --quit')
52
+ #end
53
+ end
54
+
55
+
@@ -0,0 +1,33 @@
1
+ #
2
+ # Test chimpd
3
+ #
4
+ $LOAD_PATH << File.dirname(__FILE__) + "/.."
5
+ require 'lib/right_chimp.rb'
6
+ require 'rspec'
7
+ require 'pp'
8
+
9
+ include Chimp
10
+
11
+ uri =
12
+
13
+ describe Chimp::ChimpDaemon do
14
+ before :all do
15
+ @c = ChimpDaemon.instance
16
+ @c.spawn_queue_runner
17
+ @c.spawn_webserver
18
+ end
19
+
20
+ #
21
+ # .spawn_queue_runner
22
+ #
23
+ it "should have 50 threads" do
24
+ ChimpQueue.instance.max_threads.should == 50
25
+ end
26
+
27
+ #
28
+ # .quit
29
+ #
30
+ after :all do
31
+ @c.quit
32
+ end
33
+ end
@@ -0,0 +1,44 @@
1
+ #
2
+ # Test chimpd client
3
+ #
4
+ $LOAD_PATH << File.dirname(__FILE__) + "/.."
5
+ require 'lib/right_chimp.rb'
6
+ require 'rspec'
7
+ require 'pp'
8
+
9
+ include Chimp
10
+
11
+ host = "localhost"
12
+ port = "9055"
13
+
14
+ describe Chimp::ChimpDaemonClient do
15
+ before :all do
16
+ @c = ChimpDaemon.new
17
+ @c.verbose = false
18
+ @c.concurrency = 3
19
+ @c.spawn_queue_runner
20
+ @c.spawn_webserver
21
+ end
22
+
23
+ after :all do
24
+ @c.quit if @c
25
+ end
26
+
27
+ #it "can quit a chimpd" do
28
+ # response_code = ChimpDaemonClient.quit(host, port)
29
+ # response_code.should == 200
30
+ #end
31
+
32
+ #
33
+ # .submit
34
+ #
35
+ it "can submit work to chimpd" do
36
+ c = Chimp::Chimp.new
37
+ c.tags = ["service:auditor=true"]
38
+ c.script = "SYS DNSMadeEasy Register Addresses"
39
+ c.dry_run = false
40
+ ChimpDaemonClient.submit(host, port, c)
41
+ end
42
+
43
+ end
44
+
@@ -0,0 +1,135 @@
1
+ #
2
+ # Test QueueWorker
3
+ #
4
+ $LOAD_PATH << File.dirname(__FILE__) + "/.."
5
+ require 'lib/right_chimp.rb'
6
+ require 'rspec'
7
+
8
+ include Chimp
9
+
10
+ describe SerialExecutionGroup do
11
+ before :each do
12
+ @eg = SerialExecutionGroup.new(:test)
13
+ end
14
+
15
+ #
16
+ # .ready?
17
+ #
18
+ it "should be ready when it has work in its queue" do
19
+ @eg.ready?.should == false
20
+ @eg.push(ExecNoop.new(:job_id => 0))
21
+ @eg.ready?.should == true
22
+ end
23
+
24
+ it "should not be ready while a job is executing" do
25
+ @eg.push(ExecNoop.new(:job_id => 0))
26
+ @eg.push(ExecNoop.new(:job_id => 1))
27
+ @eg.get_job(0).status = Executor::STATUS_RUNNING
28
+ @eg.ready?.should == false
29
+ end
30
+
31
+ #
32
+ # .done?
33
+ #
34
+ it "should not be done when it has work in its queue" do
35
+ @eg.done?.should == true
36
+ @eg.push(ExecNoop.new(:job_id => 0))
37
+ @eg.done?.should == false
38
+ end
39
+
40
+ #
41
+ # .size
42
+ #
43
+ it "should be able to report the correct number of items in its queue" do
44
+ @eg.push(ExecNoop.new(:job_id => 0))
45
+ @eg.push(ExecNoop.new(:job_id => 1))
46
+ @eg.push(ExecNoop.new(:job_id => 2))
47
+ @eg.push(ExecNoop.new(:job_id => 3))
48
+ @eg.push(ExecNoop.new(:job_id => 4))
49
+
50
+ @eg.size.should == 5
51
+
52
+ @eg.shift
53
+ @eg.size.should == 4
54
+
55
+ @eg.shift
56
+ @eg.size.should == 3
57
+ end
58
+
59
+ #
60
+ # .sort!
61
+ #
62
+ it "should be able to sort its queue by server name" do
63
+ @eg.push(ExecNoop.new(:job_id => 1, :server => { "nickname" => "BBB", "name" => "BBB"}))
64
+ @eg.push(ExecNoop.new(:job_id => 1, :server => { "nickname" => "CCC", "name" => "CCC"}))
65
+ @eg.push(ExecNoop.new(:job_id => 0, :server => { "nickname" => "AAA", "name" => "AAA"}))
66
+ @eg.sort!
67
+ end
68
+
69
+ #
70
+ # .running?
71
+ #
72
+ it "should tell us whether it is running" do
73
+ @eg.running?.should == false
74
+ @eg.push(ExecNoop.new(:job_id => 0))
75
+ @eg.running?.should == true
76
+ end
77
+
78
+ #
79
+ # .requeue(id)
80
+ #
81
+ it "should requeue jobs correctly" do
82
+ @eg.push(ExecNoop.new(:job_id => 0))
83
+ @eg.reset!
84
+ @eg.size.should == 0
85
+ @eg.requeue(0)
86
+ @eg.size.should == 1
87
+ end
88
+
89
+ #
90
+ # .requeue_failed_jobs
91
+ #
92
+ it "should requeue all failed jobs" do
93
+ @eg.push(ExecNoop.new(:job_id => 0))
94
+ @eg.reset!
95
+ @eg.size.should == 0
96
+
97
+ @eg.get_job(0).status = Executor::STATUS_ERROR
98
+ @eg.requeue_failed_jobs!
99
+ @eg.size.should == 1
100
+ end
101
+
102
+ #
103
+ # .cancel(id)
104
+ #
105
+ it "should cancel a job" do
106
+ @eg.push(ExecNoop.new(:job_id => 0))
107
+ @eg.size.should == 1
108
+ @eg.cancel(0)
109
+ @eg.size.should == 0
110
+ end
111
+
112
+ end
113
+
114
+ describe ParallelExecutionGroup do
115
+ before :each do
116
+ @eg = ParallelExecutionGroup.new(:test)
117
+ end
118
+
119
+ #
120
+ # .ready?
121
+ #
122
+ it "should be ready when it has work in its queue" do
123
+ @eg.ready?.should == false
124
+ @eg.push(ExecNoop.new(:job_id => 0))
125
+ @eg.push(ExecNoop.new(:job_id => 1))
126
+ @eg.ready?.should == true
127
+ end
128
+
129
+ it "should be ready while a job is executing" do
130
+ @eg.push(ExecNoop.new(:job_id => 0))
131
+ @eg.push(ExecNoop.new(:job_id => 1))
132
+ @eg.get_job(0).status = Executor::STATUS_RUNNING
133
+ @eg.ready?.should == true
134
+ end
135
+ end
@@ -0,0 +1,37 @@
1
+ #
2
+ # Test ChimpQueue
3
+ #
4
+
5
+ require 'lib/right_chimp.rb'
6
+ require 'rspec'
7
+
8
+ include Chimp
9
+
10
+ describe ChimpQueue do
11
+ before :all do
12
+ @queue = ChimpQueue.instance
13
+ @queue.max_threads = 3
14
+ @queue.start
15
+ end
16
+
17
+ before :each do
18
+ @queue.reset!
19
+ end
20
+
21
+ it "should accept work" do
22
+ @queue.push(:default, ExecNoop.new(:job_id => 0))
23
+ @queue.group[:default].get_job(0).status.should == Executor::STATUS_NONE
24
+ end
25
+
26
+ it "should distribute work" do
27
+ @queue.push(:default, ExecNoop.new(:job_id => 0))
28
+ @queue.shift.status.should == Executor::STATUS_NONE
29
+ end
30
+
31
+ it "should process the queue" do
32
+ @queue.push(:default, ExecNoop.new(:job_id => 0))
33
+ @queue.wait_until_done(:default) { }
34
+ @queue.group[:default].get_job(0).status.should == Executor::STATUS_DONE
35
+ end
36
+ end
37
+
@@ -0,0 +1,30 @@
1
+ #
2
+ # Test QueueWorker
3
+ #
4
+ $LOAD_PATH << File.dirname(__FILE__) + "/.."
5
+ require 'lib/right_chimp.rb'
6
+ require 'rspec'
7
+
8
+ include Chimp
9
+
10
+ describe QueueWorker do
11
+ it "should instantiate" do
12
+ q = QueueWorker.new
13
+ q.delay = 10
14
+ q.retry_count = 10
15
+ q.never_exit = false
16
+
17
+ ChimpQueue.instance.group = {}
18
+
19
+ q.delay.should == 10
20
+ q.retry_count.should == 10
21
+ q.never_exit.should == false
22
+ end
23
+
24
+ #it "should run" do
25
+ # q = QueueWorker.new
26
+ # q.run
27
+ #end
28
+
29
+ end
30
+
@@ -0,0 +1,33 @@
1
+ #
2
+ # Test Chimp
3
+ #
4
+ $LOAD_PATH << File.dirname(__FILE__) + "/.."
5
+ require 'lib/right_chimp.rb'
6
+ require 'rspec'
7
+
8
+ describe Chimp::Chimp do
9
+ before :each do
10
+ @c = Chimp::Chimp.new
11
+ @c.quiet = true
12
+ @c.prompt = false
13
+ @c.progress = false
14
+ @c.interactive = false
15
+ end
16
+
17
+ it "performs a tag query" do
18
+ @c.tags = ['service:dataservice=true']
19
+ @c.run
20
+ @c.servers.size.should > 0
21
+ end
22
+
23
+ it "performs a deployment query" do
24
+ @c.deployment_names = ['moo:globalring']
25
+ @c.run
26
+ @c.servers.size.should > 0
27
+ end
28
+
29
+ it "performs an array query" do
30
+ @c.array_names = ['Chimp Test Array']
31
+ @c.run
32
+ end
33
+ end