Skip to content

Commit

Permalink
Merge pull request #91 from basho-labs/mtc-gh76-persistent-path-from-…
Browse files Browse the repository at this point in the history
…riak-pkg

Configurable paths based on archive contents
  • Loading branch information
sanmiguel authored Aug 26, 2016
2 parents 692ba66 + 142c52b commit b6e5eb4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
42 changes: 42 additions & 0 deletions src/rms_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
artifacts/0,
artifact_urls/0,
persistent_path/0,
riak_root_path/0,
framework_hostname/0]).

-export([get_value/2, get_value/3]).
Expand All @@ -40,6 +41,10 @@
-define(DEFAULT_ZK, "master.mesos:2181").
-define(DEFAULT_CONSTRAINTS, "[]").
-define(STATIC_ROOT, "../artifacts/").
-define(DEFAULT_RIAK_ROOT_PATH, "root").

% The path-tail in a Riak archive, for which we search
-define(RIAK_BIN, "riak/bin/riak").

%% Helper functions.

Expand Down Expand Up @@ -115,6 +120,43 @@ artifacts() ->
get_value(executor_pkg, "riak_mesos_executor.tar.gz", string)
].

-spec riak_root_path() -> string().
riak_root_path() ->
RiakPkg = get_value(riak_pkg, "riak.tar.gz", string),
ArtifactDir = "../artifacts",
Filename = filename:join([ArtifactDir, RiakPkg]),
{ok, TarTable} = erl_tar:table(Filename, [compressed]),
find_root_path(TarTable).

%% TODO Should we log something in this case?
-spec find_root_path(list(string())) -> string().
find_root_path([]) -> ?DEFAULT_RIAK_ROOT_PATH;
find_root_path([P | Paths]) ->
case lists:suffix(?RIAK_BIN, P) of
true ->
%% Strip the known tail, leave only the prefix
find_prefix(P, ?RIAK_BIN);
false -> find_root_path(Paths)
end.

-spec find_prefix(string(), string()) -> string().
find_prefix(FullPath, Tail) ->
% We know that FullPath = Prefix ++ Tail
% How to find Prefix?
SplitPath = filename:split(FullPath),
SplitTail = filename:split(Tail),
% Reverse the path components
LiatTilps = lists:reverse(SplitTail),
HtapTilps = lists:reverse(SplitPath),
% Find the common path-tail (list-head), reverse and join
filename:join(lists:reverse(drop_common_prefix(HtapTilps, LiatTilps))).

% Drops from A the leading elements common to A and B.
-spec drop_common_prefix(A::list(), B::list()) -> list().
drop_common_prefix([], _) -> [];
drop_common_prefix([X | Rest1], [X | Rest2]) -> drop_common_prefix(Rest1, Rest2);
drop_common_prefix(Rest, _) -> Rest.

-spec artifact_urls() -> [string()].
artifact_urls() ->
%% TODO "static" is magic
Expand Down
15 changes: 9 additions & 6 deletions src/rms_node_manager.erl
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ apply_unreserved_offer(NodeKey, OfferHelper) ->
{ok, NodeCpus} = rms_metadata:get_option(node_cpus),
{ok, NodeMem} = rms_metadata:get_option(node_mem),
{ok, NodeDisk} = rms_metadata:get_option(node_disk),
{ok, ContainerPath} = rms_metadata:get_option(persistent_path),
{ok, PersistentPath} = rms_metadata:get_option(persistent_path),
NodeNumPorts = ?NODE_NUM_PORTS,
Hostname = rms_offer_helper:get_hostname(OfferHelper),
AgentIdValue = rms_offer_helper:get_agent_id_value(OfferHelper),
Expand All @@ -306,7 +306,7 @@ apply_unreserved_offer(NodeKey, OfferHelper) ->
OfferHelper3 =
rms_offer_helper:make_volume(NodeDisk, Role, Principal,
PersistenceId,
ContainerPath,
PersistentPath,
OfferHelper2),

Attributes =
Expand Down Expand Up @@ -337,7 +337,8 @@ apply_reserved_offer(NodeKey, OfferHelper) ->
{ok, NodeMem} = rms_metadata:get_option(node_mem),
{ok, NodeDisk} = rms_metadata:get_option(node_disk),
{ok, ArtifactUrls} = rms_metadata:get_option(artifact_urls),
{ok, ContainerPath} = rms_metadata:get_option(persistent_path),
{ok, PersistentPath} = rms_metadata:get_option(persistent_path),
{ok, RiakRootPath} = rms_metadata:get_option(riak_root_path),
NodeNumPorts = ?NODE_NUM_PORTS,
UnfitForReserved =
rms_offer_helper:unfit_for_reserved(
Expand All @@ -362,7 +363,7 @@ apply_reserved_offer(NodeKey, OfferHelper) ->
OfferHelper1 =
rms_offer_helper:apply_reserved_resources(
NodeCpus, NodeMem, NodeDisk, undefined, Role,
Principal, PersistenceId, ContainerPath,
Principal, PersistenceId, PersistentPath,
OfferHelper0),
%% Apply unreserved resources for task.
OfferHelper2 =
Expand Down Expand Up @@ -425,6 +426,7 @@ apply_reserved_offer(NodeKey, OfferHelper) ->
NodeName = iolist_to_binary([NodeKey, "@", NodeHostname]),
{ZkNodes, _} = rms_config:zk(),
Zookeepers = [list_to_binary(I) || I <- ZkNodes],

TaskData = [{<<"FullyQualifiedNodeName">>, NodeName},
{<<"Host">>, list_to_binary(NodeHostname)},
%% TODO: read list of zookeepers with rms_metadata:get_option/1
Expand All @@ -435,7 +437,8 @@ apply_reserved_offer(NodeKey, OfferHelper) ->
{<<"HTTPPort">>, HTTPPort},
{<<"PBPort">>, PBPort},
{<<"HandoffPort">>, HandoffPort},
{<<"DisterlPort">>, DisterlPort}],
{<<"DisterlPort">>, DisterlPort},
{<<"RiakRootPath">>, list_to_binary(RiakRootPath)}],
TaskDataBin = iolist_to_binary(mochijson2:encode(TaskData)),

% Tack a new UUID onto ExecutorId - this way we don't clash with previous instances of this same node
Expand Down Expand Up @@ -466,7 +469,7 @@ apply_reserved_offer(NodeKey, OfferHelper) ->
DisterlPort,
AgentIdValue,
ExecutorIdValue,
ContainerPath),
PersistentPath),

{ok, rms_offer_helper:add_task_to_launch(TaskInfo,
OfferHelper3)};
Expand Down
5 changes: 3 additions & 2 deletions src/rms_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ init_rest() ->

PersistentVolPath = rms_config:persistent_path(),
ArtifactUrls = rms_config:artifact_urls(),

RiakRootPath = rms_config:riak_root_path(),
Ref = riak_mesos_scheduler,
Scheduler = rms_scheduler,

Expand All @@ -132,7 +132,8 @@ init_rest() ->
{persistent_path, PersistentVolPath},
{executor_cpus, ExecutorCpus},
{executor_mem, ExecutorMem},
{artifact_urls, ArtifactUrls}],
{artifact_urls, ArtifactUrls},
{riak_root_path, RiakRootPath}],

MasterHosts = rms_config:master_hosts(),
ResubscribeInterval = rms_config:get_value(master_election_timeout, 60000,
Expand Down

0 comments on commit b6e5eb4

Please sign in to comment.