Module: OmfEc

Defined in:
omf_ec/lib/omf_ec/version.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/context.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/backward/group.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, DSL Classes: AppDefinition, Experiment, ExperimentProperty, Group

Constant Summary

VERSION =
"6.0.2.pre.2"

Class Method Summary (collapse)

Class Method Details

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

Experiment instance

Returns:



25
26
27
# File 'omf_ec/lib/omf_ec.rb', line 25

def experiment
  Experiment.instance
end

+ (Object) lib_root

Full path of lib directory



32
33
34
# File 'omf_ec/lib/omf_ec.rb', line 32

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

+ (Object) register_default_callback(topic)



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'omf_ec/lib/omf_ec.rb', line 36

def register_default_callback(topic)
  topic.on_inform do |msg|
    case msg.itype
    when 'CREATION.FAILED'
      warn "RC reports creation.failed: '#{msg[:reason]}'"
      debug msg
    when 'ERROR'
      warn "RC reports error: '#{msg[:reason]}'"
      debug msg
    when 'WARN'
      warn "RC reports warning: '#{msg[:reason]}'"
      debug msg
    when 'CREATION.OK'
      debug "Received CREATION.OK via #{topic.id}"
      info "Resource #{msg[:res_id]} #{msg.resource.address} created"

      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 "#{topic.id} >> inform: #{props.join(", ")}"

      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?



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'omf_ec/lib/omf_ec.rb', line 71

def subscribe_and_monitor(topic_id, context_obj = nil, &block)
  topic = OmfCommon::Comm::Topic[topic_id]
  if topic.nil?
    OmfCommon.comm.subscribe(topic_id) do |topic|
      if topic.error?
        error "Failed to subscribe #{topic_id}"
      else
        info "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