couchdb-replicator 0.0.1

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.
@@ -0,0 +1,13 @@
1
+ module Couchdb
2
+ class Config < Vagrant.plugin(2, :config)
3
+ attr_accessor :dbhosts
4
+
5
+ def initialize
6
+ @dbhosts = UNSET_VALUE
7
+ end
8
+
9
+ def finalize!
10
+ @dbhosts = 0 if @dbhosts == UNSET_VALUE
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,50 @@
1
+ #http://wiki.apache.org/couchdb/Getting_started_with_Ruby
2
+ require 'net/http'
3
+
4
+ module Couch
5
+
6
+ class Server
7
+ def initialize(host, port, options = nil)
8
+ @host = host
9
+ @port = port
10
+ @options = options
11
+ end
12
+
13
+ def delete(uri)
14
+ request(Net::HTTP::Delete.new(uri))
15
+ end
16
+
17
+ def get(uri)
18
+ request(Net::HTTP::Get.new(uri))
19
+ end
20
+
21
+ def put(uri, json)
22
+ req = Net::HTTP::Put.new(uri)
23
+ req["content-type"] = "application/json"
24
+ req.body = json
25
+ request(req)
26
+ end
27
+
28
+ def post(uri, json)
29
+ req = Net::HTTP::Post.new(uri)
30
+ req["content-type"] = "application/json"
31
+ req.body = json
32
+ request(req)
33
+ end
34
+
35
+ def request(req)
36
+ res = Net::HTTP.start(@host, @port) { |http|http.request(req) }
37
+ unless res.kind_of?(Net::HTTPSuccess)
38
+ handle_error(req, res)
39
+ end
40
+ res
41
+ end
42
+
43
+ private
44
+
45
+ def handle_error(req, res)
46
+ e = RuntimeError.new("#{res.code}:#{res.message}\nMETHOD:#{req.method}\nURI:#{req.path}\n#{res.body}")
47
+ raise e
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,51 @@
1
+ module CouchDB
2
+ class Provisioner < Vagrant.plugin("2", :provisioner)
3
+
4
+ def configure(root_config)
5
+ end
6
+
7
+ def provision
8
+ begin
9
+ couchHosts = config.dbHosts
10
+
11
+ firstDB = true
12
+ couchHosts.each do |couchHost|
13
+
14
+ firstCouch = Couch::Server.new(couchHost, "5984")
15
+ if firstDB
16
+ #res = firstCouch.get("/ss")
17
+ #raise
18
+ #json = res.body
19
+ #puts json
20
+ #firstCouch.put("/sofa/", "")
21
+ #firstDB = false
22
+ end
23
+
24
+ replicateFromURL = "http://" + couchHost + ":5984/sofa"
25
+ puts "createServer:" + couchHost + ":5984/sofa"
26
+
27
+ couchHosts.each do |replicateTo|
28
+ if replicateTo != couchHost
29
+
30
+ #secondCouch = Couch::Server.new(replicateTo, "5984")
31
+
32
+ replicateToURL = "http://" + replicateTo + ":5984/sofa"
33
+ payload = '{ "source":' + '"' + replicateFromURL + '"' + ',' +
34
+ ' "target":' + '"' + replicateToURL + '"' + ',' +
35
+ ' "continuous": true,' +
36
+ ' "create_target": true' +
37
+ '}'
38
+ replicateJSON = JSON.parse(payload)
39
+ puts replicateJSON
40
+
41
+ firstCouch.post("/_replicate", replicateJSON.to_json)
42
+ end
43
+ end
44
+ end
45
+ rescue
46
+ puts 'I am rescued.'
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,5 @@
1
+ module Couchdb
2
+ module Replicator
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ require "couchdb/replicator/version"
2
+
3
+ module Couchdb
4
+ class Plugin < Vagrant.plugin("2")
5
+ name "couchdb_replicator"
6
+
7
+ config(:couchdb_replicator, :provisioner) do
8
+ require File.expand_path('../couchdb_replicator/config', __FILE__)
9
+ Config
10
+ end
11
+
12
+ provisioner :couchdb_replicator do
13
+ require File.expand_path('../couchdb_replicator/provisioner', __FILE__)
14
+ Provisioner
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: couchdb-replicator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - mike.feher@arisalex.com
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-08-31 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: This is a couchdb replicator
15
+ email:
16
+ - mike.feher@arisalex.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/couchdb/couchdb_replicator/provisioner.rb
22
+ - lib/couchdb/couchdb_replicator/version.rb
23
+ - lib/couchdb/couchdb_replicator/couch.rb
24
+ - lib/couchdb/couchdb_replicator/config.rb
25
+ - lib/couchdb/couchdb_replicator.rb
26
+ homepage: ''
27
+ licenses:
28
+ - MIT
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ segments:
40
+ - 0
41
+ hash: 2813997312785440634
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ segments:
49
+ - 0
50
+ hash: 2813997312785440634
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.23
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Use this to replicate to couch instances
57
+ test_files: []