Class: Broham
- Inherits:
-
RightAws::ActiveSdb::Base
- Object
- RightAws::ActiveSdb::Base
- Broham
- Defined in:
- lib/broham.rb,
lib/broham/script.rb
Overview
Broham expects a hash constant Settings
with values for :secret_access_key
and :access_key
. The configliere gem (github.com/mrflip/configliere) can help with that.
Class Method Summary collapse
-
.cloudera_desktop(role = 'cloudera_desktop') ⇒ Object
Hadoop: cloudera desktop node.
-
.diss(*args) ⇒ Object
alternative syntax for #unregister.
- .entry_for_role(role, ip = nil) ⇒ Object
- .establish_connection(options = {}) ⇒ Object
-
.fuck_all_yall(*args) ⇒ Object
alternative syntax for #unregister_like.
-
.hadoop_jobtracker(role = 'hadoop_jobtracker') ⇒ Object
Hadoop: master jobtracker node.
-
.hadoop_namenode(role = 'hadoop_namenode') ⇒ Object
Hadoop: master namenode.
-
.host(role) ⇒ Object
Returns the last-registered host in the given role.
- .host_attrs(role) ⇒ Object
-
.hosts_like(role) ⇒ Object
Returns all hosts in the given role.
- .my_availability_zone ⇒ Object
- .my_default_ip ⇒ Object
- .my_fqdn ⇒ Object
-
.my_private_ip ⇒ Object
Registration attributes.
- .my_public_ip ⇒ Object
-
.nfs_device_path(role = 'nfs_server') ⇒ Object
NFS: device path, for stuffing into /etc/fstab.
- .register(role, attrs = {}) ⇒ Object
-
.register_as_next(role, attrs = {}) ⇒ Object
Enlists as the next among many machines filling the given role.
-
.register_nfs_share(server_path, client_path = nil, role = 'nfs_server') ⇒ Object
Register an nfs server share.
- .roles(ip = nil) ⇒ Object
-
.sup?(*args) ⇒ Boolean
alternative syntax for #host.
-
.sup_yall?(*args) ⇒ Boolean
alternative syntax for #hosts_like.
- .timestamp ⇒ Object
- .unregister(role) ⇒ Object
-
.unregister_like(role) ⇒ Object
Removes all registrations for the given role wildcard.
-
.yo!(*args) ⇒ Object
alternative syntax for #register.
-
.yo_yo_yo!(*args) ⇒ Object
alternative syntax for #register_as_next.
Instance Method Summary collapse
- #availability_zone ⇒ Object
- #default_ip ⇒ Object
- #fqdn ⇒ Object
- #idx ⇒ Object
- #private_ip ⇒ Object
- #public_ip ⇒ Object
- #to_hash ⇒ Object
- #to_pretty_json ⇒ Object
- #unregister ⇒ Object
Class Method Details
.cloudera_desktop(role = 'cloudera_desktop') ⇒ Object
Hadoop: cloudera desktop node
157 |
# File 'lib/broham.rb', line 157 def self.cloudera_desktop( role='cloudera_desktop') ; host(role) ; end |
.diss(*args) ⇒ Object
alternative syntax for #unregister
108 |
# File 'lib/broham.rb', line 108 def self.diss(*args) unregister *args ; end |
.entry_for_role(role, ip = nil) ⇒ Object
56 57 58 59 |
# File 'lib/broham.rb', line 56 def self.entry_for_role role, ip=nil ip ||= my_default_ip select_by_role_and_default_ip(role, ip) end |
.establish_connection(options = {}) ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/broham.rb', line 132 def self.establish_connection ={} return @connection if @connection = { :logger => Log }.merge access_key = [:access_key] || Settings[:access_key] secret_access_key = [:secret_access_key] || Settings[:secret_access_key] @connection = RightAws::ActiveSdb.establish_connection(access_key, secret_access_key, ) end |
.fuck_all_yall(*args) ⇒ Object
alternative syntax for #unregister_like
110 |
# File 'lib/broham.rb', line 110 def self.fuck_all_yall(*args) unregister_like *args ; end |
.hadoop_jobtracker(role = 'hadoop_jobtracker') ⇒ Object
Hadoop: master jobtracker node
153 |
# File 'lib/broham.rb', line 153 def self.hadoop_jobtracker(role='hadoop_jobtracker') ; host(role) ; end |
.hadoop_namenode(role = 'hadoop_namenode') ⇒ Object
Hadoop: master namenode
155 |
# File 'lib/broham.rb', line 155 def self.hadoop_namenode( role='hadoop_namenode') ; host(role) ; end |
.host(role) ⇒ Object
Returns the last-registered host in the given role
31 32 33 |
# File 'lib/broham.rb', line 31 def self.host role select_by_role(role, :order => 'timestamp DESC') end |
.host_attrs(role) ⇒ Object
40 41 42 43 |
# File 'lib/broham.rb', line 40 def self.host_attrs(role) { :role => role, :timestamp => , :private_ip => my_private_ip, :public_ip => my_public_ip, :default_ip => my_default_ip, :fqdn => my_fqdn } end |
.hosts_like(role) ⇒ Object
Returns all hosts in the given role
36 37 38 |
# File 'lib/broham.rb', line 36 def self.hosts_like role select(:all, :order => 'timestamp DESC').select{|bro| bro[:role].to_s =~ /^#{role}/ } end |
.my_availability_zone ⇒ Object
120 |
# File 'lib/broham.rb', line 120 def self.my_availability_zone() OHAI_INFO[:ec2][:availability_zone] ; end |
.my_default_ip ⇒ Object
118 |
# File 'lib/broham.rb', line 118 def self.my_default_ip() OHAI_INFO[:ipaddress] ; end |
.my_fqdn ⇒ Object
119 |
# File 'lib/broham.rb', line 119 def self.my_fqdn() OHAI_INFO[:fqdn] ; end |
.my_private_ip ⇒ Object
Registration attributes
116 |
# File 'lib/broham.rb', line 116 def self.my_private_ip() OHAI_INFO[:cloud][:private_ips].first rescue nil ; end |
.my_public_ip ⇒ Object
117 |
# File 'lib/broham.rb', line 117 def self.my_public_ip() OHAI_INFO[:cloud][:public_ips].first rescue nil ; end |
.nfs_device_path(role = 'nfs_server') ⇒ Object
NFS: device path, for stuffing into /etc/fstab
147 148 149 150 |
# File 'lib/broham.rb', line 147 def self.nfs_device_path role='nfs_server' nfs_server = host(role) or return [nfs_server.private_ip, nfs_server[:server_path]].join(':') end |
.register(role, attrs = {}) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/broham.rb', line 45 def self.register role, attrs={} ahost = host(role) || new ahost.attributes = (host_attrs(role).merge(attrs)) success = ahost.save success ? self.new(success) : false end |
.register_as_next(role, attrs = {}) ⇒ Object
Enlists as the next among many machines filling the given role.
This is just a simple counter: it doesn’t check whether the machine is already enlisted under a different index, or whether there are missing indices.
It uses conditional save to be sure that the count is consistent
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/broham.rb', line 70 def self.register_as_next role, attrs={} my_idx = 0 if (registered_entry = entry_for_role(role)) then return registered_entry end 100.times do ahost = host(role) || new current_max_idx = ahost[:idx] && ahost[:idx].first my_idx = current_max_idx ? current_max_idx.to_i + 1 : 0 ahost.attributes = host_attrs(role).merge({ :idx => my_idx.to_s }.merge(attrs)) expected = current_max_idx ? {:idx => (current_max_idx.to_i).to_s} : {} registered_entry = ahost.save_if(expected) break if registered_entry end register role+'-'+my_idx.to_s, { :idx => my_idx }.merge(attrs) new registered_entry end |
.register_nfs_share(server_path, client_path = nil, role = 'nfs_server') ⇒ Object
Register an nfs server share
141 142 143 144 |
# File 'lib/broham.rb', line 141 def self.register_nfs_share server_path, client_path=nil, role='nfs_server' client_path ||= server_path register(role, :server_path => server_path, :client_path => client_path) end |
.roles(ip = nil) ⇒ Object
52 53 54 55 |
# File 'lib/broham.rb', line 52 def self.roles ip=nil ip ||= my_default_ip select_all_by_default_ip(ip).map{|entry| entry['role'] } end |
.sup?(*args) ⇒ Boolean
alternative syntax for #host
104 |
# File 'lib/broham.rb', line 104 def self.sup?(*args) host *args ; end |
.sup_yall?(*args) ⇒ Boolean
alternative syntax for #hosts_like
106 |
# File 'lib/broham.rb', line 106 def self.sup_yall?(*args) hosts_like *args ; end |
.timestamp ⇒ Object
121 |
# File 'lib/broham.rb', line 121 def self.() Time.now.utc.strftime("%Y%m%d%H%M%SZ") ; end |
.unregister(role) ⇒ Object
92 93 94 |
# File 'lib/broham.rb', line 92 def self.unregister role host(role).each(&:unregister) end |
.unregister_like(role) ⇒ Object
Removes all registrations for the given role wildcard
89 90 91 |
# File 'lib/broham.rb', line 89 def self.unregister_like role hosts_like(role).each(&:unregister) end |
.yo!(*args) ⇒ Object
alternative syntax for #register
100 |
# File 'lib/broham.rb', line 100 def self.yo!(*args) register *args ; end |
.yo_yo_yo!(*args) ⇒ Object
alternative syntax for #register_as_next
102 |
# File 'lib/broham.rb', line 102 def self.yo_yo_yo!(*args) register_as_next *args ; end |
Instance Method Details
#availability_zone ⇒ Object
127 |
# File 'lib/broham.rb', line 127 def availability_zone() self['availability_zone'].first ; end |
#default_ip ⇒ Object
125 |
# File 'lib/broham.rb', line 125 def default_ip() self['default_ip' ].first ; end |
#fqdn ⇒ Object
126 |
# File 'lib/broham.rb', line 126 def fqdn() self['fqdn' ].first ; end |
#idx ⇒ Object
128 129 130 |
# File 'lib/broham.rb', line 128 def idx() self['idx'].first end |
#private_ip ⇒ Object
123 |
# File 'lib/broham.rb', line 123 def private_ip() self['private_ip' ].first || default_ip ; end |
#public_ip ⇒ Object
124 |
# File 'lib/broham.rb', line 124 def public_ip() self['public_ip' ].first || default_ip ; end |
#to_hash ⇒ Object
159 |
# File 'lib/broham.rb', line 159 def to_hash() attributes ; end |
#to_pretty_json ⇒ Object
160 161 162 |
# File 'lib/broham.rb', line 160 def to_pretty_json to_hash.reject{|k,v| k.to_s == 'id'}.to_json end |
#unregister ⇒ Object
95 96 97 |
# File 'lib/broham.rb', line 95 def unregister delete end |