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
-
#id ⇒ Symbol
readonly
Unique ID of the cluster.
-
#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.
-
.parse_config(file) ⇒ Object
Parse the config file.
Instance Method Summary collapse
-
#hpc_cluster? ⇒ Boolean
Whether this is an hpc-style cluster (i.e., meant for heavy computation).
-
#initialize(id:, 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(id:, title:, validators: {}, servers: {}, hpc_cluster: true) ⇒ Cluster
Returns a new instance of Cluster.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ood_appkit/cluster.rb', line 41 def initialize(id:, title:, validators: {}, servers: {}, hpc_cluster: true) # Set id & title of cluster @id = id @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
79 80 81 82 83 84 85 86 87 |
# File 'lib/ood_appkit/cluster.rb', line 79 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
#id ⇒ Symbol (readonly)
Unique ID of the cluster
11 12 13 |
# File 'lib/ood_appkit/cluster.rb', line 11 def id @id end |
#servers ⇒ Hash<Server> (readonly)
Hash of servers this cluster supports
23 24 25 |
# File 'lib/ood_appkit/cluster.rb', line 23 def servers @servers end |
#title ⇒ String (readonly)
Title of the cluster
15 16 17 |
# File 'lib/ood_appkit/cluster.rb', line 15 def title @title end |
#validators ⇒ Hash<#valid?> (readonly)
Hash of validators this cluster validates against
19 20 21 |
# File 'lib/ood_appkit/cluster.rb', line 19 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
29 30 31 32 33 34 |
# File 'lib/ood_appkit/cluster.rb', line 29 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.merge(id: k) h[k] = c if c.valid? || force end end |
.parse_config(file) ⇒ Object
Parse the config file
98 99 100 |
# File 'lib/ood_appkit/cluster.rb', line 98 def self.parse_config(file) YAML.load(File.read(file)).deep_symbolize_keys.fetch(VERSION, {}) end |
Instance Method Details
#hpc_cluster? ⇒ Boolean
Whether this is an hpc-style cluster (i.e., meant for heavy computation)
71 72 73 |
# File 'lib/ood_appkit/cluster.rb', line 71 def hpc_cluster? @hpc_cluster end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Check if method ends with custom *_server or *_server?
92 93 94 |
# File 'lib/ood_appkit/cluster.rb', line 92 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
65 66 67 |
# File 'lib/ood_appkit/cluster.rb', line 65 def valid? !@validators.any? {|name, validator| !validator.valid?} end |