diff --git a/apps/efka/src/docker/docker_commands.erl b/apps/efka/src/docker/docker_commands.erl index 3760c7c..0406510 100644 --- a/apps/efka/src/docker/docker_commands.erl +++ b/apps/efka/src/docker/docker_commands.erl @@ -165,23 +165,7 @@ gather_output(Port, Acc) -> {Status, iolist_to_binary(Acc)} end. -extract_sha256(Output) when is_binary(Output) -> - Parts = binary:split(Output, <<$\n>>, [global]), - lager:debug("parts: ~p", [Parts]), - case lists:search(fun(Line) -> starts_with(Line, <<"Digest:">>) end, Parts) of - {value, Digest} -> - Sha256 = lists:last(binary:split(Digest, <<":">>, [global])), - {ok, Sha256}; - false -> - error - end. -starts_with(Binary, Prefix) when is_binary(Binary), is_binary(Prefix) -> - PrefixSize = byte_size(Prefix), - case Binary of - <> -> true; - _ -> false - end. %% 构建所有参数 build_options(Config) -> diff --git a/apps/efka/src/docker/docker_manager.erl b/apps/efka/src/docker/docker_manager.erl index ba25f2b..fa89ec9 100644 --- a/apps/efka/src/docker/docker_manager.erl +++ b/apps/efka/src/docker/docker_manager.erl @@ -33,7 +33,7 @@ %%% API %%%=================================================================== --spec deploy(TaskId :: integer(), Config :: map()) -> {ok, ContainerId :: binary()} | {error, Reason :: binary()}. +-spec deploy(TaskId :: integer(), Config :: map()) -> ok | {error, Reason :: binary()}. deploy(TaskId, Config) when is_integer(TaskId), is_map(Config) -> gen_server:call(?SERVER, {deploy, TaskId, Config}). diff --git a/apps/efka/src/efka_codec.erl b/apps/efka/src/efka_codec.erl index 8ea401b..ea75674 100644 --- a/apps/efka/src/efka_codec.erl +++ b/apps/efka/src/efka_codec.erl @@ -102,8 +102,6 @@ decode0(_, _) -> -spec marshal(Type :: integer(), Field :: any()) -> binary(). marshal(?I32, Field) when is_integer(Field) -> <>; -marshal(?Bytes, undefined) -> - <>; marshal(?Bytes, Field) when is_binary(Field) -> Len = byte_size(Field), <>; diff --git a/apps/efka/src/efka_remote_agent.erl b/apps/efka/src/efka_remote_agent.erl index dbf5ddf..253380a 100644 --- a/apps/efka/src/efka_remote_agent.erl +++ b/apps/efka/src/efka_remote_agent.erl @@ -92,11 +92,12 @@ handle_event(cast, {metric_data, ServiceId, DeviceUUID, RouteKey, Metric}, ?STAT efka_transport:send(TransportPid, Packet), {keep_state, State}; -handle_event(cast, {metric_data, ServiceId, DeviceUUID, LineProtocolData}, _, State) -> +handle_event(cast, {metric_data, ServiceId, DeviceUUID, RouteKey, Metric}, _, State) -> Packet = efka_codec:encode(?MESSAGE_DATA, #data{ service_id = ServiceId, device_uuid = DeviceUUID, - metric = LineProtocolData + route_key = RouteKey, + metric = Metric }), ok = cache_model:insert(Packet), {keep_state, State}; @@ -272,7 +273,8 @@ handle_event(info, {server_rpc, PacketId, #rpc_container{method = <<"config">>, % {keep_state, State}; %% 处理命令 -handle_event(info, {server_command, #command{command_type = ?COMMAND_AUTH, command = Auth}}, StateName, State = #state{transport_pid = TransportPid}) -> +handle_event(info, {server_command, #command{command_type = ?COMMAND_AUTH, command = Auth0}}, StateName, State = #state{transport_pid = TransportPid}) -> + Auth = binary_to_integer(Auth0), case {Auth, StateName} of {1, ?STATE_ACTIVATED} -> {keep_state, State}; diff --git a/apps/efka/src/efka_util.erl b/apps/efka/src/efka_util.erl index fbe0e54..eae5318 100644 --- a/apps/efka/src/efka_util.erl +++ b/apps/efka/src/efka_util.erl @@ -14,6 +14,7 @@ -export([timestamp/0, number_format/2, timestamp_ms/0, float_to_binary/2, int_format/2]). -export([chunks/2, rand_bytes/1, uuid/0, md5/1, sha_uuid/0]). -export([json_data/1, json_error/2]). +-export([starts_with/2]). get_file_md5(FilePath) when is_list(FilePath) -> {ok, FileData} = file:read_file(FilePath), @@ -102,4 +103,12 @@ float_to_binary(V, Decimals) when is_float(V), is_integer(Decimals) -> sha_uuid() -> Salt = crypto:strong_rand_bytes(32), Str = string:lowercase(binary:encode_hex(crypto:hash(sha256, Salt))), - binary:part(Str, 1, 32). \ No newline at end of file + binary:part(Str, 1, 32). + +-spec starts_with(Binary :: binary(), Prefix :: binary()) -> boolean(). +starts_with(Binary, Prefix) when is_binary(Binary), is_binary(Prefix) -> + PrefixSize = byte_size(Prefix), + case Binary of + <> -> true; + _ -> false + end. \ No newline at end of file