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.



552
553
554
555
556
# File 'lib/blackstack-deployer.rb', line 552

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.



559
560
561
562
563
# File 'lib/blackstack-deployer.rb', line 559

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.



573
574
575
576
577
# File 'lib/blackstack-deployer.rb', line 573

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.



580
581
582
583
584
# File 'lib/blackstack-deployer.rb', line 580

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



763
764
765
766
767
768
769
770
771
# File 'lib/blackstack-deployer.rb', line 763

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



594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
# File 'lib/blackstack-deployer.rb', line 594

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
#puts 'a'
  # connect the node
  #self.logger.logs "Connecting to node #{n.name}... "
  n.connect
  #self.logger.done
#puts 'b'
  # run the routine
  #self.logger.logs "Running routine #{r.name}... "
  r.run(n)
  #self.logger.done
#puts 'c' 
  # 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.



567
568
569
570
# File 'lib/blackstack-deployer.rb', line 567

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.



588
589
590
591
# File 'lib/blackstack-deployer.rb', line 588

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