diff options
| author | Daniil Fedotov <dfedotov@pivotal.io> | 2016-02-19 11:24:13 +0000 |
|---|---|---|
| committer | Daniil Fedotov <dfedotov@pivotal.io> | 2016-02-19 11:24:13 +0000 |
| commit | a1c765da79f81c8e07191fccb4aecb14819eeb1f (patch) | |
| tree | bdc03d27caa99394eafd1872e90e5a2d3e496725 /src | |
| parent | d0bc71dba5a07786d4f9d71445b55276bfb12846 (diff) | |
| download | rabbitmq-server-git-a1c765da79f81c8e07191fccb4aecb14819eeb1f.tar.gz | |
Use advanced config as inittial config. Extract plugin schemas
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit.erl | 2 | ||||
| -rw-r--r-- | src/rabbit_config.erl | 23 | ||||
| -rw-r--r-- | src/rabbit_plugins.erl | 69 |
3 files changed, 68 insertions, 26 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl index 7fafaf4d4d..278ec0197d 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -302,8 +302,6 @@ ensure_config() -> broker_start() -> Plugins = rabbit_plugins:setup(), - % Duplicate ensure_config to support plugin schemas. - ensure_config(), ToBeLoaded = Plugins ++ ?APPS, start_apps(ToBeLoaded), case os:type() of diff --git a/src/rabbit_config.erl b/src/rabbit_config.erl index a6107aef6d..4bccc5d0c7 100644 --- a/src/rabbit_config.erl +++ b/src/rabbit_config.erl @@ -8,7 +8,7 @@ schema_dir/0]). prepare_and_use_config() -> - case config_exist() of + case erlang_config_used() of true -> %% Use .config file ok; @@ -25,10 +25,14 @@ prepare_and_use_config() -> end end. -config_exist() -> +erlang_config_used() -> case init:get_argument(config) of - {ok, Config} -> rabbit_file:is_file(Config ++ ".config"); - _ -> false + error -> false; + {ok, Config} -> + ConfigFile = Config ++ ".config", + rabbit_file:is_file(ConfigFile) + andalso + get_advanced_config() =/= {ok, ConfigFile} end. get_confs() -> @@ -61,6 +65,7 @@ update_app_config(ConfigFile) -> generate_config_file(ConfFiles, ConfDir, ScriptDir) -> SchemaDir = schema_dir(), + prepare_plugin_schemas(SchemaDir), % SchemaFile = filename:join([ScriptDir, "rabbitmq.schema"]), Cuttlefish = filename:join([ScriptDir, "cuttlefish"]), GeneratedDir = filename:join([ConfDir, "generated"]), @@ -107,3 +112,13 @@ get_advanced_config() -> end; _ -> none end. + + +prepare_plugin_schemas(SchemaDir) -> + case rabbit_file:is_dir(SchemaDir) of + true -> rabbit_plugins:extract_schemas(SchemaDir); + false -> ok + end. + + + diff --git a/src/rabbit_plugins.erl b/src/rabbit_plugins.erl index 3d960edcbe..1c1f478f6f 100644 --- a/src/rabbit_plugins.erl +++ b/src/rabbit_plugins.erl @@ -16,9 +16,11 @@ -module(rabbit_plugins). -include("rabbit.hrl"). +-include_lib("stdlib/include/zip.hrl"). -export([setup/0, active/0, read_enabled/1, list/1, list/2, dependencies/3]). -export([ensure/1]). +-export([extract_schemas/1]). %%---------------------------------------------------------------------------- @@ -80,6 +82,53 @@ setup() -> Enabled = read_enabled(EnabledFile), prepare_plugins(Enabled). +extract_schemas(SchemaDir) -> + Loaded = ok == application:load(rabbit), + {ok, EnabledFile} = application:get_env(rabbit, enabled_plugins_file), + Enabled = read_enabled(EnabledFile), + + {ok, PluginsDistDir} = application:get_env(rabbit, plugins_dir), + + AllPlugins = list(PluginsDistDir), + Wanted = dependencies(false, Enabled, AllPlugins), + WantedPlugins = lookup_plugins(Wanted, AllPlugins), + io:format("Extracting schema for ~p~n", [Wanted]), + [ extract_schema(Plugin, SchemaDir) || Plugin <- WantedPlugins ], + case Loaded of + true -> ok; + false -> application:unload(rabbit) + end. + +extract_schema(#plugin{type = ez, location = Location}, SchemaDir) -> + {ok, Files} = zip:extract(Location, + [memory, {file_filter, + fun(#zip_file{name = Name}) -> + string:str(Name, "priv/schema") > 0 + end}]), + lists:foreach( + fun({FileName, Content}) -> + ok = file:write_file(filename:join([SchemaDir, + filename:basename(FileName)]), + Content) + end, + Files), + ok; +extract_schema(#plugin{type = dir, location = Location}, SchemaDir) -> + PluginSchema = filename:join([Location, + "priv", + "schema"]), + case rabbit_file:is_dir(PluginSchema) of + false -> ok; + true -> + PluginSchemaFiles = + [ filename:join(PluginSchema, FileName) + || FileName <- rabbit_file:wildcard(".*\\.schema", + PluginSchema) ], + [ file:copy(SchemaFile, SchemaDir) + || SchemaFile <- PluginSchemaFiles ] + end. + + %% @doc Lists the plugins which are currently running. active() -> {ok, ExpandDir} = application:get_env(rabbit, plugins_expand_dir), @@ -229,7 +278,6 @@ clean_plugin(Plugin, ExpandDir) -> prepare_dir_plugin(PluginAppDescPath) -> PluginEbinDir = filename:dirname(PluginAppDescPath), Plugin = filename:basename(PluginAppDescPath, ".app"), - copy_plugin_schema(Plugin, PluginAppDescPath), code:add_patha(PluginEbinDir), case filelib:wildcard(PluginEbinDir++ "/*.beam") of [] -> @@ -252,25 +300,6 @@ prepare_dir_plugin(PluginAppDescPath) -> %%---------------------------------------------------------------------------- -copy_plugin_schema(Plugin, PluginAppDescPath) -> - PluginSchema = filename:join([PluginAppDescPath, - "priv", - "schema"]), - PluginSchemaFiles = [ filename:join(PluginSchema, FileName) - || FileName <- rabbit_file:wildcard(".*\\.schema", - PluginSchema) ], - case rabbit_file:is_dir(PluginSchema) of - false -> ok; - true -> - SchemaDir = rabbit_config:schema_dir(), - case rabbit_file:is_dir(SchemaDir) of - true -> [ file:copy(SchemaFile, SchemaDir) - || SchemaFile <- PluginSchemaFiles ]; - false -> rabbit_log:info("Failed to copy plugin schema. " - "Schema dir doesn't exist") - end - end. - delete_recursively(Fn) -> case rabbit_file:recursive_delete([Fn]) of ok -> ok; |
