Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
Noah
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Noah
Commits
6773fbb6
Commit
6773fbb6
authored
Apr 10, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updating sample data script. Tagging work
parent
5ea50e75
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
137 additions
and
76 deletions
+137
-76
Rakefile
Rakefile
+2
-68
application_routes.rb
lib/noah/application_routes.rb
+12
-0
link_routes.rb
lib/noah/link_routes.rb
+8
-2
models.rb
lib/noah/models.rb
+2
-3
link.rb
lib/noah/models/link.rb
+13
-0
taggable.rb
lib/noah/taggable.rb
+9
-2
sample_data.rb
spec/support/sample_data.rb
+84
-0
index.haml
views/index.haml
+7
-1
No files found.
Rakefile
View file @
6773fbb6
...
...
@@ -40,75 +40,9 @@ end
desc
"Populate database with sample dataset"
task
:sample
,
:redis_url
do
|
t
,
args
|
require
'noah'
Ohm
::
connect
(
:url
=>
args
.
redis_url
)
Ohm
::
redis
.
flushdb
puts
"Creating watchers..."
Noah
::
Watcher
.
create
:endpoint
=>
"dummy://applications"
,
:pattern
=>
"//noah/applications"
Noah
::
Watcher
.
create
:endpoint
=>
"dummy://configurations"
,
:pattern
=>
"//noah/configurations"
Noah
::
Watcher
.
create
:endpoint
=>
"dummy://hosts"
,
:pattern
=>
"//noah/hosts"
Noah
::
Watcher
.
create
:endpoint
=>
"dummy://services"
,
:pattern
=>
"//noah/services"
Noah
::
Watcher
.
create
:endpoint
=>
"dummy://ephemerals"
,
:pattern
=>
"//noah/ephemerals"
puts
"Creating Host entry for 'localhost'"
h
=
Noah
::
Host
.
create
(
:name
=>
'localhost'
,
:status
=>
"up"
)
if
h
.
save
%w[redis noah]
.
each
do
|
service
|
puts
"Create Service entry for
#{
service
}
"
s
=
Noah
::
Service
.
create
(
:name
=>
service
,
:status
=>
"up"
,
:host
=>
h
)
h
.
services
<<
s
end
end
puts
"Creating Application entry for 'noah'"
a
=
Noah
::
Application
.
create
(
:name
=>
'noah'
)
if
a
.
save
puts
"Creating Configuration entry for 'noah'"
cr
=
Noah
::
Configuration
.
create
(
:name
=>
'redis'
,
:format
=>
'string'
,
:body
=>
'redis://127.0.0.1:6379/0'
)
ch
=
Noah
::
Configuration
.
create
(
:name
=>
'host'
,
:format
=>
'string'
,
:body
=>
'localhost'
)
cp
=
Noah
::
Configuration
.
create
(
:name
=>
'port'
,
:format
=>
'string'
,
:body
=>
'9292'
)
%w[cr ch cp]
.
each
do
|
c
|
a
.
configurations
<<
eval
(
c
)
end
end
puts
"Creating sample entries - Host and Service"
%w[host1.domain.com host2.domain.com host3.domain.com]
.
each
do
|
host
|
h
=
Noah
::
Host
.
create
(
:name
=>
host
,
:status
=>
"up"
)
if
h
.
save
%w[http https smtp mysql]
.
each
do
|
service
|
s
=
Noah
::
Service
.
create
(
:name
=>
service
,
:status
=>
"pending"
,
:host
=>
h
)
h
.
services
<<
s
end
end
end
puts
"Creating sample entries - Application and Configuration"
my_yaml
=
<<
EOY
development:
database: development_database
adapter: mysql
username: dev_user
password: dev_password
EOY
my_json
=
<<
EOJ
{
"id":"hostname",
"data":"localhost"
}
EOJ
a1
=
Noah
::
Application
.
create
(
:name
=>
'myrailsapp1'
)
if
a1
.
save
c1
=
Noah
::
Configuration
.
create
(
:name
=>
'database.yml'
,
:format
=>
'yaml'
,
:body
=>
my_yaml
)
a1
.
configurations
<<
c1
end
a2
=
Noah
::
Application
.
create
(
:name
=>
'myrestapp1'
)
if
a2
.
save
c2
=
Noah
::
Configuration
.
create
(
:name
=>
'config.json'
,
:format
=>
'json'
,
:body
=>
my_json
)
a2
.
configurations
<<
c2
end
puts
"Sample data populated!"
sample_data
=
File
.
expand_path
(
File
.
join
(
".."
,
"spec"
,
"support"
,
"sample_data.rb"
),
__FILE__
)
instance_eval
(
File
.
open
(
sample_data
).
read
)
end
begin
...
...
lib/noah/application_routes.rb
View file @
6773fbb6
...
...
@@ -19,6 +19,14 @@ class Noah::App
end
end
put
'/applications/:appname/tag'
do
|
appname
|
required_params
=
[
"tags"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
(
data
.
keys
.
sort
==
required_params
.
sort
)
?
(
a
=
Noah
::
Application
.
find
(:
name
=>
appname
).
first
)
:
(
raise
"Missing Parameters"
)
a
.
nil?
?
(
halt
404
)
:
(
a
.
tag!
(
data
[
'tags'
]))
a
.
to_json
end
put
'/applications/:appname/watch'
do
|
appname
|
required_params
=
[
"endpoint"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
...
...
@@ -27,6 +35,10 @@ class Noah::App
w
.
to_json
end
put
'/applications/:appname/link/:linkname'
do
|
appname
,
linkname
|
end
put
'/applications/:appname/?'
do
|
appname
|
required_params
=
[
"name"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
...
...
lib/noah/link_routes.rb
View file @
6773fbb6
class
Noah
::
App
get
'/*/?'
do
path
=
params
[
:splat
][
0
]
get
'/:link_name/:model_name/?'
do
|
path
,
model
|
link_name
=
Noah
::
Link
.
find
(
:path
=>
"/"
+
path
).
first
(
halt
404
)
if
link_name
.
nil?
(
halt
404
)
if
link_name
.
to_hash
.
has_key?
(
model
.
to_sym
)
==
false
link_name
.
to_hash
[
model
.
to_sym
].
to_json
end
get
'/:link_name/?'
do
|
path
|
link_name
=
Noah
::
Link
.
find
(
:path
=>
"/"
+
path
).
first
(
halt
404
)
if
link_name
.
nil?
link_name
.
to_json
...
...
lib/noah/models.rb
View file @
6773fbb6
...
...
@@ -37,9 +37,8 @@ module Noah
path
.
nil?
?
(
raise
ArgumentError
,
"Must provide a path"
)
:
p
=
path
begin
l
=
Link
.
new
:path
=>
p
,
:source
=>
base_pattern
l
.
valid?
?
l
.
save
:
(
raise
"
#{
l
.
errors
}
"
)
l
.
name
l
=
Link
.
find_or_create
:path
=>
p
l
.
nodes
=
self
rescue
Exception
=>
e
e
.
message
end
...
...
lib/noah/models/link.rb
View file @
6773fbb6
...
...
@@ -57,6 +57,19 @@ module Noah
def
name
@name
=
path
end
class
<<
self
def
find_or_create
(
opts
=
{})
begin
find
(
opts
).
first
.
nil?
?
obj
=
new
(
opts
)
:
obj
=
find
(
opts
).
first
if
obj
.
valid?
obj
.
save
end
obj
rescue
Exception
=>
e
e
.
message
end
end
end
private
def
node_to_class
(
node
)
node
.
match
(
/^Noah::(.*):(\d+)$/
)
...
...
lib/noah/taggable.rb
View file @
6773fbb6
...
...
@@ -5,14 +5,21 @@ module Noah::Taggable
end
def
tag!
(
tag_name
)
tags
<<
::
Noah
::
Tag
.
find_or_create
(
:name
=>
tag_name
)
case
tag_name
.
class
.
to_s
when
"Array"
tag_name
.
each
do
|
t
|
tags
<<
::
Noah
::
Tag
.
find_or_create
(
:name
=>
t
)
end
else
tags
<<
Noah
::
Tag
.
find_or_create
(
:name
=>
tag_name
)
end
end
def
untag!
(
tag_name
)
end
def
to_hash
tag_arr
=
[]
tag_arr
=
Array
.
new
self
.
tags
.
sort
.
each
{
|
t
|
tag_arr
<<
t
.
name
}
if
self
.
tags
.
size
!=
0
super
.
merge
(
:tags
=>
tag_arr
)
end
...
...
spec/support/sample_data.rb
0 → 100644
View file @
6773fbb6
require
'noah'
Ohm
::
redis
.
flushdb
puts
"Creating sample entries - Watchers"
Noah
::
Watcher
.
create
:endpoint
=>
"dummy://applications"
,
:pattern
=>
"//noah/applications"
Noah
::
Watcher
.
create
:endpoint
=>
"dummy://configurations"
,
:pattern
=>
"//noah/configurations"
Noah
::
Watcher
.
create
:endpoint
=>
"dummy://hosts"
,
:pattern
=>
"//noah/hosts"
Noah
::
Watcher
.
create
:endpoint
=>
"dummy://services"
,
:pattern
=>
"//noah/services"
Noah
::
Watcher
.
create
:endpoint
=>
"dummy://ephemerals"
,
:pattern
=>
"//noah/ephemerals"
puts
"Creating Host entry for 'localhost'"
h
=
Noah
::
Host
.
create
(
:name
=>
'localhost'
,
:status
=>
"up"
)
if
h
.
save
%w[redis noah]
.
each
do
|
service
|
puts
"Create Service entry for
#{
service
}
"
s
=
Noah
::
Service
.
create
(
:name
=>
service
,
:status
=>
"up"
,
:host_id
=>
h
.
id
)
h
.
services
<<
s
end
end
puts
"Creating Application entry for 'noah'"
a
=
Noah
::
Application
.
create
(
:name
=>
'noah'
)
if
a
.
save
puts
"Creating Configuration entry for 'noah'"
cr
=
Noah
::
Configuration
.
create
(
:name
=>
'redis'
,
:format
=>
'string'
,
:body
=>
'redis://127.0.0.1:6379/0'
)
ch
=
Noah
::
Configuration
.
create
(
:name
=>
'host'
,
:format
=>
'string'
,
:body
=>
'localhost'
)
cp
=
Noah
::
Configuration
.
create
(
:name
=>
'port'
,
:format
=>
'string'
,
:body
=>
'9292'
)
%w[cr ch cp]
.
each
do
|
c
|
a
.
configurations
<<
eval
(
c
)
end
end
puts
"Creating sample entries - Host and Service"
%w[host1.domain.com host2.domain.com host3.domain.com]
.
each
do
|
host
|
h
=
Noah
::
Host
.
create
(
:name
=>
host
,
:status
=>
"up"
)
if
h
.
save
%w[http https smtp mysql]
.
each
do
|
service
|
s
=
Noah
::
Service
.
create
(
:name
=>
service
,
:status
=>
"pending"
,
:host
=>
h
)
h
.
services
<<
s
end
end
end
puts
"Creating sample entries - Application and Configuration"
my_yaml
=
<<
EOY
development:
database: development_database
adapter: mysql
username: dev_user
password: dev_password
EOY
my_json
=
<<
EOJ
{
"id":"hostname",
"data":"localhost"
}
EOJ
a1
=
Noah
::
Application
.
create
(
:name
=>
'myrailsapp1'
)
if
a1
.
save
c1
=
Noah
::
Configuration
.
create
(
:name
=>
'database.yml'
,
:format
=>
'yaml'
,
:body
=>
my_yaml
)
a1
.
configurations
<<
c1
end
a2
=
Noah
::
Application
.
create
(
:name
=>
'myrestapp1'
)
if
a2
.
save
c2
=
Noah
::
Configuration
.
create
(
:name
=>
'config.json'
,
:format
=>
'json'
,
:body
=>
my_json
)
a2
.
configurations
<<
c2
end
puts
"Creating sample entries - Ephemerals"
e1
=
Noah
::
Ephemeral
.
create
(
:path
=>
'/some/random/path/item1'
,
:data
=>
'some_data'
)
e2
=
Noah
::
Ephemeral
.
create
(
:path
=>
'/some/random/path/'
,
:data
=>
'{"children":["item1", "item2"]}'
)
puts
"Creating sample entries - Links and Tags"
l1
=
Noah
::
Link
.
new
l1
.
path
=
"/my_sample_organization"
l1
.
save
l1
.
nodes
=
[
a1
,
c2
,
Noah
::
Host
.
find
(
:name
=>
'localhost'
).
first
,
Noah
::
Service
.
find
(
:name
=>
'redis'
).
first
,
e1
,
e2
]
a1
.
tag!
[
"production"
,
"sample_data"
]
e2
.
tag!
"ephemeral"
puts
"Sample data populated!"
views/index.haml
View file @
6773fbb6
...
...
@@ -52,4 +52,10 @@
%a
{
:href
=>
"configurations/myrailsapp1/database.yml"
}
database.yml file for myrailsapp1 (should return the proper content-type)
%li
%a
{
:href
=>
"configurations/myrestapp1/config.json"
}
config.json file for myrestapp1
#header
%h2
Links
%ul
%li
%a
{
:href
=>
"my_sample_organization"
}
Sample Organization Link
%li
%a
{
:href
=>
"my_sample_organization/hosts"
}
Sample Organization Link - Hosts
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment