auser-poolparty 0.2.15 → 0.2.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/Manifest.txt +28 -10
  2. data/bin/cloud +2 -2
  3. data/bin/cloud-provision +1 -1
  4. data/bin/cloud-run +19 -0
  5. data/bin/pool +2 -2
  6. data/bin/server-fire-cmd +16 -0
  7. data/bin/server-start-master +32 -0
  8. data/bin/server-start-node +32 -0
  9. data/lib/erlang/messenger/Rakefile +12 -0
  10. data/lib/erlang/messenger/ebin/master.app +19 -0
  11. data/lib/erlang/messenger/ebin/master_app.beam +0 -0
  12. data/lib/erlang/messenger/{lib/load_app.app → ebin/node.app} +6 -5
  13. data/lib/erlang/messenger/ebin/node_app.beam +0 -0
  14. data/lib/erlang/messenger/ebin/pm_client.beam +0 -0
  15. data/lib/erlang/messenger/ebin/pm_cluster.beam +0 -0
  16. data/lib/erlang/messenger/ebin/pm_event_handler.beam +0 -0
  17. data/lib/erlang/messenger/ebin/pm_master.beam +0 -0
  18. data/lib/erlang/messenger/ebin/pm_master_rel-0.1.rel +7 -0
  19. data/lib/erlang/messenger/ebin/pm_master_supervisor.beam +0 -0
  20. data/lib/erlang/messenger/ebin/pm_node.beam +0 -0
  21. data/lib/erlang/messenger/ebin/pm_node_rel-0.1.rel +7 -0
  22. data/lib/erlang/messenger/ebin/pm_node_supervisor.beam +0 -0
  23. data/lib/erlang/messenger/ebin/utils.beam +0 -0
  24. data/lib/erlang/messenger/pm_master_rel-0.1.boot +0 -0
  25. data/lib/erlang/messenger/pm_master_rel-0.1.script +169 -0
  26. data/lib/erlang/messenger/pm_node_rel-0.1.boot +0 -0
  27. data/lib/erlang/messenger/pm_node_rel-0.1.script +169 -0
  28. data/lib/erlang/messenger/src/master_app.erl +39 -0
  29. data/lib/erlang/messenger/src/node_app.erl +39 -0
  30. data/lib/erlang/messenger/src/pm_client.erl +14 -0
  31. data/lib/erlang/messenger/src/pm_cluster.erl +4 -1
  32. data/lib/erlang/messenger/src/pm_event_handler.erl +21 -0
  33. data/lib/erlang/messenger/src/pm_master.erl +113 -21
  34. data/lib/erlang/messenger/src/pm_master_supervisor.erl +33 -1
  35. data/lib/erlang/messenger/src/pm_node.erl +111 -65
  36. data/lib/erlang/messenger/src/pm_node_supervisor.erl +22 -15
  37. data/lib/erlang/messenger/src/utils.erl +45 -0
  38. data/lib/poolparty/base_packages/ruby.rb +1 -1
  39. data/lib/poolparty/helpers/console.rb +3 -2
  40. data/lib/poolparty/helpers/optioner.rb +6 -2
  41. data/lib/poolparty/helpers/provisioner_base.rb +5 -3
  42. data/lib/poolparty/helpers/provisioners/slave.rb +3 -0
  43. data/lib/poolparty/modules/resourcing_dsl.rb +4 -0
  44. data/lib/poolparty/net/remote_instance.rb +1 -1
  45. data/lib/poolparty/net/remoter.rb +11 -4
  46. data/lib/poolparty/plugins/git.rb +6 -12
  47. data/lib/poolparty/version.rb +1 -1
  48. data/poolparty.gemspec +4 -4
  49. data/spec/poolparty/bin/console_spec.rb +1 -1
  50. data/spec/poolparty/helpers/optioner_spec.rb +2 -1
  51. data/spec/poolparty/helpers/provisioner_base_spec.rb +1 -1
  52. data/spec/poolparty/helpers/provisioners/master_spec.rb +1 -1
  53. data/spec/poolparty/net/remote_spec.rb +51 -42
  54. data/spec/poolparty/pool/resources/gem_spec.rb +0 -1
  55. data/website/index.html +1 -1
  56. metadata +34 -13
  57. data/bin/pool-start-monitor +0 -1
  58. data/lib/erlang/messenger/ebin/erl_crash.dump +0 -12138
  59. data/lib/erlang/messenger/ebin/load_app.beam +0 -0
  60. data/lib/erlang/messenger/src/load_app.erl +0 -26
@@ -0,0 +1,169 @@
1
+ %% script generated at {2008,10,23} {2,11,55}
2
+ {script,
3
+ {"pm_node_rel","0.1"},
4
+ [{preLoaded,
5
+ [erlang,erl_prim_loader,prim_file,prim_inet,init,otp_ring0]},
6
+ {progress,preloaded},
7
+ {path,
8
+ ["/opt/local/lib/erlang/lib/kernel-2.12.2/ebin",
9
+ "/opt/local/lib/erlang/lib/stdlib-1.15.2/ebin"]},
10
+ {primLoad,[error_handler]},
11
+ {kernel_load_completed},
12
+ {progress,kernel_load_completed},
13
+ {path,["/opt/local/lib/erlang/lib/kernel-2.12.2/ebin"]},
14
+ {primLoad,
15
+ [zlib,wrap_log_reader,user_sup,user_drv,user,seq_trace,rpc,
16
+ ram_file,pg2,packages,os,net_kernel,net_adm,net,
17
+ kernel_config,kernel,inet_udp,inet_tcp_dist,inet_tcp,
18
+ inet_sctp,inet_res,inet_parse,inet_hosts,
19
+ inet_gethost_native,inet_dns,inet_db,inet_config,inet6_udp,
20
+ inet6_tcp_dist,inet6_tcp,inet,hipe_unified_loader,heart,
21
+ group,global_search,global_group,global,gen_udp,gen_tcp,
22
+ gen_sctp,file_server,file_io_server,file,erts_debug,
23
+ error_logger,erl_reply,erl_epmd,erl_distribution,erl_ddll,
24
+ erl_boot_server,dist_util,dist_ac,disk_log_sup,
25
+ disk_log_server,disk_log_1,disk_log,code_server,code_aux,
26
+ code,auth,application_starter,application_master,
27
+ application_controller,application]},
28
+ {path,["/opt/local/lib/erlang/lib/stdlib-1.15.2/ebin"]},
29
+ {primLoad,
30
+ [zip,win32reg,timer,sys,supervisor_bridge,supervisor,string,
31
+ sofs,slave,shell_default,shell,sets,regexp,random,queue,
32
+ qlc_pt,qlc,proplists,proc_lib,pool,pg,otp_internal,ordsets,
33
+ orddict,ms_transform,math,log_mf_h,lists,lib,io_lib_pretty,
34
+ io_lib_fread,io_lib_format,io_lib,io,gen_server,gen_fsm,
35
+ gen_event,gen,gb_trees,gb_sets,filename,filelib,file_sorter,
36
+ eval_bits,ets,escript,error_logger_tty_h,
37
+ error_logger_file_h,erl_tar,erl_scan,erl_pp,erl_posix_msg,
38
+ erl_parse,erl_lint,erl_internal,erl_expand_records,erl_eval,
39
+ erl_compile,erl_bits,epp,edlin_expand,edlin,digraph_utils,
40
+ digraph,dict,dets_v9,dets_v8,dets_utils,dets_sup,
41
+ dets_server,dets,calendar,c,beam_lib,base64,array]},
42
+ {path,["/opt/local/lib/erlang/lib/sasl-2.1.5.2/ebin"]},
43
+ {primLoad,
44
+ [systools_relup,systools_rc,systools_make,systools_lib,
45
+ systools,sasl_report_tty_h,sasl_report_file_h,sasl_report,
46
+ sasl,release_handler_1,release_handler,rb_format_supp,rb,
47
+ overload,misc_supp,format_lib_supp,erlsrv,alarm_handler]},
48
+ {path,
49
+ ["/Users/auser/Sites/work/citrusbyte/internal/gems/pool-party/poolparty/lib/erlang/messenger/ebin"]},
50
+ {primLoad,[utils,pm_node_supervisor,pm_node,node_app]},
51
+ {progress,modules_loaded},
52
+ {path,
53
+ ["/opt/local/lib/erlang/lib/kernel-2.12.2/ebin",
54
+ "/opt/local/lib/erlang/lib/stdlib-1.15.2/ebin",
55
+ "/opt/local/lib/erlang/lib/sasl-2.1.5.2/ebin",
56
+ "/Users/auser/Sites/work/citrusbyte/internal/gems/pool-party/poolparty/lib/erlang/messenger/ebin"]},
57
+ {kernelProcess,heart,{heart,start,[]}},
58
+ {kernelProcess,error_logger,{error_logger,start_link,[]}},
59
+ {kernelProcess,application_controller,
60
+ {application_controller,start,
61
+ [{application,kernel,
62
+ [{description,"ERTS CXC 138 10"},
63
+ {vsn,"2.12.2"},
64
+ {id,[]},
65
+ {modules,
66
+ [application,application_controller,application_master,
67
+ application_starter,auth,code,code_aux,packages,
68
+ code_server,dist_util,erl_boot_server,
69
+ erl_distribution,erl_prim_loader,erl_reply,erlang,
70
+ error_handler,error_logger,file,file_server,
71
+ file_io_server,prim_file,global,global_group,
72
+ global_search,group,heart,hipe_unified_loader,
73
+ inet6_tcp,inet6_tcp_dist,inet6_udp,inet_config,
74
+ inet_hosts,inet_gethost_native,inet_tcp_dist,init,
75
+ kernel,kernel_config,net,net_adm,net_kernel,os,
76
+ ram_file,rpc,user,user_drv,user_sup,disk_log,
77
+ disk_log_1,disk_log_server,disk_log_sup,dist_ac,
78
+ erl_ddll,erl_epmd,erts_debug,gen_tcp,gen_udp,gen_sctp,
79
+ prim_inet,inet,inet_db,inet_dns,inet_parse,inet_res,
80
+ inet_tcp,inet_udp,inet_sctp,pg2,seq_trace,
81
+ wrap_log_reader,zlib,otp_ring0]},
82
+ {registered,
83
+ [application_controller,erl_reply,auth,boot_server,
84
+ code_server,disk_log_server,disk_log_sup,
85
+ erl_prim_loader,error_logger,file_server_2,
86
+ fixtable_server,global_group,global_name_server,heart,
87
+ init,kernel_config,kernel_sup,net_kernel,net_sup,rex,
88
+ user,os_server,ddll_server,erl_epmd,inet_db,pg2]},
89
+ {applications,[]},
90
+ {included_applications,[]},
91
+ {env,[{error_logger,tty}]},
92
+ {start_phases,undefined},
93
+ {maxT,infinity},
94
+ {maxP,infinity},
95
+ {mod,{kernel,[]}}]}]}},
96
+ {progress,init_kernel_started},
97
+ {apply,
98
+ {application,load,
99
+ [{application,stdlib,
100
+ [{description,"ERTS CXC 138 10"},
101
+ {vsn,"1.15.2"},
102
+ {id,[]},
103
+ {modules,
104
+ [array,base64,beam_lib,c,calendar,dets,dets_server,
105
+ dets_sup,dets_utils,dets_v8,dets_v9,dict,digraph,
106
+ digraph_utils,edlin,edlin_expand,epp,eval_bits,
107
+ erl_bits,erl_compile,erl_eval,erl_expand_records,
108
+ erl_internal,erl_lint,erl_parse,erl_posix_msg,erl_pp,
109
+ erl_scan,erl_tar,error_logger_file_h,
110
+ error_logger_tty_h,escript,ets,file_sorter,filelib,
111
+ filename,gb_trees,gb_sets,gen,gen_event,gen_fsm,
112
+ gen_server,io,io_lib,io_lib_format,io_lib_fread,
113
+ io_lib_pretty,lib,lists,log_mf_h,math,ms_transform,
114
+ orddict,ordsets,otp_internal,pg,pool,proc_lib,
115
+ proplists,qlc,qlc_pt,queue,random,regexp,sets,shell,
116
+ shell_default,slave,sofs,string,supervisor,
117
+ supervisor_bridge,sys,timer,win32reg,zip]},
118
+ {registered,
119
+ [timer_server,rsh_starter,take_over_monitor,
120
+ pool_master,dets]},
121
+ {applications,[kernel]},
122
+ {included_applications,[]},
123
+ {env,[]},
124
+ {start_phases,undefined},
125
+ {maxT,infinity},
126
+ {maxP,infinity}]}]}},
127
+ {apply,
128
+ {application,load,
129
+ [{application,sasl,
130
+ [{description,"SASL CXC 138 11"},
131
+ {vsn,"2.1.5.2"},
132
+ {id,[]},
133
+ {modules,
134
+ [sasl,alarm_handler,format_lib_supp,misc_supp,overload,
135
+ rb,rb_format_supp,release_handler,release_handler_1,
136
+ erlsrv,sasl_report,sasl_report_tty_h,
137
+ sasl_report_file_h,systools,systools_make,systools_rc,
138
+ systools_relup,systools_lib]},
139
+ {registered,
140
+ [sasl_sup,alarm_handler,overload,release_handler]},
141
+ {applications,[kernel,stdlib]},
142
+ {included_applications,[]},
143
+ {env,[{sasl_error_logger,tty},{errlog_type,all}]},
144
+ {start_phases,undefined},
145
+ {maxT,infinity},
146
+ {maxP,infinity},
147
+ {mod,{sasl,[]}}]}]}},
148
+ {apply,
149
+ {application,load,
150
+ [{application,node,
151
+ [{description,"Node Server for PoolParty"},
152
+ {vsn,"0.1"},
153
+ {id,[]},
154
+ {modules,[node_app,pm_node,pm_node_supervisor,utils]},
155
+ {registered,[pm_node,pm_node_supervisor]},
156
+ {applications,[kernel,stdlib]},
157
+ {included_applications,[]},
158
+ {env,[]},
159
+ {start_phases,[]},
160
+ {maxT,infinity},
161
+ {maxP,infinity},
162
+ {mod,{node_app,[]}}]}]}},
163
+ {progress,applications_loaded},
164
+ {apply,{application,start_boot,[kernel,permanent]}},
165
+ {apply,{application,start_boot,[stdlib,permanent]}},
166
+ {apply,{application,start_boot,[sasl,permanent]}},
167
+ {apply,{application,start_boot,[node,permanent]}},
168
+ {apply,{c,erlangrc,[]}},
169
+ {progress,started}]}.
@@ -0,0 +1,39 @@
1
+ -module (master_app).
2
+ -behaviour(application).
3
+
4
+ %% Application callbacks
5
+ -export([start/2, stop/1]).
6
+
7
+ %%====================================================================
8
+ %% Application callbacks
9
+ %%====================================================================
10
+ %%--------------------------------------------------------------------
11
+ %% Function: start(Type, StartArgs) -> {ok, Pid} |
12
+ %% {ok, Pid, State} |
13
+ %% {error, Reason}
14
+ %% Description: This function is called whenever an application
15
+ %% is started using application:start/1,2, and should start the processes
16
+ %% of the application. If the application is structured according to the
17
+ %% OTP design principles as a supervision tree, this means starting the
18
+ %% top supervisor of the tree.
19
+ %%--------------------------------------------------------------------
20
+ start(_Type, StartArgs) ->
21
+ case pm_master_supervisor:start_link(StartArgs) of
22
+ {ok, Pid} ->
23
+ {ok, Pid};
24
+ Error ->
25
+ Error
26
+ end.
27
+
28
+ %%--------------------------------------------------------------------
29
+ %% Function: stop(State) -> void()
30
+ %% Description: This function is called whenever an application
31
+ %% has stopped. It is intended to be the opposite of Module:start/2 and
32
+ %% should do any necessary cleaning up. The return value is ignored.
33
+ %%--------------------------------------------------------------------
34
+ stop(_State) ->
35
+ ok.
36
+
37
+ %%====================================================================
38
+ %% Internal functions
39
+ %%====================================================================
@@ -0,0 +1,39 @@
1
+ -module (node_app).
2
+ -behaviour(application).
3
+
4
+ %% Application callbacks
5
+ -export([start/2, stop/1]).
6
+
7
+ %%====================================================================
8
+ %% Application callbacks
9
+ %%====================================================================
10
+ %%--------------------------------------------------------------------
11
+ %% Function: start(Type, StartArgs) -> {ok, Pid} |
12
+ %% {ok, Pid, State} |
13
+ %% {error, Reason}
14
+ %% Description: This function is called whenever an application
15
+ %% is started using application:start/1,2, and should start the processes
16
+ %% of the application. If the application is structured according to the
17
+ %% OTP design principles as a supervision tree, this means starting the
18
+ %% top supervisor of the tree.
19
+ %%--------------------------------------------------------------------
20
+ start(_Type, StartArgs) ->
21
+ case pm_node_supervisor:start_link(StartArgs) of
22
+ {ok, Pid} ->
23
+ {ok, Pid};
24
+ Error ->
25
+ Error
26
+ end.
27
+
28
+ %%--------------------------------------------------------------------
29
+ %% Function: stop(State) -> void()
30
+ %% Description: This function is called whenever an application
31
+ %% has stopped. It is intended to be the opposite of Module:start/2 and
32
+ %% should do any necessary cleaning up. The return value is ignored.
33
+ %%--------------------------------------------------------------------
34
+ stop(_State) ->
35
+ ok.
36
+
37
+ %%====================================================================
38
+ %% Internal functions
39
+ %%====================================================================
@@ -0,0 +1,14 @@
1
+ -module (pm_client).
2
+ -export ([send_cmd/1, reconfigure_cloud/0, get_load/1, get_live_nodes/0]).
3
+
4
+ % Run commands on the running master process
5
+ % erl -pa ./ebin/ -run pm_client get_load cpu -run init stop -noshell
6
+
7
+ % Send the command Cmd to the pm_master process
8
+ send_cmd(Cmd) -> pm_master:fire_cmd(Cmd).
9
+ % Reconfigure the cloud
10
+ reconfigure_cloud() -> pm_master:reconfigure_cloud().
11
+ % Get the load on the cloud of type Type
12
+ get_load(Type) -> pm_master:get_load(Type).
13
+ % Get a list of the live nodes
14
+ get_live_nodes() -> pm_master:get_live_nodes().
@@ -28,4 +28,7 @@ erl_system_args()->
28
28
  Shared, " +Mea r10b "
29
29
  ]).
30
30
  %% Do not forget to start erlang with a command like:
31
- %% erl -rsh ssh -sname clustmaster
31
+ %% erl -rsh ssh -sname clustmaster
32
+
33
+ basic_test_() ->
34
+ ?_assert(true).
@@ -0,0 +1,21 @@
1
+ % Handles generic events
2
+ -module (pm_event_handler).
3
+ -export ([make/0, add_handler/1, event/1]).
4
+
5
+ % Make a new event handler
6
+ make() ->
7
+ register(?MODULE, spawn(fun() -> handle_events(fun no_op/1) end )).
8
+
9
+ add_handler(Fun) ->
10
+ whereis(?MODULE) ! {add, Fun}.
11
+
12
+ event(X) -> whereis(?MODULE) ! {event, X}.
13
+
14
+ handle_events(Fun) ->
15
+ receive
16
+ {event, Any} ->
17
+ (catch Fun(Any)),
18
+ handle_events(Fun)
19
+ end.
20
+
21
+ no_op(_) -> void.
@@ -1,27 +1,119 @@
1
- % The client is a running process that will run on the master node
2
- % and spawn requests to the pm_nodes and compile the responses
3
- % for use within the poolparty network
1
+ %%%-------------------------------------------------------------------
2
+ %%% File : pm_master.erl
3
+ %%% Author : Ari Lerner <arilerner@mac.com>
4
+ %%% The client is a running process that will run on the master node
5
+ %%% and spawn requests to the pm_nodes and compile the responses
6
+ %%% for use within the poolparty network
7
+ %%%-------------------------------------------------------------------
8
+ -module(pm_master).
9
+ -behaviour(gen_server).
4
10
 
5
- -module (pm_master).
11
+ %% API
12
+ -export([start_link/0]).
6
13
 
7
- -ifdef(EUNIT).
8
- -include_lib("eunit/include/eunit.hrl").
9
- -endif.
14
+ %% gen_server callbacks
15
+ -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
16
+ terminate/2, code_change/3]).
17
+ -record(state, {}).
18
+ -define(SERVER, ?MODULE).
10
19
 
11
20
  % Client function definitions
12
- -export ([get_load/2]).
21
+ -export ([get_load/1, reconfigure_cloud/0, fire_cmd/1, get_live_nodes/0]).
22
+
23
+ %%====================================================================
24
+ %% API
25
+ %%====================================================================
26
+ %%--------------------------------------------------------------------
27
+ %% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
28
+ %% Description: Starts the server
29
+ %%--------------------------------------------------------------------
30
+ start_link() ->
31
+ gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
32
+
33
+ %%====================================================================
34
+ %% gen_server callbacks
35
+ %%====================================================================
36
+
37
+ %%--------------------------------------------------------------------
38
+ %% Function: init(Args) -> {ok, State} |
39
+ %% {ok, State, Timeout} |
40
+ %% ignore |
41
+ %% {stop, Reason}
42
+ %% Description: Initiates the server
43
+ %%--------------------------------------------------------------------
44
+ init([]) ->
45
+ {ok, #state{}}.
46
+
47
+ %%--------------------------------------------------------------------
48
+ %% Function: %% handle_call(Request, From, State) -> {reply, Reply, State} |
49
+ %% {reply, Reply, State, Timeout} |
50
+ %% {noreply, State} |
51
+ %% {noreply, State, Timeout} |
52
+ %% {stop, Reason, Reply, State} |
53
+ %% {stop, Reason, State}
54
+ %% Description: Handling call messages
55
+ %%--------------------------------------------------------------------
56
+ handle_call(_Request, _From, State) ->
57
+ Reply = ok,
58
+ {reply, Reply, State}.
59
+
60
+ %%--------------------------------------------------------------------
61
+ %% Function: handle_cast(Msg, State) -> {noreply, State} |
62
+ %% {noreply, State, Timeout} |
63
+ %% {stop, Reason, State}
64
+ %% Description: Handling cast messages
65
+ %%--------------------------------------------------------------------
66
+ handle_cast(_Msg, State) ->
67
+ {noreply, State}.
68
+
69
+ %%--------------------------------------------------------------------
70
+ %% Function: handle_info(Info, State) -> {noreply, State} |
71
+ %% {noreply, State, Timeout} |
72
+ %% {stop, Reason, State}
73
+ %% Description: Handling all non call/cast messages
74
+ %%--------------------------------------------------------------------
75
+ handle_info(_Info, State) ->
76
+ {noreply, State}.
77
+
78
+ %%--------------------------------------------------------------------
79
+ %% Function: terminate(Reason, State) -> void()
80
+ %% Description: This function is called by a gen_server when it is about to
81
+ %% terminate. It should be the opposite of Module:init/1 and do any necessary
82
+ %% cleaning up. When it returns, the gen_server terminates with Reason.
83
+ %% The return value is ignored.
84
+ %%--------------------------------------------------------------------
85
+ terminate(_Reason, _State) ->
86
+ ok.
87
+
88
+ %%--------------------------------------------------------------------
89
+ %% Func: code_change(OldVsn, State, Extra) -> {ok, NewState}
90
+ %% Description: Convert process state when code is changed
91
+ %%--------------------------------------------------------------------
92
+ code_change(_OldVsn, State, _Extra) ->
93
+ {ok, State}.
94
+
95
+ %%--------------------------------------------------------------------
96
+ %%% Internal functions
97
+ %%--------------------------------------------------------------------
13
98
 
14
99
  % pm_master:get_load("0", "cpu").
15
- get_load(Index, Type) ->
16
- Pid = get_pid_from_index(Index),
17
- gen_server:call(Pid, get_load_for_type, [Type]).
18
-
19
- % Private methods
20
- get_pid_from_index(Index) ->
21
- String = lists:append(["pm_node", Index]),
22
- io:format("Looking for ~p~n", [String]),
23
- whereis(str).
24
-
25
- % Tests
26
- basic_test_() ->
27
- ?_assert(get_pid_from_index == 0).
100
+ get_load(Type) ->
101
+ Nodes = get_live_nodes(),
102
+ {Loads, _} = rpc:multicall(Nodes, pm_node, get_load_for_type, [Type]),
103
+ {utils:convert_responses_to_int_list(Loads)}.
104
+
105
+ % Send reconfigure tasks to every node
106
+ reconfigure_cloud() ->
107
+ Nodes = get_live_nodes(),
108
+ {_, _} = rpc:multicall(Nodes, pm_node, run_reconfig, []),
109
+ {ok}.
110
+
111
+ % Fire the given command on all nodes
112
+ fire_cmd(Cmd) ->
113
+ Nodes = get_live_nodes(),
114
+ {_, _} = rpc:multicall(Nodes, pm_node, fire_cmd, [Cmd]),
115
+ {ok}.
116
+
117
+ % Get the live nodes
118
+ get_live_nodes() ->
119
+ nodes().
@@ -2,7 +2,39 @@
2
2
  % client service
3
3
 
4
4
  -module (pm_master_supervisor).
5
+ -behaviour(supervisor).
6
+
7
+ -export([start/0, start_in_shell_for_testing/0, start_link/1, init/1]).
5
8
 
6
9
  -ifdef(EUNIT).
7
10
  -include_lib("eunit/include/eunit.hrl").
8
- -endif.
11
+ -endif.
12
+
13
+ start() ->
14
+ spawn(fun() ->
15
+ supervisor:start_link({local, ?MODULE}, ?MODULE, _Arg = [])
16
+ end).
17
+
18
+ start_in_shell_for_testing() ->
19
+ {ok, Pid} = supervisor:start_link({local, ?MODULE}, ?MODULE, _Arg = []),
20
+ unlink(Pid).
21
+
22
+ start_link(Args) ->
23
+ supervisor:start_link({local, ?MODULE}, ?MODULE, Args).
24
+
25
+ init([]) ->
26
+ RestartStrategy = one_for_one,
27
+ MaxRestarts = 3, % 1000
28
+ MaxTimeBetRestarts = 30, % 3600
29
+
30
+ SupFlags = {RestartStrategy, MaxRestarts, MaxTimeBetRestarts},
31
+
32
+ LoadServers = [
33
+ {pm_master1,
34
+ {pm_master, start_link, []},
35
+ permanent, 5000, worker,
36
+ [pm_master]
37
+ }
38
+ ],
39
+
40
+ {ok, {SupFlags, LoadServers}}.
@@ -1,79 +1,125 @@
1
- %%%***************************************
2
- %%%
3
- %%% PoolParty node-server
4
- %%% Author: Ari Lerner <ari.the.lerner@gmail.com>
5
- %%%
6
- %%% Description: This server runs on the poolparty nodes
7
- %%%
8
- %%%***************************************
9
-
10
- % The name of our module
11
- -module (pm_node).
12
-
13
- -ifdef(EUNIT).
14
- -include_lib("eunit/include/eunit.hrl").
15
- -endif.
16
-
17
- % We are using the gen_server behaviour
18
- -behaviour (gen_server).
19
- -export ([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
1
+ %%%-------------------------------------------------------------------
2
+ %%% File : pm_node.erl
3
+ %%% Author : Ari Lerner <arilerner@mac.com>
4
+ %%% The client is a running process that will run on the master node
5
+ %%% and spawn requests to the pm_nodes and compile the responses
6
+ %%% for use within the poolparty network
7
+ %%%-------------------------------------------------------------------
8
+ -module(pm_node).
9
+ -behaviour(gen_server).
10
+
11
+ %% API
12
+ -export([start_link/0]).
13
+
14
+ %% gen_server callbacks
15
+ -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
16
+ terminate/2, code_change/3]).
17
+ -record(state, {}).
18
+ -define(SERVER, ?MODULE).
20
19
 
21
20
  % Client function definitions
22
- -export ([start_link/1, stop/0]).
23
- -export ([get_load_for_type/2]).
21
+ -export ([stop/0]).
22
+ -export ([get_load_for_type/1, fire_cmd/1, run_reconfig/0]).
24
23
 
25
- % Client Function API Calls
26
- get_load_for_type(From, Type) ->
27
- io:format("Getting load for "++Type++" on ~p~n", [From]),
28
- String = string:concat("server-get-load -m ",Type),
29
- gen_server:reply(From, {load, os:cmd(String)}).
24
+ %%====================================================================
25
+ %% API
26
+ %%====================================================================
27
+ %%--------------------------------------------------------------------
28
+ %% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
29
+ %% Description: Starts the server
30
+ %%
31
+ %% Starts the timer to fire off a ping to the master to let the master
32
+ %% know that it is alive
33
+ %%
34
+ %% Fires a ping every 10 seconds
35
+ %%--------------------------------------------------------------------
36
+ start_link() ->
37
+ utils:start_timer(10000, fun() -> net_adm:ping(master@auser) end),
38
+ gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
30
39
 
31
- start_link(Index) ->
32
- io:format("Starting pm_node~p...~n", [Index]),
33
- String = list_to_atom(string:concat("pm_node", Index)),
34
- gen_server:start_link({global, String}, String, [], []).
40
+ %%====================================================================
41
+ %% gen_server callbacks
42
+ %%====================================================================
35
43
 
36
- stop() ->
37
- gen_server:cast(?MODULE, stop).
38
-
39
- % Load monitor methods
40
- % TODO: Make this dynamic
41
- % get_system_load() ->
42
-
43
- % Gen server callbacks
44
- % Sends the response and state back
45
- init([]) ->
44
+ %%--------------------------------------------------------------------
45
+ %% Function: init(Args) -> {ok, State} |
46
+ %% {ok, State, Timeout} |
47
+ %% ignore |
48
+ %% {stop, Reason}
49
+ %% Description: Initiates the server
50
+ %%--------------------------------------------------------------------
51
+ init([]) ->
46
52
  process_flag(trap_exit, true),
47
- {ok, []}.
48
-
49
- % Handle synchronous messages
50
- % Signature:
51
- % handle_call(_Request, _From, State) ->
52
- % {reply, ignored, State}
53
- %
54
- % Gets the load on the server
55
- handle_call({get_load, Type}, From, State) ->
56
- spawn(?MODULE, get_load_for_type, [From, Type]),
57
- {noreply, State};
58
- handle_call(_Request, _From, State) -> % The catch-all
59
- {reply, ignored, State}.
60
-
61
- % Handle asynchronous messages
62
- handle_cast(stop, State) ->
63
- {stop, normal, State};
53
+ {ok, #state{}}.
54
+
55
+ %%--------------------------------------------------------------------
56
+ %% Function: %% handle_call(Request, From, State) -> {reply, Reply, State} |
57
+ %% {reply, Reply, State, Timeout} |
58
+ %% {noreply, State} |
59
+ %% {noreply, State, Timeout} |
60
+ %% {stop, Reason, Reply, State} |
61
+ %% {stop, Reason, State}
62
+ %% Description: Handling call messages
63
+ %%--------------------------------------------------------------------
64
+ handle_call(_Request, _From, State) ->
65
+ Reply = ok,
66
+ {reply, Reply, State}.
67
+
68
+ %%--------------------------------------------------------------------
69
+ %% Function: handle_cast(Msg, State) -> {noreply, State} |
70
+ %% {noreply, State, Timeout} |
71
+ %% {stop, Reason, State}
72
+ %% Description: Handling cast messages
73
+ %%--------------------------------------------------------------------
64
74
  handle_cast(_Msg, State) ->
65
- {noreply, State}.
75
+ {noreply, State}.
66
76
 
67
- % Handle other messages
77
+ %%--------------------------------------------------------------------
78
+ %% Function: handle_info(Info, State) -> {noreply, State} |
79
+ %% {noreply, State, Timeout} |
80
+ %% {stop, Reason, State}
81
+ %% Description: Handling all non call/cast messages
82
+ %%--------------------------------------------------------------------
68
83
  handle_info(_Info, State) ->
69
84
  io:format("Info message received from: ~p~n", [_Info]),
70
85
  {noreply, State}.
71
86
 
72
- % Exit
73
- terminate(_Reason, State) ->
74
- io:format("Server is stopping...~n"),
75
- {ok, State}.
87
+ %%--------------------------------------------------------------------
88
+ %% Function: terminate(Reason, State) -> void()
89
+ %% Description: This function is called by a gen_server when it is about to
90
+ %% terminate. It should be the opposite of Module:init/1 and do any necessary
91
+ %% cleaning up. When it returns, the gen_server terminates with Reason.
92
+ %% The return value is ignored.
93
+ %%--------------------------------------------------------------------
94
+ terminate(_Reason, _State) ->
95
+ utils:stop_timer(),
96
+ ok.
76
97
 
77
- % If the code changes
98
+ %%--------------------------------------------------------------------
99
+ %% Func: code_change(OldVsn, State, Extra) -> {ok, NewState}
100
+ %% Description: Convert process state when code is changed
101
+ %%--------------------------------------------------------------------
78
102
  code_change(_OldVsn, State, _Extra) ->
79
- {ok, State}.
103
+ {ok, State}.
104
+
105
+ %%--------------------------------------------------------------------
106
+ %%% Internal functions
107
+ %%--------------------------------------------------------------------
108
+
109
+ % Get the load for the type sent...
110
+ get_load_for_type(Type) ->
111
+ String = string:concat(". /etc/profile && server-get-load -m ",Type),
112
+ {os:cmd(String)}.
113
+
114
+ % Rerun the configuration
115
+ run_reconfig() -> {os:cmd(". /etc/profile && server-rerun")}.
116
+
117
+ % Allows us to fire off any command (allowed by poolparty on the check)
118
+ fire_cmd(Cmd) ->
119
+ String = ". /etc/profile && server-fire-cmd \""++Cmd++"\"",
120
+ io:format("Sending command "++String),
121
+ {os:cmd(String)}.
122
+
123
+ % Stop the pm_node entirely
124
+ stop() ->
125
+ gen_server:cast(?MODULE, stop).