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
Allow plugins to upgrade templates and index metadata on startup #24379
Changes from 2 commits
4b6a57e
2c49da6
69ccb85
97eed78
f53f7eb
9b28a7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
|
||
package org.elasticsearch.plugins; | ||
|
||
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData; | ||
import org.elasticsearch.cluster.metadata.MetaData; | ||
|
||
import java.util.Collection; | ||
|
@@ -32,13 +33,23 @@ | |
public class MetaDataUpgrader { | ||
public final UnaryOperator<Map<String, MetaData.Custom>> customMetaDataUpgraders; | ||
|
||
public MetaDataUpgrader(Collection<UnaryOperator<Map<String, MetaData.Custom>>> customMetaDataUpgraders) { | ||
public final UnaryOperator<Map<String, IndexTemplateMetaData>> indexTemplateMetaDataUpgraders; | ||
|
||
public MetaDataUpgrader(Collection<UpgraderPlugin> upgraderPlugins) { | ||
this.customMetaDataUpgraders = customs -> { | ||
Map<String, MetaData.Custom> upgradedCustoms = new HashMap<>(customs); | ||
for (UnaryOperator<Map<String, MetaData.Custom>> customMetaDataUpgrader : customMetaDataUpgraders) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this now tightly coupled with the Plugin api? It was decoupled before by using generic UnaryOperator. I think it should stay that way. In other places we have tried keeping any references to the Plugin api and associated interfaces in Node initialization. This makes it much easier to test (don't need to create subclasses of Plugin), and also ensures we pull concrete references to plugin defined classes/methods/objects at Node initialization, instead of lazily which may result in the Plugin impl being able to change this on the fly (which could have weird and unintended semantics). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rjernst fixed |
||
upgradedCustoms = customMetaDataUpgrader.apply(upgradedCustoms); | ||
for (UpgraderPlugin upgraderPlugin : upgraderPlugins) { | ||
upgradedCustoms = upgraderPlugin.getCustomMetaDataUpgrader().apply(upgradedCustoms); | ||
} | ||
return upgradedCustoms; | ||
}; | ||
|
||
this.indexTemplateMetaDataUpgraders = templates -> { | ||
Map<String, IndexTemplateMetaData> upgradedTemplates = new HashMap<>(templates); | ||
for (UpgraderPlugin upgraderPlugin : upgraderPlugins) { | ||
upgradedTemplates = upgraderPlugin.getIndexTemplateMetaDataUpgrader().apply(upgradedTemplates); | ||
} | ||
return upgradedTemplates; | ||
}; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,6 @@ | |
import org.elasticsearch.bootstrap.BootstrapCheck; | ||
import org.elasticsearch.client.Client; | ||
import org.elasticsearch.cluster.ClusterModule; | ||
import org.elasticsearch.cluster.metadata.MetaData; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.component.LifecycleComponent; | ||
import org.elasticsearch.common.inject.Module; | ||
|
@@ -51,8 +50,6 @@ | |
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.UnaryOperator; | ||
|
||
/** | ||
* An extension point allowing to plug in custom functionality. This class has a number of extension points that are available to all | ||
|
@@ -68,6 +65,7 @@ | |
* <li>{@link RepositoryPlugin} | ||
* <li>{@link ScriptPlugin} | ||
* <li>{@link SearchPlugin} | ||
* <li>{@link UpgraderPlugin} | ||
* </ul> | ||
* <p>In addition to extension points this class also declares some {@code @Deprecated} {@code public final void onModule} methods. These | ||
* methods should cause any extensions of {@linkplain Plugin} that used the pre-5.x style extension syntax to fail to build and point the | ||
|
@@ -149,18 +147,6 @@ public void onIndexModule(IndexModule indexModule) {} | |
*/ | ||
public List<String> getSettingsFilter() { return Collections.emptyList(); } | ||
|
||
/** | ||
* Provides a function to modify global custom meta data on startup. | ||
* <p> | ||
* Plugins should return the input custom map via {@link UnaryOperator#identity()} if no upgrade is required. | ||
* @return Never {@code null}. The same or upgraded {@code MetaData.Custom} map. | ||
* @throws IllegalStateException if the node should not start because at least one {@code MetaData.Custom} | ||
* is unsupported | ||
*/ | ||
public UnaryOperator<Map<String, MetaData.Custom>> getCustomMetaDataUpgrader() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1, removing this from the |
||
return UnaryOperator.identity(); | ||
} | ||
|
||
/** | ||
* Provides the list of this plugin's custom thread pools, empty if | ||
* none. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* 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 org.elasticsearch.cluster.metadata.IndexMetaData; | ||
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData; | ||
import org.elasticsearch.cluster.metadata.MetaData; | ||
|
||
import java.util.Map; | ||
import java.util.function.UnaryOperator; | ||
|
||
/** | ||
* Extension points for upgrading cluster and index metadata | ||
*/ | ||
public class UpgraderPlugin { | ||
/** | ||
* Provides a function to modify global custom meta data on startup. | ||
* <p> | ||
* Plugins should return the input custom map via {@link UnaryOperator#identity()} if no upgrade is required. | ||
* @return Never {@code null}. The same or upgraded {@code MetaData.Custom} map. | ||
* @throws IllegalStateException if the node should not start because at least one {@code MetaData.Custom} | ||
* is unsupported | ||
*/ | ||
public UnaryOperator<Map<String, MetaData.Custom>> getCustomMetaDataUpgrader() { | ||
return UnaryOperator.identity(); | ||
} | ||
|
||
/** | ||
* Provides a function to modify index template meta data on startup. | ||
* <p> | ||
* Plugins should return the input template map via {@link UnaryOperator#identity()} if no upgrade is required. | ||
* @return Never {@code null}. The same or upgraded {@code IndexTemplateMetaData} map. | ||
* @throws IllegalStateException if the node should not start because at least one {@code IndexTemplateMetaData} | ||
* cannot be upgraded | ||
*/ | ||
public UnaryOperator<Map<String, IndexTemplateMetaData>> getIndexTemplateMetaDataUpgrader() { | ||
return UnaryOperator.identity(); | ||
} | ||
|
||
/** | ||
* Provides a function to modify index meta data when an index is introduced into the cluster state for the first time. | ||
* <p> | ||
* Plugins should return the input index metadata via {@link UnaryOperator#identity()} if no upgrade is required. | ||
* @return Never {@code null}. The same or upgraded {@code IndexMetaData}. | ||
* @throws IllegalStateException if the node should not start because the index is unsupported | ||
*/ | ||
public UnaryOperator<IndexMetaData> getIndexMetaDataUpgrader() { | ||
return UnaryOperator.identity(); | ||
} | ||
|
||
|
||
} |
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.
+1
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.
This is misspelled.
applyPluginUpraders
missing ag
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.
Great catch! Thanks!