Sha256: ab27cda6a274bd87aae250501b37ea4e0825dc22564008257c79f17633b6a705

Contents?: true

Size: 1.65 KB

Versions: 49

Compression:

Stored size: 1.65 KB

Contents

# Copyright (c) 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 http://opensource.org/licenses/MIT.
# By downloading or using this software you accept the terms and the liability disclaimer in the License.

# OMF_VERSIONS = 6.0
#

def_property('garage', 'garage', 'Name of garage')

defEvent :engine_created do |state|
  # state is an array holds list of resources, and automatically updated once OMF inform messages received.
  state.find_all do |v|
    v[:type] == 'engine' && !v[:membership].empty?
  end.size > 0
end

defEvent :rpm_reached_4000 do |state|
  state.find_all do |v|
    v[:type] == 'engine' && v[:rpm] && v[:rpm] >= 4000
  end.size >= 1
end

# Define a group and add garages to it.
defGroup('garages', prop.garage)

# :ALL_UP is a pre-defined event,
# triggered when all resources set to be part of groups are available and configured as members of the associated groups.
onEvent :ALL_UP do
  group('garages') do |g|
    g.create_resource('my_engine', type: 'engine')

    onEvent :engine_created do
      info ">>> Accelerating all engines"
      g.resources[type: 'engine'].throttle = 50

      # We periodically check engine RPM
      every 2.second do
        g.resources[type: 'engine'].rpm
      end
    end

    onEvent :rpm_reached_4000 do
      info ">>> Engine RPM reached 4000"
      info ">>> Reduce engine throttle"
      g.resources[type: 'engine'].throttle = 0
    end

    after 20.seconds do
      info ">>> Release engines"
      g.resources[type: 'engine'].release
      done!
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
omf_ec-6.2.3 example/engine_oedl.rb
omf_ec-6.2.2 example/engine_oedl.rb
omf_ec-6.2.1 example/engine_oedl.rb
omf_ec-6.2.0 example/engine_oedl.rb
omf_ec-6.2.0.pre.2 example/engine_oedl.rb
omf_ec-6.2.0.pre.1 example/engine_oedl.rb
omf_ec-6.1.14.pre.2 example/engine_oedl.rb
omf_ec-6.1.14.pre.1 example/engine_oedl.rb
omf_ec-6.1.12 example/engine_oedl.rb
omf_ec-6.1.11 example/engine_oedl.rb
omf_ec-6.1.10 example/engine_oedl.rb
omf_ec-6.1.9 example/engine_oedl.rb
omf_ec-6.1.9.pre.4 example/engine_oedl.rb
omf_ec-6.1.9.pre.3 example/engine_oedl.rb
omf_ec-6.1.9.pre.2 example/engine_oedl.rb
omf_ec-6.1.8 example/engine_oedl.rb
omf_ec-6.1.7 example/engine_oedl.rb
omf_ec-6.1.6 example/engine_oedl.rb
omf_ec-6.1.6.pre.2 example/engine_oedl.rb
omf_ec-6.1.6.pre.1 example/engine_oedl.rb