broham 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -4,9 +4,9 @@ require 'broham'
4
4
  require 'broham/script'
5
5
  require 'json'
6
6
 
7
- cluster = Broham.get_cluster_settings
8
- cluster_name, role_name = [Settings[:cluster_name], Settings[:role_name]]
7
+ Broham.get_cluster_settings
8
+ role_name = Settings[:role_name]
9
9
 
10
- $stderr.puts %Q{Retrieving '#{role_name}' for cluster '#{cluster_name}'}
11
- resp = cluster.host role_name
10
+ $stderr.puts %Q{Retrieving '#{role_name}'}
11
+ resp = Broham.host role_name
12
12
  $stderr.puts resp.to_pretty_json
@@ -4,11 +4,10 @@ require 'broham'
4
4
  require 'broham/script'
5
5
  Settings.define :set, :description => %Q{Any arg prefixed with "--set" will become an extra arg to register: 'broham-register foo --set-path=/path/to/foo' sets :path => '/path/to/foo' as an additional attribute}, :type => Hash
6
6
 
7
- cluster = Broham.get_cluster_settings
8
- cluster_name, role_name, broham_args = [Settings[:cluster_name], Settings[:role_name], Settings[:set]||{}]
7
+ Broham.get_cluster_settings
8
+ role_name, broham_args = [Settings[:role_name], Settings[:set]||{}]
9
9
 
10
- $stderr.puts %Q{Registering as #{role_name} in #{cluster_name} cluster, with #{broham_args.inspect}}
11
- resp = cluster.register role_name, broham_args
12
- node = cluster.host role_name
10
+ $stderr.puts %Q{Registering as #{role_name} with #{broham_args.inspect}}
11
+ resp = Broham.register role_name, broham_args
12
+ node = Broham.host role_name
13
13
  $stderr.puts resp.to_pretty_json
14
-
@@ -4,10 +4,10 @@ require 'broham'
4
4
  require 'broham/script'
5
5
  Settings.define :set, :description => %Q{Any arg prefixed with "--set" will become an extra arg to register: 'broham-register foo --set-path=/path/to/foo' sets :path => '/path/to/foo' as an additional attribute}, :type => Hash
6
6
 
7
- cluster = Broham.get_cluster_settings
8
- cluster_name, role_name, broham_args = [Settings[:cluster_name], Settings[:role_name], Settings[:set]||{}]
7
+ Broham.get_cluster_settings
8
+ role_name, broham_args = [Settings[:role_name], Settings[:set]||{}]
9
9
 
10
- $stderr.puts %Q{Registering as next #{role_name} in #{cluster_name} cluster, with #{broham_args.inspect}}
11
- resp = cluster.register_as_next role_name, broham_args
10
+ $stderr.puts %Q{Registering as next #{role_name} with #{broham_args.inspect}}
11
+ resp = Broham.register_as_next role_name, broham_args
12
12
  $stderr.puts resp.to_pretty_json
13
13
 
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'broham'
4
+ require 'broham/script'
5
+ require 'json'
6
+
7
+ Broham.get_cluster_settings
8
+ role_name = Settings[:role_name]
9
+
10
+ $stderr.puts %Q{Retrieving '#{role_name}'}
11
+ resp = Broham.host role_name
12
+ $stderr.puts resp.to_pretty_json
@@ -3,10 +3,11 @@ require 'rubygems'
3
3
  require 'broham'
4
4
  require 'broham/script'
5
5
 
6
- cluster = Broham.get_cluster_settings
7
- cluster_name, role_name = [Settings[:cluster_name], Settings[:role_name] ]
8
6
 
9
- $stderr.puts %Q{Removing all #{role_name} from #{cluster_name} cluster}
10
- resps = cluster.unregister_all role_name
7
+ Broham.get_cluster_settings
8
+ role_name = Settings[:role_name]
9
+
10
+ $stderr.puts %Q{Removing all #{role_name}}
11
+ resps = Broham.unregister_all role_name
11
12
  $stderr.puts resps.map{|resp| resp.to_pretty_json }
12
13
 
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'broham'
4
+ require 'broham/script'
5
+ Settings.define :set, :description => %Q{Any arg prefixed with "--set" will become an extra arg to register: 'broham-register foo --set-path=/path/to/foo' sets :path => '/path/to/foo' as an additional attribute}, :type => Hash
6
+
7
+ Broham.get_cluster_settings
8
+ role_name, broham_args = [Settings[:role_name], Settings[:set]||{}]
9
+
10
+ $stderr.puts %Q{Registering as #{role_name} with #{broham_args.inspect}}
11
+ resp = Broham.register role_name, broham_args
12
+ node = Broham.host role_name
13
+ $stderr.puts resp.to_pretty_json
@@ -5,14 +5,14 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{broham}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Philip (flip) Kromer"]
12
12
  s.date = %q{2010-04-05}
13
13
  s.description = %q{Bro! Broham always knows where his bros are, bro. Using broham, a newly-created cloud machine can annouce its availability for a certain role ("nfs_server" or "db_slave-2"), allowing any other interested nodes to discover its public_ip, private_ip, etc. See also: http://j.mp/amongbros}
14
14
  s.email = %q{flip@infochimps.org}
15
- s.executables = ["broham-host", "broham-register", "broham-register_as_next", "broham-unregister-all"]
15
+ s.executables = ["broham-host", "broham-register", "broham-register_as_next", "broham-sup", "broham-unregister-all", "broham-yo"]
16
16
  s.extra_rdoc_files = [
17
17
  "LICENSE",
18
18
  "README.textile"
@@ -27,7 +27,9 @@ Gem::Specification.new do |s|
27
27
  "bin/broham-host",
28
28
  "bin/broham-register",
29
29
  "bin/broham-register_as_next",
30
+ "bin/broham-sup",
30
31
  "bin/broham-unregister-all",
32
+ "bin/broham-yo",
31
33
  "broham.gemspec",
32
34
  "lib/broham.rb",
33
35
  "lib/broham/script.rb",
@@ -22,127 +22,125 @@ Settings.define :secret_access_key, :required => true, :description => "Amazon A
22
22
  # and +:access_key+. The configliere gem (http://github.com/mrflip/configliere)
23
23
  # can help with that.
24
24
  #
25
- module Broham
26
- class Cluster < RightAws::ActiveSdb::Base
27
- # Returns the last-registered host in the given role
28
- def self.host role
29
- select_by_role(role, :order => 'timestamp DESC')
30
- end
31
-
32
- # Returns all hosts in the given role
33
- def self.hosts role
34
- select_all_by_role(role, :order => 'timestamp DESC')
35
- end
25
+ class Broham < RightAws::ActiveSdb::Base
26
+ # Returns the last-registered host in the given role
27
+ def self.host role
28
+ select_by_role(role, :order => 'timestamp DESC')
29
+ end
36
30
 
37
- def self.host_attrs(role)
38
- { :role => role, :timestamp => timestamp,
39
- :private_ip => my_private_ip, :public_ip => my_public_ip, :default_ip => my_default_ip, :fqdn => my_fqdn }
40
- end
31
+ # Returns all hosts in the given role
32
+ def self.hosts role
33
+ select_all_by_role(role, :order => 'timestamp DESC')
34
+ end
41
35
 
42
- def self.register role, attrs={}
43
- ahost = host(role) || new
44
- ahost.attributes = (host_attrs(role).merge(attrs))
45
- success = ahost.save
46
- success ? self.new(success) : false
47
- end
36
+ def self.host_attrs(role)
37
+ { :role => role, :timestamp => timestamp,
38
+ :private_ip => my_private_ip, :public_ip => my_public_ip, :default_ip => my_default_ip, :fqdn => my_fqdn }
39
+ end
48
40
 
49
- #
50
- # Enlists as the next among many machines filling the given role.
51
- #
52
- # This is just a simple counter: it doesn't check whether the machine is
53
- # already enlisted under a different index, or whether there are missing
54
- # indices.
55
- #
56
- # It uses conditional save to be sure that the count is consistent
57
- #
58
- def self.register_as_next role, attrs={}
59
- my_idx = 0
60
- 100.times do
61
- ahost = host(role) || new
62
- current_max_idx = ahost[:idx] && ahost[:idx].first
63
- my_idx = (current_max_idx.to_i + 1)
64
- ahost.attributes = host_attrs(role).merge({ :idx => my_idx.to_s }.merge(attrs))
65
- expected = current_max_idx ? {:idx => (current_max_idx.to_i + rand(5)).to_s} : {}
66
- success = ahost.save_if(expected)
67
- break if success
68
- end
69
- register role+'-'+my_idx.to_s, { :idx => my_idx }.merge(attrs)
70
- end
41
+ def self.register role, attrs={}
42
+ ahost = host(role) || new
43
+ ahost.attributes = (host_attrs(role).merge(attrs))
44
+ success = ahost.save
45
+ success ? self.new(success) : false
46
+ end
71
47
 
72
- # alternative syntax for #register
73
- def self.yo!(*args) register *args ; end
74
- # alternative syntax for #register_as_next
75
- def self.yo_yo_yo!(*args) register_as_next *args ; end
76
- # alternative syntax for #host
77
- def self.sup?(*args) host *args ; end
78
- # alternative syntax for #hosts
79
- def self.sup_bros?(*args) hosts *args ; end
80
-
81
- #
82
- # Removes all registrations for the given role
83
- #
84
- def self.unregister_all role
85
- select_all_by_role(role).each(&:delete)
48
+ #
49
+ # Enlists as the next among many machines filling the given role.
50
+ #
51
+ # This is just a simple counter: it doesn't check whether the machine is
52
+ # already enlisted under a different index, or whether there are missing
53
+ # indices.
54
+ #
55
+ # It uses conditional save to be sure that the count is consistent
56
+ #
57
+ def self.register_as_next role, attrs={}
58
+ my_idx = 0
59
+ 100.times do
60
+ ahost = host(role) || new
61
+ current_max_idx = ahost[:idx] && ahost[:idx].first
62
+ my_idx = (current_max_idx.to_i + 1)
63
+ ahost.attributes = host_attrs(role).merge({ :idx => my_idx.to_s }.merge(attrs))
64
+ expected = current_max_idx ? {:idx => (current_max_idx.to_i + rand(5)).to_s} : {}
65
+ success = ahost.save_if(expected)
66
+ break if success
86
67
  end
68
+ register role+'-'+my_idx.to_s, { :idx => my_idx }.merge(attrs)
69
+ end
87
70
 
88
- #
89
- # Registration attributes
90
- #
91
-
92
- def self.my_private_ip() OHAI_INFO[:cloud][:private_ips].first rescue nil ; end
93
- def self.my_public_ip() OHAI_INFO[:cloud][:public_ips].first rescue nil ; end
94
- def self.my_default_ip() OHAI_INFO[:ipaddress] ; end
95
- def self.my_fqdn() OHAI_INFO[:fqdn] ; end
96
- def self.my_availability_zone() OHAI_INFO[:ec2][:availability_zone] ; end
97
- def self.timestamp() Time.now.utc.strftime("%Y%m%d%H%M%S") ; end
98
-
99
- def private_ip() self['private_ip' ] || default_ip ; end
100
- def public_ip() self['public_ip' ] || default_ip ; end
101
- def default_ip() self['default_ip' ] ; end
102
- def fqdn() self['fqdn' ] ; end
103
- def availability_zone() self['availability_zone'] ; end
104
- def idx()
105
- self['idx']
106
- end
71
+ # alternative syntax for #register
72
+ def self.yo!(*args) register *args ; end
73
+ # alternative syntax for #register_as_next
74
+ def self.yo_yo_yo!(*args) register_as_next *args ; end
75
+ # alternative syntax for #host
76
+ def self.sup?(*args) host *args ; end
77
+ # alternative syntax for #hosts
78
+ def self.sup_bros?(*args) hosts *args ; end
107
79
 
108
- def self.establish_connection
109
- @connection ||= RightAws::ActiveSdb.establish_connection(Settings[:access_key], Settings[:secret_access_key])
110
- end
80
+ #
81
+ # Removes all registrations for the given role
82
+ #
83
+ def self.unregister_all role
84
+ select_all_by_role(role).each(&:delete)
85
+ end
111
86
 
112
- # Register an nfs server share
113
- def self.register_nfs_share server_path, client_path=nil, role='nfs_server'
114
- client_path ||= server_path
115
- register(role, :server_path => server_path, :client_path => client_path)
116
- end
87
+ #
88
+ # Registration attributes
89
+ #
117
90
 
118
- # NFS: device path, for stuffing into /etc/fstab
119
- def self.nfs_device_path role='nfs_server'
120
- nfs_server = host(role) or return
121
- [nfs_server.private_ip, nfs_server[:server_path]].join(':')
122
- end
91
+ def self.my_private_ip() OHAI_INFO[:cloud][:private_ips].first rescue nil ; end
92
+ def self.my_public_ip() OHAI_INFO[:cloud][:public_ips].first rescue nil ; end
93
+ def self.my_default_ip() OHAI_INFO[:ipaddress] ; end
94
+ def self.my_fqdn() OHAI_INFO[:fqdn] ; end
95
+ def self.my_availability_zone() OHAI_INFO[:ec2][:availability_zone] ; end
96
+ def self.timestamp() Time.now.utc.strftime("%Y%m%d%H%M%S") ; end
97
+
98
+ def private_ip() self['private_ip' ] || default_ip ; end
99
+ def public_ip() self['public_ip' ] || default_ip ; end
100
+ def default_ip() self['default_ip' ] ; end
101
+ def fqdn() self['fqdn' ] ; end
102
+ def availability_zone() self['availability_zone'] ; end
103
+ def idx()
104
+ self['idx']
105
+ end
123
106
 
124
- # Hadoop: master jobtracker node
125
- def self.hadoop_jobtracker(role='hadoop_jobtracker') ; host(role) ; end
126
- # Hadoop: master namenode
127
- def self.hadoop_namenode( role='hadoop_namenode') ; host(role) ; end
128
- # Hadoop: cloudera desktop node
129
- def self.cloudera_desktop( role='cloudera_desktop') ; host(role) ; end
107
+ def self.establish_connection
108
+ @connection ||= RightAws::ActiveSdb.establish_connection(Settings[:access_key], Settings[:secret_access_key])
109
+ end
130
110
 
131
- def to_hash() attributes ; end
132
- def to_pretty_json
133
- to_hash.reject{|k,v| k.to_s == 'id'}.to_json
134
- end
111
+ # Register an nfs server share
112
+ def self.register_nfs_share server_path, client_path=nil, role='nfs_server'
113
+ client_path ||= server_path
114
+ register(role, :server_path => server_path, :client_path => client_path)
115
+ end
135
116
 
117
+ # NFS: device path, for stuffing into /etc/fstab
118
+ def self.nfs_device_path role='nfs_server'
119
+ nfs_server = host(role) or return
120
+ [nfs_server.private_ip, nfs_server[:server_path]].join(':')
136
121
  end
137
122
 
123
+ # Hadoop: master jobtracker node
124
+ def self.hadoop_jobtracker(role='hadoop_jobtracker') ; host(role) ; end
125
+ # Hadoop: master namenode
126
+ def self.hadoop_namenode( role='hadoop_namenode') ; host(role) ; end
127
+ # Hadoop: cloudera desktop node
128
+ def self.cloudera_desktop( role='cloudera_desktop') ; host(role) ; end
138
129
 
139
- #
140
- # Metaprogramming
141
- #
142
- def self.new cluster
143
- cluster_klass = '::'+Extlib::Inflection.classify(cluster.to_s)
144
- module_eval(%Q{ class #{cluster_klass} < Broham::Cluster ; end })
145
- cluster_klass.constantize rescue nil
130
+ def to_hash() attributes ; end
131
+ def to_pretty_json
132
+ to_hash.reject{|k,v| k.to_s == 'id'}.to_json
146
133
  end
134
+
147
135
  end
148
136
 
137
+
138
+ # #
139
+ # # Metaprogramming
140
+ # #
141
+ # def self.new cluster
142
+ # cluster_klass = '::'+Extlib::Inflection.classify(cluster.to_s)
143
+ # module_eval(%Q{ class #{cluster_klass} < Broham::Cluster ; end })
144
+ # cluster_klass.constantize rescue nil
145
+ # end
146
+
@@ -1,21 +1,17 @@
1
- module Broham
1
+ class Broham < RightAws::ActiveSdb::Base
2
2
 
3
3
  def self.get_cluster_settings
4
4
  Configliere.use :commandline, :config_file
5
5
  Settings.read('broham.yaml')
6
6
  Settings.resolve!
7
- Settings[:cluster_name] = Settings.rest.shift
8
7
  Settings[:role_name] = Settings.rest.shift
9
8
  check_args!
10
- cluster = Broham.new(Settings[:cluster_name])
11
- cluster.establish_connection
12
- cluster.create_domain
13
- cluster
9
+ self.establish_connection
14
10
  end
15
11
 
16
12
  def self.check_args!
17
- if (Settings[:cluster_name].blank? || Settings[:role_name].blank?)
18
- warn "Please supply a cluster name and a role as the first two arguments"
13
+ if Settings[:role_name].blank?
14
+ warn "Please supply a role as the first argument"
19
15
  exit(-1)
20
16
  end
21
17
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Philip (flip) Kromer
@@ -49,7 +49,9 @@ executables:
49
49
  - broham-host
50
50
  - broham-register
51
51
  - broham-register_as_next
52
+ - broham-sup
52
53
  - broham-unregister-all
54
+ - broham-yo
53
55
  extensions: []
54
56
 
55
57
  extra_rdoc_files:
@@ -65,7 +67,9 @@ files:
65
67
  - bin/broham-host
66
68
  - bin/broham-register
67
69
  - bin/broham-register_as_next
70
+ - bin/broham-sup
68
71
  - bin/broham-unregister-all
72
+ - bin/broham-yo
69
73
  - broham.gemspec
70
74
  - lib/broham.rb
71
75
  - lib/broham/script.rb