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.



279
280
281
282
283
# File 'lib/my-ruby-deployer.rb', line 279

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)
end

.add_nodes(a) ⇒ Object

add an array of nodes to the list of nodes.



286
287
288
289
290
# File 'lib/my-ruby-deployer.rb', line 286

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.



300
301
302
303
304
# File 'lib/my-ruby-deployer.rb', line 300

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.



307
308
309
310
311
# File 'lib/my-ruby-deployer.rb', line 307

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



490
491
492
493
494
495
496
497
498
# File 'lib/my-ruby-deployer.rb', line 490

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) ⇒ Object

running a routine on a node



321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'lib/my-ruby-deployer.rb', line 321

def self.run_routine(node_name, routine_name, l=nil)
  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)
  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.



294
295
296
297
# File 'lib/my-ruby-deployer.rb', line 294

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.



315
316
317
318
# File 'lib/my-ruby-deployer.rb', line 315

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