noah 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +13 -0
- data/.gitignore +7 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +85 -0
- data/README.md +213 -0
- data/Rakefile +105 -0
- data/autotest/discover.rb +1 -0
- data/bin/noah +8 -0
- data/config.ru +3 -0
- data/doc/coverage/index.html +138 -0
- data/doc/coverage/jquery-1.3.2.min.js +19 -0
- data/doc/coverage/jquery.tablesorter.min.js +15 -0
- data/doc/coverage/lib-helpers_rb.html +393 -0
- data/doc/coverage/lib-models_rb.html +1449 -0
- data/doc/coverage/noah_rb.html +2019 -0
- data/doc/coverage/print.css +12 -0
- data/doc/coverage/rcov.js +42 -0
- data/doc/coverage/screen.css +270 -0
- data/lib/noah.rb +18 -0
- data/lib/noah/app.rb +317 -0
- data/lib/noah/applications.rb +46 -0
- data/lib/noah/configurations.rb +49 -0
- data/lib/noah/helpers.rb +57 -0
- data/lib/noah/hosts.rb +54 -0
- data/lib/noah/models.rb +5 -0
- data/lib/noah/services.rb +57 -0
- data/lib/noah/version.rb +3 -0
- data/lib/noah/watchers.rb +18 -0
- data/noah.gemspec +44 -0
- data/spec/application_spec.rb +83 -0
- data/spec/configuration_spec.rb +25 -0
- data/spec/host_spec.rb +119 -0
- data/spec/noahapp_application_spec.rb +108 -0
- data/spec/noahapp_configuration_spec.rb +112 -0
- data/spec/noahapp_host_spec.rb +116 -0
- data/spec/noahapp_service_spec.rb +121 -0
- data/spec/noahapp_spec.rb +20 -0
- data/spec/service_spec.rb +112 -0
- data/spec/spec_helper.rb +105 -0
- data/views/200.erb +1 -0
- data/views/404.erb +1 -0
- data/views/500.erb +1 -0
- data/views/index.haml +49 -0
- metadata +348 -0
data/.autotest
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'autotest/growl'
|
2
|
+
Autotest.add_hook(:initialize) {|at|
|
3
|
+
at.add_exception %r{^\.git} # ignore Version Control System
|
4
|
+
at.add_exception %r{^./tmp} # ignore temp files, lest autotest will run again, and again...
|
5
|
+
at.clear_mappings # take out the default (test/test*rb)
|
6
|
+
at.add_mapping(%r{^noah\.rb$}) {|f, _|
|
7
|
+
Dir['spec/**/*.rb']
|
8
|
+
}
|
9
|
+
at.add_mapping(%r{^lib/.*\.rb$}) {|f, _|
|
10
|
+
Dir['spec/**/*.rb']
|
11
|
+
}
|
12
|
+
nil
|
13
|
+
}
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
noah (0.0.5)
|
5
|
+
haml (= 3.0.25)
|
6
|
+
ohm (= 0.1.3)
|
7
|
+
ohm-contrib (= 0.1.0)
|
8
|
+
rake (= 0.8.7)
|
9
|
+
sinatra (= 1.1.2)
|
10
|
+
sinatra-namespace (= 0.6.1)
|
11
|
+
thin (= 1.2.7)
|
12
|
+
vegas (= 0.1.8)
|
13
|
+
yajl-ruby (= 0.7.9)
|
14
|
+
|
15
|
+
GEM
|
16
|
+
remote: http://rubygems.org/
|
17
|
+
specs:
|
18
|
+
ZenTest (4.4.2)
|
19
|
+
autotest (4.4.6)
|
20
|
+
ZenTest (>= 4.4.1)
|
21
|
+
autotest-growl (0.2.9)
|
22
|
+
backports (1.18.2)
|
23
|
+
daemons (1.1.0)
|
24
|
+
diff-lcs (1.1.2)
|
25
|
+
eventmachine (0.12.10)
|
26
|
+
haml (3.0.25)
|
27
|
+
monkey-lib (0.5.4)
|
28
|
+
backports
|
29
|
+
nest (1.1.0)
|
30
|
+
redis (~> 2.1)
|
31
|
+
ohm (0.1.3)
|
32
|
+
nest (~> 1.0)
|
33
|
+
ohm-contrib (0.1.0)
|
34
|
+
ohm
|
35
|
+
rack (1.2.1)
|
36
|
+
rack-test (0.5.7)
|
37
|
+
rack (>= 1.0)
|
38
|
+
rake (0.8.7)
|
39
|
+
rcov (0.9.9)
|
40
|
+
redis (2.1.1)
|
41
|
+
rspec (2.4.0)
|
42
|
+
rspec-core (~> 2.4.0)
|
43
|
+
rspec-expectations (~> 2.4.0)
|
44
|
+
rspec-mocks (~> 2.4.0)
|
45
|
+
rspec-core (2.4.0)
|
46
|
+
rspec-expectations (2.4.0)
|
47
|
+
diff-lcs (~> 1.1.2)
|
48
|
+
rspec-mocks (2.4.0)
|
49
|
+
sinatra (1.1.2)
|
50
|
+
rack (~> 1.1)
|
51
|
+
tilt (~> 1.2)
|
52
|
+
sinatra-advanced-routes (0.5.1)
|
53
|
+
monkey-lib (~> 0.5.0)
|
54
|
+
sinatra (~> 1.0)
|
55
|
+
sinatra-sugar (~> 0.5.0)
|
56
|
+
sinatra-namespace (0.6.1)
|
57
|
+
sinatra (~> 1.1)
|
58
|
+
sinatra-reloader (0.5.0)
|
59
|
+
sinatra (~> 1.0)
|
60
|
+
sinatra-advanced-routes (~> 0.5.0)
|
61
|
+
sinatra-sugar (0.5.0)
|
62
|
+
monkey-lib (~> 0.5.0)
|
63
|
+
sinatra (~> 1.0)
|
64
|
+
thin (1.2.7)
|
65
|
+
daemons (>= 1.0.9)
|
66
|
+
eventmachine (>= 0.12.6)
|
67
|
+
rack (>= 1.0.0)
|
68
|
+
tilt (1.2.2)
|
69
|
+
vegas (0.1.8)
|
70
|
+
rack (>= 1.0.0)
|
71
|
+
yajl-ruby (0.7.9)
|
72
|
+
|
73
|
+
PLATFORMS
|
74
|
+
java
|
75
|
+
ruby
|
76
|
+
|
77
|
+
DEPENDENCIES
|
78
|
+
ZenTest (= 4.4.2)
|
79
|
+
autotest (= 4.4.6)
|
80
|
+
autotest-growl (= 0.2.9)
|
81
|
+
noah!
|
82
|
+
rack-test (= 0.5.7)
|
83
|
+
rcov (= 0.9.9)
|
84
|
+
rspec (= 2.4.0)
|
85
|
+
sinatra-reloader (= 0.5.0)
|
data/README.md
ADDED
@@ -0,0 +1,213 @@
|
|
1
|
+
# Noah testing quickstart
|
2
|
+
(make sure redis is running)
|
3
|
+
|
4
|
+
## Setup
|
5
|
+
There is no specific configuration file in use anymore. Everything is configured via command-line options to the noah binary or stored in config.ru.
|
6
|
+
|
7
|
+
* The instance of Redis is configured via the `REDIS_URL` env setting. This is honored by Ohm.
|
8
|
+
* Redis DSN strings are in the format of "redis://hostname:port/db"
|
9
|
+
* `RACK_ENV` is honored.
|
10
|
+
* `rake sample["redis://localhost:6379/2"]` populates the locally running redis instance - db 2
|
11
|
+
* `rake spec` runs the test suite (using 'redis://localhost:6379/3' for storing test data)
|
12
|
+
|
13
|
+
_rake sample_
|
14
|
+
|
15
|
+
Creating Host entry for 'localhost'
|
16
|
+
Create Service entry for redis
|
17
|
+
Create Service entry for noah
|
18
|
+
Creating Application entry for 'noah'
|
19
|
+
Creating Configuration entry for 'noah'
|
20
|
+
Creating sample entries - Host and Service
|
21
|
+
Creating sample entries - Application and Configuration
|
22
|
+
Setup successful!
|
23
|
+
|
24
|
+
## Run it
|
25
|
+
There are two way to run Noah
|
26
|
+
|
27
|
+
### config.ru
|
28
|
+
Edit config.ru to change the redis instance or rack environment.
|
29
|
+
|
30
|
+
### bin/noah
|
31
|
+
The binary script in bin was created using [Vegas](https://github.com/quirkey/vegas). It accepts the familiar rack options as well as an option for specifying the redis url.
|
32
|
+
|
33
|
+
bin/noah -p 9292 -s thin -d -F -e production -r redis://localhost:6379/2
|
34
|
+
[2011-02-07 16:48:15 -0500] Starting 'noah'...
|
35
|
+
[2011-02-07 16:48:15 -0500] trying port 9292...
|
36
|
+
Couldn't get a file descriptor referring to the console
|
37
|
+
[2011-02-07 16:48:15 -0500] Running with Rack handler: Rack::Handler::Thin
|
38
|
+
>> Thin web server (v1.2.7 codename No Hup)
|
39
|
+
>> Maximum connections set to 1024
|
40
|
+
>> Listening on 0.0.0.0:9292, CTRL+C to stop
|
41
|
+
|
42
|
+
If you leave off `-F`, all information will be logged to `$HOME/.vegas/noah`. Run `bin/noah -h` for more options.
|
43
|
+
|
44
|
+
Please note on JRuby that the port setting does not work for some f'cking reason. Bug claims to have been fixed. Until then, when on Jruby run like so:
|
45
|
+
|
46
|
+
noah -F -d -r redis://localhost:6379/0
|
47
|
+
|
48
|
+
## Example links
|
49
|
+
[Noah Start Page](http://localhost:9292/)
|
50
|
+
|
51
|
+
If you have Noah running, you can hit the above link for some links created by the setup samples.
|
52
|
+
|
53
|
+
## All configs
|
54
|
+
_curl http://localhost:9292/c/_
|
55
|
+
|
56
|
+
[
|
57
|
+
{"id":"1",
|
58
|
+
"name":"db",
|
59
|
+
"format":"string",
|
60
|
+
"body":"redis://127.0.0.1:6379/0",
|
61
|
+
"update_at":"2011-01-17 14:12:43 UTC",
|
62
|
+
"application":"noah"
|
63
|
+
}
|
64
|
+
]
|
65
|
+
|
66
|
+
## All services
|
67
|
+
_curl http://localhost:9292/s/_
|
68
|
+
|
69
|
+
[
|
70
|
+
{
|
71
|
+
"id":"1",
|
72
|
+
"name":"redis",
|
73
|
+
"status":"up",
|
74
|
+
"updated_at":"2011-01-17 14:12:43 UTC",
|
75
|
+
"host":"localhost"
|
76
|
+
},
|
77
|
+
{
|
78
|
+
"id":"2",
|
79
|
+
"name":"noah",
|
80
|
+
"status":"up",
|
81
|
+
"updated_at":"2011-01-17 14:12:43 UTC",
|
82
|
+
"host":"localhost"
|
83
|
+
}
|
84
|
+
]
|
85
|
+
|
86
|
+
## All hosts
|
87
|
+
_curl http://localhost:9292/h/_
|
88
|
+
|
89
|
+
[
|
90
|
+
{
|
91
|
+
"id":"1",
|
92
|
+
"name":"localhost",
|
93
|
+
"status":"up",
|
94
|
+
"updated_at":"2011-01-17 14:12:43 UTC",
|
95
|
+
"services":[
|
96
|
+
{
|
97
|
+
"id":"1",
|
98
|
+
"name":"redis",
|
99
|
+
"status":"up",
|
100
|
+
"updated_at":"2011-01-17 14:12:43 UTC",
|
101
|
+
"host":"localhost"
|
102
|
+
},
|
103
|
+
{
|
104
|
+
"id":"2",
|
105
|
+
"name":"noah",
|
106
|
+
"status":"up",
|
107
|
+
"updated_at":"2011-01-17 14:12:43 UTC",
|
108
|
+
"host":"localhost"
|
109
|
+
}
|
110
|
+
]
|
111
|
+
}
|
112
|
+
]
|
113
|
+
|
114
|
+
## All applications
|
115
|
+
_curl http://localhost:9292/a/_
|
116
|
+
|
117
|
+
[
|
118
|
+
{
|
119
|
+
"id":"1",
|
120
|
+
"name":"noah",
|
121
|
+
"updated_at":"2011-01-17 14:12:43 UTC"
|
122
|
+
}
|
123
|
+
]
|
124
|
+
|
125
|
+
Most other combinations of endpoints work as well:
|
126
|
+
|
127
|
+
* `http://localhost:9292/h/<hostname>/<servicename>` - `<servicename>` on `<hostname>`
|
128
|
+
* `http://localhost:9292/a/<appname>/<configname>` - Configuration for `<appname>`
|
129
|
+
* `http://localhost:9292/c/<appname>/<element>` - Specific configuration element for `<appname>`
|
130
|
+
|
131
|
+
{
|
132
|
+
"id":"1",
|
133
|
+
"name":"db",
|
134
|
+
"format":"string",
|
135
|
+
"body":"redis://127.0.0.1:6379/0",
|
136
|
+
"update_at":"2011-01-17 14:12:43 UTC",
|
137
|
+
"application":"noah"
|
138
|
+
}
|
139
|
+
|
140
|
+
# Adding new entries
|
141
|
+
There are two ways to add new objects: via irb and via the [API](https://github.com/lusis/Noah/wiki/Stabilize-API) on a running instance. The API is still in a state of flux.
|
142
|
+
|
143
|
+
## Adding a new application and configuration item
|
144
|
+
|
145
|
+
irb -rohm -rohm/contrib -r./lib/noah/models.rb
|
146
|
+
|
147
|
+
a1 = Application.create(:name => 'myapplication')
|
148
|
+
if a1.save
|
149
|
+
a1.configurations << Configuration.create(:name => 'jsonconfigobj', :format => 'json', :body => '{"configvar1":"foo","configvar2":"bar"}', :application => a1)
|
150
|
+
end
|
151
|
+
JSON.parse(Configuration[2].body)
|
152
|
+
|
153
|
+
{"configvar1"=>"foo", "configvar2"=>"bar"}
|
154
|
+
|
155
|
+
## database.yml inside Noah? Sure!
|
156
|
+
|
157
|
+
dbyaml = <<EOY
|
158
|
+
development:
|
159
|
+
adapter: mysql
|
160
|
+
database: rails_development
|
161
|
+
username: root
|
162
|
+
password: my super secret password
|
163
|
+
EOY
|
164
|
+
a2 = Application.create(:name => 'myrailsapp')
|
165
|
+
if a2.save
|
166
|
+
a2.configurations << Configuration.create(:name => 'database.yml', :format => 'yaml', :body => dbyaml, :application => a2)
|
167
|
+
end
|
168
|
+
puts YAML.dump(Configuration[3].body)
|
169
|
+
|
170
|
+
development:
|
171
|
+
adapter: mysql
|
172
|
+
database: rails_development
|
173
|
+
username: root
|
174
|
+
password: my super secret password
|
175
|
+
|
176
|
+
# Hosts and Services/Applications and Configurations
|
177
|
+
Host/Services and Applications/Configurations are almost the same thing with a few exceptions. Here are some basic facts:
|
178
|
+
|
179
|
+
* Hosts have many Services
|
180
|
+
* Applications have many Configurations
|
181
|
+
* Hosts and Services have a status - `up`,`down` or `pending`
|
182
|
+
|
183
|
+
The intention of the `status` field for Hosts and Services is that a service might, when starting up, set the appropriate status. Same goes for said service shutting down. This also applies to hosts (i.e. a curl PUT is sent to Noah during the boot process).
|
184
|
+
|
185
|
+
While an application might have different "configurations" based on environment (production, qa, dev), the Configuration object in Noah is intended to be more holistic i.e. these are the Configuration atoms (a yaml file, property X, property Y) that form the running configuration of an Application.
|
186
|
+
|
187
|
+
Here's a holistic example using a tomcat application:
|
188
|
+
|
189
|
+
* Host running tomcat comes up. It sets its status as "pending"
|
190
|
+
* Each service on the box starts up and sets its status to "pending" and finally "up" (think steps in the init script for the service)
|
191
|
+
* Tomcat (now in the role of `Application`) given a single property in a properties file called "bootstrap.url", grabs a list of `Configuration`atoms it needs to run. Let's say, by default, Tomcat starts up with all webapps disabled. Using the `Configuration` item `webapps`, it knows which ones to start up.
|
192
|
+
* Each webapp (an application under a different context root) now has the role of `Application` and the role of `Service`. As an application, the webapp would grab things that would normally be stored in a .properties file. Maybe even the log4j.xml file. In the role of `Service`, a given webapp might be an API endpoint and so it would have a hostname (a virtual host maybe?) and services associated with it. Each of those, has a `status`.
|
193
|
+
|
194
|
+
That might be confusing and it's a fairly overly-contrived example. A more comon use case would be the above where, instead of storing the database.yml on the server, the Rails application actually reads the file from Noah. Now that might not be too exciting but try this example:
|
195
|
+
|
196
|
+
* Rails application with memcached as part of the stack.
|
197
|
+
* Instead of a local configuration file, the list of memcached servers is a `Configuration` object belonging to the rails application's `Application` object.
|
198
|
+
* As new memcached servers are brought online, your CM tool (puppet or chef) updates Noah
|
199
|
+
* Your Rails application either via restarting (and thus rebootstrapping the list of memcached servers from Noah) or using the Watcher subsystem is instantly aware of those servers. You could fairly easily implement a custom Watcher that, when the list of memcached server changes, the Passenger restart file is written.
|
200
|
+
|
201
|
+
Make sense?
|
202
|
+
|
203
|
+
# Constraints
|
204
|
+
You can view all the constraints inside `models.rb` but here they are for now:
|
205
|
+
|
206
|
+
* A new host must have at least `name` and `status` set.
|
207
|
+
* A new service must have at least `name` and `status` set.
|
208
|
+
* Each Host `name` must be unique
|
209
|
+
* Each Service `name` per Host must be unique
|
210
|
+
* Each Application `name` must exist and be unique
|
211
|
+
* Each Configuration name per Application must be unique.
|
212
|
+
* Each Configuration must have `name`,`format` and `body`
|
213
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
begin
|
3
|
+
Bundler.setup(:default, :development)
|
4
|
+
rescue Bundler::BundlerError => e
|
5
|
+
$stderr.puts e.message
|
6
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
7
|
+
exit e.status_code
|
8
|
+
end
|
9
|
+
require 'rake'
|
10
|
+
|
11
|
+
require 'rspec/core'
|
12
|
+
require 'rspec/core/rake_task'
|
13
|
+
|
14
|
+
Bundler::GemHelper.install_tasks
|
15
|
+
|
16
|
+
desc "Populate database with sample dataset"
|
17
|
+
task :sample, :redis_url do |t, args|
|
18
|
+
require 'ohm'
|
19
|
+
begin
|
20
|
+
require 'yajl'
|
21
|
+
rescue LoadError
|
22
|
+
require 'json'
|
23
|
+
end
|
24
|
+
require File.join(File.dirname(__FILE__), 'lib','noah')
|
25
|
+
|
26
|
+
|
27
|
+
Ohm::connect(:url => args.redis_url)
|
28
|
+
Ohm::redis.flushdb
|
29
|
+
puts "Creating Host entry for 'localhost'"
|
30
|
+
h = Host.create(:name => 'localhost', :status => "up")
|
31
|
+
if h.save
|
32
|
+
%w[redis noah].each do |service|
|
33
|
+
puts "Create Service entry for #{service}"
|
34
|
+
s = Service.create(:name => service, :status => "up", :host => h)
|
35
|
+
h.services << s
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
puts "Creating Application entry for 'noah'"
|
40
|
+
a = Application.create(:name => 'noah')
|
41
|
+
if a.save
|
42
|
+
puts "Creating Configuration entry for 'noah'"
|
43
|
+
cr = Configuration.create(:name => 'redis', :format => 'string', :body => 'redis://127.0.0.1:6379/0', :application => a)
|
44
|
+
ch = Configuration.create(:name => 'host', :format => 'string', :body => 'localhost', :application => a)
|
45
|
+
cp = Configuration.create(:name => 'port', :format => 'string', :body => '9292', :application => a)
|
46
|
+
%w[cr ch cp].each do |c|
|
47
|
+
a.configurations << eval(c)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
puts "Creating sample entries - Host and Service"
|
52
|
+
%w[host1.domain.com host2.domain.com host3.domain.com].each do |host|
|
53
|
+
h = Host.create(:name => host, :status => "up")
|
54
|
+
if h.save
|
55
|
+
%w[http https smtp mysql].each do |service|
|
56
|
+
s = Service.create(:name => service, :status => "pending", :host => h)
|
57
|
+
h.services << s
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
puts "Creating sample entries - Application and Configuration"
|
63
|
+
my_yaml = <<EOY
|
64
|
+
development:
|
65
|
+
database: development_database
|
66
|
+
adapter: mysql
|
67
|
+
username: dev_user
|
68
|
+
password: dev_password
|
69
|
+
EOY
|
70
|
+
my_json = <<EOJ
|
71
|
+
{
|
72
|
+
"id":"hostname",
|
73
|
+
"data":"localhost"
|
74
|
+
}
|
75
|
+
EOJ
|
76
|
+
|
77
|
+
a1 = Application.create(:name => 'myrailsapp1')
|
78
|
+
if a1.save
|
79
|
+
c1 = Configuration.create(:name => 'database.yml', :format => 'yaml', :body => my_yaml, :application => a1)
|
80
|
+
a1.configurations << c1
|
81
|
+
end
|
82
|
+
|
83
|
+
a2 = Application.create(:name => 'myrestapp1')
|
84
|
+
if a2.save
|
85
|
+
c2 = Configuration.create(:name => 'config.json', :format => 'json', :body => my_json, :application => a2)
|
86
|
+
a2.configurations << c2
|
87
|
+
end
|
88
|
+
puts "Sample data populated!"
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
93
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
94
|
+
end
|
95
|
+
|
96
|
+
namespace :coverage do
|
97
|
+
desc "Delete aggregate coverage data."
|
98
|
+
task(:clean) { rm_f "coverage.data" }
|
99
|
+
end
|
100
|
+
desc "Run Rcov code coverage analysis"
|
101
|
+
RSpec::Core::RakeTask.new(:coverage) do |t|
|
102
|
+
t.rcov = true
|
103
|
+
t.verbose = true
|
104
|
+
t.rcov_opts = %q[--aggregate coverage.data --sort coverage --text-report --exclude "config,.bundle/*,gems/*,spec/*" -o doc/coverage -Ilib -i "noah.rb"]
|
105
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Autotest.add_discovery { "rspec2" }
|
data/bin/noah
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
|
3
|
+
require 'noah'
|
4
|
+
require 'vegas'
|
5
|
+
|
6
|
+
Vegas::Runner.new(Noah::App, 'noah') do |runner, opts, app|
|
7
|
+
opts.on("-r", "--redis URL", "redis url to connect to (default: redis://localhost:6379/0)") {|r| ENV["REDIS_URL"] = r }
|
8
|
+
end
|
data/config.ru
ADDED