Merge pull request #10756 from zmstone/0519-refactor-move-lib-ee-emqx_ee_conf-to-apps-emqx_enterprise

0519 refactor move lib ee emqx ee conf to apps emqx enterprise
This commit is contained in:
Zaiming (Stone) Shi 2023-05-22 16:56:51 +02:00 committed by GitHub
commit 1f44dd4579
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 239 additions and 114 deletions

View File

@ -859,8 +859,8 @@ setup_node(Node, Opts) when is_map(Opts) ->
LoadSchema andalso LoadSchema andalso
begin begin
%% to avoid sharing data between executions and/or %% to avoid sharing data between executions and/or
%% nodes. these variables might notbe in the %% nodes. these variables might not be in the
%% config file (e.g.: emqx_ee_conf_schema). %% config file (e.g.: emqx_enterprise_schema).
NodeDataDir = filename:join([ NodeDataDir = filename:join([
PrivDataDir, PrivDataDir,
node(), node(),

View File

@ -1076,7 +1076,7 @@ cluster(Config) ->
{priv_data_dir, PrivDataDir}, {priv_data_dir, PrivDataDir},
{load_schema, true}, {load_schema, true},
{start_autocluster, true}, {start_autocluster, true},
{schema_mod, emqx_ee_conf_schema}, {schema_mod, emqx_enterprise_schema},
{env_handler, fun {env_handler, fun
(emqx) -> (emqx) ->
application:set_env(emqx, boot_modules, [broker, router]), application:set_env(emqx, boot_modules, [broker, router]),

View File

@ -496,7 +496,7 @@ cluster(Config) ->
{priv_data_dir, PrivDataDir}, {priv_data_dir, PrivDataDir},
{load_schema, true}, {load_schema, true},
{start_autocluster, true}, {start_autocluster, true},
{schema_mod, emqx_ee_conf_schema}, {schema_mod, emqx_enterprise_schema},
{env_handler, fun {env_handler, fun
(emqx) -> (emqx) ->
application:set_env(emqx, boot_modules, [broker, router]), application:set_env(emqx, boot_modules, [broker, router]),

View File

@ -560,7 +560,7 @@ fields("node") ->
emqx_schema:comma_separated_atoms(), emqx_schema:comma_separated_atoms(),
#{ #{
mapping => "emqx_machine.applications", mapping => "emqx_machine.applications",
default => [], default => <<"">>,
'readOnly' => true, 'readOnly' => true,
importance => ?IMPORTANCE_HIDDEN, importance => ?IMPORTANCE_HIDDEN,
desc => ?DESC(node_applications) desc => ?DESC(node_applications)

View File

@ -0,0 +1,94 @@
Business Source License 1.1
Licensor: Hangzhou EMQ Technologies Co., Ltd.
Licensed Work: EMQX Enterprise Edition
The Licensed Work is (c) 2023
Hangzhou EMQ Technologies Co., Ltd.
Additional Use Grant: Students and educators are granted right to copy,
modify, and create derivative work for research
or education.
Change Date: 2027-02-01
Change License: Apache License, Version 2.0
For information about alternative licensing arrangements for the Software,
please contact Licensor: https://www.emqx.com/en/contact
Notice
The Business Source License (this document, or the “License”) is not an Open
Source license. However, the Licensed Work will eventually be made available
under an Open Source License, as stated in this License.
License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.
“Business Source License” is a trademark of MariaDB Corporation Ab.
-----------------------------------------------------------------------------
Business Source License 1.1
Terms
The Licensor hereby grants you the right to copy, modify, create derivative
works, redistribute, and make non-production use of the Licensed Work. The
Licensor may make an Additional Use Grant, above, permitting limited
production use.
Effective on the Change Date, or the fourth anniversary of the first publicly
available distribution of a specific version of the Licensed Work under this
License, whichever comes first, the Licensor hereby grants you rights under
the terms of the Change License, and the rights granted in the paragraph
above terminate.
If your use of the Licensed Work does not comply with the requirements
currently in effect as described in this License, you must purchase a
commercial license from the Licensor, its affiliated entities, or authorized
resellers, or you must refrain from using the Licensed Work.
All copies of the original and modified Licensed Work, and derivative works
of the Licensed Work, are subject to this License. This License applies
separately for each version of the Licensed Work and the Change Date may vary
for each version of the Licensed Work released by Licensor.
You must conspicuously display this License on each original or modified copy
of the Licensed Work. If you receive the Licensed Work in original or
modified form from a third party, the terms and conditions set forth in this
License apply to your use of that work.
Any use of the Licensed Work in violation of this License will automatically
terminate your rights under this License for the current and all other
versions of the Licensed Work.
This License does not grant you any right in any trademark or logo of
Licensor or its affiliates (provided that you may use a trademark or logo of
Licensor as expressly required by this License).
TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
TITLE.
MariaDB hereby grants you permission to use this Licenses text to license
your works, and to refer to it using the trademark “Business Source License”,
as long as you comply with the Covenants of Licensor below.
Covenants of Licensor
In consideration of the right to use this Licenses text and the “Business
Source License” name and trademark, Licensor covenants to MariaDB, and to all
other recipients of the licensed work to be provided by Licensor:
1. To specify as the Change License the GPL Version 2.0 or any later version,
or a license that is compatible with GPL Version 2.0 or a later version,
where “compatible” means that software provided under the Change License can
be included in a program with software provided under GPL Version 2.0 or a
later version. Licensor may specify additional Change Licenses without
limitation.
2. To either: (a) specify an additional grant of rights to use that does not
impose any additional restriction on the right granted in this License, as
the Additional Use Grant; or (b) insert the text “None”.
3. To specify a Change Date.
4. Not to modify this License in any other way.

View File

@ -0,0 +1,6 @@
# EMQX Enterprise Application
This application so fart only holds EMQX config schema for enterprise edition.
In the future this application will collect more responsibilities in managing
enterprise edition specific features.

View File

@ -1,6 +1,6 @@
{application, emqx_ee_conf, [ {application, emqx_enterprise, [
{description, "EMQX Enterprise Edition configuration schema"}, {description, "EMQX Enterprise Edition"},
{vsn, "0.1.2"}, {vsn, "0.1.0"},
{registered, []}, {registered, []},
{applications, [ {applications, [
kernel, kernel,

View File

@ -0,0 +1,65 @@
%%--------------------------------------------------------------------
%% Copyright (c) 2022-2023 EMQ Technologies Co., Ltd. All Rights Reserved.
%%--------------------------------------------------------------------
-module(emqx_enterprise_schema).
-behaviour(hocon_schema).
-export([namespace/0, roots/0, fields/1, translations/0, translation/1, validations/0, desc/1]).
-define(EE_SCHEMA_MODULES, [emqx_license_schema, emqx_ee_schema_registry_schema]).
namespace() ->
emqx_conf_schema:namespace().
roots() ->
redefine_roots(
lists:foldl(
fun(Module, Roots) ->
Roots ++ apply(Module, roots, [])
end,
emqx_conf_schema:roots(),
?EE_SCHEMA_MODULES
)
).
fields("node") ->
redefine_node(emqx_conf_schema:fields("node"));
fields(Name) ->
emqx_conf_schema:fields(Name).
translations() ->
emqx_conf_schema:translations().
translation(Name) ->
emqx_conf_schema:translation(Name).
validations() ->
emqx_conf_schema:validations().
redefine_node(Fields) ->
Overrides = [{"applications", #{default => <<"emqx_license">>}}],
override(Fields, Overrides).
redefine_roots(Roots) ->
Overrides = [{"node", #{type => hoconsc:ref(?MODULE, "node")}}],
override(Roots, Overrides).
override(Fields, []) ->
Fields;
override(Fields, [{Name, Override} | More]) ->
Schema = find_schema(Name, Fields),
NewSchema = hocon_schema:override(Schema, Override),
NewFields = replace_schema(Name, NewSchema, Fields),
override(NewFields, More).
find_schema(Name, Fields) ->
{Name, Schema} = lists:keyfind(Name, 1, Fields),
Schema.
replace_schema(Name, Schema, Fields) ->
lists:keyreplace(Name, 1, Fields, {Name, Schema}).
desc(Name) ->
emqx_conf_schema:desc(Name).

View File

@ -0,0 +1,52 @@
%%--------------------------------------------------------------------
%% Copyright (c) 2022-2023 EMQ Technologies Co., Ltd. All Rights Reserved.
%%--------------------------------------------------------------------
-module(emqx_enterprise_schema_SUITE).
-compile(nowarn_export_all).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl").
all() ->
emqx_common_test_helpers:all(?MODULE).
%%------------------------------------------------------------------------------
%% Tests
%%------------------------------------------------------------------------------
t_namespace(_Config) ->
?assertEqual(
emqx_conf_schema:namespace(),
emqx_enterprise_schema:namespace()
).
t_roots(_Config) ->
EnterpriseRoots = emqx_enterprise_schema:roots(),
?assertMatch({license, _}, lists:keyfind(license, 1, EnterpriseRoots)).
t_fields(_Config) ->
CeFields = emqx_conf_schema:fields("node"),
EeFields = emqx_enterprise_schema:fields("node"),
?assertEqual(length(CeFields), length(EeFields)),
lists:foreach(
fun({{CeName, CeSchema}, {EeName, EeSchema}}) ->
?assertEqual(CeName, EeName),
case CeName of
"applications" ->
ok;
_ ->
?assertEqual({CeName, CeSchema}, {EeName, EeSchema})
end
end,
lists:zip(CeFields, EeFields)
).
t_translations(_Config) ->
[Root | _] = emqx_enterprise_schema:translations(),
?assertEqual(
emqx_conf_schema:translation(Root),
emqx_enterprise_schema:translation(Root)
).

View File

@ -2,7 +2,7 @@
%% Copyright (c) 2022-2023 EMQ Technologies Co., Ltd. All Rights Reserved. %% Copyright (c) 2022-2023 EMQ Technologies Co., Ltd. All Rights Reserved.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-module(emqx_ee_conf_schema_tests). -module(emqx_enterprise_schema_tests).
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
@ -22,7 +22,7 @@ doc_gen_test() ->
"priv", "priv",
"i18n.conf" "i18n.conf"
]), ]),
_ = emqx_conf:dump_schema(Dir, emqx_ee_conf_schema, I18nFile), _ = emqx_conf:dump_schema(Dir, emqx_enterprise_schema, I18nFile),
ok ok
end end
}. }.

2
build
View File

@ -106,7 +106,7 @@ make_docs() {
fi fi
case "$(is_enterprise "$PROFILE")" in case "$(is_enterprise "$PROFILE")" in
'yes') 'yes')
SCHEMA_MODULE='emqx_ee_conf_schema' SCHEMA_MODULE='emqx_enterprise_schema'
;; ;;
'no') 'no')
SCHEMA_MODULE='emqx_conf_schema' SCHEMA_MODULE='emqx_conf_schema'

7
dev
View File

@ -131,10 +131,10 @@ export PROFILE
case "${PROFILE}" in case "${PROFILE}" in
emqx) emqx)
SCHEMA_MOD='emqx_conf_schema' export SCHEMA_MOD='emqx_conf_schema'
;; ;;
emqx-enterprise) emqx-enterprise)
SCHEMA_MOD='emqx_ee_conf_schema' export SCHEMA_MOD='emqx_enterprise_schema'
;; ;;
esac esac
@ -329,11 +329,10 @@ boot() {
copy_other_conf_files copy_other_conf_files
APPS="$(apps_to_load)" APPS="$(apps_to_load)"
BOOT_SEQUENCE=" BOOT_SEQUENCE="
Apps=[${APPS}], Apps=[${APPS}],
ok=lists:foreach(fun application:load/1, Apps), ok=lists:foreach(fun application:load/1, Apps),
io:format(user, \"~nLoaded ~p apps~n\", [length(Apps)]), io:format(user, \"~nLoaded: ~p~n\", [Apps]),
{ok, _} = application:ensure_all_started(emqx_machine). {ok, _} = application:ensure_all_started(emqx_machine).
" "

View File

@ -1,3 +0,0 @@
# emqx_ee_conf
EMQX Enterprise configuration schema

View File

@ -1,35 +0,0 @@
%%--------------------------------------------------------------------
%% Copyright (c) 2022-2023 EMQ Technologies Co., Ltd. All Rights Reserved.
%%--------------------------------------------------------------------
-module(emqx_ee_conf_schema).
-behaviour(hocon_schema).
-export([namespace/0, roots/0, fields/1, translations/0, translation/1, validations/0]).
-define(EE_SCHEMA_MODULES, [emqx_license_schema, emqx_ee_schema_registry_schema]).
namespace() ->
emqx_conf_schema:namespace().
roots() ->
lists:foldl(
fun(Module, Roots) ->
Roots ++ apply(Module, roots, [])
end,
emqx_conf_schema:roots(),
?EE_SCHEMA_MODULES
).
fields(Name) ->
emqx_conf_schema:fields(Name).
translations() ->
emqx_conf_schema:translations().
translation(Name) ->
emqx_conf_schema:translation(Name).
validations() ->
emqx_conf_schema:validations().

View File

@ -1,53 +0,0 @@
%%--------------------------------------------------------------------
%% Copyright (c) 2022-2023 EMQ Technologies Co., Ltd. All Rights Reserved.
%%--------------------------------------------------------------------
-module(emqx_ee_conf_schema_SUITE).
-compile(nowarn_export_all).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl").
all() ->
emqx_common_test_helpers:all(?MODULE).
%%------------------------------------------------------------------------------
%% Tests
%%------------------------------------------------------------------------------
t_namespace(_Config) ->
?assertEqual(
emqx_conf_schema:namespace(),
emqx_ee_conf_schema:namespace()
).
t_roots(_Config) ->
BaseRoots = emqx_conf_schema:roots(),
EnterpriseRoots = emqx_ee_conf_schema:roots(),
?assertEqual([], BaseRoots -- EnterpriseRoots),
?assert(
lists:any(
fun
({license, _}) -> true;
(_) -> false
end,
EnterpriseRoots
)
).
t_fields(_Config) ->
?assertEqual(
emqx_conf_schema:fields("node"),
emqx_ee_conf_schema:fields("node")
).
t_translations(_Config) ->
[Root | _] = emqx_ee_conf_schema:translations(),
?assertEqual(
emqx_conf_schema:translation(Root),
emqx_ee_conf_schema:translation(Root)
).

View File

@ -345,7 +345,7 @@ cluster(Config) ->
{priv_data_dir, PrivDataDir}, {priv_data_dir, PrivDataDir},
{load_schema, true}, {load_schema, true},
{start_autocluster, true}, {start_autocluster, true},
{schema_mod, emqx_ee_conf_schema}, {schema_mod, emqx_enterprise_schema},
%% need to restart schema registry app in the tests so %% need to restart schema registry app in the tests so
%% that it re-registers the config handler that is lost %% that it re-registers the config handler that is lost
%% when emqx_conf restarts during join. %% when emqx_conf restarts during join.

View File

@ -73,10 +73,10 @@ setup_test(TestCase, Config) when
[ [
{apps, [emqx_conf, emqx_license]}, {apps, [emqx_conf, emqx_license]},
{load_schema, false}, {load_schema, false},
{schema_mod, emqx_ee_conf_schema}, {schema_mod, emqx_enterprise_schema},
{env_handler, fun {env_handler, fun
(emqx) -> (emqx) ->
emqx_config:save_schema_mod_and_names(emqx_ee_conf_schema), emqx_config:save_schema_mod_and_names(emqx_enterprise_schema),
%% emqx_config:save_schema_mod_and_names(emqx_license_schema), %% emqx_config:save_schema_mod_and_names(emqx_license_schema),
application:set_env(emqx, boot_modules, []), application:set_env(emqx, boot_modules, []),
application:set_env( application:set_env(
@ -90,7 +90,7 @@ setup_test(TestCase, Config) when
), ),
ok; ok;
(emqx_conf) -> (emqx_conf) ->
emqx_config:save_schema_mod_and_names(emqx_ee_conf_schema), emqx_config:save_schema_mod_and_names(emqx_enterprise_schema),
%% emqx_config:save_schema_mod_and_names(emqx_license_schema), %% emqx_config:save_schema_mod_and_names(emqx_license_schema),
application:set_env( application:set_env(
emqx, emqx,

View File

@ -384,7 +384,7 @@ defmodule EMQXUmbrella.MixProject do
if(edition_type == :enterprise, if(edition_type == :enterprise,
do: [ do: [
emqx_license: :permanent, emqx_license: :permanent,
emqx_ee_conf: :load, emqx_enterprise: :load,
emqx_ee_connector: :permanent, emqx_ee_connector: :permanent,
emqx_ee_bridge: :permanent, emqx_ee_bridge: :permanent,
emqx_bridge_kafka: :permanent, emqx_bridge_kafka: :permanent,
@ -785,7 +785,7 @@ defmodule EMQXUmbrella.MixProject do
end end
end end
defp emqx_schema_mod(:enterprise), do: :emqx_ee_conf_schema defp emqx_schema_mod(:enterprise), do: :emqx_enterprise_schema
defp emqx_schema_mod(:community), do: :emqx_conf_schema defp emqx_schema_mod(:community), do: :emqx_conf_schema
defp bcrypt_dep() do defp bcrypt_dep() do

View File

@ -346,7 +346,7 @@ overlay_vars_edition(ce) ->
]; ];
overlay_vars_edition(ee) -> overlay_vars_edition(ee) ->
[ [
{emqx_schema_mod, emqx_ee_conf_schema}, {emqx_schema_mod, emqx_enterprise_schema},
{is_enterprise, "yes"} {is_enterprise, "yes"}
]. ].
@ -453,7 +453,7 @@ is_app(Name) ->
relx_apps_per_edition(ee) -> relx_apps_per_edition(ee) ->
[ [
emqx_license, emqx_license,
{emqx_ee_conf, load}, {emqx_enterprise, load},
emqx_ee_connector, emqx_ee_connector,
emqx_ee_bridge, emqx_ee_bridge,
emqx_bridge_kafka, emqx_bridge_kafka,