class OmfEc::Context::GroupContext
Holds group configuration
Attributes
group[RW]
guard[RW]
operation[RW]
Public Class Methods
new(opts)
click to toggle source
# File lib/omf_ec/context/group_context.rb, line 13 def initialize(opts) self.group = opts.delete(:group) self.guard = opts self end
Public Instance Methods
[](opts = {})
click to toggle source
Supports OEDL 6 syntax [] for setting FRCP guard
@param [Hash] opts option hash which sets constraints
@example Reduce throttle to zero for all resources of type ‘engine’ from group ‘A’
group('A') do |g| g.resources[type: 'engine'].throttle = 0 end
# File lib/omf_ec/context/group_context.rb, line 29 def [](opts = {}) self.guard.merge!(opts) self end
method_missing(name, *args, &block)
click to toggle source
Calling standard methods or assignments will simply trigger sending a FRCP message
@example OEDL
# Will send FRCP CONFIGURE message g.resources[type: 'engine'].throttle = 0 # Will send FRCP REQUEST message g.resources[type: 'engine'].rpm # Will send FRCP RELEASE message g.resources[type: 'engine'].release
# File lib/omf_ec/context/group_context.rb, line 45 def method_missing(name, *args, &block) if name =~ /(.+)=/ self.operation = :configure name = $1 elsif name =~ /release/ self.operation = :release else self.operation = :request end send_message(name, *args, &block) end
send_message(name, value = nil, &block)
click to toggle source
Send FRCP message
@param [String] name of the property @param [Object] value of the property, for configuring
# File lib/omf_ec/context/group_context.rb, line 61 def send_message(name, value = nil, &block) if self.guard[:type] topic = self.group.resource_topic(self.guard[:type]) else topic = self.group.topic end if topic.nil? if self.guard[:type] warn "Group '#{self.group.name}' has NO resources of type '#{self.guard[:type]}' ready. Could not send message." else warn "Group topic '#{self.group.name}' NOT subscribed. Could not send message." end return end case self.operation when :configure topic.configure({ name => value }, { guard: self.guard, assert: OmfEc.experiment.assertion }) when :request topic.request([:uid, :hrn, name], { guard: self.guard, assert: OmfEc.experiment.assertion }) when :release topics_to_release = OmfEc.experiment.state.find_all do |res_state| all_equal(self.guard.keys) do |k| res_state[k] == self.guard[k] end end topics_to_release.each do |res_state| OmfEc.subscribe_and_monitor(res_state.uid) do |child_topic| OmfEc.subscribe_and_monitor(self.group.id) do |group_topic| group_topic.release(child_topic, { assert: OmfEc.experiment.assertion }) if child_topic end end end end end