[openserverplatform] r120 committed - Refactoring the code

3 views
Skip to first unread message

openserve...@googlecode.com

unread,
Nov 5, 2009, 1:24:45 PM11/5/09
to openserve...@googlegroups.com
Revision: 120
Author: discipleofranok
Date: Thu Nov 5 10:24:11 2009
Log: Refactoring the code

http://code.google.com/p/openserverplatform/source/detail?r=120

Added:
/trunk/doc/osp_manager.html
/trunk/src/osp_manager.erl
Deleted:
/trunk/src/osp_recover.erl
Modified:
/trunk/doc/edoc-info
/trunk/doc/modules-frame.html
/trunk/doc/osp.html
/trunk/doc/osp_admin.html
/trunk/doc/osp_app.html
/trunk/doc/osp_broker.html
/trunk/doc/osp_compile.html
/trunk/doc/osp_file.html
/trunk/doc/osp_mnesia.html
/trunk/doc/osp_proto.html
/trunk/doc/osp_servlet.html
/trunk/doc/osp_socket.html
/trunk/doc/osp_sup.html
/trunk/doc/osp_web.html
/trunk/doc/overview-summary.html
/trunk/ebin/osp.app
/trunk/include/conf.hrl
/trunk/src/osp.erl
/trunk/src/osp_admin.erl
/trunk/src/osp_compile.erl
/trunk/src/osp_file.erl
/trunk/src/osp_web.erl

=======================================
--- /dev/null
+++ /trunk/doc/osp_manager.html Thu Nov 5 10:24:11 2009
@@ -0,0 +1,81 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<title>Module osp_manager</title>
+<link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc">
+</head>
+<body bgcolor="white">
+<div class="navbar"><a name="#navbar_top"></a><table width="100%"
border="0" cellspacing="0" cellpadding="2" summary="navigation
bar"><tr><td><a href="overview-summary.html"
target="overviewFrame">Overview</a></td><td><a
href="http://www.erlang.org/"><img src="erlang.png" align="right"
border="0" alt="erlang logo"></a></td></tr></table></div>
+<hr>
+
+<h1>Module osp_manager</h1>
+<ul class="index"><li><a href="#description">Description</a></li><li><a
href="#index">Function Index</a></li><li><a href="#functions">Function
Details</a></li></ul>Manages all application servlets running on the node.
+<p>Copyright © 2009 Jacob Torrey</p>
+
+<p><b>Authors:</b> Jacob Torrey (<a
href="mailto:torr...@clarkson.edu"><tt>torr...@clarkson.edu</tt></a>).</p>
+
+<h2><a name="description">Description</a></h2>Manages all application
servlets running on the node
+<h2><a name="index">Function Index</a></h2>
+<table width="100%" border="1" cellspacing="0" cellpadding="2"
summary="function index"><tr><td valign="top"><a
href="#bkup_db-2">bkup_db/2</a></td><td></td></tr>
+<tr><td valign="top"><a href="#nodeapp-0">nodeapp/0</a></td><td>Returns
the App-Node listing for the cluster.</td></tr>
+<tr><td valign="top"><a
href="#shutdown_osp-0">shutdown_osp/0</a></td><td>Shuts down the entire OSP
cluster, and quits the Erlang VM.</td></tr>
+<tr><td valign="top"><a
href="#start_servlet-3">start_servlet/3</a></td><td>Starts a servlet
application on a given node.</td></tr>
+<tr><td valign="top"><a href="#startup-0">startup/0</a></td><td>Starts the
local OSP node and all applications meant to be run on the node.</td></tr>
+<tr><td valign="top"><a href="#stats-0">stats/0</a></td><td>This returns a
string of the OSP cluster statistics.</td></tr>
+<tr><td valign="top"><a href="#stop_node-0">stop_node/0</a></td><td>Stops
all the applications on a given node.</td></tr>
+<tr><td valign="top"><a
href="#stop_servlet-2">stop_servlet/2</a></td><td>Attempts to find and stop
an application on the cluster.</td></tr>
+<tr><td valign="top"><a href="#uptime-0">uptime/0</a></td><td>Returns a
human readable string of the cluster uptime.</td></tr>
+</table>
+
+<h2><a name="functions">Function Details</a></h2>
+
+<h3 class="function"><a name="bkup_db-2">bkup_db/2</a></h3>
+<div class="spec">
+<p><tt>bkup_db(Node::<a href="#type-node">node()</a>, Type::atom()) -&gt;
ok</tt></p>
+</div>
+
+<h3 class="function"><a name="nodeapp-0">nodeapp/0</a></h3>
+<div class="spec">
+<p><tt>nodeapp() -&gt; list()</tt></p>
+</div><p>Returns the App-Node listing for the cluster</p>
+
+<h3 class="function"><a name="shutdown_osp-0">shutdown_osp/0</a></h3>
+<div class="spec">
+<p><tt>shutdown_osp() -&gt; ok</tt></p>
+</div><p>Shuts down the entire OSP cluster, and quits the Erlang VM</p>
+
+<h3 class="function"><a name="start_servlet-3">start_servlet/3</a></h3>
+<div class="spec">
+<p><tt>start_servlet(App::atom(), Port::<a href="#type-int">int()</a>,
Node::<a href="#type-node">node()</a>) -&gt; ok | error</tt></p>
+</div><p>Starts a servlet application on a given node</p>
+
+<h3 class="function"><a name="startup-0">startup/0</a></h3>
+<div class="spec">
+<p><tt>startup() -&gt; {ok, pid(), pid()}</tt></p>
+</div><p>Starts the local OSP node and all applications meant to be run on
the node</p>
+
+<h3 class="function"><a name="stats-0">stats/0</a></h3>
+<div class="spec">
+<p><tt>stats() -&gt; string()</tt></p>
+</div><p>This returns a string of the OSP cluster statistics</p>
+
+<h3 class="function"><a name="stop_node-0">stop_node/0</a></h3>
+<div class="spec">
+<p><tt>stop_node() -&gt; any()</tt></p>
+</div><p>Stops all the applications on a given node</p>
+
+<h3 class="function"><a name="stop_servlet-2">stop_servlet/2</a></h3>
+<div class="spec">
+<p><tt>stop_servlet(App::atom(), Node::<a href="#type-node">node()</a>)
-&gt; ok | error</tt></p>
+</div><p>Attempts to find and stop an application on the cluster</p>
+
+<h3 class="function"><a name="uptime-0">uptime/0</a></h3>
+<div class="spec">
+<p><tt>uptime() -&gt; string()</tt></p>
+</div><p>Returns a human readable string of the cluster uptime</p>
+<hr>
+
+<div class="navbar"><a name="#navbar_bottom"></a><table width="100%"
border="0" cellspacing="0" cellpadding="2" summary="navigation
bar"><tr><td><a href="overview-summary.html"
target="overviewFrame">Overview</a></td><td><a
href="http://www.erlang.org/"><img src="erlang.png" align="right"
border="0" alt="erlang logo"></a></td></tr></table></div>
+<p><i>Generated by EDoc, Nov 5 2009, 11:34:37.</i></p>
+</body>
+</html>
=======================================
--- /dev/null
+++ /trunk/src/osp_manager.erl Thu Nov 5 10:24:11 2009
@@ -0,0 +1,224 @@
+%% @author Jacob Torrey <torr...@clarkson.edu>
+%% @copyright 2009 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]).
+
+% 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 ->
+ store(uptime,
calendar:datetime_to_gregorian_seconds(erlang:universaltime()));
+ _ ->
+ ok
+ end,
+ case retrieve(nodeapp) of
+ undefined ->
+ store(nodeapp, []);
+ _ ->
+ ok
+ end,
+ F = fun({App, Port}) ->
+ start_servlet(App, Port, node())
+ end,
+ lists:foreach(F, osp:get_conf('AUTO_STARTED')),
+ Pid = spawn(fun() -> loop() end),
+ {ok, Pid, osp_web:start()}.
+
+%% @doc Stops all the applications on a given node
+%% spec stop_node() -> ok
+stop_node() ->
+ Apps = retrieve(nodeapp),
+ Node = node(),
+ {value, {Node, LocalApps}} = lists:keysearch(node(), 1, Apps),
+ F = fun({App, _}) ->
+ osp_broker:stop(App)
+ end,
+ lists:foreach(F, LocalApps),
+ store(nodeapp, lists:keydelete(node(), 1, Apps)),
+ ok.
+
+%% @doc An endless loop to satisfy OTP's Pid requirement
+%% @spec loop() -> none()
+loop() ->
+ receive
+ _ ->
+ loop()
+ end.
+
+%% @doc The mnesia startup routine for osp_admin
+%% @spec start_mnesia() -> ok
+start_mnesia() ->
+ case lists:member(mnesia_sup, erlang:registered()) of
+ true ->
+ ok;
+ false ->
+ mnesia:start()
+ end,
+ case catch(mnesia:table_info(osp_table, all)) of
+ {'EXIT', _} ->
+ mnesia:create_table(osp_table, [{record_name, osp_table},
{disc_copies, [node()]}, {attributes, record_info(fields, osp_table)}]);
+ _ ->
+ ok
+ end,
+ ok.
+
+%% @doc Stores a value in the mnesia database
+%% @spec store(any(), any()) -> ok
+store(Key, Val) ->
+ osp_mnesia:store(osp_table, Key, Val).
+
+%% @doc Gets a value from the mnesia database
+%% @spec retrieve(any()) -> any()
+retrieve(Key) ->
+ osp_mnesia:retrieve(osp_table, Key).
+
+%% @doc Returns the App-Node listing for the cluster
+%% @spec nodeapp() -> list()
+nodeapp() ->
+ retrieve(nodeapp).
+
+%% @todo This needs to update on every start of a new application
+%% @spec bkup_db(node(), atom()) -> ok
+bkup_db(Node, Type) ->
+ Tables = mnesia:system_info(tables),
+ F = fun(TableName) ->
+ mnesia:add_table_copy(TableName, Node, Type),
+ rpc:call(Node, mnesia, wait_for_tables, [[TableName], 1000])
+ end,
+ lists:foreach(F, Tables),
+ ok.
+
+%% @doc Starts an appropriately typed table copy for a passed
+%% @spec start_db(node(), atom()) -> ok | error
+start_db(Node, App) ->
+ TableName = erlang:list_to_atom(erlang:atom_to_list(App) ++ "_table"),
+ rpc:call(Node, mnesia, start, []),
+ case rpc:call(Node, init, get_argument, [loader]) of
+ error ->
+ rpc:call(Node, mnesia, change_config, [extra_db_nodes, [node()]]),
+ rpc:call(Node, mnesia, change_table_copy_type, [schema, Node,
disc_copies]),
+ mnesia:add_table_copy(TableName, Node, disc_copies);
+ {ok, [["inet"]]} ->
+ mnesia:add_table_copy(TableName, Node, ram_copies),
+ rpc:call(Node, mnesia, change_config, [extra_db_nodes, [node()]]);
+ {ok, [["efile"]]} ->
+ rpc:call(Node, mnesia, change_config, [extra_db_nodes, [node()]]),
+ 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]),
+ ok.
+
+%% @doc Returns a string of the allowed slave IPs
+%% @spec get_ok_slaves() -> string()
+get_ok_slaves() ->
+ Slaves = erl_boot_server:which_slaves(),
+ Fun = fun({NM, IP}, A) ->
+ A ++ "\tIP: " ++ ip_to_string(IP) ++ " Netmask: " ++ ip_to_string(NM)
++ "\r\n"
+ end,
+ lists:foldl(Fun, [], Slaves).
+
+%% @doc Returns a human readable string from a tuple version of an IP
address
+%% @spec ip_to_string(tuple()) -> string()
+ip_to_string({A, B, C, D}) ->
+ erlang:integer_to_list(A) ++ "." ++ erlang:integer_to_list(B) ++ "."
++ erlang:integer_to_list(C) ++ "." ++ erlang:integer_to_list(D).
+
+%% @doc This returns a string of the OSP cluster statistics
+%% @spec stats() -> string()
+stats() ->
+ F = fun(Node, A) -> A ++ io_lib:format("~p: ~.2f\r\n", [Node,
round(100 * rpc:call(Node, cpu_sup, avg1, []) / 256) / 100]) end,
+ Out1 = "Nodes in the cluster and their CPU Utilization: \r\n",
+ Out2 = lists:foldl(F, Out1, [node() | nodes()]),
+ Out2 ++ "The following IPs are allowed to be diskless:\r\n" ++
get_ok_slaves().
+
+%% @doc Attempts to find and stop an application on the cluster
+%% @spec stop_servlet(atom(), node()) -> ok | error
+stop_servlet(App, Node) ->
+ case lists:member(Node, [node() | nodes()]) of
+ true ->
+ if
+ Node =:= node() ->
+ osp_broker:stop(App);
+ true->
+ rpc:call(Node, osp_broker, stop, [App])
+ end,
+ del_app_from_list(Node, App),
+ ok;
+ false ->
+ error
+ end.
+
+%% @doc Starts a servlet application on a given node
+%% @spec start_servlet(atom(), int(), node()) -> ok | error
+start_servlet(App, Port, Node) ->
+ case lists:member(Node, [node() | nodes()]) of
+ true ->
+ if
+ Node =:= node() ->
+ osp_broker:start(App, Port);
+ true->
+ start_db(Node, App),
+ rpc:call(Node, osp_broker, start, [App, Port])
+ end,
+ add_app_to_list(Node, App, Port),
+ ok;
+ false ->
+ error
+ end.
+
+%% @doc Returns a human readable string of the cluster uptime
+%% @spec uptime() -> string()
+uptime() ->
+ Seconds = retrieve(uptime),
+ NSeconds =
calendar:datetime_to_gregorian_seconds(erlang:universaltime()),
+ {{_, _, Days}, {Hours, Mins, Secs}} =
calendar:gregorian_seconds_to_datetime(NSeconds - Seconds),
+ erlang:integer_to_list(Days - 1) ++ " days " ++
erlang:integer_to_list(Hours) ++ " hrs " ++ erlang:integer_to_list(Mins)
++ " mins " ++ erlang:integer_to_list(Secs) ++ " secs".
+
+%% @doc Shuts down the entire OSP cluster, and quits the Erlang VM
+%% @spec shutdown_osp() -> ok
+shutdown_osp() ->
+ F = fun(Node) ->
+ rpc:call(Node, application, stop, [osp]),
+ rpc:call(Node, init, stop, [])
+ end,
+ lists:foreach(F, nodes()),
+ store(uptime, undefined),
+ store(nodeapp, []),
+ init:stop().
+
+%% @doc Deletes an application from the list of running applications
+%% @spec del_app_from_list(atom(), atom()) -> ok
+del_app_from_list(Node, App) ->
+ NodeApp = retrieve(nodeapp),
+ {Node, AppList} = lists:keyfind(Node, 1, NodeApp),
+ AL2 = lists:keydelete(App, 1, AppList),
+ store(nodeapp, lists:keyreplace(Node, 1, NodeApp, {Node, AL2})),
+ ok.
+
+%% @doc Adds an application to the list of running applications
+%% @spec add_app_to_list(atom(), atom(), integer()) -> ok
+add_app_to_list(Node, App, Port) ->
+ Nodeapp = retrieve(nodeapp),
+ case lists:keyfind(Node, 1, Nodeapp) of
+ false ->
+ store(nodeapp, [{Node, [{App, Port}]} | Nodeapp]);
+ {Node, AppList} ->
+ store(nodeapp, lists:keyreplace(Node, 1, Nodeapp, {Node, AppList ++
[{App, Port}]}))
+ end,
+ ok.
=======================================
--- /trunk/src/osp_recover.erl Wed Nov 4 05:36:34 2009
+++ /dev/null
@@ -1,7 +0,0 @@
-%% @author Jacob Torrey <torr...@clarkson.edu>
-%% @copyright 2009 Jacob Torrey
-%% @doc Provides the functionality for a node to recover any running
applications after a crash
--module(osp_recover).
-
--export([]).
-
=======================================
--- /trunk/doc/edoc-info Wed Nov 4 05:36:34 2009
+++ /trunk/doc/edoc-info Thu Nov 5 10:24:11 2009
@@ -1,4 +1,4 @@
{application,osp}.
{packages,[]}.
-{modules,[osp,osp_admin,osp_app,osp_broker,osp_compile,osp_file,osp_mnesia,
- osp_proto,osp_servlet,osp_socket,osp_sup,osp_web]}.
+{modules,[osp,osp_admin,osp_app,osp_broker,osp_compile,osp_file,osp_manager,
+ osp_mnesia,osp_proto,osp_servlet,osp_socket,osp_sup,osp_web]}.
=======================================
--- /trunk/doc/modules-frame.html Wed Nov 4 05:36:34 2009
+++ /trunk/doc/modules-frame.html Thu Nov 5 10:24:11 2009
@@ -13,6 +13,7 @@
<tr><td><a href="osp_broker.html" target="overviewFrame"
class="module">osp_broker</a></td></tr>
<tr><td><a href="osp_compile.html" target="overviewFrame"
class="module">osp_compile</a></td></tr>
<tr><td><a href="osp_file.html" target="overviewFrame"
class="module">osp_file</a></td></tr>
+<tr><td><a href="osp_manager.html" target="overviewFrame"
class="module">osp_manager</a></td></tr>
<tr><td><a href="osp_mnesia.html" target="overviewFrame"
class="module">osp_mnesia</a></td></tr>
<tr><td><a href="osp_proto.html" target="overviewFrame"
class="module">osp_proto</a></td></tr>
<tr><td><a href="osp_servlet.html" target="overviewFrame"
class="module">osp_servlet</a></td></tr>
=======================================
--- /trunk/doc/osp.html Wed Nov 4 05:36:34 2009
+++ /trunk/doc/osp.html Thu Nov 5 10:24:11 2009
@@ -17,6 +17,7 @@
<h2><a name="description">Description</a></h2>The exports for controlling
the OSP system as a whole
<h2><a name="index">Function Index</a></h2>
<table width="100%" border="1" cellspacing="0" cellpadding="2"
summary="function index"><tr><td valign="top"><a
href="#gen_docs-0">gen_docs/0</a></td><td>Provides an export to regenerate
the documentation with edoc.</td></tr>
+<tr><td valign="top"><a href="#get_conf-1">get_conf/1</a></td><td>Returns
the configuration for a given key.</td></tr>
<tr><td valign="top"><a href="#join-1">join/1</a></td><td>Joins node to an
existing OSP cluster.</td></tr>
<tr><td valign="top"><a href="#setup-0">setup/0</a></td><td>Setups mnesia
and the OTP rel scripts for the first time.</td></tr>
<tr><td valign="top"><a href="#start-0">start/0</a></td><td>Starts the
first 'master' node.</td></tr>
@@ -30,6 +31,11 @@
<p><tt>gen_docs() -&gt; ok</tt></p>
</div><p>Provides an export to regenerate the documentation with edoc</p>

+<h3 class="function"><a name="get_conf-1">get_conf/1</a></h3>
+<div class="spec">
+<p><tt>get_conf(Key::atom()) -&gt; any()</tt></p>
+</div><p>Returns the configuration for a given key</p>
+
<h3 class="function"><a name="join-1">join/1</a></h3>
<div class="spec">
<p><tt>join(X1::list()) -&gt; pong | pang</tt></p>
@@ -52,6 +58,6 @@
<hr>

<div class="navbar"><a name="#navbar_bottom"></a><table width="100%"
border="0" cellspacing="0" cellpadding="2" summary="navigation
bar"><tr><td><a href="overview-summary.html"
target="overviewFrame">Overview</a></td><td><a
href="http://www.erlang.org/"><img src="erlang.png" align="right"
border="0" alt="erlang logo"></a></td></tr></table></div>
-<p><i>Generated by EDoc, Oct 30 2009, 20:13:44.</i></p>
+<p><i>Generated by EDoc, Nov 5 2009, 11:34:37.</i></p>
</body>
</html>
=======================================
--- /trunk/doc/osp_admin.html Wed Nov 4 05:36:34 2009
+++ /trunk/doc/osp_admin.html Thu Nov 5 10:24:11 2009
@@ -9,23 +9,19 @@
<hr>

<h1>Module osp_admin</h1>
-<ul class="index"><li><a href="#description">Description</a></li><li><a
href="#index">Function Index</a></li><li><a href="#functions">Function
Details</a></li></ul>Provides an interface to administer the OSP cluster.
+<ul class="index"><li><a href="#description">Description</a></li><li><a
href="#index">Function Index</a></li><li><a href="#functions">Function
Details</a></li></ul>Provides a telnet interface to administer the OSP
cluster.
<p>Copyright © 2009 Jacob Torrey &lt;torr...@clarkson.edu&gt;</p>

<p><b>Version:</b> 0.4</p>
<p><b>Authors:</b> Jacob Ian Torrey (<a
href="mailto:torr...@clarkson.edu"><tt>torr...@clarkson.edu</tt></a>).</p>

-<h2><a name="description">Description</a></h2>Provides an interface to
administer the OSP cluster
+<h2><a name="description">Description</a></h2>Provides a telnet interface
to administer the OSP cluster
<h2><a name="index">Function Index</a></h2>
<table width="100%" border="1" cellspacing="0" cellpadding="2"
summary="function index"><tr><td valign="top"><a
href="#cleanup-0">cleanup/0</a></td><td>A callback for the OSP broker
service.</td></tr>
<tr><td valign="top"><a href="#init-0">init/0</a></td><td>Routine for
starting the master boot server and autostarted applications.</td></tr>
-<tr><td valign="top"><a href="#nodeapp-0">nodeapp/0</a></td><td>Returns
the App-Node listing for the cluster.</td></tr>
<tr><td valign="top"><a href="#proto-0">proto/0</a></td><td>Returns the
protocol for the application (this is a TCP applcation).</td></tr>
<tr><td valign="top"><a href="#server-1">server/1</a></td><td>The main
server loop.</td></tr>
-<tr><td valign="top"><a
href="#shutdown_osp-0">shutdown_osp/0</a></td><td>Shuts down the entire OSP
cluster, and quits the Erlang VM.</td></tr>
<tr><td valign="top"><a
href="#start_mnesia-0">start_mnesia/0</a></td><td>The mnesia startup
routine for osp_admin.</td></tr>
-<tr><td valign="top"><a href="#stats_osp-0">stats_osp/0</a></td><td>This
returns a string of the OSP cluster statistics.</td></tr>
-<tr><td valign="top"><a
href="#uptime_osp-0">uptime_osp/0</a></td><td>Returns a human readable
string of the cluster uptime.</td></tr>
</table>

<h2><a name="functions">Function Details</a></h2>
@@ -40,11 +36,6 @@
<p><tt>init() -&gt; ok</tt></p>
</div><p>Routine for starting the master boot server and autostarted
applications</p>

-<h3 class="function"><a name="nodeapp-0">nodeapp/0</a></h3>
-<div class="spec">
-<p><tt>nodeapp() -&gt; list()</tt></p>
-</div><p>Returns the App-Node listing for the cluster</p>
-
<h3 class="function"><a name="proto-0">proto/0</a></h3>
<div class="spec">
<p><tt>proto() -&gt; tcp</tt></p>
@@ -55,28 +46,13 @@
<p><tt>server(Sock::tuple()) -&gt; none()</tt></p>
</div><p>The main server loop</p>

-<h3 class="function"><a name="shutdown_osp-0">shutdown_osp/0</a></h3>
-<div class="spec">
-<p><tt>shutdown_osp() -&gt; ok</tt></p>
-</div><p>Shuts down the entire OSP cluster, and quits the Erlang VM</p>
-
<h3 class="function"><a name="start_mnesia-0">start_mnesia/0</a></h3>
<div class="spec">
<p><tt>start_mnesia() -&gt; ok</tt></p>
</div><p>The mnesia startup routine for osp_admin</p>
-
-<h3 class="function"><a name="stats_osp-0">stats_osp/0</a></h3>
-<div class="spec">
-<p><tt>stats_osp() -&gt; list()</tt></p>
-</div><p>This returns a string of the OSP cluster statistics</p>
-
-<h3 class="function"><a name="uptime_osp-0">uptime_osp/0</a></h3>
-<div class="spec">
-<p><tt>uptime_osp() -&gt; list()</tt></p>
-</div><p>Returns a human readable string of the cluster uptime</p>
<hr>

<div class="navbar"><a name="#navbar_bottom"></a><table width="100%"
border="0" cellspacing="0" cellpadding="2" summary="navigation
bar"><tr><td><a href="overview-summary.html"
target="overviewFrame">Overview</a></td><td><a
href="http://www.erlang.org/"><img src="erlang.png" align="right"
border="0" alt="erlang logo"></a></td></tr></table></div>
-<p><i>Generated by EDoc, Oct 30 2009, 20:13:45.</i></p>
+<p><i>Generated by EDoc, Nov 5 2009, 11:34:37.</i></p>
</body>
</html>
=======================================
--- /trunk/doc/osp_app.html Wed Nov 4 05:36:34 2009
+++ /trunk/doc/osp_app.html Thu Nov 5 10:24:11 2009
@@ -34,6 +34,6 @@
<hr>

<div class="navbar"><a name="#navbar_bottom"></a><table width="100%"
border="0" cellspacing="0" cellpadding="2" summary="navigation
bar"><tr><td><a href="overview-summary.html"
target="overviewFrame">Overview</a></td><td><a
href="http://www.erlang.org/"><img src="erlang.png" align="right"
border="0" alt="erlang logo"></a></td></tr></table></div>
-<p><i>Generated by EDoc, Oct 30 2009, 20:13:44.</i></p>
+<p><i>Generated by EDoc, Nov 5 2009, 11:34:37.</i></p>
</body>
</html>
=======================================
--- /trunk/doc/osp_broker.html Wed Nov 4 05:36:34 2009
+++ /trunk/doc/osp_broker.html Thu Nov 5 10:24:11 2009
@@ -40,6 +40,6 @@
<hr>

<div class="navbar"><a name="#navbar_bottom"></a><table width="100%"
border="0" cellspacing="0" cellpadding="2" summary="navigation
bar"><tr><td><a href="overview-summary.html"
target="overviewFrame">Overview</a></td><td><a
href="http://www.erlang.org/"><img src="erlang.png" align="right"
border="0" alt="erlang logo"></a></td></tr></table></div>
-<p><i>Generated by EDoc, Oct 30 2009, 20:13:45.</i></p>
+<p><i>Generated by EDoc, Nov 5 2009, 11:34:37.</i></p>
</body>
</html>
=======================================
--- /trunk/doc/osp_compile.html Wed Nov 4 05:36:34 2009
+++ /trunk/doc/osp_compile.html Thu Nov 5 10:24:11 2009
@@ -25,7 +25,7 @@

<h3 class="function"><a name="compile-1">compile/1</a></h3>
<div class="spec">
-<p><tt>compile(Filename::list()) -&gt; {ok, list()} | {error,
list()}</tt></p>
+<p><tt>compile(Filename::string()) -&gt; {ok, list()} | {error,
list()}</tt></p>
</div><p>Generates and compiles a servlet from a .sdf</p>

<h3 class="function"><a name="distribute-2">distribute/2</a></h3>
@@ -35,11 +35,11 @@

<h3 class="function"><a name="servlet_to_app-1">servlet_to_app/1</a></h3>
<div class="spec">
-<p><tt>servlet_to_app(Filename::list()) -&gt; {ok, list()} | {error,
list()}</tt></p>
+<p><tt>servlet_to_app(Filename::string()) -&gt; {ok, list()} | {error,
list()}</tt></p>
</div><p>Compiles a servlet and moves it to the application directory if
compilation is successful</p>
<hr>

<div class="navbar"><a name="#navbar_bottom"></a><table width="100%"
border="0" cellspacing="0" cellpadding="2" summary="navigation
bar"><tr><td><a href="overview-summary.html"
target="overviewFrame">Overview</a></td><td><a
href="http://www.erlang.org/"><img src="erlang.png" align="right"
border="0" alt="erlang logo"></a></td></tr></table></div>
-<p><i>Generated by EDoc, Oct 30 2009, 20:13:44.</i></p>
+<p><i>Generated by EDoc, Nov 5 2009, 11:34:37.</i></p>
</body>
</html>
=======================================
--- /trunk/doc/osp_file.html Wed Nov 4 05:36:34 2009
+++ /trunk/doc/osp_file.html Thu Nov 5 10:24:11 2009
@@ -32,7 +32,7 @@

<h3 class="function"><a name="fopen-3">fopen/3</a></h3>
<div class="spec">
-<p><tt>fopen(App::list(), Filename::list(), Flags::list()) -&gt; <a
href="#type-io_device">io_device()</a> | {err, list()}</tt></p>
+<p><tt>fopen(App::list(), Filename::string(), Flags::list()) -&gt; <a
href="#type-io_device">io_device()</a> | {err, list()}</tt></p>
</div><p>Opens a file for reading or writing</p>

<h3 class="function"><a name="fread-2">fread/2</a></h3>
@@ -52,6 +52,6 @@
<hr>

<div class="navbar"><a name="#navbar_bottom"></a><table width="100%"
border="0" cellspacing="0" cellpadding="2" summary="navigation
bar"><tr><td><a href="overview-summary.html"
target="overviewFrame">Overview</a></td><td><a
href="http://www.erlang.org/"><img src="erlang.png" align="right"
border="0" alt="erlang logo"></a></td></tr></table></div>
-<p><i>Generated by EDoc, Oct 30 2009, 20:13:45.</i></p>
+<p><i>Generated by EDoc, Nov 5 2009, 11:34:37.</i></p>
</body>
</html>
=======================================
--- /trunk/doc/osp_mnesia.html Wed Nov 4 05:36:34 2009
+++ /trunk/doc/osp_mnesia.html Thu Nov 5 10:24:11 2009
@@ -46,6 +46,6 @@
<hr>

<div class="navbar"><a name="#navbar_bottom"></a><table width="100%"
border="0" cellspacing="0" cellpadding="2" summary="navigation
bar"><tr><td><a href="overview-summary.html"
target="overviewFrame">Overview</a></td><td><a
href="http://www.erlang.org/"><img src="erlang.png" align="right"
border="0" alt="erlang logo"></a></td></tr></table></div>
-<p><i>Generated by EDoc, Oct 30 2009, 20:13:44.</i></p>
+<p><i>Generated by EDoc, Nov 5 2009, 11:34:37.</i></p>
</body>
</html>
=======================================
--- /trunk/doc/osp_proto.html Wed Nov 4 05:36:34 2009
+++ /trunk/doc/osp_proto.html Thu Nov 5 10:24:11 2009
@@ -19,7 +19,8 @@
<table width="100%" border="1" cellspacing="0" cellpadding="2"
summary="function index"><tr><td valign="top"><a
href="#accept-1">accept/1</a></td><td>Returns a function to accept a socket
or connection.</td></tr>
<tr><td valign="top"><a href="#close-1">close/1</a></td><td>Returns a
function to close the socket.</td></tr>
<tr><td valign="top"><a
href="#set_control-1">set_control/1</a></td><td>Returns a function that
sets the controlling process of Sock to Pid.</td></tr>
-<tr><td valign="top"><a href="#start-1">start/1</a></td><td>Returns a
function (arity 1) for starting a server socket.</td></tr>
+<tr><td valign="top"><a href="#start-1">start/1</a></td><td>Returns a
function (arity 1) for starting a server socket with default socket
options.</td></tr>
+<tr><td valign="top"><a href="#start-2">start/2</a></td><td>Returnes a
function (arity 1) for starting a server socket with passed socket
options.</td></tr>
</table>

<h2><a name="functions">Function Details</a></h2>
@@ -36,16 +37,21 @@

<h3 class="function"><a name="set_control-1">set_control/1</a></h3>
<div class="spec">
-<p><tt>set_control(X1) -&gt; any()</tt></p>
+<p><tt>set_control(X1::tcp | udp | sctp) -&gt; <a
href="#type-fun">'fun'()</a></tt></p>
</div><p>Returns a function that sets the controlling process of Sock to
Pid</p>

<h3 class="function"><a name="start-1">start/1</a></h3>
<div class="spec">
-<p><tt>start(X1) -&gt; any()</tt></p>
-</div><p>Returns a function (arity 1) for starting a server socket</p>
+<p><tt>start(X1::tcp | udp | sctp) -&gt; <a
href="#type-fun">'fun'()</a></tt></p>
+</div><p>Returns a function (arity 1) for starting a server socket with
default socket options</p>
+
+<h3 class="function"><a name="start-2">start/2</a></h3>
+<div class="spec">
+<p><tt>start(X1::tcp | udp | sctp, Options::list()) -&gt; <a
href="#type-fun">'fun'()</a></tt></p>
+</div><p>Returnes a function (arity 1) for starting a server socket with
passed socket options</p>
<hr>

<div class="navbar"><a name="#navbar_bottom"></a><table width="100%"
border="0" cellspacing="0" cellpadding="2" summary="navigation
bar"><tr><td><a href="overview-summary.html"
target="overviewFrame">Overview</a></td><td><a
href="http://www.erlang.org/"><img src="erlang.png" align="right"
border="0" alt="erlang logo"></a></td></tr></table></div>
-<p><i>Generated by EDoc, Oct 30 2009, 20:13:45.</i></p>
+<p><i>Generated by EDoc, Nov 5 2009, 11:34:37.</i></p>
</body>
</html>
=======================================
--- /trunk/doc/osp_servlet.html Wed Nov 4 05:36:34 2009
+++ /trunk/doc/osp_servlet.html Thu Nov 5 10:24:11 2009
@@ -29,6 +29,6 @@
<hr>

<div class="navbar"><a name="#navbar_bottom"></a><table width="100%"
border="0" cellspacing="0" cellpadding="2" summary="navigation
bar"><tr><td><a href="overview-summary.html"
target="overviewFrame">Overview</a></td><td><a
href="http://www.erlang.org/"><img src="erlang.png" align="right"
border="0" alt="erlang logo"></a></td></tr></table></div>
-<p><i>Generated by EDoc, Oct 30 2009, 20:13:44.</i></p>
+<p><i>Generated by EDoc, Nov 5 2009, 11:34:37.</i></p>
</body>
</html>
=======================================
--- /trunk/doc/osp_socket.html Wed Nov 4 05:36:34 2009
+++ /trunk/doc/osp_socket.html Thu Nov 5 10:24:11 2009
@@ -46,6 +46,6 @@
<hr>

<div class="navbar"><a name="#navbar_bottom"></a><table width="100%"
border="0" cellspacing="0" cellpadding="2" summary="navigation
bar"><tr><td><a href="overview-summary.html"
target="overviewFrame">Overview</a></td><td><a
href="http://www.erlang.org/"><img src="erlang.png" align="right"
border="0" alt="erlang logo"></a></td></tr></table></div>
-<p><i>Generated by EDoc, Oct 30 2009, 20:13:44.</i></p>
+<p><i>Generated by EDoc, Nov 5 2009, 11:34:37.</i></p>
</body>
</html>
=======================================
--- /trunk/doc/osp_sup.html Wed Nov 4 05:36:34 2009
+++ /trunk/doc/osp_sup.html Thu Nov 5 10:24:11 2009
@@ -34,6 +34,6 @@
<hr>

<div class="navbar"><a name="#navbar_bottom"></a><table width="100%"
border="0" cellspacing="0" cellpadding="2" summary="navigation
bar"><tr><td><a href="overview-summary.html"
target="overviewFrame">Overview</a></td><td><a
href="http://www.erlang.org/"><img src="erlang.png" align="right"
border="0" alt="erlang logo"></a></td></tr></table></div>
-<p><i>Generated by EDoc, Oct 30 2009, 20:13:44.</i></p>
+<p><i>Generated by EDoc, Nov 5 2009, 11:34:37.</i></p>
</body>
</html>
=======================================
--- /trunk/doc/osp_web.html Wed Nov 4 05:36:34 2009
+++ /trunk/doc/osp_web.html Thu Nov 5 10:24:11 2009
@@ -46,6 +46,6 @@
<hr>

<div class="navbar"><a name="#navbar_bottom"></a><table width="100%"
border="0" cellspacing="0" cellpadding="2" summary="navigation
bar"><tr><td><a href="overview-summary.html"
target="overviewFrame">Overview</a></td><td><a
href="http://www.erlang.org/"><img src="erlang.png" align="right"
border="0" alt="erlang logo"></a></td></tr></table></div>
-<p><i>Generated by EDoc, Oct 30 2009, 20:13:44.</i></p>
+<p><i>Generated by EDoc, Nov 5 2009, 11:34:37.</i></p>
</body>
</html>
=======================================
--- /trunk/doc/overview-summary.html Wed Nov 4 05:36:34 2009
+++ /trunk/doc/overview-summary.html Thu Nov 5 10:24:11 2009
@@ -13,6 +13,6 @@
developing highly-available, multi-threaded networked applications.
<hr>
<div class="navbar"><a name="#navbar_bottom"></a><table width="100%"
border="0" cellspacing="0" cellpadding="2" summary="navigation
bar"><tr><td><a href="overview-summary.html"
target="overviewFrame">Overview</a></td><td><a
href="http://www.erlang.org/"><img src="erlang.png" align="right"
border="0" alt="erlang logo"></a></td></tr></table></div>
-<p><i>Generated by EDoc, Oct 30 2009, 20:13:45.</i></p>
+<p><i>Generated by EDoc, Nov 5 2009, 11:34:37.</i></p>
</body>
</html>
=======================================
--- /trunk/ebin/osp.app Wed Nov 4 05:36:34 2009
+++ /trunk/ebin/osp.app Thu Nov 5 10:24:11 2009
@@ -1,7 +1,7 @@
{application, osp,
[{description, "Open Server Platform"},
{vsn, "0.4"},
- {modules, [osp, osp_app, osp_admin, osp_broker, osp_mnesia,
osp_socket, osp_proto, osp_servlet, osp_compile, osp_file, osp_sup,
osp_web, osp_recover]},
+ {modules, [osp, osp_app, osp_admin, osp_broker, osp_mnesia,
osp_socket, osp_proto, osp_servlet, osp_compile, osp_file, osp_sup,
osp_web, osp_manager]},
{registered, [osp_admin]},
{applications, [kernel, sasl, stdlib, os_mon, inets]},
{mod, {osp_app, []}}
=======================================
--- /trunk/include/conf.hrl Wed Nov 4 05:36:34 2009
+++ /trunk/include/conf.hrl Thu Nov 5 10:24:11 2009
@@ -1,31 +1,31 @@
% OSP Server Configuration

% Use FQDNs
--define(USEFQDN, false).
+{'USEFQDN', false}.

% The name of this node (if the above is true, this must be a FQDN)
--define(NODENAME, 'master@localhost').
+{'NODENAME', 'master@localhost'}.

% Port the admin console should listen on
--define(ADMINPORT, 9876).
+{'ADMINPORT', 9876}.

% The secret cookie
--define(COOKIE, 'AMOJDKFJHEJDHJKSJDY').
+{'COOKIE', 'AMOJDKFJHEJDHJKSJDY'}.

% Auto started applications as {name, port} tuples
--define(AUTO_STARTED, []).
+{'AUTO_STARTED', [{osp_admin, 9876}]}.

% Allowed diskless client IPs
--define(ALLOWED_DISKLESS, ['127.0.0.1']).
+{'ALLOWED_DISKLESS', ['127.0.0.1']}.

% Whether the application filesystem is just on the master node, or shared
(like NFS)
--define(SHARED_FS, false).
+{'SHARED_FS', false}.

% The prefix of the application file area
--define(FS_PREFIX, "/tmp").
+{'FS_PREFIX', "/tmp"}.

% Where OSP will store the compiled applications
--define(APP_DIR, "apps").
+{'APP_DIR', "apps"}.

% Where OSP will store the application source code
--define(SRC_DIR, "servlets").
+{'SRC_DIR', "servlets"}.
=======================================
--- /trunk/src/osp.erl Wed Nov 4 05:36:34 2009
+++ /trunk/src/osp.erl Thu Nov 5 10:24:11 2009
@@ -2,49 +2,41 @@
%% @author Jacob Torrey <torr...@clarkson.edu>
%% @doc The exports for controlling the OSP system as a whole
-module(osp).
--export([start/0, stop/1, join/1, setup/0, gen_docs/0]).
-
--include("../include/conf.hrl").
+-export([start/0, stop/1, join/1, setup/0, gen_docs/0, get_conf/1]).

-define(VERSION, "0.4").

%% @doc Starts the first 'master' node
%% @spec start() -> {ok, Pid, pid()} | {error, Reason}
start() ->
- case ?USEFQDN of
+ case get_conf('USEFQDN') of
true ->
- net_kernel:start([?NODENAME]);
+ net_kernel:start([get_conf('NODENAME')]);
false ->
- net_kernel:start([?NODENAME, shortnames])
+ net_kernel:start([get_conf('NODENAME'), shortnames])
end,
- erlang:set_cookie(node(), ?COOKIE),
- code:add_path(?APP_DIR),
+ erlang:set_cookie(node(), get_conf('COOKIE')),
+ code:add_path(get_conf('APP_DIR')),
application:start(mnesia),
- Pid = osp_broker:start(osp_admin, ?ADMINPORT),
- case Pid of
- {error, Err} ->
- {error, Err};
- _ ->
- {ok, Pid, osp_web:start()}
- end.
+ osp_manager:startup().

%% @doc Stops OSP on this node
%% @spec stop(Pid) -> ok
stop(Pid) ->
- osp_broker:stop(osp_admin),
+ osp_manager:stop_node(),
osp_broker:shutdown(),
osp_web:stop(Pid).

%% @doc Setups mnesia and the OTP rel scripts for the first time
%% @spec setup() -> ok
setup() ->
- case ?USEFQDN of
+ case get_conf('USEFQDN') of
true ->
- net_kernel:start([?NODENAME]);
+ net_kernel:start([get_conf('NODENAME')]);
false ->
- net_kernel:start([?NODENAME, shortnames])
+ net_kernel:start([get_conf('NODENAME'), shortnames])
end,
- erlang:set_cookie(node(), ?COOKIE),
+ erlang:set_cookie(node(), get_conf('COOKIE')),
write_rel(),
mnesia:create_schema([node()]),
init:stop().
@@ -82,3 +74,14 @@
%% @spec gen_docs() -> ok
gen_docs() ->
edoc:application(osp, ".", []).
+
+%% @doc Returns the configuration for a given key
+%% @spec get_conf(atom()) -> any()
+get_conf(Key) ->
+ {ok, L} = file:consult("include/conf.hrl"),
+ case lists:keysearch(Key, 1, L) of
+ {value, {Key, V}} ->
+ V;
+ false ->
+ {error, keynotfound}
+ end.
=======================================
--- /trunk/src/osp_admin.erl Wed Nov 4 05:36:34 2009
+++ /trunk/src/osp_admin.erl Thu Nov 5 10:24:11 2009
@@ -1,34 +1,16 @@
%% @author Jacob Ian Torrey <torr...@clarkson.edu>
%% @copyright 2009 Jacob Torrey <torr...@clarkson.edu>
%% @version 0.4
-%% @doc Provides an interface to administer the OSP cluster
+%% @doc Provides a telnet interface to administer the OSP cluster
-module(osp_admin).
-behavior(osp_servlet).

% Export OSP server callback
-export([start_mnesia/0, server/1, init/0, cleanup/0, proto/0]).

-% Export the admin functions for the web console
--export([shutdown_osp/0, stats_osp/0, uptime_osp/0, nodeapp/0]).
-
-% Include the OSP configuration
--include("../include/conf.hrl").
-
% Import the OSP socket library
-import(osp_socket, [send/2, recv/2, sendf/3, close/1]).

-% Define the Mnesia record
--record(osp_table, {key, val}).
-
-%% @doc Stores a value in the mnesia database
-%% @spec store(atom(), any()) -> ok
-store(Key, Val) ->
- osp_mnesia:store(osp_admin_table, Key, Val).
-
-%% @doc Gets a value from the mnesia database
-retrieve(Key) ->
- osp_mnesia:retrieve(osp_admin_table, Key).
-
%% @doc Returns the protocol for the application (this is a TCP applcation)
%% @spec proto() -> tcp
proto() ->
@@ -37,25 +19,8 @@
%% @doc The mnesia startup routine for osp_admin
%% @spec start_mnesia() -> ok
start_mnesia() ->
- case lists:member(mnesia_sup, erlang:registered()) of
- true ->
- ok;
- false ->
- mnesia:start()
- end,
- case catch(mnesia:table_info(osp_admin_table, all)) of
- {'EXIT', _} ->
- mnesia:create_table(osp_admin_table, [{record_name, osp_table},
{disc_copies, [node()]}, {attributes, record_info(fields, osp_table)}]);
- _ ->
- ok
- end,
ok.

-%% @doc Returns the App-Node listing for the cluster
-%% @spec nodeapp() -> list()
-nodeapp() ->
- retrieve(nodeapp).
-
%% @doc The main server loop
%% @spec server(tuple()) -> none()
server(Sock) ->
@@ -79,14 +44,14 @@
"help" -> % Print out the help message
send(Sock, <<"OSP Admin Console\n\tquit - Quits the console\n\tstats
- Prints general stats about the OSP cluster\n\tstart <appname> <port>
<node> - Starts appname on node\n\tadd-diskless-ip <ip> - Adds IP to the
allowed diskless server pool\n\tshutdown - Shutdown OSP on all
nodes\n\tadd-backup-server <node> <type> - Makes node a backup server
keeping an up-to-date copy of all the shared state in the cluster; type may
be ram for faster, non-persistant storage, or disk for data
persistance\n\tstop <appname> <node> - Stops the given servlet on
node\n\tmigrate <appname> <fromnode> <tonode> <port> - Migrates a servlet
from fromnode to tonode, starting it on the given port\n">>);
"stats" -> % Display some stats
- send(Sock, stats_osp());
+ send(Sock, osp_manager:stats());
"quit" ->
close(Sock),
exit(normal);
"shutdown" ->
send(Sock, "Shutting down\r\n"),
close(Sock),
- shutdown_osp();
+ osp_manager:shutdown_osp();
"" ->
ok;
Unknown -> % Handle multi-word command
@@ -98,7 +63,7 @@
Port = erlang:list_to_integer(PortList),
App = erlang:list_to_atom(AppList),
Node = erlang:list_to_atom(NodeList),
- case start_servlet(App, Port, Node) of
+ case osp_mamager:start_servlet(App, Port, Node) of
ok ->
sendf(Sock, "~p started on ~p port ~p~n", [App, Node, Port]);
error ->
@@ -110,13 +75,13 @@
From = erlang:list_to_atom(FromNodeList),
App = erlang:list_to_atom(AppList),
Node = erlang:list_to_atom(NodeList),
- case start_servlet(App, Port, Node) of
+ case osp_manager:start_servlet(App, Port, Node) of
ok ->
sendf(Sock, "~p started on ~p port ~p~n", [App, Node, Port]);
error ->
send(Sock, "Sorry, the node you requested couldn't be found\r\n")
end,
- case stop_servlet(App, From) of
+ case osp_manager:stop_servlet(App, From) of
ok ->
sendf(Sock, "Stopped ~p on ~p ~n", [App, Node]);
error ->
@@ -135,11 +100,11 @@
case Type of
ram ->
rpc:call(Node, mnesia, change_config, [extra_db_nodes, [node()]]),
- bkup_db(Node, ram_copies);
+ osp_manager:bkup_db(Node, ram_copies);
disk ->
rpc:call(Node, mnesia, change_config, [extra_db_nodes, [node()]]),
rpc:call(Node, mnesia, change_table_copy_type, [schema, Node,
disc_copies]),
- bkup_db(Node, disc_copies);
+ osp_manager:bkup_db(Node, disc_copies);
_ ->
send(Sock, "Sorry, unknown backup type: " ++ TypeL ++ "\r\n")
end;
@@ -147,7 +112,7 @@
[Comm, AppL, NodeL] = Split,
App = erlang:list_to_atom(AppL),
Node = erlang:list_to_atom(NodeL),
- case stop_servlet(App, Node) of
+ case osp_manager:stop_servlet(App, Node) of
ok ->
sendf(Sock, "Stopped ~p on ~p ~n", [App, Node]);
error ->
@@ -158,155 +123,12 @@
end
end.

-%% @todo This needs to update on every start of a new application
-%% @spec bkup_db(node(), atom()) -> ok
-bkup_db(Node, Type) ->
- Tables = mnesia:system_info(tables),
- F = fun(TableName) ->
- mnesia:add_table_copy(TableName, Node, Type),
- rpc:call(Node, mnesia, wait_for_tables, [[TableName], 1000])
- end,
- lists:foreach(F, Tables),
- ok.
-
-%% @doc Starts an appropriately typed table copy for a passed
-%% @spec start_db(node(), atom()) -> ok | error
-start_db(Node, App) ->
- TableName = erlang:list_to_atom(erlang:atom_to_list(App) ++ "_table"),
- rpc:call(Node, mnesia, start, []),
- case rpc:call(Node, init, get_argument, [loader]) of
- error ->
- rpc:call(Node, mnesia, change_config, [extra_db_nodes, [node()]]),
- rpc:call(Node, mnesia, change_table_copy_type, [schema, Node,
disc_copies]),
- mnesia:add_table_copy(TableName, Node, disc_copies);
- {ok, [["inet"]]} ->
- mnesia:add_table_copy(TableName, Node, ram_copies),
- rpc:call(Node, mnesia, change_config, [extra_db_nodes, [node()]]);
- {ok, [["efile"]]} ->
- rpc:call(Node, mnesia, change_config, [extra_db_nodes, [node()]]),
- 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]),
- ok.
-
-%% @doc Returns a human readable string from a tuple version of an IP
address
-%% @spec ip_to_string(tuple()) -> string()
-ip_to_string({A, B, C, D}) ->
- erlang:integer_to_list(A) ++ "." ++ erlang:integer_to_list(B) ++ "."
++ erlang:integer_to_list(C) ++ "." ++ erlang:integer_to_list(D).
-
-%% @doc Returns a string of the allowed slave IPs
-%% @spec get_ok_slaves() -> string()
-get_ok_slaves() ->
- Slaves = erl_boot_server:which_slaves(),
- Fun = fun({NM, IP}, A) ->
- A ++ "\tIP: " ++ ip_to_string(IP) ++ " Netmask: " ++ ip_to_string(NM)
++ "\r\n"
- end,
- lists:foldl(Fun, [], Slaves).
-
-%% @doc This returns a string of the OSP cluster statistics
-%% @spec stats_osp() -> list()
-stats_osp() ->
- F = fun(Node, A) -> A ++ io_lib:format("~p: ~.2f\r\n", [Node,
round(100 * rpc:call(Node, cpu_sup, avg1, []) / 256) / 100]) end,
- Out1 = "Nodes in the cluster and their CPU Utilization: \r\n",
- Out2 = lists:foldl(F, Out1, [node() | nodes()]),
- Out2 ++ "The following IPs are allowed to be diskless:\r\n" ++
get_ok_slaves().
-
-%% @doc Attempts to find and stop an application on the cluster
-%% @spec stop_servlet(atom(), node()) -> ok | error
-stop_servlet(App, Node) ->
- case lists:member(Node, [node() | nodes()]) of
- true ->
- if
- Node =:= node() ->
- osp_broker:stop(App);
- true->
- rpc:call(Node, osp_broker, stop, [App])
- end,
- del_app_from_list(Node, App),
- ok;
- false ->
- error
- end.
-
-%% @doc Starts a servlet application on a given node
-%% @spec start_servlet(atom(), int(), node()) -> ok | error
-start_servlet(App, Port, Node) ->
- case lists:member(Node, [node() | nodes()]) of
- true ->
- if
- Node =:= node() ->
- osp_broker:start(App, Port);
- true->
- start_db(Node, App),
- rpc:call(Node, osp_broker, start, [App, Port])
- end,
- add_app_to_list(Node, App, Port),
- ok;
- false ->
- error
- end.
-
-%% @doc Returns a human readable string of the cluster uptime
-%% @spec uptime_osp() -> list()
-uptime_osp() ->
- Seconds = retrieve(uptime),
- NSeconds =
calendar:datetime_to_gregorian_seconds(erlang:universaltime()),
- {{_, _, Days}, {Hours, Mins, Secs}} =
calendar:gregorian_seconds_to_datetime(NSeconds - Seconds),
- erlang:integer_to_list(Days - 1) ++ " days " ++
erlang:integer_to_list(Hours) ++ " hrs " ++ erlang:integer_to_list(Mins)
++ " mins " ++ erlang:integer_to_list(Secs) ++ " secs".
-
-%% @doc Shuts down the entire OSP cluster, and quits the Erlang VM
-%% @spec shutdown_osp() -> ok
-shutdown_osp() ->
- F = fun(Node) ->
- rpc:call(Node, init, stop, [])
- end,
- lists:foreach(F, nodes()),
- init:stop().
-
-%% @doc Routine for starting the master boot server and autostarted
applications
+%% @doc Callback for the OSP broker service
%% @spec init() -> ok
init() ->
- erl_boot_server:start(['127.0.0.1']),
- DL = fun(IP) ->
- erl_boot_server:add_slave(IP)
- end,
- lists:foreach(DL, ?ALLOWED_DISKLESS),
- store(uptime,
calendar:datetime_to_gregorian_seconds(erlang:universaltime())),
- case retrieve(nodeapp) of
- undefined ->
- store(nodeapp, [{node(), [{osp_admin, ?ADMINPORT}]}]);
- _ ->
- add_app_to_list(node(), osp_admin, ?ADMINPORT)
- end,
- F = fun({App, Port}) ->
- start_servlet(App, Port, node())
- end,
- lists:foreach(F, ?AUTO_STARTED),
ok.

%% @doc A callback for the OSP broker service
%% @spec cleanup() -> ok
cleanup() ->
ok.
-
-%% @doc Deletes an application from the list of running applications
-%% @spec del_app_from_list(atom(), atom()) -> ok
-del_app_from_list(Node, App) ->
- NodeApp = retrieve(nodeapp),
- {Node, AppList} = lists:keyfind(Node, 1, NodeApp),
- AL2 = lists:keydelete(App, 1, AppList),
- store(nodeapp, lists:keyreplace(Node, 1, NodeApp, {Node, AL2})),
- ok.
-
-%% @doc Adds an application to the list of running applications
-%% @spec add_app_to_list(atom(), atom(), integer()) -> ok
-add_app_to_list(Node, App, Port) ->
- Nodeapp = retrieve(nodeapp),
- case lists:keyfind(Node, 1, Nodeapp) of
- false ->
- store(nodeapp, [{Node, [{App, Port}]} | Nodeapp]);
- {Node, AppList} ->
- store(nodeapp, lists:keyreplace(Node, 1, Nodeapp, {Node, AppList ++
[{App, Port}]}))
- end,
- ok.
=======================================
--- /trunk/src/osp_compile.erl Wed Nov 4 05:36:34 2009
+++ /trunk/src/osp_compile.erl Thu Nov 5 10:24:11 2009
@@ -3,8 +3,6 @@
%% @doc Provides servlet compilation functionality
-module(osp_compile).

--include("../include/conf.hrl").
-
-export([compile/1, distribute/2, servlet_to_app/1]).

%% @doc Generates and compiles a servlet from a .sdf
@@ -44,7 +42,7 @@
ModuleName = string:join(lists:reverse(lists:nthtail(1,
lists:reverse(string:tokens(Basename, ".")))), "."),
case Compile of
{ok, _} = Output ->
- file:rename(ModuleName ++ ".beam", ?APP_DIR ++ "/" ++ ModuleName
++ ".beam"),
+ file:rename(ModuleName ++ ".beam", osp:get_conf('APP_DIR') ++ "/" ++
ModuleName ++ ".beam"),
file:delete(ModuleName ++ ".erl");
{error, _} = Output ->
file:delete(ModuleName ++ ".erl")
=======================================
--- /trunk/src/osp_file.erl Wed Nov 4 05:36:34 2009
+++ /trunk/src/osp_file.erl Thu Nov 5 10:24:11 2009
@@ -3,17 +3,16 @@
%% @doc File operations for OSP programs
-module(osp_file).

--include("../include/conf.hrl").
-export([fopen/3, fread/2, fwrite/2, fclose/1, fseek/3]).

%% @doc Calls a command either on the local FS, or the remote FS depending
on how the FS is setup
%% @spec call_func(atom(), atom(), list()) -> any()
call_func(M, F, A) ->
- case ?SHARED_FS of
+ case osp:get_conf('SHARED_FS') of
true ->
Ret = apply(M, F, A);
false ->
- Ret = rpc:call(?NODENAME, M, F, A)
+ Ret = rpc:call(osp:get_conf('NODENAME'), M, F, A)
end,
Ret.

@@ -21,7 +20,7 @@
%% @spec fopen(list(), string(), list()) -> io_device() | {err, list()}
%% @todo Harden the file jailing system
fopen(App, Filename, Flags) ->
- Filename2 = ?FS_PREFIX ++ "/" ++ App ++ "/" ++ Filename,
+ Filename2 = osp:get_conf('FS_PREFIX') ++ "/" ++ App ++ "/" ++ Filename,
Ret = call_func(file, open, [Filename2, Flags]),
case Ret of
{ok, FP} ->
=======================================
--- /trunk/src/osp_web.erl Wed Nov 4 05:36:34 2009
+++ /trunk/src/osp_web.erl Thu Nov 5 10:24:11 2009
@@ -49,15 +49,15 @@
case Op of
"shutdown" ->
mod_esi:deliver(Session, "OSP Shutdown"),
- osp_admin:shutdown_osp();
+ osp_manager:shutdown_osp();
"stats" ->
- mod_esi:deliver(Session, nl2br(osp_admin:stats_osp()));
+ mod_esi:deliver(Session, nl2br(osp_manager:stats()));
"uptime" ->
- mod_esi:deliver(Session, osp_admin:uptime_osp());
+ mod_esi:deliver(Session, osp_manager:uptime());
"nodes" ->
mod_esi:deliver(Session, erlang:integer_to_list(length([node() |
nodes()])));
"appnode" ->
- mod_esi:deliver(Session, io_lib:format("~p", [osp_admin:nodeapp()]));
+ mod_esi:deliver(Session, io_lib:format("~p",
[osp_manager:nodeapp()]));
_ ->
mod_esi:deliver(Session, "")
end.
Reply all
Reply to author
Forward
0 new messages