Class: OodReservations::Reservation::Node

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/ood_reservations/reservation.rb

Overview

Object that describes a reserved node on a generic batch server FIXME: This should be generalized in some other gem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, ppn:, ppn_used:, props:, jobs:) ⇒ Node

Returns a new instance of Node.

Parameters:

  • id (#to_s)

    id of node

  • ppn (#to_i)

    number of cores

  • ppn_used (#to_i)

    number of used cores

  • props (Array<#to_sym>)

    list of properties of node

  • jobs (Array<#to_s>)

    list of jobs on node



123
124
125
126
127
128
129
# File 'lib/ood_reservations/reservation.rb', line 123

def initialize(id:, ppn:, ppn_used:, props:, jobs:)
  @id       = id.to_s
  @ppn      = ppn.to_i
  @ppn_used = ppn_used.to_i
  @props    = props.map(&:to_sym)
  @jobs     = jobs.map(&:to_s)
end

Instance Attribute Details

#idString (readonly)

The id of the node

Returns:

  • (String)

    id of node



100
101
102
# File 'lib/ood_reservations/reservation.rb', line 100

def id
  @id
end

#jobsArray<String> (readonly)

A list of jobs running on this node

Returns:

  • (Array<String>)

    list of jobs running on node



116
117
118
# File 'lib/ood_reservations/reservation.rb', line 116

def jobs
  @jobs
end

#ppnFixnum (readonly)

The number of cores on this node

Returns:

  • (Fixnum)

    number of cores



104
105
106
# File 'lib/ood_reservations/reservation.rb', line 104

def ppn
  @ppn
end

#ppn_usedFixnum (readonly)

The number of cores used on this node

Returns:

  • (Fixnum)

    number of cores used



108
109
110
# File 'lib/ood_reservations/reservation.rb', line 108

def ppn_used
  @ppn_used
end

#propsArray<Symbol> (readonly)

A list of properties describing this node

Returns:

  • (Array<Symbol>)

    list of properties



112
113
114
# File 'lib/ood_reservations/reservation.rb', line 112

def props
  @props
end

Instance Method Details

#<=>(other) ⇒ Boolean

The comparison operator for sorting values

Parameters:

  • other (#to_s)

    object to compare against

Returns:

  • (Boolean)

    how objects compare



146
147
148
# File 'lib/ood_reservations/reservation.rb', line 146

def <=>(other)
  to_s <=> other.to_s
end

#eql?(other) ⇒ Boolean

Check whether objects are identical to each other

Parameters:

  • other (#to_h)

    object to compare against

Returns:

  • (Boolean)

    whether objects are identical



153
154
155
# File 'lib/ood_reservations/reservation.rb', line 153

def eql?(other)
  self.class == other.class && self == other
end

#hashFixnum

Generate a hash value for this object

Returns:

  • (Fixnum)

    hash value of object



159
160
161
# File 'lib/ood_reservations/reservation.rb', line 159

def hash
  [self.class, to_s].hash
end

#is_free?Boolean

Is this node free to be used?

Returns:

  • (Boolean)

    free to use?



133
134
135
# File 'lib/ood_reservations/reservation.rb', line 133

def is_free?
  ppn_used == 0
end

#to_sString

Convert object to string

Returns:

  • (String)

    the string describing this object



139
140
141
# File 'lib/ood_reservations/reservation.rb', line 139

def to_s
  id
end