From 4a55b273f50aebf4692370e9e399b788d8128ae1 Mon Sep 17 00:00:00 2001 From: Przemyslaw Krowinski Date: Mon, 10 Jun 2019 22:32:52 +0200 Subject: [PATCH 1/5] Add dummy changes --- backend/master_vars.config | 2 +- backend/rebar.lock | 26 +++++++ backend/slave_vars.config | 2 +- backend/src/conway_game.app.src | 2 +- backend/src/conway_master_worker.erl | 6 +- backend/src/conway_slave.erl | 105 +++++++++++++++++++++++++-- backend/src/conway_slave_sup.erl | 2 +- backend/src/rest_endpoint.erl | 11 +-- 8 files changed, 140 insertions(+), 16 deletions(-) create mode 100644 backend/rebar.lock diff --git a/backend/master_vars.config b/backend/master_vars.config index 5eeaf5f..5abe26e 100644 --- a/backend/master_vars.config +++ b/backend/master_vars.config @@ -1 +1 @@ -{node_name, 'master@host'}. +{node_name, 'master@127.0.0.1'}. diff --git a/backend/rebar.lock b/backend/rebar.lock new file mode 100644 index 0000000..2591e65 --- /dev/null +++ b/backend/rebar.lock @@ -0,0 +1,26 @@ +{"1.1.0", +[{<<"cowboy">>, + {git,"git://github.com/ninenines/cowboy.git", + {ref,"d846827b2a70317914621328bd617e4e5d4d13d8"}}, + 0}, + {<<"cowlib">>, + {git,"https://github.com/ninenines/cowlib", + {ref,"75aaeb8415033b07303febbfeba66d6d3413ad06"}}, + 1}, + {<<"epmd">>, + {git,"https://github.com/erlang/epmd", + {ref,"4d1a595b9d5c32fc0e55f462da381de62de23bf0"}}, + 0}, + {<<"grisp">>,{pkg,<<"grisp">>,<<"1.1.4">>},0}, + {<<"jiffy">>,{pkg,<<"jiffy">>,<<"0.15.2">>},0}, + {<<"mapz">>,{pkg,<<"mapz">>,<<"0.3.0">>},1}, + {<<"ranch">>, + {git,"https://github.com/ninenines/ranch", + {ref,"3190aef88aea04d6dce8545fe9b4574288903f44"}}, + 1}]}. +[ +{pkg_hash,[ + {<<"grisp">>, <<"5C22D6F9C0B47A90F132E56AC9D85659B5AC469BAF04B4C98EE1E0EF5894319B">>}, + {<<"jiffy">>, <<"DE266C390111FD4EA28B9302F0BC3D7472468F3B8E0ACEABFBEFA26D08CD73B7">>}, + {<<"mapz">>, <<"438D24746CE5A252101E00B2032EFDF7FC69EB32689D3B805DE5E6DD7F52614F">>}]} +]. diff --git a/backend/slave_vars.config b/backend/slave_vars.config index 05b5cec..6db9a26 100644 --- a/backend/slave_vars.config +++ b/backend/slave_vars.config @@ -1 +1 @@ -{node_name, 'slave@host'}. +{node_name, 'slave@127.0.0.1'}. diff --git a/backend/src/conway_game.app.src b/backend/src/conway_game.app.src index cdd485a..cf6906d 100644 --- a/backend/src/conway_game.app.src +++ b/backend/src/conway_game.app.src @@ -10,7 +10,7 @@ jiffy, runtime_tools ]}, - {env,[ {masterhost, 'master@host'}, + {env,[ {masterhost, 'master@127.0.0.1'}, {slave_n, 1}]}, {modules, []}, diff --git a/backend/src/conway_master_worker.erl b/backend/src/conway_master_worker.erl index aa91a11..8ba54ce 100644 --- a/backend/src/conway_master_worker.erl +++ b/backend/src/conway_master_worker.erl @@ -102,7 +102,9 @@ handle_cast({update, NodeName, Rect, G}, #state{state = computing, {noreply, State#state{current_rects = NewCurrentRects}} end; handle_cast(M, S) -> - io:format("[WARN] Unknown cast: ~p in state ~p~n", [M, S]), + io:format("[WARN] Unknown cast: ~p ~n", [M]), + io:format("[WARN] in state ~p~n", [S]), + io:format("[WARN] State: ~p ~n", [S#state.state]), {noreply, S}. handle_info({'DOWN', Ref, _, _, Reason} = M, S) -> @@ -116,7 +118,7 @@ handle_info(_, S) -> noderef() -> {ok, NodeName} = application:get_env(conway_game, masterhost), {?MODULE, NodeName}. - + inc_generation(#state{goal_generations = N, generation = M} = State) when N == M -> NewState = State#state{state = finished, generation = M}, ws_h:update_state(format_state(NewState)), diff --git a/backend/src/conway_slave.erl b/backend/src/conway_slave.erl index 422615d..053825e 100644 --- a/backend/src/conway_slave.erl +++ b/backend/src/conway_slave.erl @@ -1,8 +1,103 @@ +%%% @author zofiapolkowska +%%% @copyright (C) 2019, zofiapolkowska +%%% @doc +%%% +%%% @end +%%% Created : 2019-06-04 18:06:41.713061 + -module(conway_slave). --export([loop/0]). +-behaviour(gen_server). + +%% API +-export([start_link/0, + init_state/5]). + +%% Callbacks +-export([init/1, + handle_call/3, + handle_cast/2, + handle_info/2, + terminate/2, + code_change/3]). + +-define(SERVER, ?MODULE). +-define(PRINT(Var), io:format("DEBUG: ~p:~p - ~p~n~n ~p~n~n", [?MODULE, ?LINE, ??Var, Var])). + +-record(state, { + rect = null, + current_gen = 0, + max_gen = 1, + node_name = "" +}). + +%%% API + +start_link() -> + gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). + +init_state(Node, StartingRect, Gens, _Slaves, _W) -> + io:format("Init State~n", []), + gen_server:call({?MODULE, Node}, {init_state, Node, StartingRect, Gens}), + gen_server:cast({?MODULE, Node}, {tick}). + +%%% gen_server callbacks + +init([]) -> + io:format("Slave initialized~n", []), + conway_master_worker:register_slave(node()), + + {ok, #state{}}. + +handle_call({init_state, NodeName, StartingRect, Gens}, _From, State) -> + Rect = [], + NewState = #state{ + rect = StartingRect, + current_gen = 0, + max_gen = Gens, + node_name = NodeName + }, + {reply, ok, NewState}. + +handle_cast({tick}, #state{max_gen = MaxGen, current_gen = CurrentGen} = State) when CurrentGen >= MaxGen -> + {noreply, State}; +handle_cast({tick}, State) -> + % TODO: Pattern match + NewGen = State#state.current_gen + 1, + + %Fields = rect:map(fun(x, y, value) -> update_cell(x, y, value, State#state.rect) end, State#state.rect), + NewRect = rect:map(fun update_cell/3, State#state.rect), + %NewRect = map:put(fields, Fields, State#state.rect), + + NewState = State#state{ + current_gen = NewGen, + rect = NewRect}, + + conway_master_worker:update_state( + NewState#state.node_name, + NewState#state.rect, + NewState#state.current_gen), + + io:format("Tick: Generation ~p ~n", [current_gen]), + + timer:sleep(500), + gen_server:cast({?MODULE, State#state.node_name}, {tick}), + + {noreply, State}; + +handle_cast(_Msg, State) -> + {noreply, State}. + +handle_info(_Info, State) -> + {noreply, State}. + +terminate(_Reason, _State) -> + ok. + +code_change(_OldVsn, State, _Extra) -> + {ok, State}. + +%%% Internal functions -loop() -> - io:format("I am alive~n", []), - timer:sleep(10000), - loop(). +update_cell(X, Y, _Value) -> + {{X, Y}, true}. diff --git a/backend/src/conway_slave_sup.erl b/backend/src/conway_slave_sup.erl index 68beaa9..65475f6 100644 --- a/backend/src/conway_slave_sup.erl +++ b/backend/src/conway_slave_sup.erl @@ -31,5 +31,5 @@ start_link() -> %% Before OTP 18 tuples must be used to specify a child. e.g. %% Child :: {Id,StartFunc,Restart,Shutdown,Type,Modules} init([]) -> - ConwayWorker = #{id => conway_slave, start => {conway_slave, loop, []}}, + ConwayWorker = #{id => conway_slave, start => {conway_slave, start_link, []}}, {ok, { {one_for_all, 0, 1}, [ConwayWorker]} }. diff --git a/backend/src/rest_endpoint.erl b/backend/src/rest_endpoint.erl index 3a5a2f2..4332cd5 100644 --- a/backend/src/rest_endpoint.erl +++ b/backend/src/rest_endpoint.erl @@ -3,12 +3,13 @@ -export([init/2]). -export([content_types_provided/2]). -export([content_types_accepted/2]). +-export([content_types_accepted/2]). -export([allowed_methods/2]). -export([to_json/2]). init(Req, Opts) -> - ReqWithCORS = add_cors_headers(Req), - {cowboy_rest, ReqWithCORS, Opts}. + ReqWithCORS = add_cors_headers(Req), + {cowboy_rest, ReqWithCORS, Opts}. allowed_methods(Req, State) -> {[<<"POST">>, <<"GET">>, <<"OPTIONS">>], Req, State}. @@ -29,7 +30,7 @@ to_json(Req, State) -> <<"GET">> -> get_state(Req, State); <<"OPTIONS">> -> - {true, Req, State} + {true, Req, State} end. start_the_game(Req, State) -> @@ -72,8 +73,8 @@ to_int(B) when is_list(B) -> %% Helpers add_cors_headers(Req) -> - Req1 = cowboy_req:set_resp_header(<<"access-control-allow-origin">>, <<"*">>, Req), - cowboy_req:set_resp_header(<<"access-control-allow-headers">>, <<"Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With">>, Req1). + Req1 = cowboy_req:set_resp_header(<<"access-control-allow-origin">>, <<"*">>, Req), + cowboy_req:set_resp_header(<<"access-control-allow-headers">>, <<"Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With">>, Req1). is_master_node_started() -> case maps:get(start_state, conway_master_worker:get_state()) of From c49f10425c2fb8af1bf5cf0db4ad6dc698e4b462 Mon Sep 17 00:00:00 2001 From: Przemyslaw Krowinski Date: Mon, 10 Jun 2019 23:05:56 +0200 Subject: [PATCH 2/5] Add game of life calculations --- backend/src/conway_slave.erl | 35 ++++++-- conway_dashboard/package-lock.json | 123 ++++++++--------------------- 2 files changed, 61 insertions(+), 97 deletions(-) diff --git a/backend/src/conway_slave.erl b/backend/src/conway_slave.erl index 053825e..74ae8e9 100644 --- a/backend/src/conway_slave.erl +++ b/backend/src/conway_slave.erl @@ -65,8 +65,8 @@ handle_cast({tick}, State) -> % TODO: Pattern match NewGen = State#state.current_gen + 1, - %Fields = rect:map(fun(x, y, value) -> update_cell(x, y, value, State#state.rect) end, State#state.rect), - NewRect = rect:map(fun update_cell/3, State#state.rect), + NewRect = rect:map(fun(X, Y, Value) -> update_cell(X, Y, Value, State#state.rect) end, State#state.rect), + %NewRect = rect:map(fun update_cell/3, State#state.rect), %NewRect = map:put(fields, Fields, State#state.rect), NewState = State#state{ @@ -78,12 +78,12 @@ handle_cast({tick}, State) -> NewState#state.rect, NewState#state.current_gen), - io:format("Tick: Generation ~p ~n", [current_gen]), + io:format("Tick: Generation ~p ~n", [NewGen]), - timer:sleep(500), + timer:sleep(300), gen_server:cast({?MODULE, State#state.node_name}, {tick}), - {noreply, State}; + {noreply, NewState}; handle_cast(_Msg, State) -> {noreply, State}. @@ -99,5 +99,26 @@ code_change(_OldVsn, State, _Extra) -> %%% Internal functions -update_cell(X, Y, _Value) -> - {{X, Y}, true}. +update_cell(X, Y, Value, Rect) -> + Neighbours = [ + rect:get(Rect, {X-1, Y-1}), + rect:get(Rect, {X, Y-1}), + rect:get(Rect, {X+1, Y-1}), + rect:get(Rect, {X-1, Y}), + rect:get(Rect, {X+1, Y}), + rect:get(Rect, {X-1, Y+1}), + rect:get(Rect, {X, Y+1}), + rect:get(Rect, {X+1, Y+1}) + ], + Count = length(lists:filter(fun(Value) -> + case Value of + true -> true; + _ -> false + end + end, Neighbours)), + NewValue = case {Count, Value} of + {2, true} -> true; + {3, _} -> true; + _ -> false + end, + {{X, Y}, NewValue}. diff --git a/conway_dashboard/package-lock.json b/conway_dashboard/package-lock.json index 7424b76..c876c70 100644 --- a/conway_dashboard/package-lock.json +++ b/conway_dashboard/package-lock.json @@ -2946,8 +2946,7 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true, - "optional": true + "bundled": true }, "aproba": { "version": "1.2.0", @@ -2965,13 +2964,11 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, - "optional": true + "bundled": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2984,18 +2981,15 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", - "bundled": true, - "optional": true + "bundled": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -3098,8 +3092,7 @@ }, "inherits": { "version": "2.0.3", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -3109,7 +3102,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -3122,20 +3114,17 @@ "minimatch": { "version": "3.0.4", "bundled": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true, - "optional": true + "bundled": true }, "minipass": { "version": "2.3.5", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -3152,7 +3141,6 @@ "mkdirp": { "version": "0.5.1", "bundled": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -3225,8 +3213,7 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "object-assign": { "version": "4.1.1", @@ -3236,7 +3223,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -3312,8 +3298,7 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -3343,7 +3328,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -3361,7 +3345,6 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -3400,13 +3383,11 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true, - "optional": true + "bundled": true }, "yallist": { "version": "3.0.3", - "bundled": true, - "optional": true + "bundled": true } } }, @@ -6580,8 +6561,7 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true, - "optional": true + "bundled": true }, "aproba": { "version": "1.2.0", @@ -6599,13 +6579,11 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, - "optional": true + "bundled": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -6618,18 +6596,15 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", - "bundled": true, - "optional": true + "bundled": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -6732,8 +6707,7 @@ }, "inherits": { "version": "2.0.3", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -6743,7 +6717,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -6756,20 +6729,17 @@ "minimatch": { "version": "3.0.4", "bundled": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true, - "optional": true + "bundled": true }, "minipass": { "version": "2.3.5", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -6786,7 +6756,6 @@ "mkdirp": { "version": "0.5.1", "bundled": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -6859,8 +6828,7 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "object-assign": { "version": "4.1.1", @@ -6870,7 +6838,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -6946,8 +6913,7 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -6977,7 +6943,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -6995,7 +6960,6 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -7034,13 +6998,11 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true, - "optional": true + "bundled": true }, "yallist": { "version": "3.0.3", - "bundled": true, - "optional": true + "bundled": true } } }, @@ -13428,8 +13390,7 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true, - "optional": true + "bundled": true }, "aproba": { "version": "1.2.0", @@ -13447,13 +13408,11 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, - "optional": true + "bundled": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -13466,18 +13425,15 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", - "bundled": true, - "optional": true + "bundled": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -13580,8 +13536,7 @@ }, "inherits": { "version": "2.0.3", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -13591,7 +13546,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -13604,20 +13558,17 @@ "minimatch": { "version": "3.0.4", "bundled": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true, - "optional": true + "bundled": true }, "minipass": { "version": "2.2.4", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -13634,7 +13585,6 @@ "mkdirp": { "version": "0.5.1", "bundled": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -13707,8 +13657,7 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "object-assign": { "version": "4.1.1", @@ -13718,7 +13667,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -13794,8 +13742,7 @@ }, "safe-buffer": { "version": "5.1.1", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -13825,7 +13772,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -13843,7 +13789,6 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -13882,13 +13827,11 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true, - "optional": true + "bundled": true }, "yallist": { "version": "3.0.2", - "bundled": true, - "optional": true + "bundled": true } } } From 678a3187cdef34a2967e37ad0465053aae7bc813 Mon Sep 17 00:00:00 2001 From: Przemyslaw Krowinski Date: Sun, 23 Jun 2019 10:43:25 +0200 Subject: [PATCH 3/5] Update config and ensure that project works with 1 master and 1 slave --- backend/grisp/grisp_base/files/erl_inetrc | 2 +- backend/grisp/grisp_base/files/grisp.ini.mustache | 2 +- backend/grisp/grisp_base/files/wpa_supplicant.conf | 4 ++-- backend/master_vars.config | 2 +- backend/src/conway_game.app.src | 2 +- backend/src/conway_master_worker.erl | 1 + backend/src/conway_slave.erl | 4 ++-- backend/vm.args | 2 +- 8 files changed, 10 insertions(+), 9 deletions(-) diff --git a/backend/grisp/grisp_base/files/erl_inetrc b/backend/grisp/grisp_base/files/erl_inetrc index 2f479f2..da067c8 100644 --- a/backend/grisp/grisp_base/files/erl_inetrc +++ b/backend/grisp/grisp_base/files/erl_inetrc @@ -1,5 +1,5 @@ % Add hosts -{host, {X,X,X,X}, ["hostname"]}. +{host, {10,152,0,13}, ["mainframe1"]}. % Do not monitor the hosts file {hosts_file, ""}. diff --git a/backend/grisp/grisp_base/files/grisp.ini.mustache b/backend/grisp/grisp_base/files/grisp.ini.mustache index 9f0579c..156a0fa 100644 --- a/backend/grisp/grisp_base/files/grisp.ini.mustache +++ b/backend/grisp/grisp_base/files/grisp.ini.mustache @@ -7,5 +7,5 @@ args = erl.rtems -- -home . -pa . -root conway_game -boot conway_game/releases/0 [network] ip_self = dhcp wlan = enable -hostname = boardX +hostname = board0002 wpa = wpa_supplicant.conf diff --git a/backend/grisp/grisp_base/files/wpa_supplicant.conf b/backend/grisp/grisp_base/files/wpa_supplicant.conf index efd149a..b9a6801 100644 --- a/backend/grisp/grisp_base/files/wpa_supplicant.conf +++ b/backend/grisp/grisp_base/files/wpa_supplicant.conf @@ -1,5 +1,5 @@ network={ - ssid="MagicGrisp" + ssid="__YOUR_SSID_HERE__" key_mgmt=WPA-PSK - psk="SecretGrisp" + psk="__YOUR_PASSWORD_HERE__" } diff --git a/backend/master_vars.config b/backend/master_vars.config index 5abe26e..0d9f77e 100644 --- a/backend/master_vars.config +++ b/backend/master_vars.config @@ -1 +1 @@ -{node_name, 'master@127.0.0.1'}. +{node_name, master}. diff --git a/backend/src/conway_game.app.src b/backend/src/conway_game.app.src index cf6906d..244cb03 100644 --- a/backend/src/conway_game.app.src +++ b/backend/src/conway_game.app.src @@ -10,7 +10,7 @@ jiffy, runtime_tools ]}, - {env,[ {masterhost, 'master@127.0.0.1'}, + {env,[ {masterhost, 'master@mainframe1'}, {slave_n, 1}]}, {modules, []}, diff --git a/backend/src/conway_master_worker.erl b/backend/src/conway_master_worker.erl index 8ba54ce..7a61bc5 100644 --- a/backend/src/conway_master_worker.erl +++ b/backend/src/conway_master_worker.erl @@ -47,6 +47,7 @@ reset_state() -> gen_server:call(noderef(), reset_state). get_state_raw() -> gen_server:call(noderef(), get_state_raw). init([SlaveN]) -> + io:format("Master node ~p~n", [node()]), {ok, #state{max_slaves = SlaveN, started = true}}. handle_call(reset_state, _, #state{ max_slaves = MaxSl }) -> diff --git a/backend/src/conway_slave.erl b/backend/src/conway_slave.erl index 74ae8e9..1661195 100644 --- a/backend/src/conway_slave.erl +++ b/backend/src/conway_slave.erl @@ -44,8 +44,8 @@ init_state(Node, StartingRect, Gens, _Slaves, _W) -> %%% gen_server callbacks init([]) -> - io:format("Slave initialized~n", []), - conway_master_worker:register_slave(node()), + io:format("Slave initialized~p~n", [node()]), + % conway_master_worker:register_slave(node()), {ok, #state{}}. diff --git a/backend/vm.args b/backend/vm.args index c8234b1..d35b3d0 100644 --- a/backend/vm.args +++ b/backend/vm.args @@ -1,4 +1,4 @@ --name {{node_name}} +-sname {{node_name}} ## Cookie for distributed erlang -setcookie conway_game From eca12d0f7e31ab3325ca9419185a5dd72593d52a Mon Sep 17 00:00:00 2001 From: Przemyslaw Krowinski Date: Mon, 24 Jun 2019 23:07:23 +0200 Subject: [PATCH 4/5] Use ssid and password from the original project --- backend/grisp/grisp_base/files/wpa_supplicant.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/grisp/grisp_base/files/wpa_supplicant.conf b/backend/grisp/grisp_base/files/wpa_supplicant.conf index b9a6801..efd149a 100644 --- a/backend/grisp/grisp_base/files/wpa_supplicant.conf +++ b/backend/grisp/grisp_base/files/wpa_supplicant.conf @@ -1,5 +1,5 @@ network={ - ssid="__YOUR_SSID_HERE__" + ssid="MagicGrisp" key_mgmt=WPA-PSK - psk="__YOUR_PASSWORD_HERE__" + psk="SecretGrisp" } From b711df25adeb8fd2b0924ba41f0a355f515b6ecc Mon Sep 17 00:00:00 2001 From: Przemyslaw Krowinski Date: Mon, 24 Jun 2019 23:14:31 +0200 Subject: [PATCH 5/5] Update formatting --- backend/src/conway_slave.erl | 109 ++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/backend/src/conway_slave.erl b/backend/src/conway_slave.erl index 1661195..144ba34 100644 --- a/backend/src/conway_slave.erl +++ b/backend/src/conway_slave.erl @@ -44,81 +44,82 @@ init_state(Node, StartingRect, Gens, _Slaves, _W) -> %%% gen_server callbacks init([]) -> - io:format("Slave initialized~p~n", [node()]), - % conway_master_worker:register_slave(node()), + io:format("Slave initialized~p~n", [node()]), + conway_master_worker:register_slave(node()), - {ok, #state{}}. + {ok, #state{}}. handle_call({init_state, NodeName, StartingRect, Gens}, _From, State) -> - Rect = [], - NewState = #state{ - rect = StartingRect, - current_gen = 0, - max_gen = Gens, - node_name = NodeName - }, - {reply, ok, NewState}. + Rect = [], + NewState = #state{ + rect = StartingRect, + current_gen = 0, + max_gen = Gens, + node_name = NodeName + }, + {reply, ok, NewState}. handle_cast({tick}, #state{max_gen = MaxGen, current_gen = CurrentGen} = State) when CurrentGen >= MaxGen -> - {noreply, State}; + {noreply, State}; + handle_cast({tick}, State) -> - % TODO: Pattern match - NewGen = State#state.current_gen + 1, + NewGen = State#state.current_gen + 1, - NewRect = rect:map(fun(X, Y, Value) -> update_cell(X, Y, Value, State#state.rect) end, State#state.rect), - %NewRect = rect:map(fun update_cell/3, State#state.rect), - %NewRect = map:put(fields, Fields, State#state.rect), + NewRect = rect:map(fun(X, Y, Value) -> update_cell(X, Y, Value, State#state.rect) end, State#state.rect), - NewState = State#state{ - current_gen = NewGen, - rect = NewRect}, + NewState = State#state{ + current_gen = NewGen, + rect = NewRect}, - conway_master_worker:update_state( - NewState#state.node_name, - NewState#state.rect, - NewState#state.current_gen), + conway_master_worker:update_state( + NewState#state.node_name, + NewState#state.rect, + NewState#state.current_gen), - io:format("Tick: Generation ~p ~n", [NewGen]), + io:format("Tick: Generation ~p ~n", [NewGen]), - timer:sleep(300), - gen_server:cast({?MODULE, State#state.node_name}, {tick}), + timer:sleep(300), + gen_server:cast({?MODULE, State#state.node_name}, {tick}), - {noreply, NewState}; + {noreply, NewState}; handle_cast(_Msg, State) -> - {noreply, State}. + {noreply, State}. handle_info(_Info, State) -> - {noreply, State}. + {noreply, State}. terminate(_Reason, _State) -> - ok. + ok. code_change(_OldVsn, State, _Extra) -> - {ok, State}. + {ok, State}. %%% Internal functions update_cell(X, Y, Value, Rect) -> - Neighbours = [ - rect:get(Rect, {X-1, Y-1}), - rect:get(Rect, {X, Y-1}), - rect:get(Rect, {X+1, Y-1}), - rect:get(Rect, {X-1, Y}), - rect:get(Rect, {X+1, Y}), - rect:get(Rect, {X-1, Y+1}), - rect:get(Rect, {X, Y+1}), - rect:get(Rect, {X+1, Y+1}) - ], - Count = length(lists:filter(fun(Value) -> - case Value of - true -> true; - _ -> false - end - end, Neighbours)), - NewValue = case {Count, Value} of - {2, true} -> true; - {3, _} -> true; - _ -> false - end, - {{X, Y}, NewValue}. + Neighbours = [ + rect:get(Rect, {X-1, Y-1}), + rect:get(Rect, {X, Y-1}), + rect:get(Rect, {X+1, Y-1}), + rect:get(Rect, {X-1, Y}), + rect:get(Rect, {X+1, Y}), + rect:get(Rect, {X-1, Y+1}), + rect:get(Rect, {X, Y+1}), + rect:get(Rect, {X+1, Y+1}) + ], + + Count = length(lists:filter(fun(Value) -> + case Value of + true -> true; + _ -> false + end + end, Neighbours)), + + NewValue = case {Count, Value} of + {2, true} -> true; + {3, _} -> true; + _ -> false + end, + + {{X, Y}, NewValue}.