summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorazul <azul@leap.se>2014-07-01 09:41:29 +0200
committerazul <azul@leap.se>2014-07-01 09:41:29 +0200
commit478cd9faf5fb78b2f9905ec098827d4c4188c19d (patch)
treee5350de662651b57e6c2b71bf17c4018a2f9e3fa
parent3c431ed42419dd55fc4064133b899cb494278051 (diff)
parent54cd8bcaf762b85b7f60ced0a87be4b77be263a9 (diff)
Merge pull request #16 from azul/feature/replication
minor replication fixes
-rwxr-xr-xbin/tapicero2
-rw-r--r--lib/tapicero/replication.rb33
-rw-r--r--lib/tapicero/user_database.rb6
3 files changed, 24 insertions, 17 deletions
diff --git a/bin/tapicero b/bin/tapicero
index 49e73c2..658dace 100755
--- a/bin/tapicero
+++ b/bin/tapicero
@@ -51,7 +51,7 @@ Tapicero::CONFIGS.concat ARGV.grep(/\.ya?ml$/)
# if flags have been set but an action is missing we assume
# tapicero should run in foreground.
-if ARGV.first.start_with?('--')
+if ARGV.first && ARGV.first.start_with?('--')
ARGV.unshift '--'
ARGV.unshift 'run'
end
diff --git a/lib/tapicero/replication.rb b/lib/tapicero/replication.rb
index 1a2db22..2d9b842 100644
--- a/lib/tapicero/replication.rb
+++ b/lib/tapicero/replication.rb
@@ -4,6 +4,8 @@ require 'json'
module Tapicero
class Replication
+ attr_reader :source, :target
+
LocalEndpoint = Struct.new(:name) do
def key; name; end
def url; name; end
@@ -14,11 +16,11 @@ module Tapicero
def key; domain; end
def url; "http://#{creds}@#{domain}:#{port}/#{name}"; end
def save_url; "http://#{username}@#{domain}:#{port}/#{name}"; end
- def domain; remote[:internal_domain]; end
- def port; remote[:couch_port]; end
- def name; remote[:name]; end
- def creds; username + ':' + credentials[:password]; end
- def username; credentials[:username]; end
+ def domain; remote["domain_internal"]; end
+ def port; remote["couch_port"]; end
+ def name; remote["name"]; end
+ def creds; username + ':' + credentials["password"]; end
+ def username; credentials["username"]; end
end
def initialize(source, target)
@@ -27,18 +29,18 @@ module Tapicero
end
def run(options)
- Tapicero.logger.debug "Replicating from #{source.save_url} to #{target.save_url}."
+ Tapicero.logger.info "Replicating from #{source.save_url} to #{target.save_url}."
replication_db.save_doc replication_doc.merge(options)
end
def replication_doc
{
- _id: "#{source.key}_to_#{target.key}"
- source: source.url,
- target: target.url,
- user_ctx: {
- name: replication_credentials[:username],
- roles: [replication_credentials[:role]]
+ "_id" => source.domain.gsub('.', '_'),
+ "source" => source.url,
+ "target" => target.url,
+ "user_ctx" => {
+ name: replication_credentials["username"],
+ roles: [replication_credentials["role"]]
}
}
end
@@ -46,13 +48,15 @@ module Tapicero
protected
def endpoint_for(hash_or_string)
- hash_or_string.respond_to? :[] ?
+ hash_or_string.respond_to?(:keys) ?
RemoteEndpoint.new(hash_or_string, replication_credentials) :
LocalEndpoint.new(hash_or_string)
end
def replication_credentials
- config.options[:replication].slice(:username, :password, :role)
+ config.options[:replication].select do |k,v|
+ %w/username password role/.include? k
+ end
end
def replication_db
@@ -67,4 +71,5 @@ module Tapicero
Tapicero.config
end
+ end
end
diff --git a/lib/tapicero/user_database.rb b/lib/tapicero/user_database.rb
index 4061292..7e205ad 100644
--- a/lib/tapicero/user_database.rb
+++ b/lib/tapicero/user_database.rb
@@ -1,5 +1,6 @@
require 'couchrest'
require 'json'
+require 'tapicero/replication'
module Tapicero
class UserDatabase
@@ -27,9 +28,10 @@ module Tapicero
def replicate()
return unless config.options[:mode] == 'mirror'
replication = config.options[:replication]
- replication[:masters].each do |key, node|
+ replication["masters"].each do |key, node|
+ node["name"] = name
retry_request_once "Replicating" do
- Replication.new(source, name).run continuous: true
+ Tapicero::Replication.new(node, name).run continuous: true
end
end
end