From b7d3184200ddfbc405aaaa1579f527b8eaab511f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Wed, 28 Apr 2021 17:52:41 +0200 Subject: [PATCH] align with es221 --- .../main/java/org/xbib/elx/api/BasicClient.java | 4 ++-- .../src/main/java/org/xbib/elx/api/BulkClient.java | 6 +++--- .../org/xbib/elx/common/AbstractAdminClient.java | 4 +++- .../org/xbib/elx/common/AbstractBasicClient.java | 8 ++++---- .../org/xbib/elx/common/AbstractBulkClient.java | 6 ++++-- .../xbib/elx/common/DefaultIndexDefinition.java | 1 - .../java/org/xbib/elx/http/HttpBulkClient.java | 3 +-- .../java/org/xbib/elx/http/HttpSearchClient.java | 3 +-- .../java/org/xbib/elx/node/NodeAdminClient.java | 3 +-- .../java/org/xbib/elx/node/NodeBulkClient.java | 3 +-- .../java/org/xbib/elx/node/NodeClientHelper.java | 14 +++++++++----- .../java/org/xbib/elx/node/NodeSearchClient.java | 3 +-- 12 files changed, 30 insertions(+), 28 deletions(-) diff --git a/elx-api/src/main/java/org/xbib/elx/api/BasicClient.java b/elx-api/src/main/java/org/xbib/elx/api/BasicClient.java index 62b767b..d10b49d 100644 --- a/elx-api/src/main/java/org/xbib/elx/api/BasicClient.java +++ b/elx-api/src/main/java/org/xbib/elx/api/BasicClient.java @@ -8,6 +8,8 @@ import java.util.concurrent.TimeUnit; public interface BasicClient extends Closeable { + void init(Settings settings); + void putClusterSetting(String key, Object value, long timeout, TimeUnit timeUnit); /** @@ -23,8 +25,6 @@ public interface BasicClient extends Closeable { */ ElasticsearchClient getClient(); - void init(Settings settings); - /** * Get cluster name. * @return the cluster name diff --git a/elx-api/src/main/java/org/xbib/elx/api/BulkClient.java b/elx-api/src/main/java/org/xbib/elx/api/BulkClient.java index 28b9e3a..5c9ce79 100644 --- a/elx-api/src/main/java/org/xbib/elx/api/BulkClient.java +++ b/elx-api/src/main/java/org/xbib/elx/api/BulkClient.java @@ -65,7 +65,7 @@ public interface BulkClient extends BasicClient, Flushable { * Delete request. * * @param indexDefinition the index definition - * @param id the id + * @param id the id * @return this */ BulkClient delete(IndexDefinition indexDefinition, String id); @@ -85,7 +85,7 @@ public interface BulkClient extends BasicClient, Flushable { * Note that updates only work correctly when all operations between nodes are synchronized. * * @param indexDefinition the index definition - * @param id the id + * @param id the id * @param source the source * @return this */ @@ -95,7 +95,7 @@ public interface BulkClient extends BasicClient, Flushable { * Update document. Use with precaution! Does not work in all cases. * * @param indexDefinition the index definition - * @param id the id + * @param id the id * @param source the source * @return this */ diff --git a/elx-common/src/main/java/org/xbib/elx/common/AbstractAdminClient.java b/elx-common/src/main/java/org/xbib/elx/common/AbstractAdminClient.java index 1e9cce3..1b165a1 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/AbstractAdminClient.java +++ b/elx-common/src/main/java/org/xbib/elx/common/AbstractAdminClient.java @@ -131,6 +131,7 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements if (isIndexDefinitionDisabled(indexDefinition)) { return -1; } + ensureClientIsPresent(); String index = indexDefinition.getFullIndexName(); GetSettingsRequest request = new GetSettingsRequest().indices(index); GetSettingsResponse response = client.execute(GetSettingsAction.INSTANCE, request).actionGet(); @@ -168,6 +169,7 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements if (index == null) { return Collections.emptyMap(); } + ensureClientIsPresent(); GetAliasesRequest getAliasesRequest = new GetAliasesRequest().indices(index); return getFilters(client.execute(GetAliasesAction.INSTANCE, getAliasesRequest).actionGet()); } @@ -331,7 +333,7 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements } } if (candidateIndices.isEmpty()) { - logger.info("no candidates found"); + logger.info("no candidates found"); return new EmptyPruneResult(); } if (mintokeep > 0 && candidateIndices.size() <= mintokeep) { diff --git a/elx-common/src/main/java/org/xbib/elx/common/AbstractBasicClient.java b/elx-common/src/main/java/org/xbib/elx/common/AbstractBasicClient.java index 26dc196..8ec0b81 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/AbstractBasicClient.java +++ b/elx-common/src/main/java/org/xbib/elx/common/AbstractBasicClient.java @@ -71,9 +71,9 @@ public abstract class AbstractBasicClient implements BasicClient { @Override public void init(Settings settings) { + this.settings = settings; if (closed.compareAndSet(false, true)) { logger.log(Level.INFO, "initializing with settings = " + settings.toDelimitedString(',')); - this.settings = settings; setClient(createClient(settings)); } } @@ -176,6 +176,7 @@ public abstract class AbstractBasicClient implements BasicClient { @Override public boolean isIndexExists(IndexDefinition indexDefinition) { + ensureClientIsPresent(); IndicesExistsRequest indicesExistsRequest = new IndicesExistsRequest(); indicesExistsRequest.indices(indexDefinition.getFullIndexName()); IndicesExistsResponse indicesExistsResponse = @@ -185,18 +186,17 @@ public abstract class AbstractBasicClient implements BasicClient { @Override public void close() throws IOException { - ensureClientIsPresent(); if (closed.compareAndSet(false, true)) { - closeClient(settings); if (scheduler != null) { scheduler.shutdown(); } + closeClient(settings); } } protected abstract ElasticsearchClient createClient(Settings settings); - protected abstract void closeClient(Settings settings) throws IOException; + protected abstract void closeClient(Settings settings); protected void updateIndexSetting(String index, String key, Object value, long timeout, TimeUnit timeUnit) { ensureClientIsPresent(); diff --git a/elx-common/src/main/java/org/xbib/elx/common/AbstractBulkClient.java b/elx-common/src/main/java/org/xbib/elx/common/AbstractBulkClient.java index ac2b5f7..5001739 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/AbstractBulkClient.java +++ b/elx-common/src/main/java/org/xbib/elx/common/AbstractBulkClient.java @@ -191,8 +191,10 @@ public abstract class AbstractBulkClient extends AbstractBasicClient implements @Override public BulkClient index(IndexRequest indexRequest) { - ensureClientIsPresent(); - bulkProcessor.add(indexRequest); + if (bulkProcessor != null) { + ensureClientIsPresent(); + bulkProcessor.add(indexRequest); + } return this; } diff --git a/elx-common/src/main/java/org/xbib/elx/common/DefaultIndexDefinition.java b/elx-common/src/main/java/org/xbib/elx/common/DefaultIndexDefinition.java index f36e171..3b08b01 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/DefaultIndexDefinition.java +++ b/elx-common/src/main/java/org/xbib/elx/common/DefaultIndexDefinition.java @@ -94,7 +94,6 @@ public class DefaultIndexDefinition implements IndexDefinition { if (settings.get("settings") != null && settings.get("mapping") != null) { setSettings(findSettingsFrom(settings.get("settings"))); setMappings(findMappingsFrom(settings.get("mapping"))); - setReplicaCount(settings.getAsInt("replica", 0)); boolean shift = settings.getAsBoolean("shift", false); setShift(shift); if (shift) { diff --git a/elx-http/src/main/java/org/xbib/elx/http/HttpBulkClient.java b/elx-http/src/main/java/org/xbib/elx/http/HttpBulkClient.java index 33e2824..89f26b2 100644 --- a/elx-http/src/main/java/org/xbib/elx/http/HttpBulkClient.java +++ b/elx-http/src/main/java/org/xbib/elx/http/HttpBulkClient.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.xbib.elx.common.AbstractBulkClient; -import java.io.IOException; /** * Elasticsearch HTTP bulk client. @@ -35,7 +34,7 @@ public class HttpBulkClient extends AbstractBulkClient implements ElasticsearchC } @Override - protected void closeClient(Settings settings) throws IOException { + protected void closeClient(Settings settings) { helper.closeClient(settings); } diff --git a/elx-http/src/main/java/org/xbib/elx/http/HttpSearchClient.java b/elx-http/src/main/java/org/xbib/elx/http/HttpSearchClient.java index 3257284..044efde 100644 --- a/elx-http/src/main/java/org/xbib/elx/http/HttpSearchClient.java +++ b/elx-http/src/main/java/org/xbib/elx/http/HttpSearchClient.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.xbib.elx.common.AbstractSearchClient; -import java.io.IOException; /** * Elasticsearch HTTP search client. @@ -35,7 +34,7 @@ public class HttpSearchClient extends AbstractSearchClient implements Elasticsea } @Override - protected void closeClient(Settings settings) throws IOException { + protected void closeClient(Settings settings) { helper.closeClient(settings); } diff --git a/elx-node/src/main/java/org/xbib/elx/node/NodeAdminClient.java b/elx-node/src/main/java/org/xbib/elx/node/NodeAdminClient.java index 7b73a19..772924a 100644 --- a/elx-node/src/main/java/org/xbib/elx/node/NodeAdminClient.java +++ b/elx-node/src/main/java/org/xbib/elx/node/NodeAdminClient.java @@ -3,7 +3,6 @@ package org.xbib.elx.node; import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.settings.Settings; import org.xbib.elx.common.AbstractAdminClient; -import java.io.IOException; public class NodeAdminClient extends AbstractAdminClient { @@ -20,7 +19,7 @@ public class NodeAdminClient extends AbstractAdminClient { } @Override - public void closeClient(Settings settings) throws IOException { + public void closeClient(Settings settings) { helper.closeClient(settings); } } diff --git a/elx-node/src/main/java/org/xbib/elx/node/NodeBulkClient.java b/elx-node/src/main/java/org/xbib/elx/node/NodeBulkClient.java index 566d99e..3e74426 100644 --- a/elx-node/src/main/java/org/xbib/elx/node/NodeBulkClient.java +++ b/elx-node/src/main/java/org/xbib/elx/node/NodeBulkClient.java @@ -3,7 +3,6 @@ package org.xbib.elx.node; import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.settings.Settings; import org.xbib.elx.common.AbstractBulkClient; -import java.io.IOException; public class NodeBulkClient extends AbstractBulkClient { @@ -20,7 +19,7 @@ public class NodeBulkClient extends AbstractBulkClient { } @Override - public void closeClient(Settings settings) throws IOException { + public void closeClient(Settings settings) { helper.closeClient(settings); } } diff --git a/elx-node/src/main/java/org/xbib/elx/node/NodeClientHelper.java b/elx-node/src/main/java/org/xbib/elx/node/NodeClientHelper.java index 04ae279..58efbf1 100644 --- a/elx-node/src/main/java/org/xbib/elx/node/NodeClientHelper.java +++ b/elx-node/src/main/java/org/xbib/elx/node/NodeClientHelper.java @@ -40,11 +40,15 @@ public class NodeClientHelper { key -> innerCreateClient(settings)); } - public void closeClient(Settings settings) throws IOException { - ElasticsearchClient client = clientMap.remove(settings.get("cluster.name")); - if (client != null) { - logger.debug("closing node..."); - node.close(); + public void closeClient(Settings settings) { + clientMap.remove(settings.get("cluster.name")); + logger.debug("closing node..."); + if (node != null) { + try { + node.close(); + } catch (IOException e) { + logger.log(Level.WARN, e.getMessage(), e); + } node = null; } } diff --git a/elx-node/src/main/java/org/xbib/elx/node/NodeSearchClient.java b/elx-node/src/main/java/org/xbib/elx/node/NodeSearchClient.java index cfcf2fe..3269e22 100644 --- a/elx-node/src/main/java/org/xbib/elx/node/NodeSearchClient.java +++ b/elx-node/src/main/java/org/xbib/elx/node/NodeSearchClient.java @@ -3,7 +3,6 @@ package org.xbib.elx.node; import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.settings.Settings; import org.xbib.elx.common.AbstractSearchClient; -import java.io.IOException; public class NodeSearchClient extends AbstractSearchClient { @@ -20,7 +19,7 @@ public class NodeSearchClient extends AbstractSearchClient { } @Override - public void closeClient(Settings settings) throws IOException { + public void closeClient(Settings settings) { helper.closeClient(settings); } }