Class: Dendrite::ServiceGraph

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
ActiveModel::Validations
Defined in:
lib/dendrite/service_graph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeServiceGraph

Returns a new instance of ServiceGraph.



14
15
16
# File 'lib/dendrite/service_graph.rb', line 14

def initialize
  @services = {}
end

Instance Attribute Details

#servicesObject (readonly)

Returns the value of attribute services.



6
7
8
# File 'lib/dendrite/service_graph.rb', line 6

def services
  @services
end

Instance Method Details

#<<(service) ⇒ Object

Raises:

  • (KeyError)


18
19
20
21
22
# File 'lib/dendrite/service_graph.rb', line 18

def <<(service)
  raise KeyError unless service.name
  raise DuplicateService, service.name if services.keys.include?(service.name)
  services[service.name] = service
end

#[](name) ⇒ Object



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

def [](name)
  services.fetch(name)
end

#collisionsObject



28
29
30
31
32
33
34
35
# File 'lib/dendrite/service_graph.rb', line 28

def collisions
  services.values.group_by(&:loadbalancer_port)
                 .reject {|port, svc| port == nil}
                 .select {|port, svc| svc.length > 1}
                 .each do |port, svc|
    errors.add("port_collisions_#{port}", "collision between #{svc.collect(&:name).join(',')}")
  end
end

#validate_nodesObject



37
38
39
40
41
# File 'lib/dendrite/service_graph.rb', line 37

def validate_nodes
  services.each do |name, service|
    errors.add(name, service.errors.messages) unless service.valid?
  end
end