Class: Dendrite::Generators::Synapse
- Defined in:
- lib/dendrite/generators/synapse.rb
Defined Under Namespace
Classes: ServiceConfig
Instance Attribute Summary collapse
-
#read_only ⇒ Object
readonly
Returns the value of attribute read_only.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(graph:, service_names:, environment: :dev) ⇒ Synapse
constructor
A new instance of Synapse.
- #to_h ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(graph:, service_names:, environment: :dev) ⇒ Synapse
Returns a new instance of Synapse.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dendrite/generators/synapse.rb', line 5 def initialize(graph:, service_names:, environment: :dev) super(graph: graph, service_names: service_names) dep = [] read_only = {} @services.each do |service| service.dependencies.each do |_, dependency| dep << dependency.service if read_only.keys.include?(dependency.service.name) if read_only[dependency.service.name] != dependency.read_only raise "Trying to add r/o and r/w for same service" end else read_only[dependency.service.name] = dependency.read_only end end end @read_only = read_only @services = dep.uniq @services.group_by { |service| service.loadbalancer_port }.each do |port, services| if services.length > 1 raise PortCollision, "Port collission between #{services.collect(&:name).join(',')}" end end @services = @services.collect { |service| ServiceConfig.new(service, environment)} end |
Instance Attribute Details
#read_only ⇒ Object (readonly)
Returns the value of attribute read_only.
4 5 6 |
# File 'lib/dendrite/generators/synapse.rb', line 4 def read_only @read_only end |
Instance Method Details
#to_h ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/dendrite/generators/synapse.rb', line 32 def to_h service_list = services.inject({}) do |hash, service| if read_only[service.name] data = service.to_h discovery_data = data[:discovery].merge({ path: "/smartstack/services/#{service.organization}/#{service.component}/#{service.service.real_name}_readonly/instances" }) data[:discovery] = discovery_data hash[service.name] = data else hash[service.name] = service.to_h end hash end { haproxy: Dendrite::Config.global_haproxy_config, file_output: { output_directory: '/tmp/synapse.config' } }.merge({services: service_list}) end |