Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Registration of VMs done via InnerOutbound

  • Loading branch information...
commit 1fdd0cef734b23d5240fe69ff49501f38fca097d 1 parent f920868
krakatoa krakatoa authored
3  lib/cucub-server.rb
View
@@ -1,5 +1,8 @@
require 'cucub-protocol'
+require 'ostruct'
+
require_relative './server/channel'
+require_relative './stats_collector'
require_relative './dispatcher'
require_relative './server'
16 lib/server.rb
View
@@ -5,8 +5,11 @@ module Cucub
class Server
include Singleton
+ attr_reader :stats_collector
+
def initialize
@dispatcher = Cucub::Dispatcher.instance
+ @stats_collector = Cucub::StatsCollector.new
end
def start!(server_opts={})
@@ -23,6 +26,19 @@ def address
@address
end
+ def register_vm(params)
+ puts "REGISTER_VM: #{params}"
+ uid, klass = params
+
+ vm = OpenStruct.new
+ vm.uid = uid
+ vm.klass = klass.underscore
+
+ # @vm_manager.register_vm(vm)
+ @stats_collector.register_vm(vm)
+ puts "registered: #{uid} #{klass}"
+ end
+
def config_filepath
@config_filepath
end
16 lib/server/channel.rb
View
@@ -15,6 +15,8 @@ def self.reply
@reply.bind("tcp://#{Cucub::Server.instance.address}:6441")
@reply.register
+ # TODO Do this setting on Dispatcher ?
+ # TODO Decouple into a Different handler: OuterInboundRouting
@reply.on_receive { |msg|
# Chequear por llamada async / sync
@@ -79,7 +81,19 @@ def self.inner_outbound
@inner_outbound.bind "ipc:///tmp/cucub-inner-outbound.sock"
@inner_outbound.register
@inner_outbound.on_receive {|msg|
- puts "Received at Inner Outbound: #{msg}"
+ message = Cucub::Message.parse(msg)
+ puts "Received @inner_outbound@server: #{message.inspect}"
+ case message.header.to.layer
+ when :server
+ message.unlock(:inner_outbound)
+ case message.body.action
+ when "register"
+ Cucub::Server.instance.register_vm(message.body.additionals)
+ end
+ end
+
+
+ # Cucub::Server.instance.register_vm()
}
end
2  lib/server/configuration.rb
View
@@ -6,7 +6,7 @@ class Configuration
include Singleton
def initialize
- @loader = Cucub::Protocol::Loader.instance
+ @loader = Cucub::Protocol::Loader.new
set_config_file
reload
end
38 lib/stats_collector.rb
View
@@ -0,0 +1,38 @@
+module Cucub
+ class StatsCollector
+ #include Singleton
+
+ def initialize
+ @stats = { :vm_stats => {}, :server_stats => {:sent => 0} }
+ end
+
+ def register_vm(vm)
+ vm.assigned = 0
+ vm.done = 0
+ @stats[:vm_stats][vm.klass] ||= []
+ @stats[:vm_stats][vm.klass] << vm
+ end
+
+ def sent_msg_to(uid, klass)
+ vm = @stats[:vm_stats][klass].select {|v| v.uid == uid}[0]
+ vm.assigned += 1
+
+ @stats[:server_stats][:sent] += 1
+ end
+
+ def sent_messages
+ @stats[:server_stats][:sent]
+ end
+
+ def mark_done(uid, klass)
+ vm = @stats[:vm_stats][klass].select {|v| v.uid == uid}[0]
+ vm.done += 1
+ vm.assigned -= 1
+ puts "#{vm.klass} #{uid}: #{vm.assigned} assigned; #{vm.done} done"
+ end
+
+ def vm_stats
+ @stats[:vm_stats]
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.