Permalink
Browse files

updated json responses for XDCR responder

  • Loading branch information...
1 parent 01e923b commit c503ca98c5ba17c17be44e4e32856e69aad88a6c @scalabl3 committed Nov 6, 2012
Showing with 139 additions and 94 deletions.
  1. +139 −94 xdcr.rb
View
233 xdcr.rb
@@ -3,16 +3,26 @@
require 'json'
require 'active_support'
+
+
basic_auth do
realm 'Give me password!'
username 'Administrator'
password 'ababab'
end
+
+
+XDCR_RECEIVER = "127.0.0.1"
+XDCR_PORT = 4567
+XDCR_BUCKET = "default"
UUID_POOL = "3b5211459ec34c589522f78c2284099e" #SecureRandom.uuid.gsub("-", "")
UUID_BUCKET = "9e4d14d5a9be45cba5ec5534f42e129b" #SecureRandom.uuid.gsub("-", "")
+VBucketMap = []
+1024.times { VBucketMap << [0,-1] }
+
+
-5.times { puts }
get '/pools' do
require_basic_auth
@@ -22,19 +32,21 @@
puts 'GET requested /pools'
puts params.inspect
- pool = {
- :pools => [
- {
+ out = {
+ :pools => [ {
:name => "default",
:uri => "/pools/default?uuid=#{UUID_POOL}",
- }],
+ } ],
:uuid => UUID_POOL
}
- puts pool.to_json
- pool.to_json
+ puts out.to_json
+ out.to_json
end
+
+
+
get '/pools/default' do
require_basic_auth
content_type :json
@@ -43,138 +55,171 @@
puts 'GET requested /pools/default'
puts params.inspect
- default_pool = {
- :name => "default",
- :buckets => { :uri => "/pools/default/buckets?uuid=#{UUID_POOL}" }
+ out = {
+ :buckets => { :uri => "/pools/default/buckets?uuid=#{UUID_POOL}" },
+ :nodes => [ {
+ :ports => {
+ :direct => XDCR_PORT
+ },
+ :couchApiBase => "http://#{XDCR_RECEIVER}:#{XDCR_PORT}/",
+ :hostname => "#{XDCR_RECEIVER}:#{XDCR_PORT}"
+ } ]
}
- puts default_pool.to_json
- default_pool.to_json
+ puts out.to_json
+ out.to_json
end
+
+
+
get '/pools/default/buckets' do
require_basic_auth
+ content_type :json
5.times { puts }
puts 'GET requested /pools/default/buckets'
+
+ out = [
+ {
+ :bucketCapabilities => [ "couchapi" ],
+ :bucketType => "membase",
+ :nodes => [ {
+ :ports => { :direct => XDCR_PORT },
+ :couchApiBase => "http://#{XDCR_RECEIVER}:#{XDCR_PORT}/#{XDCR_BUCKET}",
+ :hostname => "#{XDCR_RECEIVER}:#{XDCR_PORT}"
+ } ],
+ :name => XDCR_BUCKET,
+ :vBucketServerMap => {
+ :serverList => [ "#{XDCR_RECEIVER}:#{XDCR_PORT}" ],
+ :vBucketMap => VBucketMap
+ },
+ :uuid => "00000000000000000000000000000000",
+ :uri => "/pools/default/buckets/#{XDCR_BUCKET}?bucket_uuid=00000000000000000000000000000000"
+ }
+ ]
+ puts out.to_json
+ out.to_json
end
+
+
+
get '/pools/default/buckets/:bucket' do
require_basic_auth
+ content_type :json
+
+ 5.times { puts }
puts "GET requested /pools/buckets/#{params[:bucket]}"
+ out = [
+ {
+ :bucketCapabilities => [ "couchapi" ],
+ :bucketType => "membase",
+ :nodes => [ {
+ :ports => { :direct => XDCR_PORT },
+ :couchApiBase => "http://#{XDCR_RECEIVER}:#{XDCR_PORT}/#{XDCR_BUCKET}",
+ :hostname => "#{XDCR_RECEIVER}:#{XDCR_PORT}"
+ } ],
+ :name => XDCR_BUCKET,
+ :vBucketServerMap => {
+ :serverList => [ "#{XDCR_RECEIVER}:#{XDCR_PORT}" ],
+ :vBucketMap => vBucketMap
+ },
+ :uuid => "00000000000000000000000000000000",
+ :uri => "/pools/default/buckets/#{XDCR_BUCKET}?bucket_uuid=00000000000000000000000000000000"
+ }
+ ]
+
+ puts out.to_json
+ out.to_json
end
+
+
get '/:database' do #(HEAD, GET)
require_basic_auth
+ content_type :json
+
+ 5.times { puts }
puts "GET requested [database] /#{params[:database]}"
+
+
+ if params[:database] == XDCR_BUCKET
+ out = { :db_name => XDCR_BUCKET }
+ status 200
+
+ puts out.to_json
+ out.to_json
+ else
+ status 404
+ nil
+ end
end
+
+
+
get '/:database/:docid' do #(GET)
require_basic_auth
+ content_type :json
+
+ 5.times { puts }
puts "GET requested [database] /#{params[:database]}/#{params[:docid]}"
+ if params[:database] == XDCR_BUCKET
+ status 200
+ nil
+ else
+ status 404
+ nil
+ end
end
+
+
+
post '/:database/_ensure_full_commit' do #(POST)
require_basic_auth
+ content_type :json
+
+ 5.times { puts }
puts "POST requested [database] /#{params[:database]}/_ensure_full_commit"
+ status 201
+
+ out = { :ok => true }
+ puts out.to_json
+ out.to_json
end
+
+
+
post '/{database}/_revs_diff' do #(POST)
require_basic_auth
+ content_type :json
+
+ 5.times { puts }
puts "POST requested [database] /#{params[:database]}/_revs_diff"
+ status 201
+ nil
end
+
+
+
post '/:database/_bulk_docs' do #(POST)
require_basic_auth
+ content_type :json
+
+ 5.times { puts }
puts "POST requested [database] /#{params[:database]}/_bulk_docs"
+ status 201
+ nil
end
-
-=begin
-
-=begin
-0: {name:Humin, bucketType:membase, authType:sasl, saslPassword:, proxyPort:0, replicaIndex:false,…}
-authType: "sasl"
-autoCompactionSettings: false
-basicStats: {quotaPercentUsed:2.9049456119537354, opsPerSec:0, viewOps:0, diskFetches:0, itemCount:0,…}
-bucketCapabilities: [touch, couchapi]
-bucketCapabilitiesVer: ""
-bucketType: "membase"
-controllers: {flush:/pools/default/buckets/Humin/controller/doFlush,…}
-ddocs: {uri:/pools/default/buckets/Humin/ddocs}
-fastWarmupSettings: false
-localRandomKeyUri: "/pools/default/buckets/Humin/localRandomKey"
-name: "Humin"
-nodeLocator: "vbucket"
-nodes: [{systemStats:{cpu_utilization_rate:20.875, swap_total:9663676416, swap_used:8909201408},…}]
-proxyPort: 0
-quota: {ram:1073741824, rawRAM:1073741824}
-replicaIndex: false
-replicaNumber: 1
-saslPassword: ""
-stats: {uri:/pools/default/buckets/Humin/stats, directoryURI:/pools/default/buckets/Humin/statsDirectory,…}
-streamingUri: "/pools/default/bucketsStreaming/Humin?bucket_uuid=ff5e6309de6095b842f101813c5c1fa3"
-uri: "/pools/default/buckets/Humin?bucket_uuid=ff5e6309de6095b842f101813c5c1fa3"
-uuid: "ff5e6309de6095b842f101813c5c1fa3"
-vBucketServerMap: {hashAlgorithm:CRC, numReplicas:1, serverList:[127.0.0.1:11210],…}
-1: {name:cbfs, bucketType:membase, authType:sasl, saslPassword:, proxyPort:0, replicaIndex:false,…}
-authType: "sasl"
-autoCompactionSettings: false
-basicStats: {quotaPercentUsed:2.8981730341911316, opsPerSec:0, viewOps:0, diskFetches:0, itemCount:201,…}
-bucketCapabilities: [touch, couchapi]
-bucketCapabilitiesVer: ""
-bucketType: "membase"
-controllers: {flush:/pools/default/buckets/cbfs/controller/doFlush,…}
-ddocs: {uri:/pools/default/buckets/cbfs/ddocs}
-fastWarmupSettings: false
-localRandomKeyUri: "/pools/default/buckets/cbfs/localRandomKey"
-name: "cbfs"
-nodeLocator: "vbucket"
-nodes: [{systemStats:{cpu_utilization_rate:20.875, swap_total:9663676416, swap_used:8909201408},…}]
-proxyPort: 0
-quota: {ram:1073741824, rawRAM:1073741824}
-replicaIndex: false
-replicaNumber: 1
-saslPassword: ""
-stats: {uri:/pools/default/buckets/cbfs/stats, directoryURI:/pools/default/buckets/cbfs/statsDirectory,…}
-streamingUri: "/pools/default/bucketsStreaming/cbfs?bucket_uuid=3fceefcf9ce939b0bdbd066cc126a703"
-uri: "/pools/default/buckets/cbfs?bucket_uuid=3fceefcf9ce939b0bdbd066cc126a703"
-uuid: "3fceefcf9ce939b0bdbd066cc126a703"
-vBucketServerMap: {hashAlgorithm:CRC, numReplicas:1, serverList:[127.0.0.1:11210],…}
-2: {name:default, bucketType:membase, authType:sasl, saslPassword:, proxyPort:0, replicaIndex:false,…}
-authType: "sasl"
-autoCompactionSettings: false
-basicStats: {quotaPercentUsed:14.880996704101562, opsPerSec:0, viewOps:0, diskFetches:0, itemCount:6,…}
-bucketCapabilities: [touch, couchapi]
-bucketCapabilitiesVer: ""
-bucketType: "membase"
-controllers: {flush:/pools/default/buckets/default/controller/doFlush,…}
-ddocs: {uri:/pools/default/buckets/default/ddocs}
-fastWarmupSettings: false
-=end
-
-
-=begin
-localRandomKeyUri: "/pools/default/buckets/default/localRandomKey"
-name: "default"
-nodeLocator: "vbucket"
-nodes: [{systemStats:{cpu_utilization_rate:20.875, swap_total:9663676416, swap_used:8909201408},…}]
-proxyPort: 0
-quota: {ram:209715200, rawRAM:209715200}
-replicaIndex: false
-replicaNumber: 1
-saslPassword: ""
-stats: {uri:/pools/default/buckets/default/stats, directoryURI:/pools/default/buckets/default/statsDirectory,…}
-streamingUri: "/pools/default/bucketsStreaming/default?bucket_uuid=72e8847e947a3c03748df0e155dc2760"
-uri: "/pools/default/buckets/default?bucket_uuid=72e8847e947a3c03748df0e155dc2760"
-uuid: "72e8847e947a3c03748df0e155dc2760"
-vBucketServerMap: {hashAlgorithm:CRC, numReplicas:1, serverList:[127.0.0.1:11210],…}
-
-=end

0 comments on commit c503ca9

Please sign in to comment.