From fd15599557c08a27c6038e97a02383275f380e8f Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Fri, 26 Sep 2025 15:45:31 +0800 Subject: [PATCH] fix --- apps/iot/src/http_handlers/container_handler.erl | 3 +-- apps/iot/src/iot_host.erl | 12 ++++++------ apps/iot/src/message/message_codec.erl | 4 ++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/apps/iot/src/http_handlers/container_handler.erl b/apps/iot/src/http_handlers/container_handler.erl index 4dd7ea4..5de9b9d 100644 --- a/apps/iot/src/http_handlers/container_handler.erl +++ b/apps/iot/src/http_handlers/container_handler.erl @@ -46,8 +46,7 @@ handle_request("POST", "/container/deploy", _, #{<<"uuid">> := UUID, <<"task_id" undefined -> {ok, 200, iot_util:json_error(404, <<"host not found">>)}; Pid when is_pid(Pid) -> - ConfigBin = jiffy:encode(Config, [force_utf8]), - case iot_host:deploy_container(Pid, TaskId, ConfigBin) of + case iot_host:deploy_container(Pid, TaskId, Config) of {ok, Ref} -> case iot_host:await_reply(Ref, 5000) of {ok, Result} -> diff --git a/apps/iot/src/iot_host.erl b/apps/iot/src/iot_host.erl index cd4374c..b65d05c 100644 --- a/apps/iot/src/iot_host.erl +++ b/apps/iot/src/iot_host.erl @@ -91,25 +91,25 @@ attach_channel(Pid, ChannelPid) when is_pid(Pid), is_pid(ChannelPid) -> -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) -> - Request = #jsonrpc_request{id = 0, method = <<"config_container">>, params = #{<<"container_name">> => ContainerName, <<"config">> => ConfigJson}}, + Request = #jsonrpc_request{method = <<"config_container">>, params = #{<<"container_name">> => ContainerName, <<"config">> => ConfigJson}}, EncConfigBin = message_codec:encode(?MESSAGE_JSONRPC_REQUEST, Request), gen_statem:call(Pid, {rpc_call, self(), EncConfigBin}). --spec deploy_container(Pid :: pid(), TaskId :: integer(), Config :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}. -deploy_container(Pid, TaskId, Config) when is_pid(Pid), is_integer(TaskId), is_binary(Config) -> - Request = #jsonrpc_request{id = 0, method = <<"deploy">>, params = #{<<"task_id">> => TaskId, <<"config">> => Config}}, +-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) -> + Request = #jsonrpc_request{method = <<"deploy">>, params = #{<<"task_id">> => TaskId, <<"config">> => Config}}, EncDeployBin = message_codec:encode(?MESSAGE_JSONRPC_REQUEST, Request), gen_statem:call(Pid, {rpc_call, self(), EncDeployBin}). -spec start_container(Pid :: pid(), ContainerName :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}. start_container(Pid, ContainerName) when is_pid(Pid), is_binary(ContainerName) -> - Request = #jsonrpc_request{id = 0, method = <<"start_container">>, params = #{<<"container_name">> => ContainerName}}, + Request = #jsonrpc_request{method = <<"start_container">>, params = #{<<"container_name">> => ContainerName}}, EncCallBin = message_codec:encode(?MESSAGE_JSONRPC_REQUEST, Request), gen_statem:call(Pid, {rpc_call, self(), EncCallBin}). -spec stop_container(Pid :: pid(), ContainerName :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}. stop_container(Pid, ContainerName) when is_pid(Pid), is_binary(ContainerName) -> - Request = #jsonrpc_request{id = 0, method = <<"stop_container">>, params = #{<<"container_name">> => ContainerName}}, + Request = #jsonrpc_request{method = <<"stop_container">>, params = #{<<"container_name">> => ContainerName}}, EncCallBin = message_codec:encode(?MESSAGE_JSONRPC_REQUEST, Request), gen_statem:call(Pid, {rpc_call, self(), EncCallBin}). diff --git a/apps/iot/src/message/message_codec.erl b/apps/iot/src/message/message_codec.erl index 065eeca..e98f7f3 100644 --- a/apps/iot/src/message/message_codec.erl +++ b/apps/iot/src/message/message_codec.erl @@ -37,7 +37,7 @@ encode0(#jsonrpc_reply{result = Result, error = undefined}) -> ResultBin = jiffy:encode(#{<<"result">> => Result}, [force_utf8]), iolist_to_binary([marshal(?Bytes, ResultBin)]); encode0(#jsonrpc_reply{result = undefined, error = Error}) -> - ResultBin = jiffy:encode(#{<<"error">> => Error}, [force_utf8]), + ResultBin = iolist_to_binary(jiffy:encode(#{<<"error">> => Error}, [force_utf8])), iolist_to_binary([marshal(?Bytes, ResultBin)]); encode0(#pub{topic = Topic, content = Content}) -> iolist_to_binary([ @@ -51,7 +51,7 @@ encode0(#command{command_type = CommandType, command = Command}) -> ]); encode0(#jsonrpc_request{method = Method, params = Params}) -> - ReqBody = jiffy:encode(#{<<"method">> => Method, <<"params">> => Params}, [force_utf8]), + ReqBody = iolist_to_binary(jiffy:encode(#{<<"method">> => Method, <<"params">> => Params}, [force_utf8])), marshal(?Bytes, ReqBody); encode0(#data{service_id = ServiceId, device_uuid = DeviceUUID, route_key = RouteKey, metric = Metric}) -> iolist_to_binary([