Module: BlackStack::Deployer
- Defined in:
- lib/my-ruby-deployer.rb
Overview
Deployer is a library that can be used to deploy a cluster of nodes.
Defined Under Namespace
Modules: CommandModule, DB, NodeModule, RoutineModule Classes: Command, Node, Routine
Constant Summary collapse
- @@nodes =
[]
- @@routines =
[]
Class Method Summary collapse
-
.add_node(h) ⇒ Object
add a node to the list of nodes.
-
.add_nodes(a) ⇒ Object
add an array of nodes to the list of nodes.
-
.add_routine(h) ⇒ Object
add a routine to the list of routines.
-
.add_routines(a) ⇒ Object
add an array of routines to the list of routines.
-
.deploy(routine_name = nil, l = nil) ⇒ Object
deploying all db-updates and run all routines on all nodes.
-
.nodes ⇒ Object
get the array of nodes assigned to the module.
-
.routines ⇒ Object
get the array of routines assigned to the module.
-
.run_routine(node_name, routine_name, l = nil, params = {}) ⇒ Object
running a routine on a node.
-
.set_nodes(a) ⇒ Object
remove all exisiting nodes in he list of nodes.
-
.set_routines(a) ⇒ Object
remove all exisiting routines in he list of routines.
Class Method Details
.add_node(h) ⇒ Object
add a node to the list of nodes.
283 284 285 286 287 |
# File 'lib/my-ruby-deployer.rb', line 283 def self.add_node(h) errors = BlackStack::Deployer::NodeModule.descriptor_errors(h) raise errors.join(".\n") unless errors.empty? @@nodes << BlackStack::Deployer::Node.new(h) end |
.add_nodes(a) ⇒ Object
add an array of nodes to the list of nodes.
290 291 292 293 294 |
# File 'lib/my-ruby-deployer.rb', line 290 def self.add_nodes(a) # validate: the parameter a is an array raise "The parameter a is not an array" unless a.is_a?(Array) a.each { |h| BlackStack::Deployer.add_node(h) } end |
.add_routine(h) ⇒ Object
add a routine to the list of routines.
304 305 306 307 308 |
# File 'lib/my-ruby-deployer.rb', line 304 def self.add_routine(h) errors = BlackStack::Deployer::RoutineModule.descriptor_errors(h) raise errors.join(".\n") unless errors.empty? @@routines << BlackStack::Deployer::Routine.new(h) end |
.add_routines(a) ⇒ Object
add an array of routines to the list of routines.
311 312 313 314 315 |
# File 'lib/my-ruby-deployer.rb', line 311 def self.add_routines(a) # validate: the parameter a is an array raise "The parameter a is not an array" unless a.is_a?(Array) a.each { |h| BlackStack::Deployer.add_routine(h) } end |
.deploy(routine_name = nil, l = nil) ⇒ Object
deploying all db-updates and run all routines on all nodes
495 496 497 498 499 500 501 502 503 |
# File 'lib/my-ruby-deployer.rb', line 495 def self.deploy(routine_name=nil, l=nil) l = BlackStack::DummyLogger.new(nil) if l.nil? @@nodes.each { |n| l.logs "Node #{n.name}... " n.deploy(routine_name, l) l.done } end |
.nodes ⇒ Object
get the array of nodes assigned to the module
14 15 16 |
# File 'lib/my-ruby-deployer.rb', line 14 def self.nodes @@nodes end |
.routines ⇒ Object
get the array of routines assigned to the module
19 20 21 |
# File 'lib/my-ruby-deployer.rb', line 19 def self.routines @@routines end |
.run_routine(node_name, routine_name, l = nil, params = {}) ⇒ Object
running a routine on a node
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/my-ruby-deployer.rb', line 325 def self.run_routine(node_name, routine_name, l=nil, params={}) l = BlackStack::DummyLogger.new(nil) if l.nil? errors = [] # find the node with the value node_name in the key :name n = @@nodes.select { |n| n.name == node_name }.first # find the routine with the value routine_name in the key :name r = @@routines.select { |r| r.name == routine_name }.first # validate: the node n exists errors << "Node #{node_name} not found" unless n # validate: the routine r exists errors << "Routine #{routine_name} not found" unless r # raise exception if any error has been found raise "The routine #{routine_name} cannot be run on the node #{node_name}: #{errors.uniq.join(".\n")}" if errors.length > 0 # connect the node l.logs "Connecting to node #{n.name}... " n.connect l.done # run the routine l.logs "Running routine #{r.name}... " r.run(n, l, params) l.done # disconnect the node l.logs "Disconnecting from node #{n.name}... " n.disconnect l.done end |
.set_nodes(a) ⇒ Object
remove all exisiting nodes in he list of nodes. then, add the nodes in the parameter a to the list of nodes.
298 299 300 301 |
# File 'lib/my-ruby-deployer.rb', line 298 def self.set_nodes(a) @@nodes.clear BlackStack::Deployer.add_nodes(a) end |
.set_routines(a) ⇒ Object
remove all exisiting routines in he list of routines. then, add the routines in the parameter a to the list of routines.
319 320 321 322 |
# File 'lib/my-ruby-deployer.rb', line 319 def self.set_routines(a) @@routines.clear BlackStack::Deployer.add_routines(a) end |