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- 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.
-
#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:) ⇒ 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
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/dendrite/service_node.rb', line 130 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], 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 :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.
114 115 116 |
# File 'lib/dendrite/service_node.rb', line 114 def component @component end |
#default_servers ⇒ Object (readonly)
Returns the value of attribute default_servers.
114 115 116 |
# File 'lib/dendrite/service_node.rb', line 114 def default_servers @default_servers end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
114 115 116 |
# File 'lib/dendrite/service_node.rb', line 114 def dependencies @dependencies end |
#deploy ⇒ Object (readonly)
Returns the value of attribute deploy.
114 115 116 |
# File 'lib/dendrite/service_node.rb', line 114 def deploy @deploy end |
#lead_email ⇒ Object (readonly)
Returns the value of attribute lead_email.
114 115 116 |
# File 'lib/dendrite/service_node.rb', line 114 def lead_email @lead_email end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
114 115 116 |
# File 'lib/dendrite/service_node.rb', line 114 def end |
#organization ⇒ Object (readonly)
Returns the value of attribute organization.
114 115 116 |
# File 'lib/dendrite/service_node.rb', line 114 def organization @organization end |
#ports ⇒ Object (readonly)
Returns the value of attribute ports.
114 115 116 |
# File 'lib/dendrite/service_node.rb', line 114 def ports @ports end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
114 115 116 |
# File 'lib/dendrite/service_node.rb', line 114 def scale @scale end |
#team_email ⇒ Object (readonly)
Returns the value of attribute team_email.
114 115 116 |
# File 'lib/dendrite/service_node.rb', line 114 def team_email @team_email end |
#telemetry ⇒ Object (readonly)
Returns the value of attribute telemetry.
114 115 116 |
# File 'lib/dendrite/service_node.rb', line 114 def telemetry @telemetry end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
114 115 116 |
# File 'lib/dendrite/service_node.rb', line 114 def type @type end |
#users ⇒ Object (readonly)
Returns the value of attribute users.
114 115 116 |
# File 'lib/dendrite/service_node.rb', line 114 def users @users end |
Instance Method Details
#add_dependency(service:, latency:, identifier:) ⇒ Object
177 178 179 |
# File 'lib/dendrite/service_node.rb', line 177 def add_dependency(service:, latency:, identifier:) @dependencies[service.name] = Dependency.new(service, latency, identifier) end |
#loadbalancer_port ⇒ Object
173 174 175 |
# File 'lib/dendrite/service_node.rb', line 173 def loadbalancer_port ports[:loadbalancer_port].port if ports[:loadbalancer_port] end |
#name ⇒ Object
165 166 167 |
# File 'lib/dendrite/service_node.rb', line 165 def name "#{organization}_#{component}_#{@name}" if @name end |
#real_name ⇒ Object
161 162 163 |
# File 'lib/dendrite/service_node.rb', line 161 def real_name @name end |
#service_port ⇒ Object
169 170 171 |
# File 'lib/dendrite/service_node.rb', line 169 def service_port ports[:service_port].port if ports[:service_port] end |
#to_h ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/dendrite/service_node.rb', line 181 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 |