-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add the ability to bundle multiple plugins into a meta plugin #28022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6e928ff
Add the ability to bundle multiple plugins into an uber plugin
jimczi dfe70de
fix tests
jimczi c8728c3
fix test on windows
jimczi bcca2b2
make sure that the sub-plugins are always listed in the same orde
jimczi 8ebccab
rename uber => meta
jimczi 15a6ae4
Merge branch 'master' into feature/uber_plugin
jimczi 2565998
typo
jimczi 067e271
fix qa tests
jimczi aabfc06
restore master assertions
jimczi 98bb465
fix another test
jimczi 33f4aee
update error message
jimczi 25546f2
generate two dummy plugins in the meta plugin example
jimczi 07f9cc9
address reviews
jimczi e3083ba
meta plugin should be moved into its final destination
jimczi 84604d8
validate all bundled plugin names before installing a meta plugin
jimczi 43c38e0
remove debug leftover
jimczi 5043500
include the properties files examples instead of linking to the examp…
jimczi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
buildSrc/src/main/resources/meta-plugin-descriptor.properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Elasticsearch meta plugin descriptor file | ||
| # This file must exist as 'meta-plugin-descriptor.properties' in a folder named `elasticsearch`. | ||
| # | ||
| ### example meta plugin for "meta-foo" | ||
| # | ||
| # meta-foo.zip <-- zip file for the meta plugin, with this structure: | ||
| #|____elasticsearch/ | ||
| #| |____ <sub_plugin_1> <-- The plugin files for sub_plugin_1 (the content of the elastisearch directory) | ||
| #| |____ <sub_plugin_2> <-- The plugin files for sub_plugin_2 | ||
| #| |____ meta-plugin-descriptor.properties <-- example contents below: | ||
| # | ||
| # description=My meta plugin | ||
| # name=meta-foo | ||
| # plugins=sub_plugin_1,sub_plugin_2 | ||
| # | ||
| ### mandatory elements for all meta plugins: | ||
| # | ||
| # 'description': simple summary of the meta plugin | ||
| description=${description} | ||
| # | ||
| # 'name': the meta plugin name | ||
| name=${name} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
core/src/main/java/org/elasticsearch/plugins/MetaPluginInfo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.plugins; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.util.Arrays; | ||
| import java.util.Map; | ||
| import java.util.Properties; | ||
| import java.util.function.Function; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| /** | ||
| * An in-memory representation of the meta plugin descriptor. | ||
| */ | ||
| public class MetaPluginInfo { | ||
| static final String ES_META_PLUGIN_PROPERTIES = "meta-plugin-descriptor.properties"; | ||
|
|
||
| private final String name; | ||
| private final String description; | ||
|
|
||
| /** | ||
| * Construct plugin info. | ||
| * | ||
| * @param name the name of the plugin | ||
| * @param description a description of the plugin | ||
| */ | ||
| private MetaPluginInfo(String name, String description) { | ||
| this.name = name; | ||
| this.description = description; | ||
| } | ||
|
|
||
| /** | ||
| * @return Whether the provided {@code path} is a meta plugin. | ||
| */ | ||
| public static boolean isMetaPlugin(final Path path) { | ||
| return Files.exists(path.resolve(ES_META_PLUGIN_PROPERTIES)); | ||
| } | ||
|
|
||
| /** | ||
| * @return Whether the provided {@code path} is a meta properties file. | ||
| */ | ||
| public static boolean isPropertiesFile(final Path path) { | ||
| return ES_META_PLUGIN_PROPERTIES.equals(path.getFileName().toString()); | ||
| } | ||
|
|
||
| /** reads (and validates) meta plugin metadata descriptor file */ | ||
|
|
||
| /** | ||
| * Reads and validates the meta plugin descriptor file. | ||
| * | ||
| * @param path the path to the root directory for the meta plugin | ||
| * @return the meta plugin info | ||
| * @throws IOException if an I/O exception occurred reading the meta plugin descriptor | ||
| */ | ||
| public static MetaPluginInfo readFromProperties(final Path path) throws IOException { | ||
| final Path descriptor = path.resolve(ES_META_PLUGIN_PROPERTIES); | ||
|
|
||
| final Map<String, String> propsMap; | ||
| { | ||
| final Properties props = new Properties(); | ||
| try (InputStream stream = Files.newInputStream(descriptor)) { | ||
| props.load(stream); | ||
| } | ||
| propsMap = props.stringPropertyNames().stream().collect(Collectors.toMap(Function.identity(), props::getProperty)); | ||
| } | ||
|
|
||
| final String name = propsMap.remove("name"); | ||
| if (name == null || name.isEmpty()) { | ||
| throw new IllegalArgumentException( | ||
| "property [name] is missing for meta plugin in [" + descriptor + "]"); | ||
| } | ||
| final String description = propsMap.remove("description"); | ||
| if (description == null) { | ||
| throw new IllegalArgumentException( | ||
| "property [description] is missing for meta plugin [" + name + "]"); | ||
| } | ||
|
|
||
| if (propsMap.isEmpty() == false) { | ||
| throw new IllegalArgumentException("Unknown properties in meta plugin descriptor: " + propsMap.keySet()); | ||
| } | ||
|
|
||
| return new MetaPluginInfo(name, description); | ||
| } | ||
|
|
||
| /** | ||
| * The name of the meta plugin. | ||
| * | ||
| * @return the meta plugin name | ||
| */ | ||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| /** | ||
| * The description of the meta plugin. | ||
| * | ||
| * @return the meta plugin description | ||
| */ | ||
| public String getDescription() { | ||
| return description; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
|
|
||
| MetaPluginInfo that = (MetaPluginInfo) o; | ||
|
|
||
| if (!name.equals(that.name)) return false; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return name.hashCode(); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| final StringBuilder information = new StringBuilder() | ||
| .append("- Plugin information:\n") | ||
| .append("Name: ").append(name).append("\n") | ||
| .append("Description: ").append(description); | ||
| return information.toString(); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sub -> bundled (as suggested in a previous comment)