fix
This commit is contained in:
parent
fd15599557
commit
0da6bb543c
@ -13,6 +13,25 @@
|
|||||||
%% API
|
%% API
|
||||||
-export([handle_request/4]).
|
-export([handle_request/4]).
|
||||||
|
|
||||||
|
handle_request("GET", "/container/get_all", #{<<"uuid">> := UUID}, _) when is_binary(UUID) ->
|
||||||
|
%% 检查ConfigJson是否是合法的json字符串
|
||||||
|
case iot_host:get_pid(UUID) of
|
||||||
|
undefined ->
|
||||||
|
{ok, 200, iot_util:json_error(-1, <<"host not found">>)};
|
||||||
|
Pid when is_pid(Pid) ->
|
||||||
|
case iot_host:get_containers(Pid) of
|
||||||
|
{ok, Ref} ->
|
||||||
|
case iot_host:await_reply(Ref, 10000) of
|
||||||
|
{ok, Result} ->
|
||||||
|
{ok, 200, iot_util:json_data(Result)};
|
||||||
|
{error, Reason} ->
|
||||||
|
{ok, 200, iot_util:json_error(-1, Reason)}
|
||||||
|
end;
|
||||||
|
{error, Reason} when is_binary(Reason) ->
|
||||||
|
{ok, 200, iot_util:json_error(-1, Reason)}
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
|
||||||
%% 下发config.json, 微服务接受后,保存服务配置
|
%% 下发config.json, 微服务接受后,保存服务配置
|
||||||
handle_request("POST", "/container/push_config", _,
|
handle_request("POST", "/container/push_config", _,
|
||||||
#{<<"uuid">> := UUID, <<"container_name">> := ContainerName, <<"config">> := Config, <<"timeout">> := Timeout0})
|
#{<<"uuid">> := UUID, <<"container_name">> := ContainerName, <<"config">> := Config, <<"timeout">> := Timeout0})
|
||||||
|
|||||||
@ -25,7 +25,7 @@
|
|||||||
-export([get_metric/1, get_status/1]).
|
-export([get_metric/1, get_status/1]).
|
||||||
%% 通讯相关
|
%% 通讯相关
|
||||||
-export([pub/3, attach_channel/2, command/3]).
|
-export([pub/3, attach_channel/2, command/3]).
|
||||||
-export([deploy_container/3, start_container/2, stop_container/2, config_container/3, await_reply/2]).
|
-export([deploy_container/3, start_container/2, stop_container/2, config_container/3, get_containers/1, await_reply/2]).
|
||||||
%% 设备管理
|
%% 设备管理
|
||||||
-export([reload_device/2, delete_device/2, activate_device/3]).
|
-export([reload_device/2, delete_device/2, activate_device/3]).
|
||||||
-export([heartbeat/1]).
|
-export([heartbeat/1]).
|
||||||
@ -89,6 +89,12 @@ get_metric(Pid) when is_pid(Pid) ->
|
|||||||
attach_channel(Pid, ChannelPid) when is_pid(Pid), is_pid(ChannelPid) ->
|
attach_channel(Pid, ChannelPid) when is_pid(Pid), is_pid(ChannelPid) ->
|
||||||
gen_statem:call(Pid, {attach_channel, ChannelPid}).
|
gen_statem:call(Pid, {attach_channel, ChannelPid}).
|
||||||
|
|
||||||
|
-spec get_containers(Pid :: pid()) -> {ok, Ref :: reference()} | {error, Reason :: any()}.
|
||||||
|
get_containers(Pid) when is_pid(Pid) ->
|
||||||
|
Request = #jsonrpc_request{method = <<"get_containers">>, params = #{}},
|
||||||
|
EncConfigBin = message_codec:encode(?MESSAGE_JSONRPC_REQUEST, Request),
|
||||||
|
gen_statem:call(Pid, {rpc_call, self(), EncConfigBin}).
|
||||||
|
|
||||||
-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 = #jsonrpc_request{method = <<"config_container">>, params = #{<<"container_name">> => ContainerName, <<"config">> => ConfigJson}},
|
Request = #jsonrpc_request{method = <<"config_container">>, params = #{<<"container_name">> => ContainerName, <<"config">> => ConfigJson}},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user