Class: Dendrite::Generators::Nerve

Inherits:
Base
  • Object
show all
Defined in:
lib/dendrite/generators/nerve.rb

Defined Under Namespace

Classes: ServiceConfig

Constant Summary collapse

DEFAULT_PORT =

We use this for batch jobs so they can register

1111

Instance Attribute Summary

Attributes inherited from Base

#graph, #services

Instance Method Summary collapse

Methods inherited from Base

#to_json, #to_yaml

Constructor Details

#initialize(graph:, service_names:) ⇒ Nerve

Returns a new instance of Nerve.



7
8
9
10
# File 'lib/dendrite/generators/nerve.rb', line 7

def initialize(graph:, service_names:)
  super
  @services = @services.collect { |service| ServiceConfig.new(service)}
end

Instance Method Details

#to_hObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dendrite/generators/nerve.rb', line 12

def to_h
  service_list = services.inject({}) do |hash, service|
    if service.read_write
      hash[service.name] = service.to_h
      hash["#{service.name}_readonly"] = service.to_h.merge({
        zk_path: "/smartstack/services/#{service.organization}/#{service.component}/#{service.service.real_name}_readonly/instances"
      })
    elsif service.read_only
      hash["#{service.name}_readonly"] = service.to_h.merge({
        zk_path: "/smartstack/services/#{service.organization}/#{service.component}/#{service.service.real_name}_readonly/instances"
      })
    else
      hash[service.name] = service.to_h
    end

    hash
  end

  {
    instance_id: Dendrite::Config.instance
  }.merge({services: service_list})
end