You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2017/03/14 19:26:44 UTC
[49/50] couch-replicator commit: updated refs/heads/63012-scheduler
to 27a5eae
Add 'source' and 'target' fields to _scheduler/docs terminal states output
Previously terminal states from _scheduler/docs were different from others
as they did not have source and target data in the summary.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/commit/419ea1d9
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/tree/419ea1d9
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/diff/419ea1d9
Branch: refs/heads/63012-scheduler
Commit: 419ea1d99afc89c7d783e8c9cd428b219e42628d
Parents: 0b51c1b
Author: Nick Vatamaniuc <va...@apache.org>
Authored: Tue Mar 7 02:57:21 2017 -0500
Committer: Nick Vatamaniuc <va...@apache.org>
Committed: Tue Mar 7 02:57:21 2017 -0500
----------------------------------------------------------------------
src/couch_replicator.erl | 62 ++++++++++++++++++++++++++++--
src/couch_replicator_docs.erl | 2 +-
src/couch_replicator_js_functions.hrl | 8 +++-
3 files changed, 65 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/419ea1d9/src/couch_replicator.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator.erl b/src/couch_replicator.erl
index 59fb292..f2b0d02 100644
--- a/src/couch_replicator.erl
+++ b/src/couch_replicator.erl
@@ -19,6 +19,7 @@
-include_lib("couch/include/couch_db.hrl").
-include("couch_replicator.hrl").
+-include("couch_replicator_api_wrap.hrl").
-include_lib("couch_mrview/include/couch_mrview.hrl").
-define(REPLICATION_STATES, [
@@ -197,13 +198,13 @@ handle_replicator_doc_query({row, Props}, {Db, Cb, UserAcc, States}) ->
DocStateBin = couch_util:get_value(key, Props),
DocState = erlang:binary_to_existing_atom(DocStateBin, utf8),
MapValue = couch_util:get_value(value, Props),
- {StartTime, StateTime, StateInfo} = case MapValue of
- [StartT, StateT, Info] ->
- {StartT, StateT, Info};
+ {Source, Target, StartTime, StateTime, StateInfo} = case MapValue of
+ [Src, Tgt, StartT, StateT, Info] ->
+ {Src, Tgt, StartT, StateT, Info};
_Other ->
% Handle the case where the view code was upgraded but new view code
% wasn't updated yet (before a _scheduler/docs request was made)
- {null, null, null}
+ {null, null, null, null, null}
end,
% Set the error_count to 1 if failed. This is mainly for consistency as
% jobs from doc_processor and scheduler will have that value set
@@ -214,6 +215,8 @@ handle_replicator_doc_query({row, Props}, {Db, Cb, UserAcc, States}) ->
{doc_id, DocId},
{database, Db},
{id, null},
+ {source, strip_url_creds(Source)},
+ {target, strip_url_creds(Target)},
{state, DocState},
{error_count, ErrorCount},
{info, StateInfo},
@@ -232,6 +235,16 @@ handle_replicator_doc_query(complete, Acc) ->
{stop, Acc}.
+-spec strip_url_creds(binary() | {[_]}) -> binary().
+strip_url_creds(Endpoint) ->
+ case couch_replicator_docs:parse_rep_db(Endpoint, [], []) of
+ #httpdb{url=Url} ->
+ iolist_to_binary(couch_util:url_strip_password(Url));
+ LocalDb when is_binary(LocalDb) ->
+ LocalDb
+ end.
+
+
-spec filter_replicator_doc_query(atom(), [atom()]) -> boolean().
filter_replicator_doc_query(_DocState, []) ->
true;
@@ -267,6 +280,8 @@ doc_from_db(RepDb, DocId, UserCtx) ->
case fabric:open_doc(RepDb, DocId, [UserCtx, ejson_body]) of
{ok, Doc} ->
{Props} = couch_doc:to_json_obj(Doc, []),
+ Source = get_value(<<"source">>, Props),
+ Target = get_value(<<"target">>, Props),
State = get_value(<<"_replication_state">>, Props, null),
StartTime = get_value(<<"_replication_start_time">>, Props, null),
StateTime = get_value(<<"_replication_state_time">>, Props, null),
@@ -284,6 +299,8 @@ doc_from_db(RepDb, DocId, UserCtx) ->
{doc_id, DocId},
{database, RepDb},
{id, null},
+ {source, strip_url_creds(Source)},
+ {target, strip_url_creds(Target)},
{state, State},
{error_count, ErrorCount},
{info, StateInfo},
@@ -359,4 +376,41 @@ expect_rep_user_ctx(Name, Role) ->
#rep{user_ctx = UserCtx}
end).
+
+strip_url_creds_test_() ->
+ {
+ foreach,
+ fun () -> meck:expect(config, get, fun(_, _, Default) -> Default end) end,
+ fun (_) -> meck:unload() end,
+ [
+ t_strip_local_db_creds(),
+ t_strip_http_basic_creds(),
+ t_strip_http_props_creds()
+ ]
+ }.
+
+
+t_strip_local_db_creds() ->
+ ?_test(?assertEqual(<<"localdb">>, strip_url_creds(<<"localdb">>))).
+
+
+t_strip_http_basic_creds() ->
+ ?_test(begin
+ Url1 = <<"http://adm:pass@host/db">>,
+ ?assertEqual(<<"http://adm:*****@host/db/">>, strip_url_creds(Url1)),
+ Url2 = <<"https://adm:pass@host/db">>,
+ ?assertEqual(<<"https://adm:*****@host/db/">>, strip_url_creds(Url2))
+ end).
+
+
+t_strip_http_props_creds() ->
+ ?_test(begin
+ Props1 = {[{<<"url">>, <<"http://adm:pass@host/db">>}]},
+ ?assertEqual(<<"http://adm:*****@host/db/">>, strip_url_creds(Props1)),
+ Props2 = {[ {<<"url">>, <<"http://host/db">>},
+ {<<"headers">>, {[{<<"Authorization">>, <<"Basic pa55">>}]}}
+ ]},
+ ?assertEqual(<<"http://host/db/">>, strip_url_creds(Props2))
+ end).
+
-endif.
http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/419ea1d9/src/couch_replicator_docs.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator_docs.erl b/src/couch_replicator_docs.erl
index c0a9acd..5bdfe92 100644
--- a/src/couch_replicator_docs.erl
+++ b/src/couch_replicator_docs.erl
@@ -12,7 +12,7 @@
-module(couch_replicator_docs).
--export([parse_rep_doc/1, parse_rep_doc/2]).
+-export([parse_rep_doc/1, parse_rep_doc/2, parse_rep_db/3]).
-export([parse_rep_doc_without_id/1, parse_rep_doc_without_id/2]).
-export([before_doc_update/2, after_doc_read/2]).
-export([ensure_rep_db_exists/0, ensure_rep_ddoc_exists/1]).
http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/419ea1d9/src/couch_replicator_js_functions.hrl
----------------------------------------------------------------------
diff --git a/src/couch_replicator_js_functions.hrl b/src/couch_replicator_js_functions.hrl
index 3724b19..dbad050 100644
--- a/src/couch_replicator_js_functions.hrl
+++ b/src/couch_replicator_js_functions.hrl
@@ -176,15 +176,19 @@
function(doc) {
state = doc._replication_state;
if (state === 'failed') {
+ source = doc.source;
+ target = doc.target;
start_time = doc._replication_start_time;
last_updated = doc._replication_state_time;
state_reason = doc._replication_state_reason;
- emit('failed', [start_time, last_updated, state_reason]);
+ emit('failed', [source, target, start_time, last_updated, state_reason]);
} else if (state === 'completed') {
+ source = doc.source;
+ target = doc.target;
start_time = doc._replication_start_time;
last_updated = doc._replication_state_time;
stats = doc._replication_stats;
- emit('completed', [start_time, last_updated, stats]);
+ emit('completed', [source, target, start_time, last_updated, stats]);
}
}
">>).