Class: Synapse::Easy::Service
- Inherits:
-
Object
- Object
- Synapse::Easy::Service
- Includes:
- Fake::Hash
- Defined in:
- lib/synapse/easy/service.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#application ⇒ Object
Returns the value of attribute application.
-
#customer ⇒ Object
Returns the value of attribute customer.
-
#default_servers ⇒ Object
readonly
Returns the value of attribute default_servers.
-
#enable_backend ⇒ Object
Returns the value of attribute enable_backend.
-
#enable_frontend ⇒ Object
Returns the value of attribute enable_frontend.
-
#extension ⇒ Object
Returns the value of attribute extension.
-
#fall ⇒ Object
Returns the value of attribute fall.
-
#function ⇒ Object
Returns the value of attribute function.
-
#hosts ⇒ Object
Returns the value of attribute hosts.
-
#inter ⇒ Object
Returns the value of attribute inter.
-
#keep_default_servers ⇒ Object
Returns the value of attribute keep_default_servers.
-
#leader_election ⇒ Object
Returns the value of attribute leader_election.
-
#method ⇒ Object
Returns the value of attribute method.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#port ⇒ Object
Returns the value of attribute port.
-
#registry ⇒ Object
Returns the value of attribute registry.
-
#rise ⇒ Object
Returns the value of attribute rise.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #add_default_server(name, port) ⇒ Object
- #address ⇒ Object
- #aliases ⇒ Object
- #discover_via(discovery_data) ⇒ Object
- #discovery ⇒ Object
- #haproxy ⇒ Object
- #host ⇒ Object
-
#initialize(params = {}) ⇒ Service
constructor
A new instance of Service.
- #listen ⇒ Object
- #provide_at(haproxy_data) ⇒ Object
- #remove_default_server(name, port) ⇒ Object
- #server_options ⇒ Object
- #to_s(format = "%P://%h:%p") ⇒ Object (also: #s)
- #to_synapse ⇒ Object
- #to_uri ⇒ Object
- #to_url ⇒ Object (also: #url)
Constructor Details
#initialize(params = {}) ⇒ Service
Returns a new instance of Service.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/synapse/easy/service.rb', line 15 def initialize params={} @default_servers ||= [] @discovery ||= {} @haproxy ||= {} @port = params[:port] @port ||= Freeport.port @hosts = params[:hosts] @hosts ||= Resolv::Consul.services(:zookeeper).collect{|x|"#{x.address}:#{x.port}"} @mode = params[:mode] @mode ||= :tcp @uri = params[:uri] @uri ||= "/" @inter = params[:inter] @inter ||= 2000 @rise = params[:rise] @rise ||= 2 @fall = params[:fall] @fall ||= 3 @method ||= "zookeeper" @registry = params[:registry] @registry ||= "nerve" @customer = params[:customer] @customer ||= "global" @application = params[:application] @application ||= "generic" @function = params[:function] @function ||= "common" @extension = params[:extension] @extension ||= "services" @path = params[:path] @path ||= Pathname.new("/#{@registry}").join(@customer.to_s,@application.to_s,@function.to_s,@extension.to_s).to_s @name = params[:name] @name ||= [@customer,@application,@function].join("_") @active ||= false @enable_frontend = params[:enable_frontend] @enable_frontend ||= true if @enable_frontend.nil? end |
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active.
10 11 12 |
# File 'lib/synapse/easy/service.rb', line 10 def active @active end |
#application ⇒ Object
Returns the value of attribute application.
10 11 12 |
# File 'lib/synapse/easy/service.rb', line 10 def application @application end |
#customer ⇒ Object
Returns the value of attribute customer.
10 11 12 |
# File 'lib/synapse/easy/service.rb', line 10 def customer @customer end |
#default_servers ⇒ Object (readonly)
Returns the value of attribute default_servers.
14 15 16 |
# File 'lib/synapse/easy/service.rb', line 14 def default_servers @default_servers end |
#enable_backend ⇒ Object
Returns the value of attribute enable_backend.
10 11 12 |
# File 'lib/synapse/easy/service.rb', line 10 def enable_backend @enable_backend end |
#enable_frontend ⇒ Object
Returns the value of attribute enable_frontend.
10 11 12 |
# File 'lib/synapse/easy/service.rb', line 10 def enable_frontend @enable_frontend end |
#extension ⇒ Object
Returns the value of attribute extension.
10 11 12 |
# File 'lib/synapse/easy/service.rb', line 10 def extension @extension end |
#fall ⇒ Object
Returns the value of attribute fall.
10 11 12 |
# File 'lib/synapse/easy/service.rb', line 10 def fall @fall end |
#function ⇒ Object
Returns the value of attribute function.
10 11 12 |
# File 'lib/synapse/easy/service.rb', line 10 def function @function end |
#hosts ⇒ Object
Returns the value of attribute hosts.
10 11 12 |
# File 'lib/synapse/easy/service.rb', line 10 def hosts @hosts end |
#inter ⇒ Object
Returns the value of attribute inter.
10 11 12 |
# File 'lib/synapse/easy/service.rb', line 10 def inter @inter end |
#keep_default_servers ⇒ Object
Returns the value of attribute keep_default_servers.
10 11 12 |
# File 'lib/synapse/easy/service.rb', line 10 def keep_default_servers @keep_default_servers end |
#leader_election ⇒ Object
Returns the value of attribute leader_election.
10 11 12 |
# File 'lib/synapse/easy/service.rb', line 10 def leader_election @leader_election end |
#method ⇒ Object
Returns the value of attribute method.
10 11 12 |
# File 'lib/synapse/easy/service.rb', line 10 def method @method end |
#mode ⇒ Object
Returns the value of attribute mode.
10 11 12 |
# File 'lib/synapse/easy/service.rb', line 10 def mode @mode end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/synapse/easy/service.rb', line 10 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
10 11 12 |
# File 'lib/synapse/easy/service.rb', line 10 def path @path end |
#port ⇒ Object
Returns the value of attribute port.
10 11 12 |
# File 'lib/synapse/easy/service.rb', line 10 def port @port end |
#registry ⇒ Object
Returns the value of attribute registry.
10 11 12 |
# File 'lib/synapse/easy/service.rb', line 10 def registry @registry end |
#rise ⇒ Object
Returns the value of attribute rise.
10 11 12 |
# File 'lib/synapse/easy/service.rb', line 10 def rise @rise end |
#uri ⇒ Object
Returns the value of attribute uri.
10 11 12 |
# File 'lib/synapse/easy/service.rb', line 10 def uri @uri end |
Instance Method Details
#add_default_server(name, port) ⇒ Object
52 53 54 |
# File 'lib/synapse/easy/service.rb', line 52 def add_default_server name, port @default_servers << "#{name}:#{port}" end |
#address ⇒ Object
104 105 106 |
# File 'lib/synapse/easy/service.rb', line 104 def address Resolv::DNS.new.getaddress(host.to_s).to_s end |
#aliases ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/synapse/easy/service.rb', line 67 def aliases [ @application, [@application,@function].join("_"), [@customer,@application].join("_"), ] end |
#discover_via(discovery_data) ⇒ Object
58 59 60 |
# File 'lib/synapse/easy/service.rb', line 58 def discover_via discovery_data @discovery = discovery_data end |
#discovery ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/synapse/easy/service.rb', line 74 def discovery { method: method, path: path, hosts: hosts, }.with_indifferent_access end |
#haproxy ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/synapse/easy/service.rb', line 81 def haproxy result = {}.with_indifferent_access result[:port] = port if enable_frontend result[:listen] = listen result[:server_options] = result end |
#host ⇒ Object
64 65 66 |
# File 'lib/synapse/easy/service.rb', line 64 def host "localhost" end |
#listen ⇒ Object
91 92 93 94 95 96 |
# File 'lib/synapse/easy/service.rb', line 91 def listen [ "mode #{mode}", ( "option httpchk GET #{uri}" if uri and mode.to_s == "http" ) ].compact end |
#provide_at(haproxy_data) ⇒ Object
61 62 63 |
# File 'lib/synapse/easy/service.rb', line 61 def provide_at haproxy_data @haproxy = haproxy_data end |
#remove_default_server(name, port) ⇒ Object
55 56 57 |
# File 'lib/synapse/easy/service.rb', line 55 def remove_default_server name, port @default_servers.delete "#{name}:#{port}" end |
#server_options ⇒ Object
88 89 90 |
# File 'lib/synapse/easy/service.rb', line 88 def "check inter #{inter} rise #{rise} fall #{fall}" if [inter,rise,fall].compact.size == 3 end |
#to_s(format = "%P://%h:%p") ⇒ Object Also known as: s
107 108 109 110 111 112 |
# File 'lib/synapse/easy/service.rb', line 107 def to_s format="%P://%h:%p" format = format.gsub('%P',mode.to_s) format = format.gsub('%h',host.to_s) format = format.gsub('%i',address.to_s) format.gsub('%p',port.to_s) end |
#to_synapse ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/synapse/easy/service.rb', line 97 def to_synapse return application => { default_servers:default_servers, discovery: discovery, haproxy: haproxy } end |
#to_uri ⇒ Object
119 120 121 |
# File 'lib/synapse/easy/service.rb', line 119 def to_uri URI to_s() end |
#to_url ⇒ Object Also known as: url
114 115 116 117 |
# File 'lib/synapse/easy/service.rb', line 114 def to_url return unless mode.to_sym == :http to_s() end |