lib/nuri/master.rb in nuri-0.5.1 vs lib/nuri/master.rb in nuri-0.5.2

- old
+ new

@@ -1,12 +1,11 @@ require 'thread' class Nuri::Master - include Nuri::Net::Helper + include Nuri::Helper include Nuri::Orchestrator include Nuri::Choreographer - #include Nuri::Server SfpUnknown = Sfp::Unknown.new SfpUndefined = Sfp::Undefined.new AgentSchema = '$.Node' @@ -155,13 +154,14 @@ # print the status of goal state puts "Goal state:".yellow goalgen.results.each { |k,v| next if k[0,1] == '_' - print "- #{k}: " + Sfp::Helper.sfp_to_s(v['_value']).green - print " #{Sfp::Helper.sfp_to_s(f1.results[k])}".red if f1.results.has_key?(k) and - f1.results[k] != v['_value'] + print " #{k}: " + Sfp::Helper::Sfp2Ruby.val(v['_value']).to_s.green + if f1.results.has_key?(k) and f1.results[k] != v['_value'] + print " " + Sfp::Helper::Sfp2Ruby.val(f1.results[k]).to_s.red + end puts "" } # add global constraint (if exist) task['global'] = @model['global'] if @model.has_key?('global') @@ -336,15 +336,17 @@ (not modules.has_key?(m) or modules[m] != get_local_module_hash(m).to_s) } return true if list == '' - if system("cd #{@modules_dir}; ./install_module #{address} #{port} #{list} 1>/dev/null 2>/tmp/install_module.error") - puts "Push modules #{list}to #{name} [OK]".green - else - puts "Push modules #{list}to #{name} [Failed]".red + output = JSON.parse(`cd #{@modules_dir}; ./install_module #{address} #{port} #{list}`) + if output['installed_modules'].length > 0 + puts ("Push modules: " + output['installed_modules'].join(" ") + " to agent #{name} [OK]").green end + if output['missing_modules'].length > 0 + puts ("Missing modules: " + output['missing_modules'].join(" ") + ".").red + end return true rescue Exception => e puts "[WARN] Cannot push module to #{name} - #{e}".red @@ -423,13 +425,10 @@ v['_context'] == 'class' } end def get_agents - #@model.select { |k,v| !(k[0,1] == '_' or not v.is_a?(Hash) or - # v['_context'] != 'object' or v['_classes'].index(AgentSchema).nil?) - #} Nuri::Master.agents(@model) end def self.agents(sfp) sfp.select { |k,v| !(k[0] == '_' or not v.is_a?(Hash) or @@ -582,19 +581,19 @@ vm = operator.params['$.vm'].sub(/^\$\./, '') next if !@map.has_key?(vm) # for each not-exist state VM, add an effect @map[vm].each { |k,v| - next if operator.has_key?(k) # skip if variable is exist (avoid overwrite) + next if operator.has_key?(k) # skip if variable is exist (avoid overwrite) next if k =~ /\.sfpAddress/ or k =~ /\.sfpPort/ # skip "sfpAddress" and "sfpPort" # because these will be assigned dynamically var = parser.variables[k] next if var.nil? # the variable is not found if v.is_a?(Hash) val = parser.types[v['_value']][0] if v['_context'] == 'null' - raise Exception, "Not implemented yet." # this may arise on Set values + raise Exception, "Not implemented yet." # this may arise on Set values else val = v end # add the value to variable's values @@ -604,22 +603,9 @@ # create new parameter, and then add to the operator parameter = Sfp::Parameter.new(var, nil, val) operator[var.name] = parameter } end - end - - def self.start - # TODO - fork { - while true do - sleep 5000 - end - } - end - - def self.stop - # TODO end end ### Helper classes/modules