7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/couchdbSync/provisioner.rb', line 7
def provision
puts config.dbhosts
couchHosts = config.dbhosts
couchDB = config.couchdb
firstDB = true
couchHosts.each do |couchHost|
firstCouch = Couch::Server.new(couchHost, "5984")
if firstDB
begin
res = firstCouch.get("/" + couchDB)
json = res.body
puts json
rescue
firstCouch.put("/"+ couchDB +"/", "")
firstDB = false
end
end
replicateFromURL = "http://" + couchHost + ":5984/" + couchDB
puts "createServer:" + couchHost + ":5984/" + couchDB
couchHosts.each do |replicateTo|
if replicateTo != couchHost
replicateToURL = "http://" + replicateTo + ":5984/" + couchDB
payload = '{ "source":' + '"' + replicateFromURL + '"' + ',' +
' "target":' + '"' + replicateToURL + '"' + ',' +
' "continuous": true,' +
' "create_target": true' +
'}'
replicateJSON = JSON.parse(payload)
puts replicateJSON
firstCouch.post("/_replicate", replicateJSON.to_json)
end
end
end
end
|