Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi! I cleaned up your code for you! #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ fuzed
by Dave Fayram <dfayram at powerset dot com>,
Tom Preston-Werner <tom at powerset dot com>,
Abhay Kumar <abhay at powerset dot com>

Webiste: http://fuzed.rubyforge.org
Mailing List: http://groups.google.com/group/fuzed

== Summary

Fuzed is an Erlang-based clustering system designed to let several
single-threaded processes (which may or may not be reliable) form
single-threaded processes (which may or may not be reliable) form
into a pool which can serve requests to remote hosts. These resources
need not be homogeneous, Fuzed breaks them up into homogeneous pools
internally and serves out requests without "crossing the streams"
Expand All @@ -24,7 +24,7 @@ to see exactly how it is used internally.

* Erlang: http://www.erlang.org (>= 5.6.1)
* Ruby: http://www.ruby-lang.org (>= 1.8.6)
* Ruby Gems:
* Ruby Gems:
* rake: http://rake.rubyforge.org (>= 0.8.1)
* rack: http://rack.rubyforge.org (>= 0.3.0)
* erlectricity: http://github.com/mojombo/erlectricity (>= 0.2.1)
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ task :test => [:default] do
env_peek = ENV['MOD'] || ENV['MODS'] || ENV['MODULE'] || ENV['MODULES']
if env_peek
mods = env_peek.split(",")
else
else
mods = Dir["etest/*_test.erl"].map { |x| x.match(/etest\/(.*)_test.erl/)[1] }
end
mod_directives = mods.map {|m| "-run #{m} test"}.join(" ")
Expand Down
12 changes: 6 additions & 6 deletions conf/fuzed_base.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
%% rotating log and minimal tty
[{sasl, [
%% rotating log and minimal tty
[{sasl, [
{sasl_error_logger, false},
{errlog_type, error},
{error_logger_mf_dir,"/p/log/fuzed"},
{error_logger_mf_maxbytes,52428800}, % 50 MB
{error_logger_mf_maxfiles, 10}
]}].
{error_logger_mf_dir,"/p/log/fuzed"},
{error_logger_mf_maxbytes,52428800}, % 50 MB
{error_logger_mf_maxfiles, 10}
]}].
2 changes: 1 addition & 1 deletion elibs/fuzed_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
start(_Type, StartArgs) ->
net_kernel:set_net_ticktime(30),
fuzed_supervisor:start_link(StartArgs).

stop(_State) ->
ok.
30 changes: 15 additions & 15 deletions elibs/fuzed_code_monitor.erl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
%%%-------------------------------------------------------------------
%%% File : /Users/dfayram/Projects/new_fuzed/elibs/fuzed_code_monitor.erl
%%% Author :
%%% Author :
%%%-------------------------------------------------------------------
-module(fuzed_code_monitor).
-behaviour(gen_server).

%% API
-export([modified_modules/0, reload_modified_modules/0,reload_modified_modules_for_all_nodes/0,
reload_specified_modules/1, reload_ruby_code/0, reload_ruby_code_for_all_nodes/0,
reload_specified_modules/1, reload_ruby_code/0, reload_ruby_code_for_all_nodes/0,
global_upgrade/1]).

%% gen_server callbacks
Expand All @@ -27,24 +27,24 @@ start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
start() ->
gen_server:start({local, ?MODULE}, ?MODULE, [], []).

%%====================================================================
%% gen_server callbacks & API
%%====================================================================

modified_modules() ->
modified_modules() ->
gen_server:call(?MODULE, modified_modules).

reload_modified_modules() ->
reload_modified_modules() ->
gen_server:cast(?MODULE, reset).

reload_specified_modules(Modules) ->
reload_specified_modules(Modules) ->
spawn(fun() -> [force_reload_module(M) || M <- Modules] end),
ok.
reload_ruby_code() ->

reload_ruby_code() ->
spawn(
fun() ->
fun() ->
try resource_manager:cycle()
catch
error:_ -> ok
Expand All @@ -53,7 +53,7 @@ reload_ruby_code() ->
),
ok.

reload_ruby_code_for_all_nodes() ->
reload_ruby_code_for_all_nodes() ->
reload_ruby_code(),
[rpc:call(Node, ?MODULE, reload_ruby_code, []) || Node <- nodes()],
nodes().
Expand All @@ -68,7 +68,7 @@ global_upgrade(ruby) -> reload_ruby_code_for_all_nodes();
global_upgrade(erlang) -> reload_modified_modules_for_all_nodes();
global_upgrade(all) -> global_upgrade(erlang), global_upgrade(ruby);
global_upgrade(_) -> global_upgrade(all).


%%--------------------------------------------------------------------
%% Function: init(Args) -> {ok, State} |
Expand All @@ -89,7 +89,7 @@ init([]) ->
%% {stop, Reason, State}
%% Description: Handling call messages
%%--------------------------------------------------------------------
handle_call(modified_modules, _From, State) ->
handle_call(modified_modules, _From, State) ->
{reply, local_modified_modules(), State};
handle_call(_Request, _From, State) ->
Reply = ok,
Expand All @@ -101,8 +101,8 @@ handle_call(_Request, _From, State) ->
%% {stop, Reason, State}
%% Description: Handling cast messages
%%--------------------------------------------------------------------
handle_cast(reset, State) ->
spawn(fun() -> timer:sleep(1000), [force_reload_module(M) || M <- mm()] end),
handle_cast(reset, State) ->
spawn(fun() -> timer:sleep(1000), [force_reload_module(M) || M <- mm()] end),
{noreply, State};
handle_cast(_Msg, State) ->
{noreply, State}.
Expand Down Expand Up @@ -183,6 +183,6 @@ find_module_file(Path) ->
end
end.

force_reload_module(Module) ->
force_reload_module(Module) ->
code:purge(Module),
code:load_file(Module).
2 changes: 1 addition & 1 deletion elibs/fuzed_frontend_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
start(_Type, StartArgs) ->
net_kernel:set_net_ticktime(30),
fuzed_frontend_supervisor:start_link(StartArgs).

stop(_State) ->
ok.
26 changes: 13 additions & 13 deletions elibs/fuzed_frontend_supervisor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ start() ->
spawn(fun() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, _Arg = [])
end).

start_shell() ->
{ok, Pid} = supervisor:start_link({local, ?MODULE}, ?MODULE, _Arg = []),
unlink(Pid).

start_link(Args) ->
supervisor:start_link({local, ?MODULE}, ?MODULE, Args).


init([]) ->
case application:get_env(pidfile) of
Expand All @@ -25,15 +25,15 @@ init([]) ->
ok = file:write_file(Location, list_to_binary(Pid));
undefined -> ok
end,

Master = application:get_env(master),
case Master of
{ok, MasterNode} ->
ping_master(MasterNode);
undefined ->
MasterNode = node()
end,

case application:get_env(conf) of
{ok, Conf} ->
yaws_frontend:start(Conf);
Expand All @@ -45,13 +45,13 @@ init([]) ->
ResponderModule = figure_responder(),
FrameworkModule = figure_framework_module(),
AppModSpecs = process_appmods(application:get_env(appmods)),

case application:get_env(http_server) of
{ok, mochiweb} -> mochiweb_frontend:start(IP, Port, DocRoot, SSL, ResponderModule, FrameworkModule, AppModSpecs);
_ -> yaws_frontend:start(IP, Port, DocRoot, SSL, ResponderModule, FrameworkModule, AppModSpecs)
end
end,

{ok, {{one_for_one, 10, 600},
[{master_beater,
{master_beater, start_link, [MasterNode, ?GLOBAL_TIMEOUT, ?SLEEP_CYCLE]},
Expand All @@ -75,15 +75,15 @@ ssl_config() ->
{_Any2, undefined} -> none;
_Else -> {ssl, Key, Cert}
end.

% Helper functions

ping_master(Node) ->
ping_master(Node) ->
case net_adm:ping(Node) of
pong ->
pong ->
timer:sleep(?SLEEP_CYCLE),
ok;
pang ->
pang ->
error_logger:info_msg("Master node ~p not available. Retrying in 5 seconds.~n", [Node]),
timer:sleep(?SLEEP_CYCLE),
ping_master(Node)
Expand All @@ -95,12 +95,12 @@ figure_responder() ->
Module;
undefined -> frontend_responder
end.

figure_framework_module() ->
{ok, Framework} = application:get_env(framework),
FrameworkString = atom_to_list(Framework),
FrameworkModuleString = FrameworkString ++ "_framework",
list_to_atom(FrameworkModuleString).

process_appmods(undefined) -> [];
process_appmods({ok, V}) -> V.
2 changes: 1 addition & 1 deletion elibs/fuzed_node_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
start(_Type, StartArgs) ->
net_kernel:set_net_ticktime(30),
fuzed_node_supervisor:start_link(StartArgs).

stop(_State) ->
ok.
24 changes: 12 additions & 12 deletions elibs/fuzed_node_supervisor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ start() ->
spawn(fun() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, _Arg = [])
end).

start_shell() ->
{ok, Pid} = supervisor:start_link({local, ?MODULE}, ?MODULE, _Arg = []),
unlink(Pid).

start_link(Args) ->
supervisor:start_link({local, ?MODULE}, ?MODULE, Args).


init([]) ->
Master = application:get_env(master),
Expand All @@ -29,35 +29,35 @@ init([]) ->
{ok, NumNodes} = application:get_env(num_nodes),
{ok, Spec} = application:get_env(spec),
init_helper(MasterNode, NumNodes, Spec).


% Helper functions

ping_master(Node) ->
ping_master(Node) ->
case net_adm:ping(Node) of
pong ->
pong ->
timer:sleep(?SLEEP_CYCLE),
ok;
pang ->
pang ->
error_logger:info_msg("Master node ~p not available. Retrying in 5 seconds.~n", [Node]),
timer:sleep(?SLEEP_CYCLE),
ping_master(Node)
end.

init_helper(Master, NumNodes, Spec) when is_integer(NumNodes) ->
error_logger:info_msg("Starting with ~p set(s) of nodes.~n", [NumNodes]),
error_logger:info_msg("Starting with ~p set(s) of nodes.~n", [NumNodes]),
start_rm(Master, explode_spec(Spec, NumNodes)).
explode_spec(Specs, N) ->

explode_spec(Specs, N) ->
SBins = [list_to_binary(X) || X <- Specs],
lists:sort([binary_to_list(X) || X <- lists:flatten(lists:duplicate(N, SBins))]).

start_rm(Master, NodeSpec) ->
error_logger:info_msg("Starting with spec: ~p~n", [NodeSpec]),
Maker = fun(N) ->
Maker = fun(N) ->
node_api:heat(N, ?HEAT_DURATION)
end,
Killer = fun(X) -> X end,
Killer = fun(X) -> X end,
{ok, {{one_for_one, 10, 600},
[{resource_manager,
{resource_manager, start_link, [Master, NodeSpec, Maker, Killer, ?GLOBAL_TIMEOUT]},
Expand Down
14 changes: 7 additions & 7 deletions elibs/fuzed_supervisor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ start() ->
spawn(fun() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, _Arg = [])
end).

start_shell() ->
{ok, Pid} = supervisor:start_link({local, ?MODULE}, ?MODULE, _Arg = []),
unlink(Pid).

start_link(Args) ->
application:set_env(fuzed, in_rotation, true),
supervisor:start_link({local, ?MODULE}, ?MODULE, Args).

init([]) ->
% start the master server
IP = {0,0,0,0},
Port = 9001,
DocRoot = filename:dirname(code:which(?MODULE)) ++ "/../web",

case application:get_env(http_server) of
{ok, mochiweb} -> mochiweb_master:start(IP, Port, DocRoot);
_ -> yaws_master:start(IP, Port, DocRoot)
end,

%erl_boot_server:add_subnet({0, 0, 0, 0}, {0, 0, 0, 0}),

% return the supervisor spec for the resource fountain
{ok, {{one_for_one, 100, 300},
[{resource_fountain,
Expand All @@ -44,7 +44,7 @@ init([]) ->
{fuzed_code_monitor,
{fuzed_code_monitor, start_link, []},
permanent, 10000, worker, [fuzed_code_monitor]},
{logger,
{logger,
{logger, start_link, ["/var/log/fuzed"]},
permanent, 10000, worker, [logger]}
]}}.
Loading