TD-296: Drop mg tag remains (#30)

This commit is contained in:
Alexey S 2022-06-07 13:38:22 +03:00 committed by GitHub
parent 83ee553fd0
commit fb0570df68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 98 additions and 127 deletions

View File

@ -120,22 +120,22 @@ handle_function_(Fun, Args, _Opts) when
set_meta(ID) -> set_meta(ID) ->
scoper:add_meta(#{customer_id => ID}). scoper:add_meta(#{customer_id => ID}).
get_history(Ref) -> get_history(ID) ->
History = hg_machine:get_history(?NS, Ref), History = hg_machine:get_history(?NS, ID),
unmarshal_history(map_history_error(History)). unmarshal_history(map_history_error(History)).
get_history(Ref, AfterID, Limit) -> get_history(ID, AfterID, Limit) ->
History = hg_machine:get_history(?NS, Ref, AfterID, Limit), History = hg_machine:get_history(?NS, ID, AfterID, Limit),
unmarshal_history(map_history_error(History)). unmarshal_history(map_history_error(History)).
get_state(Ref) -> get_state(ID) ->
collapse_history(get_history(Ref)). collapse_history(get_history(ID)).
get_state(Ref, AfterID, Limit) -> get_state(ID, AfterID, Limit) ->
collapse_history(get_history(Ref, AfterID, Limit)). collapse_history(get_history(ID, AfterID, Limit)).
get_initial_state(Ref) -> get_initial_state(ID) ->
collapse_history(get_history(Ref, undefined, 1)). collapse_history(get_history(ID, undefined, 1)).
get_public_history(CustomerID, #payproc_EventRange{'after' = AfterID, limit = Limit}) -> get_public_history(CustomerID, #payproc_EventRange{'after' = AfterID, limit = Limit}) ->
[publish_customer_event(CustomerID, Ev) || Ev <- get_history(CustomerID, AfterID, Limit)]. [publish_customer_event(CustomerID, Ev) || Ev <- get_history(CustomerID, AfterID, Limit)].

View File

@ -82,23 +82,16 @@
%% API %% API
-spec get(hg_machine:ref()) -> {ok, st()} | {error, notfound}. -spec get(hg_machine:id()) -> {ok, st()} | {error, notfound}.
get(Ref) -> get(Id) ->
case hg_machine:get_history(?NS, Ref) of case hg_machine:get_history(?NS, Id) of
{ok, History} -> {ok, History} ->
{ok, collapse_history(unmarshal_history(History))}; {ok, collapse_history(unmarshal_history(History))};
Error -> Error ->
Error Error
end. end.
-spec get_payment(hg_machine:tag() | payment_id(), st()) -> {ok, payment_st()} | {error, notfound}. -spec get_payment(payment_id(), st()) -> {ok, payment_st()} | {error, notfound}.
get_payment({tag, Tag}, #st{payments = Ps}) ->
case lists:dropwhile(fun({_, PS}) -> not lists:member(Tag, get_payment_tags(PS)) end, Ps) of
[{_ID, PaymentSession} | _] ->
{ok, PaymentSession};
[] ->
{error, notfound}
end;
get_payment(PaymentID, St) -> get_payment(PaymentID, St) ->
case try_get_payment_session(PaymentID, St) of case try_get_payment_session(PaymentID, St) of
PaymentSession when PaymentSession /= undefined -> PaymentSession when PaymentSession /= undefined ->
@ -107,9 +100,6 @@ get_payment(PaymentID, St) ->
{error, notfound} {error, notfound}
end. end.
get_payment_tags(PaymentSession) ->
hg_invoice_payment:get_tags(PaymentSession).
-spec get_payment_opts(st()) -> hg_invoice_payment:opts(). -spec get_payment_opts(st()) -> hg_invoice_payment:opts().
get_payment_opts(St = #st{invoice = Invoice, party = undefined}) -> get_payment_opts(St = #st{invoice = Invoice, party = undefined}) ->
#{ #{
@ -367,29 +357,25 @@ set_invoicing_meta(InvoiceID, PaymentID) ->
-spec process_callback(tag(), callback()) -> -spec process_callback(tag(), callback()) ->
{ok, callback_response()} | {error, invalid_callback | notfound | failed} | no_return(). {ok, callback_response()} | {error, invalid_callback | notfound | failed} | no_return().
process_callback(Tag, Callback) -> process_callback(Tag, Callback) ->
MachineRef = case hg_machine_tag:get_binding(namespace(), Tag) of
case hg_machine_tag:get_binding(namespace(), Tag) of {ok, _EntityID, MachineID} ->
{ok, _EntityID, MachineID} -> case hg_machine:call(?NS, MachineID, {callback, Tag, Callback}) of
MachineID; {ok, _} = Ok ->
{error, not_found} -> Ok;
%% Fallback to machinegun tagging {exception, invalid_callback} ->
%% TODO: Remove after migration grace period {error, invalid_callback};
{tag, Tag} {error, _} = Error ->
end, Error
case hg_machine:call(?NS, MachineRef, {callback, Tag, Callback}) of end;
{ok, _Reply} = Response ->
Response;
{exception, invalid_callback} ->
{error, invalid_callback};
{error, _} = Error -> {error, _} = Error ->
Error Error
end. end.
%% %%
-spec fail(hg_machine:ref()) -> ok. -spec fail(hg_machine:id()) -> ok.
fail(Ref) -> fail(Id) ->
case hg_machine:call(?NS, Ref, fail) of case hg_machine:call(?NS, Id, fail) of
{error, failed} -> {error, failed} ->
ok; ok;
{error, Error} -> {error, Error} ->
@ -400,19 +386,19 @@ fail(Ref) ->
%% %%
get_history(Ref) -> get_history(ID) ->
History = hg_machine:get_history(?NS, Ref), History = hg_machine:get_history(?NS, ID),
unmarshal_history(map_history_error(History)). unmarshal_history(map_history_error(History)).
get_history(Ref, AfterID, Limit) -> get_history(ID, AfterID, Limit) ->
History = hg_machine:get_history(?NS, Ref, AfterID, Limit), History = hg_machine:get_history(?NS, ID, AfterID, Limit),
unmarshal_history(map_history_error(History)). unmarshal_history(map_history_error(History)).
get_state(Ref) -> get_state(ID) ->
collapse_history(get_history(Ref)). collapse_history(get_history(ID)).
get_state(Ref, AfterID, Limit) -> get_state(ID, AfterID, Limit) ->
collapse_history(get_history(Ref, AfterID, Limit)). collapse_history(get_history(ID, AfterID, Limit)).
get_public_history(InvoiceID, #payproc_EventRange{'after' = AfterID, limit = Limit}) -> get_public_history(InvoiceID, #payproc_EventRange{'after' = AfterID, limit = Limit}) ->
[publish_invoice_event(InvoiceID, Ev) || Ev <- get_history(InvoiceID, AfterID, Limit)]. [publish_invoice_event(InvoiceID, Ev) || Ev <- get_history(InvoiceID, AfterID, Limit)].

View File

@ -5,8 +5,6 @@
-type msgp() :: mg_msgpack_marshalling:msgpack_value(). -type msgp() :: mg_msgpack_marshalling:msgpack_value().
-type id() :: mg_proto_base_thrift:'ID'(). -type id() :: mg_proto_base_thrift:'ID'().
-type tag() :: {tag, mg_proto_base_thrift:'Tag'()}.
-type ref() :: id() | tag().
-type ns() :: mg_proto_base_thrift:'Namespace'(). -type ns() :: mg_proto_base_thrift:'Namespace'().
-type args() :: _. -type args() :: _.
@ -60,8 +58,6 @@
}. }.
-export_type([id/0]). -export_type([id/0]).
-export_type([ref/0]).
-export_type([tag/0]).
-export_type([ns/0]). -export_type([ns/0]).
-export_type([args/0]). -export_type([args/0]).
-export_type([event_id/0]). -export_type([event_id/0]).
@ -117,13 +113,13 @@
start(Ns, ID, Args) -> start(Ns, ID, Args) ->
call_automaton('Start', {Ns, ID, wrap_args(Args)}). call_automaton('Start', {Ns, ID, wrap_args(Args)}).
-spec thrift_call(ns(), ref(), service_name(), function_ref(), args()) -> response() | {error, notfound | failed}. -spec thrift_call(ns(), id(), service_name(), function_ref(), args()) -> response() | {error, notfound | failed}.
thrift_call(Ns, Ref, Service, FunRef, Args) -> thrift_call(Ns, Id, Service, FunRef, Args) ->
thrift_call(Ns, Ref, Service, FunRef, Args, undefined, undefined, forward). thrift_call(Ns, Id, Service, FunRef, Args, undefined, undefined, forward).
-spec thrift_call(Ns, Ref, Service, FunRef, Args, After, Limit, Direction) -> Result when -spec thrift_call(Ns, Id, Service, FunRef, Args, After, Limit, Direction) -> Result when
Ns :: ns(), Ns :: ns(),
Ref :: ref(), Id :: id(),
Service :: service_name(), Service :: service_name(),
FunRef :: function_ref(), FunRef :: function_ref(),
Args :: args(), Args :: args(),
@ -131,10 +127,10 @@ thrift_call(Ns, Ref, Service, FunRef, Args) ->
Limit :: integer() | undefined, Limit :: integer() | undefined,
Direction :: forward | backward, Direction :: forward | backward,
Result :: response() | {error, notfound | failed}. Result :: response() | {error, notfound | failed}.
thrift_call(Ns, Ref, Service, FunRef, Args, After, Limit, Direction) -> thrift_call(Ns, Id, Service, FunRef, Args, After, Limit, Direction) ->
EncodedArgs = marshal_thrift_args(Service, FunRef, Args), EncodedArgs = marshal_thrift_args(Service, FunRef, Args),
Call = {thrift_call, Service, FunRef, EncodedArgs}, Call = {thrift_call, Service, FunRef, EncodedArgs},
case do_call(Ns, Ref, Call, After, Limit, Direction) of case do_call(Ns, Id, Call, After, Limit, Direction) of
{ok, Response} -> {ok, Response} ->
% should be specific to a processing interface already % should be specific to a processing interface already
unmarshal_thrift_response(Service, FunRef, Response); unmarshal_thrift_response(Service, FunRef, Response);
@ -142,56 +138,56 @@ thrift_call(Ns, Ref, Service, FunRef, Args, After, Limit, Direction) ->
Error Error
end. end.
-spec call(ns(), ref(), Args :: term()) -> response() | {error, notfound | failed}. -spec call(ns(), id(), Args :: term()) -> response() | {error, notfound | failed}.
call(Ns, Ref, Args) -> call(Ns, Id, Args) ->
call(Ns, Ref, Args, undefined, undefined, forward). call(Ns, Id, Args, undefined, undefined, forward).
-spec call(Ns, Ref, Args, After, Limit, Direction) -> Result when -spec call(Ns, Id, Args, After, Limit, Direction) -> Result when
Ns :: ns(), Ns :: ns(),
Ref :: ref(), Id :: id(),
Args :: args(), Args :: args(),
After :: event_id() | undefined, After :: event_id() | undefined,
Limit :: integer() | undefined, Limit :: integer() | undefined,
Direction :: forward | backward, Direction :: forward | backward,
Result :: response() | {error, notfound | failed}. Result :: response() | {error, notfound | failed}.
call(Ns, Ref, Args, After, Limit, Direction) -> call(Ns, Id, Args, After, Limit, Direction) ->
case do_call(Ns, Ref, {schemaless_call, Args}, After, Limit, Direction) of case do_call(Ns, Id, {schemaless_call, Args}, After, Limit, Direction) of
{ok, Response} -> {ok, Response} ->
unmarshal_schemaless_response(Response); unmarshal_schemaless_response(Response);
{error, _} = Error -> {error, _} = Error ->
Error Error
end. end.
-spec repair(ns(), ref(), term()) -> -spec repair(ns(), id(), term()) ->
{ok, term()} | {error, notfound | failed | working | {repair, {failed, binary()}}} | no_return(). {ok, term()} | {error, notfound | failed | working | {repair, {failed, binary()}}} | no_return().
repair(Ns, Ref, Args) -> repair(Ns, Id, Args) ->
Descriptor = prepare_descriptor(Ns, Ref, #mg_stateproc_HistoryRange{}), Descriptor = prepare_descriptor(Ns, Id, #mg_stateproc_HistoryRange{}),
call_automaton('Repair', {Descriptor, wrap_args(Args)}). call_automaton('Repair', {Descriptor, wrap_args(Args)}).
-spec get_history(ns(), ref()) -> {ok, history()} | {error, notfound} | no_return(). -spec get_history(ns(), id()) -> {ok, history()} | {error, notfound} | no_return().
get_history(Ns, Ref) -> get_history(Ns, Id) ->
get_history(Ns, Ref, undefined, undefined, forward). get_history(Ns, Id, undefined, undefined, forward).
-spec get_history(ns(), ref(), undefined | event_id(), undefined | non_neg_integer()) -> -spec get_history(ns(), id(), undefined | event_id(), undefined | non_neg_integer()) ->
{ok, history()} | {error, notfound} | no_return(). {ok, history()} | {error, notfound} | no_return().
get_history(Ns, Ref, AfterID, Limit) -> get_history(Ns, Id, AfterID, Limit) ->
get_history(Ns, Ref, AfterID, Limit, forward). get_history(Ns, Id, AfterID, Limit, forward).
-spec get_history(ns(), ref(), undefined | event_id(), undefined | non_neg_integer(), direction()) -> -spec get_history(ns(), id(), undefined | event_id(), undefined | non_neg_integer(), direction()) ->
{ok, history()} | {error, notfound} | no_return(). {ok, history()} | {error, notfound} | no_return().
get_history(Ns, Ref, AfterID, Limit, Direction) -> get_history(Ns, Id, AfterID, Limit, Direction) ->
case get_machine(Ns, Ref, AfterID, Limit, Direction) of case get_machine(Ns, Id, AfterID, Limit, Direction) of
{ok, #{history := History}} -> {ok, #{history := History}} ->
{ok, History}; {ok, History};
Error -> Error ->
Error Error
end. end.
-spec get_machine(ns(), ref(), undefined | event_id(), undefined | non_neg_integer(), direction()) -> -spec get_machine(ns(), id(), undefined | event_id(), undefined | non_neg_integer(), direction()) ->
{ok, machine()} | {error, notfound} | no_return(). {ok, machine()} | {error, notfound} | no_return().
get_machine(Ns, Ref, AfterID, Limit, Direction) -> get_machine(Ns, Id, AfterID, Limit, Direction) ->
Range = #mg_stateproc_HistoryRange{'after' = AfterID, limit = Limit, direction = Direction}, Range = #mg_stateproc_HistoryRange{'after' = AfterID, limit = Limit, direction = Direction},
Descriptor = prepare_descriptor(Ns, Ref, Range), Descriptor = prepare_descriptor(Ns, Id, Range),
case call_automaton('GetMachine', {Descriptor}) of case call_automaton('GetMachine', {Descriptor}) of
{ok, #mg_stateproc_Machine{} = Machine} -> {ok, #mg_stateproc_Machine{} = Machine} ->
{ok, unmarshal_machine(Machine)}; {ok, unmarshal_machine(Machine)};
@ -201,21 +197,21 @@ get_machine(Ns, Ref, AfterID, Limit, Direction) ->
%% %%
-spec do_call(Ns, Ref, Args, After, Limit, Direction) -> Result when -spec do_call(Ns, Id, Args, After, Limit, Direction) -> Result when
Ns :: ns(), Ns :: ns(),
Ref :: ref(), Id :: id(),
Args :: args(), Args :: args(),
After :: event_id() | undefined, After :: event_id() | undefined,
Limit :: integer() | undefined, Limit :: integer() | undefined,
Direction :: forward | backward, Direction :: forward | backward,
Result :: {ok, response()} | {error, notfound | failed}. Result :: {ok, response()} | {error, notfound | failed}.
do_call(Ns, Ref, Args, After, Limit, Direction) -> do_call(Ns, Id, Args, After, Limit, Direction) ->
HistoryRange = #mg_stateproc_HistoryRange{ HistoryRange = #mg_stateproc_HistoryRange{
'after' = After, 'after' = After,
'limit' = Limit, 'limit' = Limit,
'direction' = Direction 'direction' = Direction
}, },
Descriptor = prepare_descriptor(Ns, Ref, HistoryRange), Descriptor = prepare_descriptor(Ns, Id, HistoryRange),
case call_automaton('Call', {Descriptor, wrap_args(Args)}) of case call_automaton('Call', {Descriptor, wrap_args(Args)}) of
{ok, Response} -> {ok, Response} ->
{ok, unmarshal_response(Response)}; {ok, unmarshal_response(Response)};
@ -549,15 +545,10 @@ marshal_term(V) ->
unmarshal_term({bin, B}) -> unmarshal_term({bin, B}) ->
binary_to_term(B). binary_to_term(B).
-spec prepare_descriptor(ns(), ref(), history_range()) -> descriptor(). -spec prepare_descriptor(ns(), id(), history_range()) -> descriptor().
prepare_descriptor(NS, Ref, Range) -> prepare_descriptor(NS, Id, Range) ->
#mg_stateproc_MachineDescriptor{ #mg_stateproc_MachineDescriptor{
ns = NS, ns = NS,
ref = prepare_ref(Ref), ref = {id, Id},
range = Range range = Range
}. }.
prepare_ref(ID) when is_binary(ID) ->
{id, ID};
prepare_ref({tag, Tag}) ->
{tag, Tag}.

View File

@ -6,12 +6,12 @@
-export([create_binding/3]). -export([create_binding/3]).
-export([create_binding/4]). -export([create_binding/4]).
-type tag() :: mg_proto_base_thrift:'Tag'(). -type tag() :: dmsl_base_thrift:'Tag'().
-type ns() :: hg_machine:ns(). -type ns() :: hg_machine:ns().
-type entity_id() :: dmsl_base_thrift:'ID'(). -type entity_id() :: dmsl_base_thrift:'ID'().
-type machine_id() :: hg_machine:id(). -type machine_id() :: hg_machine:id().
-spec get_binding(ns(), tag()) -> {ok, entity_id(), machine_id()} | {error, not_found}. -spec get_binding(ns(), tag()) -> {ok, entity_id(), machine_id()} | {error, notfound}.
get_binding(NS, Tag) -> get_binding(NS, Tag) ->
WoodyContext = hg_context:get_woody_context(hg_context:load()), WoodyContext = hg_context:get_woody_context(hg_context:load()),
case bender_client:get_internal_id(tag_to_external_id(NS, Tag), WoodyContext) of case bender_client:get_internal_id(tag_to_external_id(NS, Tag), WoodyContext) of
@ -20,7 +20,7 @@ get_binding(NS, Tag) ->
{ok, EntityID, #{<<"machine-id">> := MachineID}} -> {ok, EntityID, #{<<"machine-id">> := MachineID}} ->
{ok, EntityID, MachineID}; {ok, EntityID, MachineID};
{error, internal_id_not_found} -> {error, internal_id_not_found} ->
{error, not_found} {error, notfound}
end. end.
-spec create_binding(ns(), tag(), entity_id()) -> ok | no_return(). -spec create_binding(ns(), tag(), entity_id()) -> ok | no_return().

View File

@ -30,21 +30,19 @@ handle_function('ProcessPaymentCallback', {Tag, Callback}, _) ->
handle_function('ProcessRecurrentTokenCallback', {Tag, Callback}, _) -> handle_function('ProcessRecurrentTokenCallback', {Tag, Callback}, _) ->
handle_callback_result(hg_recurrent_paytool:process_callback(Tag, {provider, Callback})); handle_callback_result(hg_recurrent_paytool:process_callback(Tag, {provider, Callback}));
handle_function('GetPayment', {Tag}, _) -> handle_function('GetPayment', {Tag}, _) ->
{InvoiceRef, PaymentRef} = case hg_machine_tag:get_binding(hg_invoice:namespace(), Tag) of
case hg_machine_tag:get_binding(hg_invoice:namespace(), Tag) of {ok, PaymentID, InvoiceID} ->
{ok, EntityID, MachineID} -> case hg_invoice:get(InvoiceID) of
{MachineID, EntityID}; {ok, InvoiceSt} ->
{error, not_found} -> case hg_invoice:get_payment(PaymentID, InvoiceSt) of
%% Fallback to machinegun tagging {ok, PaymentSt} ->
%% TODO: Remove after migration grace period hg_invoice_payment:construct_payment_info(
{{tag, Tag}, {tag, Tag}} PaymentSt,
end, hg_invoice:get_payment_opts(InvoiceSt)
case hg_invoice:get(InvoiceRef) of );
{ok, InvoiceSt} -> {error, notfound} ->
case hg_invoice:get_payment(PaymentRef, InvoiceSt) of hg_woody_wrapper:raise(#prxprv_PaymentNotFound{})
{ok, PaymentSt} -> end;
Opts = hg_invoice:get_payment_opts(InvoiceSt),
hg_invoice_payment:construct_payment_info(PaymentSt, Opts);
{error, notfound} -> {error, notfound} ->
hg_woody_wrapper:raise(#prxprv_PaymentNotFound{}) hg_woody_wrapper:raise(#prxprv_PaymentNotFound{})
end; end;

View File

@ -751,20 +751,16 @@ dispatch_callback({provider, Payload}, St) ->
-spec process_callback(tag(), callback()) -> -spec process_callback(tag(), callback()) ->
{ok, callback_response()} | {error, invalid_callback | notfound | failed} | no_return(). {ok, callback_response()} | {error, invalid_callback | notfound | failed} | no_return().
process_callback(Tag, Callback) -> process_callback(Tag, Callback) ->
MachineRef = case hg_machine_tag:get_binding(namespace(), Tag) of
case hg_machine_tag:get_binding(namespace(), Tag) of {ok, _EntityID, MachineID} ->
{ok, _EntityID, MachineID} -> case hg_machine:call(?NS, MachineID, {callback, Callback}) of
MachineID; {ok, _} = Ok ->
{error, not_found} -> Ok;
%% Fallback to machinegun tagging {exception, invalid_callback} ->
%% TODO: Remove after migration grace period {error, invalid_callback};
{tag, Tag} {error, _} = Error ->
end, Error
case hg_machine:call(?NS, MachineRef, {callback, Callback}) of end;
{ok, _CallbackResponse} = Result ->
Result;
{exception, invalid_callback} ->
{error, invalid_callback};
{error, _} = Error -> {error, _} = Error ->
Error Error
end. end.

View File

@ -50,7 +50,7 @@
{<<"metrics">>,{pkg,<<"metrics">>,<<"1.0.1">>},2}, {<<"metrics">>,{pkg,<<"metrics">>,<<"1.0.1">>},2},
{<<"mg_proto">>, {<<"mg_proto">>,
{git,"https://github.com/valitydev/machinegun-proto.git", {git,"https://github.com/valitydev/machinegun-proto.git",
{ref,"e4784ab4647ae9dfdf1733ff2ec97578632f137d"}}, {ref,"7d780d5aa445e37b4816ac8a433bfaffe3715f63"}},
0}, 0},
{<<"mimerl">>,{pkg,<<"mimerl">>,<<"1.2.0">>},2}, {<<"mimerl">>,{pkg,<<"mimerl">>,<<"1.2.0">>},2},
{<<"msgpack_proto">>, {<<"msgpack_proto">>,