fix
This commit is contained in:
parent
e9c7d64e79
commit
4862fdc94b
@ -95,44 +95,37 @@ attach_channel(Pid, ChannelPid) when is_pid(Pid), is_pid(ChannelPid) ->
|
|||||||
|
|
||||||
-spec get_containers(Pid :: pid()) -> {ok, Ref :: reference()} | {error, Reason :: any()}.
|
-spec get_containers(Pid :: pid()) -> {ok, Ref :: reference()} | {error, Reason :: any()}.
|
||||||
get_containers(Pid) when is_pid(Pid) ->
|
get_containers(Pid) when is_pid(Pid) ->
|
||||||
Request = #'JsonRpcRequest'{method = <<"get_containers">>, params = erlang:term_to_binary(#{} )},
|
gen_statem:call(Pid, {jsonrpc_call, self(), {<<"get_containers">>, #{}}}).
|
||||||
gen_statem:call(Pid, {jsonrpc_call, self(), Request}).
|
|
||||||
|
|
||||||
-spec config_container(Pid :: pid(), ContainerName :: binary(), ConfigJson :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}.
|
-spec config_container(Pid :: pid(), ContainerName :: binary(), ConfigJson :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}.
|
||||||
config_container(Pid, ContainerName, ConfigJson) when is_pid(Pid), is_binary(ContainerName), is_binary(ConfigJson) ->
|
config_container(Pid, ContainerName, ConfigJson) when is_pid(Pid), is_binary(ContainerName), is_binary(ConfigJson) ->
|
||||||
Request = #'JsonRpcRequest'{method = <<"config_container">>,
|
Params = #{<<"container_name">> => ContainerName, <<"config">> => ConfigJson},
|
||||||
params = erlang:term_to_binary(#{<<"container_name">> => ContainerName, <<"config">> => ConfigJson})},
|
gen_statem:call(Pid, {jsonrpc_call, self(), {<<"config_container">>, Params}}).
|
||||||
gen_statem:call(Pid, {jsonrpc_call, self(), Request}).
|
|
||||||
|
|
||||||
-spec deploy_container(Pid :: pid(), TaskId :: integer(), Config :: map()) -> {ok, Ref :: reference()} | {error, Reason :: any()}.
|
-spec deploy_container(Pid :: pid(), TaskId :: integer(), Config :: map()) -> {ok, Ref :: reference()} | {error, Reason :: any()}.
|
||||||
deploy_container(Pid, TaskId, Config) when is_pid(Pid), is_integer(TaskId), is_map(Config) ->
|
deploy_container(Pid, TaskId, Config) when is_pid(Pid), is_integer(TaskId), is_map(Config) ->
|
||||||
Request = #'JsonRpcRequest'{method = <<"deploy">>,
|
Params = #{<<"task_id">> => TaskId, <<"config">> => Config},
|
||||||
params = erlang:term_to_binary(#{<<"task_id">> => TaskId, <<"config">> => Config})},
|
gen_statem:call(Pid, {jsonrpc_call, self(), {<<"deploy">>, Params}}).
|
||||||
gen_statem:call(Pid, {jsonrpc_call, self(), Request}).
|
|
||||||
|
|
||||||
-spec start_container(Pid :: pid(), ContainerName :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}.
|
-spec start_container(Pid :: pid(), ContainerName :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}.
|
||||||
start_container(Pid, ContainerName) when is_pid(Pid), is_binary(ContainerName) ->
|
start_container(Pid, ContainerName) when is_pid(Pid), is_binary(ContainerName) ->
|
||||||
Request = #'JsonRpcRequest'{method = <<"start_container">>,
|
Params = #{<<"container_name">> => ContainerName},
|
||||||
params = erlang:term_to_binary(#{<<"container_name">> => ContainerName})},
|
gen_statem:call(Pid, {jsonrpc_call, self(), {<<"start_container">>, Params}}).
|
||||||
gen_statem:call(Pid, {jsonrpc_call, self(), Request}).
|
|
||||||
|
|
||||||
-spec stop_container(Pid :: pid(), ContainerName :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}.
|
-spec stop_container(Pid :: pid(), ContainerName :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}.
|
||||||
stop_container(Pid, ContainerName) when is_pid(Pid), is_binary(ContainerName) ->
|
stop_container(Pid, ContainerName) when is_pid(Pid), is_binary(ContainerName) ->
|
||||||
Request = #'JsonRpcRequest'{method = <<"stop_container">>,
|
Params = #{<<"container_name">> => ContainerName},
|
||||||
params = erlang:term_to_binary(#{<<"container_name">> => ContainerName})},
|
gen_statem:call(Pid, {jsonrpc_call, self(), {<<"stop_container">>, Params}}).
|
||||||
gen_statem:call(Pid, {jsonrpc_call, self(), Request}).
|
|
||||||
|
|
||||||
-spec kill_container(Pid :: pid(), ContainerName :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}.
|
-spec kill_container(Pid :: pid(), ContainerName :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}.
|
||||||
kill_container(Pid, ContainerName) when is_pid(Pid), is_binary(ContainerName) ->
|
kill_container(Pid, ContainerName) when is_pid(Pid), is_binary(ContainerName) ->
|
||||||
Request = #'JsonRpcRequest'{method = <<"kill_container">>,
|
Params = #{<<"container_name">> => ContainerName},
|
||||||
params = erlang:term_to_binary(#{<<"container_name">> => ContainerName})},
|
gen_statem:call(Pid, {jsonrpc_call, self(), {<<"kill_container">>, Params}}).
|
||||||
gen_statem:call(Pid, {jsonrpc_call, self(), Request}).
|
|
||||||
|
|
||||||
-spec remove_container(Pid :: pid(), ContainerName :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}.
|
-spec remove_container(Pid :: pid(), ContainerName :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}.
|
||||||
remove_container(Pid, ContainerName) when is_pid(Pid), is_binary(ContainerName) ->
|
remove_container(Pid, ContainerName) when is_pid(Pid), is_binary(ContainerName) ->
|
||||||
Request = #'JsonRpcRequest'{method = <<"remove_container">>,
|
Params = #{<<"container_name">> => ContainerName},
|
||||||
params = erlang:term_to_binary(#{<<"container_name">> => ContainerName})},
|
gen_statem:call(Pid, {jsonrpc_call, self(), {<<"remove_container">>, Params}}).
|
||||||
gen_statem:call(Pid, {jsonrpc_call, self(), Request}).
|
|
||||||
|
|
||||||
-spec await_reply(Ref :: reference(), Timeout :: integer()) -> {ok, Result :: binary()} | {error, Reason :: binary()}.
|
-spec await_reply(Ref :: reference(), Timeout :: integer()) -> {ok, Result :: binary()} | {error, Reason :: binary()}.
|
||||||
await_reply(Ref, Timeout) when is_reference(Ref), is_integer(Timeout) ->
|
await_reply(Ref, Timeout) when is_reference(Ref), is_integer(Timeout) ->
|
||||||
|
|||||||
@ -44,8 +44,8 @@ command(Pid, CommandType, Command) when is_pid(Pid), is_integer(CommandType), is
|
|||||||
gen_server:cast(Pid, {command, CommandType, Command}).
|
gen_server:cast(Pid, {command, CommandType, Command}).
|
||||||
|
|
||||||
%% 向通道中写入消息
|
%% 向通道中写入消息
|
||||||
-spec jsonrpc_call(Pid :: pid(), ReceiverPid :: pid(), Request :: #'JsonRpcRequest'{}) -> Ref :: reference().
|
-spec jsonrpc_call(Pid :: pid(), ReceiverPid :: pid(), Request :: {Method :: binary(), Params :: any()}) -> Ref :: reference().
|
||||||
jsonrpc_call(Pid, ReceiverPid, Request = #'JsonRpcRequest'{}) when is_pid(Pid), is_pid(ReceiverPid) ->
|
jsonrpc_call(Pid, ReceiverPid, Request = {Method, _Params}) when is_pid(Pid), is_pid(ReceiverPid), is_binary(Method) ->
|
||||||
Ref = make_ref(),
|
Ref = make_ref(),
|
||||||
gen_server:cast(Pid, {jsonrpc_call, ReceiverPid, Ref, Request}),
|
gen_server:cast(Pid, {jsonrpc_call, ReceiverPid, Ref, Request}),
|
||||||
Ref.
|
Ref.
|
||||||
@ -90,7 +90,9 @@ handle_cast({command, CommandType, Command}, State = #state{transport = Transpor
|
|||||||
{noreply, State};
|
{noreply, State};
|
||||||
|
|
||||||
%% 推送消息
|
%% 推送消息
|
||||||
handle_cast({jsonrpc_call, ReceiverPid, Ref, Request = #'JsonRpcRequest'{}}, State = #state{transport = Transport, socket = Socket, packet_id = PacketId, inflight = Inflight}) ->
|
handle_cast({jsonrpc_call, ReceiverPid, Ref, {Method, Params}}, State = #state{transport = Transport, socket = Socket, packet_id = PacketId, inflight = Inflight})
|
||||||
|
when is_binary(Method) ->
|
||||||
|
Request = #'JsonRpcRequest'{method = Method, params = erlang:term_to_binary(Params)},
|
||||||
Encoded = message_pb:encode_msg(Request, 'JsonRpcRequest'),
|
Encoded = message_pb:encode_msg(Request, 'JsonRpcRequest'),
|
||||||
EncRequest = <<?MESSAGE_JSONRPC_REQUEST, Encoded/binary>>,
|
EncRequest = <<?MESSAGE_JSONRPC_REQUEST, Encoded/binary>>,
|
||||||
Transport:send(Socket, <<?PACKET_REQUEST, PacketId:32, EncRequest/binary>>),
|
Transport:send(Socket, <<?PACKET_REQUEST, PacketId:32, EncRequest/binary>>),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user