Skip to content

Commit 67e21d7

Browse files
author
Andrei Zavada
committed
option to define network to run stanchion on
1 parent 2a15bc0 commit 67e21d7

File tree

14 files changed

+83
-65
lines changed

14 files changed

+83
-65
lines changed

apps/riak_cs/priv/riak_cs.schema

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@
5656
{validators, ["valid_host"]}
5757
]}.
5858

59-
%% @doc Configuration for access to request
60-
%% serialization service
61-
{mapping, "stanchion_host", "riak_cs.stanchion_host", [
62-
{default, {"{{stanchion_host}}", {{stanchion_port}} }},
63-
{datatype, [fqdn, ip]},
64-
{validators, ["valid_host"]}
65-
]}.
66-
6759
%% @doc Default cert location for https can be overridden
6860
%% with the ssl config variable, for example:
6961
{mapping, "ssl.certfile", "riak_cs.ssl.certfile", [
@@ -79,14 +71,19 @@
7971
]}.
8072

8173

82-
8374
%% @doc Stanchion http/https port and IP address to listen at
8475
{mapping, "stanchion.listener", "riak_cs.stanchion_listener", [
8576
{default, {"{{stanchion_ip}}", {{stanchion_port}} }},
8677
{datatype, ip},
8778
{validators, ["valid_host"]}
8879
]}.
8980

81+
%% @doc Netmask to use when selecting which network to place stanchion on
82+
{mapping, "stanchion_netmask", "riak_cs.stanchion_netmask", [
83+
{default, "{{stanchion_netmask}}"},
84+
{datatype, string}
85+
]}.
86+
9087
%% @doc SSL configuration for access to request serialization
9188
%% service. With `on`, Riak CS connects to Stanchion with SSL.
9289
{mapping, "stanchion.ssl", "riak_cs.stanchion_ssl", [

apps/riak_cs/src/riak_cs_config.erl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,15 @@
6262
max_key_length/0,
6363
read_before_last_manifest_write/0,
6464
region/0,
65-
stanchion/0,
6665
set_stanchion/2, set_stanchion/3,
6766
use_2i_for_storage_calc/0,
6867
detailed_storage_calc/0,
6968
quota_modules/0,
7069
active_delete_threshold/0,
7170
fast_user_get/0,
7271
root_host/0,
72+
stanchion/0,
73+
stanchion_netmask/0,
7374
stanchion_hosting_mode/0,
7475
tussle_voss_riak_host/0
7576
]).
@@ -381,6 +382,11 @@ stanchion() ->
381382
{ok, SSL} = application:get_env(riak_cs, stanchion_ssl),
382383
{Host, Port, SSL}.
383384

385+
-spec stanchion_netmask() -> string().
386+
stanchion_netmask() ->
387+
{ok, A} = application:get_env(riak_cs, stanchion_netmask),
388+
A.
389+
384390
-spec set_stanchion(string(), inet:port()) -> ok.
385391
set_stanchion(Host, Port) ->
386392
application:set_env(riak_cs, stanchion_host, {Host, Port}),

apps/riak_cs/src/riak_cs_utils.erl

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
stanchion_data/0,
7373
camel_case/1,
7474
capitalize/1,
75-
this_host_addr/0
75+
this_host_addresses/0,
76+
select_addr_for_stanchion/0
7677
]).
7778

7879
-include("riak_cs.hrl").
@@ -536,35 +537,58 @@ capitalize("") -> "";
536537
capitalize([H|T]) -> string:to_upper([H]) ++ T.
537538

538539

539-
540-
this_host_addr() ->
540+
-spec select_addr_for_stanchion() -> string().
541+
select_addr_for_stanchion() ->
541542
{ok, Ifs} = inet:getifaddrs(),
543+
Mask = riak_cs_config:stanchion_netmask(),
544+
{ok, {M1, M2, M3, M4}} = inet:parse_address(Mask),
542545
case lists:filtermap(
543-
fun({_If, PL}) ->
544-
case proplists:get_value(addr, PL) of
545-
AA when AA /= undefined,
546-
AA /= {127,0,0,1},
547-
AA /= {0,0,0,0},
548-
size(AA) == 4 ->
549-
{A1, A2, A3, A4} = AA,
550-
{true, {_If, lists:flatten(io_lib:format("~b.~b.~b.~b", [A1, A2, A3, A4]))}};
551-
_ ->
546+
fun({_If, IfOpts}) ->
547+
{A1, A2, A3, A4} = Addr = extract_addr(IfOpts),
548+
if (M1 band A1) > 0 andalso
549+
(M2 band A2) > 0 andalso
550+
(M3 band A3) > 0 andalso
551+
(M4 band A4) > 0 ->
552+
{true, Addr};
553+
el/=se ->
552554
false
553555
end
554-
end, Ifs) of
555-
[{If, IP}] ->
556-
?LOG_DEBUG("this host address is ~s on iface ~s", [IP, If]),
557-
IP;
558-
[{If, IP}|_] ->
559-
logger:warning("This host has multiple network interfaces configured:"
560-
" selecting ~p on ~s", [IP, If]),
561-
IP;
556+
end,
557+
Ifs) of
558+
[{A1, A2, A3, A4}|_] ->
559+
lists:flatten(io_lib:format("~b.~b.~b.~b", [A1, A2, A3, A4]));
562560
[] ->
563-
logger:warning("This host has no network interfaces with assigned addresses:"
564-
" falling back to 127.0.0.1", []),
561+
logger:warning("No network interfaces with assigned addresses matching ~s:"
562+
" falling back to 127.0.0.1", [Mask]),
565563
"127.0.0.1"
566564
end.
567565

566+
extract_addr(IfItem) ->
567+
case proplists:get_value(addr, IfItem) of
568+
AA when AA /= undefined,
569+
AA /= {0,0,0,0},
570+
size(AA) == 4 ->
571+
AA;
572+
_ ->
573+
{127,0,0,1}
574+
end.
575+
576+
-spec this_host_addresses() -> [string()].
577+
this_host_addresses() ->
578+
{ok, Ifs} = inet:getifaddrs(),
579+
lists:filtermap(
580+
fun({_If, PL}) ->
581+
case proplists:get_value(addr, PL) of
582+
AA when AA /= undefined,
583+
AA /= {0,0,0,0},
584+
size(AA) == 4 ->
585+
{A1, A2, A3, A4} = AA,
586+
{true, lists:flatten(io_lib:format("~b.~b.~b.~b", [A1, A2, A3, A4]))};
587+
_ ->
588+
false
589+
end
590+
end, Ifs).
591+
568592
-ifdef(TEST).
569593

570594
camel_case_test() ->

apps/riak_cs/src/stanchion_migration.erl

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@
3737
-spec validate_stanchion() -> ok.
3838
validate_stanchion() ->
3939
{ConfiguredIP, ConfiguredPort, _Ssl} = riak_cs_config:stanchion(),
40-
logger:info("validate_stanchion: ~p", [{ConfiguredIP, ConfiguredPort}]),
40+
logger:debug("validate_stanchion: ~p", [{ConfiguredIP, ConfiguredPort}]),
4141
case read_stanchion_data() of
4242
{ok, {{Host, Port}, Node}}
4343
when Host == ConfiguredIP,
4444
Port == ConfiguredPort,
4545
Node == node() ->
46-
logger:info("validate_stanchion: matching data read"),
46+
logger:debug("validate_stanchion: matching data read"),
4747
ok;
4848
{ok, {{Host, Port}, Node}} ->
4949
logger:info("stanchion details updated: ~s:~p on ~s", [Host, Port, Node]),
50-
case riak_cs_utils:this_host_addr() of
51-
ConfiguredIP when node() == Node ->
50+
case lists:member(ConfiguredIP, riak_cs_utils:this_host_addresses()) of
51+
true when node() == Node ->
5252
stop_stanchion_here(),
5353
ok;
5454
_ ->
@@ -57,21 +57,19 @@ validate_stanchion() ->
5757
apply_stanchion_details({Host, Port});
5858
{error, notfound} ->
5959
logger:info("no previously saved stanchion details; adopting stanchion here"),
60-
apply_stanchion_details({ConfiguredIP, ConfiguredPort}),
61-
start_stanchion_here(),
62-
ok = save_stanchion_data({ConfiguredIP, ConfiguredPort})
60+
adopt_stanchion()
6361
end.
6462

6563

6664
-spec adopt_stanchion() -> ok | {error, stanchion_not_relocatable}.
6765
adopt_stanchion() ->
6866
case riak_cs_config:stanchion_hosting_mode() of
6967
auto ->
70-
ThisHostAddr = riak_cs_utils:this_host_addr(),
68+
Addr = riak_cs_utils:select_addr_for_stanchion(),
7169
{ok, {_IP, Port}} = application:get_env(riak_cs, stanchion_listener),
7270
start_stanchion_here(),
73-
ok = save_stanchion_data({ThisHostAddr, Port}),
74-
apply_stanchion_details({ThisHostAddr, Port}),
71+
ok = save_stanchion_data({Addr, Port}),
72+
apply_stanchion_details({Addr, Port}),
7573
ok;
7674
M ->
7775
logger:error("Riak CS stanchion_hosting_mode is ~s. Cannot adopt stanchion.", [M]),

apps/riak_cs/src/stanchion_sup.erl

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,6 @@ ensure_service_bucket_props(Pbc) ->
4949
-spec init([]) -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
5050
init([]) ->
5151
Children = [],
52-
%% stanchion webmachine to be added to this sup on demand
53-
%% {ok, Mode} = application:get_env(riak_cs, stanchion_hosting_mode),
54-
%% ThisHostAddr = riak_cs_utils:this_host_addr(),
55-
%% case stanchion_migration:do_we_get_to_run_stanchion(Mode, ThisHostAddr) of
56-
%% {use_saved, HostPort} ->
57-
%% ok = stanchion_migration:apply_stanchion_details(HostPort),
58-
%% [];
59-
%% use_ours ->
60-
%% {ok, {_IP, Port}} = application:get_env(riak_cs, stanchion_listener),
61-
%% ok = stanchion_migration:save_stanchion_data({ThisHostAddr, Port}),
62-
%% stanchion_process_specs()
63-
%% end,
6452
{ok, {#{strategy => one_for_one,
6553
intensity => 10,
6654
period => 10}, Children

config/sys.config.defaults

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ RIAK_HOST="127.0.0.1"
77
RIAK_PORT=8087
88
RCS_LISTENER_IP="0.0.0.0"
99
RCS_LISTENER_PORT=8080
10+
STANCHION_HOSTING_MODE=auto
1011
STANCHION_LISTENER_IP="0.0.0.0"
1112
STANCHION_LISTENER_PORT=8085
12-
13-
STANCHION_HOST="127.0.0.1"
1413
STANCHION_PORT=8085
1514
STANCHION_SSL=false
15+
STANCHION_NETMASK="255.255.255.255"
16+
TUSSLE_VOSS_RIAK_HOST=auto
1617
AUTH_V4_ENABLED=true
1718
AUTH_BYPASS=false
1819

config/sys.docker.config.src

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@
3232
{auth_bypass, ${AUTH_BYPASS}},
3333
{admin_key, ${ADMIN_KEY}},
3434
{anonymous_user_creation, ${ANONYMOUS_USER_CREATION}},
35-
{stanchion_host,{${STANCHION_HOST}, ${STANCHION_PORT}}},
3635
{riak_host, {${RIAK_HOST}, ${RIAK_PORT}}},
3736
{listener, {${RCS_LISTENER_IP}, ${RCS_LISTENER_PORT}}},
37+
{stanchion_hosting_mode, ${STANCHION_HOSTING_MODE}},
3838
{stanchion_listener, ${STANCHION_LISTENER_IP}, ${STANCHION_LISTENER_PORT}},
3939
{stanchion_ssl, ${STANCHION_SSL}},
4040
{stanchion_ssl_certfile, ${STANCHION_SSL_CERTFILE}},
4141
{stanchion_ssl_keyfile, ${STANCHION_SSL_KEYFILE}},
42+
{stanchion_netmask, ${STANCHION_NETMASK}},
43+
{tussle_voss_riak_host, ${TUSSLE_VOSS_RIAK_HOST}}
4244
{connection_pools,[{request_pool,{128,0}},{bucket_list_pool,{5,0}}]}]},
4345
{sasl,[{sasl_error_logger,false}]},
4446
{webmachine,

rebar.docker.config

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@
1919
, {mochiweb, "3.1.1"}
2020
, {exometer_core, "v1.5.7"}
2121
, {uuid, "2.0.5", {pkg, uuid_erl}}
22+
, {poolboy, "1.5.2"}
2223
, {webmachine, {git, "https://github.com/TI-Tokyo/webmachine.git", {tag, "1.11.2rc2"}}}
2324
, {riakc, {git, "https://github.com/basho/riak-erlang-client", {tag, "3.0.8+p1"}}}
24-
, {poolboy, {git, "https://github.com/basho/poolboy", {tag, "riak_kv-3.0.0"}}}
2525
, {cluster_info, {git, "https://github.com/basho/cluster_info", {tag, "2.1.0"}}}
26-
, {riak_repl_pb_api, {git,"https://github.com/TI-Tokyo/riak_repl_pb_api.git", {tag, "3.0.9"}}}
27-
, {riak_cs_multibag, {git,"https://github.com/TI-Tokyo/riak_cs_multibag.git", {branch, "develop"}}}
26+
, {riak_repl_pb_api, {git, "https://github.com/TI-Tokyo/riak_repl_pb_api.git", {tag, "3.1.0rc2"}}}
27+
, {riak_cs_multibag, {git, "https://github.com/TI-Tokyo/riak_cs_multibag.git", {tag, "3.1.0rc1"}}}
2828
]
2929
}.
3030

3131

32-
{relx, [ {release, {'riak-cs', "3.0"},
32+
{relx, [ {release, {'riak-cs', "3.1"},
3333
[ sasl
3434
, riak_cs
3535
]
@@ -64,5 +64,3 @@
6464
[ {del, meck, [{erl_opts, [warnings_as_errors]}]}
6565
]
6666
}.
67-
68-
{dialyzer, [{plt_apps, all_deps}]}.

rel/pkg/alpine/vars.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
{auth_module, riak_cs_s3_auth}.
3131
{stanchion_hosting_mode, auto}.
3232
{tussle_voss_riak_host, auto}.
33+
{stanchion_netmask, "255.255.255.255"}.
3334

3435
3536
{crash_dump, "{{platform_log_dir}}/erl_crash.dump"}.

rel/pkg/deb/vars.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
{auth_module, riak_cs_s3_auth}.
3333
{stanchion_hosting_mode, auto}.
3434
{tussle_voss_riak_host, auto}.
35+
{stanchion_netmask, "255.255.255.255"}.
3536

3637
3738
{crash_dump, "{{platform_log_dir}}/erl_crash.dump"}.

0 commit comments

Comments
 (0)