Class: OmfRc::ResourceProxy::AbstractResource
- Inherits:
-
Object
- Object
- OmfRc::ResourceProxy::AbstractResource
- Includes:
- MonitorMixin, OmfRc::ResourceProxyDSL
- Defined in:
- omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb
Overview
Suppose you have read the DEVELOPERS GUIDE which explains the basic the resource controller system.
This is the abstract resource proxy class, which provides the base of all proxy implementations. When creating new resource instances, this abstract class will always be initialised first and then extended by one of the specific resource proxy modules.
Instead of initialise abstract resource directly, use Resource Factory's methods.
Proxy documentation has grouped FRCP API methods for your convenience.
We follow a simple naming convention for request/configure properties.
request_xxx() indicates property 'xxx' can be requested using FRCP REQUEST message.
configure_xxx(value) indicates property 'xxx' can be configured with 'value' using FRCP CONFIGURE message.
Currently official OMF RC gem contains following resource proxies:
Representing physical/virtual machine
Executing OML enabled application and monitor output
Configuring network interfaces
Installing packages
Creating virtual machines
Constant Summary
- RELEASE_WAIT =
Time to wait before releasing resource, wait for deleting pubsub topics
5
- DEFAULT_CREATION_OPTS =
{ suppress_create_message: false, create_children_resources: true }
- @@defaults =
Hashie::Mash.new
Constants included from OmfRc::ResourceProxyDSL
OmfRc::ResourceProxyDSL::DEFAULT_PROP_ACCESS, OmfRc::ResourceProxyDSL::PROXY_DIR, OmfRc::ResourceProxyDSL::UTIL_DIR
Instance Attribute Summary (collapse)
-
- (Object) certificate
Returns the value of attribute certificate.
-
- (Object) children
readonly
Returns the value of attribute children.
-
- (Object) creation_opts
readonly
Returns the value of attribute creation_opts.
-
- (Object) hrn
(also: #name)
Returns the value of attribute hrn.
-
- (Object) membership
readonly
Returns the value of attribute membership.
-
- (Object) membership_topics
readonly
Returns the value of attribute membership_topics.
-
- (Object) opts
readonly
Returns the value of attribute opts.
-
- (Object) property
Returns the value of attribute property.
-
- (Object) state
Returns the value of attribute state.
-
- (Object) topics
readonly
Returns the value of attribute topics.
-
- (Object) type
Returns the value of attribute type.
-
- (Object) uid
Returns the value of attribute uid.
FRCP Request Methods (collapse)
-
- (Hashie::Mash) request_available_properties(*args)
Return a list of all properties can be requested and configured.
-
- (Hashie::Mash) request_child_resources(*args)
Request child resources.
-
- (Object) request_hrn(*args)
(also: #request_name)
Make hrn accessible through pubsub interface.
-
- (Object) request_membership(*args)
Query resource's membership.
-
- (Object) request_res_index(*args)
Query resource's index number.
-
- (Array<Symbol>) request_supported_children_type(*args)
Return a list of child resources this resource can create.
-
- (Object) request_type(*args)
Make type accessible through pubsub interface.
-
- (Object) request_uid(*args)
Make uid accessible through pubsub interface.
FRCP Configure Methods (collapse)
-
- (Object) configure_membership(*args)
Make resource part of the group topic, it will alter existing membership array.
-
- (Object) configure_res_index(index)
Set the resource index, overwriting any previous index The index is a unique integer for each resource in an experiment It's used e.g.
Class Method Summary (collapse)
-
+ (Object) set_defaults(resource_type, defaults)
Set defaults for a particular resource class.
Instance Method Summary (collapse)
-
- (Object) add_prop_status_to_response(res_ctx, msg_props, response)
private
Getting property status, adding them to inform message.
-
- (Boolean) check_guard(message)
private
Checking if current object met the condition set by message guard section.
-
- (AbstractResource) create(type, opts = {}, creation_opts = {}, &creation_callback)
Create a new resource in the context of this resource.
-
- (Object) defaults(key = nil)
Set defaults for a particular resource class.
-
- (Object) disconnect
Disconnect using communicator.
-
- (Object) execute_omf_operation(message, obj, topic)
Execute operation based on the type of the message.
-
- (Object) get_binding
Get binding of current object, used for ERB eval.
-
- (Object) handle_configure_message(message, obj, response)
FRCP CONFIGURE message handler.
-
- (Object) handle_create_message(message, obj, response)
FRCP CREATE message handler.
-
- (Object) handle_message(message, obj)
Handling all messages, then delegate them to individual handler.
-
- (Object) handle_release_message(message, obj, response)
FRCP RELEASE message handler.
-
- (Object) handle_request_message(message, obj, response)
FRCP REQUEST message handler.
-
- (Object) inform(itype, inform_data, topic = nil)
Publish an inform message.
- - (Object) inform_creation_failed(reason)
- - (Object) inform_error(reason)
- - (Object) inform_status(props)
- - (Object) inform_warn(reason)
-
- (Object) init_configure(res_ctx, props)
private
Used for setting properties came with FRCP CREATE message.
-
- (AbstractResource) initialize(type, opts = {}, creation_opts = {}, &creation_callback)
constructor
Initialisation.
- - (Object) log_metadata(key, value, domain) private
-
- (Boolean) namespaced_property?(name)
private
Check if a property has namespace associated.
-
- (Array<OmfRc::ResourceProxy::AbstractResource>) objects_by_topic(name)
private
To deal with FRCP messages published to a group topic, we need to find out what resources belongs to that topic.
-
- (Object) process_omf_message(message, topic)
Parse omf message and execute as instructed by the message.
-
- (AbstractResource) release(res_id)
Release a child resource.
-
- (Boolean) release_self
Release this resource.
-
- (Object) replyto_address(obj, replyto = nil)
private
Retrieve replyto address.
-
- (Object) resource_address
Return the public 'routable' address for this resource or nil if not known yet.
-
- (Object) resource_topic
Return resource' pubsub topic it has subscribed.
-
- (Hash) to_hash
Return a hash describing a reference to this object.
Methods included from OmfRc::ResourceProxyDSL
#call_hook, #hook_defined?, included
Constructor Details
- (AbstractResource) initialize(type, opts = {}, creation_opts = {}, &creation_callback)
Initialisation
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 120 def initialize(type, opts = {}, creation_opts = {}, &creation_callback) super() @opts = Hashie::Mash.new(opts) @creation_opts = Hashie::Mash.new(DEFAULT_CREATION_OPTS.merge(creation_opts)) @type = type @uid = (@opts.delete(:uid) || SecureRandom.uuid).to_s @hrn = @opts.delete(:hrn) @hrn = @hrn.to_s if @hrn @node_index = nil @children = [] @membership = [] @topics = [] @membership_topics = {} @property = Hashie::Mash.new OmfCommon.comm.subscribe(@uid, routing_key: "o.op") do |t| @topics << t if t.error? warn "Could not create topic '#{uid}', will shutdown, trying to clean up old topics. Please start it again once it has been shutdown." OmfCommon.comm.disconnect OmfCommon.eventloop.stop else begin # Setup authentication related properties if (@certificate = @opts.delete(:certificate)) elsif (pcert = @opts.delete(:parent_certificate)) @certificate = pcert.dup end if @certificate @certificate.resource_id = resource_address OmfCommon::Auth::CertificateStore.instance.register(@certificate) end # Extend resource with Resource Module, can be obtained from Factory emodule = OmfRc::ResourceFactory.proxy_list[@type].proxy_module || "OmfRc::ResourceProxy::#{@type.camelize}".constantize self.extend(emodule) # Initiate property hash with default property values self.methods.each do |m| self.__send__(m) if m =~ /default_property_(.+)/ end # Bootstrap initial configure, this should handle membership too init_configure(self, @opts) # Execute resource before_ready hook if any call_hook :before_ready, self # Prepare init :creation_ok message copts = { src: self.resource_address } copts[:cert] = @certificate.to_pem_compact if @certificate cprops = @property cprops[:res_id] = self.resource_address add_prop_status_to_response(self, @opts.keys, cprops) # Then send inform message to itself, with all resource options' current values. t.inform(:creation_ok, cprops, copts) unless creation_opts[:suppress_create_message] t.(@uid) do |imsg| (imsg, t) end creation_callback.call(self) if creation_callback rescue => e error "Encountered exception: #{e.}, returning ERROR message" error e.backtrace.join("\n") t.inform(:creation_failed, { reason: e. }, { src: self.resource_address }) end end end end |
Instance Attribute Details
- (Object) certificate
Returns the value of attribute certificate
103 104 105 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 103 def certificate @certificate end |
- (Object) children (readonly)
Returns the value of attribute children
104 105 106 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 104 def children @children end |
- (Object) creation_opts (readonly)
Returns the value of attribute creation_opts
104 105 106 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 104 def creation_opts @creation_opts end |
- (Object) hrn Also known as: name
Returns the value of attribute hrn
103 104 105 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 103 def hrn @hrn end |
- (Object) membership (readonly)
Returns the value of attribute membership
104 105 106 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 104 def membership @membership end |
- (Object) membership_topics (readonly)
Returns the value of attribute membership_topics
104 105 106 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 104 def membership_topics @membership_topics end |
- (Object) opts (readonly)
Returns the value of attribute opts
104 105 106 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 104 def opts @opts end |
- (Object) property
Returns the value of attribute property
103 104 105 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 103 def property @property end |
- (Object) state
Returns the value of attribute state
103 104 105 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 103 def state @state end |
- (Object) topics (readonly)
Returns the value of attribute topics
104 105 106 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 104 def topics @topics end |
- (Object) type
Returns the value of attribute type
103 104 105 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 103 def type @type end |
- (Object) uid
Returns the value of attribute uid
103 104 105 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 103 def uid @uid end |
Class Method Details
+ (Object) set_defaults(resource_type, defaults)
Set defaults for a particular resource class. Can be retrieved with 'defaults' in the instance.
99 100 101 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 99 def self.set_defaults(resource_type, defaults) @@defaults[resource_type.to_sym] = defaults end |
Instance Method Details
- (Object) add_prop_status_to_response(res_ctx, msg_props, response) (private)
Getting property status, adding them to inform message
785 786 787 788 789 790 791 792 793 794 795 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 785 def add_prop_status_to_response(res_ctx, msg_props, response) msg_props.each do |p| # Property can either be defined as 'request' API call # or just an internal variable, e.g. uid, hrn, etc. if res_ctx.respond_to? "request_#{p}" response[p] = res_ctx.__send__("request_#{p}") elsif res_ctx.respond_to? p response[p] = res_ctx.__send__(p) end end end |
- (Boolean) check_guard(message) (private)
Checking if current object met the condition set by message guard section
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 746 def check_guard() guard = .guard if guard.nil? || guard.empty? return true else guard.keys.all? do |key| value = self.__send__("request_#{key}") if value.kind_of? Symbol value.to_s == guard[key].to_s else value == guard[key] end end end end |
- (Object) configure_membership(*args)
Make resource part of the group topic, it will alter existing membership array
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 400 def configure_membership(*args) case args[0] when Symbol, String, Array new_membership = [args[0]].flatten.compact when Hash leave_membership = [args[0][:leave]].flatten.compact only_membership = [args[0][:only]].flatten.compact end new_membership && new_membership.each do |new_m| unless @membership.include?(new_m) OmfCommon.comm.subscribe(new_m, routing_key: "o.op") do |t| if t.error? warn "Group #{new_m} disappeared" self.synchronize do @membership.delete(m) end else self.synchronize do @membership << new_m @membership_topics[new_m] = t self.inform(:status, { membership: @membership }, t) end t.(@uid) do |imsg| (imsg, t) end end end end end leave_membership && leave_membership.each do |leave_m| if (leave_m_topic = @membership_topics[leave_m]) self.synchronize do leave_m_topic.unsubscribe(leave_m) @membership.delete(leave_m) @membership_topics.delete_if { |k, v| k == leave_m } end end end unless only_membership.nil? || only_membership.empty? configure_membership({ leave: @membership }) configure_membership(only_membership) end @membership end |
- (Object) configure_res_index(index)
Set the resource index, overwriting any previous index The index is a unique integer for each resource in an experiment It's used e.g. to give each node an IP address such as x.x.x.res_index
455 456 457 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 455 def configure_res_index(index) @res_index = index end |
- (AbstractResource) create(type, opts = {}, creation_opts = {}, &creation_callback)
Create a new resource in the context of this resource. This resource becomes parent, and newly created resource becomes child
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 234 def create(type, opts = {}, creation_opts = {}, &creation_callback) unless request_supported_children_type.include?(type.to_sym) raise StandardError, "Resource #{type} is not designed to be created by #{self.type}" end opts[:parent_certificate] = @certificate if @certificate opts[:parent] = self call_hook(:before_create, self, type, opts) new_resource = OmfRc::ResourceFactory.create(type.to_sym, opts, creation_opts, &creation_callback) (self.uid, new_resource.uid, :create) call_hook(:after_create, self, new_resource) self.synchronize do children << new_resource end new_resource end |
- (Object) defaults(key = nil)
Set defaults for a particular resource class. Can be retrieved with 'defaults' in the instance.
201 202 203 204 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 201 def defaults(key = nil) d = @@defaults[@type] || {} key ? d[key] : d end |
- (Object) disconnect
Disconnect using communicator
226 227 228 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 226 def disconnect OmfCommon.comm.disconnect end |
- (Object) execute_omf_operation(message, obj, topic)
Execute operation based on the type of the message
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 490 def execute_omf_operation(, obj, topic) begin response_h = (, obj) rescue => ex err_resp = .(nil, {}, src: resource_address) err_resp[:reason] = ex.to_s error "Encountered exception, returning ERROR message" debug ex. debug ex.backtrace.join("\n") return inform(:error, err_resp, topic) end case .operation #when :create # inform(:creation_ok, response_h, topic) when :request, :configure inform(:status, response_h, topic) when :release OmfCommon.eventloop.after(RELEASE_WAIT) do inform(:released, response_h, topic) if response_h[:res_id] end end end |
- (Object) get_binding
Get binding of current object, used for ERB eval
221 222 223 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 221 def get_binding binding end |
- (Object) handle_configure_message(message, obj, response)
FRCP CONFIGURE message handler
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 583 def (, obj, response) conf_properties = .properties conf_result = Hashie::Mash.new call_hook(:pre_configure, obj, conf_properties, conf_result) if obj.respond_to?(:configure_all) obj.configure_all(conf_properties, conf_result) else conf_properties.each do |key, value| method_name = "configure_#{key}" conf_result[key] = obj.__send__(method_name, value) end end call_hook(:post_configure, obj, conf_properties, conf_result) conf_result.each do |key, value| if namespaced_property?(key) response[key, namespace] = value else response[key] = value end end end |
- (Object) handle_create_message(message, obj, response)
FRCP CREATE message handler
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 550 def (, obj, response) new_name = [:name] || [:hrn] msg_props = .properties.merge({ hrn: new_name }) obj.create([:type], msg_props, &lambda do |new_obj| begin response[:res_id] = new_obj.resource_address response[:uid] = new_obj.uid # Getting property status, for preparing inform msg add_prop_status_to_response(new_obj, msg_props.keys, response) if (cred = new_obj.certificate) response[:cert] = cred.to_pem_compact end # self here is the parent self.inform(:creation_ok, response) rescue => ex err_resp = .(nil, {}, src: resource_address) err_resp[:reason] = ex.to_s error "Encountered exception, returning ERROR message" debug ex. debug ex.backtrace.join("\n") return self.inform(:error, err_resp) end end) end |
- (Object) handle_message(message, obj)
Handling all messages, then delegate them to individual handler
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 518 def (, obj) # We really don't care about inform messages which created from here return nil if .operation == :inform unless [:create, :request, :configure, :release].include?(.operation) raise StandardError, <<-ERROR Invalid message received (Unknown OMF operation #{.operation}): #{}. Please check protocol schema of version #{OmfCommon::PROTOCOL_VERSION}. ERROR end response = .(nil, {}, src: resource_address) response.replyto = replyto_address(obj, .replyto) case .operation when :create (, obj, response) when :request (, obj, response) when :configure (, obj, response) when :release (, obj, response) end response end |
- (Object) handle_release_message(message, obj, response)
FRCP RELEASE message handler
640 641 642 643 644 645 646 647 648 649 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 640 def (, obj, response) res_id = .res_id released_obj = obj.release(res_id) # TODO: Under what circumstances would 'realease_obj' be NIL # # When release message send to a group, for bulk releasing, # the proxy might not be aware of a res_id it received response[:res_id] = released_obj.resource_address if released_obj response end |
- (Object) handle_request_message(message, obj, response)
FRCP REQUEST message handler
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 614 def (, obj, response) request_props = if .has_properties? .properties.keys.map(&:to_sym) & obj.request_available_properties.request else # Return ALL props when nothing specified obj.request_available_properties.request end request_props.each do |p_name| method_name = "request_#{p_name.to_s}" value = obj.__send__(method_name) if value if namespaced_property?(p_name) response[p_name, namespace] = value else response[p_name] = value end end end end |
- (Object) inform(itype, inform_data, topic = nil)
Publish an inform message
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 657 def inform(itype, inform_data, topic = nil) inform_data = inform_data.dup # better make a copy unless address = resource_address OmfCommon.eventloop.after(1) do # try again in a bit and see if address has been set by then inform(itype, inform_data, topic = nil) end warn "INFORM message delayed as resource's address is not known yet" return end if inform_data.is_a? Hash inform_data = Hashie::Mash.new(inform_data) if inform_data.class == Hash #idata = inform_data.dup idata = { src: address, type: self.type # NOTE: Should we add the object's type as well??? } = OmfCommon::Message.(itype.to_s.upcase, inform_data, idata) else = inform_data end .itype = itype unless itype == :released [:hrn] ||= self.hrn if self.hrn end # Just send to all topics, including group membership (membership_topics.map { |mt| mt[1] } + @topics).each do |t| t.publish(, { routing_key: "o.info" }) OmfRc::ResourceProxy::MPPublished.inject(Time.now.to_f, self.uid, t.id, .mid) if OmfCommon::Measure.enabled? end end |
- (Object) inform_creation_failed(reason)
702 703 704 705 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 702 def inform_creation_failed(reason) error reason inform :creation_failed, { reason: reason } end |
- (Object) inform_error(reason)
697 698 699 700 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 697 def inform_error(reason) error reason inform :error, { reason: reason } end |
- (Object) inform_status(props)
693 694 695 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 693 def inform_status(props) inform :status, props end |
- (Object) inform_warn(reason)
707 708 709 710 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 707 def inform_warn(reason) warn reason inform :warn, { reason: reason } end |
- (Object) init_configure(res_ctx, props) (private)
Used for setting properties came with FRCP CREATE message.
767 768 769 770 771 772 773 774 775 776 777 778 779 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 767 def init_configure(res_ctx, props) props.each do |key, value| if res_ctx.respond_to? "configure_#{key}" res_ctx.__send__("configure_#{key}", value) elsif res_ctx.respond_to? "initialise_#{key}" # For read only props, they won't have "configure" method defined, # we can still set them directly during this creation. res_ctx.__send__("initialise_#{key}", value) end end call_hook(:after_initial_configured, res_ctx) end |
- (Object) log_metadata(key, value, domain) (private)
804 805 806 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 804 def (key, value, domain) OmfRc::MetaData.inject(domain.to_s, key.to_s, value.to_s) end |
- (Boolean) namespaced_property?(name) (private)
Check if a property has namespace associated
800 801 802 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 800 def namespaced_property?(name) respond_to?(:namespace) && name =~ /^(.+)__(.+)$/ end |
- (Array<OmfRc::ResourceProxy::AbstractResource>) objects_by_topic(name) (private)
To deal with FRCP messages published to a group topic, we need to find out what resources belongs to that topic.
725 726 727 728 729 730 731 732 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 725 def objects_by_topic(name) if name == uid || membership.any? { |m| m.include?(name) } objs = [self] else objs = children.find_all { |v| v.uid == name || v.membership.any? { |m| m.include?(name) } } end objs end |
- (Object) process_omf_message(message, topic)
Parse omf message and execute as instructed by the message
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 465 def (, topic) unless .is_a? OmfCommon::Message raise ArgumentError, "Expected OmfCommon::Message, but got '#{.class}'" end unless .valid? raise StandardError, "Invalid message received: #{pubsub_item_payload}. Please check protocol schema of version #{OmfCommon::PROTOCOL_VERSION}." end return unless check_guard() # We really don't care about inform messages which created from here return nil if .operation == :inform objects_by_topic(topic.id.to_s).each do |obj| OmfRc::ResourceProxy::MPReceived.inject(Time.now.to_f, self.uid, topic.id.to_s, .mid) if OmfCommon::Measure.enabled? execute_omf_operation(, obj, topic) end end |
- (AbstractResource) release(res_id)
Release a child resource
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 259 def release(res_id) if (child = children.find { |v| v.uid.to_s == res_id.to_s }) if child.release_self() self.synchronize do children.delete(child) end child else child = nil end debug "#{child.uid} released" else debug "#{res_id} does not belong to #{self.uid}(#{self.hrn}) - #{children.map(&:uid).inspect}" end child end |
- (Boolean) release_self
Release this resource. Should ONLY be called by parent resource.
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 279 def release_self # Release children resource recursively children.each do |c| if c.release_self self.synchronize do children.delete(c) end end end return false unless children.empty? info "Releasing hrn: #{hrn}, uid: #{uid}" call_hook(:before_release, self) props = { res_id: resource_address } props[:hrn] = hrn if hrn inform :released, props # clean up topics @topics.each do |t| t.unsubscribe(@uid) end @membership_topics.each_value do |t| if t.respond_to? :delete_on_message_cbk_by_id t.(@uid) end t.unsubscribe(@uid) end true end |
- (Object) replyto_address(obj, replyto = nil) (private)
Retrieve replyto address
738 739 740 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 738 def replyto_address(obj, replyto = nil) replyto || obj.uid end |
- (Hashie::Mash) request_available_properties(*args)
Return a list of all properties can be requested and configured
333 334 335 336 337 338 339 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 333 def request_available_properties(*args) Hashie::Mash.new(request: [], configure: []).tap do |mash| methods.each do |m| mash[$1] << $2.to_sym if m =~ /^(request|configure)_(.+)/ && $2 != "available_properties" end end end |
- (Hashie::Mash) request_child_resources(*args)
Request child resources
373 374 375 376 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 373 def request_child_resources(*args) #children.map { |c| Hashie::Mash.new({ uid: c.uid, name: c.hrn }) } children.map { |c| c.to_hash } end |
- (Object) request_hrn(*args) Also known as: request_name
Make hrn accessible through pubsub interface
352 353 354 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 352 def request_hrn(*args) hrn end |
- (Object) request_membership(*args)
Query resource's membership
361 362 363 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 361 def request_membership(*args) @membership end |
- (Object) request_res_index(*args)
Query resource's index number
366 367 368 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 366 def request_res_index(*args) @res_index end |
- (Array<Symbol>) request_supported_children_type(*args)
Return a list of child resources this resource can create
321 322 323 324 325 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 321 def request_supported_children_type(*args) OmfRc::ResourceFactory.proxy_list.reject { |v| v == @type.to_s }.find_all do |k, v| (v.create_by && v.create_by.include?(@type.to_sym)) || v.create_by.nil? end.map(&:first).map(&:to_sym) end |
- (Object) request_type(*args)
Make type accessible through pubsub interface
347 348 349 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 347 def request_type(*args) type end |
- (Object) request_uid(*args)
Make uid accessible through pubsub interface
342 343 344 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 342 def request_uid(*args) uid end |
- (Object) resource_address
Return the public 'routable' address for this resource or nil if not known yet.
216 217 218 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 216 def resource_address resource_topic.address end |
- (Object) resource_topic
Return resource' pubsub topic it has subscribed.
207 208 209 210 211 212 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 207 def resource_topic if @topics.empty? raise TopicNotSubscribedError, "Resource '#{@uid}' has not subscribed to any topics" end @topics[0] end |
- (Hash) to_hash
Return a hash describing a reference to this object
715 716 717 |
# File 'omf_rc/lib/omf_rc/resource_proxy/abstract_resource.rb', line 715 def to_hash { uid: @uid, address: resource_address() } end |