Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added bin/cucub-vm and all Servolux/CLI/Configuration stuff

  • Loading branch information...
commit 4da0fc08a5610ebb9147a430868aac32de270c51 1 parent e52c1d7
@krakatoa krakatoa authored
View
7 Gemfile
@@ -3,8 +3,13 @@ source "http://rubygems.org"
# Example:
# 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 "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.
# Include everything needed to run rake, tests, features, etc.
View
6 Gemfile.lock
@@ -41,18 +41,22 @@ GEM
rspec-expectations (2.11.3)
diff-lcs (~> 1.1.3)
rspec-mocks (2.11.3)
+ servolux (0.10.0)
simplecov (0.7.1)
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
simplecov-html (0.7.1)
+ thor (0.16.0)
PLATFORMS
ruby
DEPENDENCIES
bundler (~> 1.2.1)
- cucub-protocol!
+ cucub-protocol (= 0.0.1)!
jeweler (~> 1.8.4)
ma-zmq!
rspec
+ servolux
simplecov
+ thor
View
12 bin/cucub-vm.rb
@@ -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
View
8 examples/boot.rb
@@ -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 {})
View
26 examples/protocol.ini
@@ -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
View
7 examples/reply_channel_test.rb
@@ -0,0 +1,7 @@
+class Core
+ def state(i)
+ puts "--ack--"
+ sleep(i)
+ puts "Hola! #{i}"
+ end
+end
View
1  lib/cucub-vm.rb
@@ -2,3 +2,4 @@
require './lib/object'
require './lib/objects_hub'
+require './lib/vm'
View
32 lib/vm.rb
@@ -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
View
51 lib/vm/cli.rb
@@ -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
View
35 lib/vm/configuration.rb
@@ -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
View
28 lib/vm/servolux.rb
@@ -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')
Please sign in to comment.
Something went wrong with that request. Please try again.