Module: OmfEc

Defined in:
omf_ec/lib/omf_ec/property.rb,
omf_ec/lib/omf_ec.rb,
omf_ec/lib/omf_ec/dsl.rb,
omf_ec/lib/omf_ec/group.rb,
omf_ec/lib/omf_ec/graph.rb,
omf_ec/lib/omf_ec/runner.rb,
omf_ec/lib/omf_ec/context.rb,
omf_ec/lib/omf_ec/version.rb,
omf_ec/lib/omf_ec/parameter.rb,
omf_ec/lib/omf_ec/prototype.rb,
omf_ec/lib/omf_ec/group_ext.rb,
omf_ec/lib/omf_ec/experiment.rb,
omf_ec/lib/omf_ec/backward/dsl.rb,
omf_ec/lib/omf_ec/app_definition.rb,
omf_ec/lib/omf_ec/experiment_property.rb,
omf_ec/lib/omf_ec/backward/app_definition.rb,
omf_ec/lib/omf_ec/backward/default_events.rb

Overview

Copyright © 2012 National ICT Australia Limited (NICTA). This software may be used and distributed solely under the terms of the MIT license (License). You should find a copy of the License in LICENSE.TXT or at opensource.org/licenses/MIT. By downloading or using this software you accept the terms and the liability disclaimer in the License.

Defined Under Namespace

Modules: Backward, Context, CreatePropertiesModule, DSL, Graph, GroupExt Classes: AppDefinition, Experiment, ExperimentProperty, Group, MPReceived, Parameter, Property, Prototype, Runner

Constant Summary

VERSION =
OmfCommon.version_of('omf_ec')

Class Method Summary (collapse)

Class Method Details

+ (OmfEc::Experiment) experiment Also known as: exp

Experiment instance

Returns:



37
38
39
# File 'omf_ec/lib/omf_ec.rb', line 37

def experiment
  Experiment.instance
end

+ (Object) lib_root

Full path of lib directory



44
45
46
# File 'omf_ec/lib/omf_ec.rb', line 44

def lib_root
  File.expand_path("../..", "#{__FILE__}/lib")
end

+ (Object) register_default_callback(topic)



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'omf_ec/lib/omf_ec.rb', line 48

def register_default_callback(topic)
  topic.on_inform do |msg|
    OmfEc::MPReceived.inject(Time.now.to_f, topic.id, msg.mid) if OmfCommon::Measure.enabled?
    case msg.itype.upcase
    when 'CREATION.FAILED'
      warn "RC reports creation.failed: '#{msg[:reason]}'", msg.src
      debug msg, msg.src
    when 'ERROR'
      warn "RC reports error: '#{msg[:reason]}'", msg.src
      debug msg, msg.src
    when 'WARN'
      warn "RC reports warning: '#{msg[:reason]}'", msg.src
      debug msg, msg.src
    when 'CREATION.OK'
      debug "Resource #{msg[:res_id]} created"
      debug "Received CREATION.OK via #{topic.id}"
      debug msg, msg.src

      OmfEc.experiment.add_or_update_resource_state(msg.resource_address, msg.properties)
      OmfEc.experiment.process_events
    when 'STATUS'
      props = []
      msg.each_property { |k, v| props << "#{k}: #{v}" }
      #debug "Received INFORM via #{topic.id} >> #{props.join(", ")}", msg.src

      if msg[:status_type] == 'APP_EVENT'
        info "APP_EVENT #{msg[:event]} from app #{msg[:app]} - msg: #{msg[:msg]}"
      end

      OmfEc.experiment.add_or_update_resource_state(msg.src, msg.properties)
      #OmfEc.experiment.process_events
    end
  end
end

+ (Object) subscribe_and_monitor(topic_id, context_obj = nil, &block)

TODO: Could we find a better name for this method?



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'omf_ec/lib/omf_ec.rb', line 84

def subscribe_and_monitor(topic_id, context_obj = nil, &block)
  topic = OmfCommon::Comm::Topic[topic_id]
  if topic.nil?
    OmfCommon.comm.subscribe(topic_id, routing_key: "o.info") do |topic|
      if topic.error?
        error "Failed to subscribe #{topic_id}"
      else
        debug "Subscribed to #{topic_id}"
        context_obj.associate_topic(topic) if context_obj
        block.call(context_obj || topic) if block
        register_default_callback(topic)
      end
    end
  else
    context_obj.associate_topic(topic) if context_obj
    block.call(context_obj || topic) if block
  end
end