Class: OmfEc::Context::AppContext
- Inherits:
-
Object
- Object
- OmfEc::Context::AppContext
- Defined in:
- lib/omf_ec/context/app_context.rb
Overview
Holds application configuration
Constant Summary collapse
- @@context_count =
Keep track of contexts for each app, i.e. multiple contexts can share the same app def. This happens for example when a group can have the same applications added to it many times, but with different parameter values for each. Thus we need to distinguish these different context
Hash.new
Instance Attribute Summary collapse
-
#app_def ⇒ Object
Returns the value of attribute app_def.
-
#name ⇒ Object
Returns the value of attribute name.
-
#oml_collections ⇒ Object
Returns the value of attribute oml_collections.
-
#param_values ⇒ Object
Returns the value of attribute param_values.
-
#proto_props ⇒ Object
Returns the value of attribute proto_props.
Instance Method Summary collapse
- #bindProperty(prop_name, prop_ref = prop_name) ⇒ Object
-
#initialize(name, location = nil, group) ⇒ AppContext
constructor
A new instance of AppContext.
-
#measure(mp, opts, &block) ⇒ Object
For now this follows v5.4 syntax…
- #mp_table_names ⇒ Object
- #properties ⇒ Object
- #setProperty(key, property_value) ⇒ Object
Constructor Details
#initialize(name, location = nil, group) ⇒ AppContext
Returns a new instance of AppContext.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/omf_ec/context/app_context.rb', line 17 def initialize(name, location = nil, group) load_oedl(location) unless location.nil? if OmfEc.experiment.app_definitions.key?(name) self.app_def = OmfEc.experiment.app_definitions[name] self.param_values = Hash.new self.oml_collections = Array.new @@context_count[name] = 0 unless @@context_count.key?(name) id = @@context_count[name] @@context_count[name] += 1 self.name = "#{name}_cxt_#{id}" @group = group self else raise RuntimeError, "Cannot create context for unknown application '#{name}'" end end |
Instance Attribute Details
#app_def ⇒ Object
Returns the value of attribute app_def.
9 10 11 |
# File 'lib/omf_ec/context/app_context.rb', line 9 def app_def @app_def end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/omf_ec/context/app_context.rb', line 9 def name @name end |
#oml_collections ⇒ Object
Returns the value of attribute oml_collections.
9 10 11 |
# File 'lib/omf_ec/context/app_context.rb', line 9 def oml_collections @oml_collections end |
#param_values ⇒ Object
Returns the value of attribute param_values.
9 10 11 |
# File 'lib/omf_ec/context/app_context.rb', line 9 def param_values @param_values end |
#proto_props ⇒ Object
Returns the value of attribute proto_props.
9 10 11 |
# File 'lib/omf_ec/context/app_context.rb', line 9 def proto_props @proto_props end |
Instance Method Details
#bindProperty(prop_name, prop_ref = prop_name) ⇒ Object
60 61 62 63 |
# File 'lib/omf_ec/context/app_context.rb', line 60 def bindProperty(prop_name, prop_ref = prop_name) @proto_props ||= Hashie::Mash.new @proto_props[prop_name] = prop_ref end |
#measure(mp, opts, &block) ⇒ Object
For now this follows v5.4 syntax… We have not yet finalised an OML syntax inside OEDL for v6 TODO: v6 currently does not support OML filters. Formerly in v5.x, these filters were defined in an optional block.
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/omf_ec/context/app_context.rb', line 69 def measure(mp, opts, &block) collect_point = opts.delete(:collect) collect_point ||= OmfEc.experiment.oml_uri if collect_point.nil? warn "No OML URI configured for measurement collection! "+ "(see option 'oml_uri'). Disabling OML Collection for '#{mp}'." return end stream = { :mp => mp , :filters => [] }.merge(opts) index = @oml_collections.find_index { |c| c[:url] == collect_point } @oml_collections << {:url => collect_point, :streams => [stream] } if index.nil? @oml_collections[index][:streams] << stream unless index.nil? end |
#mp_table_names ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/omf_ec/context/app_context.rb', line 106 def mp_table_names {}.tap do |m_t_n| @oml_collections.map { |v| v[:streams] }.flatten.each do |s| mp = s[:mp].to_s m_t_n[mp] = "#{self.app_def.name}_#{mp}" end end end |
#properties ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/omf_ec/context/app_context.rb', line 83 def properties # deep copy the properties from the app definition original = Marshal.load(Marshal.dump(app_def.properties)) # now build the properties for this context # - use the properties from app definition as the base # - if this context's param_values has a property which also exists in # the app def and if that property has an assigned value, then # use that value for the properties of this context p = original.merge({type: 'application', state: 'created'}) @param_values.each do |k,v| if p[:parameters].key?(k) p[:parameters][k][:value] = v.kind_of?(OmfEc::ExperimentProperty) ? v.value : v end end if @oml_collections.size > 0 p[:use_oml] = true p[:oml][:id] = @name p[:oml][:experiment] = OmfEc.experiment.id p[:oml][:collection] = @oml_collections end p end |
#setProperty(key, property_value) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/omf_ec/context/app_context.rb', line 34 def setProperty(key, property_value) app_def_param = app_def.properties.parameters raise OEDLUnknownProperty.new(key, "Unknown parameter '#{key}' for application "+ "definition '#{app_def.name}'") if app_def_param.nil? || !app_def_param.key?(key) if property_value.kind_of?(OmfEc::ExperimentProperty) @param_values[key] = property_value.value # if this app parameter has its dynamic attribute set to true, then # we register a callback block to the ExperimentProperty, which will # be called each time the property changes its value if app_def_param[key][:dynamic] info "Binding dynamic parameter '#{key}' to the property '#{property_value.name}'" property_value.on_change do |new_value| info "Updating dynamic app parameter '#{key}' with value: '#{new_value}'" OmfEc.subscribe_and_monitor(@group.resource_group(:application)) do |topic| p = properties p[:parameters][key.to_sym][:value] = property_value.value topic.configure(p, { guard: { hrn: @name} } ) end end end else @param_values[key] = property_value end self end |