Class: Ironfan::Dsl::Component

Inherits:
Ironfan::Dsl show all
Includes:
Gorillib::Builder, Gorillib::Concern, Plugin::Base
Defined in:
lib/ironfan/headers.rb,
lib/ironfan/dsl/component.rb

Instance Attribute Summary

Attributes included from Gorillib::Resolution

#underlay

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Plugin::Base

#to_node

Methods inherited from Ironfan::Dsl

#_skip_fields, #skip_fields, #to_manifest

Methods included from Gorillib::Resolution

#deep_resolve, #merge_resolve, #merge_values, #read_resolved_attribute, #read_set_attribute, #read_set_or_underlay_attribute, #read_underlay_attribute, #resolve, #resolve!, #resolve_value

Methods included from CookbookRequirements

#_cookbook_reqs, #children, #cookbook_req, #cookbook_reqs, #join_req

Methods inherited from Builder

ui, #ui

Constructor Details

#initialize(attrs, &blk) ⇒ Component

Returns a new instance of Component.


13
14
15
16
17
18
# File 'lib/ironfan/dsl/component.rb', line 13

def initialize(attrs, &blk)
  attrs.merge!(facet_name:   (attrs[:owner].name unless attrs[:owner].nil? or not attrs[:owner].is_a?(Facet)),
               cluster_name: (attrs[:owner].cluster_name unless attrs[:owner].nil?),
               realm_name:   (attrs[:owner].realm_name unless attrs[:owner].nil?))
  super attrs, &blk
end

Class Method Details

.announce_nameObject


41
42
43
# File 'lib/ironfan/dsl/component.rb', line 41

def self.announce_name
  plugin_name
end

.from_node(node = NilCheckDelegate.new(nil)) ⇒ Object


35
36
37
38
39
# File 'lib/ironfan/dsl/component.rb', line 35

def self.from_node(node = NilCheckDelegate.new(nil))
  cluster_name = node['cluster_name'].to_s
  realm_name = node['realm_name'].to_s
  super(node).tap{ |x| x.receive!(cluster_name: cluster_name, realm_name: realm_name) }                                        
end

.plugin_hook(owner, attrs, plugin_name, full_name, &blk) ⇒ Object


20
21
22
23
# File 'lib/ironfan/dsl/component.rb', line 20

def self.plugin_hook owner, attrs, plugin_name, full_name, &blk
  (this = new(attrs.merge(owner: owner, name: full_name), &blk))._project(owner)
  this
end

.to_nodeObject


29
30
31
32
33
# File 'lib/ironfan/dsl/component.rb', line 29

def self.to_node
  super.tap do |node|
    node.set['cluster_name'] = cluster_name
  end
end

Instance Method Details

#_project(compute) ⇒ Object


49
50
51
52
# File 'lib/ironfan/dsl/component.rb', line 49

def _project(compute)
  compute.component name, self
  project(compute)
end

#announce(component_name) ⇒ Object


62
63
64
65
66
# File 'lib/ironfan/dsl/component.rb', line 62

def announce(component_name)
  Chef::Log.debug("announced #{announce_name} for #{cluster_name}")
  realm_announcements[[realm_name, component_name]] = [cluster_name, facet_name]
  realm_subscriptions(component_name).each{|blk| blk.call(cluster_name, facet_name)}
end

#announce_nameObject


45
46
47
# File 'lib/ironfan/dsl/component.rb', line 45

def announce_name
  self.class.announce_name
end

#announce_to(node) ⇒ Object


25
26
27
# File 'lib/ironfan/dsl/component.rb', line 25

def announce_to node
  node.set['components']["#{cluster_name}-#{name}"]['name'] = name
end

#discover(component_name, &blk) ⇒ Object


68
69
70
71
72
73
74
75
# File 'lib/ironfan/dsl/component.rb', line 68

def discover(component_name, &blk)
  if already_announced = realm_announcements[[realm_name, component_name]]
    yield *already_announced
  else
    Chef::Log.debug("#{cluster_name}: no one announced #{announce_name}. subscribing")
    realm_subscriptions(component_name) << blk
  end
end

#realm_announcementsObject


54
55
56
# File 'lib/ironfan/dsl/component.rb', line 54

def realm_announcements
  (@@realm_announcements ||= {})
end

#realm_subscriptions(component_name) ⇒ Object


58
59
60
# File 'lib/ironfan/dsl/component.rb', line 58

def realm_subscriptions component_name
  (@@realm_subscriptions ||= {})[component_name] ||= []
end