Skip to content
Browse files

lots more working, getting POSTS to _rev_diff now

  • Loading branch information...
1 parent e9149eb commit f9102b5175a9a6694aca3279f60c80837d51b999 @scalabl3 committed Nov 6, 2012
Showing with 125 additions and 48 deletions.
  1. +8 −5 README.md
  2. +117 −43 xdcr.rb
View
13 README.md
@@ -36,16 +36,19 @@ $ ruby xdcr.rb
- /pools/default/buckets (GET)
- /pools/default/buckets/{bucket} (GET)
- /{database} (HEAD, GET)
-- /{database}/master/{vbucket};{uuid} **GETTING STUCK HERE**
+- /{database}/{vbucket};{uuid}
+- /{database}/master/{vbucket};{uuid}
- /{database}/{docid} (GET)
-**NOT POSTING YET**
- /{database}/_ensure_full_commit (POST)
-- /{database}/_revs_diff (POST)
+- /{database}/_revs_diff (POST) **GETTING STUCK HERE on the Response**
- /{database}/_bulk_docs (POST)
# Currently Working on... #
***Current Error***
-2012-11-06 13:52:45 - Error replicating vbucket 9:
- {db_not_found, <<"http://Administrator:*****@127.0.0.1:4567/default/master;9e4d14d5a9be45cba5ec5534f42e129b/">>}
+Error replicating vbucket 965:
+
+```javascript
+{{nocatch, {bad_request, <<"Invalid rev format">>}}, [{couch_doc,parse_rev,1}, {couch_api_wrap, '-get_missing_revs/2-fun-0-', 1}, {lists,map,2}, {couch_api_wrap, '-get_missing_revs/2-fun-1-', 3}, {xdc_vbucket_rep_worker, find_missing,2}, {xdc_vbucket_rep_worker, queue_fetch_loop,4}]}
+```
View
160 xdcr.rb
@@ -3,7 +3,7 @@
require 'json'
require 'active_support'
-set :server, 'webrick'
+#set :server, 'webrick'
basic_auth do
realm 'Give me password!'
@@ -20,17 +20,17 @@
UUID_BUCKET = "9e4d14d5a9be45cba5ec5534f42e129b" #SecureRandom.uuid.gsub("-", "")
VBucketMap = []
1024.times { VBucketMap << [0,1] }
-puts VBucketMap.size
+#puts VBucketMap.size
get '/pools' do
require_basic_auth
content_type :json
- 5.times { puts }
- puts 'GET requested /pools'
- puts params.inspect
+ #5.times { puts }
+ #puts 'GET requested /pools'
+ #puts params.inspect
out = {
:pools => [ {
@@ -40,7 +40,7 @@
:uuid => UUID_POOL
}
- puts out.to_json
+ #puts out.to_json
out.to_json
end
@@ -51,9 +51,9 @@
require_basic_auth
content_type :json
- 5.times { puts }
- puts 'GET requested /pools/default'
- puts params.inspect
+ #5.times { puts }
+ #puts 'GET requested /pools/default'
+ #puts params.inspect
out = {
:buckets => { :uri => "/pools/default/buckets?uuid=#{UUID_POOL}" },
@@ -66,7 +66,7 @@
} ]
}
- puts out.to_json
+ #puts out.to_json
out.to_json
end
@@ -77,9 +77,9 @@
require_basic_auth
content_type :json
- 5.times { puts }
- puts 'GET requested /pools/default/buckets'
- puts params.inspect
+ #5.times { puts }
+ #puts 'GET requested /pools/default/buckets'
+ #puts params.inspect
out = [
{
@@ -111,8 +111,8 @@
require_basic_auth
content_type :json
- 5.times { puts }
- puts "GET requested /pools/buckets/#{params[:bucket]}"
+ #5.times { puts }
+ #puts "GET requested /pools/buckets/#{params[:bucket]}"
out = [
{
@@ -143,19 +143,16 @@
#/default/602;9e4d14d5a9be45cba5ec5534f42e129b
vbucket_regex = %r{[\/]([\w]+)([\/]|%2f)([\d]+)([;]|%3b)([\w]+)}
-
-
-
head vbucket_regex do
require_basic_auth
content_type :json
- params[:captures].each_with_index do |c,i|
- puts "capture[#{i}] = #{c}"
- end
- puts params.inspect
+ #params[:captures].each_with_index do |c,i|
+ # puts "capture[#{i}] = #{c}"
+ #end
+ #puts params.inspect
- result = database_response("HEAD", params[:captures][0], params[:captures][2].to_i, params[:captures][4])
+ result = response_db_vbucket("HEAD", params[:captures][0], params[:captures][2].to_i, params[:captures][4])
status result[0]
end
@@ -166,12 +163,12 @@
require_basic_auth
content_type :json
- params[:captures].each_with_index do |c,i|
- puts "capture[#{i}] = #{c}"
- end
- puts params.inspect
+ #params[:captures].each_with_index do |c,i|
+ # puts "capture[#{i}] = #{c}"
+ #end
+ #puts params.inspect
- result = database_response("GET", params[:captures][0], params[:captures][2].to_i, params[:captures][4])
+ result = response_db_vbucket("GET", params[:captures][0], params[:captures][2].to_i, params[:captures][4])
status result[0]
result_hash = { :db_name => XDCR_BUCKET }
@@ -185,14 +182,11 @@
-
-
-
#encapsulate GET and HEAD request results
-def database_response(method, database, vbucket_number, uuid)
+def response_db_vbucket(method, database, vbucket_number, uuid)
- 5.times { puts }
- puts "#{method} requested [database] /#{database}/#{vbucket_number};#{uuid}"
+ #5.times { puts }
+ #puts "#{method} requested [database] /#{database}/#{vbucket_number};#{uuid}"
if database == XDCR_BUCKET
return [200]
@@ -205,7 +199,57 @@ def database_response(method, database, vbucket_number, uuid)
-=begin
+
+vbucket_master_regex = %r{[\/]([\w]+)([\/]|%2f|%2F)([\w]+)([;]|%3b|%3B)([\w]+)}
+
+head vbucket_master_regex do
+ require_basic_auth
+ content_type :json
+
+ #params[:captures].each_with_index do |c,i|
+ # puts "capture[#{i}] = #{c}"
+ #end
+ #puts params.inspect
+
+ result = response_db_master("HEAD", params[:captures][0], params[:captures][2], params[:captures][4])
+ status result[0]
+end
+
+get vbucket_master_regex do
+ require_basic_auth
+ content_type :json
+
+ #params[:captures].each_with_index do |c,i|
+ # puts "capture[#{i}] = #{c}"
+ #end
+ #puts params.inspect
+
+ result = response_db_master("GET", params[:captures][0], params[:captures][2], params[:captures][4])
+ status result[0]
+
+ result_hash = { :db_name => XDCR_BUCKET }
+
+ if result[0].to_i == 200
+ return result_hash.to_json
+ else
+ return nil
+ end
+end
+
+
+#encapsulate GET and HEAD request results
+def response_db_master(method, database, master, uuid)
+
+ #5.times { puts }
+ #puts "#{method} requested [database] /#{database}/#{master};#{uuid}"
+
+ if database == XDCR_BUCKET
+ return [200]
+ else
+ return [404]
+ end
+end
+
@@ -225,34 +269,64 @@ def database_response(method, database, vbucket_number, uuid)
end
+revs_diff_regex = %r{[\/]([\w]+)([\/]|%2f|%2F)([\w]+)([;]|%3b|%3B)([\w]+)[\/](_revs_diff)}
-
-post '/:database/_revs_diff' do #(POST)
+post revs_diff_regex do #(POST)
require_basic_auth
content_type :json
5.times { puts }
- puts params.inspect
- puts "POST requested [database] /#{params[:database]}/_revs_diff"
- status 201
+ #puts "POST requested [database] /#{params[:captures][0]}/_revs_diff"
+ #puts params.class.to_s
+ #json = JSON.parse(params[0][0]) if params && params[0]
+
+ #print "json: "
+ #puts json.inspect
+ #puts request.body.inspect
- nil
+ request.body.rewind # in case someone already read it
+ raw_data = request.body.read
+ data = JSON.parse raw_data
+ puts raw_data
+ puts data.inspect
+ puts
+
+
+ out = {} # "03ee06461a12f3c288bb865b22000170": {"missing": ["2-3a24009a9525bde9e4bfa8a99046b00d"]} }
+ data.each_pair do |k,v|
+ out[k] = { :missing => [v] }
+ end
+
+ #params.each_pair do |k,v|
+ # puts "v[#{k}] = #{v}"
+ #end
+
+ status 200
+
+ puts out.to_json
+ out.to_json
end
+
+
post '/:database/_bulk_docs' do #(POST)
require_basic_auth
content_type :json
5.times { puts }
- puts params.inspect
- puts params[:data].inspect if params[:data]
puts "POST requested [database] /#{params[:database]}/_bulk_docs"
+
+ request.body.rewind # in case someone already read it
+ data = JSON.parse request.body.read
+ puts data.inspect
+
status 201
nil
end
+=begin
get '/:database' do #(HEAD, GET)
require_basic_auth

0 comments on commit f9102b5

Please sign in to comment.
Something went wrong with that request. Please try again.