fix(mgmt): remove schema_registry calls from opensource code

This commit is contained in:
Shawn 2020-12-10 16:12:52 +08:00
parent f061b5aa34
commit 12e0028b77
4 changed files with 11 additions and 31 deletions

View File

@ -20,11 +20,11 @@ ensure-rebar3:
$(REBAR): ensure-rebar3
.PHONY: xref
xref:
xref: $(REBAR)
$(REBAR) xref
.PHONY: dialyzer
dialyzer:
dialyzer: $(REBAR)
$(REBAR) dialyzer
.PHONY: distclean

View File

@ -128,7 +128,6 @@
, export_auth_username/0
, export_auth_mnesia/0
, export_acl_mnesia/0
, export_schemas/0
, import_rules/1
, import_resources/1
, import_blacklist/1
@ -138,7 +137,6 @@
, import_auth_username/1
, import_auth_mnesia/1
, import_acl_mnesia/1
, import_schemas/1
, to_version/1
]).
@ -679,13 +677,6 @@ export_acl_mnesia() ->
end, [], ets:tab2list(emqx_acl))
end.
export_schemas() ->
case ets:info(emqx_schema) of
undefined -> [];
_ ->
[emqx_schema_api:format_schema(Schema) || Schema <- emqx_schema_registry:get_all_schemas()]
end.
import_rules(Rules) ->
lists:foreach(fun(#{<<"id">> := RuleId,
<<"rawsql">> := RawSQL,
@ -795,12 +786,6 @@ import_acl_mnesia(Acls) ->
<<"allow">> := Allow} <- Acls ]
end.
import_schemas(Schemas) ->
case ets:info(emqx_schema) of
undefined -> ok;
_ -> [emqx_schema_registry:add_schema(emqx_schema_api:make_schema_params(Schema)) || Schema <- Schemas]
end.
any_to_atom(L) when is_list(L) -> list_to_atom(L);
any_to_atom(B) when is_binary(B) -> binary_to_atom(B, utf8);
any_to_atom(A) when is_atom(A) -> A.

View File

@ -84,7 +84,6 @@ export(_Bindings, _Params) ->
AuthUsername = emqx_mgmt:export_auth_username(),
AuthMnesia = emqx_mgmt:export_auth_mnesia(),
AclMnesia = emqx_mgmt:export_acl_mnesia(),
Schemas = emqx_mgmt:export_schemas(),
Seconds = erlang:system_time(second),
{{Y, M, D}, {H, MM, S}} = emqx_mgmt_util:datetime(Seconds),
Filename = io_lib:format("emqx-export-~p-~p-~p-~p-~p-~p.json", [Y, M, D, H, MM, S]),
@ -100,8 +99,7 @@ export(_Bindings, _Params) ->
{auth_clientid, AuthClientid},
{auth_username, AuthUsername},
{auth_mnesia, AuthMnesia},
{acl_mnesia, AclMnesia},
{schemas, Schemas}
{acl_mnesia, AclMnesia}
],
Bin = emqx_json:encode(Data),
@ -180,20 +178,19 @@ do_import(Filename) ->
case lists:member(Version, ?VERSIONS) of
true ->
try
emqx_mgmt:import_confs(maps:get(<<"configs">>, Data, []), maps:get(<<"listeners_state">>, Data, [])),
%emqx_mgmt:import_confs(maps:get(<<"configs">>, Data, []), maps:get(<<"listeners_state">>, Data, [])),
emqx_mgmt:import_resources(maps:get(<<"resources">>, Data, [])),
emqx_mgmt:import_rules(maps:get(<<"rules">>, Data, [])),
emqx_mgmt:import_blacklist(maps:get(<<"blacklist">>, Data, [])),
emqx_mgmt:import_applications(maps:get(<<"apps">>, Data, [])),
emqx_mgmt:import_users(maps:get(<<"users">>, Data, [])),
emqx_mgmt:import_modules(maps:get(<<"modules">>, Data, [])),
%emqx_mgmt:import_modules(maps:get(<<"modules">>, Data, [])),
emqx_mgmt:import_auth_clientid(maps:get(<<"auth_clientid">>, Data, [])),
emqx_mgmt:import_auth_username(maps:get(<<"auth_username">>, Data, [])),
emqx_mgmt:import_auth_mnesia(maps:get(<<"auth_mnesia">>, Data, []), Version),
emqx_mgmt:import_acl_mnesia(maps:get(<<"acl_mnesia">>, Data, []), Version),
emqx_mgmt:import_schemas(maps:get(<<"schemas">>, Data, [])),
%emqx_mgmt:import_auth_mnesia(maps:get(<<"auth_mnesia">>, Data, []), Version),
%emqx_mgmt:import_acl_mnesia(maps:get(<<"acl_mnesia">>, Data, []), Version),
logger:debug("The emqx data has been imported successfully"),
ok
error({not_implemented, [import_confs,import_modules,import_auth_mnesia,import_acl_mnesia]})
catch Class:Reason:Stack ->
logger:error("The emqx data import failed: ~0p", [{Class,Reason,Stack}]),
{error, import_failed}

View File

@ -567,7 +567,6 @@ data(["export"]) ->
AuthUsername = emqx_mgmt:export_auth_username(),
AuthMnesia = emqx_mgmt:export_auth_mnesia(),
AclMnesia = emqx_mgmt:export_acl_mnesia(),
Schemas = emqx_mgmt:export_schemas(),
Seconds = erlang:system_time(second),
{{Y, M, D}, {H, MM, S}} = emqx_mgmt_util:datetime(Seconds),
Filename = io_lib:format("emqx-export-~p-~p-~p-~p-~p-~p.json", [Y, M, D, H, MM, S]),
@ -583,8 +582,8 @@ data(["export"]) ->
{auth_clientid, AuthClientID},
{auth_username, AuthUsername},
{auth_mnesia, AuthMnesia},
{acl_mnesia, AclMnesia},
{schemas, Schemas}],
{acl_mnesia, AclMnesia}
],
ok = filelib:ensure_dir(NFilename),
case file:write_file(NFilename, emqx_json:encode(Data)) of
ok ->
@ -610,7 +609,6 @@ data(["import", Filename]) ->
emqx_mgmt:import_auth_username(maps:get(<<"auth_username">>, Data, [])),
emqx_mgmt:import_auth_mnesia(maps:get(<<"auth_mnesia">>, Data, [])),
emqx_mgmt:import_acl_mnesia(maps:get(<<"acl_mnesia">>, Data, [])),
emqx_mgmt:import_schemas(maps:get(<<"schemas">>, Data, [])),
emqx_ctl:print("The emqx data has been imported successfully.~n")
catch Class:Reason:Stack ->
emqx_ctl:print("The emqx data import failed due: ~0p~n", [{Class,Reason,Stack}])