diff --git a/src/main/java/org/codelibs/fess/app/web/admin/upgrade/AdminUpgradeAction.java b/src/main/java/org/codelibs/fess/app/web/admin/upgrade/AdminUpgradeAction.java index 0fc6dc1bb..9178c17ff 100644 --- a/src/main/java/org/codelibs/fess/app/web/admin/upgrade/AdminUpgradeAction.java +++ b/src/main/java/org/codelibs/fess/app/web/admin/upgrade/AdminUpgradeAction.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Consumer; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -79,6 +80,8 @@ public class AdminUpgradeAction extends FessAdminAction { // private static final Logger logger = LoggerFactory.getLogger(AdminUpgradeAction.class); + private static final String VERSION_10_2 = "10.2"; + private static final String VERSION_10_1 = "10.1"; private static final String VERSION_10_0 = "10.0"; @@ -158,9 +161,23 @@ public class AdminUpgradeAction extends FessAdminAction { }); verifyToken(() -> asIndexHtml()); - if (VERSION_10_1.equals(form.targetVersion)) { + if (VERSION_10_2.equals(form.targetVersion)) { + try { + upgradeFrom10_2(); + upgradeFromAll(); + + saveInfo(messages -> messages.addSuccessUpgradeFrom(GLOBAL)); + + fessEsClient.refresh(); + } catch (final Exception e) { + logger.warn("Failed to upgrade data.", e); + saveError(messages -> messages.addErrorsFailedToUpgradeFrom(GLOBAL, VERSION_10_1, e.getLocalizedMessage())); + } + } else if (VERSION_10_1.equals(form.targetVersion)) { try { upgradeFrom10_1(); + upgradeFrom10_2(); + upgradeFromAll(); saveInfo(messages -> messages.addSuccessUpgradeFrom(GLOBAL)); @@ -173,6 +190,8 @@ public class AdminUpgradeAction extends FessAdminAction { try { upgradeFrom10_0(); upgradeFrom10_1(); + upgradeFrom10_2(); + upgradeFromAll(); saveInfo(messages -> messages.addSuccessUpgradeFrom(GLOBAL)); @@ -187,6 +206,20 @@ public class AdminUpgradeAction extends FessAdminAction { return redirect(getClass()); } + private void upgradeFromAll() { + final IndicesAdminClient indicesClient = fessEsClient.admin().indices(); + final String crawlerIndex = fessConfig.getIndexDocumentCrawlerIndex(); + + // .crawler + if (existsIndex(indicesClient, crawlerIndex, IndicesOptions.fromOptions(false, true, true, true))) { + deleteIndex(indicesClient, crawlerIndex, response -> {}); + } + } + + private void upgradeFrom10_2() { + // TODO + } + private void upgradeFrom10_1() { final IndicesAdminClient indicesClient = fessEsClient.admin().indices(); final String indexConfigPath = "fess_indices"; @@ -196,6 +229,7 @@ public class AdminUpgradeAction extends FessAdminAction { final String searchIndex = fessConfig.getIndexDocumentSearchIndex(); final String oldDocIndex = "fess"; final String suggestAnalyzerIndex = ".suggest.analyzer"; + final String suggestIndex = fessConfig.getIndexDocumentSuggestIndex(); // file uploadResource(indexConfigPath, oldDocIndex, "ja/mapping.txt"); @@ -701,31 +735,21 @@ public class AdminUpgradeAction extends FessAdminAction { } // fess.suggest - final String suggestIndex = fessConfig.getIndexDocumentSuggestIndex(); if (existsIndex(indicesClient, suggestIndex, IndicesOptions.fromOptions(false, true, true, true))) { - indicesClient.prepareDelete(suggestIndex).execute(new ActionListener() { - - @Override - public void onResponse(DeleteIndexResponse response) { - scheduledJobService.getScheduledJob("suggest_indexer").ifPresent(entity -> { - if (!entity.isEnabled() || entity.isRunning()) { - logger.warn("suggest_indexer job is running."); - return; - } - try { - entity.start(); - } catch (final Exception e) { - logger.warn("Failed to start suggest_indexer job.", e); - } - }).orElse(() -> { - logger.warn("No suggest_indexer job."); - }); - } - - @Override - public void onFailure(Throwable e) { - logger.warn("Failed to delete " + suggestIndex + " index.", e); - } + deleteIndex(indicesClient, suggestIndex, response -> { + scheduledJobService.getScheduledJob("suggest_indexer").ifPresent(entity -> { + if (!entity.isEnabled() || entity.isRunning()) { + logger.warn("suggest_indexer job is running."); + return; + } + try { + entity.start(); + } catch (final Exception e) { + logger.warn("Failed to start suggest_indexer job.", e); + } + }).orElse(() -> { + logger.warn("No suggest_indexer job."); + }); }); } } @@ -1049,4 +1073,20 @@ public class AdminUpgradeAction extends FessAdminAction { return false; } + private void deleteIndex(final IndicesAdminClient indicesClient, final String index, final Consumer comsumer) { + indicesClient.prepareDelete(index).execute(new ActionListener() { + + @Override + public void onResponse(DeleteIndexResponse response) { + logger.info("Deleted " + index + " index."); + comsumer.accept(response); + } + + @Override + public void onFailure(Throwable e) { + logger.warn("Failed to delete " + index + " index.", e); + } + }); + } + } \ No newline at end of file diff --git a/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java b/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java index ad29b4606..1de838390 100644 --- a/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java +++ b/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java @@ -363,6 +363,9 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction /** The key of the configuration. e.g. fess */ String INDEX_DOCUMENT_SUGGEST_INDEX = "index.document.suggest.index"; + /** The key of the configuration. e.g. .crawler */ + String INDEX_DOCUMENT_CRAWLER_INDEX = "index.document.crawler.index"; + /** The key of the configuration. e.g. lang,role,label,anchor */ String INDEX_ADMIN_ARRAY_FIELDS = "index.admin.array.fields"; @@ -2046,6 +2049,13 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction */ String getIndexDocumentSuggestIndex(); + /** + * Get the value for the key 'index.document.crawler.index'.
+ * The value is, e.g. .crawler
+ * @return The value of found property. (NotNull: if not found, exception but basically no way) + */ + String getIndexDocumentCrawlerIndex(); + /** * Get the value for the key 'index.admin.array.fields'.
* The value is, e.g. lang,role,label,anchor
@@ -4690,6 +4700,10 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction return get(FessConfig.INDEX_DOCUMENT_SUGGEST_INDEX); } + public String getIndexDocumentCrawlerIndex() { + return get(FessConfig.INDEX_DOCUMENT_CRAWLER_INDEX); + } + public String getIndexAdminArrayFields() { return get(FessConfig.INDEX_ADMIN_ARRAY_FIELDS); } diff --git a/src/main/resources/fess_config.properties b/src/main/resources/fess_config.properties index 88a9d1fa5..cdcd4bc07 100644 --- a/src/main/resources/fess_config.properties +++ b/src/main/resources/fess_config.properties @@ -173,6 +173,7 @@ index.document.search.index=fess.search index.document.update.index=fess.update index.document.type=doc index.document.suggest.index=fess +index.document.crawler.index=.crawler # doc management index.admin.array.fields=lang,role,label,anchor