From 55e88d6857362031b9e9336e847b38d8dbd0d8d0 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Tue, 8 Aug 2017 10:17:58 +0200 Subject: [PATCH] Watcher: Ignore if template is missing when upgrade is running (elastic/x-pack-elasticsearch#2199) If one of the old watcher templates does not exist when we try to delete it, the upgrade should just continue. Original commit: elastic/x-pack-elasticsearch@6a52bad329a710b0cef9916154ff380447e57091 --- .../elasticsearch/xpack/upgrade/Upgrade.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/plugin/src/main/java/org/elasticsearch/xpack/upgrade/Upgrade.java b/plugin/src/main/java/org/elasticsearch/xpack/upgrade/Upgrade.java index 28ef3153cd7..4d7cb9b0743 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/upgrade/Upgrade.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/upgrade/Upgrade.java @@ -29,6 +29,7 @@ import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.indices.IndexTemplateMissingException; import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestHandler; @@ -290,13 +291,22 @@ public class Upgrade implements ActionPlugin { private static ActionListener deleteIndexTemplateListener(String name, ActionListener listener, Runnable runnable) { - return ActionListener.wrap(r -> { - if (r.isAcknowledged()) { - runnable.run(); - } else { - listener.onFailure(new ElasticsearchException("Deleting [{}] template was not acknowledged", name)); - } - }, listener::onFailure); + return ActionListener.wrap( + r -> { + if (r.isAcknowledged()) { + runnable.run(); + } else { + listener.onFailure(new ElasticsearchException("Deleting [{}] template was not acknowledged", name)); + } + }, + // if the index template we tried to delete is gone already, no need to worry + e -> { + if (e instanceof IndexTemplateMissingException) { + runnable.run(); + } else { + listener.onFailure(e); + } + }); } private static void startWatcherIfNeeded(Boolean shouldStartWatcher, Client client, ActionListener listener) {