From 76093ae516de41b9d26f014640d13ace1f017a0d Mon Sep 17 00:00:00 2001 From: Andrey Mayorov Date: Thu, 5 Jul 2018 13:57:59 +0300 Subject: [PATCH] [WIP] Setup ff_server application --- Dockerfile.sh | 2 +- apps/ff_server/src/ff_server.erl | 76 +++++++++++++++++++++++++------- config/sys.config | 31 ++++++++++--- config/vm.args | 4 +- rebar.config | 2 +- 5 files changed, 89 insertions(+), 26 deletions(-) diff --git a/Dockerfile.sh b/Dockerfile.sh index 97654e5..a6c983b 100755 --- a/Dockerfile.sh +++ b/Dockerfile.sh @@ -3,7 +3,7 @@ cat < COPY ./_build/prod/rel/${SERVICE_NAME} /opt/${SERVICE_NAME} -CMD /opt/payproc-server/bin/payproc-server foreground +CMD /opt/${SERVICE_NAME}/bin/${SERVICE_NAME} foreground EXPOSE 8022 # A bit of magic below to get a proper branch name # even when the HEAD is detached (Hey Jenkins! diff --git a/apps/ff_server/src/ff_server.erl b/apps/ff_server/src/ff_server.erl index 8f395fa..651bf0a 100644 --- a/apps/ff_server/src/ff_server.erl +++ b/apps/ff_server/src/ff_server.erl @@ -1,6 +1,12 @@ %%% %%% Server startup %%% +%%% TODOs +%%% +%%% - We should probably most of what is hardcoded here to the application +%%% environment. +%%% - Provide healthcheck. +%%% -module(ff_server). @@ -49,25 +55,63 @@ stop(_State) -> init([]) -> % TODO % - Make it palatable - {Backends1, ChildSpecs1} = lists:unzip([ - contruct_backend_childspec('identity' , ff_identity_machine), - contruct_backend_childspec('wallet' , ff_wallet_machine) + {Backends, Handlers} = lists:unzip([ + contruct_backend_childspec('ff/identity' , ff_identity_machine), + contruct_backend_childspec('ff/wallet' , ff_wallet_machine), + contruct_backend_childspec('ff/destination' , ff_destination_machine), + contruct_backend_childspec('ff/withdrawal' , ff_withdrawal_machine), + contruct_backend_childspec('ff/withdrawal/session' , ff_withdrawal_session_machine) ]), - {Backends2, ChildSpecs2} = lists:unzip([ - contruct_backend_childspec('destination' , ff_destination_machine), - contruct_backend_childspec('withdrawal' , ff_withdrawal_machine), - contruct_backend_childspec('withdrawal/session' , ff_withdrawal_session_machine) - ]), - ok = application:set_env(fistful, backends, Backends1), - ok = application:set_env(ff_withdraw, backends, Backends2), - {ok, + ok = application:set_env(fistful, backends, Backends), + {ok, IP} = inet:parse_address(genlib_app:env(?MODULE, ip, "::0")), + {ok, { + % TODO + % - Zero thoughts given while defining this strategy. #{strategy => one_for_one}, - ChildSpecs1 ++ ChildSpecs2 - }. + [ + woody_server:child_spec( + ?MODULE, + maps:merge( + maps:with([net_opts, handler_limits], genlib_app:env(?MODULE, woody_opts, #{})), + #{ + ip => IP, + port => genlib_app:env(?MODULE, port, 8022), + handlers => [], + event_handler => scoper_woody_event_handler, + additional_routes => machinery_mg_backend:get_routes( + Handlers, + maps:merge( + genlib_app:env(?MODULE, route_opts, #{}), + #{ + event_handler => scoper_woody_event_handler + } + ) + ) + } + ) + ) + ] + }}. contruct_backend_childspec(NS, Handler) -> - Opts = #{name => NS}, + Be = {machinery_mg_backend, #{ + schema => machinery_mg_schema_generic, + client => get_service_client('automaton') + }}, { - {NS, machinery_gensrv_backend:new(Opts)}, - machinery_gensrv_backend:child_spec(Handler, Opts) + {NS, Be}, + {{fistful, Handler}, + #{ + path => ff_string:join(["/v1/stateproc/", NS]), + backend_config => #{schema => machinery_mg_schema_generic} + } + } }. + +get_service_client(ServiceID) -> + case genlib_app:env(?MODULE, services, #{}) of + #{ServiceID := V} -> + ff_woody_client:new(V); + #{} -> + error({'woody service undefined', ServiceID}) + end. diff --git a/config/sys.config b/config/sys.config index aabe227..4f63aaf 100644 --- a/config/sys.config +++ b/config/sys.config @@ -17,6 +17,16 @@ {storage, scoper_storage_lager} ]}, + {dmt_client, [ + {max_cache_size, #{ + elements => 1 + }}, + {service_urls, #{ + 'Repository' => <<"http://dominant:8022/v1/domain/repository">>, + 'RepositoryClient' => <<"http://dominant:8022/v1/domain/repository_client">> + }} + ]}, + {fistful, [ {providers, #{ <<"ncoeps">> => #{ @@ -25,7 +35,7 @@ <<"person">> => #{ name => <<"Person">>, contact_template_id => 10000, - initial_level => <<"anonymous">> + initial_level => <<"anonymous">>, levels => #{ <<"anonymous">> => #{ name => <<"Anonymous">>, @@ -50,16 +60,25 @@ } } } + }}, + {services, #{ + 'partymgmt' => "http://hellgate:8022/v1/processing/partymgmt", + 'accounter' => "http://shumway:8022/accounter" }} ]}, - {fistful_server, [ + {ff_server, [ {ip, "::"}, {port, 8022}, - {net_opts, [ - % Bump keepalive timeout up to a minute - {timeout, 60000} - ]} + {woody_opts, #{ + net_opts => [ + % Bump keepalive timeout up to a minute + {timeout, 60000} + ] + }}, + {services, #{ + 'automaton' => "http://machinegun:8022/v1/automaton" + }} ]} ]. diff --git a/config/vm.args b/config/vm.args index eedc296..11635c5 100644 --- a/config/vm.args +++ b/config/vm.args @@ -1,6 +1,6 @@ --sname fistfulsrv +-sname ffsrv --setcookie fistfulsrv_cookie +-setcookie ffsrv +K true +A 10 diff --git a/rebar.config b/rebar.config index 429a35c..24cbddc 100644 --- a/rebar.config +++ b/rebar.config @@ -110,7 +110,7 @@ {tools , load}, % profiler {recon , load}, {lager_logstash_formatter , load}, - fistful_server + ff_server ]}, {sys_config , "./config/sys.config"}, {vm_args , "./config/vm.args"},