Module: BlackStack::Deployer
- Defined in:
- lib/blackstack-deployer.rb
Overview
Deployer is a library that can be used to deploy a cluster of nodes.
Defined Under Namespace
Modules: CommandModule, DB, MatchModule, NoMatchModule, NodeModule, RoutineModule Classes: Command, Match, NoMatch, Node, Routine
Constant Summary collapse
- @@logger =
BlackStack::BaseLogger.new(nil)
- @@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 ⇒ Object
deploying all db-updates and run all routines on all nodes.
-
.logger ⇒ Object
get the logger assigned to the module.
-
.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) ⇒ Object
running a routine on a node.
-
.set_logger(i_logger) ⇒ Object
set the logger.
-
.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.
447 448 449 450 451 |
# File 'lib/blackstack-deployer.rb', line 447 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, @@logger) end |
.add_nodes(a) ⇒ Object
add an array of nodes to the list of nodes.
454 455 456 457 458 |
# File 'lib/blackstack-deployer.rb', line 454 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.
468 469 470 471 472 |
# File 'lib/blackstack-deployer.rb', line 468 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.
475 476 477 478 479 |
# File 'lib/blackstack-deployer.rb', line 475 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 ⇒ Object
deploying all db-updates and run all routines on all nodes
658 659 660 661 662 663 664 665 666 |
# File 'lib/blackstack-deployer.rb', line 658 def self.deploy() tlogger = BlackStack::Deployer::logger @@nodes.each { |n| tlogger.logs "Node #{n.name}... " n.deploy() tlogger.done } end |
.logger ⇒ Object
get the logger assigned to the module
17 18 19 |
# File 'lib/blackstack-deployer.rb', line 17 def self.logger @@logger end |
.nodes ⇒ Object
get the array of nodes assigned to the module
22 23 24 |
# File 'lib/blackstack-deployer.rb', line 22 def self.nodes @@nodes end |
.routines ⇒ Object
get the array of routines assigned to the module
27 28 29 |
# File 'lib/blackstack-deployer.rb', line 27 def self.routines @@routines end |
.run_routine(node_name, routine_name) ⇒ Object
running a routine on a node
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 |
# File 'lib/blackstack-deployer.rb', line 489 def self.run_routine(node_name, routine_name) 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 self.logger.logs "Connecting to node #{n.name}... " n.connect self.logger.done # run the routine self.logger.logs "Running routine #{r.name}... " r.run(n) self.logger.done # disconnect the node self.logger.logs "Disconnecting from node #{n.name}... " n.disconnect self.logger.done end |
.set_logger(i_logger) ⇒ Object
set the logger
12 13 14 |
# File 'lib/blackstack-deployer.rb', line 12 def self.set_logger(i_logger) @@logger = i_logger 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.
462 463 464 465 |
# File 'lib/blackstack-deployer.rb', line 462 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.
483 484 485 486 |
# File 'lib/blackstack-deployer.rb', line 483 def self.set_routines(a) @@routines.clear BlackStack::Deployer.add_routines(a) end |