Skip to content

Commit

Permalink
Joining and web population is complete!
Browse files Browse the repository at this point in the history
  • Loading branch information
ranok committed Mar 23, 2010
1 parent 3731fea commit da21230
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
27 changes: 19 additions & 8 deletions src/osp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,26 @@ start() ->
end,
erlang:set_cookie(node(), get_conf('COOKIE')),
code:add_path(get_conf('APP_DIR')),
{ok, _} = erl_boot_server:start(['127.0.0.1']),
DL = fun(IP) ->
erl_boot_server:add_slave(IP)
end,
lists:foreach(DL, osp:get_conf('ALLOWED_DISKLESS')),
application:start(mnesia),
osp_manager:startup().
{ok, Pid} = osp_manager:startup(),
{ok, Pid, osp_web:start()}.

%% @doc Joins node to an existing OSP cluster
%% @spec join(list()) -> pong | pang
join([Node]) when is_atom(Node) ->
true = net_kernel:connect_node(Node),
application:start(sasl),
application:start(os_mon),
application:start(mnesia),
rpc:call(Node, osp_manager, start_db, [node(), osp]),
osp_manager:startup();
join([Node]) when is_list(Node) ->
join([erlang:list_to_atom(Node)]).

%% @doc Stops OSP on this node
%% @spec stop(Pid) -> ok
Expand All @@ -41,13 +59,6 @@ setup() ->
mnesia:create_schema([node()]),
init:stop().

%% @doc Joins node to an existing OSP cluster
%% @spec join(list()) -> pong | pang
join([Node]) ->
application:start(sasl),
application:start(os_mon),
net_adm:ping(Node).

%% @doc Dynamically gets the version of all the required applications to run OSP
%% @spec get_vsn(atom()) -> list()
get_vsn(Module) ->
Expand Down
20 changes: 8 additions & 12 deletions src/osp_manager.erl
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
%% @author Jacob Torrey <torreyji@clarkson.edu>
%% @copyright 2009 Jacob Torrey
%% @copyright 2010 Jacob Torrey
%% @doc Manages all application servlets running on the node
-module(osp_manager).

% Application callbacks
-export([startup/0, stop_node/0]).

% Export the admin functions
-export([shutdown_osp/0, stats/0, uptime/0, nodeapp/0, start_servlet/3, stop_servlet/2, bkup_db/2, servlet_running/2, apps/0]).
-export([shutdown_osp/0, stats/0, uptime/0, nodeapp/0, start_servlet/3, stop_servlet/2, bkup_db/2, servlet_running/2, apps/0, start_db/2]).

% Define the Mnesia record
-record(osp_table, {key, val}).

%% @doc Starts the local OSP node and all applications meant to be run on the node
%% @spec startup() -> {ok, pid(), pid()}
startup() ->
erl_boot_server:start(['127.0.0.1']),
DL = fun(IP) ->
erl_boot_server:add_slave(IP)
end,
lists:foreach(DL, osp:get_conf('ALLOWED_DISKLESS')),
start_mnesia(),
case retrieve(uptime) of
undefined ->
Expand All @@ -42,8 +37,10 @@ startup() ->
{_, LocalApps} ->
lists:foreach(F, LocalApps)
end,
add_app_to_list(node(), null, 0), % Adds a dummy app to the list to have it show up in the nodeapp
del_app_from_list(node(), null),
Pid = spawn(fun() -> loop() end),
{ok, Pid, osp_web:start()}.
{ok, Pid}.

%% @doc Stops all the applications on a given node
%% spec stop_node() -> ok
Expand Down Expand Up @@ -128,7 +125,7 @@ start_db(Node, App) ->
rpc:call(Node, mnesia, change_table_copy_type, [schema, Node, disc_copies]),
mnesia:add_table_copy(TableName, Node, disc_copies)
end,
rpc:call(Node, mnesia, wait_for_tables, [[TableName], 1000]),
rpc:call(Node, mnesia, wait_for_tables, [[schema, TableName], 5000]),
ok.

%% @doc Returns a string of the allowed slave IPs
Expand Down Expand Up @@ -163,11 +160,10 @@ stats() ->
stop_servlet(App, Node) ->
case lists:member(Node, [node() | nodes()]) of
true ->
{Node, LocalHost} = lists:keyfind(Node, 1, nodeapp()),
case lists:keyfind(App, 1, LocalHost) of
case servlet_running(Node, App) of
false ->
error;
_ ->
true ->
if
Node =:= node() ->
osp_broker:stop(App),
Expand Down

0 comments on commit da21230

Please sign in to comment.