2015-04-30 08:28:43 +00:00
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
%%
|
|
|
|
%% Copyright (c) 2007-2015 Basho Technologies, Inc. All Rights Reserved.
|
|
|
|
%%
|
|
|
|
%% This file is provided to you under the Apache License,
|
|
|
|
%% Version 2.0 (the "License"); you may not use this file
|
|
|
|
%% except in compliance with the License. You may obtain
|
|
|
|
%% a copy of the License at
|
|
|
|
%%
|
|
|
|
%% http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
%%
|
|
|
|
%% Unless required by applicable law or agreed to in writing,
|
|
|
|
%% software distributed under the License is distributed on an
|
|
|
|
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
%% KIND, either express or implied. See the License for the
|
|
|
|
%% specific language governing permissions and limitations
|
|
|
|
%% under the License.
|
|
|
|
%%
|
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
|
|
|
|
%% @doc Supervisor for Machi FLU servers and their related support
|
|
|
|
%% servers.
|
|
|
|
|
|
|
|
-module(machi_flu_psup).
|
|
|
|
|
|
|
|
-behaviour(supervisor).
|
|
|
|
|
|
|
|
%% External API
|
2015-05-07 09:39:39 +00:00
|
|
|
-export([make_package_spec/4, start_flu_package/4, stop_flu_package/1]).
|
2015-04-30 08:28:43 +00:00
|
|
|
%% Internal API
|
2015-05-02 07:59:28 +00:00
|
|
|
-export([start_link/4,
|
|
|
|
make_p_regname/1, make_mgr_supname/1, make_proj_supname/1]).
|
2015-04-30 08:28:43 +00:00
|
|
|
|
|
|
|
%% Supervisor callbacks
|
|
|
|
-export([init/1]).
|
|
|
|
|
2015-05-07 09:39:39 +00:00
|
|
|
make_package_spec(FluName, TcpPort, DataDir, Props) ->
|
|
|
|
{FluName, {machi_flu_psup, start_link,
|
|
|
|
[FluName, TcpPort, DataDir, Props]},
|
|
|
|
permanent, 5000, supervisor, []}.
|
|
|
|
|
2015-04-30 08:28:43 +00:00
|
|
|
start_flu_package(FluName, TcpPort, DataDir, Props) ->
|
2015-05-07 09:39:39 +00:00
|
|
|
Spec = make_package_spec(FluName, TcpPort, DataDir, Props),
|
2015-04-30 08:28:43 +00:00
|
|
|
{ok, _SupPid} = supervisor:start_child(machi_flu_sup, Spec).
|
|
|
|
|
2015-04-30 12:20:21 +00:00
|
|
|
stop_flu_package(FluName) ->
|
|
|
|
case supervisor:terminate_child(machi_flu_sup, FluName) of
|
|
|
|
ok ->
|
|
|
|
ok = supervisor:delete_child(machi_flu_sup, FluName);
|
|
|
|
Else ->
|
|
|
|
Else
|
|
|
|
end.
|
2015-04-30 08:28:43 +00:00
|
|
|
|
|
|
|
start_link(FluName, TcpPort, DataDir, Props) ->
|
|
|
|
supervisor:start_link({local, make_p_regname(FluName)}, ?MODULE,
|
|
|
|
[FluName, TcpPort, DataDir, Props]).
|
|
|
|
|
|
|
|
init([FluName, TcpPort, DataDir, Props0]) ->
|
|
|
|
RestartStrategy = one_for_all,
|
|
|
|
MaxRestarts = 1000,
|
|
|
|
MaxSecondsBetweenRestarts = 3600,
|
|
|
|
SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts},
|
|
|
|
|
|
|
|
ProjRegName = make_proj_supname(FluName),
|
2015-04-30 14:16:08 +00:00
|
|
|
Props = [{projection_store_registered_name, ProjRegName},
|
|
|
|
{use_partition_simulator,false}|Props0],
|
2015-04-30 08:28:43 +00:00
|
|
|
ProjSpec = {ProjRegName,
|
|
|
|
{machi_projection_store, start_link,
|
2015-05-08 09:17:41 +00:00
|
|
|
[ProjRegName, DataDir, FluName]},
|
2015-04-30 08:28:43 +00:00
|
|
|
permanent, 5000, worker, []},
|
|
|
|
MgrSpec = {make_mgr_supname(FluName),
|
|
|
|
{machi_chain_manager1, start_link,
|
2015-04-30 14:16:08 +00:00
|
|
|
[FluName, [], Props]},
|
2015-04-30 08:28:43 +00:00
|
|
|
permanent, 5000, worker, []},
|
|
|
|
FluSpec = {FluName,
|
|
|
|
{machi_flu1, start_link,
|
|
|
|
[ [{FluName, TcpPort, DataDir}|Props] ]},
|
|
|
|
permanent, 5000, worker, []},
|
|
|
|
{ok, {SupFlags, [ProjSpec, MgrSpec, FluSpec]}}.
|
|
|
|
|
|
|
|
make_p_regname(FluName) when is_atom(FluName) ->
|
|
|
|
list_to_atom("flusup_" ++ atom_to_list(FluName)).
|
|
|
|
|
|
|
|
make_mgr_supname(MgrName) when is_atom(MgrName) ->
|
2015-05-02 07:59:28 +00:00
|
|
|
machi_chain_manager1:make_chmgr_regname(MgrName).
|
2015-04-30 08:28:43 +00:00
|
|
|
|
|
|
|
make_proj_supname(ProjName) when is_atom(ProjName) ->
|
|
|
|
list_to_atom(atom_to_list(ProjName) ++ "_pstore").
|