Class: Synapse::Easy::Service
- Inherits:
-
Object
- Object
- Synapse::Easy::Service
- Includes:
- FakeHash
- 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.
-
#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
- #to_synapse ⇒ Object
Methods included from FakeHash
#[], #[]=, #has_key?, #include?
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 |
# File 'lib/synapse/easy/service.rb', line 15 def initialize params={} @default_servers ||= [] @discovery ||= {} @haproxy ||= {} @port ||= Freeport.port @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 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 |
#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
48 49 50 |
# File 'lib/synapse/easy/service.rb', line 48 def add_default_server name, port @default_servers << "#{name}:#{port}" end |
#address ⇒ Object
100 101 102 |
# File 'lib/synapse/easy/service.rb', line 100 def address Resolv::DNS.new.getaddress(host.to_s).to_s end |
#aliases ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/synapse/easy/service.rb', line 63 def aliases [ @application, [@application,@function].join("_"), [@customer,@application].join("_"), ] end |
#discover_via(discovery_data) ⇒ Object
54 55 56 |
# File 'lib/synapse/easy/service.rb', line 54 def discover_via discovery_data @discovery = discovery_data end |
#discovery ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/synapse/easy/service.rb', line 70 def discovery { method: method, path: path, hosts: hosts, }.with_indifferent_access end |
#haproxy ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/synapse/easy/service.rb', line 77 def haproxy { port: port, listen: listen, server_options: , }.with_indifferent_access end |
#host ⇒ Object
60 61 62 |
# File 'lib/synapse/easy/service.rb', line 60 def host "localhost" end |
#listen ⇒ Object
87 88 89 90 91 92 |
# File 'lib/synapse/easy/service.rb', line 87 def listen [ "mode #{mode}", ( "option httpchk #{uri}" if uri and mode.to_s == "http" ) ].compact end |
#provide_at(haproxy_data) ⇒ Object
57 58 59 |
# File 'lib/synapse/easy/service.rb', line 57 def provide_at haproxy_data @haproxy = haproxy_data end |
#remove_default_server(name, port) ⇒ Object
51 52 53 |
# File 'lib/synapse/easy/service.rb', line 51 def remove_default_server name, port @default_servers.delete "#{name}:#{port}" end |
#server_options ⇒ Object
84 85 86 |
# File 'lib/synapse/easy/service.rb', line 84 def "check inter #{inter} rise #{rise} fall #{fall}" if [inter,rise,fall].compact.size == 3 end |
#to_s(format = "%P://%h:%p") ⇒ Object
103 104 105 106 107 108 |
# File 'lib/synapse/easy/service.rb', line 103 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
93 94 95 96 97 98 99 |
# File 'lib/synapse/easy/service.rb', line 93 def to_synapse return application => { default_servers:default_servers, discovery: discovery, haproxy: haproxy } end |