Class: WiseOMF::Client::ReservationManager

Inherits:
Object
  • Object
show all
Defined in:
lib/wise_omf/client.rb

Overview

The reservation manager handles the creation and storage of node groups and stores all relevant information for the current experiment. The manager is designed as factory, so that it only exists once in the experiment. If you need to talk to a single node, call the ResverationManager.groupForNode(nodeUrn) method. If you want a custom subset of nodes, call the ReservationManager.groupForNodes(nodeUrnArray) method. For talking to all nodes, you can get the approprita group bei calling ReservationManager.allNodesGroup.

Class Method Summary collapse

Class Method Details

.allNodesGroupWiseOMF::Client::WiseGroup

Returns a group to work with when interacting with all nodes of the reservation

Returns:



248
249
250
251
252
253
254
255
# File 'lib/wise_omf/client.rb', line 248

def self.allNodesGroup
  groupId = WiseOMFUtils::UIDHelper.node_group_uid(@@reservation, @@nodeUrns)
  if @@nodeGroups[groupId].nil?
    @@nodeGroups[groupId] = WiseOMF::Client::WiseGroup.new('AllNodes', groupId)
    @@nodeGroups[groupId].init_callback
  end
  @@nodeGroups[groupId]
end

.createGroupForNodes(nodeUrns, name = nil, &block) ⇒ Object

Method for creating a group for an arbitrary subset of nodes

Parameters:

  • nodeUrns (Array, Set)

    a set of node urns to create a group for. Important: the set must be a real subset of all nodes in the reservation.

  • name (String) (defaults to: nil)

    the groups name

  • &block

    a block to perform after the creation was finished



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/wise_omf/client.rb', line 206

def self.createGroupForNodes(nodeUrns, name = nil, &block)
  groupId = WiseOMFUtils::UIDHelper.node_group_uid(@@reservation, nodeUrns)
  if @@nodeGroups[groupId].nil?
    if name.nil?
      group = WiseOMF::Client::WiseGroup.new(nodeUrns.to_s, groupId)
    else
      group = WiseOMF::Client::WiseGroup.new(name, groupId)
    end
    @@nodeGroups[groupId] = group
    info 'Creating new group'
    group.init_callback {
      info 'Topic initialized'
      group.group.topic.on_message(:wait_for_membership) { |msg|
        info "Wait for Membership: #{msg.to_yaml}"
        if msg.properties.membership && msg.properties.membership.include?(group.group.address)
          info 'New group setup finished'
          group.group.topic.unsubscribe(:wait_for_membership)
          block.call(group) if block
        end

      }
      @@reservationGroup.group.topic.create(:wisebed_node, {uid: groupId, urns: nodeUrns, membership: group.group.address})
    }

  else
    block.call(@@nodeGroups[groupId]) if block
  end
end

.doneObject

Finalizes all node groups and the reservation group. Call this method at the end of your experiment just before calling OmfEc::Experiment.done



280
281
282
283
284
# File 'lib/wise_omf/client.rb', line 280

def self.done
  info 'Cleaning Reservation Resources'
  @@nodeGroups.each_value { |group| group.done }
  @@reservationGroup.done
end

.groupForNode(nodeUrn) ⇒ Object

Returns a WiseGroup to talk to. This group should be used for interacting with single nodes.

@return the group for a single resource

Parameters:

  • nodeUrn (String)

    the node urn



262
263
264
265
266
267
268
269
# File 'lib/wise_omf/client.rb', line 262

def self.groupForNode(nodeUrn)
  groupId = WiseOMFUtils::UIDHelper.node_group_uid(@@reservation, [nodeUrn])
  if @@nodeGroups[groupId].nil?
    @@nodeGroups[groupId] = WiseOMF::Client::WiseGroup.new(nodeUrn, groupId)
    @@nodeGroups[groupId].init_callback
  end
  @@nodeGroups[groupId]
end

.groupForNodes(nodeUrns) ⇒ WiseOMF::Client::WiseGroup

Returns a group to use when interacting with an arbitrary subset of the all nodes set

Parameters:

  • nodeUrns (Array, Set, #read)

    a list of nodes to get the group for.

Returns:



240
241
242
243
# File 'lib/wise_omf/client.rb', line 240

def self.groupForNodes(nodeUrns)
  groupId = WiseOMFUtils::UIDHelper.node_group_uid(@@reservation, nodeUrns)
  @@nodeGroups[groupId]
end

.init(reservation, nodeUrns) ⇒ Object

Initializes the reservation manager class and creates the following WiseGroups:

- The allNodesGroup (containing all nodes of this reservation)
- One node group for each single node
- One group for the reservation itself

Parameters:

  • reservation (Hash)

    a hash explaining by the following YAML example:


    :secretReservationKeys:

    - :nodeUrnPrefix: "urn:wisebed:uzl1:"
      :key: "7601BE4781736B57BC6185D1AAF33A9F"
    - :nodeUrnPrefix: "..."
      :key: "..."
    
  • nodeUrns (Set, Array)

    a set of node urns beeing part of this reservation.



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/wise_omf/client.rb', line 176

def self.init(reservation, nodeUrns)
  @@nodeGroups = {}
  @@reservation = reservation
  @@nodeUrns = nodeUrns
  @@reservationGroup = WiseOMF::Client::WiseGroup.new('ReservationGroup', self.reservationID)
  @@reservationGroup.init_callback
  # Creating the all nodes group:
  self.allNodesGroup

  # Creating the single node groups:
  @@nodeUrns.each { |node|
    self.groupForNode(node)
  }

end

.reservationGroupObject

Getter for the reservation group

@return the group



195
196
197
# File 'lib/wise_omf/client.rb', line 195

def self.reservationGroup
  @@reservationGroup
end

.reservationIDObject

Getter for the reservation id of the current reservation

@return the reservation id for this reservation



274
275
276
# File 'lib/wise_omf/client.rb', line 274

def self.reservationID
  WiseOMFUtils::UIDHelper.reservation_uid(@@reservation)
end