Class: BlackStack::Workmesh::Node

Inherits:
Object
  • Object
show all
Includes:
Infrastructure::NodeModule
Defined in:
lib/workmesh.rb

Overview

stub node class stub node class is already defined in the blackstack-nodes gem: github.com/leandrosardi/blackstack-nodes we inherit from it to add some extra methods and attributes

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h, i_logger = nil) ⇒ Node

initialize the node



63
64
65
66
67
68
69
70
# File 'lib/workmesh.rb', line 63

def initialize(h, i_logger=nil)
  errors = BlackStack::Workmesh::Node.descriptor_errors(h)
  raise "The node descriptor is not valid: #{errors.uniq.join(".\n")}" if errors.length > 0
  super(h, i_logger)
  self.workmesh_api_key = h[:workmesh_api_key]
  self.workmesh_port = h[:workmesh_port]
  self.workmesh_service = h[:workmesh_service]
end

Instance Attribute Details

#workmesh_api_keyObject

array of workers belonging to this node



43
44
45
# File 'lib/workmesh.rb', line 43

def workmesh_api_key
  @workmesh_api_key
end

#workmesh_portObject

Returns the value of attribute workmesh_port.



44
45
46
# File 'lib/workmesh.rb', line 44

def workmesh_port
  @workmesh_port
end

#workmesh_serviceObject

Returns the value of attribute workmesh_service.



45
46
47
# File 'lib/workmesh.rb', line 45

def workmesh_service
  @workmesh_service
end

Class Method Details

.descriptor_errors(h) ⇒ Object

add validations to the node descriptor



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/workmesh.rb', line 47

def self.descriptor_errors(h)
  errors = BlackStack::Infrastructure::NodeModule.descriptor_errors(h)
  # validate: the key :max_workers exists and is an integer
  errors << "The key :workmesh_api_key is missing" if h[:workmesh_api_key].nil?
  errors << "The key :workmesh_api_key must be an String" unless h[:workmesh_api_key].is_a?(String)
  # validate: the key :workmesh_port exists and is an integer
  errors << "The key :workmesh_port is missing" if h[:workmesh_port].nil?
  errors << "The key :workmesh_port must be an Integer" unless h[:workmesh_port].is_a?(Integer)
  # validate: the key :workmesh_service exists and is an symbol, and its string matches with the name of one of the services in the @@services array
  errors << "The key :workmesh_service is missing" if h[:workmesh_service].nil?
  errors << "The key :workmesh_service must be an Symbol" unless h[:workmesh_service].is_a?(Symbol)
  errors << "The key :workmesh_service must be one of the following: #{BlackStack::Workmesh.services.map { |s| s.name }}" unless BlackStack::Workmesh.services.map { |s| s.name }.include?(h[:workmesh_service].to_s)
  # return list of errors
  errors.uniq
end

Instance Method Details

#deploy(l = nil) ⇒ Object

run deployment routines



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/workmesh.rb', line 80

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

  l.logs 'Updating config.rb... '
    BlackStack::Deployer::run_routine(self.name, 'workmesh-update-config')
  l.done

  l.logs 'Updating source... '
    BlackStack::Deployer::run_routine(self.name, 'workmesh-update-source')
  l.done
end

#to_hashObject

returh a hash descriptor of the node



72
73
74
75
76
77
78
# File 'lib/workmesh.rb', line 72

def to_hash()
  ret = super()
  ret[:workmesh_api_key] = self.workmesh_api_key
  ret[:workmesh_port] = self.workmesh_port
  ret[:workmesh_service] = self.workmesh_service
  ret
end