Module: Puppet_X::EnterpriseModules::Oracle::Access
- Includes:
- EasyType::Helpers, Settings
- Defined in:
- lib/puppet_x/enterprisemodules/oracle/access.rb
Overview
Docs
Class Method Summary collapse
Instance Method Summary collapse
- #add_sid_to(elements, sid) ⇒ Object
- #for_version(hash) ⇒ Object
-
#hex_to_raw(raw) ⇒ Object
This is the reverse of Oracle’s rawtohex TODO: See if we can make this more efficient.
- #instance ⇒ Object
- #module_name ⇒ Object
- #ora_autorequire(type, property) ⇒ Object
-
#oracle_version?(sid, version) ⇒ Boolean
Check if the oracle version of the specified sid is equal to the specified version.
- #resource_list_for(property) ⇒ Object
-
#safe_sql(command, options) ⇒ Object
Execute a user specified sql and ensure that after this sql, we are still connected to the correct container.
-
#select_statement(versioned_command, sid) ⇒ Object
Returns the first valid sql statement in the versioned command.
- #sid_from(source) ⇒ Object
- #sid_from_resource ⇒ Object
-
#sql(command, options = {}) ⇒ Object
Use this function to execute Oracle statements.
-
#sql_on_all_asm_sids(command, parameters = {}) ⇒ Object
Use this function to execute Oracle statements on all running asm sids.
-
#sql_on_all_database_sids(command, parameters = {}) ⇒ Object
Use this function to execute Oracle statements on all running databases.
-
#sql_on_all_mgmt_sids(command, parameters = {}) ⇒ Object
Use this function to execute Oracle statements on all running mgmtdb sids.
-
#sql_on_all_mt_sids(command, parameters = {}) ⇒ Object
Use this function to execute Oracle statements on all running multitenant databases.
-
#sql_on_all_normal_sids(command, parameters = {}) ⇒ Object
Use this function to execute Oracle statements on all running normal databases.
-
#sql_on_all_primary_database_sids(command, parameters = {}) ⇒ Object
Use this function to execute Oracle statements on all running databases.
-
#sql_on_all_sids(command, parameters = {}) ⇒ Object
Use this function to execute Oracle statements on all running sid.
-
#sql_on_sids(sids, command, parameters = {}) ⇒ Array
Run the sql commmand on all specified sids.
-
#timeout_specified ⇒ Object
This is a little hack to get a specified timeout value.
- #versioned_statement?(command) ⇒ Boolean
Class Method Details
.included(parent) ⇒ Object
24 25 26 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 24 def self.included(parent) parent.extend(Access) end |
Instance Method Details
#add_sid_to(elements, sid) ⇒ Object
258 259 260 261 262 263 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 258 def add_sid_to(elements, sid) elements.collect do |e| e['SID'] = sid e end end |
#for_version(hash) ⇒ Object
28 29 30 31 32 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 28 def for_version(hash) hash.collect do |version, query| [lambda { |sid| oracle_version?(sid, version) }, query] end end |
#hex_to_raw(raw) ⇒ Object
This is the reverse of Oracle’s rawtohex TODO: See if we can make this more efficient
38 39 40 41 42 43 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 38 def hex_to_raw(raw) raw.chars.each_slice(2).collect do |slice| txt = slice[0] + slice[1] txt.hex.chr end.join end |
#instance ⇒ Object
306 307 308 309 310 311 312 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 306 def instance if resource[:instances].any? resource[:instances].select { |_inst, host| host.include? Facter.value('hostname') }.to_h.keys[0] else resource.name end end |
#module_name ⇒ Object
20 21 22 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 20 def module_name 'ora_config' end |
#ora_autorequire(type, property) ⇒ Object
276 277 278 279 280 281 282 283 284 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 276 def ora_autorequire(type, property) autorequire(type) do if property.is_a?(Array) property.collect { |p| resource_list_for(p) }.flatten else resource_list_for(property) end end end |
#oracle_version?(sid, version) ⇒ Boolean
Check if the oracle version of the specified sid is equal to the specified version.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 49 def oracle_version?(sid, version) return true if version.to_s == 'default' if version.instance_of?(String) || version.instance_of?(Symbol) oracle_major_version(sid) == version.to_s.to_i elsif version.instance_of?(Regexp) database_version(sid) =~ version else fail 'Invalid type specified for sql version query' end end |
#resource_list_for(property) ⇒ Object
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 286 def resource_list_for(property) value = property.is_a?(Proc) ? instance_exec(&property) : send(property) current_sid = self[:sid] if value.nil? || value.empty? nil elsif value.is_a?(::Array) if current_sid value.collect { |element| "#{element}@#{current_sid}" }.flatten else value end else current_sid ? "#{value}@#{current_sid}" : value end end |
#safe_sql(command, options) ⇒ Object
Execute a user specified sql and ensure that after this sql, we are still connected to the correct container.
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 226 def safe_sql(command, ) # # There are two cases where we don't want/need the check and just execute the sql: # 1) On an ASM sid # 2) When Oracle is not running # # regarding case 2, the exec might contain a start command we would like to execure without # any other checks # return sql(command, ) if asm_sid?(sid_from_resource) || (normal_db?(sid_from_resource) && !running_db?(sid_from_resource)) # # First ensure the correct rootdb information, when we know we are connected to the correct database. # rootdb?(sid_from_resource) output = sql(command, ) # # In ora_exec you can run arbitrary sql scripts. Also scripts that can connect to # an other container. This can confuse the daemon. Therefor after we execute a script, we always connect to the correct # container again. begin sql(template('ora_config/ora_exec/ensure_correct_container.sql.erb', binding), ) if rootdb?(sid_from_resource) || containerdb?(sid_from_resource) rescue RuntimeError => e # # If the database was shutdown in the ora_exec command, the reconnect will get a ORA-01034: ORACLE not available # error. So if this error occurs, just let it be. All other errors will be raised again # raise unless /ORA-01034/.match?(e.) end output end |
#select_statement(versioned_command, sid) ⇒ Object
Returns the first valid sql statement in the versioned command
183 184 185 186 187 188 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 183 def select_statement(versioned_command, sid) versioned_command.each do |version_proc, statement| return statement if version_proc.call(sid) end fail 'no valid version found' end |
#sid_from(source) ⇒ Object
302 303 304 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 302 def sid_from(source) source.sid.nil? ? default_database_sid : source.sid end |
#sid_from_resource ⇒ Object
272 273 274 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 272 def sid_from_resource sid_from(resource) end |
#sql(command, options = {}) ⇒ Object
Use this function to execute Oracle statements
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 202 def sql(command, = {}) [:timeout] ||= resource[:timeout] if timeout_specified parse = .fetch(:parse, true) @sql = Sql.new() sid = @sql.sid statement = if versioned_statement?(command) select_statement(command, sid) else command end Puppet.debug "executing #{statement} on #{sid}" results = @sql.execute(statement) if parse add_sid_to(convert_csv_data_to_hash(results, [], :col_sep => ',', :converters => lambda { |f| f ? f.strip : nil }), sid) else results end end |
#sql_on_all_asm_sids(command, parameters = {}) ⇒ Object
Use this function to execute Oracle statements on all running asm sids.
119 120 121 122 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 119 def sql_on_all_asm_sids(command, parameters = {}) sids = running_asm_sids sql_on_sids(sids, command, parameters) end |
#sql_on_all_database_sids(command, parameters = {}) ⇒ Object
Use this function to execute Oracle statements on all running databases. This excludes asm database
69 70 71 72 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 69 def sql_on_all_database_sids(command, parameters = {}) sids = running_database_sids sql_on_sids(sids, command, parameters) end |
#sql_on_all_mgmt_sids(command, parameters = {}) ⇒ Object
Use this function to execute Oracle statements on all running mgmtdb sids.
130 131 132 133 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 130 def sql_on_all_mgmt_sids(command, parameters = {}) sids = running_mgmt_sids sql_on_sids(sids, command, parameters) end |
#sql_on_all_mt_sids(command, parameters = {}) ⇒ Object
Use this function to execute Oracle statements on all running multitenant databases. This excludes asm and normal databases
108 109 110 111 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 108 def sql_on_all_mt_sids(command, parameters = {}) sids = running_mt_database_sids sql_on_sids(sids, command, parameters) end |
#sql_on_all_normal_sids(command, parameters = {}) ⇒ Object
Use this function to execute Oracle statements on all running normal databases. This excludes asm and multitenant databases
95 96 97 98 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 95 def sql_on_all_normal_sids(command, parameters = {}) sids = running_normal_database_sids sql_on_sids(sids, command, parameters) end |
#sql_on_all_primary_database_sids(command, parameters = {}) ⇒ Object
Use this function to execute Oracle statements on all running databases. This excludes asm database
82 83 84 85 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 82 def sql_on_all_primary_database_sids(command, parameters = {}) sids = running_primary_database_sids sql_on_sids(sids, command, parameters) end |
#sql_on_all_sids(command, parameters = {}) ⇒ Object
Use this function to execute Oracle statements on all running sid. This includes asm database
143 144 145 146 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 143 def sql_on_all_sids(command, parameters = {}) sids = running_sids sql_on_sids(sids, command, parameters) end |
#sql_on_sids(sids, command, parameters = {}) ⇒ Array
Run the sql commmand on all specified sids. If the sql is a String, The string will be used as the sql statement.
The command, can also be an array. In that case, every pair contains a landa followed by an sql sattement e.g
[
lamda { a check}, 'select * from tab',
lamda { an other check}, 'select * from users',
]
The check will be executed on every sid. You can use this for example to use different statements on different versions of oracle
or
171 172 173 174 175 176 177 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 171 def sql_on_sids(sids, command, parameters = {}) results = [] sids.each do |sid| results += sql(command, { :sid => sid }.merge(parameters)) end results end |
#timeout_specified ⇒ Object
This is a little hack to get a specified timeout value
266 267 268 269 270 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 266 def timeout_specified resource.timeout rescue NameError nil end |
#versioned_statement?(command) ⇒ Boolean
191 192 193 |
# File 'lib/puppet_x/enterprisemodules/oracle/access.rb', line 191 def versioned_statement?(command) command.is_a?(::Array) end |