Class: Dendrite::ServiceNode
- Inherits:
-
Object
- Object
- Dendrite::ServiceNode
- Includes:
- ActiveModel::Validations, Validator
- Defined in:
- lib/dendrite/service_node.rb
Defined Under Namespace
Classes: DefaultServer, Dependency, Deploy, Port, Scale, Telemetry
Constant Summary collapse
- VALID_EMAIL_REGEX =
/\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
Instance Attribute Summary collapse
-
#component ⇒ Object
readonly
Returns the value of attribute component.
-
#default_servers ⇒ Object
readonly
Returns the value of attribute default_servers.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#deploy ⇒ Object
readonly
Returns the value of attribute deploy.
-
#lead_email ⇒ Object
readonly
Returns the value of attribute lead_email.
-
#organization ⇒ Object
readonly
Returns the value of attribute organization.
-
#ports ⇒ Object
readonly
Returns the value of attribute ports.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
-
#team_email ⇒ Object
readonly
Returns the value of attribute team_email.
-
#telemetry ⇒ Object
readonly
Returns the value of attribute telemetry.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #add_dependency(service:, latency:) ⇒ Object
-
#initialize(**args) ⇒ ServiceNode
constructor
A new instance of ServiceNode.
- #loadbalancer_port ⇒ Object
- #name ⇒ Object
- #real_name ⇒ Object
- #service_port ⇒ Object
- #to_h ⇒ Object
Methods included from Validator
Constructor Details
#initialize(**args) ⇒ ServiceNode
Returns a new instance of ServiceNode.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/dendrite/service_node.rb', line 125 def initialize(**args) @ports = {} @default_servers = {} args.each do |k,v| case k when :ports v.each do |name, port| @ports[name] = Port.new(name, port) end when :deploy @deploy = Deploy.new(v[:repository], v[:package]) if v != nil when :scale @scale = Scale.new(v[:max_instance_count], v[:min_instance_count]) if v != nil when :telemetry @telemetry = Telemetry.new(v[:health_url], v[:notification_email]) if v != nil when :default_servers v.each do |node| @default_servers[node[:environment]] ||= [] @default_servers[node[:environment]] << DefaultServer.new(node[:environment], node[:host], node[:port]) end else instance_variable_set("@#{k}", v) end end @dependencies = {} end |
Instance Attribute Details
#component ⇒ Object (readonly)
Returns the value of attribute component.
109 110 111 |
# File 'lib/dendrite/service_node.rb', line 109 def component @component end |
#default_servers ⇒ Object (readonly)
Returns the value of attribute default_servers.
109 110 111 |
# File 'lib/dendrite/service_node.rb', line 109 def default_servers @default_servers end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
109 110 111 |
# File 'lib/dendrite/service_node.rb', line 109 def dependencies @dependencies end |
#deploy ⇒ Object (readonly)
Returns the value of attribute deploy.
109 110 111 |
# File 'lib/dendrite/service_node.rb', line 109 def deploy @deploy end |
#lead_email ⇒ Object (readonly)
Returns the value of attribute lead_email.
109 110 111 |
# File 'lib/dendrite/service_node.rb', line 109 def lead_email @lead_email end |
#organization ⇒ Object (readonly)
Returns the value of attribute organization.
109 110 111 |
# File 'lib/dendrite/service_node.rb', line 109 def organization @organization end |
#ports ⇒ Object (readonly)
Returns the value of attribute ports.
109 110 111 |
# File 'lib/dendrite/service_node.rb', line 109 def ports @ports end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
109 110 111 |
# File 'lib/dendrite/service_node.rb', line 109 def scale @scale end |
#team_email ⇒ Object (readonly)
Returns the value of attribute team_email.
109 110 111 |
# File 'lib/dendrite/service_node.rb', line 109 def team_email @team_email end |
#telemetry ⇒ Object (readonly)
Returns the value of attribute telemetry.
109 110 111 |
# File 'lib/dendrite/service_node.rb', line 109 def telemetry @telemetry end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
109 110 111 |
# File 'lib/dendrite/service_node.rb', line 109 def type @type end |
Instance Method Details
#add_dependency(service:, latency:) ⇒ Object
168 169 170 |
# File 'lib/dendrite/service_node.rb', line 168 def add_dependency(service:, latency:) @dependencies[service.name] = Dependency.new(service, latency) end |
#loadbalancer_port ⇒ Object
164 165 166 |
# File 'lib/dendrite/service_node.rb', line 164 def loadbalancer_port ports[:loadbalancer_port].port if ports[:loadbalancer_port] end |
#name ⇒ Object
156 157 158 |
# File 'lib/dendrite/service_node.rb', line 156 def name "#{organization}_#{component}_#{@name}" if @name end |
#real_name ⇒ Object
152 153 154 |
# File 'lib/dendrite/service_node.rb', line 152 def real_name @name end |
#service_port ⇒ Object
160 161 162 |
# File 'lib/dendrite/service_node.rb', line 160 def service_port ports[:service_port].port if ports[:service_port] end |
#to_h ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/dendrite/service_node.rb', line 172 def to_h data = { organization: organization, component: component, name: real_name, complete_name: name, lead_email: lead_email, team_email: team_email, type: type, ports: ports.values.collect(&:to_h), dependencies: dependencies.keys } data.merge!({deploy: deploy ? deploy.to_h : {}}) data.merge!({scale: scale ? scale.to_h : {}}) data.merge!({telemetry: telemetry ? telemetry.to_h : {}}) data.merge!({default_servers: default_servers.values.flatten.collect(&:to_h)}) end |