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