couch-replicate 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +23 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/bin/couch-replicate +11 -0
- data/lib/couch_replicate.rb +26 -0
- data/lib/couch_replicate/command_line.rb +61 -0
- data/spec/couch_replicate_spec.rb +70 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- metadata +87 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 eee-c
|
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,23 @@
|
|
1
|
+
= couch-replicate
|
2
|
+
|
3
|
+
Setup replication between CouchDB hosts.
|
4
|
+
|
5
|
+
From the command line:
|
6
|
+
|
7
|
+
couch-replicate db_name http://couch01.local:5984 http://couch02.local:5984 ...
|
8
|
+
|
9
|
+
Available options are --link, --reverse, -n
|
10
|
+
|
11
|
+
== Note on Patches/Pull Requests
|
12
|
+
|
13
|
+
* Fork the project.
|
14
|
+
* Make your feature addition or bug fix.
|
15
|
+
* Add tests for it. This is important so I don't break it in a
|
16
|
+
future version unintentionally.
|
17
|
+
* Commit, do not mess with rakefile, version, or history.
|
18
|
+
(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)
|
19
|
+
* Send me a pull request. Bonus points for topic branches.
|
20
|
+
|
21
|
+
== Copyright
|
22
|
+
|
23
|
+
Copyright (c) 2010 eee-c. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "couch-replicate"
|
8
|
+
gem.summary = %Q{Set-up automatic CouchDB replication between hosts}
|
9
|
+
gem.description = %Q{Command line and ruby interface for linking a set of CouchDB hosts for automatic replication. Includes three rudimentary replication schemes: cicular link, reverse cicular link and link to every nth host.}
|
10
|
+
gem.email = "github@eeecooks.com"
|
11
|
+
gem.homepage = "http://github.com/eee-c/couch-replicate"
|
12
|
+
gem.authors = ["Chris Strom"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
gem.add_dependency "rest-client", ">= 1.4.2"
|
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
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
43
|
+
rdoc.title = "couch-replicate #{version}"
|
44
|
+
rdoc.rdoc_files.include('README*')
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/bin/couch-replicate
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
require File.expand_path(
|
6
|
+
File.join(File.dirname(__FILE__), %w[.. lib couch_replicate]))
|
7
|
+
|
8
|
+
require File.expand_path(
|
9
|
+
File.join(File.dirname(__FILE__), %w[.. lib couch_replicate command_line]))
|
10
|
+
|
11
|
+
CouchReplicate::CommandLine.run ARGV
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'restclient'
|
2
|
+
|
3
|
+
module CouchReplicate
|
4
|
+
|
5
|
+
def self.replicate(source_host, target_host, db)
|
6
|
+
RestClient.post("#{source_host}/_replicate",
|
7
|
+
%Q|{"source":"#{db}", "target":"#{target_host}/#{db}", "continuous":true}|)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.link(db, hosts)
|
11
|
+
Array(hosts).each_cons(2) do |src, target|
|
12
|
+
self.replicate(src, target, db)
|
13
|
+
end
|
14
|
+
self.replicate(hosts.last, hosts.first, db)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.reverse_link(db, hosts)
|
18
|
+
self.link(db, hosts.reverse)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.nth(n, db, hosts)
|
22
|
+
(Array(hosts) + Array(hosts)[0..n]).each_cons(n+1) do |src, *n_hosts|
|
23
|
+
self.replicate(src, n_hosts.last, db)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'pp'
|
3
|
+
|
4
|
+
module CouchReplicate
|
5
|
+
class CommandLine
|
6
|
+
def self.run(*args)
|
7
|
+
CommandLine.new(*args).run
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :database, :hosts, :options
|
11
|
+
|
12
|
+
def initialize(args)
|
13
|
+
parse_options(args)
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
if @options[:link] || @options.empty?
|
18
|
+
$stderr.puts "Linking replication hosts..."
|
19
|
+
CouchReplicate.link(@database, @hosts)
|
20
|
+
end
|
21
|
+
if @options[:reverse]
|
22
|
+
$stderr.puts "Reverse linking replication hosts..."
|
23
|
+
CouchReplicate.reverse_link(@database, @hosts)
|
24
|
+
end
|
25
|
+
if @options[:n]
|
26
|
+
$stderr.puts "Linking every #{@options[:n]}th replication hosts..."
|
27
|
+
CouchReplicate.nth(@options[:n], @database, @hosts)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse_options(args)
|
32
|
+
@options = { }
|
33
|
+
|
34
|
+
options_parser = OptionParser.new do |opts|
|
35
|
+
opts.banner = "Usage: couch-replicate db [OPTIONS] couchdb_host_01, couchdb_host_02[, couchdb_host_03...]"
|
36
|
+
|
37
|
+
opts.separator ""
|
38
|
+
|
39
|
+
opts.on("-l", "--link", "link the hosts in a circular list (this is the default if no other options are specified)") do
|
40
|
+
@options[:link] = true
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.on("-r", "--reverse", "link the hosts in a cicular list, reversing the order supplied") do
|
44
|
+
@options[:reverse] = true
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.on("-n", "-number [LINK_EVERY=3]", "link every n hosts") do |n|
|
48
|
+
@options[:n] = n.to_i > 0 ? n.to_i : 3
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
begin
|
53
|
+
options_parser.parse!(args)
|
54
|
+
@database = args.shift
|
55
|
+
@hosts = args
|
56
|
+
rescue OptionParser::InvalidOption => e
|
57
|
+
raise e
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "CouchReplicate" do
|
4
|
+
before(:each) do
|
5
|
+
@src_host = 'http://couch01.example.org:5984'
|
6
|
+
@target_host = 'http://couch02.example.org:5984'
|
7
|
+
@db = 'test'
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be able to tell a node to replicate itself" do
|
11
|
+
RestClient.
|
12
|
+
should_receive(:post).
|
13
|
+
with("#{@src_host}/_replicate",
|
14
|
+
%Q|{"source":"#{@db}", "target":"#{@target_host}/#{@db}", "continuous":true}|)
|
15
|
+
|
16
|
+
CouchReplicate.replicate(@src_host, @target_host, @db)
|
17
|
+
end
|
18
|
+
|
19
|
+
context "replicating to multiple hosts" do
|
20
|
+
before(:each) do
|
21
|
+
@host01 = 'http://couch01.example.org:5984'
|
22
|
+
@host02 = 'http://couch02.example.org:5984'
|
23
|
+
@host03 = 'http://couch03.example.org:5984'
|
24
|
+
@host04 = 'http://couch04.example.org:5984'
|
25
|
+
@host05 = 'http://couch05.example.org:5984'
|
26
|
+
|
27
|
+
CouchReplicate.stub!(:replicate)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should replicate in a circle" do
|
31
|
+
CouchReplicate.
|
32
|
+
should_receive(:replicate).
|
33
|
+
with(@host03, @host01, @db)
|
34
|
+
|
35
|
+
CouchReplicate.link(@db, [@host01, @host02, @host03])
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should replicate in pairs" do
|
39
|
+
CouchReplicate.
|
40
|
+
should_receive(:replicate).
|
41
|
+
with(@host02, @host03, @db)
|
42
|
+
|
43
|
+
CouchReplicate.link(@db, [@host01, @host02, @host03])
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should be able to reverse link" do
|
47
|
+
CouchReplicate.
|
48
|
+
should_receive(:link).
|
49
|
+
with(@db, [@host03, @host02, @host01])
|
50
|
+
|
51
|
+
CouchReplicate.reverse_link(@db, [@host01, @host02, @host03])
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should replicate nth host" do
|
55
|
+
CouchReplicate.
|
56
|
+
should_receive(:replicate).
|
57
|
+
with(@host02, @host05, @db)
|
58
|
+
|
59
|
+
CouchReplicate.nth(3, @db, [@host01, @host02, @host03, @host04, @host05])
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should replicate nth host in a circle" do
|
63
|
+
CouchReplicate.
|
64
|
+
should_receive(:replicate).
|
65
|
+
with(@host05, @host03, @db)
|
66
|
+
|
67
|
+
CouchReplicate.nth(3, @db, [@host01, @host02, @host03, @host04, @host05])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: couch-replicate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Strom
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-03-21 00:00:00 -04:00
|
13
|
+
default_executable: couch-replicate
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.9
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rest-client
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.4.2
|
34
|
+
version:
|
35
|
+
description: "Command line and ruby interface for linking a set of CouchDB hosts for automatic replication. Includes three rudimentary replication schemes: cicular link, reverse cicular link and link to every nth host."
|
36
|
+
email: github@eeecooks.com
|
37
|
+
executables:
|
38
|
+
- couch-replicate
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- bin/couch-replicate
|
52
|
+
- lib/couch_replicate.rb
|
53
|
+
- lib/couch_replicate/command_line.rb
|
54
|
+
- spec/couch_replicate_spec.rb
|
55
|
+
- spec/spec.opts
|
56
|
+
- spec/spec_helper.rb
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: http://github.com/eee-c/couch-replicate
|
59
|
+
licenses: []
|
60
|
+
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- --charset=UTF-8
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.3.5
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Set-up automatic CouchDB replication between hosts
|
85
|
+
test_files:
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
- spec/couch_replicate_spec.rb
|