noah 0.8.2-jruby → 0.8.4-jruby

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # Noah
2
+ _"look at this effing rainbow I just made for you"_
3
+
2
4
  Noah is an application registry loosely based on [Apache ZooKeeper](http://zookeeper.apache.org)
3
5
 
4
6
  What does that mean? From the ZooKeeper Home Page:
@@ -4,6 +4,7 @@ require 'noah'
4
4
  require 'noah/agents/http_agent'
5
5
  require 'noah/agents/https_agent'
6
6
  require 'noah/agents/dummy_agent'
7
+ require 'noah/agents/rundeck_agent'
7
8
  begin
8
9
  candidates = []
9
10
  Gem.source_index.find_all {|g| candidates << g[1].name if g[1].name =~ /^noah-agents-.*/}
@@ -0,0 +1,38 @@
1
+ require File.join(File.dirname(__FILE__), 'base_agent')
2
+ require 'em-http/middleware/cookie_jar'
3
+ require 'uri'
4
+
5
+ module Noah::Agents
6
+ class RunDeckAgent < Base
7
+
8
+ PREFIX = "rundeck://"
9
+ NAME = self.class.to_s
10
+ DEFAULT_CONCURRENCY = 50
11
+
12
+ def work!(ep, message)
13
+ logger.info("Sending message to (#{ep})")
14
+ uri = URI.parse(ep)
15
+ credentials = {:j_username => uri.user, :j_password => uri.password}
16
+ EM::HttpRequest.use EM::Middleware::CookieJar
17
+ conn = EM::HttpRequest.new("http://#{uri.host}:#{uri.port}/j_security_check")
18
+ http = conn.post :body => credentials
19
+ http.callback {
20
+ logger.info("Logged in to RunDeck. Calling path")
21
+ conn2 = EM::HttpRequest.new("http://#{uri.host}:#{uri.port}#{uri.path}?#{uri.query}")
22
+ exec = conn2.get
23
+ exec.callback {
24
+ logger.info("Successfully called #{ep}")
25
+ logger.info("Response from RunDeck:")
26
+ logger.info("#{exec.response}")
27
+ }
28
+ exec.errback {
29
+ logger.error("Something went wrong with #{ep}")
30
+ }
31
+ }
32
+ http.errback {
33
+ logger.error("Something went wrong with #{ep}")
34
+ }
35
+ end
36
+
37
+ end
38
+ end
@@ -4,7 +4,7 @@ require File.join(File.dirname(__FILE__), 'models')
4
4
 
5
5
  module Noah
6
6
  class App < Sinatra::Base
7
- helpers Noah::SinatraHelpers
7
+ helpers Noah::SinatraBaseHelpers
8
8
 
9
9
  configure do
10
10
  set :app_file, __FILE__
@@ -1,137 +1,4 @@
1
- module Noah
2
- module SinatraHelpers
3
-
4
- def format_errors(model)
5
- error_messages = model.errors.present do |e|
6
- # Missing attributes
7
- e.on [:name, :not_present], "Name attribute missing"
8
- e.on [:status, :not_present], "Status attribute missing"
9
- e.on [:format, :not_present], "Format attribute missing"
10
- e.on [:body, :not_present], "Body attribute missing"
11
- e.on [:application_id, :not_present], "Application attribute missing"
12
- e.on [:path, :not_present], "Path attribute missing"
13
- e.on [:pattern, :not_present], "Pattern attribute missing"
14
- e.on [:endpoint, :not_present], "Endpoint attribute missing"
15
- # Invalid option
16
- e.on [:status, :not_member], "Status must be up, down or pending"
17
- # Duplicate keys
18
- e.on [[:name, :application_id], :not_unique], "Record already exists"
19
- e.on [[:name, :host_id], :not_unique], "Record already exists"
20
- e.on [[:endpoint, :pattern], :not_unique], "Record already exists"
21
- e.on [:path, :not_unique], "Record already exists"
22
- # Custom exceptions
23
- e.on [:pattern, :already_provided], "Pattern is already provided"
24
- e.on [:pattern, :replaces_existing], "Pattern would overwrite existing"
25
- e.on [:path, :reserved_path], "Path is reserved"
26
- end
27
- error_messages.first
28
- end
29
-
30
- def host(opts = {})
31
- Noah::Host.find(opts).first
32
- end
33
-
34
- def hosts(opts = {})
35
- Noah::Hosts.all(opts)
36
- end
37
-
38
- def service(opts = {})
39
- Noah::Service.find(options)
40
- end
41
-
42
- def services(opts = {})
43
- Noah::Services.all(opts)
44
- end
45
-
46
- def host_service(hostname, servicename)
47
- h = Noah::Host.find(:name => hostname).first
48
- if h.nil?
49
- nil
50
- else
51
- Noah::Service.find(:host_id => h.id, :name => servicename).first
52
- end
53
- end
54
-
55
- def host_services(hostname)
56
- h = Noah::Host.find(:name => hostname).first
57
- if h.nil?
58
- nil
59
- else
60
- Noah::Services.all(:host_id => id)
61
- end
62
- end
63
-
64
- def find_hosts_by_service(servicename)
65
- affected_hosts = []
66
- s = Noah::Service.find(:name => servicename)
67
- if s.nil?
68
- affected_hosts
69
- else
70
- Noah::Host.all.each {|x| affected_hosts << x if (x.services.to_a & s.to_a).length > 0}
71
- affected_hosts
72
- end
73
- end
74
-
75
- def delete_service_from_host(servicename, hostname)
76
- host = Noah::Host.find(:name => hostname).first
77
- (halt 404) if host.nil?
78
- service = Noah::Service.find(:name => servicename, :host_id => host.id).first
79
- (halt 404) if service.nil?
80
- service.delete
81
- r = {"action" => "delete", "result" => "success", "id" => service.id, "host" => host.name, "service" => servicename}
82
- r.to_json
83
- end
84
-
85
- def find_named_link(path)
86
- link = Noah::Link.find(:path => "/"+path).first
87
- if link.nil?
88
- # try finding it wihtout the slash
89
- link = Noah::Link.find(:path => path).first
90
- (halt 404) if link.nil?
91
- end
92
- return link
93
- end
94
- def add_config_to_app(appname, config_hash)
95
- begin
96
- config = Noah::Configuration.find_or_create(config_hash)
97
- if config.valid?
98
- dep_action = config.is_new? ? "create" : "update"
99
- else
100
- raise "#{format_errors(config)}"
101
- end
102
- app = Noah::Application.find_or_create(:name => appname)
103
- if app.valid?
104
- action = app.is_new? ? "create" : "update"
105
- app.configurations << config
106
- r = {"result" => "success", "id" => "#{app.id}", "name" => "#{app.name}", "action" => action, "configuration" => {"action" => dep_action, "id" => "#{config.id}", "item" => "#{config.name}"}}
107
- r.to_json
108
- else
109
- raise "#{format_errors(app)}"
110
- end
111
- rescue Exception => e
112
- e.message
113
- ensure
114
- # Clean up partial objects
115
- app.delete if app.valid? == false
116
- config.delete if config.valid? == false
117
- end
118
- end
119
-
120
- def application(opts = {})
121
- Noah::Application.find(opts).first
122
- end
123
-
124
- def applications(opts = {})
125
- Noah::Applications.all(opts)
126
- end
127
-
128
- def configuration(opts = {})
129
- Noah::Configuration.find(opts).first
130
- end
131
-
132
- def configurations(opts = {})
133
- Noah::Configurations.all(opts)
134
- end
135
- end
136
-
137
- end
1
+ require File.join(File.dirname(__FILE__), 'helpers', 'base_helpers')
2
+ require File.join(File.dirname(__FILE__), 'helpers', 'tag_helpers')
3
+ require File.join(File.dirname(__FILE__), 'helpers', 'link_helpers')
4
+ require File.join(File.dirname(__FILE__), 'helpers', 'watch_helpers')
@@ -0,0 +1,138 @@
1
+ module Noah
2
+ module SinatraBaseHelpers
3
+
4
+ def format_errors(model)
5
+ error_messages = model.errors.present do |e|
6
+ # Missing attributes
7
+ e.on [:name, :not_present], "Name attribute missing"
8
+ e.on [:status, :not_present], "Status attribute missing"
9
+ e.on [:format, :not_present], "Format attribute missing"
10
+ e.on [:body, :not_present], "Body attribute missing"
11
+ e.on [:application_id, :not_present], "Application attribute missing"
12
+ e.on [:path, :not_present], "Path attribute missing"
13
+ e.on [:pattern, :not_present], "Pattern attribute missing"
14
+ e.on [:endpoint, :not_present], "Endpoint attribute missing"
15
+ # Invalid option
16
+ e.on [:status, :not_member], "Status must be up, down or pending"
17
+ # Duplicate keys
18
+ e.on [[:name, :application_id], :not_unique], "Record already exists"
19
+ e.on [[:name, :host_id], :not_unique], "Record already exists"
20
+ e.on [[:endpoint, :pattern], :not_unique], "Record already exists"
21
+ e.on [:path, :not_unique], "Record already exists"
22
+ # Custom exceptions
23
+ e.on [:pattern, :already_provided], "Pattern is already provided"
24
+ e.on [:pattern, :replaces_existing], "Pattern would overwrite existing"
25
+ e.on [:path, :reserved_path], "Path is reserved"
26
+ end
27
+ error_messages.first
28
+ end
29
+
30
+ def host(opts = {})
31
+ Noah::Host.find(opts).first
32
+ end
33
+
34
+ def hosts(opts = {})
35
+ Noah::Hosts.all(opts)
36
+ end
37
+
38
+ def service(opts = {})
39
+ Noah::Service.find(options)
40
+ end
41
+
42
+ def services(opts = {})
43
+ Noah::Services.all(opts)
44
+ end
45
+
46
+ def host_service(hostname, servicename)
47
+ h = Noah::Host.find(:name => hostname).first
48
+ if h.nil?
49
+ nil
50
+ else
51
+ Noah::Service.find(:host_id => h.id, :name => servicename).first
52
+ end
53
+ end
54
+
55
+ def host_services(hostname)
56
+ h = Noah::Host.find(:name => hostname).first
57
+ if h.nil?
58
+ nil
59
+ else
60
+ Noah::Services.all(:host_id => id)
61
+ end
62
+ end
63
+
64
+ def find_hosts_by_service(servicename)
65
+ affected_hosts = []
66
+ s = Noah::Service.find(:name => servicename)
67
+ if s.nil?
68
+ affected_hosts
69
+ else
70
+ Noah::Host.all.each {|x| affected_hosts << x if (x.services.to_a & s.to_a).length > 0}
71
+ affected_hosts
72
+ end
73
+ end
74
+
75
+ def delete_service_from_host(servicename, hostname)
76
+ host = Noah::Host.find(:name => hostname).first
77
+ (halt 404) if host.nil?
78
+ service = Noah::Service.find(:name => servicename, :host_id => host.id).first
79
+ (halt 404) if service.nil?
80
+ service.delete
81
+ r = {"action" => "delete", "result" => "success", "id" => service.id, "host" => host.name, "service" => servicename}
82
+ r.to_json
83
+ end
84
+
85
+ def find_named_link(path)
86
+ link = Noah::Link.find(:path => "/"+path).first
87
+ if link.nil?
88
+ # try finding it wihtout the slash
89
+ link = Noah::Link.find(:path => path).first
90
+ (halt 404) if link.nil?
91
+ end
92
+ return link
93
+ end
94
+
95
+ def add_config_to_app(appname, config_hash)
96
+ begin
97
+ config = Noah::Configuration.find_or_create(config_hash)
98
+ if config.valid?
99
+ dep_action = config.is_new? ? "create" : "update"
100
+ else
101
+ raise "#{format_errors(config)}"
102
+ end
103
+ app = Noah::Application.find_or_create(:name => appname)
104
+ if app.valid?
105
+ action = app.is_new? ? "create" : "update"
106
+ app.configurations << config
107
+ r = {"result" => "success", "id" => "#{app.id}", "name" => "#{app.name}", "action" => action, "configuration" => {"action" => dep_action, "id" => "#{config.id}", "item" => "#{config.name}"}}
108
+ r.to_json
109
+ else
110
+ raise "#{format_errors(app)}"
111
+ end
112
+ rescue Exception => e
113
+ e.message
114
+ ensure
115
+ # Clean up partial objects
116
+ app.delete if app.valid? == false
117
+ config.delete if config.valid? == false
118
+ end
119
+ end
120
+
121
+ def application(opts = {})
122
+ Noah::Application.find(opts).first
123
+ end
124
+
125
+ def applications(opts = {})
126
+ Noah::Applications.all(opts)
127
+ end
128
+
129
+ def configuration(opts = {})
130
+ Noah::Configuration.find(opts).first
131
+ end
132
+
133
+ def configurations(opts = {})
134
+ Noah::Configurations.all(opts)
135
+ end
136
+ end
137
+
138
+ end
File without changes
File without changes
File without changes
@@ -30,6 +30,7 @@ module Noah
30
30
  def validate
31
31
  super
32
32
  assert_present :path
33
+ assert_unique :path
33
34
  end
34
35
 
35
36
  def to_hash
@@ -6,6 +6,15 @@ module Noah
6
6
  index :members
7
7
  index :name
8
8
 
9
+ def delete
10
+ self.members.each_value do |member_array|
11
+ member_array.each do |mem|
12
+ delete_member(mem)
13
+ end
14
+ end
15
+ super
16
+ end
17
+
9
18
  def validate
10
19
  super
11
20
  assert_present :name
@@ -29,6 +38,22 @@ module Noah
29
38
  hsh
30
39
  end
31
40
 
41
+ def delete_member(node)
42
+ nc = class_to_lower(node.class.to_s)+"s"
43
+ # Need to refactor. Essentially there are conditions we need to check for before trying to delete a member
44
+ # Are there any members at all?
45
+ # Are there any members of a given class?
46
+ # Not pretty but it works for now
47
+ if self.members.size == 0 || self.members.has_key?(nc.to_sym) == false
48
+ # no match so save and be done with it
49
+ self.save
50
+ elsif self.members[nc.to_sym].include?(node)
51
+ Ohm.redis.srem("#{self.key}:members", "#{node.key}")
52
+ node.untag!(self.name) if node.tags.include?(self)
53
+ self.save
54
+ end
55
+ end
56
+
32
57
  def to_hash
33
58
  h = {:name => name, :created_at => created_at, :updated_at => updated_at}
34
59
  h.merge!(members_to_hash)
@@ -21,6 +21,14 @@ class Noah::App
21
21
  a.to_json
22
22
  end
23
23
 
24
+ delete '/applications/:appname/tag' do |appname|
25
+ required_params = ["tags"]
26
+ data = JSON.parse(request.body.read)
27
+ (data.keys.sort == required_params.sort) ? (a=Noah::Application.find(:name=>appname).first) : (raise "Missing Parameters")
28
+ a.nil? ? (halt 404) : (a.untag!(data['tags']))
29
+ a.to_json
30
+ end
31
+
24
32
  put '/applications/:appname/watch' do |appname|
25
33
  required_params = ["endpoint"]
26
34
  data = JSON.parse(request.body.read)
@@ -38,7 +38,14 @@ class Noah::App
38
38
  (data.keys.sort == required_params.sort) ? (c=Noah::Configuration.find(:name=>configname).first) : (raise "Missing Parameters")
39
39
  c.nil? ? (halt 404) : (c.tag!(data['tags']))
40
40
  c.to_json
41
-
41
+ end
42
+ # Delete a tag[s] from a configuration object
43
+ delete '/configurations/:configname/tag' do |configname|
44
+ required_params = ["tags"]
45
+ data = JSON.parse(request.body.read)
46
+ (data.keys.sort == required_params.sort) ? (c=Noah::Configuration.find(:name=>configname).first) : (raise "Missing Parameters")
47
+ c.nil? ? (halt 404) : (c.untag!(data['tags']))
48
+ c.to_json
42
49
  end
43
50
  # Add a watch to a configuration object
44
51
  put '/configurations/:configname/watch' do |configname|
@@ -25,7 +25,7 @@ class Noah::App
25
25
  e = Noah::Ephemeral.find_or_create(opts)
26
26
  if e.valid?
27
27
  action = e.is_new? ? "create" : "update"
28
- r = {"action" => action, "result" => "success", "id" => e.id, "path" => e.path, "data" => e.data}
28
+ r = {"action" => action, "result" => "success", "id" => e.id, "path" => e.path, "data" => e.data, "created_at" => e.created_at, "updated_at" => e.updated_at}
29
29
  r.to_json
30
30
  else
31
31
  raise "#{format_errors(e)}"
@@ -41,6 +41,15 @@ class Noah::App
41
41
  a.to_json
42
42
  end
43
43
 
44
+ delete '/hosts/:hostname/tag' do |hostname|
45
+ required_params = ["tags"]
46
+ data = JSON.parse(request.body.read)
47
+ raise "Missing parameters" if data.nil?
48
+ (data.keys.sort == required_params.sort) ? (a=Noah::Host.find(:name=>hostname).first) : (raise "Missing Parameters")
49
+ a.nil? ? (halt 404) : (a.untag!(data['tags']))
50
+ a.to_json
51
+ end
52
+
44
53
  put '/hosts/:hostname/watch' do |hostname|
45
54
  required_params = ["endpoint"]
46
55
  data = JSON.parse(request.body.read)
@@ -46,6 +46,14 @@ class Noah::App
46
46
  a.to_json
47
47
  end
48
48
 
49
+ delete '/services/:servicename/:hostname/tag' do |servicename, hostname|
50
+ required_params = ["tags"]
51
+ data = JSON.parse(request.body.read)
52
+ (data.keys.sort == required_params.sort) ? (a=host_service(hostname, servicename)) : (raise "Missing Parameters")
53
+ a.nil? ? (halt 404) : (a.untag!(data['tags']))
54
+ a.to_json
55
+ end
56
+
49
57
  put '/services/:servicename/watch' do |servicename|
50
58
  required_params = ["endpoint"]
51
59
  data = JSON.parse(request.body.read)
@@ -17,9 +17,19 @@ module Noah::Taggable
17
17
  tags << my_tag
18
18
  my_tag.members = self
19
19
  end
20
+ self.save
20
21
  end
21
22
 
22
23
  def untag!(tag_name)
24
+ case tag_name.class.to_s
25
+ when "Array"
26
+ tag_name.each do |t|
27
+ remove_tag(t)
28
+ end
29
+ else
30
+ remove_tag(tag_name)
31
+ end
32
+ self.save
23
33
  end
24
34
 
25
35
  def to_hash
@@ -27,4 +37,13 @@ module Noah::Taggable
27
37
  self.tags.sort.each {|t| tag_arr << t.name} if self.tags.size != 0
28
38
  super.merge(:tags => tag_arr)
29
39
  end
40
+
41
+ protected
42
+ def remove_tag(tag_name)
43
+ my_tag = ::Noah::Tag.find(:name => tag_name).first
44
+ if self.tags.member?(my_tag)
45
+ self.tags.key.srem "#{my_tag.id}"
46
+ my_tag.delete_member(self)
47
+ end
48
+ end
30
49
  end
@@ -1,3 +1,3 @@
1
1
  module Noah
2
- VERSION = "0.8.2"
2
+ VERSION = "0.8.4"
3
3
  end
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.require_paths = ["lib"]
23
23
 
24
24
  s.add_dependency("eventmachine", ["1.0.0.beta.3"])
25
- s.add_dependency("em-http-request", ["1.0.0.beta.3"])
25
+ s.add_dependency("em-http-request", ["1.0.0.beta.4"])
26
26
  s.add_dependency("redis", ["= 2.2.0"])
27
27
  s.add_dependency("nest", ["= 1.1.0"])
28
28
  s.add_dependency("rack", ["= 1.2.2"])
@@ -0,0 +1,88 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Using the Link Model", :reset_redis => true do
4
+ before(:each) do
5
+ Ohm.redis.flushdb
6
+ @link = "/myorg"
7
+ @host = Noah::Host.create(:name => 'linked_host', :status => 'up')
8
+ @service = Noah::Service.create(:name => 'linked_service', :status => 'down', :host_id => @host.id)
9
+ @application = Noah::Application.create(:name => "linked_application")
10
+ @configuration = Noah::Configuration.create(:name => "linked_configuration", :format => "string", :body => "some_string")
11
+ @ephemeral = Noah::Ephemeral.create(:path => "/linked/ephemeral")
12
+ end
13
+ after(:each) do
14
+ Ohm.redis.flushdb
15
+ end
16
+
17
+ describe "should" do
18
+ it "create a new Noah::Link" do
19
+ l = Noah::Link.new(:path => @link)
20
+ l.valid?.should == true
21
+ l.save
22
+ l.is_new?.should == true
23
+ xl = Noah::Link.find(:path => @link).first
24
+ xl.should == l
25
+ end
26
+ it "create a new Noah::Link and add a single member" do
27
+ l = Noah::Link.create(:path => @link)
28
+ l.nodes = @host
29
+ @host.links.member?(l).should == true
30
+ @host.links.size.should == 1
31
+ l.nodes.size.should == 1
32
+ l.nodes.member?(@host.key).should == true
33
+ end
34
+
35
+ it "create a new Noah::Link and add multiple members" do
36
+ l = Noah::Link.create(:path => @link)
37
+ l.nodes = [@host, @service, @application, @configuration, @ephemeral]
38
+ l.nodes.size.should == 5
39
+ [@host, @service, @application, @configuration, @ephemeral].each do |node|
40
+ l.nodes.member?(node.key).should == true
41
+ node.links.member?(l).should == true
42
+ node.links.size.should == 1
43
+ end
44
+ end
45
+ it "link! an existing object to a single link" do
46
+ @host.link!(@link)
47
+ l = Noah::Link.find(:path => @link).first
48
+ @host.links.member?(l).should == true
49
+ @host.links.size.should == 1
50
+ l.nodes.member?(@host.key).should == true
51
+ l.nodes.size.should == 1
52
+ end
53
+ it "return a hash of all nodes" do
54
+ l = Noah::Link.create(:path => @link)
55
+ l.nodes = [@host, @service, @application, @configuration, @ephemeral]
56
+ h = l.to_hash
57
+ h[:id].should == l.id
58
+ h[:name].should == l.name
59
+ h[:updated_at].should == l.updated_at
60
+ h[:created_at].should == l.created_at
61
+ h[:hosts].has_key?(@host.name).should == true
62
+ h[:hosts][@host.name].keys.sort.should == [:id, :status, :tags, :services].sort
63
+ h[:services].has_key?(@service.name).should == true
64
+ h[:services][@service.name][@host.name].keys.sort.should == [:id, :status, :tags].sort
65
+ h[:applications].has_key?(@application.name).should == true
66
+ h[:applications][@application.name].keys.sort.should == [:id, :tags, :configurations].sort
67
+ h[:configurations].has_key?(@configuration.name).should == true
68
+ h[:configurations][@configuration.name].keys.sort.should == [:id, :tags, :format, :body].sort
69
+ h[:ephemerals].has_key?(@ephemeral.name).should == true
70
+ h[:ephemerals][@ephemeral.name].keys.sort.should == [:id, :tags, :path, :data].sort
71
+ end
72
+ end
73
+ describe "should not" do
74
+ it "create a new Noah::Link without a path" do
75
+ l = Noah::Link.create
76
+ l.valid?.should == false
77
+ l.errors.should == [[:path, :not_present]]
78
+ end
79
+ it "create a link with a duplicate name" do
80
+ l = Noah::Link.create(:path => @link)
81
+ ln = Noah::Link.create(:path => @link)
82
+ ln.valid?.should == false
83
+ ln.errors.should == [[:path, :not_unique]]
84
+ end
85
+ end
86
+ end
87
+
88
+
@@ -75,11 +75,26 @@ describe "Using the Application API", :reset_redis => false do
75
75
  Noah::Application.find(:name => @appdata[:name]).size.should == 1
76
76
  Noah::Application.find(:name => @appdata[:name]).first.is_new?.should == true
77
77
  end
78
- it "new application with new configuration should work"
78
+
79
+ it "new application with new configuration should work" do
80
+ post_json = '{"body":"awesome_string","format":"string"}'
81
+ put "/applications/my_awesome_app/configurations/my_awesome_config", post_json, "CONTENT_TYPE" => "application/json"
82
+ last_response.should be_ok
83
+ response = last_response.should return_json
84
+ response["result"].should == "success"
85
+ response["id"].nil?.should == false
86
+ response["name"].should == "my_awesome_app"
87
+ response["action"].should == "create"
88
+ response["configuration"]["action"].should == "create"
89
+ response["configuration"]["id"].nil?.should == false
90
+ response["configuration"]["item"].should == "my_awesome_config"
91
+ end
92
+
79
93
  it "new application with missing name should not work" do
80
94
  put "/applications/should_not_work", '{"foo":"bar"}', "CONTENT_TYPE" => "application/json"
81
95
  last_response.should be_invalid
82
96
  end
97
+
83
98
  it "existing application should work" do
84
99
  sleep 3
85
100
 
@@ -93,8 +108,32 @@ describe "Using the Application API", :reset_redis => false do
93
108
  Noah::Application.find(:name => @appdata[:name]).size.should == 1
94
109
  Noah::Application.find(:name => @appdata[:name]).first.is_new?.should == false
95
110
  end
96
- it "existing application with new configuration"
97
- it "existing application with existing configuration"
111
+
112
+ it "existing application with new configuration" do
113
+ post_json = '{"body":"derp","format":"string"}'
114
+ put "/applications/#{@appdata[:name]}/configurations/herp", post_json, "CONTENT_TYPE" => "application/json"
115
+ last_response.should be_ok
116
+ response = last_response.should return_json
117
+ response["result"].should == "success"
118
+ response["action"].should == "update"
119
+ response["configuration"]["action"].should == "create"
120
+ response["configuration"]["id"].nil?.should == false
121
+ response["configuration"]["item"].should == "herp"
122
+ end
123
+
124
+ it "existing application with existing configuration" do
125
+ post_json = '{"body":"derp","format":"string"}'
126
+ put "/applications/#{@appdata[:name]}/configurations/herp", post_json, "CONTENT_TYPE" => "application/json"
127
+ sleep 3
128
+ put "/applications/#{@appdata[:name]}/configurations/herp", post_json, "CONTENT_TYPE" => "application/json"
129
+ last_response.should be_ok
130
+ response = last_response.should return_json
131
+ response["result"].should == "success"
132
+ response["action"].should == "update"
133
+ response["configuration"]["action"].should == "update"
134
+ response["configuration"]["id"].nil?.should == false
135
+ response["configuration"]["item"].should == "herp"
136
+ end
98
137
  end
99
138
 
100
139
  describe "DELETE" do
@@ -60,6 +60,31 @@ describe "Using the Tag Model", :reset_redis => true do
60
60
  end
61
61
  end
62
62
  end
63
+ it "should untag! a single tag from an object" do
64
+ @application.tag! "foobarspec"
65
+ t = Noah::Tag.find(:name => 'foobarspec').first
66
+ t.nil?.should == false
67
+ @application.tags.size.should == 1
68
+ @application.tags.include?(t).should == true
69
+ t.members.size.should == 1
70
+ t.members[:applications].include?(@application).should == true
71
+ @application.untag! "foobarspec"
72
+ @application.tags.size.should == 0
73
+ t.members.size.should == 0
74
+ end
75
+ it "should untag! an array of tags from an object" do
76
+ tagz = %w{foo bar baz bang}
77
+ @application.tag! tagz
78
+ @application.tags.size.should == tagz.size
79
+ @application.untag! tagz
80
+ @application.tags.size.should == 0
81
+ tagz.each do |tag|
82
+ t = Noah::Tag.find(:name => tag).first
83
+ t.nil?.should == false
84
+ Noah::Tag.all.size.should == tagz.size
85
+ t.members.has_key?(:applications).should == false
86
+ end
87
+ end
63
88
  end
64
89
 
65
90
  describe "should not" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: noah
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.8.2
5
+ version: 0.8.4
6
6
  platform: jruby
7
7
  authors:
8
8
  - John E. Vincent
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-03 00:00:00 -04:00
13
+ date: 2011-06-08 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -32,7 +32,7 @@ dependencies:
32
32
  requirements:
33
33
  - - "="
34
34
  - !ruby/object:Gem::Version
35
- version: 1.0.0.beta.3
35
+ version: 1.0.0.beta.4
36
36
  type: :runtime
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
@@ -282,11 +282,16 @@ files:
282
282
  - lib/noah/agents/dummy_agent.rb
283
283
  - lib/noah/agents/http_agent.rb
284
284
  - lib/noah/agents/https_agent.rb
285
+ - lib/noah/agents/rundeck_agent.rb
285
286
  - lib/noah/app.rb
286
287
  - lib/noah/ark.rb
287
288
  - lib/noah/custom_watcher.rb
288
289
  - lib/noah/exceptions.rb
289
290
  - lib/noah/helpers.rb
291
+ - lib/noah/helpers/base_helpers.rb
292
+ - lib/noah/helpers/link_helpers.rb
293
+ - lib/noah/helpers/tag_helpers.rb
294
+ - lib/noah/helpers/watch_helpers.rb
290
295
  - lib/noah/linkable.rb
291
296
  - lib/noah/log.rb
292
297
  - lib/noah/models.rb
@@ -317,6 +322,7 @@ files:
317
322
  - spec/configuration_spec.rb
318
323
  - spec/ephemeral_spec.rb
319
324
  - spec/host_spec.rb
325
+ - spec/link_spec.rb
320
326
  - spec/noahapp_application_spec.rb
321
327
  - spec/noahapp_configuration_spec.rb
322
328
  - spec/noahapp_ephemeral_spec.rb
@@ -368,6 +374,7 @@ test_files:
368
374
  - spec/configuration_spec.rb
369
375
  - spec/ephemeral_spec.rb
370
376
  - spec/host_spec.rb
377
+ - spec/link_spec.rb
371
378
  - spec/noahapp_application_spec.rb
372
379
  - spec/noahapp_configuration_spec.rb
373
380
  - spec/noahapp_ephemeral_spec.rb