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)
@@show_output =
false
@@nodes =
[]
@@routines =
[]

Class Method Summary collapse

Class Method Details

.add_node(h) ⇒ Object

add a node to the list of nodes.



510
511
512
513
514
# File 'lib/blackstack-deployer.rb', line 510

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.



517
518
519
520
521
# File 'lib/blackstack-deployer.rb', line 517

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.



531
532
533
534
535
# File 'lib/blackstack-deployer.rb', line 531

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.



538
539
540
541
542
# File 'lib/blackstack-deployer.rb', line 538

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

.deployObject

deploying all db-updates and run all routines on all nodes



721
722
723
724
725
726
727
728
729
# File 'lib/blackstack-deployer.rb', line 721

def self.deploy()
  tlogger = BlackStack::Deployer::logger

  @@nodes.each { |n|
    tlogger.logs "Node #{n.name}... "
    n.deploy()
    tlogger.done
  }
end

.loggerObject

get the logger assigned to the module



28
29
30
# File 'lib/blackstack-deployer.rb', line 28

def self.logger
  @@logger
end

.nodesObject

get the array of nodes assigned to the module



33
34
35
# File 'lib/blackstack-deployer.rb', line 33

def self.nodes
  @@nodes
end

.routinesObject

get the array of routines assigned to the module



38
39
40
# File 'lib/blackstack-deployer.rb', line 38

def self.routines
  @@routines
end

.run_routine(node_name, routine_name) ⇒ Object

running a routine on a node



552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
# File 'lib/blackstack-deployer.rb', line 552

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



18
19
20
# File 'lib/blackstack-deployer.rb', line 18

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.



525
526
527
528
# File 'lib/blackstack-deployer.rb', line 525

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.



546
547
548
549
# File 'lib/blackstack-deployer.rb', line 546

def self.set_routines(a)
  @@routines.clear
  BlackStack::Deployer.add_routines(a)
end

.set_show_output(value) ⇒ Object

set show_output



13
14
15
# File 'lib/blackstack-deployer.rb', line 13

def self.set_show_output(value)
  @@show_output = value
end

.show_outputObject

get show_output



23
24
25
# File 'lib/blackstack-deployer.rb', line 23

def self.show_output
  @@show_output
end