Class: OpenShift::Profile
- Defined in:
- lib/openshift-origin-common/models/profile.rb
Instance Attribute Summary collapse
-
#component_name_map ⇒ Object
Returns the value of attribute component_name_map.
-
#configure_order ⇒ Object
Returns the value of attribute configure_order.
-
#connection_name_map ⇒ Object
Returns the value of attribute connection_name_map.
-
#generated ⇒ Object
Returns the value of attribute generated.
-
#group_name_map ⇒ Object
Returns the value of attribute group_name_map.
-
#group_overrides ⇒ Object
Returns the value of attribute group_overrides.
-
#name ⇒ Object
Returns the value of attribute name.
-
#property_overrides ⇒ Object
Returns the value of attribute property_overrides.
-
#provides ⇒ Object
Returns the value of attribute provides.
-
#service_overrides ⇒ Object
Returns the value of attribute service_overrides.
-
#start_order ⇒ Object
Returns the value of attribute start_order.
-
#stop_order ⇒ Object
Returns the value of attribute stop_order.
Instance Method Summary collapse
- #add_component(comp) ⇒ Object
- #add_connection(conn) ⇒ Object
- #add_group(group) ⇒ Object
- #components(name = nil) ⇒ Object
- #components=(data) ⇒ Object
- #connections(name = nil) ⇒ Object
- #connections=(data) ⇒ Object
- #from_descriptor(spec_hash = {}) ⇒ Object
- #groups(name = nil) ⇒ Object
- #groups=(data) ⇒ Object
-
#initialize ⇒ Profile
constructor
A new instance of Profile.
- #to_descriptor ⇒ Object
Methods inherited from Model
attr_accessor, attr_reader, attr_writer, #attributes, #attributes=, #deleted?, exclude_attributes, excludes_attributes, gen_uuid, include_attributes, includes_attributes, #new_record?, #persisted?, primary_key, require_update_attributes, requires_update_attributes, #reset_state, #to_xml
Constructor Details
#initialize ⇒ Profile
Returns a new instance of Profile.
10 11 12 13 14 |
# File 'lib/openshift-origin-common/models/profile.rb', line 10 def initialize self.generated = false self.provides = [] self.group_overrides = nil end |
Instance Attribute Details
#component_name_map ⇒ Object
Returns the value of attribute component_name_map.
4 5 6 |
# File 'lib/openshift-origin-common/models/profile.rb', line 4 def component_name_map @component_name_map end |
#configure_order ⇒ Object
Returns the value of attribute configure_order.
4 5 6 |
# File 'lib/openshift-origin-common/models/profile.rb', line 4 def configure_order @configure_order end |
#connection_name_map ⇒ Object
Returns the value of attribute connection_name_map.
4 5 6 |
# File 'lib/openshift-origin-common/models/profile.rb', line 4 def connection_name_map @connection_name_map end |
#generated ⇒ Object
Returns the value of attribute generated.
4 5 6 |
# File 'lib/openshift-origin-common/models/profile.rb', line 4 def generated @generated end |
#group_name_map ⇒ Object
Returns the value of attribute group_name_map.
4 5 6 |
# File 'lib/openshift-origin-common/models/profile.rb', line 4 def group_name_map @group_name_map end |
#group_overrides ⇒ Object
Returns the value of attribute group_overrides.
4 5 6 |
# File 'lib/openshift-origin-common/models/profile.rb', line 4 def group_overrides @group_overrides end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/openshift-origin-common/models/profile.rb', line 4 def name @name end |
#property_overrides ⇒ Object
Returns the value of attribute property_overrides.
4 5 6 |
# File 'lib/openshift-origin-common/models/profile.rb', line 4 def property_overrides @property_overrides end |
#provides ⇒ Object
Returns the value of attribute provides.
4 5 6 |
# File 'lib/openshift-origin-common/models/profile.rb', line 4 def provides @provides end |
#service_overrides ⇒ Object
Returns the value of attribute service_overrides.
4 5 6 |
# File 'lib/openshift-origin-common/models/profile.rb', line 4 def service_overrides @service_overrides end |
#start_order ⇒ Object
Returns the value of attribute start_order.
4 5 6 |
# File 'lib/openshift-origin-common/models/profile.rb', line 4 def start_order @start_order end |
#stop_order ⇒ Object
Returns the value of attribute stop_order.
4 5 6 |
# File 'lib/openshift-origin-common/models/profile.rb', line 4 def stop_order @stop_order end |
Instance Method Details
#add_component(comp) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/openshift-origin-common/models/profile.rb', line 55 def add_component(comp) component_name_map_will_change! @component_name_map = {} if @component_name_map.nil? if comp.class == Component @component_name_map[comp.name] = comp else key = comp["name"] @component_name_map[key] = Component.new(key) @component_name_map[key].attributes=comp end end |
#add_connection(conn) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/openshift-origin-common/models/profile.rb', line 79 def add_connection(conn) connection_name_map_will_change! @connection_name_map = {} if @connection_name_map.nil? if conn.class == Connection @connection_name_map[conn.name] = conn else key = conn["name"] @connection_name_map[key] = Connection.new(key) @connection_name_map[key].attributes=conn end end |
#add_group(group) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/openshift-origin-common/models/profile.rb', line 67 def add_group(group) group_name_map_will_change! @group_name_map = {} if @group_name_map.nil? if group.class == Group @group_name_map[group.name] = group else key = group["name"] @group_name_map[key] = Group.new(key) @group_name_map[key].attributes=group end end |
#components(name = nil) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/openshift-origin-common/models/profile.rb', line 28 def components(name=nil) @component_name_map = {} if @component_name_map.nil? if name.nil? @component_name_map.values else @component_name_map[name] end end |
#components=(data) ⇒ Object
16 17 18 |
# File 'lib/openshift-origin-common/models/profile.rb', line 16 def components=(data) data.each {|comp| add_component(comp)} end |
#connections(name = nil) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/openshift-origin-common/models/profile.rb', line 46 def connections(name=nil) @connection_name_map = {} if @connection_name_map.nil? if name.nil? @connection_name_map.values else @connection_name_map[name] end end |
#connections=(data) ⇒ Object
24 25 26 |
# File 'lib/openshift-origin-common/models/profile.rb', line 24 def connections=(data) data.each {|conn| add_connection(conn)} end |
#from_descriptor(spec_hash = {}) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 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 |
# File 'lib/openshift-origin-common/models/profile.rb', line 91 def from_descriptor(spec_hash = {}) self.name = spec_hash["Name"] || "default" self.provides = spec_hash["Provides"] || [] self.start_order = spec_hash["Start-Order"] || [] self.stop_order = spec_hash["Stop-Order"] || [] self.configure_order = spec_hash["Configure-Order"] || [] #fixup user data. provides, start_order, start_order, configure_order bust be arrays self.provides = [self.provides] if self.provides.class == String self.start_order = [self.start_order] if self.start_order.class == String self.stop_order = [self.stop_order] if self.stop_order.class == String self.configure_order = [self.configure_order] if self.configure_order.class == String if spec_hash.has_key?("Components") spec_hash["Components"].each do |cname, c| comp = Component.new.from_descriptor(c) comp.name = cname add_component(comp) end else comp_spec_hash = spec_hash.dup.delete_if{|k,v| !["Publishes", "Subscribes"].include?(k) } c = Component.new.from_descriptor(comp_spec_hash) c.generated = true add_component(c) end if spec_hash.has_key?("Groups") spec_hash["Groups"].each do |gname, g| group = Group.new.from_descriptor(g) group.name = gname add_group(group) end else group = Group.new self.components.each do |c| group.add_component_ref(ComponentRef.new(c.name).from_descriptor(c.name)) end if spec_hash.has_key?("Scaling") group.scaling = Scaling.new.from_descriptor(spec_hash["Scaling"]) end group.generated = true add_group(group) end if spec_hash.has_key?("Connections") spec_hash["Connections"].each do |n,c| conn = Connection.new(n).from_descriptor(c) add_connection(conn) end end self.group_overrides = [] if self.group_overrides.nil? if spec_hash.has_key?("GroupOverrides") spec_hash["GroupOverrides"].each do |go| # each group override is a list group_overrides << go.dup end end self end |
#groups(name = nil) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/openshift-origin-common/models/profile.rb', line 37 def groups(name=nil) @group_name_map = {} if @group_name_map.nil? if name.nil? @group_name_map.values else @group_name_map[name] end end |
#groups=(data) ⇒ Object
20 21 22 |
# File 'lib/openshift-origin-common/models/profile.rb', line 20 def groups=(data) data.each {|group| add_group(group)} end |
#to_descriptor ⇒ Object
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 |
# File 'lib/openshift-origin-common/models/profile.rb', line 152 def to_descriptor h = {} h["Provides"] = @provides unless @provides.nil? || @provides.empty? h["Start-Order"] = @start_order unless @start_order.nil? || @start_order.empty? h["Stop-Order"] = @stop_order unless @stop_order.nil? || @stop_order.empty? h["Configure-Order"] = @configure_order unless @configure_order.nil? || @configure_order.empty? if self.components.length == 1 && self.components.first.generated comp_h = self.components.first.to_descriptor comp_h.delete("Name") h.merge!(comp_h) else h["Components"] = {} self.components.each do |v| h["Components"][v.name] = v.to_descriptor end end if self.groups.length == 1 && self.groups.first.generated h["Scaling"] = self.groups.first.scaling.to_descriptor if !self.groups.first.scaling.generated else h["Groups"] = {} self.groups.each do |v| h["Groups"][v.name] = v.to_descriptor end end if !self.connections.empty? h["Connections"] = {} self.connections.each do |v| h["Connections"][v.name] = v.to_descriptor end end h end |