From f757b7905b96d619390e4e71a702efb43fa3d2b7 Mon Sep 17 00:00:00 2001 From: ndiezel0 Date: Fri, 8 Apr 2022 01:32:50 +0300 Subject: [PATCH] TD-262: Move from shumpune to accounter (#15) * TD-262: Move from shumpune to accounter * Fix spec * Add test * Fix --- .../src/party_management.app.src | 1 - apps/party_management/src/pm_accounting.erl | 61 +++++++------------ apps/party_management/test/pm_ct_helper.erl | 2 +- .../test/pm_party_tests_SUITE.erl | 10 ++- apps/pm_proto/src/pm_proto.erl | 2 +- docker-compose.yml => compose.yml | 2 +- config/sys.config | 2 +- rebar.config | 2 - rebar.lock | 6 +- 9 files changed, 36 insertions(+), 52 deletions(-) rename docker-compose.yml => compose.yml (96%) diff --git a/apps/party_management/src/party_management.app.src b/apps/party_management/src/party_management.app.src index 0ce9ed7..cfee163 100644 --- a/apps/party_management/src/party_management.app.src +++ b/apps/party_management/src/party_management.app.src @@ -10,7 +10,6 @@ stdlib, genlib, pm_proto, - shumpune_proto, cowboy, woody, scoper, % should be before any scoper event handler usage diff --git a/apps/party_management/src/pm_accounting.erl b/apps/party_management/src/pm_accounting.erl index 378abf9..139d2a9 100644 --- a/apps/party_management/src/pm_accounting.erl +++ b/apps/party_management/src/pm_accounting.erl @@ -1,10 +1,3 @@ -%%% Accounting -%%% -%%% TODO -%%% - Brittle posting id assignment, it should be a level upper, maybe even in -%%% `pm_cashflow`. -%%% - Stuff cash flow details in the posting description fields. - -module(pm_accounting). -export([get_account/1]). @@ -12,17 +5,12 @@ -export([create_account/1]). -include_lib("damsel/include/dmsl_payment_processing_thrift.hrl"). --include_lib("shumpune_proto/include/shumpune_shumpune_thrift.hrl"). +-include_lib("damsel/include/dmsl_accounter_thrift.hrl"). -type amount() :: dmsl_domain_thrift:'Amount'(). -type currency_code() :: dmsl_domain_thrift:'CurrencySymbolicCode'(). -type account_id() :: dmsl_accounter_thrift:'AccountID'(). --type batch_id() :: dmsl_accounter_thrift:'BatchID'(). --type final_cash_flow() :: dmsl_domain_thrift:'FinalCashFlow'(). --type batch() :: {batch_id(), final_cash_flow()}. --type clock() :: shumpune_shumpune_thrift:'Clock'(). - --export_type([batch/0]). +-type thrift_account() :: dmsl_accounter_thrift:'Account'(). -type account() :: #{ account_id => account_id(), @@ -38,25 +26,13 @@ -spec get_account(account_id()) -> account(). get_account(AccountID) -> - case call_accounter('GetAccountByID', {AccountID}) of - {ok, Result} -> - construct_account(AccountID, Result); - {exception, #shumpune_AccountNotFound{}} -> - pm_woody_wrapper:raise(#payproc_AccountNotFound{}) - end. + Account = do_get_account(AccountID), + construct_account(Account). -spec get_balance(account_id()) -> balance(). get_balance(AccountID) -> - get_balance(AccountID, {latest, #shumpune_LatestClock{}}). - --spec get_balance(account_id(), clock()) -> balance(). -get_balance(AccountID, Clock) -> - case call_accounter('GetBalanceByID', {AccountID, Clock}) of - {ok, Result} -> - construct_balance(AccountID, Result); - {exception, #shumpune_AccountNotFound{}} -> - pm_woody_wrapper:raise(#payproc_AccountNotFound{}) - end. + Account = do_get_account(AccountID), + construct_balance(Account). -spec create_account(currency_code()) -> account_id(). create_account(CurrencyCode) -> @@ -65,24 +41,31 @@ create_account(CurrencyCode) -> -spec create_account(currency_code(), binary() | undefined) -> account_id(). create_account(CurrencyCode, Description) -> case call_accounter('CreateAccount', {construct_prototype(CurrencyCode, Description)}) of + {ok, Result} -> + Result + end. + +-spec do_get_account(account_id()) -> thrift_account(). +do_get_account(AccountID) -> + case call_accounter('GetAccountByID', {AccountID}) of {ok, Result} -> Result; - {exception, Exception} -> - % FIXME - error({accounting, Exception}) + {exception, #accounter_AccountNotFound{}} -> + pm_woody_wrapper:raise(#payproc_AccountNotFound{}) end. construct_prototype(CurrencyCode, Description) -> - #shumpune_AccountPrototype{ + #accounter_AccountPrototype{ currency_sym_code = CurrencyCode, - description = Description + description = Description, + creation_time = pm_datetime:format_now() }. %% construct_account( - AccountID, - #shumpune_Account{ + #accounter_Account{ + id = AccountID, currency_sym_code = CurrencyCode } ) -> @@ -92,8 +75,8 @@ construct_account( }. construct_balance( - AccountID, - #shumpune_Balance{ + #accounter_Account{ + id = AccountID, own_amount = OwnAmount, min_available_amount = MinAvailableAmount, max_available_amount = MaxAvailableAmount diff --git a/apps/party_management/test/pm_ct_helper.erl b/apps/party_management/test/pm_ct_helper.erl index 85176f0..c5aa153 100644 --- a/apps/party_management/test/pm_ct_helper.erl +++ b/apps/party_management/test/pm_ct_helper.erl @@ -93,7 +93,7 @@ start_app(party_management = AppName) -> } }}, {services, #{ - accounter => <<"http://shumway:8022/shumpune">>, + accounter => <<"http://shumway:8022/accounter">>, automaton => <<"http://machinegun:8022/v1/automaton">>, party_management => #{ url => <<"http://party-management:8022/v1/processing/partymgmt">>, diff --git a/apps/party_management/test/pm_party_tests_SUITE.erl b/apps/party_management/test/pm_party_tests_SUITE.erl index 4f803cf..e52ce9c 100644 --- a/apps/party_management/test/pm_party_tests_SUITE.erl +++ b/apps/party_management/test/pm_party_tests_SUITE.erl @@ -69,6 +69,7 @@ -export([shop_account_set_retrieval/1]). -export([shop_account_retrieval/1]). +-export([get_account_state_not_found/1]). -export([contract_not_found/1]). -export([contract_creation/1]). @@ -242,7 +243,8 @@ groups() -> contract_creation, shop_creation, shop_account_set_retrieval, - shop_account_retrieval + shop_account_retrieval, + get_account_state_not_found ]}, {claim_management, [sequence], [ party_creation, @@ -474,6 +476,7 @@ end_per_testcase(_Name, _C) -> -spec shop_already_active(config()) -> _ | no_return(). -spec shop_account_set_retrieval(config()) -> _ | no_return(). -spec shop_account_retrieval(config()) -> _ | no_return(). +-spec get_account_state_not_found(config()) -> _ | no_return(). -spec contract_not_found(config()) -> _ | no_return(). -spec contract_creation(config()) -> _ | no_return(). @@ -1559,6 +1562,11 @@ shop_account_retrieval(C) -> {shop_account_set_retrieval, #domain_ShopAccount{guarantee = AccountID}} = ?config(saved_config, C), #payproc_AccountState{account_id = AccountID} = pm_client_party:get_account_state(AccountID, Client). +get_account_state_not_found(C) -> + Client = cfg(client, C), + {exception, #payproc_AccountNotFound{}} = + (catch pm_client_party:get_account_state(420, Client)). + %% contractor_creation(C) -> diff --git a/apps/pm_proto/src/pm_proto.erl b/apps/pm_proto/src/pm_proto.erl index cb6809a..e70affb 100644 --- a/apps/pm_proto/src/pm_proto.erl +++ b/apps/pm_proto/src/pm_proto.erl @@ -21,7 +21,7 @@ get_service(claim_committer) -> get_service(party_management) -> {dmsl_payment_processing_thrift, 'PartyManagement'}; get_service(accounter) -> - {shumpune_shumpune_thrift, 'Accounter'}; + {dmsl_accounter_thrift, 'Accounter'}; get_service(automaton) -> {mg_proto_state_processing_thrift, 'Automaton'}; get_service(processor) -> diff --git a/docker-compose.yml b/compose.yml similarity index 96% rename from docker-compose.yml rename to compose.yml index 10b6014..282b14a 100644 --- a/docker-compose.yml +++ b/compose.yml @@ -51,7 +51,7 @@ services: retries: 20 shumway: - image: docker.io/rbkmoney/shumway:44eb989065b27be619acd16b12ebdb2288b46c36 + image: docker.io/rbkmoney/shumway:d5b74714437b1a1b11689a38297fd2a6c08e0db2 restart: unless-stopped depends_on: - shumway-db diff --git a/config/sys.config b/config/sys.config index c251a2b..b6b4960 100644 --- a/config/sys.config +++ b/config/sys.config @@ -37,7 +37,7 @@ }}, {services, #{ automaton => "http://machinegun:8022/v1/automaton", - accounter => "http://shumway:8022/shumpune" + accounter => "http://shumway:8022/accounter" }}, {cache_options, #{ %% see `pm_party_cache:cache_options/0` memory => 209715200, % 200Mb, cache memory quota in bytes diff --git a/rebar.config b/rebar.config index 4311ce8..7320791 100644 --- a/rebar.config +++ b/rebar.config @@ -33,8 +33,6 @@ {damsel, {git, "https://github.com/valitydev/damsel.git", {branch, "master"}}}, {payproc_errors, {git, "https://github.com/valitydev/payproc-errors-erlang.git", {branch, "master"}}}, {mg_proto, {git, "https://github.com/valitydev/machinegun-proto.git", {branch, "master"}}}, - {shumpune_proto, - {git, "https://github.com/valitydev/shumaich-proto.git", {ref, "a0aed3bdce6aafdb832bbcde45e6278222b08c0b"}}}, {dmt_client, {git, "https://github.com/valitydev/dmt_client.git", {branch, "master"}}}, {scoper, {git, "https://github.com/valitydev/scoper.git", {branch, "master"}}}, {erl_health, {git, "https://github.com/valitydev/erlang-health.git", {branch, "master"}}} diff --git a/rebar.lock b/rebar.lock index 23e07b3..5d6a3d6 100644 --- a/rebar.lock +++ b/rebar.lock @@ -9,7 +9,7 @@ {<<"cowlib">>,{pkg,<<"cowlib">>,<<"2.11.0">>},2}, {<<"damsel">>, {git,"https://github.com/valitydev/damsel.git", - {ref,"8016313ab8c27a237a33927a0ee22dd58524e86c"}}, + {ref,"3efe7dffaae0f40a77dead166a52f8c9108f2d8d"}}, 0}, {<<"dmt_client">>, {git,"https://github.com/valitydev/dmt_client.git", @@ -47,10 +47,6 @@ {git,"https://github.com/valitydev/scoper.git", {ref,"7f3183df279bc8181efe58dafd9cae164f495e6f"}}, 0}, - {<<"shumpune_proto">>, - {git,"https://github.com/valitydev/shumaich-proto.git", - {ref,"a0aed3bdce6aafdb832bbcde45e6278222b08c0b"}}, - 0}, {<<"snowflake">>, {git,"https://github.com/valitydev/snowflake.git", {ref,"de159486ef40cec67074afe71882bdc7f7deab72"}},