1 |
|
-module(mongoose_wpool_riak). |
2 |
|
-behaviour(mongoose_wpool). |
3 |
|
|
4 |
|
-export([init/0]). |
5 |
|
-export([start/4]). |
6 |
|
-export([stop/2]). |
7 |
|
-export([is_supported_strategy/1]). |
8 |
|
|
9 |
|
%% -------------------------------------------------------------- |
10 |
|
%% mongoose_wpool callbacks |
11 |
|
init() -> |
12 |
:-( |
ok. |
13 |
|
|
14 |
|
start(HostType, Tag, WpoolOptsIn, ConnOpts) -> |
15 |
:-( |
ProcName = mongoose_wpool:make_pool_name(riak, HostType, Tag), |
16 |
:-( |
WpoolOpts = wpool_spec(WpoolOptsIn, ConnOpts), |
17 |
:-( |
mongoose_wpool:start_sup_pool(riak, ProcName, WpoolOpts). |
18 |
|
|
19 |
|
stop(_, _) -> |
20 |
:-( |
ok. |
21 |
|
|
22 |
:-( |
is_supported_strategy(available_worker) -> false; |
23 |
:-( |
is_supported_strategy(_) -> true. |
24 |
|
|
25 |
|
%% -------------------------------------------------------------- |
26 |
|
%% Other functions |
27 |
|
|
28 |
|
wpool_spec(WpoolOptsIn, ConnOpts = #{address := RiakAddr, port := RiakPort}) -> |
29 |
:-( |
SecurityOptsKV = prepare_sec_opts(ConnOpts), |
30 |
:-( |
RiakPBOpts = [auto_reconnect, keepalive], |
31 |
:-( |
WorkerArgs = RiakPBOpts ++ SecurityOptsKV, |
32 |
:-( |
Worker = {riakc_pb_socket, [RiakAddr, RiakPort, WorkerArgs]}, |
33 |
:-( |
[{worker, Worker} | WpoolOptsIn]. |
34 |
|
|
35 |
|
prepare_sec_opts(ConnOpts) -> |
36 |
:-( |
SecurityOptsKeys = [credentials, cacertfile, ssl_opts], |
37 |
:-( |
SecurityOpts = maps:with(SecurityOptsKeys, ConnOpts), |
38 |
:-( |
ListOpts = maps:to_list(SecurityOpts), |
39 |
:-( |
lists:map(fun prepare_credentials/1, ListOpts). |
40 |
|
|
41 |
|
prepare_credentials({credentials, {User, Password}}) -> |
42 |
:-( |
{credentials, User, Password}; |
43 |
|
prepare_credentials(Opt) -> |
44 |
:-( |
Opt. |