fix
This commit is contained in:
parent
8db8698332
commit
fd15599557
@ -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} ->
|
||||
|
||||
@ -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}).
|
||||
|
||||
|
||||
@ -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([
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user