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
144 145 146 |
# File 'lib/dendrite/generators/synapse.rb', line 144 def bind_address Dendrite::Config.bind_to_all? ? '0.0.0.0' : '127.0.0.1' end |
#default_servers_config ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/dendrite/generators/synapse.rb', line 73 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
90 91 92 93 94 95 96 97 98 |
# File 'lib/dendrite/generators/synapse.rb', line 90 def discovery_config { discovery: { method: 'zookeeper', hosts: Dendrite::Config.zk_hosts, path: "/smartstack/services/#{organization}/#{component}/#{service.real_name}/instances" } } end |
#haproxy_config ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/dendrite/generators/synapse.rb', line 100 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
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/dendrite/generators/synapse.rb', line 121 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
68 69 70 71 |
# File 'lib/dendrite/generators/synapse.rb', line 68 def to_h discovery_config.merge(haproxy_config) .merge(default_servers_config) end |