Skip to content

Commit

Permalink
Added bin/cucub-vm and all Servolux/CLI/Configuration stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Alonso committed Oct 24, 2012
1 parent e52c1d7 commit 4da0fc0
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Gemfile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ source "http://rubygems.org"
# Example: # Example:
# gem "activesupport", ">= 2.3.5" # gem "activesupport", ">= 2.3.5"


group :cli do
gem "thor"
gem "servolux"
end

gem "ma-zmq", :path => "/home/krakatoa/workspace/al-nattahnam/ma-zmq" gem "ma-zmq", :path => "/home/krakatoa/workspace/al-nattahnam/ma-zmq"
gem "cucub-protocol", :path => "/home/krakatoa/workspace/al-nattahnam/cucub/protocol", :require => 'cucub-protocol' gem "cucub-protocol", '0.0.1', :path => "/home/krakatoa/workspace/al-nattahnam/cucub/protocol", :require => 'cucub-protocol'


# Add dependencies to develop your gem here. # Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc. # Include everything needed to run rake, tests, features, etc.
Expand Down
6 changes: 5 additions & 1 deletion Gemfile.lock
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,18 +41,22 @@ GEM
rspec-expectations (2.11.3) rspec-expectations (2.11.3)
diff-lcs (~> 1.1.3) diff-lcs (~> 1.1.3)
rspec-mocks (2.11.3) rspec-mocks (2.11.3)
servolux (0.10.0)
simplecov (0.7.1) simplecov (0.7.1)
multi_json (~> 1.0) multi_json (~> 1.0)
simplecov-html (~> 0.7.1) simplecov-html (~> 0.7.1)
simplecov-html (0.7.1) simplecov-html (0.7.1)
thor (0.16.0)


PLATFORMS PLATFORMS
ruby ruby


DEPENDENCIES DEPENDENCIES
bundler (~> 1.2.1) bundler (~> 1.2.1)
cucub-protocol! cucub-protocol (= 0.0.1)!
jeweler (~> 1.8.4) jeweler (~> 1.8.4)
ma-zmq! ma-zmq!
rspec rspec
servolux
simplecov simplecov
thor
12 changes: 12 additions & 0 deletions bin/cucub-vm.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env ruby

STDERR.sync = STDOUT.sync = true

require 'bundler'
Bundler.require(:default, :cli)

require File.expand_path('../../lib/cucub-vm.rb', __FILE__)
require File.expand_path('../../lib/vm/servolux.rb', __FILE__)
require File.expand_path('../../lib/vm/cli.rb', __FILE__)

Cucub::VM::CLI.start
8 changes: 8 additions & 0 deletions examples/boot.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,8 @@
# Run it on root with this command: ruby bin/cucub-vm start examples/boot.rb

require './examples/reply_channel_test'

core = Core.new
#core.oid = 1

#Cucub.start!('10.0.0.5', Proc.new {})
26 changes: 26 additions & 0 deletions examples/protocol.ini
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,26 @@
[engine]
role = receiver
default_uses = mailbox
serialize = msgpack
compression = gzip
; cp = 1425

[engine#create_vps]
from = core
respond_to = class+object
uses_board = true
serialize = none
read_by = core

[agent]
default_uses = board
role = emitter

[agent#metric]
serialize = none

[agent#adelantar_metric]
from = trigger
; respond_to = broadcast
respond_to = box
read_by = monitor
7 changes: 7 additions & 0 deletions examples/reply_channel_test.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,7 @@
class Core
def state(i)
puts "--ack--"
sleep(i)
puts "Hola! #{i}"
end
end
1 change: 1 addition & 0 deletions lib/cucub-vm.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@


require './lib/object' require './lib/object'
require './lib/objects_hub' require './lib/objects_hub'
require './lib/vm'
32 changes: 32 additions & 0 deletions lib/vm.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'singleton'
require './lib/vm/configuration'

module Cucub
class VM
include Singleton

def initialize
#@dispatcher = Cucub::Dispatcher.instance
end

def start!(vm_opts={})
@config_filepath = vm_opts[:config]
@configuration = Cucub::VM::Configuration.instance
#@address = server_opts[:host]
#@dispatcher.start
end

def shutdown!
#@dispatcher.stop
end

def config_filepath
@config_filepath
end

#def address
# @address
#end
end

end
51 changes: 51 additions & 0 deletions lib/vm/cli.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'thor'
require 'thor/actions'

# check reference
# https://github.com/carlhuda/bundler/blob/master/lib/bundler/cli.rb

module Cucub
class VM
class CLI < Thor
include Thor::Actions

#default_task :start

desc "start", "start cucub-vm"
#method_option :host, :aliases => '-h', :default => '127.0.0.1', :type => :string
method_option :config, :aliases => '-c', :default => 'config/protocol.ini', :type => :string
def start(boot_file)
opts = options.dup

# puts opts.inspect
# puts gem

# encapsular esto en una clase de Cucub::Server
# mover esto a una clase de cucub:server
logger = Logger.new($stderr)
logger.level = Logger::DEBUG

# encapsular esto en una clase de Cucub::Server
pid_file = File.expand_path('cucub-vm.pid')

# before server
#driver = Driver.instance
#core = Antir::Core.instance
#core.oid = 1
servolux = Cucub::VM::Servolux.new('Cucub-VM', :logger => logger, :pid_file => pid_file)
servolux.vm_opts = opts # opts are passed raw to the servolux. They are read by a Cucub::Server instance.

boot_file = "./#{boot_file}" unless boot_file.match(/^[\/.]/)
require boot_file

# after server

servolux.startup
end

def help(cli = nil)
puts "ping"
end
end
end
end
35 changes: 35 additions & 0 deletions lib/vm/configuration.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'singleton'

module Cucub
class VM
class Configuration
include Singleton

def initialize
@loader = Cucub::Protocol::Loader.instance
set_config_file
reload
end

def set_config_file
@loader.set_path(Cucub::VM.instance.config_filepath)
end

def reload
@specification_set = @loader.parse
$stdout.puts self.classes.inspect
@uses = nil
end

def classes
# lazy load array of classes
return @classes if @classes
#uses = []
#uses << "box" if @specification_set.uses_box
#uses << "mailbox" if @specification_set.uses_mailbox
#uses << "board" if @specification_set.uses_board
@uses = @specification_set.classes
end
end
end
end
28 changes: 28 additions & 0 deletions lib/vm/servolux.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'servolux'
require 'logger'

module Cucub
class VM
class Servolux < Servolux::Server
attr_accessor :vm_opts

def run
Cucub::VM.instance.start!(@vm_opts)
Process.waitall
end

def prefork
end

def before_stopping
Cucub::VM.instance.shutdown!
end
end
end
end

# TODO implement Servolux running as a Daemon
# daemon = Servolux::Daemon.new(:server => server)
# daemon.startup
# daemon.shutdown
#Cucub.start!('10.0.0.4')

0 comments on commit 4da0fc0

Please sign in to comment.