Class: MotherBrain::Gear::MySQL::Action Private
- Inherits:
-
Object
- Object
- MotherBrain::Gear::MySQL::Action
- Includes:
- MB::Mixin::Services
- Defined in:
- lib/mb/gears/mysql/action.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
- #options ⇒ Hash readonly private
- #sql ⇒ String readonly private
Class Method Summary collapse
Instance Method Summary collapse
-
#connection_info(environment, node) ⇒ Hash
private
The MySQL connection information/credentials for the specified node.
-
#data_bag_keys ⇒ Hash
private
The keys used to look up MySQL connection information in a data bag item.
-
#initialize(sql, options) ⇒ Action
constructor
private
A new instance of Action.
-
#run(job, environment, nodes) ⇒ Object
private
Run this action on the specified nodes.
Constructor Details
#initialize(sql, options) ⇒ Action
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Action.
41 42 43 44 45 |
# File 'lib/mb/gears/mysql/action.rb', line 41 def initialize(sql, ) self.class.() @sql = sql @options = end |
Instance Attribute Details
#options ⇒ Hash (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
18 19 20 |
# File 'lib/mb/gears/mysql/action.rb', line 18 def @options end |
#sql ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/mb/gears/mysql/action.rb', line 16 def sql @sql end |
Class Method Details
.validate_options(options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 28 29 30 31 32 33 |
# File 'lib/mb/gears/mysql/action.rb', line 25 def () unless .key?(:data_bag) raise ArgumentError, "You are missing a :data_bag key in your MySQL gear options!" end unless [:data_bag].key?(:name) raise ArgumentError, "You are missing a :name key in your MySQL gear data bag options!" end end |
Instance Method Details
#connection_info(environment, node) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The MySQL connection information/credentials for the specified node.
77 78 79 80 81 |
# File 'lib/mb/gears/mysql/action.rb', line 77 def connection_info(environment, node) credentials(environment).merge(host: node.public_hostname) rescue MB::DataBagNotFound, MB::DataBagItemNotFound => ex raise MB::GearError.new(ex) end |
#data_bag_keys ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The keys used to look up MySQL connection information in a data bag item.
84 85 86 87 88 89 90 91 92 |
# File 'lib/mb/gears/mysql/action.rb', line 84 def data_bag_keys hash = data_bag_spec[:location][:hash] if hash Hash[data_bag_spec[:location][:keys].map { |k, v| [k, "#{hash}.#{v}"] }] else data_bag_spec[:location][:keys] end end |
#run(job, environment, nodes) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Run this action on the specified nodes
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/mb/gears/mysql/action.rb', line 55 def run(job, environment, nodes) threads = [] nodes.each do |node| threads << Thread.new(node) do |node| query(environment, sql, node) end end threads.each(&:join) end |