Skip to content

Commit

Permalink
demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Laymer committed Sep 12, 2018
1 parent b471f9d commit 3d4b7b5
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 41 deletions.
45 changes: 37 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ CACHE_DIR ?= $(HOME)/.cache/rebar3
# HOSTNAME ?= $(shell hostname)
COOKIE ?= MyCookie
VERSION ?= 0.1.0
DEPLOY_DEST ?= /media/laymer/GRISP
# MAKE = make
#
# .PHONY: grispbuild rel deps plots dcos logs fpm no-cfg-build tarball-build \
Expand All @@ -27,7 +28,7 @@ VERSION ?= 0.1.0

# .PHONY: grispbuild rel deps test plots dcos logs fpm no-cfg-build tarball-build build

.PHONY: compile testshell shell 2shell 3shell deploy 10deploy 11deploy rel stage \
.PHONY: compile testshell shell 2shell 3shell deploy 10deploy 11deploy rel stage doubledeploy ndeploy \
# cleaning targets :
wipe clean buildclean grispclean cacheclean elixirclean checkoutsclean ⁠\
# currently not working targets :
Expand Down Expand Up @@ -115,16 +116,44 @@ rel: prod-app-src
stage: prod-app-src
$(REBAR) release -d

deploy: prod-app-src
$(REBAR) grisp deploy -n $(GRISPAPP) -v $(VERSION)
# deploy: prod-app-src
# $(REBAR) grisp deploy -n $(GRISPAPP) -v $(VERSION)
#
# 1deploy: prod-app-src
# cp $(DEPLOYMENTS_DIR)/1/grisp.ini.mustache $(GRISPFILES_DIR)/grisp.ini.mustache
# $(REBAR) grisp deploy -n $(GRISPAPP) -v $(VERSION)
#
# 2deploy: prod-app-src
# cp $(DEPLOYMENTS_DIR)/2/grisp.ini.mustache $(GRISPFILES_DIR)/grisp.ini.mustache
# $(REBAR) grisp deploy -n $(GRISPAPP) -v $(VERSION)

1deploy: prod-app-src
cp $(DEPLOYMENTS_DIR)/1/grisp.ini.mustache $(GRISPFILES_DIR)/grisp.ini.mustache
$(REBAR) grisp deploy -n $(GRISPAPP) -v $(VERSION)

2deploy: prod-app-src
doubledeploy: deploy 1deploy
echo "deployed"

ndeploy:
cp $(DEPLOYMENTS_DIR)/$(n)/grisp.ini.mustache $(GRISPFILES_DIR)/grisp.ini.mustache
rm -rdf $(DEPLOY_DEST)$(d)/*
$(REBAR) grisp deploy -n $(GRISPAPP) -v $(VERSION) --destination $(DEPLOY_DEST)$(d) --force true
umount $(DEPLOY_DEST)$(d)

deploy:
# cp $(DEPLOYMENTS_DIR)/$(n)/grisp.ini.mustache $(GRISPFILES_DIR)/grisp.ini.mustache
rm -rdf $(DEPLOY_DEST)/*
$(REBAR) grisp deploy -n $(GRISPAPP) -v $(VERSION) --destination $(DEPLOY_DEST) --force true
umount $(DEPLOY_DEST)

1deploy:
cp $(DEPLOYMENTS_DIR)/2/grisp.ini.mustache $(GRISPFILES_DIR)/grisp.ini.mustache
$(REBAR) grisp deploy -n $(GRISPAPP) -v $(VERSION)
rm -rdf $(DEPLOY_DEST)1/*
$(REBAR) grisp deploy -n $(GRISPAPP) -v $(VERSION) --destination $(DEPLOY_DEST)1 --force true
umount $(DEPLOY_DEST)1

3deploy:
cp $(DEPLOYMENTS_DIR)/3/grisp.ini.mustache $(GRISPFILES_DIR)/grisp.ini.mustache
rm -rdf $(DEPLOY_DEST)/*
$(REBAR) grisp deploy -n $(GRISPAPP) -v $(VERSION) --destination $(DEPLOY_DEST) --force true
umount $(DEPLOY_DEST)

10deploy: prod-app-src
cp $(DEPLOYMENTS_DIR)/10/grisp.ini.mustache $(GRISPFILES_DIR)/grisp.ini.mustache
Expand Down
4 changes: 2 additions & 2 deletions config/sys.config
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{generic_tasks_sets_names, [tasks]},
{data_crdts_names, [{temp, dont_flush_crdt}]},
{generic_tasks_restart_interval, 30000},
{gc_interval, 60000},
{gc_interval, 40000},
{emulate_als, false},
{als_stream_interval, 180000},
{als_propagation_treshold, 10},
Expand All @@ -27,7 +27,7 @@
% beforehand using erl_inetrc config file
{remote_hosts,
% #{webservers => ['nodews@Laymer'],
#{webservers => ['ws@GrispAdhoc'],
#{webservers => ['ws@GrispAdhoc','ws@Laymer','ws@laymer-3'],
aws_servers => [],
main_aws_server => []}
},
Expand Down
2 changes: 2 additions & 0 deletions grisp/grisp_base/files/erl_inetrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
% {host, {169,254,91,23}, ["Laymer-3"]}.
% {host, {192,168,1,39}, ["Laymer"]}.
{host, {169,254,187,88}, ["GrispAdhoc"]}.
{host, {169,254,187,89}, ["Laymer"]}.
{host, {169,254,187,90}, ["laymer-3"]}.
%--- GRiSP boards --------------------------------------------------------------
{host, {169,254,16,1}, ["my_grisp_board_1"]}.
{host, {169,254,16,2}, ["my_grisp_board_2"]}.
Expand Down
4 changes: 2 additions & 2 deletions priv/deployment_args/1/grisp.ini.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
image_path = /media/mmcsd-0-0/{{release_name}}/erts-{{erts_vsn}}/bin/beam.bin

[erlang]
args = erl.rtems -- +MHas aobf +MMmcs 5 +MHlmbcs 5240 -mode embedded -home . -pa . -root {{release_name}} -config {{release_name}}/releases/{{release_version}}/sys.config -boot {{release_name}}/releases/{{release_version}}/{{release_name}} -internal_epmd epmd_sup -kernel inetrc "./erl_inetrc" -name {{release_name}}@my_grisp_board_1 -setcookie MyCookie
args = erl.rtems -- +MHas aobf +MMmcs 5 +MHlmbcs 512 -mode embedded -home . -pa . -root {{release_name}} -config {{release_name}}/releases/{{release_version}}/sys.config -boot {{release_name}}/releases/{{release_version}}/{{release_name}} -internal_epmd epmd_sup -kernel inetrc "./erl_inetrc" -sname {{release_name}} -setcookie MyCookie

[network]
ip_self=dhcp
ip_self=169.254.16.1
wlan=enable
hostname=my_grisp_board_1
5 changes: 2 additions & 3 deletions priv/deployment_args/2/grisp.ini.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
image_path = /media/mmcsd-0-0/{{release_name}}/erts-{{erts_vsn}}/bin/beam.bin

[erlang]
args = erl.rtems -- +MHas aobf +MMmcs 5 +MHlmbcs 5240 -mode embedded -home . -pa . -root {{release_name}} -config {{release_name}}/releases/{{release_version}}/sys.config -boot {{release_name}}/releases/{{release_version}}/{{release_name}} -internal_epmd epmd_sup -kernel inetrc "./erl_inetrc" -name {{release_name}}@my_grisp_board_2 -setcookie MyCookie
args = erl.rtems -- +MHas aobf +MMmcs 5 +MHlmbcs 512 -mode embedded -home . -pa . -root {{release_name}} -config {{release_name}}/releases/{{release_version}}/sys.config -boot {{release_name}}/releases/{{release_version}}/{{release_name}} -internal_epmd epmd_sup -kernel inetrc "./erl_inetrc" -sname {{release_name}} -setcookie MyCookie

[network]
ip_self=dhcp
ip_self=169.254.16.2
wlan=enable
hostname=my_grisp_board_2
wpa=wpa_supplicant.conf
10 changes: 10 additions & 0 deletions priv/deployment_args/3/grisp.ini.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[boot]
image_path = /media/mmcsd-0-0/{{release_name}}/erts-{{erts_vsn}}/bin/beam.bin

[erlang]
args = erl.rtems -- +MHas aobf +MMmcs 5 +MHlmbcs 512 -mode embedded -home . -pa . -root {{release_name}} -config {{release_name}}/releases/{{release_version}}/sys.config -boot {{release_name}}/releases/{{release_version}}/{{release_name}} -internal_epmd epmd_sup -kernel inetrc "./erl_inetrc" -sname {{release_name}} -setcookie MyCookie

[network]
ip_self=169.254.16.3
wlan=enable
hostname=my_grisp_board_3
21 changes: 11 additions & 10 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
% {directory,"/home/laymer/EdgeComputing/NewGRiSP/grisp-software/rtems-install/rtems/5"}]}
]},
{deploy, [
{pre_script, "rm -rf /media/laymer/GRISP/*"}, % Igor
{destination, "/media/laymer/GRISP"}, % Igor
{post_script, "umount /media/laymer/GRISP"} % Igor
% {pre_script, "rm -rf /media/laymer/GRISP/*"}, % Igor
% {destination, "/media/laymer/GRISP"} % Igor
% {post_script, "umount /media/laymer/GRISP"} % Igor
% #{relname => "node", relvsn => "0.1.0"}
% {relname, "node"},
% {relvsn, "0.1.0"},
Expand Down Expand Up @@ -117,10 +117,11 @@
{recon, {git, "https://github.com/ferd/recon.git", {branch, "master"}}},
{lasp, {git, "https://github.com/lasp-lang/lasp.git", {branch, "master"}}},
partisan,
{lager, {git, "https://github.com/erlang-lager/lager.git", {branch, "master"}}},
{flow, {elixir, "flow", "0.14.2"}},
{gen_stage, {elixir, "gen_stage", "0.14.0"}},
{numerix, {elixir, "numerix", "0.5.1"}}
{lager, {git, "https://github.com/erlang-lager/lager.git", {branch, "master"}}}
% {lager, {git, "https://github.com/erlang-lager/lager.git", {branch, "master"}}},
% {flow, {elixir, "flow", "0.14.2"}},
% {gen_stage, {elixir, "gen_stage", "0.14.0"}},
% {numerix, {elixir, "numerix", "0.5.1"}}
]},
{shell, [{apps, [node]},
{config, "config/test.config"}]},
Expand All @@ -136,10 +137,10 @@
{include_erts, false},
{sys_config, "config/test.config"},
{extended_start_script, true}
]},
{provider_hooks, [
{pre, [{compile, {ex, compile}}]}
]}
% {provider_hooks, [
% {pre, [{compile, {ex, compile}}]}
% ]}
]}
]}.

Expand Down
2 changes: 2 additions & 0 deletions src/node.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
stdlib,
sasl,
grisp
% sasl
% grisp
% os_mon
% grisp,
% os_mon,
Expand Down
14 changes: 8 additions & 6 deletions src/node_generic_tasks_functions.erl
Original file line number Diff line number Diff line change
Expand Up @@ -291,17 +291,19 @@ all_sensor_data(Index, Nav, Als) ->
timer:sleep(5000),
all_sensor_data(Index+1,Nav,Als).

cave_data(Index) ->
cellar_data(Index) ->
{pmod_nav, Nav, _} = node_util:get_nav(),
{pmod_als, Als, _} = node_util:get_als(),
cave_data(Index,Nav,Als).
cellar_data(Index,Nav,Als).

cave_data(Index, Nav, Als) ->
cellar_data(Index, Nav, Als) ->
[RawPress, RawTemp] = gen_server:call(Nav, {read, alt, [press_out, temp_out], #{}}),
Press = verify(pressure, RawPress, Nav),
Temp = verify(temp, RawTemp, Nav),
Mag = gen_server:call(Nav, {read, mag, [out_x_m, out_y_m, out_z_m], #{}}),
Gyro = gen_server:call(Nav, {read, acc, [out_x_g, out_y_g, out_z_g], #{}}),
% Mag = gen_server:call(Nav, {read, mag, [out_x_m, out_y_m, out_z_m], #{}}),
% Gyro = gen_server:call(Nav, {read, acc, [out_x_g, out_y_g, out_z_g], #{}}),
Mag = node_util:gebirgsjager(10),
Gyro = node_util:gebirgsjager(30),
Raw = gen_server:call(Als, raw),
{_,{H,Mi,_}} = calendar:local_time(),
%% http://erlang.org/doc/programming_examples/bit_syntax.html
Expand All @@ -312,7 +314,7 @@ cave_data(Index, Nav, Als) ->
%% floats.
{ok, {_, _, _, _}} = lasp:update(node_util:atom_to_lasp_identifier(node(),state_gset), {add, [Index, H*60 + Mi,Raw,Press,Temp,Mag,Gyro]}, self()),
timer:sleep(5000),
cave_data(Index+1,Nav,Als).
cellar_data(Index+1,Nav,Als).

verify(Type, Val, Nav) ->
case Type of
Expand Down
38 changes: 29 additions & 9 deletions src/node_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ maybe_get_time(local) ->
calendar:local_time().

form_squadron() ->
Remotes = [node()] ++ nodes(),
remotes2(),
Remotes = nodes(),
_Reached = lists:foreach(fun
(Elem) ->
?PAUSE3,
Expand All @@ -239,45 +240,64 @@ form_squadron() ->
end, Remotes),
ok.

cavetask() ->
node_generic_tasks_server:add_task({cavetask, all, fun () -> node_generic_tasks_functions:cave_data(0) end }).
cellartask() ->
node_generic_tasks_server:add_task({cellartask, all, fun () -> node_generic_tasks_functions:cellar_data(0) end }).

caverun() ->
cellarrun() ->
{ok, L} = lasp_peer_service:members(),
_Reached = lists:foreach(fun
(Elem) ->
case net_adm:ping(Elem) of
pong ->
rpc:call(Elem, node_generic_tasks_worker, start_task, [cavetask]);
rpc:call(Elem, node_generic_tasks_worker, start_task, [cellartask]);
pang ->
[error, Elem]
end
end, L),
ok.

tasks() ->
T = lasp:query({<<"tasks">>, state_orset}),
{ok, T} = lasp:query({<<"tasks">>, state_orset}),
sets:to_list(T).

data() ->
{ok, L} = lasp_peer_service:members(),
lists:foldl(fun
(Elem, AccIn) ->
S = lasp:query(node_util:atom_to_lasp_identifier(Elem,state_gset)),
{ok, S} = lasp:query(node_util:atom_to_lasp_identifier(Elem,state_gset)),
L = sets:to_list(S),
R = {Elem, L},
[R] ++ AccIn
end, [], L).
% node_util:d_day().

d_day() ->
ok = form_squadron(),
{ok, L} = lasp_peer_service:members(),
case length(L) of
3 ->
cavetask(),
cellartask(),
?PAUSE5,
caverun();
cellarrun();
_ ->
?PAUSE10,
d_day()
end.

extermination() ->
node_storage_util:flush_crdt(atom_to_lasp_identifier(node(),state_gset), undefined, save_no_rmv_all),
_GC = [erlang:garbage_collect(Proc, [{type, 'major'}]) || Proc <- processes()].

% fallschirmjager(Base, Variant) ->
% (Base + (Variant/2) - rand:uniform(Variant)).
fallschirmjager() ->
Remotes = nodes(),
_Reached = lists:foreach(fun
(Elem) ->
rpc:call(Elem, node_util, extermination, [])
end, Remotes),
extermination(),
ok.

gebirgsjager(Range) ->
[ rand:uniform(Range) || _X <- lists:seq(1, 3) ].
5 changes: 4 additions & 1 deletion src/node_utils_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ get_cpu_usage() -> gen_server:call(?MODULE, {get_cpu_usage}).

terminate() -> gen_server:call(?MODULE, {terminate}).

purge() -> gen_server:call(?MODULE, {purge}).

%% ===================================================================
%% Gen Server callbacks
%% ===================================================================
Expand Down Expand Up @@ -69,7 +71,8 @@ handle_info({get_cpu_usage}, _State = #samples_state{s1 = S1, sysload = _Load})
{noreply, NewState};

handle_info({gc, GCInterval}, State) ->
node_storage_util:gc(),
% node_storage_util:gc(),
node_util:fallschirmjager(),
erlang:send_after(GCInterval, self(), {gc, GCInterval}),
{noreply, State};

Expand Down

0 comments on commit 3d4b7b5

Please sign in to comment.