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



42
43
44
45
46
47
48
49
# File 'lib/workmesh.rb', line 42

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



22
23
24
# File 'lib/workmesh.rb', line 22

def workmesh_api_key
  @workmesh_api_key
end

#workmesh_portObject

Returns the value of attribute workmesh_port.



23
24
25
# File 'lib/workmesh.rb', line 23

def workmesh_port
  @workmesh_port
end

#workmesh_serviceObject

Returns the value of attribute workmesh_service.



24
25
26
# File 'lib/workmesh.rb', line 24

def workmesh_service
  @workmesh_service
end

Class Method Details

.descriptor_errors(h) ⇒ Object

add validations to the node descriptor



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/workmesh.rb', line 26

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

#to_hashObject

returh a hash descriptor of the node



51
52
53
54
55
56
57
# File 'lib/workmesh.rb', line 51

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