Class: OodAppkit::Cluster

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title:, validators: {}, servers: {}, hpc_cluster: true) ⇒ Cluster

Returns a new instance of Cluster.

Parameters:

  • title (String)

    title of cluster

  • validators (Hash) (defaults to: {})

    hash of validations that describe the validators

  • servers (Hash) (defaults to: {})

    hash of servers with corresponding server info

  • hpc_cluster (Boolean) (defaults to: true)

    whether this is an hpc-style 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

Parameters:

  • method_name

    the method name called

  • arguments

    the arguments to the call

  • block

    an optional block for the call



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

#serversHash<Server> (readonly)

Hash of servers this cluster supports

Returns:

  • (Hash<Server>)

    hash of servers



19
20
21
# File 'lib/ood_appkit/cluster.rb', line 19

def servers
  @servers
end

#titleString (readonly)

Title of the cluster

Returns:

  • (String)

    title of cluster



11
12
13
# File 'lib/ood_appkit/cluster.rb', line 11

def title
  @title
end

#validatorsHash<#valid?> (readonly)

Hash of validators this cluster validates against

Returns:

  • (Hash<#valid?>)

    hash of validators



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

Parameters:

  • file (String) (defaults to: File.expand_path('../../../config/clusters.yml', __FILE__))

    yaml file with cluster configurations

  • force (Boolean) (defaults to: false)

    whether we force invalid clusters to be included as well

Returns:

  • (Hash<Cluster>)

    list of clusters user has access to



25
26
27
28
29
30
# File 'lib/ood_appkit/cluster.rb', line 25

def self.all(file: File.expand_path('../../../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)

Returns:

  • (Boolean)

    whether this an hpc-style cluster



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?

Parameters:

  • method_name

    the method name to check

Returns:

  • (Boolean)


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

Examples:

Whether I have access to this cluster

my_cluster.valid?
#=> true

Returns:

  • (Boolean)

    whether user has access to this cluster



59
60
61
# File 'lib/ood_appkit/cluster.rb', line 59

def valid?
  !@validators.any? {|name, validator| !validator.valid?}
end