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.
449 450 451 452 453 |
# File 'lib/blackstack-deployer.rb', line 449 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.
456 457 458 459 460 |
# File 'lib/blackstack-deployer.rb', line 456 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.
470 471 472 473 474 |
# File 'lib/blackstack-deployer.rb', line 470 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.
477 478 479 480 481 |
# File 'lib/blackstack-deployer.rb', line 477 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
616 617 618 619 620 621 622 623 624 |
# File 'lib/blackstack-deployer.rb', line 616 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
19 20 21 |
# File 'lib/blackstack-deployer.rb', line 19 def self.logger @@logger end |
.nodes ⇒ Object
get the array of nodes assigned to the module
24 25 26 |
# File 'lib/blackstack-deployer.rb', line 24 def self.nodes @@nodes end |
.routines ⇒ Object
get the array of routines assigned to the module
29 30 31 |
# File 'lib/blackstack-deployer.rb', line 29 def self.routines @@routines end |
.run_routine(node_name, routine_name) ⇒ Object
running a routine on a node
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 523 524 |
# File 'lib/blackstack-deployer.rb', line 491 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
14 15 16 |
# File 'lib/blackstack-deployer.rb', line 14 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.
464 465 466 467 |
# File 'lib/blackstack-deployer.rb', line 464 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.
485 486 487 488 |
# File 'lib/blackstack-deployer.rb', line 485 def self.set_routines(a) @@routines.clear BlackStack::Deployer.add_routines(a) end |