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
71a5b6fd
Commit
71a5b6fd
authored
May 25, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
untag routes working
parent
349e759b
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
176 additions
and
140 deletions
+176
-140
app.rb
lib/noah/app.rb
+1
-1
helpers.rb
lib/noah/helpers.rb
+4
-138
base_helpers.rb
lib/noah/helpers/base_helpers.rb
+138
-0
link_helpers.rb
lib/noah/helpers/link_helpers.rb
+0
-0
tag_helpers.rb
lib/noah/helpers/tag_helpers.rb
+0
-0
watch_helpers.rb
lib/noah/helpers/watch_helpers.rb
+0
-0
applications.rb
lib/noah/routes/applications.rb
+8
-0
configurations.rb
lib/noah/routes/configurations.rb
+8
-1
hosts.rb
lib/noah/routes/hosts.rb
+9
-0
services.rb
lib/noah/routes/services.rb
+8
-0
No files found.
lib/noah/app.rb
View file @
71a5b6fd
...
@@ -4,7 +4,7 @@ require File.join(File.dirname(__FILE__), 'models')
...
@@ -4,7 +4,7 @@ require File.join(File.dirname(__FILE__), 'models')
module
Noah
module
Noah
class
App
<
Sinatra
::
Base
class
App
<
Sinatra
::
Base
helpers
Noah
::
SinatraHelpers
helpers
Noah
::
Sinatra
Base
Helpers
configure
do
configure
do
set
:app_file
,
__FILE__
set
:app_file
,
__FILE__
...
...
lib/noah/helpers.rb
View file @
71a5b6fd
module
Noah
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'helpers'
,
'base_helpers'
)
module
SinatraHelpers
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'helpers'
,
'tag_helpers'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'helpers'
,
'link_helpers'
)
def
format_errors
(
model
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'helpers'
,
'watch_helpers'
)
error_messages
=
model
.
errors
.
present
do
|
e
|
# Missing attributes
e
.
on
[
:name
,
:not_present
],
"Name attribute missing"
e
.
on
[
:status
,
:not_present
],
"Status attribute missing"
e
.
on
[
:format
,
:not_present
],
"Format attribute missing"
e
.
on
[
:body
,
:not_present
],
"Body attribute missing"
e
.
on
[
:application_id
,
:not_present
],
"Application attribute missing"
e
.
on
[
:path
,
:not_present
],
"Path attribute missing"
e
.
on
[
:pattern
,
:not_present
],
"Pattern attribute missing"
e
.
on
[
:endpoint
,
:not_present
],
"Endpoint attribute missing"
# Invalid option
e
.
on
[
:status
,
:not_member
],
"Status must be up, down or pending"
# Duplicate keys
e
.
on
[[
:name
,
:application_id
],
:not_unique
],
"Record already exists"
e
.
on
[[
:name
,
:host_id
],
:not_unique
],
"Record already exists"
e
.
on
[[
:endpoint
,
:pattern
],
:not_unique
],
"Record already exists"
e
.
on
[
:path
,
:not_unique
],
"Record already exists"
# Custom exceptions
e
.
on
[
:pattern
,
:already_provided
],
"Pattern is already provided"
e
.
on
[
:pattern
,
:replaces_existing
],
"Pattern would overwrite existing"
e
.
on
[
:path
,
:reserved_path
],
"Path is reserved"
end
error_messages
.
first
end
def
host
(
opts
=
{})
Noah
::
Host
.
find
(
opts
).
first
end
def
hosts
(
opts
=
{})
Noah
::
Hosts
.
all
(
opts
)
end
def
service
(
opts
=
{})
Noah
::
Service
.
find
(
options
)
end
def
services
(
opts
=
{})
Noah
::
Services
.
all
(
opts
)
end
def
host_service
(
hostname
,
servicename
)
h
=
Noah
::
Host
.
find
(
:name
=>
hostname
).
first
if
h
.
nil?
nil
else
Noah
::
Service
.
find
(
:host_id
=>
h
.
id
,
:name
=>
servicename
).
first
end
end
def
host_services
(
hostname
)
h
=
Noah
::
Host
.
find
(
:name
=>
hostname
).
first
if
h
.
nil?
nil
else
Noah
::
Services
.
all
(
:host_id
=>
id
)
end
end
def
find_hosts_by_service
(
servicename
)
affected_hosts
=
[]
s
=
Noah
::
Service
.
find
(
:name
=>
servicename
)
if
s
.
nil?
affected_hosts
else
Noah
::
Host
.
all
.
each
{
|
x
|
affected_hosts
<<
x
if
(
x
.
services
.
to_a
&
s
.
to_a
).
length
>
0
}
affected_hosts
end
end
def
delete_service_from_host
(
servicename
,
hostname
)
host
=
Noah
::
Host
.
find
(
:name
=>
hostname
).
first
(
halt
404
)
if
host
.
nil?
service
=
Noah
::
Service
.
find
(
:name
=>
servicename
,
:host_id
=>
host
.
id
).
first
(
halt
404
)
if
service
.
nil?
service
.
delete
r
=
{
"action"
=>
"delete"
,
"result"
=>
"success"
,
"id"
=>
service
.
id
,
"host"
=>
host
.
name
,
"service"
=>
servicename
}
r
.
to_json
end
def
find_named_link
(
path
)
link
=
Noah
::
Link
.
find
(
:path
=>
"/"
+
path
).
first
if
link
.
nil?
# try finding it wihtout the slash
link
=
Noah
::
Link
.
find
(
:path
=>
path
).
first
(
halt
404
)
if
link
.
nil?
end
return
link
end
def
add_config_to_app
(
appname
,
config_hash
)
begin
config
=
Noah
::
Configuration
.
find_or_create
(
config_hash
)
if
config
.
valid?
dep_action
=
config
.
is_new?
?
"create"
:
"update"
else
raise
"
#{
format_errors
(
config
)
}
"
end
app
=
Noah
::
Application
.
find_or_create
(
:name
=>
appname
)
if
app
.
valid?
action
=
app
.
is_new?
?
"create"
:
"update"
app
.
configurations
<<
config
r
=
{
"result"
=>
"success"
,
"id"
=>
"
#{
app
.
id
}
"
,
"name"
=>
"
#{
app
.
name
}
"
,
"action"
=>
action
,
"configuration"
=>
{
"action"
=>
dep_action
,
"id"
=>
"
#{
config
.
id
}
"
,
"item"
=>
"
#{
config
.
name
}
"
}}
r
.
to_json
else
raise
"
#{
format_errors
(
app
)
}
"
end
rescue
Exception
=>
e
e
.
message
ensure
# Clean up partial objects
app
.
delete
if
app
.
valid?
==
false
config
.
delete
if
config
.
valid?
==
false
end
end
def
application
(
opts
=
{})
Noah
::
Application
.
find
(
opts
).
first
end
def
applications
(
opts
=
{})
Noah
::
Applications
.
all
(
opts
)
end
def
configuration
(
opts
=
{})
Noah
::
Configuration
.
find
(
opts
).
first
end
def
configurations
(
opts
=
{})
Noah
::
Configurations
.
all
(
opts
)
end
end
end
lib/noah/helpers/base_helpers.rb
0 → 100644
View file @
71a5b6fd
module
Noah
module
SinatraBaseHelpers
def
format_errors
(
model
)
error_messages
=
model
.
errors
.
present
do
|
e
|
# Missing attributes
e
.
on
[
:name
,
:not_present
],
"Name attribute missing"
e
.
on
[
:status
,
:not_present
],
"Status attribute missing"
e
.
on
[
:format
,
:not_present
],
"Format attribute missing"
e
.
on
[
:body
,
:not_present
],
"Body attribute missing"
e
.
on
[
:application_id
,
:not_present
],
"Application attribute missing"
e
.
on
[
:path
,
:not_present
],
"Path attribute missing"
e
.
on
[
:pattern
,
:not_present
],
"Pattern attribute missing"
e
.
on
[
:endpoint
,
:not_present
],
"Endpoint attribute missing"
# Invalid option
e
.
on
[
:status
,
:not_member
],
"Status must be up, down or pending"
# Duplicate keys
e
.
on
[[
:name
,
:application_id
],
:not_unique
],
"Record already exists"
e
.
on
[[
:name
,
:host_id
],
:not_unique
],
"Record already exists"
e
.
on
[[
:endpoint
,
:pattern
],
:not_unique
],
"Record already exists"
e
.
on
[
:path
,
:not_unique
],
"Record already exists"
# Custom exceptions
e
.
on
[
:pattern
,
:already_provided
],
"Pattern is already provided"
e
.
on
[
:pattern
,
:replaces_existing
],
"Pattern would overwrite existing"
e
.
on
[
:path
,
:reserved_path
],
"Path is reserved"
end
error_messages
.
first
end
def
host
(
opts
=
{})
Noah
::
Host
.
find
(
opts
).
first
end
def
hosts
(
opts
=
{})
Noah
::
Hosts
.
all
(
opts
)
end
def
service
(
opts
=
{})
Noah
::
Service
.
find
(
options
)
end
def
services
(
opts
=
{})
Noah
::
Services
.
all
(
opts
)
end
def
host_service
(
hostname
,
servicename
)
h
=
Noah
::
Host
.
find
(
:name
=>
hostname
).
first
if
h
.
nil?
nil
else
Noah
::
Service
.
find
(
:host_id
=>
h
.
id
,
:name
=>
servicename
).
first
end
end
def
host_services
(
hostname
)
h
=
Noah
::
Host
.
find
(
:name
=>
hostname
).
first
if
h
.
nil?
nil
else
Noah
::
Services
.
all
(
:host_id
=>
id
)
end
end
def
find_hosts_by_service
(
servicename
)
affected_hosts
=
[]
s
=
Noah
::
Service
.
find
(
:name
=>
servicename
)
if
s
.
nil?
affected_hosts
else
Noah
::
Host
.
all
.
each
{
|
x
|
affected_hosts
<<
x
if
(
x
.
services
.
to_a
&
s
.
to_a
).
length
>
0
}
affected_hosts
end
end
def
delete_service_from_host
(
servicename
,
hostname
)
host
=
Noah
::
Host
.
find
(
:name
=>
hostname
).
first
(
halt
404
)
if
host
.
nil?
service
=
Noah
::
Service
.
find
(
:name
=>
servicename
,
:host_id
=>
host
.
id
).
first
(
halt
404
)
if
service
.
nil?
service
.
delete
r
=
{
"action"
=>
"delete"
,
"result"
=>
"success"
,
"id"
=>
service
.
id
,
"host"
=>
host
.
name
,
"service"
=>
servicename
}
r
.
to_json
end
def
find_named_link
(
path
)
link
=
Noah
::
Link
.
find
(
:path
=>
"/"
+
path
).
first
if
link
.
nil?
# try finding it wihtout the slash
link
=
Noah
::
Link
.
find
(
:path
=>
path
).
first
(
halt
404
)
if
link
.
nil?
end
return
link
end
def
add_config_to_app
(
appname
,
config_hash
)
begin
config
=
Noah
::
Configuration
.
find_or_create
(
config_hash
)
if
config
.
valid?
dep_action
=
config
.
is_new?
?
"create"
:
"update"
else
raise
"
#{
format_errors
(
config
)
}
"
end
app
=
Noah
::
Application
.
find_or_create
(
:name
=>
appname
)
if
app
.
valid?
action
=
app
.
is_new?
?
"create"
:
"update"
app
.
configurations
<<
config
r
=
{
"result"
=>
"success"
,
"id"
=>
"
#{
app
.
id
}
"
,
"name"
=>
"
#{
app
.
name
}
"
,
"action"
=>
action
,
"configuration"
=>
{
"action"
=>
dep_action
,
"id"
=>
"
#{
config
.
id
}
"
,
"item"
=>
"
#{
config
.
name
}
"
}}
r
.
to_json
else
raise
"
#{
format_errors
(
app
)
}
"
end
rescue
Exception
=>
e
e
.
message
ensure
# Clean up partial objects
app
.
delete
if
app
.
valid?
==
false
config
.
delete
if
config
.
valid?
==
false
end
end
def
application
(
opts
=
{})
Noah
::
Application
.
find
(
opts
).
first
end
def
applications
(
opts
=
{})
Noah
::
Applications
.
all
(
opts
)
end
def
configuration
(
opts
=
{})
Noah
::
Configuration
.
find
(
opts
).
first
end
def
configurations
(
opts
=
{})
Noah
::
Configurations
.
all
(
opts
)
end
end
end
lib/noah/helpers/link_helpers.rb
0 → 100644
View file @
71a5b6fd
lib/noah/helpers/tag_helpers.rb
0 → 100644
View file @
71a5b6fd
lib/noah/helpers/watch_helpers.rb
0 → 100644
View file @
71a5b6fd
lib/noah/routes/applications.rb
View file @
71a5b6fd
...
@@ -21,6 +21,14 @@ class Noah::App
...
@@ -21,6 +21,14 @@ class Noah::App
a
.
to_json
a
.
to_json
end
end
delete
'/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
.
untag!
(
data
[
'tags'
]))
a
.
to_json
end
put
'/applications/:appname/watch'
do
|
appname
|
put
'/applications/:appname/watch'
do
|
appname
|
required_params
=
[
"endpoint"
]
required_params
=
[
"endpoint"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
data
=
JSON
.
parse
(
request
.
body
.
read
)
...
...
lib/noah/routes/configurations.rb
View file @
71a5b6fd
...
@@ -38,7 +38,14 @@ class Noah::App
...
@@ -38,7 +38,14 @@ class Noah::App
(
data
.
keys
.
sort
==
required_params
.
sort
)
?
(
c
=
Noah
::
Configuration
.
find
(:
name
=>
configname
).
first
)
:
(
raise
"Missing Parameters"
)
(
data
.
keys
.
sort
==
required_params
.
sort
)
?
(
c
=
Noah
::
Configuration
.
find
(:
name
=>
configname
).
first
)
:
(
raise
"Missing Parameters"
)
c
.
nil?
?
(
halt
404
)
:
(
c
.
tag!
(
data
[
'tags'
]))
c
.
nil?
?
(
halt
404
)
:
(
c
.
tag!
(
data
[
'tags'
]))
c
.
to_json
c
.
to_json
end
# Delete a tag[s] from a configuration object
delete
'/configurations/:configname/tag'
do
|
configname
|
required_params
=
[
"tags"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
(
data
.
keys
.
sort
==
required_params
.
sort
)
?
(
c
=
Noah
::
Configuration
.
find
(:
name
=>
configname
).
first
)
:
(
raise
"Missing Parameters"
)
c
.
nil?
?
(
halt
404
)
:
(
c
.
untag!
(
data
[
'tags'
]))
c
.
to_json
end
end
# Add a watch to a configuration object
# Add a watch to a configuration object
put
'/configurations/:configname/watch'
do
|
configname
|
put
'/configurations/:configname/watch'
do
|
configname
|
...
...
lib/noah/routes/hosts.rb
View file @
71a5b6fd
...
@@ -41,6 +41,15 @@ class Noah::App
...
@@ -41,6 +41,15 @@ class Noah::App
a
.
to_json
a
.
to_json
end
end
delete
'/hosts/:hostname/tag'
do
|
hostname
|
required_params
=
[
"tags"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
raise
"Missing parameters"
if
data
.
nil?
(
data
.
keys
.
sort
==
required_params
.
sort
)
?
(
a
=
Noah
::
Host
.
find
(:
name
=>
hostname
).
first
)
:
(
raise
"Missing Parameters"
)
a
.
nil?
?
(
halt
404
)
:
(
a
.
untag!
(
data
[
'tags'
]))
a
.
to_json
end
put
'/hosts/:hostname/watch'
do
|
hostname
|
put
'/hosts/:hostname/watch'
do
|
hostname
|
required_params
=
[
"endpoint"
]
required_params
=
[
"endpoint"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
data
=
JSON
.
parse
(
request
.
body
.
read
)
...
...
lib/noah/routes/services.rb
View file @
71a5b6fd
...
@@ -46,6 +46,14 @@ class Noah::App
...
@@ -46,6 +46,14 @@ class Noah::App
a
.
to_json
a
.
to_json
end
end
delete
'/services/:servicename/:hostname/tag'
do
|
servicename
,
hostname
|
required_params
=
[
"tags"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
(
data
.
keys
.
sort
==
required_params
.
sort
)
?
(
a
=
host_service
(
hostname
,
servicename
))
:
(
raise
"Missing Parameters"
)
a
.
nil?
?
(
halt
404
)
:
(
a
.
untag!
(
data
[
'tags'
]))
a
.
to_json
end
put
'/services/:servicename/watch'
do
|
servicename
|
put
'/services/:servicename/watch'
do
|
servicename
|
required_params
=
[
"endpoint"
]
required_params
=
[
"endpoint"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
data
=
JSON
.
parse
(
request
.
body
.
read
)
...
...
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