mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 09:28:55 -04:00
Fix NPE on plugin sync (#115640)
This commit is contained in:
parent
ef85d0a53f
commit
c4c33ff359
3 changed files with 26 additions and 4 deletions
|
@ -25,6 +25,7 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -60,7 +61,7 @@ public class SyncPluginsAction {
|
||||||
* @throws UserException if a plugins config file is found.
|
* @throws UserException if a plugins config file is found.
|
||||||
*/
|
*/
|
||||||
public static void ensureNoConfigFile(Environment env) throws UserException {
|
public static void ensureNoConfigFile(Environment env) throws UserException {
|
||||||
final Path pluginsConfig = env.configFile().resolve("elasticsearch-plugins.yml");
|
final Path pluginsConfig = env.configFile().resolve(ELASTICSEARCH_PLUGINS_YML);
|
||||||
if (Files.exists(pluginsConfig)) {
|
if (Files.exists(pluginsConfig)) {
|
||||||
throw new UserException(
|
throw new UserException(
|
||||||
ExitCodes.USAGE,
|
ExitCodes.USAGE,
|
||||||
|
@ -207,9 +208,8 @@ public class SyncPluginsAction {
|
||||||
Optional<PluginsConfig> cachedPluginsConfig,
|
Optional<PluginsConfig> cachedPluginsConfig,
|
||||||
List<PluginDescriptor> existingPlugins
|
List<PluginDescriptor> existingPlugins
|
||||||
) {
|
) {
|
||||||
final Map<String, String> cachedPluginIdToLocation = cachedPluginsConfig.map(
|
final Map<String, String> cachedPluginIdToLocation = new HashMap<>();
|
||||||
config -> config.getPlugins().stream().collect(Collectors.toMap(InstallablePlugin::getId, InstallablePlugin::getLocation))
|
cachedPluginsConfig.ifPresent(config -> config.getPlugins().forEach(p -> cachedPluginIdToLocation.put(p.getId(), p.getLocation())));
|
||||||
).orElse(Map.of());
|
|
||||||
|
|
||||||
return pluginsToMaybeUpgrade.stream().filter(eachPlugin -> {
|
return pluginsToMaybeUpgrade.stream().filter(eachPlugin -> {
|
||||||
final String eachPluginId = eachPlugin.getId();
|
final String eachPluginId = eachPlugin.getId();
|
||||||
|
|
|
@ -157,6 +157,22 @@ public class SyncPluginsActionTests extends ESTestCase {
|
||||||
assertThat(pluginChanges.upgrade.get(0).getId(), equalTo("analysis-icu"));
|
assertThat(pluginChanges.upgrade.get(0).getId(), equalTo("analysis-icu"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that when there is an official plugin in the config file and in the cached config, then we
|
||||||
|
* calculate that the plugin does not need to be upgraded.
|
||||||
|
*/
|
||||||
|
public void test_getPluginChanges_withOfficialPluginCachedConfigAndNoChanges_returnsNoChanges() throws Exception {
|
||||||
|
createPlugin("analysis-icu");
|
||||||
|
config.setPlugins(List.of(new InstallablePlugin("analysis-icu")));
|
||||||
|
|
||||||
|
final PluginsConfig cachedConfig = new PluginsConfig();
|
||||||
|
cachedConfig.setPlugins(List.of(new InstallablePlugin("analysis-icu")));
|
||||||
|
|
||||||
|
final PluginChanges pluginChanges = action.getPluginChanges(config, Optional.of(cachedConfig));
|
||||||
|
|
||||||
|
assertThat(pluginChanges.isEmpty(), is(true));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that if an unofficial plugins' location has not changed in the cached config, then we
|
* Check that if an unofficial plugins' location has not changed in the cached config, then we
|
||||||
* calculate that the plugin does not need to be upgraded.
|
* calculate that the plugin does not need to be upgraded.
|
||||||
|
|
6
docs/changelog/115640.yaml
Normal file
6
docs/changelog/115640.yaml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
pr: 115640
|
||||||
|
summary: Fix NPE on plugin sync
|
||||||
|
area: Infra/CLI
|
||||||
|
type: bug
|
||||||
|
issues:
|
||||||
|
- 114818
|
Loading…
Add table
Add a link
Reference in a new issue