class CouchDB::Provisioner

Public Class Methods

config_class() click to toggle source
# File lib/couchdb/couchdb_replicator/provisioner.rb, line 50
def self.config_class
  Config
end

Public Instance Methods

configure(root_config) click to toggle source
# File lib/couchdb/couchdb_replicator/provisioner.rb, line 4
def configure(root_config)
  @to_be_copied = []
  config.dbhosts.each do |conf|
    @to_be_copied << conf
    conf.prepare root_config.vm, tmp_root
  end
end
provision() click to toggle source
# File lib/couchdb/couchdb_replicator/provisioner.rb, line 11
def provision
  couchHosts = config.dbHosts

  firstDB = true
  couchHosts.each do |couchHost|

    firstCouch = Couch::Server.new(couchHost, "5984")
    if firstDB
      #res = firstCouch.get("/ss")
      #raise
      #json = res.body
      #puts json
      #firstCouch.put("/sofa/", "")
      #firstDB = false
    end

    replicateFromURL = "http://" + couchHost + ":5984/sofa"
    puts "createServer:" + couchHost + ":5984/sofa"

    couchHosts.each do |replicateTo|
      if replicateTo != couchHost

        #secondCouch = Couch::Server.new(replicateTo, "5984")

        replicateToURL = "http://" + replicateTo + ":5984/sofa"
        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

Private Instance Methods

db_hosts() click to toggle source
# File lib/couchdb/couchdb_replicator/provisioner.rb, line 60
def db_hosts
  config.dbhosts || []
end
tmp_root() click to toggle source
# File lib/couchdb/couchdb_replicator/provisioner.rb, line 56
def tmp_root
  "/tmp/copy_my_conf"
end