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.



542
543
544
545
546
# File 'lib/blackstack-deployer.rb', line 542

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.



549
550
551
552
553
# File 'lib/blackstack-deployer.rb', line 549

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.



563
564
565
566
567
# File 'lib/blackstack-deployer.rb', line 563

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.



570
571
572
573
574
# File 'lib/blackstack-deployer.rb', line 570

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



753
754
755
756
757
758
759
760
761
# File 'lib/blackstack-deployer.rb', line 753

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



584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
# File 'lib/blackstack-deployer.rb', line 584

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.



557
558
559
560
# File 'lib/blackstack-deployer.rb', line 557

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.



578
579
580
581
# File 'lib/blackstack-deployer.rb', line 578

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