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, DomainName, Port, Scale, Telemetry
Constant Summary collapse
- VALID_EMAIL_REGEX =
/\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i- Metadata =
OpenStruct
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.
-
#domain_names ⇒ Object
readonly
Returns the value of attribute domain_names.
-
#lead_email ⇒ Object
readonly
Returns the value of attribute lead_email.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#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.
-
#users ⇒ Object
readonly
Returns the value of attribute users.
Instance Method Summary collapse
- #add_dependency(service:, latency:, identifier:, read_only: false) ⇒ 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.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/dendrite/service_node.rb', line 146 def initialize(**args) @ports = {} @default_servers = {} @domain_names = {} 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], v[:min_memory], v[:min_cpu]) 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 when :domain_names v.each do |dns| @domain_names[dns[:environment]] ||= [] @domain_names[dns[:environment]] << DomainName.new(dns[:environment], dns[:domain_name]) end when :metadata @metadata = Metadata.new(v) when :users @users = v.keys else instance_variable_set("@#{k}", v) end end @dependencies = {} end |
Instance Attribute Details
#component ⇒ Object (readonly)
Returns the value of attribute component.
130 131 132 |
# File 'lib/dendrite/service_node.rb', line 130 def component @component end |
#default_servers ⇒ Object (readonly)
Returns the value of attribute default_servers.
130 131 132 |
# File 'lib/dendrite/service_node.rb', line 130 def default_servers @default_servers end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
130 131 132 |
# File 'lib/dendrite/service_node.rb', line 130 def dependencies @dependencies end |
#deploy ⇒ Object (readonly)
Returns the value of attribute deploy.
130 131 132 |
# File 'lib/dendrite/service_node.rb', line 130 def deploy @deploy end |
#domain_names ⇒ Object (readonly)
Returns the value of attribute domain_names.
130 131 132 |
# File 'lib/dendrite/service_node.rb', line 130 def domain_names @domain_names end |
#lead_email ⇒ Object (readonly)
Returns the value of attribute lead_email.
130 131 132 |
# File 'lib/dendrite/service_node.rb', line 130 def lead_email @lead_email end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
130 131 132 |
# File 'lib/dendrite/service_node.rb', line 130 def @metadata end |
#organization ⇒ Object (readonly)
Returns the value of attribute organization.
130 131 132 |
# File 'lib/dendrite/service_node.rb', line 130 def organization @organization end |
#ports ⇒ Object (readonly)
Returns the value of attribute ports.
130 131 132 |
# File 'lib/dendrite/service_node.rb', line 130 def ports @ports end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
130 131 132 |
# File 'lib/dendrite/service_node.rb', line 130 def scale @scale end |
#team_email ⇒ Object (readonly)
Returns the value of attribute team_email.
130 131 132 |
# File 'lib/dendrite/service_node.rb', line 130 def team_email @team_email end |
#telemetry ⇒ Object (readonly)
Returns the value of attribute telemetry.
130 131 132 |
# File 'lib/dendrite/service_node.rb', line 130 def telemetry @telemetry end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
130 131 132 |
# File 'lib/dendrite/service_node.rb', line 130 def type @type end |
#users ⇒ Object (readonly)
Returns the value of attribute users.
130 131 132 |
# File 'lib/dendrite/service_node.rb', line 130 def users @users end |
Instance Method Details
#add_dependency(service:, latency:, identifier:, read_only: false) ⇒ Object
199 200 201 |
# File 'lib/dendrite/service_node.rb', line 199 def add_dependency(service:, latency:, identifier:, read_only: false) @dependencies[service.name] = Dependency.new(service, latency, identifier, read_only == true) end |
#loadbalancer_port ⇒ Object
195 196 197 |
# File 'lib/dendrite/service_node.rb', line 195 def loadbalancer_port ports[:loadbalancer_port].port if ports[:loadbalancer_port] end |
#name ⇒ Object
187 188 189 |
# File 'lib/dendrite/service_node.rb', line 187 def name "#{organization}_#{component}_#{@name}" if @name end |
#real_name ⇒ Object
183 184 185 |
# File 'lib/dendrite/service_node.rb', line 183 def real_name @name end |
#service_port ⇒ Object
191 192 193 |
# File 'lib/dendrite/service_node.rb', line 191 def service_port ports[:service_port].port if ports[:service_port] end |
#to_h ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/dendrite/service_node.rb', line 203 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 |