chore(gw): refine the cli command
This commit is contained in:
parent
630e0fb8cb
commit
9072a60652
|
@ -73,7 +73,11 @@
|
||||||
%% @doc Handle the custom gen_server:call/2 for its connection process
|
%% @doc Handle the custom gen_server:call/2 for its connection process
|
||||||
-callback handle_call(Req :: any(), channel())
|
-callback handle_call(Req :: any(), channel())
|
||||||
-> {reply, Reply :: any(), channel()}
|
-> {reply, Reply :: any(), channel()}
|
||||||
|
%% Reply to caller and trigger an event(s)
|
||||||
|
| {reply, Reply :: any(),
|
||||||
|
EventOrEvents:: tuple() | list(tuple()), channel()}
|
||||||
| {shutdown, Reason :: any(), Reply :: any(), channel()}
|
| {shutdown, Reason :: any(), Reply :: any(), channel()}
|
||||||
|
%% Shutdown the process, reply to caller and write a packet to client
|
||||||
| {shutdown, Reason :: any(), Reply :: any(),
|
| {shutdown, Reason :: any(), Reply :: any(),
|
||||||
emqx_gateway_frame:frame(), channel()}.
|
emqx_gateway_frame:frame(), channel()}.
|
||||||
|
|
||||||
|
|
|
@ -550,10 +550,16 @@ handle_call(_From, Req, State = #state{
|
||||||
case ChannMod:handle_call(Req, Channel) of
|
case ChannMod:handle_call(Req, Channel) of
|
||||||
{reply, Reply, NChannel} ->
|
{reply, Reply, NChannel} ->
|
||||||
{reply, Reply, State#state{channel = NChannel}};
|
{reply, Reply, State#state{channel = NChannel}};
|
||||||
{reply, Reply, Replies, NChannel} ->
|
{reply, Reply, Msgs, NChannel} ->
|
||||||
{reply, Reply, Replies, State#state{channel = NChannel}};
|
{reply, Reply, Msgs, State#state{channel = NChannel}};
|
||||||
{shutdown, Reason, Reply, NChannel} ->
|
{shutdown, Reason, Reply, NChannel} ->
|
||||||
shutdown(Reason, Reply, State#state{channel = NChannel})
|
shutdown(Reason, Reply, State#state{channel = NChannel});
|
||||||
|
{shutdown, Reason, Reply, Packet, NChannel} ->
|
||||||
|
NState = State#state{channel = NChannel},
|
||||||
|
ok = handle_outgoing(Packet, NState),
|
||||||
|
shutdown(Reason, Reply, NState)
|
||||||
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
@ -829,7 +835,6 @@ inc_outgoing_stats(Ctx, FrameMod, Packet) ->
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Helper functions
|
%% Helper functions
|
||||||
|
|
||||||
-compile({inline, [next_msgs/1]}).
|
|
||||||
next_msgs(Event) when is_tuple(Event) ->
|
next_msgs(Event) when is_tuple(Event) ->
|
||||||
Event;
|
Event;
|
||||||
next_msgs(More) when is_list(More) ->
|
next_msgs(More) when is_list(More) ->
|
||||||
|
|
|
@ -50,30 +50,30 @@ is_cmd(Fun) ->
|
||||||
%% Cmds
|
%% Cmds
|
||||||
|
|
||||||
gateway(["list"]) ->
|
gateway(["list"]) ->
|
||||||
lists:foreach(fun(#{id := InstaId, name := Name, type := Type}) ->
|
lists:foreach(fun(#{type := Type, status := Status}) ->
|
||||||
%% FIXME: Get the real running status
|
%% FIXME: Get the real running status
|
||||||
emqx_ctl:print("Gateway(~s, name=~s, type=~s, status=running~n",
|
emqx_ctl:print("Gateway(type=~s, status=~s~n",
|
||||||
[InstaId, Name, Type])
|
[Type, Status])
|
||||||
end, emqx_gateway:list());
|
end, emqx_gateway:list());
|
||||||
|
|
||||||
gateway(["lookup", GatewayInstaId]) ->
|
gateway(["lookup", GwType]) ->
|
||||||
case emqx_gateway:lookup(atom(GatewayInstaId)) of
|
case emqx_gateway:lookup(atom(GwType)) of
|
||||||
undefined ->
|
undefined ->
|
||||||
emqx_ctl:print("undefined~n");
|
emqx_ctl:print("undefined~n");
|
||||||
Info ->
|
Info ->
|
||||||
emqx_ctl:print("~p~n", [Info])
|
emqx_ctl:print("~p~n", [Info])
|
||||||
end;
|
end;
|
||||||
|
|
||||||
gateway(["stop", GatewayInstaId]) ->
|
gateway(["stop", GwType]) ->
|
||||||
case emqx_gateway:stop(atom(GatewayInstaId)) of
|
case emqx_gateway:stop(atom(GwType)) of
|
||||||
ok ->
|
ok ->
|
||||||
emqx_ctl:print("ok~n");
|
emqx_ctl:print("ok~n");
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
emqx_ctl:print("Error: ~p~n", [Reason])
|
emqx_ctl:print("Error: ~p~n", [Reason])
|
||||||
end;
|
end;
|
||||||
|
|
||||||
gateway(["start", GatewayInstaId]) ->
|
gateway(["start", GwType]) ->
|
||||||
case emqx_gateway:start(atom(GatewayInstaId)) of
|
case emqx_gateway:start(atom(GwType)) of
|
||||||
ok ->
|
ok ->
|
||||||
emqx_ctl:print("ok~n");
|
emqx_ctl:print("ok~n");
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
|
@ -83,12 +83,12 @@ gateway(["start", GatewayInstaId]) ->
|
||||||
gateway(_) ->
|
gateway(_) ->
|
||||||
%% TODO: create/remove APIs
|
%% TODO: create/remove APIs
|
||||||
emqx_ctl:usage([ {"gateway list",
|
emqx_ctl:usage([ {"gateway list",
|
||||||
"List all created gateway instances"}
|
"List all gateway"}
|
||||||
, {"gateway lookup <GatewayId>",
|
, {"gateway lookup <GatewayType>",
|
||||||
"Looup a gateway detailed informations"}
|
"Looup a gateway detailed informations"}
|
||||||
, {"gateway stop <GatewayId>",
|
, {"gateway stop <GatewayType>",
|
||||||
"Stop a gateway instance and release all resources"}
|
"Stop a gateway instance"}
|
||||||
, {"gateway start <GatewayId>",
|
, {"gateway start <GatewayType>",
|
||||||
"Start a gateway instance"}
|
"Start a gateway instance"}
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
@ -146,8 +146,8 @@ gateway(_) ->
|
||||||
end;
|
end;
|
||||||
|
|
||||||
'gateway-metrics'(_) ->
|
'gateway-metrics'(_) ->
|
||||||
emqx_ctl:usage([ {"gateway-metrics <Type>",
|
emqx_ctl:usage([ {"gateway-metrics <GatewayType>",
|
||||||
"List all metrics for a type of gateway"}
|
"List all metrics for a gateway"}
|
||||||
]).
|
]).
|
||||||
|
|
||||||
atom(Id) ->
|
atom(Id) ->
|
||||||
|
|
Loading…
Reference in New Issue