Skip to content

Instantly share code, notes, and snippets.

@hanikesn
Created March 19, 2014 17:18
Show Gist options
  • Save hanikesn/9646569 to your computer and use it in GitHub Desktop.
Save hanikesn/9646569 to your computer and use it in GitHub Desktop.
%% @doc Name of the riak cluster for the stats
{mapping, "riak_cluster.stats", "ark_stats.riak_cluster", [
{datatype, atom},
{default, "$(riak_cluster.default)"}
]}.
%% @doc Name of the riak cluster for the tracker
{mapping, "riak_cluster.tracker", "ark_tracker.riak_cluster", [
{datatype, atom},
{default, "$(riak_cluster.default)"}
]}.
%% @doc Name of the riak cluster used when no other is specified
{mapping, "riak_cluster.default", "riak_pool.default_cluster", [
{datatype, atom},
{default, "main_cluster"}
]}.
%% @doc Name of the riak cluster used when no other is specified
{mapping, "riak_cluster.cluster.$name.ping_request_timeout", "riak_pool.clusters", [
{default, "1500ms"},
{include_default, "main_cluster"},
{datatype, {duration, ms}}
]}.
%% @doc Name of the riak cluster used when no other is specified
{mapping, "riak_cluster.cluster.$name.reconnect_timer.value", "riak_pool.clusters.x", [
{default, "200ms"},
{include_default, "main_cluster"},
{datatype, {duration, ms}}
]}.
%% @doc Name of the riak cluster used when no other is specified
{mapping, "riak_cluster.cluster.$name.reconnect_timer.factor", "riak_pool.clusters.y", [
{default, "2"},
{include_default, "main_cluster"},
{datatype, integer}
]}.
%% @doc Name of the riak cluster used when no other is specified
{mapping, "riak_cluster.cluster.$name.reconnect_timer.incr", "riak_pool.clusters.z", [
{default, "1ms"},
{include_default, "main_cluster"},
{datatype, {duration, ms}}
]}.
%% @doc Name of the riak cluster used when no other is specified
{mapping, "riak_cluster.cluster.$name.reconnect_timer.max_value", "riak_pool.clusters.w", [
{default, "15s"},
{include_default, "main_cluster"},
{datatype, {duration, ms}}
]}.
%% @doc Name of the riak cluster used when no other is specified
{mapping, "riak_cluster.cluster.$name.pool.$pool.size", "riak_pool.clusters.p.s", [
{default, "10"},
{include_default, ["main_cluster"]},
{datatype, integer}
]}.
%% @doc Name of the riak cluster used when no other is specified
{mapping, "riak_cluster.cluster.$name.pool.$pool.max_overflow", "riak_pool.clusters.p.o", [
{default, "10"},
{include_default, ["main_cluster"]},
{datatype, integer}
]}.
%% @doc Name of the riak cluster used when no other is specified
{mapping, "riak_cluster.cluster.$name.pool.$pool.ip", "riak_pool.clusters.p.i", [
{default, {"127.0.0.1", 10017}},
{include_default, ["main_cluster"]},
{datatype, ip}
]}.
{translation,
"riak_pool.clusters",
fun(Conf) ->
GroupBy = fun(CL, N) -> lists:foldl(fun({L, _} = X, List) ->
Name = lists:nth(N, L),
case List of
[] -> [[X]];
[[{L1, _} | _] = Li | R] ->
N1 = lists:nth(N, L1),
case N1 of
Name -> [[X | Li] | R];
_ -> [[X] | List]
end
end
end, [], CL) end,
ClusterList = lists:filter(
fun({K, _V}) ->
lists:prefix(["riak_cluster", "cluster"], K)
end,
Conf),
CL1 = lists:keysort(1, ClusterList),
CL2 = GroupBy(CL1, 3),
Clusters = [{N, List} || [{[_,_,N|_],_} | _] = List <- CL2],
Cs = [{
list_to_atom(Name),
[{ping_request_timeout, cuttlefish:conf_get(["riak_cluster","cluster", Name, "ping_request_timeout"],ClusterConf)},
{rec_timer, [
{value, cuttlefish:conf_get(["riak_cluster","cluster", Name, "reconnect_timer","value"],ClusterConf)},
{factor, cuttlefish:conf_get(["riak_cluster","cluster", Name, "reconnect_timer","factor"],ClusterConf)},
{incr, cuttlefish:conf_get(["riak_cluster","cluster", Name, "reconnect_timer","incr"],ClusterConf)},
{max_value, cuttlefish:conf_get(["riak_cluster","cluster", Name, "reconnect_timer","max_value"],ClusterConf)}
]}],
[{list_to_atom(PName),
[{size, cuttlefish:conf_get(["riak_cluster","cluster", Name, "pool", PName, "size"],PoolConf)},
{max_overflow, cuttlefish:conf_get(["riak_cluster","cluster", Name, "pool",PName,"max_overflow"],PoolConf)}],
[
{host, element(1,cuttlefish:conf_get(["riak_cluster","cluster", Name, "pool",PName,"ip"], PoolConf))},
{port, element(2,cuttlefish:conf_get(["riak_cluster","cluster", Name, "pool",PName,"ip"], PoolConf))}
]} || [{[_,_,_,_,PName|_],_}|_] = PoolConf <- GroupBy(lists:filter(fun(El) -> case El of {[_,_,_,"pool"|_],_} -> true; _ -> false end end ,ClusterConf),5)]}
|| {Name, ClusterConf} <- Clusters],
case Cs of
[] ->
throw(unset);
_ -> Cs
end
end}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment