Class: OmfEc::Group
- Inherits:
-
Object
- Object
- OmfEc::Group
- Includes:
- MonitorMixin, Backward::Group
- Defined in:
- lib/omf_ec/group.rb
Overview
Group instance used in experiment script
Instance Attribute Summary collapse
-
#app_contexts ⇒ Object
Returns the value of attribute app_contexts.
-
#apps ⇒ Object
readonly
holding applications to be added to group.
-
#execs ⇒ Object
Returns the value of attribute execs.
-
#id ⇒ Object
pubsub topic id of the resource.
-
#members ⇒ Object
holding members to be added to group.
-
#name ⇒ Object
name of the resource.
-
#net_ifs ⇒ Object
network interfaces defined to be added to group.
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
Instance Method Summary collapse
-
#add_resource(*names) ⇒ Object
Add existing resources to the group.
- #address(suffix = nil) ⇒ Object
- #associate_resource_topic(name, res_topic) ⇒ Object
- #associate_topic(topic) ⇒ Object
-
#create_resource(name, opts, &block) ⇒ Object
Create a set of new resources and add them to the group.
-
#initialize(name, opts = {}, &block) ⇒ Group
constructor
A new instance of Group.
- #resource_topic(name) ⇒ Object
- #resources ⇒ OmfEc::Context::GroupContext
Methods included from Backward::Group
#addApplication, #exec, #method_missing, #net, #resource_group, #startApplication, #startApplications, #stopApplications
Constructor Details
#initialize(name, opts = {}, &block) ⇒ Group
Returns a new instance of Group.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/omf_ec/group.rb', line 25 def initialize(name, opts = {}, &block) super() self.name = name self.id = "#{OmfEc.experiment.id}.#{self.name}" # Add empty holders for members, network interfaces, and apps self.net_ifs = [] self.members = {} self.app_contexts = [] self.execs = [] @resource_topics = {} OmfEc.subscribe_and_monitor(id, self, &block) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class OmfEc::Backward::Group
Instance Attribute Details
#app_contexts ⇒ Object
Returns the value of attribute app_contexts.
20 21 22 |
# File 'lib/omf_ec/group.rb', line 20 def app_contexts @app_contexts end |
#apps ⇒ Object (readonly)
holding applications to be added to group
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/omf_ec/group.rb', line 17 class Group include MonitorMixin attr_accessor :name, :id, :net_ifs, :members, :app_contexts, :execs attr_reader :topic # @param [String] name name of the group # @param [Hash] opts def initialize(name, opts = {}, &block) super() self.name = name self.id = "#{OmfEc.experiment.id}.#{self.name}" # Add empty holders for members, network interfaces, and apps self.net_ifs = [] self.members = {} self.app_contexts = [] self.execs = [] @resource_topics = {} OmfEc.subscribe_and_monitor(id, self, &block) end def address(suffix = nil) t_id = suffix ? "#{self.id}_#{suffix.to_s}" : self.id OmfCommon.comm.string_to_topic_address(t_id) end def associate_topic(topic) self.synchronize do @topic = topic end end def associate_resource_topic(name, res_topic) self.synchronize do @resource_topics[name] = res_topic end end def resource_topic(name) @resource_topics[name] end # Add existing resources to the group # # Resources to be added could be a list of resources, groups, or the mixture of both. def add_resource(*names) names.flatten! synchronize do # Recording membership first, used for ALL_UP event names.each do |name| if (g = OmfEc.experiment.group(name))# resource to add is a group @members.merge!(g.members) else OmfEc.experiment.nodes << name unless OmfEc.experiment.nodes.include?(name) @members[name] = nil end end end end # Create a set of new resources and add them to the group # # @param [String] name # @param [Hash] opts to be used to create new resources def create_resource(name, opts, &block) self.synchronize do raise ArgumentError, "Option :type is required for creating resource" if opts[:type].nil? # Make a deep copy of opts in case it contains structures of structures begin opts = Marshal.load ( Marshal.dump(opts.merge(hrn: name))) rescue => e raise "#{e.message} - Could not deep copy opts: '#{opts.inspect}'" end # Naming convention of child resource group #resource_group_name = "#{self.id}_#{opts[:type].to_s}" resource_group_name = self.address(opts[:type]) OmfEc.subscribe_and_monitor(resource_group_name) do |res_group| associate_resource_topic(opts[:type].to_s, res_group) # Send create message to group r_type = opts.delete(:type) @topic.create(r_type, opts.merge(membership: resource_group_name)) end end end # @return [OmfEc::Context::GroupContext] def resources OmfEc::Context::GroupContext.new(group: self) end include OmfEc::Backward::Group end |
#execs ⇒ Object
Returns the value of attribute execs.
20 21 22 |
# File 'lib/omf_ec/group.rb', line 20 def execs @execs end |
#id ⇒ Object
pubsub topic id of the resource
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/omf_ec/group.rb', line 17 class Group include MonitorMixin attr_accessor :name, :id, :net_ifs, :members, :app_contexts, :execs attr_reader :topic # @param [String] name name of the group # @param [Hash] opts def initialize(name, opts = {}, &block) super() self.name = name self.id = "#{OmfEc.experiment.id}.#{self.name}" # Add empty holders for members, network interfaces, and apps self.net_ifs = [] self.members = {} self.app_contexts = [] self.execs = [] @resource_topics = {} OmfEc.subscribe_and_monitor(id, self, &block) end def address(suffix = nil) t_id = suffix ? "#{self.id}_#{suffix.to_s}" : self.id OmfCommon.comm.string_to_topic_address(t_id) end def associate_topic(topic) self.synchronize do @topic = topic end end def associate_resource_topic(name, res_topic) self.synchronize do @resource_topics[name] = res_topic end end def resource_topic(name) @resource_topics[name] end # Add existing resources to the group # # Resources to be added could be a list of resources, groups, or the mixture of both. def add_resource(*names) names.flatten! synchronize do # Recording membership first, used for ALL_UP event names.each do |name| if (g = OmfEc.experiment.group(name))# resource to add is a group @members.merge!(g.members) else OmfEc.experiment.nodes << name unless OmfEc.experiment.nodes.include?(name) @members[name] = nil end end end end # Create a set of new resources and add them to the group # # @param [String] name # @param [Hash] opts to be used to create new resources def create_resource(name, opts, &block) self.synchronize do raise ArgumentError, "Option :type is required for creating resource" if opts[:type].nil? # Make a deep copy of opts in case it contains structures of structures begin opts = Marshal.load ( Marshal.dump(opts.merge(hrn: name))) rescue => e raise "#{e.message} - Could not deep copy opts: '#{opts.inspect}'" end # Naming convention of child resource group #resource_group_name = "#{self.id}_#{opts[:type].to_s}" resource_group_name = self.address(opts[:type]) OmfEc.subscribe_and_monitor(resource_group_name) do |res_group| associate_resource_topic(opts[:type].to_s, res_group) # Send create message to group r_type = opts.delete(:type) @topic.create(r_type, opts.merge(membership: resource_group_name)) end end end # @return [OmfEc::Context::GroupContext] def resources OmfEc::Context::GroupContext.new(group: self) end include OmfEc::Backward::Group end |
#members ⇒ Object
holding members to be added to group
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/omf_ec/group.rb', line 17 class Group include MonitorMixin attr_accessor :name, :id, :net_ifs, :members, :app_contexts, :execs attr_reader :topic # @param [String] name name of the group # @param [Hash] opts def initialize(name, opts = {}, &block) super() self.name = name self.id = "#{OmfEc.experiment.id}.#{self.name}" # Add empty holders for members, network interfaces, and apps self.net_ifs = [] self.members = {} self.app_contexts = [] self.execs = [] @resource_topics = {} OmfEc.subscribe_and_monitor(id, self, &block) end def address(suffix = nil) t_id = suffix ? "#{self.id}_#{suffix.to_s}" : self.id OmfCommon.comm.string_to_topic_address(t_id) end def associate_topic(topic) self.synchronize do @topic = topic end end def associate_resource_topic(name, res_topic) self.synchronize do @resource_topics[name] = res_topic end end def resource_topic(name) @resource_topics[name] end # Add existing resources to the group # # Resources to be added could be a list of resources, groups, or the mixture of both. def add_resource(*names) names.flatten! synchronize do # Recording membership first, used for ALL_UP event names.each do |name| if (g = OmfEc.experiment.group(name))# resource to add is a group @members.merge!(g.members) else OmfEc.experiment.nodes << name unless OmfEc.experiment.nodes.include?(name) @members[name] = nil end end end end # Create a set of new resources and add them to the group # # @param [String] name # @param [Hash] opts to be used to create new resources def create_resource(name, opts, &block) self.synchronize do raise ArgumentError, "Option :type is required for creating resource" if opts[:type].nil? # Make a deep copy of opts in case it contains structures of structures begin opts = Marshal.load ( Marshal.dump(opts.merge(hrn: name))) rescue => e raise "#{e.message} - Could not deep copy opts: '#{opts.inspect}'" end # Naming convention of child resource group #resource_group_name = "#{self.id}_#{opts[:type].to_s}" resource_group_name = self.address(opts[:type]) OmfEc.subscribe_and_monitor(resource_group_name) do |res_group| associate_resource_topic(opts[:type].to_s, res_group) # Send create message to group r_type = opts.delete(:type) @topic.create(r_type, opts.merge(membership: resource_group_name)) end end end # @return [OmfEc::Context::GroupContext] def resources OmfEc::Context::GroupContext.new(group: self) end include OmfEc::Backward::Group end |
#name ⇒ Object
name of the resource
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/omf_ec/group.rb', line 17 class Group include MonitorMixin attr_accessor :name, :id, :net_ifs, :members, :app_contexts, :execs attr_reader :topic # @param [String] name name of the group # @param [Hash] opts def initialize(name, opts = {}, &block) super() self.name = name self.id = "#{OmfEc.experiment.id}.#{self.name}" # Add empty holders for members, network interfaces, and apps self.net_ifs = [] self.members = {} self.app_contexts = [] self.execs = [] @resource_topics = {} OmfEc.subscribe_and_monitor(id, self, &block) end def address(suffix = nil) t_id = suffix ? "#{self.id}_#{suffix.to_s}" : self.id OmfCommon.comm.string_to_topic_address(t_id) end def associate_topic(topic) self.synchronize do @topic = topic end end def associate_resource_topic(name, res_topic) self.synchronize do @resource_topics[name] = res_topic end end def resource_topic(name) @resource_topics[name] end # Add existing resources to the group # # Resources to be added could be a list of resources, groups, or the mixture of both. def add_resource(*names) names.flatten! synchronize do # Recording membership first, used for ALL_UP event names.each do |name| if (g = OmfEc.experiment.group(name))# resource to add is a group @members.merge!(g.members) else OmfEc.experiment.nodes << name unless OmfEc.experiment.nodes.include?(name) @members[name] = nil end end end end # Create a set of new resources and add them to the group # # @param [String] name # @param [Hash] opts to be used to create new resources def create_resource(name, opts, &block) self.synchronize do raise ArgumentError, "Option :type is required for creating resource" if opts[:type].nil? # Make a deep copy of opts in case it contains structures of structures begin opts = Marshal.load ( Marshal.dump(opts.merge(hrn: name))) rescue => e raise "#{e.message} - Could not deep copy opts: '#{opts.inspect}'" end # Naming convention of child resource group #resource_group_name = "#{self.id}_#{opts[:type].to_s}" resource_group_name = self.address(opts[:type]) OmfEc.subscribe_and_monitor(resource_group_name) do |res_group| associate_resource_topic(opts[:type].to_s, res_group) # Send create message to group r_type = opts.delete(:type) @topic.create(r_type, opts.merge(membership: resource_group_name)) end end end # @return [OmfEc::Context::GroupContext] def resources OmfEc::Context::GroupContext.new(group: self) end include OmfEc::Backward::Group end |
#net_ifs ⇒ Object
network interfaces defined to be added to group
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/omf_ec/group.rb', line 17 class Group include MonitorMixin attr_accessor :name, :id, :net_ifs, :members, :app_contexts, :execs attr_reader :topic # @param [String] name name of the group # @param [Hash] opts def initialize(name, opts = {}, &block) super() self.name = name self.id = "#{OmfEc.experiment.id}.#{self.name}" # Add empty holders for members, network interfaces, and apps self.net_ifs = [] self.members = {} self.app_contexts = [] self.execs = [] @resource_topics = {} OmfEc.subscribe_and_monitor(id, self, &block) end def address(suffix = nil) t_id = suffix ? "#{self.id}_#{suffix.to_s}" : self.id OmfCommon.comm.string_to_topic_address(t_id) end def associate_topic(topic) self.synchronize do @topic = topic end end def associate_resource_topic(name, res_topic) self.synchronize do @resource_topics[name] = res_topic end end def resource_topic(name) @resource_topics[name] end # Add existing resources to the group # # Resources to be added could be a list of resources, groups, or the mixture of both. def add_resource(*names) names.flatten! synchronize do # Recording membership first, used for ALL_UP event names.each do |name| if (g = OmfEc.experiment.group(name))# resource to add is a group @members.merge!(g.members) else OmfEc.experiment.nodes << name unless OmfEc.experiment.nodes.include?(name) @members[name] = nil end end end end # Create a set of new resources and add them to the group # # @param [String] name # @param [Hash] opts to be used to create new resources def create_resource(name, opts, &block) self.synchronize do raise ArgumentError, "Option :type is required for creating resource" if opts[:type].nil? # Make a deep copy of opts in case it contains structures of structures begin opts = Marshal.load ( Marshal.dump(opts.merge(hrn: name))) rescue => e raise "#{e.message} - Could not deep copy opts: '#{opts.inspect}'" end # Naming convention of child resource group #resource_group_name = "#{self.id}_#{opts[:type].to_s}" resource_group_name = self.address(opts[:type]) OmfEc.subscribe_and_monitor(resource_group_name) do |res_group| associate_resource_topic(opts[:type].to_s, res_group) # Send create message to group r_type = opts.delete(:type) @topic.create(r_type, opts.merge(membership: resource_group_name)) end end end # @return [OmfEc::Context::GroupContext] def resources OmfEc::Context::GroupContext.new(group: self) end include OmfEc::Backward::Group end |
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
21 22 23 |
# File 'lib/omf_ec/group.rb', line 21 def topic @topic end |
Instance Method Details
#add_resource(*names) ⇒ Object
Add existing resources to the group
Resources to be added could be a list of resources, groups, or the mixture of both.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/omf_ec/group.rb', line 64 def add_resource(*names) names.flatten! synchronize do # Recording membership first, used for ALL_UP event names.each do |name| if (g = OmfEc.experiment.group(name))# resource to add is a group @members.merge!(g.members) else OmfEc.experiment.nodes << name unless OmfEc.experiment.nodes.include?(name) @members[name] = nil end end end end |
#address(suffix = nil) ⇒ Object
40 41 42 43 |
# File 'lib/omf_ec/group.rb', line 40 def address(suffix = nil) t_id = suffix ? "#{self.id}_#{suffix.to_s}" : self.id OmfCommon.comm.string_to_topic_address(t_id) end |
#associate_resource_topic(name, res_topic) ⇒ Object
51 52 53 54 55 |
# File 'lib/omf_ec/group.rb', line 51 def associate_resource_topic(name, res_topic) self.synchronize do @resource_topics[name] = res_topic end end |
#associate_topic(topic) ⇒ Object
45 46 47 48 49 |
# File 'lib/omf_ec/group.rb', line 45 def associate_topic(topic) self.synchronize do @topic = topic end end |
#create_resource(name, opts, &block) ⇒ Object
Create a set of new resources and add them to the group
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/omf_ec/group.rb', line 83 def create_resource(name, opts, &block) self.synchronize do raise ArgumentError, "Option :type is required for creating resource" if opts[:type].nil? # Make a deep copy of opts in case it contains structures of structures begin opts = Marshal.load ( Marshal.dump(opts.merge(hrn: name))) rescue => e raise "#{e.message} - Could not deep copy opts: '#{opts.inspect}'" end # Naming convention of child resource group #resource_group_name = "#{self.id}_#{opts[:type].to_s}" resource_group_name = self.address(opts[:type]) OmfEc.subscribe_and_monitor(resource_group_name) do |res_group| associate_resource_topic(opts[:type].to_s, res_group) # Send create message to group r_type = opts.delete(:type) @topic.create(r_type, opts.merge(membership: resource_group_name)) end end end |
#resource_topic(name) ⇒ Object
57 58 59 |
# File 'lib/omf_ec/group.rb', line 57 def resource_topic(name) @resource_topics[name] end |
#resources ⇒ OmfEc::Context::GroupContext
108 109 110 |
# File 'lib/omf_ec/group.rb', line 108 def resources OmfEc::Context::GroupContext.new(group: self) end |