Skip to content

Commit e23c41f

Browse files
authored
Adopts dominant-v2 with upgraded party-management #minor (#159)
* Upgrades to dmt-client v2 * Reverts service renaming and updates dominant urls * Adopts dominant-v2 with upgraded party-management * Refactors postgres in compose * Adds makefile recipe to psql into one of a composed databases * Adds limiter w/ dmt-v2 support * Fixes route-cascading test group * Fixes formatting * Updates docker compose command and initdb script permissions * Adds domain config reset after `route_cascading` group * Bumps limiter & party-management in compose env * Bump dmt-v2, limiter & party-management * Adds missing auto tag action
1 parent 62f116f commit e23c41f

18 files changed

Lines changed: 458 additions & 234 deletions

.github/workflows/tag-action.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Create Tag
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout Repo
13+
uses: actions/checkout@v3
14+
15+
- uses: valitydev/action-tagger@v2
16+
with:
17+
github-token: ${{ secrets.GITHUB_TOKEN }}
18+
with-v: true

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ DEV_IMAGE_TAG = $(TEST_CONTAINER_NAME)-dev
1515
DEV_IMAGE_ID = $(file < .image.dev)
1616

1717
DOCKER ?= docker
18-
DOCKERCOMPOSE ?= docker-compose
18+
DOCKERCOMPOSE ?= docker compose
1919
DOCKERCOMPOSE_W_ENV = DEV_IMAGE_TAG=$(DEV_IMAGE_TAG) $(DOCKERCOMPOSE) -f compose.yaml -f compose.tracing.yaml
2020
REBAR ?= rebar3
2121
TEST_CONTAINER_NAME ?= testrunner
@@ -64,6 +64,16 @@ wdeps-%: dev-image
6464
$(DOCKERCOMPOSE_W_ENV) down; \
6565
exit $$res
6666

67+
# Database tasks
68+
69+
ifeq (db,$(firstword $(MAKECMDGOALS)))
70+
DATABASE_NAME := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
71+
$(eval $(DATABASE_NAME):;@:)
72+
endif
73+
74+
db:
75+
$(DOCKERCOMPOSE_W_ENV) exec db bash -c "PGPASSWORD=postgres psql -U $(DATABASE_NAME) -d $(DATABASE_NAME)"
76+
6777
# Rebar tasks
6878

6979
rebar-shell:

apps/hellgate/src/hg_domain.erl

Lines changed: 35 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,23 @@
66

77
-module(hg_domain).
88

9-
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
10-
-include_lib("damsel/include/dmsl_domain_conf_thrift.hrl").
9+
-include_lib("damsel/include/dmsl_domain_conf_v2_thrift.hrl").
1110

1211
%%
1312

1413
-export([head/0]).
1514
-export([get/1]).
1615
-export([get/2]).
17-
-export([get_without_exp/2]).
18-
-export([find/2]).
19-
-export([exists/2]).
20-
-export([commit/2]).
2116
-export([reset/1]).
2217

2318
-export([insert/1]).
2419
-export([update/1]).
2520
-export([upsert/1]).
26-
-export([remove/1]).
2721
-export([cleanup/0]).
2822

2923
%%
3024

31-
-type revision() :: dmt_client:version().
25+
-type revision() :: dmt_client:vsn().
3226
-type ref() :: dmsl_domain_thrift:'Reference'().
3327
-type object() :: dmsl_domain_thrift:'DomainObject'().
3428
-type data() :: _.
@@ -42,7 +36,7 @@
4236

4337
-spec head() -> revision().
4438
head() ->
45-
dmt_client:get_last_version().
39+
dmt_client:get_latest_version().
4640

4741
-spec get(ref()) -> data() | no_return().
4842
get(Ref) ->
@@ -53,69 +47,59 @@ get(Revision, Ref) ->
5347
try
5448
extract_data(dmt_client:checkout_object(Revision, Ref))
5549
catch
56-
throw:#domain_conf_ObjectNotFound{} ->
50+
throw:#domain_conf_v2_ObjectNotFound{} ->
5751
error({object_not_found, {Revision, Ref}})
5852
end.
5953

60-
-spec get_without_exp(dmt_client:version(), ref()) -> data() | get_error().
61-
get_without_exp(Revision, Ref) ->
62-
try
63-
extract_data(dmt_client:checkout_object(Revision, Ref))
64-
catch
65-
throw:#domain_conf_ObjectNotFound{} ->
66-
{object_not_found, {Revision, Ref}}
67-
end.
68-
69-
-spec find(revision(), ref()) -> data() | notfound.
70-
find(Revision, Ref) ->
71-
try
72-
extract_data(dmt_client:checkout_object(Revision, Ref))
73-
catch
74-
throw:#domain_conf_ObjectNotFound{} ->
75-
notfound
76-
end.
77-
78-
-spec exists(revision(), ref()) -> boolean().
79-
exists(Revision, Ref) ->
80-
try
81-
_ = dmt_client:checkout_object(Revision, Ref),
82-
true
83-
catch
84-
throw:#domain_conf_ObjectNotFound{} ->
85-
false
86-
end.
87-
88-
extract_data({_Tag, {_Name, _Ref, Data}}) ->
54+
extract_data(#domain_conf_v2_VersionedObject{object = {_Tag, {_Name, _Ref, Data}}}) ->
8955
Data.
9056

91-
-spec commit(revision(), dmt_client:commit()) -> revision() | no_return().
92-
commit(Revision, Commit) ->
93-
dmt_client:commit(Revision, Commit).
94-
9557
-spec reset(revision()) -> revision() | no_return().
9658
reset(ToRevision) ->
97-
#domain_conf_Snapshot{domain = Domain} = dmt_client:checkout(ToRevision),
98-
upsert(maps:values(Domain)).
59+
Objects = dmt_client:checkout_all(ToRevision),
60+
upsert(unwrap_versioned_objects(Objects)).
9961

10062
%% convenience shortcuts, use carefully
10163

10264
-spec insert(object() | [object()]) -> revision() | no_return().
10365
insert(ObjectOrMany) ->
104-
dmt_client:insert(ObjectOrMany).
66+
dmt_client:insert(ObjectOrMany, ensure_stub_author()).
10567

10668
-spec update(object() | [object()]) -> revision() | no_return().
10769
update(NewObjectOrMany) ->
108-
dmt_client:update(NewObjectOrMany).
70+
dmt_client:update(NewObjectOrMany, ensure_stub_author()).
10971

11072
-spec upsert(object() | [object()]) -> revision() | no_return().
11173
upsert(NewObjectOrMany) ->
112-
dmt_client:upsert(NewObjectOrMany).
74+
%% NOTE Checkout all objects from target version to ensure it all
75+
%% cached before operations preparation.
76+
Version = dmt_client:get_latest_version(),
77+
_ = dmt_client:checkout_all(Version),
78+
dmt_client:upsert(Version, NewObjectOrMany, ensure_stub_author()).
11379

11480
-spec remove(object() | [object()]) -> revision() | no_return().
11581
remove(ObjectOrMany) ->
116-
dmt_client:remove(ObjectOrMany).
82+
dmt_client:remove(ObjectOrMany, ensure_stub_author()).
11783

11884
-spec cleanup() -> revision() | no_return().
11985
cleanup() ->
120-
#domain_conf_Snapshot{domain = Domain} = dmt_client:checkout(latest),
121-
remove(maps:values(Domain)).
86+
Objects = dmt_client:checkout_all(latest),
87+
remove(unwrap_versioned_objects(Objects)).
88+
89+
ensure_stub_author() ->
90+
%% TODO DISCUSS Stubs and fallback authors
91+
ensure_author(~b"unknown", ~b"unknown@local").
92+
93+
ensure_author(Name, Email) ->
94+
try
95+
#domain_conf_v2_Author{id = ID} = dmt_client:get_author_by_email(Email),
96+
ID
97+
catch
98+
throw:#domain_conf_v2_AuthorNotFound{} ->
99+
dmt_client:create_author(Name, Email)
100+
end.
101+
102+
%%
103+
104+
unwrap_versioned_objects(VersionedObjects) ->
105+
lists:map(fun(#domain_conf_v2_VersionedObject{object = Object}) -> Object end, VersionedObjects).

apps/hellgate/src/hg_invoice_payment_refund.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
-type session() :: hg_session:t().
8989
-type trx_info() :: dmsl_domain_thrift:'TransactionInfo'().
9090
-type failure() :: dmsl_domain_thrift:'OperationFailure'().
91-
-type revision() :: dmt_client:version().
91+
-type revision() :: dmt_client:vsn().
9292
-type cash() :: dmsl_domain_thrift:'Cash'().
9393
-type timestamp() :: dmsl_base_thrift:'Timestamp'().
9494
-type route() :: dmsl_domain_thrift:'PaymentRoute'().

apps/hellgate/test/hg_ct_helper.erl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ start_app(dmt_client = AppName) ->
115115
}}
116116
]},
117117
{service_urls, #{
118-
'Repository' => <<"http://dominant:8022/v1/domain/repository">>,
119-
'RepositoryClient' => <<"http://dominant:8022/v1/domain/repository_client">>
118+
'AuthorManagement' => <<"http://dmt:8022/v1/domain/author">>,
119+
'Repository' => <<"http://dmt:8022/v1/domain/repository">>,
120+
'RepositoryClient' => <<"http://dmt:8022/v1/domain/repository_client">>
120121
}}
121122
]),
122123
#{}
@@ -268,11 +269,11 @@ start_app(epg_connector = AppName) ->
268269
start_app(AppName, [
269270
{databases, #{
270271
default_db => #{
271-
host => "postgres",
272+
host => "db",
272273
port => 5432,
273-
database => "progressor_db",
274-
username => "progressor",
275-
password => "progressor"
274+
database => "hellgate",
275+
username => "hellgate",
276+
password => "postgres"
276277
}
277278
}},
278279
{pools, #{

apps/hellgate/test/hg_invoice_tests_SUITE.erl

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ end).
641641

642642
-spec init_per_group(group_name(), config()) -> config().
643643
init_per_group(route_cascading, C) ->
644-
init_route_cascading_group(C);
644+
[{pre_group_domain_revision, hg_domain:head()} | init_route_cascading_group(C)];
645645
init_per_group(operation_limits, C) ->
646646
init_operation_limits_group(C);
647647
init_per_group(repair_preproc_w_limits, C) ->
@@ -650,8 +650,14 @@ init_per_group(_, C) ->
650650
C.
651651

652652
-spec end_per_group(group_name(), config()) -> _.
653-
end_per_group(_Group, _C) ->
654-
ok.
653+
end_per_group(_Group, C) ->
654+
case cfg(pre_group_domain_revision, C) of
655+
Revision when is_integer(Revision) ->
656+
_ = hg_domain:reset(Revision),
657+
ok;
658+
undefined ->
659+
ok
660+
end.
655661

656662
-spec init_per_testcase(test_case_name(), config()) -> config().
657663
init_per_testcase(Name, C) when
@@ -1185,7 +1191,7 @@ payment_shop_limit_success(C) ->
11851191
#domain_TurnoverLimit{
11861192
id = ?SHOPLIMIT_ID,
11871193
upper_boundary = ?LIMIT_UPPER_BOUNDARY,
1188-
domain_revision = dmt_client:get_last_version()
1194+
domain_revision = hg_domain:head()
11891195
}
11901196
],
11911197
ShopID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), TurnoverLimits, PartyClient),
@@ -1206,7 +1212,7 @@ payment_shop_limit_overflow(C) ->
12061212
#domain_TurnoverLimit{
12071213
id = ?SHOPLIMIT_ID,
12081214
upper_boundary = ?LIMIT_UPPER_BOUNDARY,
1209-
domain_revision = dmt_client:get_last_version()
1215+
domain_revision = hg_domain:head()
12101216
}
12111217
]),
12121218
ShopID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), TurnoverLimits, PartyClient),
@@ -1229,7 +1235,7 @@ payment_shop_limit_more_overflow(C) ->
12291235
#domain_TurnoverLimit{
12301236
id = ?SHOPLIMIT_ID,
12311237
upper_boundary = ?LIMIT_UPPER_BOUNDARY,
1232-
domain_revision = dmt_client:get_last_version()
1238+
domain_revision = hg_domain:head()
12331239
}
12341240
]),
12351241
ShopID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?trms(1), ?pinst(1), TurnoverLimits, PartyClient),
@@ -6009,7 +6015,9 @@ cascade_fixture(Revision, C) ->
60096015
init_route_cascading_group(C1) ->
60106016
PartyID = cfg(party_id, C1),
60116017
PartyClient = cfg(party_client, C1),
6012-
_ = override_domain_fixture(fun cascade_fixture_pre_shop_create/2, undefined, C1),
6018+
Revision = hg_domain:head(),
6019+
ok = hg_context:save(hg_context:create()),
6020+
_ = hg_domain:upsert(cascade_fixture_pre_shop_create(Revision, C1)),
60136021
C2 = [
60146022
{
60156023
{shop_id, ?PAYMENT_CASCADE_SUCCESS_ID},
@@ -6095,7 +6103,9 @@ init_route_cascading_group(C1) ->
60956103
}
60966104
| C1
60976105
],
6098-
override_domain_fixture(fun cascade_fixture/2, undefined, C2).
6106+
ok = hg_context:cleanup(),
6107+
_ = hg_domain:upsert(cascade_fixture(Revision, C2)),
6108+
[{base_limits_domain_revision, Revision} | C2].
60996109

61006110
init_per_cascade_case(payment_cascade_success, C) ->
61016111
ShopID = cfg({shop_id, ?PAYMENT_CASCADE_SUCCESS_ID}, C),
@@ -9361,7 +9371,7 @@ construct_domain_fixture() ->
93619371
#domain_TurnoverLimit{
93629372
id = ?LIMIT_ID,
93639373
upper_boundary = ?LIMIT_UPPER_BOUNDARY,
9364-
domain_revision = dmt_client:get_last_version()
9374+
domain_revision = hg_domain:head()
93659375
}
93669376
]}
93679377
}
@@ -9414,7 +9424,7 @@ construct_domain_fixture() ->
94149424
#domain_TurnoverLimit{
94159425
id = ?LIMIT_ID2,
94169426
upper_boundary = ?LIMIT_UPPER_BOUNDARY,
9417-
domain_revision = dmt_client:get_last_version()
9427+
domain_revision = hg_domain:head()
94189428
}
94199429
]}
94209430
}
@@ -9459,7 +9469,7 @@ construct_domain_fixture() ->
94599469
#domain_TurnoverLimit{
94609470
id = ?LIMIT_ID3,
94619471
upper_boundary = ?LIMIT_UPPER_BOUNDARY,
9462-
domain_revision = dmt_client:get_last_version()
9472+
domain_revision = hg_domain:head()
94639473
}
94649474
]}
94659475
}

apps/hellgate/test/hg_limiter_helper.erl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,18 @@
2929

3030
-spec init_per_suite(config()) -> dmt_client:vsn().
3131
init_per_suite(_Config) ->
32-
dmt_client:upsert([
33-
{limit_config, mk_config_object(?LIMIT_ID)},
34-
{limit_config, mk_config_object(?LIMIT_ID2)},
35-
{limit_config, mk_config_object(?LIMIT_ID3)},
36-
{limit_config, mk_config_object(?LIMIT_ID4)},
37-
{limit_config, mk_config_object(?SHOPLIMIT_ID)}
38-
]).
32+
dmt_client:upsert(
33+
latest,
34+
[
35+
{limit_config, mk_config_object(?LIMIT_ID)},
36+
{limit_config, mk_config_object(?LIMIT_ID2)},
37+
{limit_config, mk_config_object(?LIMIT_ID3)},
38+
{limit_config, mk_config_object(?LIMIT_ID4)},
39+
{limit_config, mk_config_object(?SHOPLIMIT_ID)}
40+
],
41+
dmt_client:create_author(genlib:unique(), genlib:unique()),
42+
#{}
43+
).
3944

4045
-spec get_amount(_) -> pos_integer().
4146
get_amount(#limiter_Limit{amount = Amount}) ->

apps/hellgate/test/hg_mock_helper.erl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ mock_services(Services, SupPid) ->
5959
mock_dominant(Services0, SupPid) ->
6060
Services1 = lists:map(
6161
fun
62+
({'AuthorManagement', Fun}) ->
63+
{'AuthorManagement', {dmsl_domain_conf_v2_thrift, 'AuthorManagement'}, Fun};
6264
({'Repository', Fun}) ->
63-
{'Repository', {dmsl_domain_conf_thrift, 'Repository'}, Fun};
65+
{'Repository', {dmsl_domain_conf_v2_thrift, 'Repository'}, Fun};
6466
({'RepositoryClient', Fun}) ->
65-
{'RepositoryClient', {dmsl_domain_conf_thrift, 'RepositoryClient'}, Fun}
67+
{'RepositoryClient', {dmsl_domain_conf_v2_thrift, 'RepositoryClient'}, Fun}
6668
end,
6769
Services0
6870
),

0 commit comments

Comments
 (0)