broham 0.0.0
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/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/broham.gemspec +58 -0
- data/lib/broham.rb +117 -0
- data/spec/broham_spec.rb +7 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +99 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Philip (flip) Kromer
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= broham
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Philip (flip) Kromer. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "broham"
|
8
|
+
gem.summary = %Q{Broham: A simple, global, highly-available, none-too-bright service registry. Broham always knows where his bros are, bro.}
|
9
|
+
gem.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}
|
10
|
+
gem.email = "flip@infochimps.org"
|
11
|
+
gem.homepage = "http://github.com/mrflip/broham"
|
12
|
+
gem.authors = ["Philip (flip) Kromer"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
gem.add_development_dependency "yard", ">= 0"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
begin
|
39
|
+
require 'yard'
|
40
|
+
YARD::Rake::YardocTask.new
|
41
|
+
rescue LoadError
|
42
|
+
task :yardoc do
|
43
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
44
|
+
end
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/broham.gemspec
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{broham}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Philip (flip) Kromer"]
|
12
|
+
s.date = %q{2010-04-05}
|
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
|
+
s.email = %q{flip@infochimps.org}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"broham.gemspec",
|
27
|
+
"lib/broham.rb",
|
28
|
+
"spec/broham_spec.rb",
|
29
|
+
"spec/spec.opts",
|
30
|
+
"spec/spec_helper.rb"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/mrflip/broham}
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.6}
|
36
|
+
s.summary = %q{Broham: A simple, global, highly-available, none-too-bright service registry. Broham always knows where his bros are, bro.}
|
37
|
+
s.test_files = [
|
38
|
+
"spec/broham_spec.rb",
|
39
|
+
"spec/spec_helper.rb"
|
40
|
+
]
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
48
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
51
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
52
|
+
end
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
55
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
data/lib/broham.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
require './settings.rb'
|
2
|
+
require 'right_aws'
|
3
|
+
RightAws::SdbInterface::API_VERSION = '2009-04-15'
|
4
|
+
require 'sdb/active_sdb'
|
5
|
+
require 'ohai'
|
6
|
+
OHAI_INFO = Ohai::System.new unless defined?(OHAI_INFO)
|
7
|
+
OHAI_INFO.all_plugins
|
8
|
+
|
9
|
+
#
|
10
|
+
# Make sure you are using a recent (>= 1.11,0) version of right_aws, and set the
|
11
|
+
# SDB_API_VERSION environment variable to '2009-04-15':
|
12
|
+
# export SDB_API_VERSION='2009-04-15'
|
13
|
+
#
|
14
|
+
|
15
|
+
#
|
16
|
+
#
|
17
|
+
#
|
18
|
+
class Broham < RightAws::ActiveSdb::Base
|
19
|
+
# Returns the last-registered host in the given role
|
20
|
+
def self.host role
|
21
|
+
select_by_role(role, :order => 'timestamp DESC')
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns all hosts in the given role
|
25
|
+
def self.hosts role
|
26
|
+
select_all_by_role(role, :order => 'timestamp DESC')
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.register role, attrs={}
|
30
|
+
ahost = host(role) || new
|
31
|
+
ahost.attributes = ({:role => role, :timestamp => timestamp,
|
32
|
+
:private_ip => my_private_ip, :public_ip => my_public_ip, :default_ip => my_default_ip,
|
33
|
+
:fqdn => my_fqdn}.merge(attrs))
|
34
|
+
success = ahost.save
|
35
|
+
success ? self.new(success) : false
|
36
|
+
end
|
37
|
+
|
38
|
+
def yo!(*args) register *args ; end
|
39
|
+
def sup?(*args) host *args ; end
|
40
|
+
def sup_bros?(*args) hosts *args ; end
|
41
|
+
|
42
|
+
|
43
|
+
#
|
44
|
+
# Enlists as the next among many machines filling the given role.
|
45
|
+
#
|
46
|
+
# This is just a simple counter: it doesn't check whether the machine is
|
47
|
+
# already enlisted under a different index, or whether there are missing
|
48
|
+
# indices.
|
49
|
+
#
|
50
|
+
# It uses conditional save to be sure that the count is consistent
|
51
|
+
#
|
52
|
+
def self.register_as_next role, attrs={}
|
53
|
+
my_idx = 0
|
54
|
+
100.times do
|
55
|
+
ahost = host(role) || new
|
56
|
+
current_max_idx = ahost[:idx] && ahost[:idx].first
|
57
|
+
my_idx = (current_max_idx.to_i + 1)
|
58
|
+
ahost.attributes = ({:role => role, :timestamp => timestamp, :idx => my_idx.to_s }.merge(attrs))
|
59
|
+
expected = current_max_idx ? {:idx => (current_max_idx.to_i + rand(5)).to_s} : {}
|
60
|
+
success = ahost.save_if(expected)
|
61
|
+
break if success
|
62
|
+
end
|
63
|
+
register role+'-'+my_idx.to_s, { :idx => my_idx }.merge(attrs)
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# Removes all registrations for the given role
|
68
|
+
#
|
69
|
+
def self.unregister_all role
|
70
|
+
select_all_by_role(role).each(&:delete)
|
71
|
+
end
|
72
|
+
|
73
|
+
#
|
74
|
+
# Registration attributes
|
75
|
+
#
|
76
|
+
|
77
|
+
def self.my_private_ip() OHAI_INFO[:cloud][:private_ips].first rescue nil ; end
|
78
|
+
def self.my_public_ip() OHAI_INFO[:cloud][:public_ips].first rescue nil ; end
|
79
|
+
def self.my_default_ip() OHAI_INFO[:ipaddress] ; end
|
80
|
+
def self.my_fqdn() OHAI_INFO[:fqdn] ; end
|
81
|
+
def self.my_availability_zone() OHAI_INFO[:ec2][:availability_zone] ; end
|
82
|
+
def self.timestamp() Time.now.utc.strftime("%Y%m%d%H%M%S") ; end
|
83
|
+
|
84
|
+
def private_ip() self['private_ip' ] ; end
|
85
|
+
def public_ip() self['public_ip' ] ; end
|
86
|
+
def default_ip() self['default_ip' ] ; end
|
87
|
+
def fqdn() self['fqdn' ] ; end
|
88
|
+
def availability_zone() self['availability_zone'] ; end
|
89
|
+
def idx() self['idx']
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.establish_connection
|
93
|
+
@connection ||= RightAws::ActiveSdb.establish_connection(Settings[:access_key], Settings[:secret_access_key])
|
94
|
+
end
|
95
|
+
|
96
|
+
#
|
97
|
+
#
|
98
|
+
#
|
99
|
+
|
100
|
+
# NFS: device path, for stuffing into /etc/fstab
|
101
|
+
def self.nfs_device_path role='nfs_server'
|
102
|
+
nfs_server = host(role) or return
|
103
|
+
[nfs_server[:private_ip], nfs_server[:remote_path]].join(':')
|
104
|
+
end
|
105
|
+
|
106
|
+
# Hadoop: master jobtracker node
|
107
|
+
def self.hadoop_jobtracker(role='hadoop_jobtracker') ; host(role) ; end
|
108
|
+
# Hadoop: master namenode
|
109
|
+
def self.hadoop_namenode( role='hadoop_namenode') ; host(role) ; end
|
110
|
+
# Hadoop: cloudera desktop node
|
111
|
+
def self.cloudera_desktop( role='cloudera_desktop') ; host(role) ; end
|
112
|
+
|
113
|
+
def to_hash() attributes ; end
|
114
|
+
end
|
115
|
+
|
116
|
+
Broham.establish_connection
|
117
|
+
Broham.create_domain
|
data/spec/broham_spec.rb
ADDED
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: broham
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 0.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Philip (flip) Kromer
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-05 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 2
|
30
|
+
- 9
|
31
|
+
version: 1.2.9
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: yard
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :development
|
45
|
+
version_requirements: *id002
|
46
|
+
description: "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"
|
47
|
+
email: flip@infochimps.org
|
48
|
+
executables: []
|
49
|
+
|
50
|
+
extensions: []
|
51
|
+
|
52
|
+
extra_rdoc_files:
|
53
|
+
- LICENSE
|
54
|
+
- README.rdoc
|
55
|
+
files:
|
56
|
+
- .document
|
57
|
+
- .gitignore
|
58
|
+
- LICENSE
|
59
|
+
- README.rdoc
|
60
|
+
- Rakefile
|
61
|
+
- VERSION
|
62
|
+
- broham.gemspec
|
63
|
+
- lib/broham.rb
|
64
|
+
- spec/broham_spec.rb
|
65
|
+
- spec/spec.opts
|
66
|
+
- spec/spec_helper.rb
|
67
|
+
has_rdoc: true
|
68
|
+
homepage: http://github.com/mrflip/broham
|
69
|
+
licenses: []
|
70
|
+
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options:
|
73
|
+
- --charset=UTF-8
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
requirements: []
|
91
|
+
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.3.6
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: "Broham: A simple, global, highly-available, none-too-bright service registry. Broham always knows where his bros are, bro."
|
97
|
+
test_files:
|
98
|
+
- spec/broham_spec.rb
|
99
|
+
- spec/spec_helper.rb
|