rightscale-nanite-dev 0.4.1.17 → 0.4.1.22

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -11,10 +11,10 @@ require 'rake/clean'
11
11
  require 'lib/nanite'
12
12
 
13
13
  GEM = "rightscale-nanite-dev"
14
- AUTHOR = "Ezra Zygmuntowicz"
15
- EMAIL = "ezra@engineyard.com"
16
- HOMEPAGE = "http://github.com/ezmobius/nanite"
17
- SUMMARY = "self assembling fabric of ruby daemons"
14
+ AUTHOR = "RightScale, Inc."
15
+ EMAIL = "support@rightscale.com"
16
+ HOMEPAGE = "http://github.com/rightscale/nanite"
17
+ SUMMARY = "Self-assembling fabric of ruby daemons; fork of ezmobius/nanite."
18
18
 
19
19
  Dir.glob('tasks/*.rake').each { |r| Rake.application.add_import r }
20
20
 
@@ -73,4 +73,4 @@ task :docs => :rdoc do
73
73
  else
74
74
  sh 'firefox rdoc/index.html'
75
75
  end
76
- end
76
+ end
@@ -39,7 +39,7 @@ require 'nanite/security/static_certificate_store'
39
39
  require 'nanite/serializer'
40
40
 
41
41
  module Nanite
42
- VERSION = '0.4.1.17' unless defined?(Nanite::VERSION)
42
+ VERSION = '0.4.1.22' unless defined?(Nanite::VERSION)
43
43
 
44
44
  class MapperNotRunning < StandardError; end
45
45
 
@@ -57,15 +57,21 @@ module Nanite
57
57
  end # ClassMethods
58
58
 
59
59
  module InstanceMethods
60
- # send nanite request to another agent (through the mapper)
60
+ # Send nanite request to another agent (through the mapper)
61
61
  def request(*args, &blk)
62
62
  MapperProxy.instance.request(*args, &blk)
63
63
  end
64
64
 
65
+ # Send nanite push to another agent (through the mapper)
65
66
  def push(*args)
66
67
  MapperProxy.instance.push(*args)
67
68
  end
69
+
70
+ # Send nanite tag query to mapper
71
+ def query_tags(*args, &blk)
72
+ MapperProxy.instance.query_tags(*args, &blk)
73
+ end
68
74
  end # InstanceMethods
69
75
 
70
76
  end # Actor
71
- end # Nanite
77
+ end # Nanite
@@ -99,7 +99,7 @@ module Nanite
99
99
  Log.init(@identity, @options[:log_path])
100
100
  Log.level = @options[:log_level] if @options[:log_level]
101
101
  @serializer = Serializer.new(@options[:format])
102
- @status_proc = lambda { parse_uptime(`uptime 2> /dev/null`) rescue 'no status' }
102
+ @status_proc ||= lambda { parse_uptime(`uptime 2> /dev/null`) rescue 'no status' }
103
103
  pid_file = PidFile.new(@identity, @options)
104
104
  pid_file.check
105
105
  if @options[:daemonize]
@@ -163,15 +163,18 @@ module Nanite
163
163
  if @options[:daemonize]
164
164
  @options[:log_path] = (@options[:log_dir] || @options[:root] || Dir.pwd)
165
165
  end
166
-
166
+
167
+ @callbacks = opts[:callbacks]
168
+ @status_proc = opts[:status_proc]
169
+
170
+ # note the return statement in case of identity being known; ensure all
171
+ # needed configurations occur before the the following line.
167
172
  return @identity = "nanite-#{@options[:identity]}" if @options[:identity]
168
173
  token = Identity.generate
169
174
  @identity = "nanite-#{token}"
170
175
  File.open(File.expand_path(File.join(@options[:root], 'config.yml')), 'w') do |fd|
171
176
  fd.write(YAML.dump(custom_config.merge(:identity => token)))
172
177
  end
173
-
174
- @callbacks = options[:callbacks]
175
178
  end
176
179
 
177
180
  def load_actors
@@ -230,7 +233,7 @@ module Nanite
230
233
  receive(serializer.load(msg))
231
234
  rescue Exception => e
232
235
  Nanite::Log.error("RECV #{e.message}")
233
- callbacks[:exception].call(e, msg, self) rescue nil if callbacks[:exception]
236
+ callbacks[:exception].call(e, msg, self) rescue nil if callbacks && callbacks[:exception]
234
237
  end
235
238
  end
236
239
  end
@@ -33,7 +33,7 @@ module Nanite
33
33
  Nanite::Log.info("RECV #{reg.to_s}")
34
34
  nanites[reg.identity] = { :services => reg.services, :status => reg.status, :tags => reg.tags, :timestamp => Time.now.utc.to_i }
35
35
  reaper.register(reg.identity, agent_timeout + 1) { nanite_timed_out(reg.identity) }
36
- callbacks[:register].call(reg.identity, mapper) if callbacks[:register]
36
+ callbacks[:register].call(reg.identity, mapper) if callbacks && callbacks[:register]
37
37
  else
38
38
  Nanite::Log.warn("RECV NOT AUTHORIZED #{reg.to_s}")
39
39
  end
@@ -41,7 +41,7 @@ module Nanite
41
41
  Nanite::Log.info("RECV #{reg.to_s}")
42
42
  reaper.unregister(reg.identity)
43
43
  nanites.delete(reg.identity)
44
- callbacks[:unregister].call(reg.identity, mapper) if callbacks[:unregister]
44
+ callbacks[:unregister].call(reg.identity, mapper) if callbacks && callbacks[:unregister]
45
45
  when TagUpdate
46
46
  Nanite::Log.info("RECV #{reg.to_s}")
47
47
  nanites.update_tags(reg.identity, reg.new_tags, reg.obsolete_tags)
@@ -55,7 +55,7 @@ module Nanite
55
55
  if nanite && timed_out?(nanite)
56
56
  Nanite::Log.info("Nanite #{token} timed out")
57
57
  nanite = nanites.delete(token)
58
- callbacks[:timeout].call(token, mapper) if callbacks[:timeout]
58
+ callbacks[:timeout].call(token, mapper) if callbacks && callbacks[:timeout]
59
59
  true
60
60
  end
61
61
  end
@@ -104,7 +104,9 @@ module Nanite
104
104
  Nanite::Log.debug("RECV #{request.to_s}")
105
105
  case request
106
106
  when Push
107
- mapper.send_push(request)
107
+ if mapper.send_push(request) == false
108
+ Nanite::Log.info("RECV - No target found for #{request.to_s}")
109
+ end
108
110
  when Request
109
111
  intm_handler = lambda do |result, job|
110
112
  result = IntermediateMessage.new(request.token, job.request.from, mapper.identity, nil, result)
@@ -118,10 +120,21 @@ module Nanite
118
120
  end
119
121
 
120
122
  if ok == false
123
+ Nanite::Log.info("RECV - No target found for #{request.to_s}")
121
124
  forward_response(result, request.persistent)
122
125
  end
123
126
  when TagQuery
124
- results = nanites.nanites_for(request)
127
+ results = {}
128
+ results = nanites.nanites_for(request) if request.tags && !request.tags.empty?
129
+ if request.agent_ids && !request.agent_ids.empty?
130
+ request.agent_ids.each do |nanite_id|
131
+ if !results.include?(nanite_id)
132
+ if nanite = nanites[nanite_id]
133
+ results[nanite_id] = nanite
134
+ end
135
+ end
136
+ end
137
+ end
125
138
  result = Result.new(request.token, request.from, results, mapper.identity)
126
139
  forward_response(result, request.persistent)
127
140
  end
@@ -174,12 +187,17 @@ module Nanite
174
187
 
175
188
  # returns all nanites that provide the given service
176
189
  def nanites_providing(request, include_timed_out)
177
- nanites.nanites_for(request).delete_if do |nanite, info|
178
- if res = !include_timed_out && timed_out?(info)
179
- Nanite::Log.debug("Ignoring timed out nanite #{nanite} in target selection - last seen at #{info[:timestamp]}")
180
- end
181
- res
182
- end
190
+ # FIXME: Not filtering out results for now to alleviate issue with
191
+ # overloaded agents not pinging in a timely fashion
192
+ # Put that code back once agents behave properly
193
+ nanites.nanites_for(request)
194
+
195
+ # nanites.nanites_for(request).delete_if do |nanite, info|
196
+ # if res = !include_timed_out && timed_out?(info)
197
+ # Nanite::Log.debug("Ignoring timed out nanite #{nanite} in target selection - last seen at #{info[:timestamp]}")
198
+ # end
199
+ # res
200
+ # end
183
201
  end
184
202
 
185
203
  def setup_queues
@@ -196,7 +214,7 @@ module Nanite
196
214
  handle_ping(ping)
197
215
  rescue Exception => e
198
216
  Nanite::Log.error("RECV [ping] #{e.message}")
199
- callbacks[:exception].call(e, ping, mapper) rescue nil if callbacks[:exception]
217
+ callbacks[:exception].call(e, ping, mapper) rescue nil if callbacks && callbacks[:exception]
200
218
  end
201
219
  end
202
220
  hb_fanout = amq.fanout('heartbeat', :durable => true)
@@ -213,7 +231,7 @@ module Nanite
213
231
  register(serializer.load(msg))
214
232
  rescue Exception => e
215
233
  Nanite::Log.error("RECV [register] #{e.message}")
216
- callbacks[:exception].call(e, msg, mapper) rescue nil if callbacks[:exception]
234
+ callbacks[:exception].call(e, msg, mapper) rescue nil if callbacks && callbacks[:exception]
217
235
  end
218
236
  end
219
237
  reg_fanout = amq.fanout('registration', :durable => true)
@@ -230,7 +248,7 @@ module Nanite
230
248
  handle_request(serializer.load(msg))
231
249
  rescue Exception => e
232
250
  Nanite::Log.error("RECV [request] #{e.message}")
233
- callbacks[:exception].call(e, msg, mapper) rescue nil if callbacks[:exception]
251
+ callbacks[:exception].call(e, msg, mapper) rescue nil if callbacks && callbacks[:exception]
234
252
  end
235
253
  end
236
254
  req_fanout = amq.fanout('request', :durable => true)
@@ -299,7 +299,7 @@ module Nanite
299
299
  job_warden.process(msg)
300
300
  rescue Exception => e
301
301
  Nanite::Log.error("RECV [result] #{e.message}")
302
- callbacks[:exception].call(e, msg, mapper) rescue nil if callbacks[:exception]
302
+ callbacks[:exception].call(e, msg, mapper) rescue nil if callbacks && callbacks[:exception]
303
303
  end
304
304
  end
305
305
  end
@@ -41,6 +41,7 @@ module Nanite
41
41
  amqp.fanout('request', :no_declare => options[:secure]).publish(serializer.dump(request))
42
42
  end
43
43
 
44
+ # Send push to given agent through the mapper
44
45
  def push(type, payload = '', opts = {})
45
46
  raise "Mapper proxy not initialized" unless identity && options
46
47
  push = Push.new(type, payload, opts)
@@ -51,6 +52,17 @@ module Nanite
51
52
  amqp.fanout('request', :no_declare => options[:secure]).publish(serializer.dump(push))
52
53
  end
53
54
 
55
+ # Send tag query to mapper
56
+ def query_tags(opts, &blk)
57
+ raise "Mapper proxy not initialized" unless identity && options
58
+ tag_query = TagQuery.new(identity, opts)
59
+ tag_query.token = Identity.generate
60
+ tag_query.persistent = opts.key?(:persistent) ? opts[:persistent] : options[:persistent]
61
+ pending_requests[tag_query.token] = { :result_handler => blk }
62
+ Nanite::Log.info("SEND #{tag_query.to_s}")
63
+ amqp.fanout('request', :no_declare => options[:secure]).publish(serializer.dump(tag_query))
64
+ end
65
+
54
66
  # Update tags registered by mapper for agent
55
67
  def update_tags(new_tags, obsolete_tags)
56
68
  raise "Mapper proxy not initialized" unless identity && options
@@ -219,24 +219,35 @@ module Nanite
219
219
  #
220
220
  # Options:
221
221
  # from is sender identity
222
- # tags list of tags that each agent in the result must match
222
+ # opts Hash of options, two options are supported, at least one must be set:
223
+ # :tags is an array of tags defining a query that returned agents tags must match
224
+ # :agent_ids is an array of agents whose tags should be returned
223
225
  class TagQuery < Packet
224
226
 
225
- attr_accessor :from, :tags
227
+ attr_accessor :from, :token, :agent_ids, :tags, :persistent
226
228
 
227
- def initialize(from, tags, size=nil)
228
- @from = from
229
- @tags = tags
230
- @size = size
229
+ def initialize(from, opts, size=nil)
230
+ @from = from
231
+ @token = opts[:token]
232
+ @agent_ids = opts[:agent_ids]
233
+ @tags = opts[:tags]
234
+ @persistent = opts[:persistent]
235
+ @size = size
231
236
  end
232
237
 
233
238
  def self.json_create(o)
234
239
  i = o['data']
235
- new(i['from'], i['tags'], o['size'])
240
+ new(i['from'], { :token => i['token'], :agent_ids => i['agent_ids'],
241
+ :tags => i['tags'], :persistent => i['persistent'] },
242
+ o['size'])
236
243
  end
237
244
 
238
245
  def to_s(filter=nil)
239
- "#{super} <#{token}> #{type} from #{id_to_s(from)}, tags #{tags.inspect}"
246
+ log_msg = "#{super} <#{token}>"
247
+ log_msg += " from #{id_to_s(from)}" if filter.nil? || filter.include?(:from)
248
+ log_msg += " agent_ids #{agent_ids.inspect}"
249
+ log_msg += " tags: #{tags.inspect}"
250
+ log_msg
240
251
  end
241
252
  end
242
253
 
@@ -45,25 +45,20 @@ module Nanite
45
45
 
46
46
  # Unserialize data using certificate store
47
47
  def self.load(json)
48
- begin
49
- raise "Missing certificate store" unless @store
50
- raise "Missing certificate" unless @cert || !@encrypt
51
- raise "Missing certificate key" unless @key || !@encrypt
52
- data = JSON.load(json)
53
- sig = Signature.from_data(data['signature'])
54
- certs = @store.get_signer(data['id'])
55
- raise "Could not find a cert for signer #{data['id']}" unless certs
56
- certs = [ certs ] unless certs.respond_to?(:any?)
57
- raise "Failed to check signature for signer #{data['id']}" unless certs.any? { |c| sig.match?(c) }
58
- jsn = data['data']
59
- if jsn && @encrypt && data['encrypted']
60
- jsn = EncryptedDocument.from_data(jsn).decrypted_data(@key, @cert)
61
- end
62
- JSON.load(jsn) if jsn
63
- rescue Exception => e
64
- Nanite::Log.error("Loading of secure packet failed: #{e.message}\n#{e.backtrace.join("\n")}")
65
- raise
48
+ raise "Missing certificate store" unless @store
49
+ raise "Missing certificate" unless @cert || !@encrypt
50
+ raise "Missing certificate key" unless @key || !@encrypt
51
+ data = JSON.load(json)
52
+ sig = Signature.from_data(data['signature'])
53
+ certs = @store.get_signer(data['id'])
54
+ raise "Could not find a cert for signer #{data['id']}" unless certs
55
+ certs = [ certs ] unless certs.respond_to?(:any?)
56
+ raise "Failed to check signature for signer #{data['id']}" unless certs.any? { |c| sig.match?(c) }
57
+ jsn = data['data']
58
+ if jsn && @encrypt && data['encrypted']
59
+ jsn = EncryptedDocument.from_data(jsn).decrypted_data(@key, @cert)
66
60
  end
61
+ JSON.load(jsn) if jsn
67
62
  end
68
63
 
69
64
  end
@@ -6,7 +6,7 @@ module Nanite
6
6
  def initialize(action, packet, serializers, msg = nil)
7
7
  @action, @packet = action, packet
8
8
  msg = ":\n#{msg}" if msg && !msg.empty?
9
- super("Could not #{action} #{packet.inspect} using #{serializers.inspect}#{msg}")
9
+ super("Could not #{action} packet using #{serializers.inspect}: #{msg}")
10
10
  end
11
11
  end # SerializationError
12
12
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rightscale-nanite-dev
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1.17
4
+ version: 0.4.1.22
5
5
  platform: ruby
6
6
  authors:
7
- - Ezra Zygmuntowicz
7
+ - RightScale, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-02 00:00:00 -08:00
12
+ date: 2010-01-12 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,8 +22,8 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 0.6.0
24
24
  version:
25
- description: self assembling fabric of ruby daemons
26
- email: ezra@engineyard.com
25
+ description: Self-assembling fabric of ruby daemons; fork of ezmobius/nanite.
26
+ email: support@rightscale.com
27
27
  executables:
28
28
  - nanite-agent
29
29
  - nanite-mapper
@@ -79,7 +79,7 @@ files:
79
79
  - bin/nanite-agent
80
80
  - bin/nanite-mapper
81
81
  has_rdoc: true
82
- homepage: http://github.com/ezmobius/nanite
82
+ homepage: http://github.com/rightscale/nanite
83
83
  licenses: []
84
84
 
85
85
  post_install_message:
@@ -105,6 +105,6 @@ rubyforge_project:
105
105
  rubygems_version: 1.3.5
106
106
  signing_key:
107
107
  specification_version: 3
108
- summary: self assembling fabric of ruby daemons
108
+ summary: Self-assembling fabric of ruby daemons; fork of ezmobius/nanite.
109
109
  test_files: []
110
110