couchdbSync 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.
- checksums.yaml +7 -0
- data/lib/couchdbSync.rb +17 -0
- data/lib/couchdbSync/config.rb +6 -0
- data/lib/couchdbSync/couch.rb +50 -0
- data/lib/couchdbSync/provisioner.rb +49 -0
- data/lib/couchdbSync/version.rb +3 -0
- metadata +49 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 3d448dc5c0a057f5c1e6af866d0cf78cb6d74482
         | 
| 4 | 
            +
              data.tar.gz: fdca769f75107f4d0586dc5a6152f11f12b7666e
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 1c372d95bce541c6b8561229d131f304e7ca700ccd3890090927128afb86a1113eca49e71d0e63646e82440089b2b305c0d8702da4dfba30625ea412df9a850a
         | 
| 7 | 
            +
              data.tar.gz: 21dc28d4175410d40f462e7aedcb77a11c0f663ada4b72e4f388fdc19e902b70d0e741b2613ad6e3d0c9580e8f63ff43c87c1c1ff18f3777f2b42b86008b83e2
         | 
    
        data/lib/couchdbSync.rb
    ADDED
    
    | @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            module CouchdbSync
         | 
| 2 | 
            +
              class Plugin < Vagrant.plugin("2")
         | 
| 3 | 
            +
                name "couchdbSync"
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                config(:couchdbSync, :provisioner) do
         | 
| 6 | 
            +
                  require File.expand_path('../couchdbSync/config', __FILE__)
         | 
| 7 | 
            +
                  Config
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                provisioner :couchdbSync do
         | 
| 11 | 
            +
                  require File.expand_path('../couchdbSync/provisioner', __FILE__)
         | 
| 12 | 
            +
                  Provisioner
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            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,49 @@ | |
| 1 | 
            +
            require File.expand_path('../couch', __FILE__)
         | 
| 2 | 
            +
            module CouchdbSync
         | 
| 3 | 
            +
              class Provisioner < Vagrant.plugin("2", :provisioner)
         | 
| 4 | 
            +
                def configure(root_config)
         | 
| 5 | 
            +
                end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def provision
         | 
| 8 | 
            +
                  puts config.dbhosts
         | 
| 9 | 
            +
                  couchHosts = config.dbhosts
         | 
| 10 | 
            +
                  couchDB = config.couchdb
         | 
| 11 | 
            +
                  firstDB = true
         | 
| 12 | 
            +
                  couchHosts.each do |couchHost|
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                    firstCouch = Couch::Server.new(couchHost, "5984")
         | 
| 15 | 
            +
                    if firstDB
         | 
| 16 | 
            +
                      begin
         | 
| 17 | 
            +
                      res = firstCouch.get("/" + couchDB)
         | 
| 18 | 
            +
                      json = res.body
         | 
| 19 | 
            +
                      puts json
         | 
| 20 | 
            +
                      rescue
         | 
| 21 | 
            +
                        firstCouch.put("/"+ couchDB +"/", "")
         | 
| 22 | 
            +
                        firstDB = false
         | 
| 23 | 
            +
                      end
         | 
| 24 | 
            +
                    end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                    replicateFromURL = "http://" + couchHost + ":5984/" + couchDB
         | 
| 27 | 
            +
                    puts "createServer:" + couchHost + ":5984/" + couchDB
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                    couchHosts.each do |replicateTo|
         | 
| 30 | 
            +
                      if replicateTo != couchHost
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                        #secondCouch = Couch::Server.new(replicateTo, "5984")
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                        replicateToURL = "http://" + replicateTo + ":5984/" + couchDB
         | 
| 35 | 
            +
                        payload = '{ "source":' + '"' + replicateFromURL + '"' + ',' +
         | 
| 36 | 
            +
                            ' "target":' + '"' + replicateToURL + '"' + ',' +
         | 
| 37 | 
            +
                            ' "continuous": true,' +
         | 
| 38 | 
            +
                            ' "create_target": true' +
         | 
| 39 | 
            +
                            '}'
         | 
| 40 | 
            +
                        replicateJSON = JSON.parse(payload)
         | 
| 41 | 
            +
                        puts replicateJSON
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                        firstCouch.post("/_replicate", replicateJSON.to_json)
         | 
| 44 | 
            +
                      end
         | 
| 45 | 
            +
                    end
         | 
| 46 | 
            +
                  end
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
              end
         | 
| 49 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,49 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: couchdbSync
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.1
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - mike.feher@arisalex.com
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2014-09-01 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies: []
         | 
| 13 | 
            +
            description: OOOOOOYYEA
         | 
| 14 | 
            +
            email:
         | 
| 15 | 
            +
            - mike.feher@arisalex.com
         | 
| 16 | 
            +
            executables: []
         | 
| 17 | 
            +
            extensions: []
         | 
| 18 | 
            +
            extra_rdoc_files: []
         | 
| 19 | 
            +
            files:
         | 
| 20 | 
            +
            - lib/couchdbSync.rb
         | 
| 21 | 
            +
            - lib/couchdbSync/config.rb
         | 
| 22 | 
            +
            - lib/couchdbSync/couch.rb
         | 
| 23 | 
            +
            - lib/couchdbSync/provisioner.rb
         | 
| 24 | 
            +
            - lib/couchdbSync/version.rb
         | 
| 25 | 
            +
            homepage: ''
         | 
| 26 | 
            +
            licenses:
         | 
| 27 | 
            +
            - MIT
         | 
| 28 | 
            +
            metadata: {}
         | 
| 29 | 
            +
            post_install_message: 
         | 
| 30 | 
            +
            rdoc_options: []
         | 
| 31 | 
            +
            require_paths:
         | 
| 32 | 
            +
            - lib
         | 
| 33 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 34 | 
            +
              requirements:
         | 
| 35 | 
            +
              - - ">="
         | 
| 36 | 
            +
                - !ruby/object:Gem::Version
         | 
| 37 | 
            +
                  version: '0'
         | 
| 38 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 39 | 
            +
              requirements:
         | 
| 40 | 
            +
              - - ">="
         | 
| 41 | 
            +
                - !ruby/object:Gem::Version
         | 
| 42 | 
            +
                  version: '0'
         | 
| 43 | 
            +
            requirements: []
         | 
| 44 | 
            +
            rubyforge_project: 
         | 
| 45 | 
            +
            rubygems_version: 2.2.2
         | 
| 46 | 
            +
            signing_key: 
         | 
| 47 | 
            +
            specification_version: 4
         | 
| 48 | 
            +
            summary: Common
         | 
| 49 | 
            +
            test_files: []
         |