Module: BlackStack::Deployer

Defined in:
lib/my-ruby-deployer.rb

Overview

Deployer is a library that can be used to deploy a cluster of nodes.

Defined Under Namespace

Modules: CommandModule, DB, NodeModule, RoutineModule Classes: Command, Node, Routine

Constant Summary collapse

@@nodes =
[]
@@routines =
[]

Class Method Summary collapse

Class Method Details

.add_node(h) ⇒ Object

add a node to the list of nodes.



338
339
340
341
342
# File 'lib/my-ruby-deployer.rb', line 338

def self.add_node(h)
  errors = BlackStack::Deployer::NodeModule.descriptor_errors(h)
  raise errors.join(".\n") unless errors.empty?
  @@nodes <<  Deployer::Node.new(h)
end

.add_nodes(a) ⇒ Object

add an array of nodes to the list of nodes.



345
346
347
348
349
# File 'lib/my-ruby-deployer.rb', line 345

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.



359
360
361
362
363
# File 'lib/my-ruby-deployer.rb', line 359

def self.add_routine(h)
  errors = BlackStack::Deployer::RoutineModule.descriptor_errors(h)
  raise errors.join(".\n") unless errors.empty?
  @@routines <<  Deployer::Routine.new(h)
end

.add_routines(a) ⇒ Object

add an array of routines to the list of routines.



366
367
368
369
370
# File 'lib/my-ruby-deployer.rb', line 366

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(routine_name = nil, l = nil) ⇒ Object

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



550
551
552
553
554
555
556
557
558
# File 'lib/my-ruby-deployer.rb', line 550

def self.deploy(routine_name=nil, l=nil)
  l = BlackStack::DummyLogger.new(nil) if l.nil?

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

.nodesObject

get the array of nodes assigned to the module



14
15
16
# File 'lib/my-ruby-deployer.rb', line 14

def self.nodes
  @@nodes
end

.routinesObject

get the array of routines assigned to the module



19
20
21
# File 'lib/my-ruby-deployer.rb', line 19

def self.routines
  @@routines
end

.run_routine(node_name, routine_name, l = nil, params = {}) ⇒ Object

running a routine on a node



380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'lib/my-ruby-deployer.rb', line 380

def self.run_routine(node_name, routine_name, l=nil, params={})
  l = BlackStack::DummyLogger.new(nil) if l.nil?
  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
  l.logs "Connecting to node #{n.name}... "
  n.connect
  l.done

  # run the routine
  l.logs "Running routine #{r.name}... "
  r.run(n, l, params)
  l.done

  # disconnect the node
  l.logs "Disconnecting from node #{n.name}... "
  n.disconnect
  l.done        
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.



353
354
355
356
# File 'lib/my-ruby-deployer.rb', line 353

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.



374
375
376
377
# File 'lib/my-ruby-deployer.rb', line 374

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