mirror of
https://github.com/valitydev/fistful-server.git
synced 2024-11-06 02:35:18 +00:00
TD-271: Machine tagging via bender (#32)
This commit is contained in:
parent
0d0c59a0c2
commit
4278ab139e
@ -136,6 +136,22 @@ start_app(ff_server = AppName) ->
|
|||||||
]),
|
]),
|
||||||
#{}
|
#{}
|
||||||
};
|
};
|
||||||
|
start_app(bender_client = AppName) ->
|
||||||
|
{
|
||||||
|
start_app_with(AppName, [
|
||||||
|
{services, #{
|
||||||
|
'Bender' => <<"http://bender:8022/v1/bender">>,
|
||||||
|
'Generator' => <<"http://bender:8022/v1/generator">>
|
||||||
|
}},
|
||||||
|
{deadline, 10000},
|
||||||
|
{retries, #{
|
||||||
|
'GenerateID' => finish,
|
||||||
|
'GetInternalID' => finish,
|
||||||
|
'_' => finish
|
||||||
|
}}
|
||||||
|
]),
|
||||||
|
#{}
|
||||||
|
};
|
||||||
start_app({AppName, AppEnv}) ->
|
start_app({AppName, AppEnv}) ->
|
||||||
{start_app_with(AppName, AppEnv), #{}};
|
{start_app_with(AppName, AppEnv), #{}};
|
||||||
start_app(AppName) ->
|
start_app(AppName) ->
|
||||||
|
@ -75,7 +75,8 @@ start_processing_apps(Options) ->
|
|||||||
{services, services(Options)},
|
{services, services(Options)},
|
||||||
{providers, identity_provider_config(Options)}
|
{providers, identity_provider_config(Options)}
|
||||||
]},
|
]},
|
||||||
ff_server
|
ff_server,
|
||||||
|
bender_client
|
||||||
]),
|
]),
|
||||||
SuiteSup = ct_sup:start(),
|
SuiteSup = ct_sup:start(),
|
||||||
{ok, _} = supervisor:start_child(
|
{ok, _} = supervisor:start_child(
|
||||||
|
@ -130,7 +130,16 @@ repair(ID, Scenario) ->
|
|||||||
{ok, process_callback_response()}
|
{ok, process_callback_response()}
|
||||||
| {error, process_callback_error()}.
|
| {error, process_callback_error()}.
|
||||||
process_callback(#{tag := Tag} = Params) ->
|
process_callback(#{tag := Tag} = Params) ->
|
||||||
call({tag, Tag}, {process_callback, Params}).
|
MachineRef =
|
||||||
|
case ff_machine_tag:get_binding(?NS, Tag) of
|
||||||
|
{ok, EntityID} ->
|
||||||
|
EntityID;
|
||||||
|
{error, not_found} ->
|
||||||
|
%% Fallback to machinegun tagging
|
||||||
|
%% TODO: Remove after migration grace period
|
||||||
|
{tag, Tag}
|
||||||
|
end,
|
||||||
|
call(MachineRef, {process_callback, Params}).
|
||||||
|
|
||||||
%% machinery callbacks
|
%% machinery callbacks
|
||||||
|
|
||||||
@ -188,8 +197,9 @@ set_action(continue, _St) ->
|
|||||||
continue;
|
continue;
|
||||||
set_action(undefined, _St) ->
|
set_action(undefined, _St) ->
|
||||||
undefined;
|
undefined;
|
||||||
set_action({setup_callback, Tag, Timer}, _St) ->
|
set_action({setup_callback, Tag, Timer}, St) ->
|
||||||
[tag_action(Tag), timer_action(Timer)];
|
ok = ff_machine_tag:create_binding(?NS, Tag, ff_withdrawal_session:id(session(St))),
|
||||||
|
timer_action(Timer);
|
||||||
set_action({setup_timer, Timer}, _St) ->
|
set_action({setup_timer, Timer}, _St) ->
|
||||||
timer_action(Timer);
|
timer_action(Timer);
|
||||||
set_action(retry, St) ->
|
set_action(retry, St) ->
|
||||||
@ -252,10 +262,6 @@ check_deadline_(Now, Deadline) when Now >= Deadline ->
|
|||||||
timer_action(Timer) ->
|
timer_action(Timer) ->
|
||||||
{set_timer, Timer}.
|
{set_timer, Timer}.
|
||||||
|
|
||||||
-spec tag_action(machinery:tag()) -> machinery:action().
|
|
||||||
tag_action(Tag) ->
|
|
||||||
{tag, Tag}.
|
|
||||||
|
|
||||||
backend() ->
|
backend() ->
|
||||||
fistful:backend(?NS).
|
fistful:backend(?NS).
|
||||||
|
|
||||||
|
37
apps/fistful/src/ff_machine_tag.erl
Normal file
37
apps/fistful/src/ff_machine_tag.erl
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
-module(ff_machine_tag).
|
||||||
|
|
||||||
|
-define(BENDER_NS, <<"machinegun-tag">>).
|
||||||
|
|
||||||
|
-export([get_binding/2]).
|
||||||
|
-export([create_binding/3]).
|
||||||
|
|
||||||
|
-type tag() :: mg_proto_base_thrift:'Tag'().
|
||||||
|
-type ns() :: machinery:namespace().
|
||||||
|
-type entity_id() :: dmsl_base_thrift:'ID'().
|
||||||
|
|
||||||
|
-spec get_binding(ns(), tag()) -> {ok, entity_id()} | {error, not_found}.
|
||||||
|
get_binding(NS, Tag) ->
|
||||||
|
WoodyContext = ff_context:get_woody_context(ff_context:load()),
|
||||||
|
case bender_client:get_internal_id(tag_to_external_id(NS, Tag), WoodyContext) of
|
||||||
|
{ok, EntityID} ->
|
||||||
|
{ok, EntityID};
|
||||||
|
{error, internal_id_not_found} ->
|
||||||
|
{error, not_found}
|
||||||
|
end.
|
||||||
|
|
||||||
|
-spec create_binding(ns(), tag(), entity_id()) -> ok | no_return().
|
||||||
|
create_binding(NS, Tag, EntityID) ->
|
||||||
|
create_binding_(NS, Tag, EntityID, undefined).
|
||||||
|
|
||||||
|
%%
|
||||||
|
|
||||||
|
create_binding_(NS, Tag, EntityID, Context) ->
|
||||||
|
WoodyContext = ff_context:get_woody_context(ff_context:load()),
|
||||||
|
case bender_client:gen_constant(tag_to_external_id(NS, Tag), EntityID, WoodyContext, Context) of
|
||||||
|
{ok, EntityID} ->
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
|
||||||
|
tag_to_external_id(NS, Tag) ->
|
||||||
|
BinNS = atom_to_binary(NS, utf8),
|
||||||
|
<<?BENDER_NS/binary, "-", BinNS/binary, "-", Tag/binary>>.
|
@ -15,7 +15,8 @@
|
|||||||
damsel,
|
damsel,
|
||||||
dmt_client,
|
dmt_client,
|
||||||
party_client,
|
party_client,
|
||||||
binbase_proto
|
binbase_proto,
|
||||||
|
bender_client
|
||||||
]},
|
]},
|
||||||
{env, []},
|
{env, []},
|
||||||
{maintainers, [
|
{maintainers, [
|
||||||
|
@ -62,6 +62,19 @@
|
|||||||
}}
|
}}
|
||||||
]},
|
]},
|
||||||
|
|
||||||
|
{bender_client, [
|
||||||
|
{services, #{
|
||||||
|
'Bender' => <<"http://bender:8022/v1/bender">>,
|
||||||
|
'Generator' => <<"http://bender:8022/v1/generator">>
|
||||||
|
}},
|
||||||
|
{deadline, 60000}
|
||||||
|
%{retries, #{
|
||||||
|
% 'GenerateID' => finish,
|
||||||
|
% 'GetInternalID' => finish,
|
||||||
|
% '_' => finish
|
||||||
|
%}}
|
||||||
|
]},
|
||||||
|
|
||||||
{fistful, [
|
{fistful, [
|
||||||
{provider, #{
|
{provider, #{
|
||||||
<<"ncoeps">> => #{
|
<<"ncoeps">> => #{
|
||||||
|
@ -20,6 +20,8 @@ services:
|
|||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
shumway:
|
shumway:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
bender:
|
||||||
|
condition: service_healthy
|
||||||
working_dir: $PWD
|
working_dir: $PWD
|
||||||
command: /sbin/init
|
command: /sbin/init
|
||||||
|
|
||||||
@ -84,6 +86,18 @@ services:
|
|||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 10
|
retries: 10
|
||||||
|
|
||||||
|
bender:
|
||||||
|
image: ghcr.io/valitydev/bender:sha-d05ea29
|
||||||
|
command: /opt/bender/bin/bender foreground
|
||||||
|
depends_on:
|
||||||
|
machinegun:
|
||||||
|
condition: service_healthy
|
||||||
|
healthcheck:
|
||||||
|
test: "/opt/bender/bin/bender ping"
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 10
|
||||||
|
|
||||||
shumway-db:
|
shumway-db:
|
||||||
image: docker.io/library/postgres:9.6
|
image: docker.io/library/postgres:9.6
|
||||||
environment:
|
environment:
|
||||||
|
@ -34,12 +34,13 @@
|
|||||||
{thrift, {git, "https://github.com/valitydev/thrift_erlang.git", {branch, "master"}}},
|
{thrift, {git, "https://github.com/valitydev/thrift_erlang.git", {branch, "master"}}},
|
||||||
{woody, {git, "https://github.com/valitydev/woody_erlang.git", {branch, "master"}}},
|
{woody, {git, "https://github.com/valitydev/woody_erlang.git", {branch, "master"}}},
|
||||||
{erl_health, {git, "https://github.com/valitydev/erlang-health.git", {branch, "master"}}},
|
{erl_health, {git, "https://github.com/valitydev/erlang-health.git", {branch, "master"}}},
|
||||||
{machinery, {git, "https://github.com/valitydev/machinery.git", {branch, "master"}}},
|
{machinery, {git, "https://github.com/valitydev/machinery-erlang.git", {branch, "master"}}},
|
||||||
{damsel, {git, "https://github.com/valitydev/damsel.git", {branch, "master"}}},
|
{damsel, {git, "https://github.com/valitydev/damsel.git", {branch, "master"}}},
|
||||||
{dmt_client, {git, "https://github.com/valitydev/dmt_client.git", {branch, master}}},
|
{dmt_client, {git, "https://github.com/valitydev/dmt_client.git", {branch, master}}},
|
||||||
{fistful_proto, {git, "https://github.com/valitydev/fistful-proto.git", {branch, "master"}}},
|
{fistful_proto, {git, "https://github.com/valitydev/fistful-proto.git", {branch, "master"}}},
|
||||||
{binbase_proto, {git, "https://github.com/valitydev/binbase-proto.git", {branch, "master"}}},
|
{binbase_proto, {git, "https://github.com/valitydev/binbase-proto.git", {branch, "master"}}},
|
||||||
{party_client, {git, "https://github.com/valitydev/party-client-erlang.git", {branch, "master"}}}
|
{party_client, {git, "https://github.com/valitydev/party-client-erlang.git", {branch, "master"}}},
|
||||||
|
{bender_client, {git, "https://github.com/valitydev/bender-client-erlang.git", {branch, "master"}}}
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
{xref_checks, [
|
{xref_checks, [
|
||||||
|
20
rebar.lock
20
rebar.lock
@ -1,8 +1,16 @@
|
|||||||
{"1.2.0",
|
{"1.2.0",
|
||||||
[{<<"accept">>,{pkg,<<"accept">>,<<"0.3.5">>},2},
|
[{<<"accept">>,{pkg,<<"accept">>,<<"0.3.5">>},2},
|
||||||
|
{<<"bender_client">>,
|
||||||
|
{git,"https://github.com/valitydev/bender-client-erlang.git",
|
||||||
|
{ref,"7e869938a29c3c232e07eaa335a1a67892e07239"}},
|
||||||
|
0},
|
||||||
|
{<<"bender_proto">>,
|
||||||
|
{git,"https://github.com/valitydev/bender-proto.git",
|
||||||
|
{ref,"38ce3ffde52fb2f52a8d042e67a3e2715adb7546"}},
|
||||||
|
1},
|
||||||
{<<"binbase_proto">>,
|
{<<"binbase_proto">>,
|
||||||
{git,"https://github.com/valitydev/binbase-proto.git",
|
{git,"https://github.com/valitydev/binbase-proto.git",
|
||||||
{ref,"4c2e11c58bc3574540f729f6ddc88796dba119ce"}},
|
{ref,"9db92d90e0e28953cdb1b30c719edb529aa86579"}},
|
||||||
0},
|
0},
|
||||||
{<<"cache">>,{pkg,<<"cache">>,<<"2.3.3">>},1},
|
{<<"cache">>,{pkg,<<"cache">>,<<"2.3.3">>},1},
|
||||||
{<<"certifi">>,{pkg,<<"certifi">>,<<"2.8.0">>},2},
|
{<<"certifi">>,{pkg,<<"certifi">>,<<"2.8.0">>},2},
|
||||||
@ -41,15 +49,19 @@
|
|||||||
{<<"idna">>,{pkg,<<"idna">>,<<"6.1.1">>},2},
|
{<<"idna">>,{pkg,<<"idna">>,<<"6.1.1">>},2},
|
||||||
{<<"jsx">>,{pkg,<<"jsx">>,<<"3.1.0">>},1},
|
{<<"jsx">>,{pkg,<<"jsx">>,<<"3.1.0">>},1},
|
||||||
{<<"machinery">>,
|
{<<"machinery">>,
|
||||||
{git,"https://github.com/valitydev/machinery.git",
|
{git,"https://github.com/valitydev/machinery-erlang.git",
|
||||||
{ref,"db7c94b9913451e9558afa19f2fe77bf48d391da"}},
|
{ref,"ff4cfefb616250f6905c25e79f74a7a30eb1aae5"}},
|
||||||
0},
|
0},
|
||||||
{<<"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,"d814d6948d4ff13f6f41d12c6613f59c805750b2"}},
|
{ref,"b43d6fd0939ee4029ec8873dbd16f3c5fbe4a95c"}},
|
||||||
1},
|
1},
|
||||||
{<<"mimerl">>,{pkg,<<"mimerl">>,<<"1.2.0">>},2},
|
{<<"mimerl">>,{pkg,<<"mimerl">>,<<"1.2.0">>},2},
|
||||||
|
{<<"msgpack_proto">>,
|
||||||
|
{git,"https://github.com/rbkmoney/msgpack-proto.git",
|
||||||
|
{ref,"ec15d5e854ea60c58467373077d90c2faf6273d8"}},
|
||||||
|
2},
|
||||||
{<<"parse_trans">>,{pkg,<<"parse_trans">>,<<"3.3.1">>},2},
|
{<<"parse_trans">>,{pkg,<<"parse_trans">>,<<"3.3.1">>},2},
|
||||||
{<<"party_client">>,
|
{<<"party_client">>,
|
||||||
{git,"https://github.com/valitydev/party-client-erlang.git",
|
{git,"https://github.com/valitydev/party-client-erlang.git",
|
||||||
|
Loading…
Reference in New Issue
Block a user