Class: OodAppkit::Cluster
- Inherits:
-
Object
- Object
- OodAppkit::Cluster
- Defined in:
- lib/ood_appkit/cluster.rb
Overview
An object that describes a given cluster of nodes used by an HPC center
Constant Summary collapse
- VERSION =
YAML configuration version
:v1
Instance Attribute Summary collapse
-
#servers ⇒ Hash<Server>
readonly
Hash of servers this cluster supports.
-
#title ⇒ String
readonly
Title of the cluster.
-
#validators ⇒ Hash<#valid?>
readonly
Hash of validators this cluster validates against.
Class Method Summary collapse
-
.all(file: File.expand_path('../../../config/clusters.yml', __FILE__), force: false) ⇒ Hash<Cluster>
A list of accessible clusters for the currently running user.
Instance Method Summary collapse
-
#hpc_cluster? ⇒ Boolean
Whether this is an hpc-style cluster (i.e., meant for heavy computation).
-
#initialize(title:, validators: {}, servers: {}, hpc_cluster: true) ⇒ Cluster
constructor
A new instance of Cluster.
-
#method_missing(method_name, *arguments, &block) ⇒ Object
Grab object from @servers hash or check if it exists.
-
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Check if method ends with custom *_server or *_server?.
-
#valid? ⇒ Boolean
Whether this is a valid cluster.
Constructor Details
#initialize(title:, validators: {}, servers: {}, hpc_cluster: true) ⇒ Cluster
Returns a new instance of Cluster.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ood_appkit/cluster.rb', line 36 def initialize(title:, validators: {}, servers: {}, hpc_cluster: true) # Set title of cluster @title = title # Generate hash of validations @validators = validators.each_with_object({}) do |(k, v), h| h[k] = v[:type].constantize.new(v) end # Generate hash of servers @servers = servers.each_with_object({}) do |(k, v), h| h[k] = v[:type].constantize.new(v) end # Is this an hpc-style cluster? @hpc_cluster = hpc_cluster end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
Grab object from @servers hash or check if it exists
73 74 75 76 77 78 79 80 81 |
# File 'lib/ood_appkit/cluster.rb', line 73 def method_missing(method_name, *arguments, &block) if /^(.+)_server$/ =~ method_name.to_s @servers.fetch($1.to_sym, nil) elsif /^(.+)_server\?$/ =~ method_name.to_s @servers.has_key? $1.to_sym else super end end |
Instance Attribute Details
#servers ⇒ Hash<Server> (readonly)
Hash of servers this cluster supports
19 20 21 |
# File 'lib/ood_appkit/cluster.rb', line 19 def servers @servers end |
#title ⇒ String (readonly)
Title of the cluster
11 12 13 |
# File 'lib/ood_appkit/cluster.rb', line 11 def title @title end |
#validators ⇒ Hash<#valid?> (readonly)
Hash of validators this cluster validates against
15 16 17 |
# File 'lib/ood_appkit/cluster.rb', line 15 def validators @validators end |
Class Method Details
.all(file: File.expand_path('../../../config/clusters.yml', __FILE__), force: false) ⇒ Hash<Cluster>
A list of accessible clusters for the currently running user
25 26 27 28 29 30 |
# File 'lib/ood_appkit/cluster.rb', line 25 def self.all(file: File.('../../../config/clusters.yml', __FILE__), force: false) parse_config(file).each_with_object({}) do |(k, v), h| c = Cluster.new v h[k] = c if c.valid? || force end end |
Instance Method Details
#hpc_cluster? ⇒ Boolean
Whether this is an hpc-style cluster (i.e., meant for heavy computation)
65 66 67 |
# File 'lib/ood_appkit/cluster.rb', line 65 def hpc_cluster? @hpc_cluster end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Check if method ends with custom *_server or *_server?
86 87 88 |
# File 'lib/ood_appkit/cluster.rb', line 86 def respond_to_missing?(method_name, include_private = false) method_name.to_s.end_with?('_server', '_server?') || super end |
#valid? ⇒ Boolean
Whether this is a valid cluster
59 60 61 |
# File 'lib/ood_appkit/cluster.rb', line 59 def valid? !@validators.any? {|name, validator| !validator.valid?} end |