Class: Dendrite::Generators::Synapse::ServiceConfig
- Inherits:
-
Struct
- Object
- Struct
- Dendrite::Generators::Synapse::ServiceConfig
- Extended by:
- Forwardable
- Defined in:
- lib/dendrite/generators/synapse.rb
Instance Method Summary collapse
- #bind_address ⇒ Object
- #default_servers_config ⇒ Object
- #discovery_config ⇒ Object
- #haproxy_config ⇒ Object
- #mode ⇒ Object
- #to_h ⇒ Object
Instance Method Details
#bind_address ⇒ Object
125 126 127 |
# File 'lib/dendrite/generators/synapse.rb', line 125 def bind_address Dendrite::Config.bind_to_all? ? '0.0.0.0' : '127.0.0.1' end |
#default_servers_config ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/dendrite/generators/synapse.rb', line 54 def default_servers_config servers = default_servers[environment] if servers { default_servers: servers.enum_for(:each_with_index).collect do |server, i| data = server.to_h.merge({ name: "default_#{name}_#{i}" }) data.delete(:environment) data end } else {} end end |
#discovery_config ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/dendrite/generators/synapse.rb', line 71 def discovery_config { discovery: { method: 'zookeeper', hosts: Dendrite::Config.zk_hosts, path: "/smartstack/services/#{organization}/#{component}/#{service.real_name}/instances" } } end |
#haproxy_config ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/dendrite/generators/synapse.rb', line 81 def haproxy_config data = { haproxy: { port: service.loadbalancer_port, bind_address: bind_address, server_options: Dendrite::Config., listen: mode, cookie_value_method: 'hash', backend_order: ( && .sticky_session) || Dendrite::Config.sticky ? 'asc' : nil } } if domain_names[environment] && domain_names[environment].length > 0 data[:haproxy][:shared_frontend] = [ "acl is_#{name} hdr_dom(host) " + domain_names[environment].collect {|dns| " -i #{dns.domain_name} "}.join , "use_backend #{name} if is_#{name}" ] end return data end |
#mode ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/dendrite/generators/synapse.rb', line 102 def mode if Dendrite::Config.http_types.include?(service.type) arr = ['mode http', 'option httplog'] key = && .sticky_session ? .sticky_session : Dendrite::Config. peer = Dendrite::Config.peer ? " peers #{Dendrite::Config.peer}": '' if Dendrite::Config.sticky if !( && .sticky_session) arr << "cookie #{key} insert nocache" end end if Dendrite::Config.sticky && && .sticky_session arr << "stick-table type string len 200 size 500m expire 30m#{peer}" arr << "stick store-response res.cook(#{key})" arr << "stick match req.cook(#{key})" end arr else ['mode tcp', 'option tcplog'] end end |
#to_h ⇒ Object
49 50 51 52 |
# File 'lib/dendrite/generators/synapse.rb', line 49 def to_h discovery_config.merge(haproxy_config) .merge(default_servers_config) end |