make shell less chatty

This commit is contained in:
helge
2020-12-23 13:58:41 -08:00
parent 2cb6ba1cd5
commit fdbeeda7ed
3 changed files with 25 additions and 27 deletions

View File

@@ -260,12 +260,6 @@ handle_cast ({exec_rpc, _RPC}, #ap_state{status=paused}=State) ->
handle_cast ({exec_rpc, RPC}, State) when is_map(RPC) andalso
is_map_key(<<"method">>,RPC) andalso
is_map_key(<<"id">>,RPC) ->
NewState = case maps:get(<<"method">>,RPC) of
<<"echo">> ->
update_debug_state({set_idle,0,0},State);
_ ->
update_debug_state({set_active,0,0},State)
end,
case ovsdb_ap_rpc:eval_req(maps:get(<<"method">>,RPC),
maps:get(<<"id">>,RPC),
RPC,
@@ -276,16 +270,16 @@ handle_cast ({exec_rpc, RPC}, State) when is_map(RPC) andalso
Bytes = length(lists:flatten(R)),
?L_I(?DBGSTR("RPC RESULT (~s): ~Bbytes",[maps:get(<<"id">>,RPC),Bytes])),
ok = ovsdb_ap_comm:send_term(State#ap_state.comm,Result),
{noreply, NewState};
{noreply, check_AP_state(RPC,State)};
{ok, Result} when is_binary(Result) ->
?L_I(?DBGSTR("RPC RAW RESULT (~s): ~Bbytes",[maps:get(<<"id">>,RPC),byte_size(Result)])),
ok = ovsdb_ap_comm:send_term(State#ap_state.comm,Result),
{noreply, NewState};
{noreply, check_AP_state(RPC,State)};
{error, Reason} ->
?L_E(?DBGSTR("RPC call '~s' failed with reason: ~s",[maps:get(<<"method">>,RPC),Reason])),
{norepl,NewState}
{norepl,State}
end;
handle_cast ({exec_rpc, RPC}, State) when is_map(RPC) andalso
is_map_key(<<"result">>,RPC) andalso
@@ -581,6 +575,25 @@ handle_mqtt_stats_update (_Serial,_Stats,State) ->
ovsdb_ap_simop:update_dhcp_leases(State#ap_state.store),
check_publish_monitor(self()),
State.
-spec check_AP_state (RPC :: #{binary() => any()}, State :: #ap_state{}) -> NewState :: #ap_state{}.
check_AP_state (RPC, #ap_state{id=Id, store=Store}=State) ->
case maps:get(<<"method">>,RPC) of
<<"echo">> ->
update_debug_state({set_idle,0,0},State);
<<"monitor">> ->
case ets:match_object(Store,#monitors{_='_'}) of
A when is_list(A) andalso length(A) > 6 ->
io:format("AP ~s finalized; monitoring ~B tables!~n",[Id,length(A)]),
_ = timer:apply_after(500,ovsdb_ap,check_publish_monitor,[self()]),
?L_IA("AP ~s finalized! Last monitor ~s",[Id]);
_ ->
?L_IA("AP ~s expects more monitors!",[Id])
end,
update_debug_state({set_active,0,0},State);
_ ->
update_debug_state({set_active,0,0},State)
end.
%%==============================================================================
%% managing statistics of access point

View File

@@ -17,18 +17,6 @@
-spec req_monitor (NameSpace :: binary(), ToMonitor :: [#{binary()=>term()}], Store :: ets:tid()) -> Result :: #{binary()=>term()}.
req_monitor (NameSpace,[{Table,Operations}|_],Store) ->
monitor (NameSpace,Table,Operations,Store);
% case Table of
% <<"Wifi_Associated_Clients">> ->
% QRes = ovsdb_dba:select_with_key(Table,[],Store),
% timer:apply_after(5000,?MODULE,publish_monitor,[self(),NameSpace,monitor_result(Table,QRes,[])]),
% #{};
% <<"DHCP_leased_IP">> ->
% QRes = ovsdb_dba:select_with_key(Table,[],Store),
% timer:apply_after(5500,?MODULE,publish_monitor,[self(),NameSpace,monitor_result(Table,QRes,[])]),
% #{};
% _ ->
% Ret
% end;
req_monitor (NameSpace,OPS,_) ->
?L_EA("Monitor request for namespace '~s' with unsupported operatiosn format ~p",[NameSpace,OPS]),
#{}.
@@ -194,9 +182,9 @@ create_pub_entries_for_table (Table,Store) ->
case ets:match_object(Store,#monitors{table=Table, _='_'}) of
[#monitors{initial=I, modify=M}] when I=:=true orelse M=:=true ->
[ create_pub_entry(Table, K, Store) || {K,_} <- ovsdb_dba:select_with_key(Table,[],Store) ],
io:format("Monitor data set up for ~s~n",[Table]);
?L_IA("Monitor data set up for ~s~n",[Table]);
_ ->
io:format("ERROR, failed setup monitor for ~s~n",[Table])
?L_EA("ERROR, failed setup monitor for ~s~n",[Table])
end.

View File

@@ -30,12 +30,9 @@ eval_req(<<"transact">>,Id,#{<<"params">>:=_P},_Store) ->
{ok, make_result(Id,<<>>)};
eval_req(<<"monitor">>,Id,#{<<"params">>:=[<<"Open_vSwitch">>,NSpace|Tables]},Store) when length(Tables)==1 ->
?L_IA("MONITOR REQUEST: (~s) for AP ~s",[NSpace,Id]),
Mon = ovsdb_ap_monitor:req_monitor(NSpace,maps:to_list(hd(Tables)),Store),
Res = make_result(Id,Mon),
% Json = iolist_to_binary(jiffy:encode(Res,[pretty])),
io:format("MONITOR REQUEST (~s)~n",[NSpace]),
?L_IA("MONITOR REQUEST: (~s)",[NSpace]),
_ = timer:apply_after(3000,ovsdb_ap,check_publish_monitor,[self()]),
{ok, Res};
eval_req(<<"monitor">>,Id,P,_) ->
?L_EA("unrecognized monitor request: ~p",[P]),