fix orgId
This commit is contained in:
parent
c067876aba
commit
bdaaf45604
@ -98,10 +98,12 @@ write(Pid, Bucket, Org, Points) when is_pid(Pid), is_binary(Bucket), is_binary(O
|
||||
create_all_buckets(SuperDeviceUUIDs) when is_list(SuperDeviceUUIDs) ->
|
||||
poolboy:transaction(influx_pool, fun(Pid) ->
|
||||
{ok, Orgs} = get_orgs(Pid),
|
||||
lager:debug("[influx_client] orgs is: ~p", [Orgs]),
|
||||
OrgMap = maps:from_list(lists:map(fun(#{<<"name">> := Name, <<"id">> := Id}) -> {Name, Id} end, Orgs)),
|
||||
OrgId = maps:get(?DEFAULT_ORG, OrgMap, <<"">>),
|
||||
lager:debug("[influx_client] org_name: ~p, id is: ~p", [?DEFAULT_ORG, OrgId]),
|
||||
lists:foreach(fun(DeviceUUID) ->
|
||||
Bucket = <<"metric_", DeviceUUID/binary>>,
|
||||
influx_client:create_bucket(Pid, ?DEFAULT_ORG, Bucket)
|
||||
influx_client:create_bucket(Pid, OrgId, Bucket)
|
||||
end, SuperDeviceUUIDs)
|
||||
end).
|
||||
|
||||
@ -110,9 +112,9 @@ create_all_buckets(SuperDeviceUUIDs) when is_list(SuperDeviceUUIDs) ->
|
||||
write(Pid, Bucket, Org, Precision, Points) when is_pid(Pid), is_binary(Bucket), is_binary(Org), is_binary(Precision), is_list(Points) ->
|
||||
gen_server:cast(Pid, {write, Bucket, Org, Precision, Points}).
|
||||
|
||||
-spec create_bucket(Pid :: pid(), Org :: binary(), Bucket :: binary()) -> ok.
|
||||
create_bucket(Pid, Org, Bucket) when is_pid(Pid), is_binary(Org), is_binary(Bucket) ->
|
||||
gen_server:call(Pid, {create_bucket, Org, Bucket}).
|
||||
-spec create_bucket(Pid :: pid(), OrgId :: binary(), Bucket :: binary()) -> ok.
|
||||
create_bucket(Pid, OrgId, Bucket) when is_pid(Pid), is_binary(OrgId), is_binary(Bucket) ->
|
||||
gen_server:call(Pid, {create_bucket, OrgId, Bucket}).
|
||||
|
||||
-spec get_orgs(Pid :: pid()) -> {ok, Orgs :: list()} | {error, Reason :: any()}.
|
||||
get_orgs(Pid) when is_pid(Pid) ->
|
||||
@ -193,7 +195,7 @@ handle_call(get_orgs, _From, State = #state{token = Token, host = Host, port = P
|
||||
{reply, {error, Reason}, State}
|
||||
end;
|
||||
|
||||
handle_call({create_bucket, Org, Bucket}, _From, State = #state{host = Host, port = Port, token = Token}) ->
|
||||
handle_call({create_bucket, OrgId, Bucket}, _From, State = #state{host = Host, port = Port, token = Token}) ->
|
||||
%% 处理headers
|
||||
Headers = [
|
||||
{<<"Content-Type">>, <<"application/json">>},
|
||||
@ -202,7 +204,7 @@ handle_call({create_bucket, Org, Bucket}, _From, State = #state{host = Host, por
|
||||
|
||||
Req = #{
|
||||
<<"name">> => Bucket,
|
||||
<<"orgID">> => Org,
|
||||
<<"orgID">> => OrgId,
|
||||
<<"retentionRules">> => [
|
||||
#{
|
||||
<<"type">> => <<"expire">>,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user